Skip to content

WEB SDK API Reference

This page documents the public exports from @slaunchx/web-sdk as defined by src/index.ts.

Secure Channel

SecureChannel

ItemSignatureDescription
Constructornew SecureChannel(baseUrl: string, portalAccessCode: string)Create a Secure Channel client bound to an SC base URL and portal access code.
MethodinitSession(): Promise<void>Fetch the RSA public key, create AES request/response keys, and establish a session.
Methodencrypt(data: unknown): Promise<string>JSON-serialize and encrypt a request payload into an SCv2 envelope string.
Methoddecrypt(envelope: string): Promise<unknown>Decrypt an SCv2 response envelope and parse the JSON payload.
MethodisSessionActive(): booleanReturn true when a session exists and has not expired.
MethodgetSessionId(): string | nullReturn the active session id, or null if none exists.

RsaPublicKeyInfo

FieldTypeDescription
keyIdstringBackend key identifier used during session creation.
publicKeystringBase64-encoded SPKI DER RSA public key.
algorithmstringAlgorithm metadata returned by the backend.
keySizenumberRSA key size in bits.
createdAtstringBackend creation timestamp.
expiresAtstringBackend expiry timestamp.

SecureChannelSession

FieldTypeDescription
sessionIdstringActive Secure Channel session id.
requestKeyCryptoKeyAES key used for request encryption.
responseKeyCryptoKeyAES key used for response decryption.
expiresAtnumberExpiry timestamp in milliseconds.

Envelope Functions

FunctionSignatureDescription
encodeEnvelopeencodeEnvelope(plaintext: Uint8Array, aesKey: CryptoKey, sessionId?: string): Promise<string>Encrypt plaintext bytes into a JSON envelope string.
decodeEnvelopedecodeEnvelope(envelope: string, aesKey: CryptoKey, sessionId?: string): Promise<Uint8Array>Parse and decrypt a JSON envelope string.

Crypto Functions

FunctionSignatureDescription
generateAesKeygenerateAesKey(): Promise<Uint8Array>Generate a raw 32-byte AES-256 key.
importAesKeyimportAesKey(raw: Uint8Array): Promise<CryptoKey>Import raw AES bytes into a Web Crypto CryptoKey.
aesGcmEncryptaesGcmEncrypt(key: CryptoKey, plaintext: Uint8Array, iv: Uint8Array, aad?: Uint8Array): Promise<{ ciphertext: Uint8Array; tag: Uint8Array }>Encrypt bytes with AES-256-GCM.
aesGcmDecryptaesGcmDecrypt(key: CryptoKey, ciphertext: Uint8Array, iv: Uint8Array, tag: Uint8Array, aad?: Uint8Array): Promise<Uint8Array>Decrypt AES-256-GCM bytes.
rsaOaepEncryptrsaOaepEncrypt(publicKey: CryptoKey, data: Uint8Array): Promise<Uint8Array>Encrypt bytes with an RSA-OAEP public key.
importRsaPublicKeyimportRsaPublicKey(spkiDer: Uint8Array): Promise<CryptoKey>Import an SPKI DER RSA public key configured for RSA-OAEP SHA-256.
randomBytesrandomBytes(n: number): Uint8ArrayGenerate cryptographically random bytes.

Utility Functions

FunctionSignatureDescription
toBase64UrltoBase64Url(bytes: Uint8Array): stringEncode bytes to Base64URL without padding.
fromBase64UrlfromBase64Url(str: string): Uint8ArrayDecode a Base64URL string into bytes.
toBase64toBase64(bytes: Uint8Array): stringEncode bytes to standard Base64 with padding.
fromBase64fromBase64(str: string): Uint8ArrayDecode a standard Base64 string into bytes.
buildAadbuildAad(sessionId: string, direction: 'request' | 'response'): Uint8ArrayBuild SCv2 additional authenticated data bytes.

Auth

AuthClient

ItemSignatureDescription
Constructornew AuthClient(config: AuthClientConfig)Create an auth client bound to a shared TokenManager.
MethodinitiateLogin(username: string, password: string): Promise<MfaChallenge>Submit credentials and receive the MFA challenge.
MethodcompleteLogin(sessionId: string, method: string, code: string): Promise<void>Complete MFA, store the returned TokenPair, and set the state to authenticated.
MethodrefreshToken(): Promise<void>Use the stored refresh token to obtain a new TokenPair.
Methodlogout(): Promise<void>Best-effort server logout followed by local state cleanup.
MethodgetState(): AuthStateReturn the current auth state.

AuthClientConfig

FieldTypeDescription
baseUrlstringAPI base URL.
portalAccessCodestringValue for X-PORTAL-ACCESS-CODE.
tokenManagerTokenManagerShared token storage for auth and request clients.

TokenManager

ItemSignatureDescription
Constructornew TokenManager()Create an in-memory token store.
MethodsetTokens(pair: TokenPair): voidStore access token, refresh token, and computed expiry time.
MethodgetAccessToken(): string | nullReturn the current access token.
MethodgetRefreshToken(): string | nullReturn the current refresh token.
MethodisExpired(): booleanReturn true when no token exists or it is expired.
Methodclear(): voidRemove all stored token state.

