@lessonkit/xapi 0.1.0
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.
- package/README.md +25 -0
- package/dist/index.cjs +64 -0
- package/dist/index.d.cts +30 -0
- package/dist/index.d.ts +30 -0
- package/dist/index.js +39 -0
- package/package.json +54 -0
package/README.md
ADDED
|
@@ -0,0 +1,25 @@
|
|
|
1
|
+
# `@lessonkit/xapi`
|
|
2
|
+
|
|
3
|
+
xAPI statement generation primitives.
|
|
4
|
+
|
|
5
|
+
## Install
|
|
6
|
+
|
|
7
|
+
```bash
|
|
8
|
+
npm install @lessonkit/xapi
|
|
9
|
+
```
|
|
10
|
+
|
|
11
|
+
## Quick example
|
|
12
|
+
|
|
13
|
+
```ts
|
|
14
|
+
import { createXAPIClient } from "@lessonkit/xapi";
|
|
15
|
+
|
|
16
|
+
const xapi = createXAPIClient({
|
|
17
|
+
transport: (statement) => {
|
|
18
|
+
// Send to your LRS (or queue offline).
|
|
19
|
+
console.log(statement);
|
|
20
|
+
},
|
|
21
|
+
});
|
|
22
|
+
|
|
23
|
+
xapi.completeLesson({ lessonId: "phishing-101" });
|
|
24
|
+
```
|
|
25
|
+
|
package/dist/index.cjs
ADDED
|
@@ -0,0 +1,64 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
var __defProp = Object.defineProperty;
|
|
3
|
+
var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
|
|
4
|
+
var __getOwnPropNames = Object.getOwnPropertyNames;
|
|
5
|
+
var __hasOwnProp = Object.prototype.hasOwnProperty;
|
|
6
|
+
var __export = (target, all) => {
|
|
7
|
+
for (var name in all)
|
|
8
|
+
__defProp(target, name, { get: all[name], enumerable: true });
|
|
9
|
+
};
|
|
10
|
+
var __copyProps = (to, from, except, desc) => {
|
|
11
|
+
if (from && typeof from === "object" || typeof from === "function") {
|
|
12
|
+
for (let key of __getOwnPropNames(from))
|
|
13
|
+
if (!__hasOwnProp.call(to, key) && key !== except)
|
|
14
|
+
__defProp(to, key, { get: () => from[key], enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable });
|
|
15
|
+
}
|
|
16
|
+
return to;
|
|
17
|
+
};
|
|
18
|
+
var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);
|
|
19
|
+
|
|
20
|
+
// src/index.ts
|
|
21
|
+
var index_exports = {};
|
|
22
|
+
__export(index_exports, {
|
|
23
|
+
createXAPIClient: () => createXAPIClient
|
|
24
|
+
});
|
|
25
|
+
module.exports = __toCommonJS(index_exports);
|
|
26
|
+
var import_core = require("@lessonkit/core");
|
|
27
|
+
function createXAPIClient(opts) {
|
|
28
|
+
const transport = opts?.transport;
|
|
29
|
+
const baseId = opts?.baseId ?? "urn:lessonkit";
|
|
30
|
+
return {
|
|
31
|
+
send: (statement) => {
|
|
32
|
+
void transport?.(statement);
|
|
33
|
+
},
|
|
34
|
+
startedLesson: ({ lessonId }) => {
|
|
35
|
+
const statement = statementFor(`${baseId}:lesson:${lessonId}`, "started");
|
|
36
|
+
void transport?.(statement);
|
|
37
|
+
},
|
|
38
|
+
completeLesson: ({ lessonId }) => {
|
|
39
|
+
const statement = statementFor(`${baseId}:lesson:${lessonId}`, "completed");
|
|
40
|
+
void transport?.(statement);
|
|
41
|
+
},
|
|
42
|
+
completeCourse: () => {
|
|
43
|
+
const statement = statementFor(`${baseId}:course`, "completed");
|
|
44
|
+
void transport?.(statement);
|
|
45
|
+
}
|
|
46
|
+
};
|
|
47
|
+
}
|
|
48
|
+
function statementFor(objectId, verb) {
|
|
49
|
+
return {
|
|
50
|
+
id: cryptoRandomId(),
|
|
51
|
+
timestamp: (0, import_core.nowIso)(),
|
|
52
|
+
verb,
|
|
53
|
+
object: { id: objectId }
|
|
54
|
+
};
|
|
55
|
+
}
|
|
56
|
+
function cryptoRandomId() {
|
|
57
|
+
const g = globalThis;
|
|
58
|
+
if (g.crypto?.randomUUID) return g.crypto.randomUUID();
|
|
59
|
+
return Math.random().toString(16).slice(2);
|
|
60
|
+
}
|
|
61
|
+
// Annotate the CommonJS export names for ESM import in node:
|
|
62
|
+
0 && (module.exports = {
|
|
63
|
+
createXAPIClient
|
|
64
|
+
});
|
package/dist/index.d.cts
ADDED
|
@@ -0,0 +1,30 @@
|
|
|
1
|
+
import { LessonId } from '@lessonkit/core';
|
|
2
|
+
|
|
3
|
+
type XAPIStatement = {
|
|
4
|
+
id: string;
|
|
5
|
+
timestamp: string;
|
|
6
|
+
verb: string;
|
|
7
|
+
object: {
|
|
8
|
+
id: string;
|
|
9
|
+
definition?: Record<string, unknown>;
|
|
10
|
+
};
|
|
11
|
+
result?: Record<string, unknown>;
|
|
12
|
+
context?: Record<string, unknown>;
|
|
13
|
+
};
|
|
14
|
+
type XAPITransport = (statement: XAPIStatement) => void | Promise<void>;
|
|
15
|
+
type XAPIClient = {
|
|
16
|
+
send: (statement: XAPIStatement) => void;
|
|
17
|
+
completeLesson: (opts: {
|
|
18
|
+
lessonId: LessonId;
|
|
19
|
+
}) => void;
|
|
20
|
+
startedLesson: (opts: {
|
|
21
|
+
lessonId: LessonId;
|
|
22
|
+
}) => void;
|
|
23
|
+
completeCourse: (opts: {}) => void;
|
|
24
|
+
};
|
|
25
|
+
declare function createXAPIClient(opts?: {
|
|
26
|
+
transport?: XAPITransport;
|
|
27
|
+
baseId?: string;
|
|
28
|
+
}): XAPIClient;
|
|
29
|
+
|
|
30
|
+
export { type XAPIClient, type XAPIStatement, type XAPITransport, createXAPIClient };
|
package/dist/index.d.ts
ADDED
|
@@ -0,0 +1,30 @@
|
|
|
1
|
+
import { LessonId } from '@lessonkit/core';
|
|
2
|
+
|
|
3
|
+
type XAPIStatement = {
|
|
4
|
+
id: string;
|
|
5
|
+
timestamp: string;
|
|
6
|
+
verb: string;
|
|
7
|
+
object: {
|
|
8
|
+
id: string;
|
|
9
|
+
definition?: Record<string, unknown>;
|
|
10
|
+
};
|
|
11
|
+
result?: Record<string, unknown>;
|
|
12
|
+
context?: Record<string, unknown>;
|
|
13
|
+
};
|
|
14
|
+
type XAPITransport = (statement: XAPIStatement) => void | Promise<void>;
|
|
15
|
+
type XAPIClient = {
|
|
16
|
+
send: (statement: XAPIStatement) => void;
|
|
17
|
+
completeLesson: (opts: {
|
|
18
|
+
lessonId: LessonId;
|
|
19
|
+
}) => void;
|
|
20
|
+
startedLesson: (opts: {
|
|
21
|
+
lessonId: LessonId;
|
|
22
|
+
}) => void;
|
|
23
|
+
completeCourse: (opts: {}) => void;
|
|
24
|
+
};
|
|
25
|
+
declare function createXAPIClient(opts?: {
|
|
26
|
+
transport?: XAPITransport;
|
|
27
|
+
baseId?: string;
|
|
28
|
+
}): XAPIClient;
|
|
29
|
+
|
|
30
|
+
export { type XAPIClient, type XAPIStatement, type XAPITransport, createXAPIClient };
|
package/dist/index.js
ADDED
|
@@ -0,0 +1,39 @@
|
|
|
1
|
+
// src/index.ts
|
|
2
|
+
import { nowIso } from "@lessonkit/core";
|
|
3
|
+
function createXAPIClient(opts) {
|
|
4
|
+
const transport = opts?.transport;
|
|
5
|
+
const baseId = opts?.baseId ?? "urn:lessonkit";
|
|
6
|
+
return {
|
|
7
|
+
send: (statement) => {
|
|
8
|
+
void transport?.(statement);
|
|
9
|
+
},
|
|
10
|
+
startedLesson: ({ lessonId }) => {
|
|
11
|
+
const statement = statementFor(`${baseId}:lesson:${lessonId}`, "started");
|
|
12
|
+
void transport?.(statement);
|
|
13
|
+
},
|
|
14
|
+
completeLesson: ({ lessonId }) => {
|
|
15
|
+
const statement = statementFor(`${baseId}:lesson:${lessonId}`, "completed");
|
|
16
|
+
void transport?.(statement);
|
|
17
|
+
},
|
|
18
|
+
completeCourse: () => {
|
|
19
|
+
const statement = statementFor(`${baseId}:course`, "completed");
|
|
20
|
+
void transport?.(statement);
|
|
21
|
+
}
|
|
22
|
+
};
|
|
23
|
+
}
|
|
24
|
+
function statementFor(objectId, verb) {
|
|
25
|
+
return {
|
|
26
|
+
id: cryptoRandomId(),
|
|
27
|
+
timestamp: nowIso(),
|
|
28
|
+
verb,
|
|
29
|
+
object: { id: objectId }
|
|
30
|
+
};
|
|
31
|
+
}
|
|
32
|
+
function cryptoRandomId() {
|
|
33
|
+
const g = globalThis;
|
|
34
|
+
if (g.crypto?.randomUUID) return g.crypto.randomUUID();
|
|
35
|
+
return Math.random().toString(16).slice(2);
|
|
36
|
+
}
|
|
37
|
+
export {
|
|
38
|
+
createXAPIClient
|
|
39
|
+
};
|
package/package.json
ADDED
|
@@ -0,0 +1,54 @@
|
|
|
1
|
+
{
|
|
2
|
+
"name": "@lessonkit/xapi",
|
|
3
|
+
"version": "0.1.0",
|
|
4
|
+
"private": false,
|
|
5
|
+
"description": "xAPI statement generation primitives for LessonKit.",
|
|
6
|
+
"license": "Apache-2.0",
|
|
7
|
+
"repository": {
|
|
8
|
+
"type": "git",
|
|
9
|
+
"url": "git+https://github.com/eddiethedean/lessonkit.git",
|
|
10
|
+
"directory": "packages/xapi"
|
|
11
|
+
},
|
|
12
|
+
"homepage": "https://github.com/eddiethedean/lessonkit",
|
|
13
|
+
"bugs": {
|
|
14
|
+
"url": "https://github.com/eddiethedean/lessonkit/issues"
|
|
15
|
+
},
|
|
16
|
+
"keywords": [
|
|
17
|
+
"lessonkit",
|
|
18
|
+
"xapi",
|
|
19
|
+
"tincan",
|
|
20
|
+
"learning",
|
|
21
|
+
"training",
|
|
22
|
+
"lrs"
|
|
23
|
+
],
|
|
24
|
+
"type": "module",
|
|
25
|
+
"main": "./dist/index.cjs",
|
|
26
|
+
"module": "./dist/index.js",
|
|
27
|
+
"types": "./dist/index.d.ts",
|
|
28
|
+
"exports": {
|
|
29
|
+
".": {
|
|
30
|
+
"types": "./dist/index.d.ts",
|
|
31
|
+
"import": "./dist/index.js",
|
|
32
|
+
"require": "./dist/index.cjs"
|
|
33
|
+
}
|
|
34
|
+
},
|
|
35
|
+
"files": [
|
|
36
|
+
"dist"
|
|
37
|
+
],
|
|
38
|
+
"scripts": {
|
|
39
|
+
"build": "tsup src/index.ts --format esm,cjs --dts",
|
|
40
|
+
"dev": "tsup src/index.ts --format esm,cjs --dts --watch",
|
|
41
|
+
"prepublishOnly": "npm run build",
|
|
42
|
+
"typecheck": "tsc -p tsconfig.json",
|
|
43
|
+
"test": "vitest run --passWithNoTests",
|
|
44
|
+
"lint": "echo \"(no lint configured yet)\""
|
|
45
|
+
},
|
|
46
|
+
"dependencies": {
|
|
47
|
+
"@lessonkit/core": "0.1.0"
|
|
48
|
+
},
|
|
49
|
+
"devDependencies": {
|
|
50
|
+
"tsup": "^8.5.0",
|
|
51
|
+
"typescript": "^5.8.3",
|
|
52
|
+
"vitest": "^3.2.4"
|
|
53
|
+
}
|
|
54
|
+
}
|