Skip to content

Commit

Permalink
move InvalidTokenTypeError to twitch-auth and use it more
Browse files Browse the repository at this point in the history
  • Loading branch information
d-fischer committed Dec 6, 2020
1 parent 8c1442a commit 5caccae
Show file tree
Hide file tree
Showing 6 changed files with 7 additions and 6 deletions.
1 change: 1 addition & 0 deletions packages/twitch-auth/src/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,7 @@ export type { RefreshConfig } from './AuthProvider/RefreshableAuthProvider';
export { StaticAuthProvider } from './AuthProvider/StaticAuthProvider';

export { InvalidTokenError } from './Errors/InvalidTokenError';
export { InvalidTokenTypeError } from './Errors/InvalidTokenTypeError';

// twitch-auth@^1 compat
export { getAppAccessToken, getUserAccessToken, refreshUserAccessToken } from './legacy';
Expand Down
3 changes: 1 addition & 2 deletions packages/twitch-chat-client/src/ChatClient.ts
Original file line number Diff line number Diff line change
Expand Up @@ -6,9 +6,8 @@ import { delay, Enumerable } from '@d-fischer/shared-utils';
import type { Listener } from '@d-fischer/typed-event-emitter';
import { IrcClient, MessageTypes } from 'ircv3';
import type { CommercialLength } from 'twitch';
import { InvalidTokenError, InvalidTokenTypeError } from 'twitch';
import { getTokenInfo, InvalidTokenError, InvalidTokenTypeError } from 'twitch-auth';
import type { AuthProvider, AccessToken } from 'twitch-auth';
import { getTokenInfo } from 'twitch-auth';
import { TwitchCommandsCapability } from './Capabilities/TwitchCommandsCapability';
import { ClearChat } from './Capabilities/TwitchCommandsCapability/MessageTypes/ClearChat';
import { HostTarget } from './Capabilities/TwitchCommandsCapability/MessageTypes/HostTarget';
Expand Down
3 changes: 2 additions & 1 deletion packages/twitch-eventsub/src/EventSubListener.ts
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@ import type { Request, RequestHandler } from 'httpanda';
import { Server } from 'httpanda';
import type { ApiClient, HelixEventSubSubscription, UserIdResolvable } from 'twitch';
import { extractUserId } from 'twitch';
import { InvalidTokenTypeError } from 'twitch-auth';
import type { ConnectionAdapter } from './Adapters/ConnectionAdapter';
import type { ConnectCompatibleApp } from './ConnectCompatibleApp';
import type { EventSubStreamOfflineEvent } from './Events/EventSubStreamOfflineEvent';
Expand Down Expand Up @@ -64,7 +65,7 @@ export class EventSubListener {
*/
constructor(apiClient: ApiClient, adapter: ConnectionAdapter, secret: string, config: EventSubConfig = {}) {
if (apiClient.tokenType !== 'app') {
throw new Error(
throw new InvalidTokenTypeError(
'EventSub requires app access tokens to work; please use the ClientCredentialsAuthProvider in your API client.'
);
}
Expand Down
4 changes: 2 additions & 2 deletions packages/twitch-pubsub-client/src/PubSubClient.ts
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
import { Enumerable } from '@d-fischer/shared-utils';
import type { ApiClient, UserIdResolvable } from 'twitch';
import { extractUserId } from 'twitch';
import { getValidTokenFromProvider } from 'twitch-auth';
import { getValidTokenFromProvider, InvalidTokenTypeError } from 'twitch-auth';
import { BasicPubSubClient } from './BasicPubSubClient';
import type { PubSubBitsBadgeUnlockMessage } from './Messages/PubSubBitsBadgeUnlockMessage';
import type { PubSubBitsMessage } from './Messages/PubSubBitsMessage';
Expand Down Expand Up @@ -46,7 +46,7 @@ export class PubSubClient {
userId = extractUserId(user);
} else {
if (apiClient.tokenType === 'app') {
throw new Error(
throw new InvalidTokenTypeError(
'App tokens are not supported by PubSubClient; you need to pass authentication representing a user.'
);
}
Expand Down
2 changes: 1 addition & 1 deletion packages/twitch/src/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -132,7 +132,6 @@ export type { CheermoteDisplayInfo } from './API/Shared/BaseCheermoteList';

export { ConfigError } from './Errors/ConfigError';
export { HellFreezesOverError } from './Errors/HellFreezesOverError';
export { InvalidTokenTypeError } from './Errors/InvalidTokenTypeError';
export { NoSubscriptionProgramError } from './Errors/NoSubscriptionProgramError';
export { StreamNotLiveError } from './Errors/StreamNotLiveError';

Expand All @@ -154,6 +153,7 @@ export type { TwitchApiCallOptions as TwitchAPICallOptions } from 'twitch-api-ca
export {
AccessToken,
InvalidTokenError,
InvalidTokenTypeError,
StaticAuthProvider,
ClientCredentialsAuthProvider,
RefreshableAuthProvider,
Expand Down

0 comments on commit 5caccae

Please sign in to comment.