@distilled.cloud/twitch 0.0.0 → 1.0.0-rc.22
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/LICENSE +201 -0
- package/README.md +79 -4
- package/lib/.lazy.json +1 -0
- package/lib/_bundle/lazy.js +4 -0
- package/lib/_bundle/sdk.js +2 -0
- package/lib/_bundle/sdk.js.map +1 -0
- package/lib/credentials.d.ts +31 -0
- package/lib/credentials.d.ts.map +1 -0
- package/lib/credentials.js +1 -0
- package/lib/errors.d.ts +49 -0
- package/lib/errors.d.ts.map +1 -0
- package/lib/errors.js +1 -0
- package/lib/index.d.ts +46 -0
- package/lib/index.d.ts.map +1 -0
- package/lib/index.js +6 -0
- package/lib/pagination.d.ts +10 -0
- package/lib/pagination.d.ts.map +1 -0
- package/lib/pagination.js +1 -0
- package/lib/protocol.d.ts +19 -0
- package/lib/protocol.d.ts.map +1 -0
- package/lib/protocol.js +1 -0
- package/lib/retry.d.ts +50 -0
- package/lib/retry.d.ts.map +1 -0
- package/lib/retry.js +1 -0
- package/lib/services/ads.d.ts +75 -0
- package/lib/services/ads.d.ts.map +1 -0
- package/lib/services/ads.js +2 -0
- package/lib/services/ads.js.map +1 -0
- package/lib/services/analytics.d.ts +90 -0
- package/lib/services/analytics.d.ts.map +1 -0
- package/lib/services/analytics.js +2 -0
- package/lib/services/analytics.js.map +1 -0
- package/lib/services/bits.d.ts +284 -0
- package/lib/services/bits.d.ts.map +1 -0
- package/lib/services/bits.js +2 -0
- package/lib/services/bits.js.map +1 -0
- package/lib/services/ccls.d.ts +26 -0
- package/lib/services/ccls.d.ts.map +1 -0
- package/lib/services/ccls.js +2 -0
- package/lib/services/ccls.js.map +1 -0
- package/lib/services/channel_points.d.ts +416 -0
- package/lib/services/channel_points.d.ts.map +1 -0
- package/lib/services/channel_points.js +2 -0
- package/lib/services/channel_points.js.map +1 -0
- package/lib/services/channels.d.ts +173 -0
- package/lib/services/channels.d.ts.map +1 -0
- package/lib/services/channels.js +2 -0
- package/lib/services/channels.js.map +1 -0
- package/lib/services/charity.d.ts +97 -0
- package/lib/services/charity.d.ts.map +1 -0
- package/lib/services/charity.js +2 -0
- package/lib/services/charity.js.map +1 -0
- package/lib/services/chat.d.ts +638 -0
- package/lib/services/chat.d.ts.map +1 -0
- package/lib/services/chat.js +33 -0
- package/lib/services/chat.js.map +1 -0
- package/lib/services/clips.d.ts +153 -0
- package/lib/services/clips.d.ts.map +1 -0
- package/lib/services/clips.js +2 -0
- package/lib/services/clips.js.map +1 -0
- package/lib/services/conduits.d.ts +172 -0
- package/lib/services/conduits.d.ts.map +1 -0
- package/lib/services/conduits.js +2 -0
- package/lib/services/conduits.js.map +1 -0
- package/lib/services/entitlements.d.ts +76 -0
- package/lib/services/entitlements.d.ts.map +1 -0
- package/lib/services/entitlements.js +2 -0
- package/lib/services/entitlements.js.map +1 -0
- package/lib/services/eventsub.d.ts +158 -0
- package/lib/services/eventsub.d.ts.map +1 -0
- package/lib/services/eventsub.js +2 -0
- package/lib/services/eventsub.js.map +1 -0
- package/lib/services/extensions.d.ts +497 -0
- package/lib/services/extensions.d.ts.map +1 -0
- package/lib/services/extensions.js +2 -0
- package/lib/services/extensions.js.map +1 -0
- package/lib/services/games.d.ts +57 -0
- package/lib/services/games.d.ts.map +1 -0
- package/lib/services/games.js +2 -0
- package/lib/services/games.js.map +1 -0
- package/lib/services/goals.d.ts +37 -0
- package/lib/services/goals.d.ts.map +1 -0
- package/lib/services/goals.js +2 -0
- package/lib/services/goals.js.map +1 -0
- package/lib/services/guest_star.d.ts +314 -0
- package/lib/services/guest_star.d.ts.map +1 -0
- package/lib/services/guest_star.js +2 -0
- package/lib/services/guest_star.js.map +1 -0
- package/lib/services/hype_train.d.ts +91 -0
- package/lib/services/hype_train.d.ts.map +1 -0
- package/lib/services/hype_train.js +2 -0
- package/lib/services/hype_train.js.map +1 -0
- package/lib/services/index.d.ts +30 -0
- package/lib/services/index.d.ts.map +1 -0
- package/lib/services/index.js +29 -0
- package/lib/services/moderation.d.ts +731 -0
- package/lib/services/moderation.d.ts.map +1 -0
- package/lib/services/moderation.js +41 -0
- package/lib/services/moderation.js.map +1 -0
- package/lib/services/polls.d.ts +173 -0
- package/lib/services/polls.d.ts.map +1 -0
- package/lib/services/polls.js +2 -0
- package/lib/services/polls.js.map +1 -0
- package/lib/services/predictions.d.ts +221 -0
- package/lib/services/predictions.d.ts.map +1 -0
- package/lib/services/predictions.js +2 -0
- package/lib/services/predictions.js.map +1 -0
- package/lib/services/raids.d.ts +34 -0
- package/lib/services/raids.d.ts.map +1 -0
- package/lib/services/raids.js +2 -0
- package/lib/services/raids.js.map +1 -0
- package/lib/services/schedule.d.ts +223 -0
- package/lib/services/schedule.d.ts.map +1 -0
- package/lib/services/schedule.js +2 -0
- package/lib/services/schedule.js.map +1 -0
- package/lib/services/search.d.ts +89 -0
- package/lib/services/search.d.ts.map +1 -0
- package/lib/services/search.js +2 -0
- package/lib/services/search.js.map +1 -0
- package/lib/services/streams.d.ts +235 -0
- package/lib/services/streams.d.ts.map +1 -0
- package/lib/services/streams.js +2 -0
- package/lib/services/streams.js.map +1 -0
- package/lib/services/subscriptions.d.ts +96 -0
- package/lib/services/subscriptions.d.ts.map +1 -0
- package/lib/services/subscriptions.js +2 -0
- package/lib/services/subscriptions.js.map +1 -0
- package/lib/services/teams.d.ts +90 -0
- package/lib/services/teams.d.ts.map +1 -0
- package/lib/services/teams.js +2 -0
- package/lib/services/teams.js.map +1 -0
- package/lib/services/users.d.ts +324 -0
- package/lib/services/users.d.ts.map +1 -0
- package/lib/services/users.js +2 -0
- package/lib/services/users.js.map +1 -0
- package/lib/services/videos.d.ts +101 -0
- package/lib/services/videos.d.ts.map +1 -0
- package/lib/services/videos.js +2 -0
- package/lib/services/videos.js.map +1 -0
- package/lib/services/whispers.d.ts +17 -0
- package/lib/services/whispers.d.ts.map +1 -0
- package/lib/services/whispers.js +2 -0
- package/lib/services/whispers.js.map +1 -0
- package/lib/services.lazy/ads.js +1 -0
- package/lib/services.lazy/analytics.js +1 -0
- package/lib/services.lazy/bits.js +1 -0
- package/lib/services.lazy/ccls.js +1 -0
- package/lib/services.lazy/channel_points.js +1 -0
- package/lib/services.lazy/channels.js +1 -0
- package/lib/services.lazy/charity.js +1 -0
- package/lib/services.lazy/chat.js +3 -0
- package/lib/services.lazy/clips.js +1 -0
- package/lib/services.lazy/conduits.js +1 -0
- package/lib/services.lazy/entitlements.js +1 -0
- package/lib/services.lazy/eventsub.js +1 -0
- package/lib/services.lazy/extensions.js +1 -0
- package/lib/services.lazy/games.js +1 -0
- package/lib/services.lazy/goals.js +1 -0
- package/lib/services.lazy/guest_star.js +1 -0
- package/lib/services.lazy/hype_train.js +1 -0
- package/lib/services.lazy/index.js +3 -0
- package/lib/services.lazy/moderation.js +3 -0
- package/lib/services.lazy/polls.js +1 -0
- package/lib/services.lazy/predictions.js +1 -0
- package/lib/services.lazy/raids.js +1 -0
- package/lib/services.lazy/schedule.js +1 -0
- package/lib/services.lazy/search.js +1 -0
- package/lib/services.lazy/streams.js +1 -0
- package/lib/services.lazy/subscriptions.js +1 -0
- package/lib/services.lazy/teams.js +1 -0
- package/lib/services.lazy/users.js +1 -0
- package/lib/services.lazy/videos.js +1 -0
- package/lib/services.lazy/whispers.js +1 -0
- package/lib/traits.d.ts +10 -0
- package/lib/traits.d.ts.map +1 -0
- package/lib/traits.js +1 -0
- package/package.json +82 -2
- package/src/credentials.ts +79 -0
- package/src/errors.ts +78 -0
- package/src/index.ts +45 -0
- package/src/pagination.ts +9 -0
- package/src/protocol.ts +43 -0
- package/src/retry.ts +69 -0
- package/src/services/ads.ts +228 -0
- package/src/services/analytics.ts +253 -0
- package/src/services/bits.ts +631 -0
- package/src/services/ccls.ts +96 -0
- package/src/services/channel_points.ts +804 -0
- package/src/services/channels.ts +471 -0
- package/src/services/charity.ts +250 -0
- package/src/services/chat.ts +1547 -0
- package/src/services/clips.ts +385 -0
- package/src/services/conduits.ts +453 -0
- package/src/services/entitlements.ts +219 -0
- package/src/services/eventsub.ts +372 -0
- package/src/services/extensions.ts +1098 -0
- package/src/services/games.ts +184 -0
- package/src/services/goals.ts +110 -0
- package/src/services/guest_star.ts +762 -0
- package/src/services/hype_train.ts +214 -0
- package/src/services/index.ts +30 -0
- package/src/services/moderation.ts +1817 -0
- package/src/services/polls.ts +363 -0
- package/src/services/predictions.ts +432 -0
- package/src/services/raids.ts +127 -0
- package/src/services/schedule.ts +539 -0
- package/src/services/search.ts +248 -0
- package/src/services/streams.ts +579 -0
- package/src/services/subscriptions.ts +247 -0
- package/src/services/teams.ts +225 -0
- package/src/services/users.ts +729 -0
- package/src/services/videos.ts +257 -0
- package/src/services/whispers.ts +71 -0
- package/src/traits.ts +47 -0
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export*from"../services/hype_train.js";
|
|
@@ -0,0 +1,3 @@
|
|
|
1
|
+
import{api$lazyNamespace as $N}from"@distilled.cloud/core/_bundle/base";
|
|
2
|
+
const $u=import.meta.url,ads=$N($u,"./ads.js"),analytics=$N($u,"./analytics.js"),bits=$N($u,"./bits.js"),ccls=$N($u,"./ccls.js"),channelPoints=$N($u,"./channel_points.js"),channels=$N($u,"./channels.js"),charity=$N($u,"./charity.js"),chat=$N($u,"./chat.js"),clips=$N($u,"./clips.js"),conduits=$N($u,"./conduits.js"),entitlements=$N($u,"./entitlements.js"),eventsub=$N($u,"./eventsub.js"),extensions=$N($u,"./extensions.js"),games=$N($u,"./games.js"),goals=$N($u,"./goals.js"),guestStar=$N($u,"./guest_star.js"),hypeTrain=$N($u,"./hype_train.js"),moderation=$N($u,"./moderation.js"),polls=$N($u,"./polls.js"),predictions=$N($u,"./predictions.js"),raids=$N($u,"./raids.js"),schedule=$N($u,"./schedule.js"),search=$N($u,"./search.js"),streams=$N($u,"./streams.js"),subscriptions=$N($u,"./subscriptions.js"),teams=$N($u,"./teams.js"),users=$N($u,"./users.js"),videos=$N($u,"./videos.js"),whispers=$N($u,"./whispers.js");
|
|
3
|
+
export{ads,analytics,bits,ccls,channelPoints,channels,charity,chat,clips,conduits,entitlements,eventsub,extensions,games,goals,guestStar,hypeTrain,moderation,polls,predictions,raids,schedule,search,streams,subscriptions,teams,users,videos,whispers};
|
|
@@ -0,0 +1,3 @@
|
|
|
1
|
+
import{$L}from"../_bundle/lazy.js";
|
|
2
|
+
const{o:$o,e:$e}=/*@__PURE__*/$L("../services/moderation.js","ooooooooppppoppoooooooooo",14193,2372);
|
|
3
|
+
export const addBlockedTerm=$o(),addChannelModerator=$o(),addChannelVip=$o(),addSuspiciousStatusToChatUser=$o(),banUser=$o(),checkAutomodStatus=$o(),deleteChatMessages=$o(),getAutomodSettings=$o(),getBannedUsers=$o(),getBlockedTerms=$o(),getModeratedChannels=$o(),getModerators=$o(),getShieldModeStatus=$o(),getUnbanRequests=$o(),getVips=$o(),manageHeldAutomodMessages=$o(),removeBlockedTerm=$o(),removeChannelModerator=$o(),removeChannelVip=$o(),removeSuspiciousStatusFromChatUser=$o(),resolveUnbanRequests=$o(),unbanUser=$o(),updateAutomodSettings=$o(),updateShieldModeStatus=$o(),warnChatUser=$o();
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export*from"../services/polls.js";
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export*from"../services/predictions.js";
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export*from"../services/raids.js";
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export*from"../services/schedule.js";
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export*from"../services/search.js";
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export*from"../services/streams.js";
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export*from"../services/subscriptions.js";
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export*from"../services/teams.js";
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export*from"../services/users.js";
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export*from"../services/videos.js";
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export*from"../services/whispers.js";
|
package/lib/traits.d.ts
ADDED
|
@@ -0,0 +1,10 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Twitch SDK trait surface -- hand-written.
|
|
3
|
+
*
|
|
4
|
+
* Re-exports the generic protocol traits from core so generated operations
|
|
5
|
+
* import everything from one place. Twitch speaks plain bearer-REST JSON with no
|
|
6
|
+
* success envelope, so there are no provider-specific traits.
|
|
7
|
+
*/
|
|
8
|
+
export { Body, Header, Query, Label, Http, ResponseCode, HttpBody, FormDataFile, KeyDictionary, UnionCases, applyErrorMatchers, getErrorMatchers, type HttpTrait, type ErrorMatcher, bodySymbol, headerSymbol, querySymbol, labelSymbol, httpSymbol, responseCodeSymbol, httpBodySymbol, formDataFileSymbol, keyDictionarySymbol, unionCasesSymbol, errorMatchersSymbol, } from "@distilled.cloud/core/trait";
|
|
9
|
+
export { BinaryResponse, SensitiveValue, RawResponse, RawResponseRoot, binaryResponseSymbol, sensitiveValueSymbol, rawResponseSymbol, rawResponseRootSymbol, } from "@distilled.cloud/core/protocol-rest";
|
|
10
|
+
//# sourceMappingURL=traits.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"traits.d.ts","sources":["../src/traits.ts"],"names":[],"mappings":"AAAA;;;;;;GAMG;AACH,OAAO,EACL,IAAI,EACJ,MAAM,EACN,KAAK,EACL,KAAK,EACL,IAAI,EACJ,YAAY,EACZ,QAAQ,EACR,YAAY,EACZ,aAAa,EACb,UAAU,EACV,kBAAkB,EAClB,gBAAgB,EAChB,KAAK,SAAS,EACd,KAAK,YAAY,EACjB,UAAU,EACV,YAAY,EACZ,WAAW,EACX,WAAW,EACX,UAAU,EACV,kBAAkB,EAClB,cAAc,EACd,kBAAkB,EAClB,mBAAmB,EACnB,gBAAgB,EAChB,mBAAmB,GACpB,MAAM,6BAA6B,CAAC;AAIrC,OAAO,EACL,cAAc,EACd,cAAc,EACd,WAAW,EACX,eAAe,EACf,oBAAoB,EACpB,oBAAoB,EACpB,iBAAiB,EACjB,qBAAqB,GACtB,MAAM,qCAAqC,CAAC"}
|
package/lib/traits.js
ADDED
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export { traits$BinaryResponse as BinaryResponse, traits$Body as Body, traits$FormDataFile as FormDataFile, traits$Header as Header, traits$Http as Http, traits$HttpBody as HttpBody, traits$KeyDictionary as KeyDictionary, traits$Label as Label, traits$Query as Query, traits$RawResponse as RawResponse, traits$RawResponseRoot as RawResponseRoot, traits$ResponseCode as ResponseCode, traits$SensitiveValue as SensitiveValue, traits$UnionCases as UnionCases, traits$applyErrorMatchers as applyErrorMatchers, traits$binaryResponseSymbol as binaryResponseSymbol, traits$bodySymbol as bodySymbol, traits$errorMatchersSymbol as errorMatchersSymbol, traits$formDataFileSymbol as formDataFileSymbol, traits$getErrorMatchers as getErrorMatchers, traits$headerSymbol as headerSymbol, traits$httpBodySymbol as httpBodySymbol, traits$httpSymbol as httpSymbol, traits$keyDictionarySymbol as keyDictionarySymbol, traits$labelSymbol as labelSymbol, traits$querySymbol as querySymbol, traits$rawResponseRootSymbol as rawResponseRootSymbol, traits$rawResponseSymbol as rawResponseSymbol, traits$responseCodeSymbol as responseCodeSymbol, traits$sensitiveValueSymbol as sensitiveValueSymbol, traits$unionCasesSymbol as unionCasesSymbol } from "./_bundle/sdk.js";
|
package/package.json
CHANGED
|
@@ -1,11 +1,91 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@distilled.cloud/twitch",
|
|
3
|
-
"version": "0.0.
|
|
3
|
+
"version": "1.0.0-rc.22",
|
|
4
4
|
"description": "Effect-native Twitch API (Helix) SDK generated from the official public API reference.",
|
|
5
5
|
"license": "Apache-2.0",
|
|
6
6
|
"repository": {
|
|
7
7
|
"type": "git",
|
|
8
8
|
"url": "https://github.com/alchemy-run/distilled",
|
|
9
9
|
"directory": "packages/twitch"
|
|
10
|
+
},
|
|
11
|
+
"files": [
|
|
12
|
+
"lib",
|
|
13
|
+
"src"
|
|
14
|
+
],
|
|
15
|
+
"type": "module",
|
|
16
|
+
"sideEffects": false,
|
|
17
|
+
"module": "src/index.ts",
|
|
18
|
+
"exports": {
|
|
19
|
+
".": {
|
|
20
|
+
"types": "./lib/index.d.ts",
|
|
21
|
+
"bun": "./src/index.ts",
|
|
22
|
+
"worker": "./src/index.ts",
|
|
23
|
+
"default": "./lib/index.js"
|
|
24
|
+
},
|
|
25
|
+
"./Credentials": {
|
|
26
|
+
"types": "./lib/credentials.d.ts",
|
|
27
|
+
"bun": "./src/credentials.ts",
|
|
28
|
+
"worker": "./src/credentials.ts",
|
|
29
|
+
"default": "./lib/credentials.js"
|
|
30
|
+
},
|
|
31
|
+
"./Errors": {
|
|
32
|
+
"types": "./lib/errors.d.ts",
|
|
33
|
+
"bun": "./src/errors.ts",
|
|
34
|
+
"worker": "./src/errors.ts",
|
|
35
|
+
"default": "./lib/errors.js"
|
|
36
|
+
},
|
|
37
|
+
"./Traits": {
|
|
38
|
+
"types": "./lib/traits.d.ts",
|
|
39
|
+
"bun": "./src/traits.ts",
|
|
40
|
+
"worker": "./src/traits.ts",
|
|
41
|
+
"default": "./lib/traits.js"
|
|
42
|
+
},
|
|
43
|
+
"./Protocol": {
|
|
44
|
+
"types": "./lib/protocol.d.ts",
|
|
45
|
+
"bun": "./src/protocol.ts",
|
|
46
|
+
"worker": "./src/protocol.ts",
|
|
47
|
+
"default": "./lib/protocol.js"
|
|
48
|
+
},
|
|
49
|
+
"./Retry": {
|
|
50
|
+
"types": "./lib/retry.d.ts",
|
|
51
|
+
"bun": "./src/retry.ts",
|
|
52
|
+
"worker": "./src/retry.ts",
|
|
53
|
+
"default": "./lib/retry.js"
|
|
54
|
+
},
|
|
55
|
+
"./Pagination": {
|
|
56
|
+
"types": "./lib/pagination.d.ts",
|
|
57
|
+
"bun": "./src/pagination.ts",
|
|
58
|
+
"worker": "./src/pagination.ts",
|
|
59
|
+
"default": "./lib/pagination.js"
|
|
60
|
+
},
|
|
61
|
+
"./*": {
|
|
62
|
+
"types": "./lib/services/*.d.ts",
|
|
63
|
+
"bun": "./src/services/*.ts",
|
|
64
|
+
"worker": "./src/services/*.ts",
|
|
65
|
+
"distilled-lazy": "./lib/services.lazy/*.js",
|
|
66
|
+
"default": "./lib/services/*.js"
|
|
67
|
+
}
|
|
68
|
+
},
|
|
69
|
+
"dependencies": {
|
|
70
|
+
"@distilled.cloud/core": "1.0.0-rc.22"
|
|
71
|
+
},
|
|
72
|
+
"devDependencies": {
|
|
73
|
+
"@distilled.cloud/dev": "0.0.0",
|
|
74
|
+
"@types/node": "26.6.5"
|
|
75
|
+
},
|
|
76
|
+
"peerDependencies": {
|
|
77
|
+
"effect": "~4.1.7"
|
|
78
|
+
},
|
|
79
|
+
"distilled": {
|
|
80
|
+
"generatedAt": "2026-11-27",
|
|
81
|
+
"specUpdatedAt": "2026-11-25"
|
|
82
|
+
},
|
|
83
|
+
"scripts": {
|
|
84
|
+
"build": "tsrs -b",
|
|
85
|
+
"convert": "node --conditions=bun scripts/convert.ts",
|
|
86
|
+
"generate": "node --conditions=bun scripts/generate.ts",
|
|
87
|
+
"typecheck": "tsrs -p tsconfig.json",
|
|
88
|
+
"specs:fetch": "git submodule update --force --init --depth=1 specs/spec-mirror-twitch",
|
|
89
|
+
"specs:update": "git submodule update --remote --force --depth=1 specs/spec-mirror-twitch"
|
|
10
90
|
}
|
|
11
|
-
}
|
|
91
|
+
}
|
|
@@ -0,0 +1,79 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Twitch credentials -- hand-written.
|
|
3
|
+
*
|
|
4
|
+
* The `Credentials` service resolves `{ accessToken, clientId, apiBaseUrl }` per
|
|
5
|
+
* request; the protocol sends them as `Authorization: Bearer <accessToken>` and
|
|
6
|
+
* `Client-Id: <clientId>`. Every Helix call needs both headers, and the client
|
|
7
|
+
* ID must be the one the token was issued to
|
|
8
|
+
* (https://dev.twitch.tv/docs/api/get-started/).
|
|
9
|
+
*
|
|
10
|
+
* The token is a user access token or an app access token
|
|
11
|
+
* (https://dev.twitch.tv/docs/authentication/#access-tokens); each operation's
|
|
12
|
+
* documentation lists which it accepts and the scopes it needs. Getting and
|
|
13
|
+
* refreshing a token is up to the caller.
|
|
14
|
+
*/
|
|
15
|
+
import * as EffectConfig from "@distilled.cloud/core/config";
|
|
16
|
+
import { ConfigError } from "@distilled.cloud/core/errors";
|
|
17
|
+
import * as Context from "effect/Context";
|
|
18
|
+
import * as Effect from "effect/Effect";
|
|
19
|
+
import * as Layer from "effect/Layer";
|
|
20
|
+
import type * as Redacted from "effect/Redacted";
|
|
21
|
+
|
|
22
|
+
/** The Helix API host. */
|
|
23
|
+
export const DEFAULT_API_BASE_URL = "https://api.twitch.tv/helix";
|
|
24
|
+
|
|
25
|
+
export interface Config {
|
|
26
|
+
readonly accessToken: Redacted.Redacted<string>;
|
|
27
|
+
/** The client ID of the app the token belongs to. */
|
|
28
|
+
readonly clientId: string;
|
|
29
|
+
readonly apiBaseUrl: string;
|
|
30
|
+
}
|
|
31
|
+
|
|
32
|
+
export class Credentials
|
|
33
|
+
extends /*@__PURE__*/ Context.Service<Credentials, Effect.Effect<Config>>()(
|
|
34
|
+
"TwitchCredentials",
|
|
35
|
+
) {}
|
|
36
|
+
|
|
37
|
+
const envConfig = /*@__PURE__*/ EffectConfig.all({
|
|
38
|
+
accessToken: /*@__PURE__*/ EffectConfig.Redacted("TWITCH_ACCESS_TOKEN"),
|
|
39
|
+
clientId: /*@__PURE__*/ EffectConfig.String("TWITCH_CLIENT_ID"),
|
|
40
|
+
apiBaseUrl: /*@__PURE__*/ EffectConfig.String("TWITCH_API_BASE_URL").pipe(
|
|
41
|
+
/*@__PURE__*/ EffectConfig.withDefault(DEFAULT_API_BASE_URL),
|
|
42
|
+
),
|
|
43
|
+
});
|
|
44
|
+
|
|
45
|
+
/**
|
|
46
|
+
* Reads `TWITCH_ACCESS_TOKEN`, `TWITCH_CLIENT_ID` and, optionally, `TWITCH_API_BASE_URL`.
|
|
47
|
+
*
|
|
48
|
+
* Its configuration is read and checked once, when the layer is built: a
|
|
49
|
+
* problem there fails the layer with `ConfigError`.
|
|
50
|
+
*/
|
|
51
|
+
export const CredentialsFromEnv = /*@__PURE__*/ Layer.effect(
|
|
52
|
+
Credentials,
|
|
53
|
+
/*@__PURE__*/ Effect.map(
|
|
54
|
+
/*@__PURE__*/ envConfig.pipe(
|
|
55
|
+
/*@__PURE__*/ Effect.mapError(
|
|
56
|
+
() =>
|
|
57
|
+
new ConfigError({
|
|
58
|
+
message: "TWITCH_ACCESS_TOKEN and TWITCH_CLIENT_ID environment variables are required",
|
|
59
|
+
}),
|
|
60
|
+
),
|
|
61
|
+
),
|
|
62
|
+
(config) => Effect.succeed(config),
|
|
63
|
+
),
|
|
64
|
+
);
|
|
65
|
+
|
|
66
|
+
/** Credentials from a redacted access token and its app's client ID. */
|
|
67
|
+
export const credentials = (config: {
|
|
68
|
+
readonly accessToken: Redacted.Redacted<string>;
|
|
69
|
+
readonly clientId: string;
|
|
70
|
+
readonly apiBaseUrl?: string;
|
|
71
|
+
}): Layer.Layer<Credentials> =>
|
|
72
|
+
Layer.succeed(
|
|
73
|
+
Credentials,
|
|
74
|
+
Effect.succeed({
|
|
75
|
+
accessToken: config.accessToken,
|
|
76
|
+
clientId: config.clientId,
|
|
77
|
+
apiBaseUrl: config.apiBaseUrl ?? DEFAULT_API_BASE_URL,
|
|
78
|
+
}),
|
|
79
|
+
);
|
package/src/errors.ts
ADDED
|
@@ -0,0 +1,78 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Twitch error types.
|
|
3
|
+
*
|
|
4
|
+
* Helix answers a failure with `{ "error": "<status text>", "status": <code>,
|
|
5
|
+
* "message": "<why>" }`, and its reference documents failures per operation
|
|
6
|
+
* only as status lists (`400`, `401`, `403`, `404`, `409`, `422`, `425`,
|
|
7
|
+
* `429`, `5xx`). The SDK dispatches on the status with core's shared classes;
|
|
8
|
+
* a status nothing maps (`425 Too Early`, for one) comes back as
|
|
9
|
+
* {@link UnknownTwitchError} with the body.
|
|
10
|
+
*/
|
|
11
|
+
export {
|
|
12
|
+
BadGateway,
|
|
13
|
+
BadRequest,
|
|
14
|
+
Conflict,
|
|
15
|
+
ConfigError,
|
|
16
|
+
Forbidden,
|
|
17
|
+
GatewayTimeout,
|
|
18
|
+
InternalServerError,
|
|
19
|
+
Locked,
|
|
20
|
+
NotFound,
|
|
21
|
+
ServiceUnavailable,
|
|
22
|
+
TooManyRequests,
|
|
23
|
+
Unauthorized,
|
|
24
|
+
UnprocessableEntity,
|
|
25
|
+
HTTP_STATUS_MAP,
|
|
26
|
+
DEFAULT_ERRORS,
|
|
27
|
+
API_ERRORS,
|
|
28
|
+
} from "@distilled.cloud/core/errors";
|
|
29
|
+
import * as Category from "@distilled.cloud/core/category";
|
|
30
|
+
import type {
|
|
31
|
+
BadRequest as CoreBadRequest,
|
|
32
|
+
Conflict as CoreConflict,
|
|
33
|
+
DefaultErrors as CoreDefaultErrors,
|
|
34
|
+
Forbidden as CoreForbidden,
|
|
35
|
+
NotFound as CoreNotFound,
|
|
36
|
+
UnprocessableEntity as CoreUnprocessableEntity,
|
|
37
|
+
} from "@distilled.cloud/core/errors";
|
|
38
|
+
import { API_ERRORS, UnknownErrorFields } from "@distilled.cloud/core/errors";
|
|
39
|
+
import * as Schema from "@distilled.cloud/core/schema-lite-typed";
|
|
40
|
+
|
|
41
|
+
/** Unknown Twitch error -- a failed response whose status has no mapped class. */
|
|
42
|
+
export class UnknownTwitchError
|
|
43
|
+
extends /*@__PURE__*/ Schema.TaggedError<UnknownTwitchError>()(
|
|
44
|
+
"UnknownTwitchError",
|
|
45
|
+
UnknownErrorFields,
|
|
46
|
+
) {}
|
|
47
|
+
|
|
48
|
+
/** A 2xx body that did not match the operation's output (validating modes only). */
|
|
49
|
+
export class TwitchParseError
|
|
50
|
+
extends /*@__PURE__*/ Schema.TaggedError<TwitchParseError>()("TwitchParseError", {
|
|
51
|
+
body: Schema.Unknown,
|
|
52
|
+
cause: Schema.Unknown,
|
|
53
|
+
}).pipe(Category.withParseError) {}
|
|
54
|
+
|
|
55
|
+
/** Errors any Twitch operation may surface besides the shared HTTP status errors. */
|
|
56
|
+
export type ClientErrors = UnknownTwitchError | TwitchParseError;
|
|
57
|
+
|
|
58
|
+
/**
|
|
59
|
+
* Default Twitch operation errors. Every operation carries the whole set: the
|
|
60
|
+
* reference's status lists are documentation, and any of these statuses can
|
|
61
|
+
* come back from any call.
|
|
62
|
+
*/
|
|
63
|
+
export type DefaultErrors =
|
|
64
|
+
| CoreDefaultErrors
|
|
65
|
+
| CoreBadRequest
|
|
66
|
+
| CoreForbidden
|
|
67
|
+
| CoreNotFound
|
|
68
|
+
| CoreConflict
|
|
69
|
+
| CoreUnprocessableEntity
|
|
70
|
+
| ClientErrors;
|
|
71
|
+
|
|
72
|
+
/**
|
|
73
|
+
* The errors declared on the Twitch service: any operation can return them,
|
|
74
|
+
* and every generated operation lists them as its `serviceErrors`. Today that
|
|
75
|
+
* is each of core's status classes (401, 403, 404, 429, the 5xx ...).
|
|
76
|
+
*/
|
|
77
|
+
export const TwitchServiceErrors = API_ERRORS;
|
|
78
|
+
export type TwitchServiceError = InstanceType<(typeof TwitchServiceErrors)[number]>;
|
package/src/index.ts
ADDED
|
@@ -0,0 +1,45 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* @distilled.cloud/twitch -- Twitch API (Helix) SDK for Effect.
|
|
3
|
+
*
|
|
4
|
+
* `./services` is generated by `scripts/generate.ts` from the Smithy models
|
|
5
|
+
* that `scripts/convert.ts` reads out of Twitch's API reference, mirrored as
|
|
6
|
+
* Markdown under `specs/spec-mirror-twitch/specs/api/reference`. Everything
|
|
7
|
+
* else in this folder is hand-written.
|
|
8
|
+
*
|
|
9
|
+
* One module per reference page: `ads`, `analytics`, `bits`, `ccls`,
|
|
10
|
+
* `channel_points`, `channels`, `charity`, `chat`, `clips`, `conduits`,
|
|
11
|
+
* `entitlements`, `eventsub`, `extensions`, `games`, `goals`, `guest_star`,
|
|
12
|
+
* `hype_train`, `moderation`, `polls`, `predictions`, `raids`, `schedule`,
|
|
13
|
+
* `search`, `streams`, `subscriptions`, `teams`, `users`, `videos` and
|
|
14
|
+
* `whispers`. Import each from its subpath.
|
|
15
|
+
*
|
|
16
|
+
* @example
|
|
17
|
+
* ```ts
|
|
18
|
+
* import { Effect, Layer } from "effect";
|
|
19
|
+
* import * as FetchHttpClient from "effect/http/FetchHttpClient";
|
|
20
|
+
* import * as Twitch from "@distilled.cloud/twitch";
|
|
21
|
+
* import * as Channels from "@distilled.cloud/twitch/channels";
|
|
22
|
+
* import * as Users from "@distilled.cloud/twitch/users";
|
|
23
|
+
*
|
|
24
|
+
* const program = Effect.gen(function* () {
|
|
25
|
+
* const { data: users = [] } = yield* Users.getUsers({ login: ["twitchdev"] });
|
|
26
|
+
* const { data: channels = [] } = yield* Channels.getChannelInformation({
|
|
27
|
+
* broadcaster_id: users.map((user) => user.id!),
|
|
28
|
+
* });
|
|
29
|
+
* return channels.map((channel) => ({ name: channel.broadcaster_name, game: channel.game_name }));
|
|
30
|
+
* });
|
|
31
|
+
*
|
|
32
|
+
* const Live = Layer.mergeAll(
|
|
33
|
+
* FetchHttpClient.layer,
|
|
34
|
+
* Twitch.CredentialsFromEnv,
|
|
35
|
+
* );
|
|
36
|
+
*
|
|
37
|
+
* program.pipe(Effect.provide(Live), Effect.runPromise).then(console.log);
|
|
38
|
+
* ```
|
|
39
|
+
*/
|
|
40
|
+
export * from "./credentials.ts";
|
|
41
|
+
export * from "./errors.ts";
|
|
42
|
+
export * as T from "./traits.ts";
|
|
43
|
+
export { TwitchProtocol, type TwitchOpError, type TwitchOpContext } from "./protocol.ts";
|
|
44
|
+
export * as Retry from "./retry.ts";
|
|
45
|
+
export { paginateCursor } from "./pagination.ts";
|
|
@@ -0,0 +1,9 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Twitch pagination -- hand-written.
|
|
3
|
+
*
|
|
4
|
+
* Helix pages by cursor: the `after` query parameter in, the next cursor in
|
|
5
|
+
* the response's `pagination.cursor` (on a few endpoints, a bare `pagination`
|
|
6
|
+
* string), absent or empty on the last page. Generated operations pass core's
|
|
7
|
+
* cursor strategy to `API.makePaginated`.
|
|
8
|
+
*/
|
|
9
|
+
export { paginateCursor } from "@distilled.cloud/core/pagination";
|
package/src/protocol.ts
ADDED
|
@@ -0,0 +1,43 @@
|
|
|
1
|
+
import type { ErrorOf } from "@distilled.cloud/core/protocol";
|
|
2
|
+
import { restProtocol, unknownErrorProps } from "@distilled.cloud/core/protocol-rest";
|
|
3
|
+
/**
|
|
4
|
+
* TwitchProtocol -- the shared bearer-REST protocol instantiated for Helix.
|
|
5
|
+
*
|
|
6
|
+
* Helix speaks plain JSON with no success envelope. Every call carries the
|
|
7
|
+
* access token as `Authorization: Bearer` and the app's `Client-Id`. A failure
|
|
8
|
+
* is `{ "error": "Bad Request", "status": 400, "message": "<why>" }`, which the
|
|
9
|
+
* factory's default extractor reads (`message` first).
|
|
10
|
+
*/
|
|
11
|
+
import * as Effect from "effect/Effect";
|
|
12
|
+
import type * as HttpClient from "effect/http/HttpClient";
|
|
13
|
+
import * as Redacted from "effect/Redacted";
|
|
14
|
+
import { Credentials } from "./credentials.ts";
|
|
15
|
+
import { TwitchParseError, UnknownTwitchError, type TwitchServiceError } from "./errors.ts";
|
|
16
|
+
|
|
17
|
+
/**
|
|
18
|
+
* What every generated Twitch operation fails with besides its own errors: the
|
|
19
|
+
* errors declared on the service, and the errors declared on the protocol.
|
|
20
|
+
* Nobody lists the protocol's: its type carries what its code fails with (a
|
|
21
|
+
* response that does not match its schema, a failed response nothing declares,
|
|
22
|
+
* core's REST errors, and what resolving the credentials fails with).
|
|
23
|
+
* Generated service files annotate operations with `API.OperationMethod<I, O,
|
|
24
|
+
* TwitchOpError, TwitchOpContext>` explicitly so the compiler never infers
|
|
25
|
+
* these back out of the schema generics.
|
|
26
|
+
*/
|
|
27
|
+
export type TwitchOpError = TwitchServiceError | ErrorOf<typeof TwitchProtocol>;
|
|
28
|
+
|
|
29
|
+
/** Context (requirements) shared by every generated Twitch operation. */
|
|
30
|
+
export type TwitchOpContext = Credentials | HttpClient.HttpClient;
|
|
31
|
+
|
|
32
|
+
export const TwitchProtocol = /*@__PURE__*/ restProtocol({
|
|
33
|
+
// Resolved on the calling fiber per request, so a refreshed token is
|
|
34
|
+
// picked up without rebuilding the layer.
|
|
35
|
+
credentials: /*@__PURE__*/ Effect.flatten(Credentials),
|
|
36
|
+
baseUrl: (creds) => creds.apiBaseUrl.replace(/\/+$/, ""),
|
|
37
|
+
headers: (creds) => ({
|
|
38
|
+
Authorization: `Bearer ${Redacted.value(creds.accessToken)}`,
|
|
39
|
+
"Client-Id": creds.clientId,
|
|
40
|
+
}),
|
|
41
|
+
unknownError: (info) => new UnknownTwitchError(unknownErrorProps(info)),
|
|
42
|
+
parseError: ({ body, cause }) => new TwitchParseError({ body, cause }),
|
|
43
|
+
});
|
package/src/retry.ts
ADDED
|
@@ -0,0 +1,69 @@
|
|
|
1
|
+
import * as Retries from "@distilled.cloud/core/retry";
|
|
2
|
+
/**
|
|
3
|
+
* Twitch retry surface -- a veneer over `@distilled.cloud/core/retry`.
|
|
4
|
+
*
|
|
5
|
+
* The `Retry` service tag is threaded into every generated operation via
|
|
6
|
+
* `API.make({ retry: Retry })`, so a caller-installed policy applies to all
|
|
7
|
+
* Twitch calls below it and core's `makeDefault` is the fallback when none is
|
|
8
|
+
* provided.
|
|
9
|
+
*
|
|
10
|
+
* @example
|
|
11
|
+
* ```ts
|
|
12
|
+
* import * as Twitch from "@distilled.cloud/twitch";
|
|
13
|
+
*
|
|
14
|
+
* myEffect.pipe(Twitch.Retry.transient);
|
|
15
|
+
* ```
|
|
16
|
+
*/
|
|
17
|
+
import * as Context from "effect/Context";
|
|
18
|
+
import * as Effect from "effect/Effect";
|
|
19
|
+
import * as Layer from "effect/Layer";
|
|
20
|
+
|
|
21
|
+
export type Options = Retries.Options;
|
|
22
|
+
export type Factory = Retries.Factory;
|
|
23
|
+
export type Policy = Retries.Policy;
|
|
24
|
+
|
|
25
|
+
/** Context tag for configuring retry behavior of Twitch API calls. */
|
|
26
|
+
export class Retry extends /*@__PURE__*/ Context.Service<Retry, Policy>()("TwitchRetry") {}
|
|
27
|
+
|
|
28
|
+
/** Provides a custom retry policy to every Twitch API call below it. */
|
|
29
|
+
export const policy: {
|
|
30
|
+
(
|
|
31
|
+
options: Options,
|
|
32
|
+
): <A, E, R>(effect: Effect.Effect<A, E, R>) => Effect.Effect<A, E, Exclude<R, Retry>>;
|
|
33
|
+
(
|
|
34
|
+
factory: Factory,
|
|
35
|
+
): <A, E, R>(effect: Effect.Effect<A, E, R>) => Effect.Effect<A, E, Exclude<R, Retry>>;
|
|
36
|
+
} = (optionsOrFactory: Options | Factory) => Effect.provide(Layer.succeed(Retry, optionsOrFactory));
|
|
37
|
+
|
|
38
|
+
/** Disables all automatic retries. */
|
|
39
|
+
export const none: <A, E, R>(
|
|
40
|
+
effect: Effect.Effect<A, E, R>,
|
|
41
|
+
) => Effect.Effect<A, E, Exclude<R, Retry>> = /*@__PURE__*/ Effect.provide(
|
|
42
|
+
/*@__PURE__*/ Layer.succeed(Retry, { while: () => false }),
|
|
43
|
+
);
|
|
44
|
+
|
|
45
|
+
/**
|
|
46
|
+
* The default retry policy (core's): transient/throttling/retryable errors,
|
|
47
|
+
* capped exponential backoff with jitter, server `retryAfter` hints honored
|
|
48
|
+
* with precedence.
|
|
49
|
+
*/
|
|
50
|
+
export const makeDefault: Factory = Retries.makeDefault;
|
|
51
|
+
|
|
52
|
+
export const jittered = Retries.jittered;
|
|
53
|
+
export const capped = Retries.capped;
|
|
54
|
+
|
|
55
|
+
/** Retry options that retry all throttling errors indefinitely. */
|
|
56
|
+
export const throttlingOptions: Options = Retries.throttlingOptions;
|
|
57
|
+
|
|
58
|
+
/** Retries all throttling errors indefinitely (honoring server hints). */
|
|
59
|
+
export const throttling: <A, E, R>(
|
|
60
|
+
effect: Effect.Effect<A, E, R>,
|
|
61
|
+
) => Effect.Effect<A, E, Exclude<R, Retry>> = /*@__PURE__*/ policy(Retries.throttlingFactory);
|
|
62
|
+
|
|
63
|
+
/** Retry options that retry all transient errors indefinitely. */
|
|
64
|
+
export const transientOptions: Options = Retries.transientOptions;
|
|
65
|
+
|
|
66
|
+
/** Retries all transient errors indefinitely. */
|
|
67
|
+
export const transient: <A, E, R>(
|
|
68
|
+
effect: Effect.Effect<A, E, R>,
|
|
69
|
+
) => Effect.Effect<A, E, Exclude<R, Retry>> = /*@__PURE__*/ policy(Retries.transientFactory);
|