From 07e3e2f3662f999f41799b39ef3dff186ce22d12 Mon Sep 17 00:00:00 2001 From: Jacob Mischka Date: Wed, 20 Sep 2023 11:06:33 -0500 Subject: [PATCH] Require endpoint and apiKey properties in SDK constructor Closes T-1149 --- src/classes/IntervalClient.ts | 9 ++------- src/examples/basic/ghostHost.ts | 15 --------------- src/examples/basic/index.ts | 1 - src/index.ts | 9 +++------ 4 files changed, 5 insertions(+), 29 deletions(-) delete mode 100644 src/examples/basic/ghostHost.ts diff --git a/src/classes/IntervalClient.ts b/src/classes/IntervalClient.ts index 0993716..691a80c 100644 --- a/src/classes/IntervalClient.ts +++ b/src/classes/IntervalClient.ts @@ -82,8 +82,6 @@ initAsyncLocalStorage() export { actionLocalStorage, pageLocalStorage } -export const DEFAULT_WEBSOCKET_ENDPOINT = 'wss://interval.com/websocket' - export function getHttpEndpoint(wsEndpoint: string) { const url = new URL(wsEndpoint) url.protocol = url.protocol.replace('ws', 'http') @@ -103,7 +101,7 @@ interface SetupConfig { export default class IntervalClient { #interval: Interval #apiKey: string | undefined - #endpoint: string = DEFAULT_WEBSOCKET_ENDPOINT + #endpoint: string #httpEndpoint: string #logger: Logger #completeHttpRequestDelayMs: number = 3000 @@ -140,10 +138,7 @@ export default class IntervalClient { this.#apiKey = config.apiKey this.#logger = new Logger(config.logLevel) this.#config = config - - if (config.endpoint) { - this.#endpoint = config.endpoint - } + this.#endpoint = config.endpoint if (config.retryIntervalMs && config.retryIntervalMs > 0) { this.#retryIntervalMs = config.retryIntervalMs diff --git a/src/examples/basic/ghostHost.ts b/src/examples/basic/ghostHost.ts deleted file mode 100644 index f6fb9b2..0000000 --- a/src/examples/basic/ghostHost.ts +++ /dev/null @@ -1,15 +0,0 @@ -import Interval from '../..' - -const anon = new Interval({ - endpoint: 'ws://localhost:3000/websocket', - routes: { - hello_world: async (io, ctx) => { - const name = await io.input.text('Your name').optional() - return { - greeting: `Hello, ${name || ctx.user.firstName || ctx.user.email}`, - } - }, - }, -}).listen() - -export default anon diff --git a/src/examples/basic/index.ts b/src/examples/basic/index.ts index 2f67440..6a7d7a9 100644 --- a/src/examples/basic/index.ts +++ b/src/examples/basic/index.ts @@ -16,7 +16,6 @@ import type { EventualMetaItem } from '../../components/displayMetadata' import * as table_actions from './table' import * as grid_actions from './grid' import unauthorized from './unauthorized' -import './ghostHost' import { generateS3Urls } from '../utils/upload' import fs from 'fs' import fakeUsers from '../utils/fakeUsers' diff --git a/src/index.ts b/src/index.ts index d036ceb..b1e18da 100644 --- a/src/index.ts +++ b/src/index.ts @@ -31,7 +31,6 @@ import type { } from './types' import IntervalError from './classes/IntervalError' import IntervalClient, { - DEFAULT_WEBSOCKET_ENDPOINT, getHttpEndpoint, actionLocalStorage, pageLocalStorage, @@ -51,14 +50,14 @@ export type { } export interface InternalConfig { - apiKey?: string + apiKey: string + endpoint: string routes?: IntervalRouteDefinitions routesDirectory?: string // TODO: Mark as deprecated soon, remove soon afterward actions?: Record // TODO: Mark as deprecated soon, remove soon afterward groups?: Record - endpoint?: string logLevel?: LogLevel retryIntervalMs?: number retryChunkIntervalMs?: number @@ -176,9 +175,7 @@ export default class Interval { this.#apiKey = config.apiKey this.#logger = new Logger(config.logLevel) - this.#httpEndpoint = getHttpEndpoint( - config.endpoint ?? DEFAULT_WEBSOCKET_ENDPOINT - ) + this.#httpEndpoint = getHttpEndpoint(config.endpoint) this.routes = new Routes( this,