Home Reference Source Repository
import Tsugi from 'tsugi-node/src/core/Tsugi.js'
public class | source

Tsugi

The Tsugi class/namespace/Utilities

Calling sequence in a NodeJS app:

 var CFG = require('./src/config/Config');
 var Tsugi = require('./src/core/Tsugi');

 launch = Tsugi.requireData(CFG, req, res);
 if ( launch.complete ) return;

Constructor Summary

Public Constructor
public

Member Summary

Public Members
public
public
public
public
public
public

Method Summary

Public Methods
public

adjustData(CFG: Config, row: object, post: object): *

Make sure that the data in our lti_ tables matches the POST data

public

checkOAuthSignature(launch: *, key: *, secret: *): *

public

extractPost(i: object, needed: *): *: object

Extract the data from POST

public

isRequest(props: *): boolean

public

loadAllData(CFG: Config, post: object): *

Load the data from our lti_ tables using one long LEFT JOIN

public

patchNeeded(needed: *): Set

Patch the value for the list of needed features and return a Set

public

requireData(CFG: ConfigSample, req: http.ClientRequest, res: http.ServerResponse, A: *, The: *, needed: *): *

Handle launch and/or set up the LTI session and global variables

public

setup(CFG: ConfigSample, req: http.ClientRequest, res: http.ServerResponse, A: *, needed: *): *

Optionally handle launch and/or set up the LTI session variables

Public Constructors

public constructor source

Public Members

public ALL: string source

public CONTEXT: string source

public NONE: string source

public USER: string source

public unit_testing: boolean source

Public Methods

public adjustData(CFG: Config, row: object, post: object): * source

Make sure that the data in our lti_ tables matches the POST data

This routine compares the POST data with the data pulled from the lti tables and goes through carefully INSERTing or UPDATING all the nexessary data in the lti tables to make sure that the lti_ table correctly match all the data from the incoming post.

While this looks like a lot of INSERT and UPDATE statements, the INSERT statements only run when we see a new user/course/link for the first time and after that, we only update is something changes. So in a high percentage of launches we are not seeing any new or updated data and so this code just falls through and does absolutely no SQL.

Params:

NameTypeAttributeDescription
CFG Config

A Tsugi Configuration object

row object

The row data (from loadAllData)

post object

The post data

Return:

*

public checkOAuthSignature(launch: *, key: *, secret: *): * source

Params:

NameTypeAttributeDescription
launch *
key *
secret *

Return:

*

public extractPost(i: object, needed: *): *: object source

Extract the data from POST

Params:

NameTypeAttributeDescription
i object

The input post data

needed *

Indicates which of the data structures are needed. If this is omitted, this assumes that CONTEXT, LINK, and USER data are required. If NONE is present, then none of the three are rquired. If some combination of the three are needed, this accepts an array of the CONTEXT, LINK, and USER can be passed in.

Return:

*

public isRequest(props: *): boolean source

Params:

NameTypeAttributeDescription
props *

Return:

boolean

public loadAllData(CFG: Config, post: object): * source

Load the data from our lti_ tables using one long LEFT JOIN

This data may or may not exist - hence the use of the long LEFT JOIN.

Params:

NameTypeAttributeDescription
CFG Config

A Tsugi Configuration object

post object

The post data

Return:

*

public patchNeeded(needed: *): Set source

Patch the value for the list of needed features and return a Set

ns = this.patchNeeded(Tsugi.ALL)
console.log(ns.has(this.ALL));

or if you don't need link..

ns = this.patchNeeded([Tsugi.USER,Tsugi.CONTEXT]))
console.log(ns.has(this.ALL));

Note - causes no harm if called more than once.

Params:

NameTypeAttributeDescription
needed *

Indicates which of the data structures are needed. If this is omitted, this assumes that CONTEXT, LINK, and USER data are required. If NONE is present, then none of the three are rquired. If some combination of the three are needed, this accepts an array of the CONTEXT, LINK, and USER can be passed in.

Return:

Set

A set of the needed values

public requireData(CFG: ConfigSample, req: http.ClientRequest, res: http.ServerResponse, A: *, The: *, needed: *): * source

Handle launch and/or set up the LTI session and global variables

Make sure we have the values we need in the LTI session This routine will not start a session if none exists. It will die is there if no session_name() (PHPSESSID) cookie or parameter. No need to create any fresh sessions here.

Params:

NameTypeAttributeDescription
CFG ConfigSample

A Tsugi Configuration object

req http.ClientRequest
res http.ServerResponse
A *

session object

The *

body (i.e. POST data)

needed *

Indicates which of the data structures are needed. If this is omitted, this assumes that CONTEXT, LINK, and USER data are required. If NONE is present, then none of the three are rquired. If some combination of the three are needed, this accepts an array of the CONTEXT, LINK, and USER can be passed in.

Return:

*

Launch A Tsugi Launch object.

public setup(CFG: ConfigSample, req: http.ClientRequest, res: http.ServerResponse, A: *, needed: *): * source

Optionally handle launch and/or set up the LTI session variables

This will set up as much of the user, context, link, and result data as it can including leaving them all null if this is called on a request with no LTI launch and no LTI data in the session. This expects req.session to be properly set up as it may read and / or write session data. If this encounters a LTI launch (POST) it might redirect and indicate that this request is now complete.

Calling sequence:

launch = tsugi.setup(CFG, req, res, session);
if (launch.complete) return;

Params:

NameTypeAttributeDescription
CFG ConfigSample

A Tsugi Configuration object

req http.ClientRequest
res http.ServerResponse
A *

session object

needed *

Indicates which of the data structures are needed. If this is omitted, this assumes that CONTEXT, LINK, and USER data are required. If NONE is present, then none of the three are rquired. If some combination of the three are needed, this accepts an array of the CONTEXT, LINK, and USER can be passed in.

Return:

*

Launch A Tsugi Launch object.