TypeScript ambient type declarations for the Tyk gateway's JSVM plugin runtime.
These types describe the API exposed inside the gateway when authoring custom
middleware in JavaScript / TypeScript. They cover both the legacy otto driver
and the modern goja driver — both expose the same globals (TykJS,
TykMakeHttpRequest, log, ...) and pass the same struct shapes across the
Go↔JS boundary.
npm install --save-dev @tyk-technologies/tyk-plugin-typesAdd a triple-slash directive at the top of your plugin entry file:
/// <reference types="@tyk-technologies/tyk-plugin-types" />
var handler = new TykJS.TykMiddleware.NewMiddleware({});
handler.NewProcessRequest(function (
request: TykRequest,
session: TykSession,
config: TykConfig
): TykHandlerResult {
request.SetHeaders["X-Hello"] = "world";
return handler.ReturnData(request, {});
});Or, if you'd rather not use a triple-slash directive, add the package to
compilerOptions.types in tsconfig.json:
{
"compilerOptions": {
"types": ["@tyk-technologies/tyk-plugin-types"]
}
}TykJS.TykMiddleware.NewMiddleware— middleware constructor and the four return helpers (ReturnData,ReturnAuthData,ReturnResponseData,NewProcessRequest,NewProcessResponse).- Request / response / session / config shapes (
TykRequest,TykResponse,TykSession,TykAccessDefinition,TykConfig,TykReturnOverrides,TykHandlerResult). - Globals registered by the gateway (
TykMakeHttpRequest,TykGetKeyData,TykSetKeyData,TykBatchRequest,log,rawlog,b64enc,b64dec,rawb64enc,rawb64dec). - Plugin key-value storage globals, goja only (
TykStorageGet,TykStorageSet,TykStorageSetNX,TykStorageDel,TykStorageTTL,TykStorageIncr). - Helper types for the JSON-string contracts (
TykHttpRequestSpec,TykHttpResponseRaw). - Manifest constants (
TykPluginDriver,TykMiddlewareHook).
These types track the gateway's JS-side API surface. Breaking changes in the gateway runtime that affect the surface will produce a major version bump here.
A starter project that demonstrates how to author, build, and unit-test plugins against these types lives at tyk-plugin-starter.
Apache 2.0