Appearance
Configuration
The startActivitySolver function accepts a configuration object as its second argument. This object allows you to customize the activity solver behavior and set some important options.
The only required options are the api auth options, which are used to authenticate the activity solver with the Mathew API.
Auth
HMAC-based auth
We use an HMAC-based system to authenticate the activity solver with the Mathew API. You get an API key (public/frontend) and an API secret (private/backend). You will use the API key to authenticate with the Mathew API and the API secret to create the signature needed to verify this authentication.
The signature has to be encoded in base 64. We accept the following methods to create the hash:
- HMAC-SHA512
- HMAC-SHA384
- HMAC-SHA256
The process is the following:
- Get an API key and and API secret from Mathew.
- Store the API secret securely in your backend (an env variable is a good choice).
- Before the user starts using the activity solver, use their user id to calculate the HMAC signature:
- Hash the user id (with the chosen SHAXXX)
- Encoded it to base 64
- Sign the user id hash with the API secret (with the chosen SHAXXX)
- Encoded it to base 64
- Initialize the activity solver with the HMAC signature, the user id and the API key.
javascript
import { startActivitySolver } from '@adaptical/mathew-activity-solver'
import '@adaptical/mathew-activity-solver/style.css'
const activitySolverRoot = document.querySelector('#app')
const apiKey = '<your-mathew-api-key>'
const userId = '<current-user-id>'
const method = 'HMAC-SHA256' // 'HMAC-SHA512' | 'HMAC-SHA384' | 'HMAC-SHA256'
const userIdHmac = await getUserIdHmac(userId) // Create this user id HMAC in your backend using your api secret
const apiAuth = { method, apiKey, userId, userIdHmac }
const activitySolverOptions = {
api: { auth: apiAuth },
language: 'en', // Optional: set interface language
}
startActivitySolver(activitySolverRoot, activitySolverOptions)Options
| Option | Default | Description |
|---|---|---|
| api | - | object Api auth configuration. |
| language | Browser language or 'es' | string Interface language. Supported: 'es', 'en', 'ca' |
| allowStudentAutoEvaluation | false in activity solving, true in autonomous practice | boolean Can the student evaluate each exercise? |
| showEndSummary | false in activity solving, true in autonomous practice | boolean Will the student see the end summary? |
Activity solver options
| Option | Default | Description |
|---|---|---|
| exercises | - | Exercise[] The exercises of the activity |
Autonomous practice options
| Option | Default | Description |
|---|---|---|
| activityId | - | string The id of the activity you want to show. Used to recover a completed activity to show its results. |
| content | - | { book: { isbn: string; section: string } } The content on which the activity will be based. It's the section of a book. |