MfaHandler

ItemSignatureDescription
Constructornew MfaHandler()Create a standalone MFA challenge helper.
MethodsetChallenge(challenge: MfaChallenge): voidStore the active challenge.
MethodgetAvailableMethods(): MfaMethod[]Return the allowed MFA methods.
MethodgetSessionId(): string | nullReturn the active MFA session id.
MethodisExpired(): booleanCheck whether the challenge is missing or expired.
Methodclear(): voidClear the active challenge.
MethodprepareVerification(method: MfaMethod, code: string): { sessionId: string; method: MfaMethod; code: string } | nullBuild the verification payload for a valid method.

Auth Types

AuthState

Variant
'unauthenticated'
'mfa_pending'
'authenticated'

MfaMethod

Variant
'EMAIL'
'TOTP'
'SMS'

MfaChallenge

FieldTypeDescription
sessionIdstringChallenge session id used in login completion.
methodsMfaMethod[]Allowed MFA methods.
expiresAtnumberExpiry timestamp in milliseconds.

LoginResult

FieldTypeDescription
accessTokenstringAccess token.
refreshTokenstringRefresh token.
expiresInnumberAccess token lifetime in seconds.

TokenPair

FieldTypeDescription
accessTokenstringAccess token.
refreshTokenstringRefresh token.
expiresInnumberAccess token lifetime in seconds.

Request

SlaunchxFetch

ItemSignatureDescription
Constructornew SlaunchxFetch(config: FetchConfig)Create a request client with standard headers, retry, and Secure Channel support.
MethodsetWorkspaceId(id: string): voidUpdate the workspace header for subsequent requests.
Methodget<T>(path: string, params?: Record<string, string>): Promise<ApiResponse<T>>Perform a GET request.
Methodpost<T>(path: string, body?: unknown): Promise<ApiResponse<T>>Perform a POST request.
Methodput<T>(path: string, body?: unknown): Promise<ApiResponse<T>>Perform a PUT request.
Methoddelete<T>(path: string, body?: unknown): Promise<ApiResponse<T>>Perform a DELETE request.
MethodsecurePost<T>(path: string, body: unknown): Promise<ApiResponse<T>>Perform an encrypted POST request over Secure Channel.

FetchConfig

FieldTypeDescription
baseUrlstringAPI base URL.
portalAccessCodestringValue for X-PORTAL-ACCESS-CODE.
tokenManagerTokenManagerShared token storage.
workspaceIdstringOptional workspace header value.
localestringOptional locale header value. Defaults to en in HeaderBuilder.
onTokenExpired() => voidOptional callback when a normal request still ends in 401.
onError(error: SdkError) => voidOptional callback for non-401 request errors and secure request errors.

HeaderBuilder

ItemSignatureDescription
Constructornew HeaderBuilder(config: HeaderBuilderConfig)Create a reusable header builder.
MethodsetWorkspaceId(id: string): voidUpdate the workspace header for future builds.
Methodbuild(bearerToken?: string | null): Record<string, string>Build standard SDK headers.
MethodbuildSecure(scSessionId: string, bearerToken?: string | null): Record<string, string>Build standard headers plus SC headers.

HeaderBuilderConfig

FieldTypeDescription
portalAccessCodestringRequired portal access code.
localestringOptional locale. Defaults to en.
workspaceIdstringOptional workspace id.
scVersionnumberDeclared in the type but not used by the current implementation.
scSessionIdstringDeclared in the type but not used by the current implementation.

RetryPolicy

ItemSignatureDescription
Constructornew RetryPolicy(tokenManager: TokenManager, refreshFn: () => Promise<void>, config?: RetryConfig)Create a retry policy with optional backoff settings.
Methodexecute(doRequest: () => Promise<Response>): Promise<Response>Execute a request with 401 refresh handling and 5xx retry.

RetryConfig

FieldTypeDescription
maxRetriesnumberMaximum number of retry rounds for 5xx responses. Default 2.
baseDelayMsnumberBase backoff delay in milliseconds. Default 500.
maxDelayMsnumberMaximum backoff delay in milliseconds. Default 5000.

Error Handling

mapResponseToError

FunctionSignatureDescription
mapResponseToErrormapResponseToError(response: Response): Promise<SdkError>Convert a failed Response into SdkError.

BackendErrorBody

FieldTypeDescription
codestringBackend error code.
messagestringBackend error message.

PublicErrorCode

Variant
UNAUTHORIZED
FORBIDDEN
NOT_FOUND
VALIDATION_ERROR
RATE_LIMITED
INTERNAL_ERROR
SERVICE_UNAVAILABLE
SESSION_EXPIRED
MFA_REQUIRED
MFA_INVALID

Shared Types

SdkError

ItemSignatureDescription
Constructornew SdkError(code: string, message: string, httpStatus?: number)Create a typed SDK error.
Propertycode: stringStructured error code.
PropertyhttpStatus?: numberOptional HTTP status from the failed response.

ApiResponse<T>

FieldTypeDescription
successbooleanIndicates whether the request succeeded.
dataTPresent on success.
errorSdkErrorPresent on failure.

SlaunchX Internal Documentation