### Installing LTIaaS Node.js SDK Source: https://github.com/ltiaas/ltiaas-node-sdk/blob/main/Readme.md This snippet demonstrates how to install the LTIaaS Node.js SDK using npm, the Node.js package manager. This command adds the `ltiaas` package to your project's dependencies, making its functionalities available for use in your application. ```bash npm install ltiaas ``` -------------------------------- ### Initializing LaunchClient with LTIK Authentication (JavaScript) Source: https://github.com/ltiaas/ltiaas-node-sdk/blob/main/Readme.md This example shows how to initialize the `LaunchClient` using LTIK (Learning Tools Interoperability Key) token authentication. This method is typically used within an LTI launch context where an LTIK token is provided by the LTIaaS platform, enabling secure communication for LTI-specific operations. ```js const client = new LaunchClient({ apiKey: "your-api-key", ltik: "your-ltik-token" }); ``` -------------------------------- ### Initializing LaunchClient with API Key Authentication (JavaScript) Source: https://github.com/ltiaas/ltiaas-node-sdk/blob/main/Readme.md This example illustrates initializing the `LaunchClient` using only an API key. This authentication method provides general access to the LTIaaS platform's public APIs and is typically used for operations that do not require specific LTI launch context or elevated permissions. ```js const client = new LaunchClient({ apiKey: "your-api-key" }); ``` -------------------------------- ### Activating an LTI Platform (TypeScript) Source: https://github.com/ltiaas/ltiaas-node-sdk/blob/main/Readme.md This snippet demonstrates how to activate a registered LTI platform, enabling it for launches and service requests. It takes the platform's unique id and returns a void Promise. The example also shows how activation can be combined with platform registration. ```TypeScript // Activate a platform await client.activatePlatform("platform-123"); // Can be used in combination with platform registration const platform = await client.registerPlatform({ name: "Canvas Instance", url: "https://canvas.instructure.com" }); await client.activatePlatform(platform.id); ``` -------------------------------- ### Retrieving Course Memberships (TypeScript) Source: https://github.com/ltiaas/ltiaas-node-sdk/blob/main/Readme.md This example illustrates how to fetch all course memberships for the current context and how to apply filters such as 'role', 'limit', and 'offset' to refine the results. It also demonstrates how to access the returned membership data, including the array of members, total count, and context information. ```typescript // Get all memberships const allMemberships = await client.getMemberships(); // Get memberships with filters const filteredMemberships = await client.getMemberships({ role: "Learner", limit: 10, offset: 0 }); // Access membership data console.log(filteredMemberships.members); // Array of members console.log(filteredMemberships.totalItems); // Total count console.log(filteredMemberships.context); // Course context ``` -------------------------------- ### Updating Gradebook Line Items (TypeScript) Source: https://github.com/ltiaas/ltiaas-node-sdk/blob/main/Readme.md This example shows how to update an existing gradebook line item by providing its ID and the properties to be modified, such as score maximum, label, tag, and start/end dates. It then demonstrates how to access the properties of the updated line item. ```typescript // Update a line item const updatedLineItem = await client.updateLineItem("item-123", { scoreMaximum: 100, label: "Updated Assignment", tag: "quiz", startDateTime: "2023-01-01T00:00:00Z", endDateTime: "2023-12-31T23:59:59Z" }); // Access updated line item data console.log(updatedLineItem.id); console.log(updatedLineItem.label); console.log(updatedLineItem.scoreMaximum); ``` -------------------------------- ### Creating Gradebook Line Items (TypeScript) Source: https://github.com/ltiaas/ltiaas-node-sdk/blob/main/Readme.md This example shows how to create new gradebook columns (line items) with both basic and comprehensive details, including score maximum, label, resource ID, custom tags, and start/end dates. It also demonstrates how to access the unique ID and URL of the newly created line item. ```typescript // Create a basic line item const newLineItem = await client.createLineItem({ scoreMaximum: 100, label: "Midterm Exam", resourceId: "exam-001" }); // Create a line item with all properties const detailedLineItem = await client.createLineItem({ scoreMaximum: 100, label: "Final Project", resourceId: "project-001", tag: "final-assessment", resourceLinkId: "link-123", startDateTime: "2024-01-01T00:00:00Z", endDateTime: "2024-01-15T23:59:59Z" }); // Access the created line item data console.log(newLineItem.id); console.log(newLineItem.url); ``` -------------------------------- ### Building HTML Form for LTI Deep Linking (TypeScript) Source: https://github.com/ltiaas/ltiaas-node-sdk/blob/main/Readme.md This example demonstrates how to use `client.buildDeepLinkingForm` to generate an HTML form for deep linking content items back to the LTI platform. It shows how to define `contentItems` with properties like type, title, URL, and custom parameters, and how to configure form options such as `accept_multiple` and `auto_create`. ```typescript // Create content items const contentItems = [ { type: "ltiResourceLink", title: "My Resource", url: "https://your.ltiaas.com/lti/launch?resource=2", custom: { difficulty: "intermediate" } } ]; // Build form with options const form = await client.buildDeepLinkingForm(contentItems, { accept_multiple: false, auto_create: true }); // The returned form can be inserted into your HTML document.getElementById('form-container').innerHTML = form; ``` -------------------------------- ### Deleting an LTI Platform (TypeScript) Source: https://github.com/ltiaas/ltiaas-node-sdk/blob/main/Readme.md This snippet shows how to permanently remove an LTI platform integration. It requires the platform's unique id and returns a void Promise upon successful deletion. The example also includes error handling for robust implementation. ```TypeScript // Delete a platform by ID await client.deletePlatform("platform-123"); // Delete with error handling try { await client.deletePlatform("platform-123"); console.log("Platform successfully deleted"); } catch (error) { console.error("Failed to delete platform:", error); } ``` -------------------------------- ### Deleting Gradebook Line Items (TypeScript) Source: https://github.com/ltiaas/ltiaas-node-sdk/blob/main/Readme.md This snippet demonstrates how to delete a specific gradebook line item using its unique identifier. It also includes an example of error handling for the deletion operation, noting that the ID must be URL-encoded and that deletion is irreversible. ```typescript // Delete a line item by ID await client.deleteLineItem("12345"); // Delete with error handling try { await client.deleteLineItem("12345"); console.log("Line item successfully deleted"); } catch (error) { console.error("Failed to delete line item:", error); } ``` -------------------------------- ### Retrieving Raw Registration Request Data with LTI SaaS Node.js SDK (TypeScript) Source: https://github.com/ltiaas/ltiaas-node-sdk/blob/main/Readme.md This section shows how to retrieve the unprocessed raw registration request data using client.getRawRegistrationRequest, which requires API Key authentication. It includes an example of initializing the LaunchClient with an API key and domain. The method returns a Promise resolving to a RawRegistrationRequest object, containing details like url, familyCode, version, supportedScopes, and supportedMessages. ```typescript // Initialize client with API key const client = new LaunchClient({ apiKey: "your-api-key", domain: "your-domain" }); // Get raw registration request const rawRegistration = await client.getRawRegistrationRequest("registration-id"); // Access registration data console.log(rawRegistration.url); console.log(rawRegistration.familyCode); console.log(rawRegistration.supportedScopes); console.log(rawRegistration.supportedMessages); ``` -------------------------------- ### Retrieving and Accessing LTI ID Token (TypeScript) Source: https://github.com/ltiaas/ltiaas-node-sdk/blob/main/Readme.md This example demonstrates how to retrieve the decoded LTI ID token using `client.getIdToken()` and access its properties. It shows how to extract user information (ID, roles), platform details (name), and check the availability of LTI services like outcomes, which requires LTIK authentication. ```typescript // Get the ID token const idToken = await client.getIdToken(); // Access user information console.log(idToken.user.id); console.log(idToken.user.roles); // Access platform information console.log(idToken.platform.name); // Check service availability console.log(idToken.services.outcomes.available); ``` -------------------------------- ### Initializing LaunchClient with Service Key Authentication (JavaScript) Source: https://github.com/ltiaas/ltiaas-node-sdk/blob/main/Readme.md This snippet demonstrates initializing the `LaunchClient` with a service key. Service key authentication is suitable for server-to-server communication or when performing operations that require broader access than a single LTI launch context, often used for administrative tasks. ```js const client = new LaunchClient({ apiKey: "your-api-key", serviceKey: "your-service-key" }); ``` -------------------------------- ### Registering a New LTI Platform (TypeScript) Source: https://github.com/ltiaas/ltiaas-node-sdk/blob/main/Readme.md This snippet demonstrates how to register a new LTI platform with the LTIaaS service. It requires a PartialPlatform object containing essential configuration details like name, URL, client ID, deployment ID, and OAuth2 endpoints. The method returns a Platform object with the newly registered platform's details. ```TypeScript // Register a new platform const newPlatform = await client.registerPlatform({ name: "Canvas LMS", url: "https://canvas.instructure.com", clientId: "12345", deploymentId: "deployment_123", authenticationEndpoint: "https://canvas.instructure.com/auth", accesstokenEndpoint: "https://canvas.instructure.com/token", jwksEndpoint: "https://canvas.instructure.com/.well-known/jwks.json" }); // Access platform data console.log(newPlatform.id); console.log(newPlatform.status); console.log(newPlatform.createdAt); ``` -------------------------------- ### Building Deep Linking Form Components (TypeScript) Source: https://github.com/ltiaas/ltiaas-node-sdk/blob/main/Readme.md This snippet demonstrates how to create content items and use the `buildDeepLinkingFormComponents` method to generate the necessary JWT, form data, and endpoint for a custom deep linking form. It also shows how to populate an HTML form with these components and submit it. ```typescript // Create content items const contentItems = [ { type: "ltiResourceLink", title: "Sample Resource", url: "https://your.ltiaas.com/lti/launch?resource=2", custom: { difficulty: "intermediate" } } ]; // Build form components with options const formComponents = await client.buildDeepLinkingFormComponents(contentItems, { accept_types: ["ltiResourceLink"], accept_multiple: false, auto_create: true }); // Use the components to build a custom form document.getElementById("form-jwt").value = formComponents.jwt; document.getElementById("form-endpoint").value = formComponents.endpoint; document.getElementById("form-formData").value = formComponents.formData; document.getElementById("my-form").submit(); ``` -------------------------------- ### Completing Platform Registration Request with LTI SaaS Node.js SDK (TypeScript) Source: https://github.com/ltiaas/ltiaas-node-sdk/blob/main/Readme.md This section demonstrates how to finalize a platform registration request using the client.completeRegistrationRequest method, which requires API Key authentication. It details the RegistrationOptions object, including url, familyCode, version, supportedScopes, and supportedMessages with their types and placements. The method returns a Promise resolving to a RegistrationCompletion object containing registration details and credentials. ```typescript // Complete a registration request const registration = await client.completeRegistrationRequest("reg-123", { url: "https://tool.example.com/launch", familyCode: "my-tool", version: "1.0.0", supportedScopes: [ "https://purl.imsglobal.org/spec/lti-ags/scope/score", "https://purl.imsglobal.org/spec/lti-nrps/scope/contextmembership.readonly" ], supportedMessages: [ { type: "LtiResourceLinkRequest", placements: ["ContentArea", "CourseNavigation"] } ] }); // Access registration completion data console.log(registration.clientId); console.log(registration.deploymentId); console.log(registration.toolConfiguration); ``` -------------------------------- ### Retrieving Specific LTI Platform Details with LTI SaaS Node.js SDK (TypeScript) Source: https://github.com/ltiaas/ltiaas-node-sdk/blob/main/Readme.md This section demonstrates how to fetch detailed information for a specific LTI platform by its ID using the client.getPlatform method, which requires API Key authentication. It outlines the structure of the returned Platform object, including id, name, url, clientId, deploymentId, various endpoints, and status fields. The method returns a Promise resolving to this Platform object. ```typescript // Fetch a specific platform const platformId = "platform-123"; const platform = await client.getPlatform(platformId); // Access platform details console.log(platform.name); console.log(platform.url); console.log(platform.active); console.log(platform.clientId); console.log(platform.deploymentId); ``` -------------------------------- ### Retrieving Registered LTI Platforms with LTI SaaS Node.js SDK (TypeScript) Source: https://github.com/ltiaas/ltiaas-node-sdk/blob/main/Readme.md This section illustrates how to retrieve a list of registered LTI platforms using the client.getPlatforms method, which requires API Key authentication. It explains how to use PlatformsFilter options like limit, offset, active, search, and version for filtering. The method returns a Promise resolving to a PlatformContainer object, which includes an array of platform objects and pagination metadata. ```typescript // Get platforms with basic filtering const platforms = await client.getPlatforms({ limit: 20, offset: 0 }); // Get platforms with advanced filtering const filteredPlatforms = await client.getPlatforms({ limit: 10, offset: 0, active: true, search: "canvas", version: "1.3.0" }); // Access platform data console.log(filteredPlatforms.platforms); // Array of platform objects console.log(filteredPlatforms.totalItems); // Total count ``` -------------------------------- ### Retrieving Registration Request by ID with LTI SaaS Node.js SDK (TypeScript) Source: https://github.com/ltiaas/ltiaas-node-sdk/blob/main/Readme.md This section demonstrates how to fetch a formatted registration request using the client.getRegistrationRequest method, requiring API Key authentication. It details the RegistrationRequest object's structure, including url, familyCode, version, supportedScopes, and supportedMessages with their types and placements. The method returns a Promise resolving to this RegistrationRequest object. ```typescript // Get a registration request const registrationRequest = await client.getRegistrationRequest("reg-123"); // Access registration request data console.log(registrationRequest.url); // Platform registration URL console.log(registrationRequest.familyCode); // Platform family code console.log(registrationRequest.supportedScopes); // Array of supported scopes console.log(registrationRequest.supportedMessages); // Array of supported message configurations ``` -------------------------------- ### Updating an Existing LTI Platform (TypeScript) Source: https://github.com/ltiaas/ltiaas-node-sdk/blob/main/Readme.md This snippet illustrates how to modify an existing LTI platform's configuration. It takes the platform's unique id and a PartialPlatform object with the properties to be updated. The method returns the updated Platform object, reflecting the changes. ```TypeScript // Update platform configuration const updatedPlatform = await client.updatePlatform("platform-123", { name: "Updated Canvas Instance", clientId: "new-client-id", deploymentId: "new-deployment-id", authenticationEndpoint: "https://canvas.example.com/auth" }); // Access updated platform data console.log(updatedPlatform.name); console.log(updatedPlatform.active); console.log(updatedPlatform.updatedAt); ``` -------------------------------- ### Retrieving Gradebook Line Items (TypeScript) Source: https://github.com/ltiaas/ltiaas-node-sdk/blob/main/Readme.md This snippet demonstrates how to retrieve a list of all gradebook line items for the current context. It also shows how to use filters like 'tag', 'limit', and 'offset' to narrow down the results and how to access the array of line items and the total count. ```typescript // Get all line items const allLineItems = await client.getLineItems(); // Get line items with filters const filteredLineItems = await client.getLineItems({ tag: "midterm", limit: 25, offset: 0 }); // Access line items data console.log(filteredLineItems.lineItems); // Array of line items console.log(filteredLineItems.totalItems); // Total count ``` -------------------------------- ### Submitting Scores with LTI SaaS Node.js SDK (TypeScript) Source: https://github.com/ltiaas/ltiaas-node-sdk/blob/main/Readme.md This section demonstrates how to submit scores for a specific line item using the client.submitScore method. It outlines the required Score object properties such as userId, scoreGiven, scoreMaximum, activityProgress, gradingProgress, and an optional comment. The method returns a Promise that resolves to void. ```typescript // Submit a basic score await client.submitScore("lineitem-123", { userId: "student-456", scoreGiven: 85, scoreMaximum: 100, activityProgress: "Completed", gradingProgress: "FullyGraded", comment: "Excellent work on the assignment!" }); // Submit a score with minimum required fields await client.submitScore("lineitem-789", { userId: "student-101", scoreGiven: 42, scoreMaximum: 50, activityProgress: "Completed", gradingProgress: "FullyGraded" }); ``` -------------------------------- ### Retrieving a Specific Gradebook Line Item (TypeScript) Source: https://github.com/ltiaas/ltiaas-node-sdk/blob/main/Readme.md This snippet demonstrates how to retrieve a single gradebook line item by its unique identifier. It also includes a basic error handling mechanism using a try-catch block to manage potential failures during the API call. ```typescript // Get a single line item by ID const lineItem = await client.getLineItem("12345"); // Access line item properties console.log(lineItem.id); console.log(lineItem.scoreMaximum); console.log(lineItem.label); // Example with error handling try { const lineItem = await client.getLineItem("12345"); // Process line item data } catch (error) { // Handle any errors console.error("Failed to fetch line item:", error); } ``` -------------------------------- ### Retrieving and Processing Raw LTI ID Token (TypeScript) Source: https://github.com/ltiaas/ltiaas-node-sdk/blob/main/Readme.md This snippet illustrates how to fetch the raw, unprocessed LTI ID token using `client.getRawIdToken()`. It demonstrates checking the `ltiVersion` property to conditionally handle LTI 1.3 and LTI 1.2 token structures, accessing specific claims like `iss` for LTI 1.3 or `resource_link_id` for LTI 1.2. ```typescript // Get raw ID token const rawToken = await client.getRawIdToken(); // Check LTI version and handle accordingly if (rawToken.ltiVersion === "1.3.0") { // Handle LTI 1.3 token console.log(rawToken.iss); console.log(rawToken["https://purl.imsglobal.org/spec/lti/claim/message_type"]); } else { // Handle LTI 1.2 token console.log(rawToken.resource_link_id); console.log(rawToken.lti_message_type); } ``` -------------------------------- ### Retrieving Scores for a Line Item with LTI SaaS Node.js SDK (TypeScript) Source: https://github.com/ltiaas/ltiaas-node-sdk/blob/main/Readme.md This section illustrates how to retrieve scores for a given line item using the client.getScores method. It explains how to apply optional ResultsFilter parameters like limit, offset, userId, url, and timestamp to refine the results. The method returns a Promise resolving to a ResultContainer object, which includes an array of score results and pagination metadata. ```typescript // Get all scores for a line item const allScores = await client.getScores("lineitem-123"); // Get scores with filters const filteredScores = await client.getScores("lineitem-123", { limit: 10, offset: 0, userId: "student-456" }); // Access score data console.log(filteredScores.results); // Array of score results console.log(filteredScores.totalItems); // Total count of scores ``` -------------------------------- ### Handling InvalidSessionError in LTIaaS SDK (JavaScript) Source: https://github.com/ltiaas/ltiaas-node-sdk/blob/main/Readme.md This snippet demonstrates how to catch and handle `InvalidSessionError` when an SDK method is called with an incorrect authentication type. It shows how to access `currentSession` and `allowedSessionTypes` properties of the error to provide informative feedback about the session mismatch. ```js try { await client.getIdToken(); // Requires LTIK authentication } catch (error) { if (error instanceof InvalidSessionError) { console.error(`Current session: ${error.currentSession}`); console.error(`Allowed sessions: ${error.allowedSessionTypes.join(', ')}`); } } ``` -------------------------------- ### Deactivating an LTI Platform (TypeScript) Source: https://github.com/ltiaas/ltiaas-node-sdk/blob/main/Readme.md This snippet shows how to deactivate an LTI platform integration, preventing further launches and interactions. It requires the platform's unique id and returns a void Promise. Deactivated platforms can be reactivated later. ```TypeScript // Deactivate a platform await client.deactivatePlatform("platform-123"); ``` === COMPLETE CONTENT === This response contains all available snippets from this library. No additional content exists. Do not make further requests.