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
99 changes: 78 additions & 21 deletions types/ltijs/lib/Provider/Provider.d.ts
Original file line number Diff line number Diff line change
Expand Up @@ -18,11 +18,10 @@ export interface DeploymentOptions {
}

export interface ProviderOptions {
appUrl?: string | undefined;
loginUrl?: string | undefined;
sessionTimeoutUrl?: string | undefined;
invalidTokenUrl?: string | undefined;
keysetUrl?: string | undefined;
appRoute?: string | undefined;
loginRoute?: string | undefined;
keysetRoute?: string | undefined;
dynregRoute?: string | undefined;
https?: boolean | undefined;
ssl?: {
key: string;
Expand All @@ -35,15 +34,47 @@ export interface ProviderOptions {
cookies?: {
secure?: boolean | undefined;
sameSite?: string | undefined;
domain?: string | undefined;
} | undefined;
devMode?: boolean | undefined;
ltiaas?: boolean | undefined;
tokenMaxAge?: number | undefined;
dynReg?: {
url: string;
name: string;
logo?: string | undefined;
description?: string | undefined;
redirectUris?: string[] | undefined;
customParameters?: any;
autoActivate?: boolean | undefined;
useDeepLinking?: boolean | undefined;
} | undefined;

/**
* @deprecated Use `appRoute` property instead.
*/
appUrl?: string | undefined;
/**
* @deprecated Use `loginRoute` property instead.
*/
loginUrl?: string | undefined;
/**
* @deprecated Use `keysetRoute` property instead.
*/
keysetUrl?: string | undefined;
}

export interface RequestCallback {
// eslint-disable-next-line @typescript-eslint/no-invalid-void-type
(request: Request, response: Response, next: NextFunction): Response | void;
}

export interface OnConnectCallback {
export interface TokenRequestCallback {
// eslint-disable-next-line @typescript-eslint/no-invalid-void-type
(connection: IdToken, request: Request, response: Response, next: NextFunction): Response | void;
(token: IdToken, request: Request, response: Response, next: NextFunction): Response | void;
}

export interface UnregisteredPlatformCallback {
export interface FinalRequestCallback {
// eslint-disable-next-line @typescript-eslint/no-invalid-void-type
(request: Request, response: Response): Response | void;
}
Expand All @@ -58,6 +89,13 @@ export interface RedirectOptions {
ignoreRoot?: boolean | undefined;
}

export type GetPlatformFunction = (
url: string,
clientId?: string,
ENCRYPTIONKEY?: string,
Database?: Database,
) => Promise<Platform[] | Platform | false>;

declare class Provider {
app: Express;

Expand All @@ -72,34 +110,53 @@ declare class Provider {

close(): Promise<boolean>;

onConnect(_connectCallback: OnConnectCallback, options?: OnConnectOptions): true;
onConnect(_connectCallback: TokenRequestCallback, options?: OnConnectOptions): true;

onDeepLinking(_connectCallback: OnConnectCallback, options?: OnConnectOptions): true;
onDeepLinking(_deepLinkingCallback: TokenRequestCallback): true;

onUnregisteredPlatform(_unregisteredPlatformCallback: UnregisteredPlatformCallback): true;
onDynamicRegistration(_dynamicRegistrationCallback: RequestCallback): true;

loginUrl(): string;
onSessionTimeout(_sessionTimeoutCallback: FinalRequestCallback): true;

appUrl(): string;
onInvalidToken(_invalidTokenCallback: FinalRequestCallback): true;

sessionTimeoutUrl(): string;
onUnregisteredPlatform(_unregisteredPlatformCallback: FinalRequestCallback): true;

invalidTokenUrl(): string;
appRoute(): string;

keysetUrl(): string;
loginRoute(): string;

keysetRoute(): string;

dynRegRoute(): string;

whitelist(...urls: Array<string | { route: string; method: string }>): true;

registerPlatform(config: PlatformConfig): Promise<Platform | false>;
registerPlatform(
platform: PlatformConfig,
getPlatform?: GetPlatformFunction,
ENCRYPTIONKEY?: string,
Database?: Database,
): Promise<Platform>;

getPlatform(url: string): Promise<Platform[] | false>;
getPlatform(url: string, clientId: string): Promise<Platform | false>;
getPlatform(
url: string,
clientId?: string,
ENCRYPTIONKEY?: string,
Database?: Database,
): Promise<Platform[] | Platform | false>;

deletePlatform(url: string, clientId: string): Promise<boolean>;
updatePlatformById(platformId: string, platformInfo: PlatformConfig): Promise<Platform>;

getAllPlatforms(): Promise<Platform[] | false>;
deletePlatform(url: string, clientId: string): Promise<true>;

getAllPlatforms(): Promise<Platform[]>;

redirect(response: Response, path: string, options?: RedirectOptions): void;

appUrl(): string;
loginUrl(): string;
keysetUrl(): string;
}

declare const defaultProvider: Provider;
Expand Down
19 changes: 10 additions & 9 deletions types/ltijs/ltijs-tests.ts
Original file line number Diff line number Diff line change
Expand Up @@ -50,11 +50,9 @@ const ltiAdvanced = Provider.setup(
},
},
{
appUrl: "/",
loginUrl: "/login",
sessionTimeoutUrl: "/sessionTimeout",
invalidTokenUrl: "/invalidToken",
keysetUrl: "/keys",
appRoute: "/",
loginRoute: "/login",
keysetRoute: "/keys",
staticPath: "/views",
https: true,
ssl: {
Expand All @@ -72,7 +70,6 @@ const ltiAdvanced = Provider.setup(
// $ExpectType true
ltiMinimal.onConnect(
(connection, request, response) => {
console.log(connection.endpoint);
ltiMinimal.redirect(response, "/main");
},
{
Expand Down Expand Up @@ -104,7 +101,7 @@ ltiMinimal.deploy(deploymentOptions);
// $ExpectType Promise<true | undefined>
ltiAdvanced.deploy({ port: 4040, silent: true });

// $ExpectType Promise<false | Platform>
// $ExpectType Promise<Platform>
ltiAdvanced.registerPlatform({
url: "https://platform.url",
name: "Platform Name",
Expand Down Expand Up @@ -167,13 +164,17 @@ ltiAdvanced.app.get("/any", (request: Request, response: Response) => {
ltiAdvanced.getPlatform("https://platform.url").then(async (platform) => {
if (!platform) return;

const p = Array.isArray(platform) ? platform[0] : platform;

// $expectType string | boolean
const name = await platform?.[0]?.platformName();
const name = await p.platformName();
});

ltiAdvanced.getPlatform("https://platform.url", "123").then(async (platform) => {
if (!platform) return;

const p = Array.isArray(platform) ? platform[0] : platform;

// $expectType string | boolean
const name = await platform.platformName();
const name = await p.platformName();
});
2 changes: 1 addition & 1 deletion types/ltijs/package.json
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
{
"private": true,
"name": "@types/ltijs",
"version": "4.0.9999",
"version": "5.9.9999",
"projects": [
"https://cvmcosta.github.io/ltijs"
],
Expand Down