Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
35 changes: 12 additions & 23 deletions src/lib/seam/connect/auth.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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<string, string>

Expand Down Expand Up @@ -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)
7 changes: 7 additions & 0 deletions src/lib/seam/connect/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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'
35 changes: 35 additions & 0 deletions src/lib/seam/connect/token.ts
Original file line number Diff line number Diff line change
@@ -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)