@openlearning/xapi
Advanced tools
Comparing version
import { XApiState } from "./lrs"; | ||
import { XApiConfig } from "./xapi-interface"; | ||
export declare const saveActivityState: (config: XApiConfig, stateId: string, state: XApiState) => Promise<boolean>; | ||
export declare const retrieveActivityState: (config: XApiConfig, stateId: string, isNullOnNotFound?: boolean) => Promise<XApiState>; | ||
export declare const retrieveActivityState: (config: XApiConfig, stateId: string, defaultValue?: import("./statement").JsonSerializableObject | undefined) => Promise<XApiState>; |
@@ -15,3 +15,3 @@ "use strict"; | ||
exports.saveActivityState = saveActivityState; | ||
const retrieveActivityState = (config, stateId, isNullOnNotFound = false) => { | ||
const retrieveActivityState = (config, stateId, defaultValue) => { | ||
if (!config) { | ||
@@ -25,4 +25,4 @@ return Promise.reject({ | ||
return lrs.retrieveActivityState(config.activity_id, stateId, config.actor).then((response) => { | ||
if (isNullOnNotFound && response.status === 404) { | ||
return Promise.resolve(null); | ||
if (defaultValue && response.status === 404) { | ||
return Promise.resolve(defaultValue); | ||
} | ||
@@ -29,0 +29,0 @@ else if (response.status !== 200) { |
{ | ||
"name": "@openlearning/xapi", | ||
"version": "0.1.2", | ||
"version": "0.1.3", | ||
"main": "dist/index.js", | ||
@@ -19,2 +19,3 @@ "types": "dist/index.d.ts", | ||
"build": "tsc", | ||
"bundle": "webpack", | ||
"prepare": "npm run build", | ||
@@ -25,9 +26,15 @@ "version": "git add -A src", | ||
"devDependencies": { | ||
"typescript": "^4.2.4" | ||
"@babel/core": "^7.14.5", | ||
"@babel/preset-env": "^7.14.5", | ||
"ts-loader": "^9.2.3", | ||
"typescript": "^4.3.2", | ||
"webpack": "^5.38.1", | ||
"webpack-cli": "^4.7.2" | ||
}, | ||
"dependencies": {}, | ||
"files": [ | ||
"dist", | ||
"vendor" | ||
] | ||
"dist" | ||
], | ||
"dependencies": { | ||
"babel-loader": "^8.2.2" | ||
} | ||
} |
@@ -11,3 +11,3 @@ # xApi Client Library for OpenLearning | ||
``` | ||
```javascript | ||
import { | ||
@@ -21,6 +21,14 @@ initLrs, | ||
} from "@openlearning/xapi"; | ||
``` | ||
The webpage will be loaded with query string arguments that configure the LRS connection. | ||
The `initLrs` function returns the configuration retrieved from the query (search) string. | ||
```javascript | ||
// on load | ||
const lrsConfig = initLrs(); | ||
``` | ||
Once an LRS connection is configured, this config can be used with the other functions, | ||
e.g. to mark this activity as completed: | ||
```javascript | ||
// mark as completed | ||
@@ -31,4 +39,7 @@ saveCompletion(lrsConfig); | ||
saveCompletion(lrsConfig, myData); | ||
``` | ||
// publish attachments (default, optional last argument) | ||
Or to send file URLs to OpenLearning as attachments that can then be shared by the learner: | ||
```javascript | ||
// publish (replace) attachments (default, last argument is optional) | ||
saveAttachments(lrsConfig, [{ | ||
@@ -48,3 +59,9 @@ contentType: "text/plain", | ||
}], "attached"); | ||
``` | ||
Activity State can also be set and retrieved for the current user of this activity: | ||
Note, to use these, the setting: "OpenLearning LRS: Use OpenLearning to store xAPI documents and state (Experimental)" | ||
needs to be activated under Course Setup > Advanced. | ||
```javascript | ||
// store state (for the activity and current user) | ||
@@ -59,1 +76,33 @@ saveActivityState(lrsConfig, stateId, state); | ||
``` | ||
## Standalone Bundle | ||
If you're not using npm (e.g. you're not building with webpack, etc.) and want to just use a `<script>` tag, using: | ||
```html | ||
<script src="./bundle/openlearning-xapi.js"></script"> | ||
``` | ||
will define: | ||
```javascript | ||
window.xApi = { | ||
initLrs, | ||
saveStatement, | ||
saveAttachments, | ||
saveCompletion, | ||
saveActivityState, | ||
retrieveActivityState | ||
}; | ||
``` | ||
## Development | ||
Build the `./dist` folder: | ||
``` | ||
npm run build | ||
``` | ||
Build the standalone bundle: `./bundle/openlearning-xapi.js`: | ||
``` | ||
npm run bundle | ||
``` |
Sorry, the diff of this file is not supported yet
24592
6.45%104
89.09%1
Infinity%6
500%+ Added
+ Added
+ Added
+ Added
+ Added
+ Added
+ Added
+ Added
+ Added
+ Added
+ Added
+ Added
+ Added
+ Added
+ Added
+ Added
+ Added
+ Added
+ Added
+ Added
+ Added
+ Added
+ Added
+ Added
+ Added
+ Added
+ Added
+ Added
+ Added
+ Added
+ Added
+ Added
+ Added
+ Added
+ Added
+ Added
+ Added
+ Added
+ Added
+ Added
+ Added
+ Added
+ Added
+ Added
+ Added
+ Added
+ Added
+ Added
+ Added
+ Added
+ Added
+ Added
+ Added
+ Added
+ Added
+ Added
+ Added
+ Added
+ Added
+ Added
+ Added
+ Added
+ Added
+ Added
+ Added
+ Added
+ Added
+ Added
+ Added
+ Added
+ Added
+ Added
+ Added
+ Added
+ Added
+ Added
+ Added
+ Added
+ Added
+ Added
+ Added
+ Added
+ Added
+ Added
+ Added
+ Added
+ Added
+ Added
+ Added
+ Added
+ Added
+ Added
+ Added
+ Added
+ Added
+ Added
+ Added
+ Added
+ Added
+ Added
+ Added
+ Added
+ Added
+ Added
+ Added
+ Added
+ Added
+ Added
+ Added
+ Added
+ Added
+ Added
+ Added
+ Added
+ Added
+ Added
+ Added
+ Added
+ Added
+ Added
+ Added