@openstax/ts-utils 1.44.1 → 1.44.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.
- package/dist/cjs/services/lrsGateway/addStatementDefaultFields.js +2 -7
- package/dist/cjs/services/lrsGateway/attempt-utils.d.ts +5 -4
- package/dist/cjs/services/lrsGateway/attempt-utils.js +23 -8
- package/dist/cjs/services/lrsGateway/file-system.js +2 -7
- package/dist/cjs/services/lrsGateway/index.d.ts +2 -7
- package/dist/cjs/services/lrsGateway/index.js +4 -25
- package/dist/cjs/tsconfig.without-specs.cjs.tsbuildinfo +1 -1
- package/dist/esm/services/lrsGateway/addStatementDefaultFields.js +2 -7
- package/dist/esm/services/lrsGateway/attempt-utils.d.ts +5 -4
- package/dist/esm/services/lrsGateway/attempt-utils.js +21 -7
- package/dist/esm/services/lrsGateway/file-system.js +2 -7
- package/dist/esm/services/lrsGateway/index.d.ts +2 -7
- package/dist/esm/services/lrsGateway/index.js +2 -23
- package/dist/esm/tsconfig.without-specs.esm.tsbuildinfo +1 -1
- package/package.json +1 -1
|
@@ -1,14 +1,9 @@
|
|
|
1
1
|
import formatISO from 'date-fns/formatISO';
|
|
2
2
|
import { v4 as uuid } from 'uuid';
|
|
3
|
+
import { formatAgent } from './attempt-utils';
|
|
3
4
|
export const addStatementDefaultFields = (statement, user) => ({
|
|
4
5
|
id: uuid(),
|
|
5
|
-
actor:
|
|
6
|
-
account: {
|
|
7
|
-
homePage: 'https://openstax.org',
|
|
8
|
-
name: user.uuid,
|
|
9
|
-
},
|
|
10
|
-
objectType: 'Agent',
|
|
11
|
-
},
|
|
6
|
+
actor: formatAgent(user.uuid),
|
|
12
7
|
timestamp: formatISO(new Date()),
|
|
13
8
|
...statement,
|
|
14
9
|
});
|
|
@@ -1,4 +1,5 @@
|
|
|
1
|
-
import { LrsGateway, UXapiStatement } from '.';
|
|
1
|
+
import { LrsGateway, UXapiStatement, XapiAgent } from '.';
|
|
2
|
+
export declare const formatAgent: (agent: string | XapiAgent) => XapiAgent;
|
|
2
3
|
export declare const EXT_PENDING_SCORING = "https://openstax.org/xapi/extensions/pending-scoring";
|
|
3
4
|
export type AttemptEntry = {
|
|
4
5
|
attempt: UXapiStatement;
|
|
@@ -54,7 +55,7 @@ export declare const createStatement: (verb: UXapiStatement["verb"], activity: {
|
|
|
54
55
|
extensions?: {
|
|
55
56
|
[key: string]: string;
|
|
56
57
|
};
|
|
57
|
-
}, attempt: string, parentActivityIRI?: string) => Pick<UXapiStatement, "object" | "verb" | "context">;
|
|
58
|
+
}, attempt: string, parentActivityIRI?: string, instructor?: string) => Pick<UXapiStatement, "object" | "verb" | "context">;
|
|
58
59
|
export declare const createAttemptStatement: (activity: {
|
|
59
60
|
iri: string;
|
|
60
61
|
type: string;
|
|
@@ -83,7 +84,7 @@ export declare const createCompletedStatement: (attemptStatement: UXapiStatement
|
|
|
83
84
|
export declare const putCompletedStatement: (gateway: LrsGateway, attemptStatement: UXapiStatement, result: UXapiStatement["result"], user?: string) => Promise<import(".").EagerXapiStatement>;
|
|
84
85
|
export declare const createCompletedPendingScoringStatement: (attemptStatement: UXapiStatement) => Pick<UXapiStatement, "object" | "verb" | "context" | "result">;
|
|
85
86
|
export declare const putCompletedPendingScoringStatement: (gateway: LrsGateway, attemptStatement: UXapiStatement, user?: string) => Promise<import(".").EagerXapiStatement>;
|
|
86
|
-
export declare const createScoredStatement: (attemptStatement: UXapiStatement, result: UXapiStatement["result"]) => Pick<UXapiStatement, "object" | "verb" | "context" | "result">;
|
|
87
|
-
export declare const putScoredStatement: (gateway: LrsGateway, attemptStatement: UXapiStatement, result: UXapiStatement["result"], user?: string) => Promise<import(".").EagerXapiStatement>;
|
|
87
|
+
export declare const createScoredStatement: (attemptStatement: UXapiStatement, result: UXapiStatement["result"], instructor?: string) => Pick<UXapiStatement, "object" | "verb" | "context" | "result">;
|
|
88
|
+
export declare const putScoredStatement: (gateway: LrsGateway, attemptStatement: UXapiStatement, result: UXapiStatement["result"], user?: string, instructor?: string) => Promise<import(".").EagerXapiStatement>;
|
|
88
89
|
export declare const createScoredPendingScoringStatement: (attemptStatement: UXapiStatement, result: UXapiStatement["result"]) => Pick<UXapiStatement, "object" | "verb" | "context" | "result">;
|
|
89
90
|
export declare const putScoredPendingScoringStatement: (gateway: LrsGateway, attemptStatement: UXapiStatement, result: UXapiStatement["result"], user?: string) => Promise<import(".").EagerXapiStatement>;
|
|
@@ -11,6 +11,18 @@ import intervalToDuration from 'date-fns/intervalToDuration';
|
|
|
11
11
|
import isAfter from 'date-fns/isAfter';
|
|
12
12
|
import isBefore from 'date-fns/isBefore';
|
|
13
13
|
import parseISO from 'date-fns/parseISO';
|
|
14
|
+
export const formatAgent = (agent) => {
|
|
15
|
+
if (typeof agent === 'string') {
|
|
16
|
+
return {
|
|
17
|
+
objectType: 'Agent',
|
|
18
|
+
account: {
|
|
19
|
+
homePage: 'https://openstax.org',
|
|
20
|
+
name: agent,
|
|
21
|
+
},
|
|
22
|
+
};
|
|
23
|
+
}
|
|
24
|
+
return agent;
|
|
25
|
+
};
|
|
14
26
|
var Verb;
|
|
15
27
|
(function (Verb) {
|
|
16
28
|
Verb["Attempted"] = "http://adlnet.gov/expapi/verbs/attempted";
|
|
@@ -153,7 +165,7 @@ export const loadActivityAttemptInfo = async (gateway, activityIRI, options) =>
|
|
|
153
165
|
const loadOptions = parentActivityAttempt ? { ...partialOptions, registration: parentActivityAttempt } : partialOptions;
|
|
154
166
|
return resolveAttemptInfo(await gateway.getAllXapiStatements({ ...loadOptions, activity: activityIRI }), { ...options, activityIRI });
|
|
155
167
|
};
|
|
156
|
-
export const createStatement = (verb, activity, attempt, parentActivityIRI) => {
|
|
168
|
+
export const createStatement = (verb, activity, attempt, parentActivityIRI, instructor) => {
|
|
157
169
|
return {
|
|
158
170
|
context: {
|
|
159
171
|
...(parentActivityIRI ? {
|
|
@@ -167,6 +179,7 @@ export const createStatement = (verb, activity, attempt, parentActivityIRI) => {
|
|
|
167
179
|
},
|
|
168
180
|
} : {}),
|
|
169
181
|
registration: attempt,
|
|
182
|
+
...(instructor ? { instructor: formatAgent(instructor) } : {}),
|
|
170
183
|
},
|
|
171
184
|
object: {
|
|
172
185
|
definition: {
|
|
@@ -210,7 +223,7 @@ export const createAttemptStatement = (activity, parentActivity) => {
|
|
|
210
223
|
} : {}),
|
|
211
224
|
...(parentActivity.attempt ? {
|
|
212
225
|
registration: parentActivity.attempt,
|
|
213
|
-
} : {})
|
|
226
|
+
} : {}),
|
|
214
227
|
},
|
|
215
228
|
} : {}),
|
|
216
229
|
object: {
|
|
@@ -276,7 +289,7 @@ export const createCompletedStatement = (attemptStatement, result) => {
|
|
|
276
289
|
statement: {
|
|
277
290
|
objectType: 'StatementRef',
|
|
278
291
|
id: attemptStatement.id,
|
|
279
|
-
}
|
|
292
|
+
},
|
|
280
293
|
},
|
|
281
294
|
object: attemptStatement.object,
|
|
282
295
|
verb: {
|
|
@@ -304,7 +317,7 @@ export const putCompletedPendingScoringStatement = async (gateway, attemptStatem
|
|
|
304
317
|
], user))[0];
|
|
305
318
|
};
|
|
306
319
|
// scored statement for when the open written response has been graded.
|
|
307
|
-
export const createScoredStatement = (attemptStatement, result) => {
|
|
320
|
+
export const createScoredStatement = (attemptStatement, result, instructor) => {
|
|
308
321
|
var _a, _b;
|
|
309
322
|
return {
|
|
310
323
|
context: {
|
|
@@ -317,7 +330,8 @@ export const createScoredStatement = (attemptStatement, result) => {
|
|
|
317
330
|
statement: {
|
|
318
331
|
objectType: 'StatementRef',
|
|
319
332
|
id: attemptStatement.id,
|
|
320
|
-
}
|
|
333
|
+
},
|
|
334
|
+
...(instructor ? { instructor: formatAgent(instructor) } : {}),
|
|
321
335
|
},
|
|
322
336
|
object: attemptStatement.object,
|
|
323
337
|
verb: {
|
|
@@ -330,8 +344,8 @@ export const createScoredStatement = (attemptStatement, result) => {
|
|
|
330
344
|
}
|
|
331
345
|
};
|
|
332
346
|
};
|
|
333
|
-
export const putScoredStatement = async (gateway, attemptStatement, result, user) => {
|
|
334
|
-
return (await gateway.putXapiStatements([createScoredStatement(attemptStatement, result)], user))[0];
|
|
347
|
+
export const putScoredStatement = async (gateway, attemptStatement, result, user, instructor) => {
|
|
348
|
+
return (await gateway.putXapiStatements([createScoredStatement(attemptStatement, result, instructor)], user))[0];
|
|
335
349
|
};
|
|
336
350
|
// scored statement for retry assessments - records a score but marks the attempt as still pending scoring
|
|
337
351
|
export const createScoredPendingScoringStatement = (attemptStatement, result) => createScoredStatement(attemptStatement, {
|
|
@@ -7,6 +7,7 @@ import { resolveConfigValue } from '../../config';
|
|
|
7
7
|
import { UnauthorizedError } from '../../errors';
|
|
8
8
|
import { ifDefined } from '../../guards';
|
|
9
9
|
import { hashValue } from '../../misc/hashValue';
|
|
10
|
+
import { formatAgent } from './attempt-utils';
|
|
10
11
|
const pageSize = 5;
|
|
11
12
|
export const fileSystemLrsGateway = (initializer) => (configProvider) => ({ authProvider }) => {
|
|
12
13
|
const name = resolveConfigValue(configProvider[initializer.configSpace || 'fileSystem'].name);
|
|
@@ -69,13 +70,7 @@ export const fileSystemLrsGateway = (initializer) => (configProvider) => ({ auth
|
|
|
69
70
|
const statementsWithDefaults = statements.map(statement => ({
|
|
70
71
|
...statement,
|
|
71
72
|
id: uuid(),
|
|
72
|
-
actor:
|
|
73
|
-
account: {
|
|
74
|
-
homePage: 'https://openstax.org',
|
|
75
|
-
name: author.uuid,
|
|
76
|
-
},
|
|
77
|
-
objectType: 'Agent',
|
|
78
|
-
},
|
|
73
|
+
actor: formatAgent(author.uuid),
|
|
79
74
|
timestamp: formatISO(new Date()),
|
|
80
75
|
}));
|
|
81
76
|
await load;
|
|
@@ -23,13 +23,7 @@ export interface StateDocument {
|
|
|
23
23
|
[key: string]: any;
|
|
24
24
|
}
|
|
25
25
|
export interface XapiStatement {
|
|
26
|
-
actor:
|
|
27
|
-
account: {
|
|
28
|
-
homePage: 'https://openstax.org';
|
|
29
|
-
name: string;
|
|
30
|
-
};
|
|
31
|
-
objectType: 'Agent';
|
|
32
|
-
};
|
|
26
|
+
actor: XapiAgent;
|
|
33
27
|
id: string;
|
|
34
28
|
context?: {
|
|
35
29
|
contextActivities?: {
|
|
@@ -46,6 +40,7 @@ export interface XapiStatement {
|
|
|
46
40
|
};
|
|
47
41
|
registration?: string;
|
|
48
42
|
platform?: string;
|
|
43
|
+
instructor?: XapiAgent;
|
|
49
44
|
};
|
|
50
45
|
object: {
|
|
51
46
|
definition?: {
|
|
@@ -7,6 +7,7 @@ import { ifDefined } from '../../guards';
|
|
|
7
7
|
import { retryWithDelay } from '../../misc/helpers';
|
|
8
8
|
import { METHOD } from '../../routing';
|
|
9
9
|
import { addStatementDefaultFields } from './addStatementDefaultFields';
|
|
10
|
+
import { formatAgent } from './attempt-utils';
|
|
10
11
|
import { RequestBatcher } from './batching';
|
|
11
12
|
export const lrsGateway = (initializer) => (configProvider) => {
|
|
12
13
|
const config = configProvider[ifDefined(initializer.configSpace, 'lrs')];
|
|
@@ -33,22 +34,6 @@ export const lrsGateway = (initializer) => (configProvider) => {
|
|
|
33
34
|
const makeFetch = async (options) => {
|
|
34
35
|
return enableBatching ? batcher.queueRequest(options) : batcher.singleRequest(options);
|
|
35
36
|
};
|
|
36
|
-
/**
|
|
37
|
-
* Formats an agent parameter into a full XapiAgent object.
|
|
38
|
-
* Accepts either a UUID string or a full XapiAgent object.
|
|
39
|
-
*/
|
|
40
|
-
const formatAgent = (agent) => {
|
|
41
|
-
if (typeof agent === 'string') {
|
|
42
|
-
return {
|
|
43
|
-
objectType: 'Agent',
|
|
44
|
-
account: {
|
|
45
|
-
homePage: 'https://openstax.org',
|
|
46
|
-
name: agent,
|
|
47
|
-
},
|
|
48
|
-
};
|
|
49
|
-
}
|
|
50
|
-
return agent;
|
|
51
|
-
};
|
|
52
37
|
// Note: This method actually uses POST
|
|
53
38
|
const putXapiStatements = async (statements, user) => {
|
|
54
39
|
const userObj = user
|
|
@@ -110,13 +95,7 @@ ${await response.text()}`);
|
|
|
110
95
|
queryParams.until = options.until;
|
|
111
96
|
// Add agent unless anyUser is true
|
|
112
97
|
if (anyUser !== true) {
|
|
113
|
-
queryParams.agent = JSON.stringify(
|
|
114
|
-
account: {
|
|
115
|
-
homePage: 'https://openstax.org',
|
|
116
|
-
name: user || assertDefined(await authProvider.getUser(), new UnauthorizedError()).uuid,
|
|
117
|
-
},
|
|
118
|
-
objectType: 'Agent',
|
|
119
|
-
});
|
|
98
|
+
queryParams.agent = JSON.stringify(formatAgent(user || assertDefined(await authProvider.getUser(), new UnauthorizedError()).uuid));
|
|
120
99
|
}
|
|
121
100
|
return makeFetch({
|
|
122
101
|
path: '/data/xAPI/statements',
|