Reference / @getenginex/sdk/extension / ExtensionTransport
ExtensionTransport
Transport of an SDK client, for product packages (@getenginex/sdk-igaming, @getenginex/sdk-predictions). Every request goes through the same session, token renewal, tenant, locale, timeout, hooks, validation and dispose() of the app's client: a product package never creates its own session, tenant or transport.
Methods
reportError()
reportError(
error,ctx):EnginexError
Normalizes error into EnginexError and calls onError exactly once: for failures that the package's method detects after a successful response (e.g. the response carried neither a URL nor game HTML). Returns the error for the method to throw — the same object handed to the hook.
Parameters
error
unknown
ctx
Returns
Example
if (!launch.url && !launch.html) {
throw transport.reportError(new Error('launch without URL or HTML'), { method: 'POST', path: '/casino/launch' })
}Throws
Never throws. The returned error can be identified with isEnginexError (prefer it over instanceof EnginexError, which fails between the CJS files of the main entry and the extension entry).
request()
request<
T>(spec):Promise<T>
Makes a request and returns the response decoded by the schema.
Type Parameters
T
T
Parameters
spec
Returns
Promise<T>
Example
const game = await transport.request({ method: 'GET', path: '/casino/games/g-1', schema: gameSchema(), options })Throws
The same error as a core method: HTTP/gateway, UNAUTHENTICATED, NETWORK_ERROR, TIMEOUT, ABORTED, VALIDATION_ERROR or CONFIGURATION_ERROR (including after dispose() and with auth, validation or perPageParam outside the contract, before any fetch). onError is called exactly once with that same object. Identify the error with isEnginexError(error, code), not with instanceof EnginexError: in CommonJS, the main entry and the extension entry are separate files, each with its own copy of the class.
requestPage()
requestPage<
T>(spec):Promise<Page<T>>
Makes a paginated listing and returns a Page.
Type Parameters
T
T
Parameters
spec
Returns
Promise<Page<T>>
Example
const page = await transport.requestPage({ method: 'GET', path: '/casino/games', item: gameSchema(), page: 1 })Throws
As in ExtensionTransport.request (use isEnginexError, not instanceof).