Usage example:

import { ScormClient } from 'scorm-client'

const client = new ScormClient(appId, secretKey, "read")

// will fetch a course using a token with the default scope, in this case 'read'
const course: Course = await client.getCourse(courseId)

// will delete a course using a token with 'write' scope
const result: SuccessIndicator = await client.deleteCourse(courseId, { scope: 'write' })

You will notice that no call has been made to the authenticate() method before starting to use the client. When a method is invoked and no valid auth token for the given scope can be found, then the client will attempt to authenticate and fetch a token for that scope. As such, tokens are explicitly associated with a specific scope, and the client will internally manage a set of tokens and their associated scopes.

Any future calls for a given scope will use the token associated with it. If no scope is specified (in the options for a method), then the default scope (assigned at client instantiation) will be assumed. You are able to manually authenticate() different scopes, which is simply asking the client to fetch and store a token for a scope, such that it is immediately available in method calls later.

Note: the scope can also be a list of space separated scopes, e.g. "write:course read:registration". In such a case the token will be associated with all the specified scopes.

Hierarchy

  • ScormClient

Constructors

  • Parameters

    • appId: string

      A SCORM Cloud application ID

    • secretKey: string

      The secret key for the given application ID

    • defaultScope: string

      An auth scope or space separated list of scopes, e.g. "write:course read:registration". This will be the default scope used if a method on the client is invoked without specifying an explicit scope in the method's Options

    • defaultExpiry: number = 3600

      The amount of time, in seconds, after which auth tokens should expire. If unspecified, it will default to 3600 (1 hour)

    Returns ScormClient

