@lti-tool/core 0.13.0 → 0.13.2

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -18,6 +18,13 @@ import type { TokenService } from './token.service.js';
18
18
  * @see https://www.imsglobal.org/spec/lti-ags/v2p0
19
19
  */
20
20
  export class AGSService {
21
+ /**
22
+ * Creates a new AGSService instance.
23
+ *
24
+ * @param tokenService - Token service for obtaining OAuth2 bearer tokens
25
+ * @param storage - Storage adapter for retrieving launch configurations
26
+ * @param logger - Logger instance for debug and error logging
27
+ */
21
28
  constructor(
22
29
  private tokenService: TokenService,
23
30
  private storage: LTIStorage,
@@ -243,6 +250,16 @@ export class AGSService {
243
250
  * @param updateLineItem - Updated line item data including all required fields
244
251
  * @returns Promise resolving to the HTTP response containing the updated line item
245
252
  * @throws {Error} When AGS line item service is not available for the session or update fails
253
+ *
254
+ * @example
255
+ * ```typescript
256
+ * const response = await agsService.updateLineItem(session, {
257
+ * label: 'Quiz 1 (Updated)',
258
+ * scoreMaximum: 100,
259
+ * tag: 'quiz'
260
+ * });
261
+ * const updatedLineItem = await response.json();
262
+ * ```
246
263
  */
247
264
  async updateLineItem(
248
265
  session: LTISession,
@@ -276,6 +293,12 @@ export class AGSService {
276
293
  * @param session - Active LTI session containing AGS line item endpoint configuration
277
294
  * @returns Promise resolving to the HTTP response (typically 204 No Content on success)
278
295
  * @throws {Error} When AGS line item service is not available for the session or deletion fails
296
+ *
297
+ * @example
298
+ * ```typescript
299
+ * const response = await agsService.deleteLineItem(session);
300
+ * console.log('Line item deleted successfully');
301
+ * ```
279
302
  */
280
303
  async deleteLineItem(session: LTISession): Promise<Response> {
281
304
  if (!session.services?.ags?.lineitem) {
@@ -8,11 +8,16 @@ import type { DeepLinkingContentItem } from '../schemas/lti13/deepLinking/conten
8
8
  * Deep Linking service for LTI 1.3.
9
9
  * Generates signed JWT responses containing selected content items to return to the platform.
10
10
  *
11
- * @param keyPair - RSA key pair for signing client assertion JWTs (must be RS256 compatible)
12
- * @param keyId - Key identifier for JWT header, should match JWKS key ID (defaults to 'main')
13
11
  * @see https://www.imsglobal.org/spec/lti-dl/v2p0
14
12
  */
15
13
  export class DeepLinkingService {
14
+ /**
15
+ * Creates a new DeepLinkingService instance.
16
+ *
17
+ * @param keyPair - RSA key pair for signing client assertion JWTs (must be RS256 compatible)
18
+ * @param logger - Logger instance for debug and error logging
19
+ * @param keyId - Key identifier for JWT header, should match JWKS key ID (defaults to 'main')
20
+ */
16
21
  constructor(
17
22
  private keyPair: CryptoKeyPair,
18
23
  private logger: BaseLogger,
@@ -25,7 +30,7 @@ export class DeepLinkingService {
25
30
  *
26
31
  * @param session - Active LTI session containing Deep Linking configuration
27
32
  * @param contentItems - Array of content items selected by the user
28
- * @returns HTML string containing auto-submit form
33
+ * @returns Promise resolving to an HTML string containing auto-submit form
29
34
  * @throws {Error} When Deep Linking is not available for the session
30
35
  *
31
36
  * @example
@@ -65,7 +70,7 @@ export class DeepLinkingService {
65
70
  *
66
71
  * @param session - Active LTI session with Deep Linking configuration
67
72
  * @param contentItems - Array of selected content items
68
- * @returns Signed JWT string
73
+ * @returns Promise resolving to a signed JWT string
69
74
  */
70
75
  private async createDeepLinkingJWT(
71
76
  session: LTISession,
@@ -63,6 +63,13 @@ import {
63
63
  * @see https://www.imsglobal.org/spec/lti-dr/v1p0 LTI 1.3 Dynamic Registration specification
64
64
  */
65
65
  export class DynamicRegistrationService {
66
+ /**
67
+ * Creates a new DynamicRegistrationService instance.
68
+ *
69
+ * @param storage - Storage adapter for persisting client and deployment configurations
70
+ * @param dynamicRegistrationConfig - Tool configuration including URLs and service settings
71
+ * @param logger - Logger instance for debug and error logging
72
+ */
66
73
  constructor(
67
74
  private storage: LTIStorage,
68
75
  private dynamicRegistrationConfig: DynamicRegistrationConfig,
@@ -13,6 +13,13 @@ import type { TokenService } from './token.service.js';
13
13
  * @see https://www.imsglobal.org/spec/lti-nrps/v2p0
14
14
  */
15
15
  export class NRPSService {
16
+ /**
17
+ * Creates a new NRPSService instance.
18
+ *
19
+ * @param tokenService - Token service for obtaining OAuth2 bearer tokens
20
+ * @param storage - Storage adapter for retrieving launch configurations
21
+ * @param logger - Logger instance for debug and error logging
22
+ */
16
23
  constructor(
17
24
  private tokenService: TokenService,
18
25
  private storage: LTIStorage,
@@ -24,8 +31,15 @@ export class NRPSService {
24
31
  * Returns raw response that should be parsed by the calling service.
25
32
  *
26
33
  * @param session - Active LTI session containing NRPS service endpoints
27
- * @returns Raw HTTP response containing membership data
34
+ * @returns Promise resolving to the HTTP response containing membership data
28
35
  * @throws {Error} When NRPS is not available for this session or request fails
36
+ *
37
+ * @example
38
+ * ```typescript
39
+ * const response = await nrpsService.getMembers(session);
40
+ * const data = await response.json();
41
+ * console.log('Course members:', data.members);
42
+ * ```
29
43
  */
30
44
  async getMembers(session: LTISession): Promise<Response> {
31
45
  if (!session.services?.nrps?.membershipUrl) {
@@ -6,6 +6,8 @@ import { SignJWT } from 'jose';
6
6
  *
7
7
  * Implements RFC 7523 (JWT Profile for OAuth 2.0 Client Authentication and Authorization Grants)
8
8
  * as required by LTI 1.3 security framework.
9
+ *
10
+ * @see https://www.rfc-editor.org/rfc/rfc7523
9
11
  */
10
12
  export class TokenService {
11
13
  /**
@@ -24,7 +26,7 @@ export class TokenService {
24
26
  *
25
27
  * @param clientId - OAuth2 client identifier
26
28
  * @param tokenUrl - Platform's token endpoint URL
27
- * @returns Signed JWT client assertion
29
+ * @returns Promise resolving to a signed JWT client assertion string
28
30
  */
29
31
  async createClientAssertion(clientId: string, tokenUrl: string): Promise<string> {
30
32
  return await new SignJWT({
@@ -49,7 +51,8 @@ export class TokenService {
49
51
  * @param clientId - OAuth2 client identifier
50
52
  * @param tokenUrl - Platform's token endpoint URL
51
53
  * @param scope - Requested OAuth2 scope (e.g., AGS score scope)
52
- * @returns Bearer access token for API calls
54
+ * @returns Promise resolving to a bearer access token string for API calls
55
+ * @throws {Error} When the token request fails or response is missing access_token
53
56
  */
54
57
  async getBearerToken(
55
58
  clientId: string,
@@ -0,0 +1,22 @@
1
+ /**
2
+ * Formats an unknown error into a readable string message.
3
+ * Handles Error objects, strings, and other types safely.
4
+ *
5
+ * @param error - The error to format (can be Error, string, or any other type)
6
+ * @returns Formatted error message string
7
+ *
8
+ * @example
9
+ * ```typescript
10
+ * try {
11
+ * await riskyOperation();
12
+ * } catch (error) {
13
+ * throw new Error(`Operation failed: ${formatError(error)}`);
14
+ * }
15
+ * ```
16
+ */
17
+ export function formatError(error: unknown): string {
18
+ if (error instanceof Error) {
19
+ return error.message;
20
+ }
21
+ return String(error);
22
+ }