diff --git a/src/lib/seam/connect/auth.ts b/src/lib/seam/connect/auth.ts index 38065f39..9486d839 100644 --- a/src/lib/seam/connect/auth.ts +++ b/src/lib/seam/connect/auth.ts @@ -14,6 +14,18 @@ import { type SeamHttpOptionsWithPersonalAccessToken, } from './options.js' import type { Options } from './parse-options.js' +import { + accessTokenPrefix, + clientSessionTokenPrefix, + isAccessToken, + isClientSessionToken, + isJwt, + isPublishableKey, + isSeamToken, + jwtPrefix, + publishableKeyTokenPrefix, + tokenPrefix, +} from './token.js' type Headers = Record @@ -256,29 +268,6 @@ export const warnOnInsecureuserIdentifierKey = ( } } -const tokenPrefix = 'seam_' - -const accessTokenPrefix = 'seam_at' - -const jwtPrefix = 'ey' - -const clientSessionTokenPrefix = 'seam_cst' - -const publishableKeyTokenPrefix = 'seam_pk' - -const isClientSessionToken = (token: string): boolean => - token.startsWith(clientSessionTokenPrefix) - -const isAccessToken = (token: string): boolean => - token.startsWith(accessTokenPrefix) - -const isJwt = (token: string): boolean => token.startsWith(jwtPrefix) - -const isSeamToken = (token: string): boolean => token.startsWith(tokenPrefix) - -const isPublishableKey = (token: string): boolean => - token.startsWith(publishableKeyTokenPrefix) - // SOURCE: https://stackoverflow.com/a/46181 const isEmail = (value: string): boolean => /^[^\s@]+@[^\s@]+\.[^\s@]+$/.test(value) diff --git a/src/lib/seam/connect/index.ts b/src/lib/seam/connect/index.ts index ab0f238c..0d3c2c24 100644 --- a/src/lib/seam/connect/index.ts +++ b/src/lib/seam/connect/index.ts @@ -14,4 +14,11 @@ export * from './routes/index.js' export * from './seam-http.js' export * from './seam-http-error.js' export * from './seam-http-multi-workspace.js' +export { + isApiKey, + isClientSessionToken, + isConsoleSessionToken, + isPersonalAccessToken, + isPublishableKey, +} from './token.js' export * from 'lib/params-serializer.js' diff --git a/src/lib/seam/connect/token.ts b/src/lib/seam/connect/token.ts new file mode 100644 index 00000000..313ce97e --- /dev/null +++ b/src/lib/seam/connect/token.ts @@ -0,0 +1,35 @@ +export const tokenPrefix = 'seam_' + +export const accessTokenPrefix = 'seam_at' + +export const jwtPrefix = 'ey' + +export const clientSessionTokenPrefix = 'seam_cst' + +export const publishableKeyTokenPrefix = 'seam_pk' + +export const isAccessToken = (token: string): boolean => + token.startsWith(accessTokenPrefix) + +export const isJwt = (token: string): boolean => token.startsWith(jwtPrefix) + +export const isSeamToken = (token: string): boolean => + token.startsWith(tokenPrefix) + +export const isApiKey = (token: string): boolean => + !isClientSessionToken(token) && + !isJwt(token) && + !isAccessToken(token) && + !isPublishableKey(token) && + isSeamToken(token) + +export const isClientSessionToken = (token: string): boolean => + token.startsWith(clientSessionTokenPrefix) + +export const isPublishableKey = (token: string): boolean => + token.startsWith(publishableKeyTokenPrefix) + +export const isConsoleSessionToken = (token: string): boolean => isJwt(token) + +export const isPersonalAccessToken = (token: string): boolean => + isAccessToken(token)