Methods

  • Attempt to authenticate and store an auth token, associated with a given scope

    Throws

    ScormClientError with an httpStatus of 401 on authentication failure

    Parameters

    • scope: string

      An auth scope or space separated list of scopes

    • Optional expiry: number

      The amount of time, in seconds, after which the auth token should expire. If unspecified, it will use the default value provided in the constructor.

    Returns Promise<AuthToken>

  • Get a launch link, which is a relatively short lived url, used to launch the course for a given registration. Launch links are meant as a way to provide access to your content. When a learner visits the link, the course will be launched and registration progress will start to be tracked.

    API Method - BuildRegistrationLaunchLink

    Parameters

    • registrationId: string

      The registration ID for which to create and return a launch link

    • redirectOnExitUrl: string

      The URL the application should redirect to when the learner exits or completes a course. Alternatively one of the following keywords can be used:

      • closer : A page that automatically tries to close the browser tab/window
      • blank : A blank page
      • message : A page with a message about the course being complete

      If an invalid url is specified, the Message.html page will be loaded

    • options: LaunchLinkOptions = {}

      LaunchLinkOptions

    Returns Promise<LaunchLink>

  • Creates a new registration. Registrations are the billable unit in SCORM Cloud, and represents the link between a learner and a course. A registration will contain a few pieces of information such as learner identifiers, the id of the course being registered for, and several other optional fields.

    A registration must be tied to a specific course at creation time. When the registration is "launched" (see createLaunchLink), the course specified at creation time will be launched.

    API Method - CreateRegistration

    Throws

    ScormClientError if an invalid request was made, or an error encountered, or if the referenced course or learner does not exist, or if creating a duplicate registration

    Returns

    A SuccessIndicator

    Parameters

    • registrationId: string

      An ID for this registration

    • courseId: string

      The course ID for which the learner should be registered

    • learner: Learner

      The details of the learner, at minimum a learner ID should be specified

    • options: RegistrationOptions = {}

      RegistrationOptions

    Returns Promise<SuccessIndicator>

  • Deletes the specified version of the course. If deleting the last remaining version of the course, the course itself will be deleted and no longer accessible. When a course is deleted, so is everything connected to the course. This includes:

    • Registrations
    • Invitations
    • Dispatches
    • Debug Logs

    API Method - DeleteCourseVersion

    Throws

    ScormClientError if an invalid request was made, or an error encountered, or if the referenced course does not exist

    Returns

    A SuccessIndicator

    Parameters

    • courseId: string

      The course ID

    • versionNumber: number

      The version number

    • options: Options = {}

      Options

    Returns Promise<SuccessIndicator>

  • Check the status of a course import. This can be called incrementally to check the progress of a call to any of the import options. Note: The import job ID is only valid for one week after the course import finishes.

    API Method - GetImportJobStatus

    Throws

    ScormClientError if an invalid request was made, or an error encountered

    Returns

    A ImportJobResult, or undefined if no job result was not found

    Parameters

    • jobId: string

      The import job ID

    • options: Options = {}

      Options

    Returns Promise<undefined | ImportJobResult>

  • TODO: Test this function to see what happens with non-existent courses and/or course versions and confirm what is return and what is thrown. Update the function to handle scenarios appropriately ...

    Returns information about all versions of the course. This can be useful to see information such as registration counts and modification times across the versions of a course.

    API Method - GetCourseVersions

    Throws

    ScormClientError if an invalid request was made, or an error encountered,

    Returns

    An array of Course, or an empty array if no courses were found. This method does not support pagination, all versions will be returned

    Parameters

    Returns Promise<undefined | Course[]>

  • Returns a list of courses. Can be filtered to provide a subset of results.

    This request is paginated and will only provide a limited amount of resources at a time. If there are more results to be collected, a more token provided with the response which can be passed to get the next page of results. When passing this token, no other filter parameters can be sent as part of the request. The resources will continue to respect the filters passed in by the original request.

    API Method - GetCourses

    Throws

    ScormClientError if an invalid request was made, or an error encountered

    Returns

    A CourseQueryResponse that has a property named courses, which is an array of type Course, or an empty array if no courses were found. It also includes a 'more' property which, if present, can be used to retrieve the next paginated set of results

    Parameters

    Returns Promise<CourseQueryResponse>

  • Returns a list of registrations. Can be filtered to provide a subset of results.

    This request is paginated and will only provide a limited amount of resources at a time. If there are more results to be collected, a more token provided with the response which can be passed to get the next page of results. When passing this token, no other filter parameters can be sent as part of the request. The resources will continue to respect the filters passed in by the original request.

    API Method - GetRegistrations

    Throws

    ScormClientError if an invalid request was made, or an error encountered

    Returns

    A RegistrationQueryResponse that has a property named registrations, which is an array of type Registration, or an empty array if no registrations were found. It also includes a 'more' property which, if present, can be used to retrieve the next paginated set of results

    Parameters

    Returns Promise<RegistrationQueryResponse>

  • Returns a list of registrations for the given course. Can be filtered to provide a subset of results.

    This request is paginated and will only provide a limited amount of resources at a time. If there are more results to be collected, a more token provided with the response which can be passed to get the next page of results. When passing this token, no other filter parameters can be sent as part of the request. The resources will continue to respect the filters passed in by the original request.

    API Method - GetRegistrations

    Throws

    ScormClientError if an invalid request was made, or an error encountered

    Returns

    A RegistrationQueryResponse that has a property named registrations, which is an array of type Registration, or an empty array if no registrations were found. It also includes a 'more' property which, if present, can be used to retrieve the next paginated set of results

    Parameters

    • courseId: string

      The course ID for which to return registrations

    • options: RegistrationQueryOptions = {}

      RegistrationQueryOptions

    Returns Promise<RegistrationQueryResponse>

  • Returns a list of registrations for the given learner. Can be filtered to provide a subset of results.

    This request is paginated and will only provide a limited amount of resources at a time. If there are more results to be collected, a more token provided with the response which can be passed to get the next page of results. When passing this token, no other filter parameters can be sent as part of the request. The resources will continue to respect the filters passed in by the original request.

    API Method - GetRegistrations

    Throws

    ScormClientError if an invalid request was made, or an error encountered

    Returns

    A RegistrationQueryResponse that has a property named registrations, which is an array of type Registration, or an empty array if no registrations were found. It also includes a 'more' property which, if present, can be used to retrieve the next paginated set of results

    Parameters

    • learnerId: string

      The learner ID for which to return registrations

    • options: RegistrationQueryOptions = {}

      RegistrationQueryOptions

    Returns Promise<RegistrationQueryResponse>

  • Checks that the registration exists within SCORM Cloud. No registration data will be returned for this call. If you are looking for information about the registration, try using getRegistration instead.

    API Method - GetRegistration

    Throws

    ScormClientError if an invalid request was made

    Returns

    A boolean true or false

    Parameters

    • registrationId: string

      An ID for which registration to check

    • options: Options = {}

      Options

    Returns Promise<Boolean>

  • Creates or updates an asset file uploaded from your file system into the course version. The file will be sent as part of the request and will be stored in SCORM Cloud alongside the course. This is a useful way to modify the course structure without needing to reimport the whole course after you've made changes.

    If the course structure is being heavily modified, consider creating a new version instead. This can be done by calling importCourse, while passing true for mayCreateNewVersion

    API Method - UploadCourseVersionAssetFile

    Throws

    ScormClientError if an invalid request was made, or an error encountered

    Returns

    A types.CourseVersionAssetUploadResponse if successfull

    Parameters

    • courseId: string

      The course ID

    • versionNumber: number

      The version number

    • filePath: string

      The local path to the file that must be imported to SCORM Cloud

    • destinationPath: string

      The relative path from the course's base directory on SCORM Cloud, to where the asset file will be uploaded

    • options: CourseVersionAssetUploadOptions = {}

      CourseVersionAssetUploadOptions

    Returns Promise<SuccessIndicator>

Generated using TypeDoc