ltijs
Version:
Easily turn your web application into a LTI 1.3 Learning Tool.
93 lines (92 loc) • 5.74 kB
TypeScript
import { PlatformManager } from '#services/platform-manager/platform-manager.service';
import { DynamicRegistration } from '#services/dynamic-registration/dynamic-registration.service';
import type { DatabaseManager } from '#services/database-manager/database-manager.types';
import type { HttpHandler, RouteHandler } from '#services/http-handler/http-handler.types';
import type { CacheManager } from '#services/cache-manager/cache-manager.types';
import type { InactivePlatformHandler, OnLaunchHandler, UnregisteredPlatformHandler } from '#services/launch/launch.types';
import type { LaunchContext } from '#services/launch/launch-context.service';
import type { DeployOptions, ProviderOptions } from '#services/provider/provider.types';
/**
* The library's main entry point. Construct one per application (`new Provider(options)`), wire up
* launch handlers, then call {@link Provider.listen} to start listening. Everything else, platform
* registration, resuming a launch outside the original request, closing down cleanly, goes through
* this instance or the sub-services exposed on it.
*/
export declare class Provider {
private readonly DEFAULT_LOGIN_ROUTE;
private readonly DEFAULT_LAUNCH_ROUTE;
private readonly DEFAULT_KEYSET_ROUTE;
private readonly DEFAULT_DYNAMIC_REGISTRATION_ROUTE;
private readonly DEFAULT_PORT;
private readonly DEFAULT_TOKEN_MAX_AGE_SECONDS;
private readonly STARTUP_BANNER;
/** The active storage backend. Defaults to `MongoDatabaseManager`; override via `ProviderOptions.databaseManager`. */
readonly databaseManager: DatabaseManager;
/** Register, look up, update, and (de)activate platforms. See its own methods for the full CRUD surface. */
readonly platformManager: PlatformManager;
/** The active HTTP framework adapter. Defaults to `ExpressHttpHandler`; override via `ProviderOptions.httpHandler`. */
readonly httpHandler: HttpHandler;
/** The active cache backend. Defaults to a no-op; override via `ProviderOptions.cacheManager` (e.g. `RedisCacheManager`). */
readonly cacheManager: CacheManager;
/** Only set when `ProviderOptions.dynamicRegistration` was provided at construction. */
readonly dynamicRegistrationService?: DynamicRegistration;
private readonly logger;
private readonly loginRoute;
private readonly launchRoute;
private readonly keysetRoute;
private readonly dynamicRegistrationRoute?;
private readonly launchService;
private readonly port;
/**
* Every dependency (`databaseManager`, `cacheManager`, `httpHandler`, `requestHandler`, `logger`) has a
* working default: pass nothing beyond a database connection (or a full `databaseManager`) to get a
* runnable provider. Route defaults are `/lti/login`, `/lti/launch`, `/lti/keys`, `/lti/register`.
*/
constructor(options: ProviderOptions);
/** Called on a standard resource-link launch (the common case: a student/instructor opening the tool from the LMS). */
onResourceLink(handler: OnLaunchHandler): void;
/** Alias of `onResourceLink()`, matching legacy's exact method name for anyone migrating from legacy ltijs. */
onConnect(handler: OnLaunchHandler): void;
/** Called when the platform launches the tool for content selection (the deep-linking message type). */
onDeepLinking(handler: OnLaunchHandler): void;
/** Called on a submission-review launch (an instructor reviewing a learner's graded submission). */
onSubmissionReview(handler: OnLaunchHandler): void;
/**
* Called instead of throwing the default `UnregisteredPlatformError` when a login request arrives
* from a platform this tool hasn't registered yet. Must fully send the response itself.
*/
onUnregisteredPlatform(handler: UnregisteredPlatformHandler): void;
/**
* Called instead of throwing the default `PlatformNotActivatedError` when a login request arrives
* from a platform that's registered but deactivated. Must fully send the response itself.
*/
onInactivePlatform(handler: InactivePlatformHandler): void;
/**
* Overrides the default GET handler for the dynamic-registration route. Throws
* `DynamicRegistrationNotConfiguredError` if `ProviderOptions.dynamicRegistration` wasn't set.
*/
onDynamicRegistration(handler: RouteHandler): void;
/**
* Resumes a previously-issued launch by its ltik: the session-resumption entry point for a
* follow-up request (e.g. protecting a custom app route, or submitting a grade from a background
* job) using a ltik obtained from an earlier `LaunchContext`.
*/
getLaunchContext(ltik: string): Promise<LaunchContext>;
/** Registers `path` as an additional launch route, dispatching through the same launch handlers. */
registerLtiRoute(path: string): void;
private setupDynamicRegistration;
/**
* Connects the database and cache backends, starts the HTTP listener, and registers a `SIGINT` handler
* that calls {@link Provider.close} before exiting. Prints a startup banner unless `options.silent`.
* Port and TLS were already given to the `httpHandler` at construction time (see
* `ProviderOptions.server`, which only applies to the default `ExpressHttpHandler`; a custom
* `httpHandler` is expected to already be fully configured).
*/
listen(options?: DeployOptions): Promise<void>;
/** @deprecated Alias of {@link Provider.listen}, kept for backwards compatibility. */
deploy(options?: DeployOptions): Promise<void>;
/** Stops the HTTP listener and closes the database and cache connections, in that order. */
close(): Promise<void>;
private printStartupBanner;
}
export default Provider;