@openstax/ts-utils 1.5.0 → 1.5.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/config/envConfig.js +12 -3
- package/dist/cjs/services/lrsGateway/xapiUtils.d.ts +3 -1
- package/dist/cjs/services/lrsGateway/xapiUtils.js +11 -2
- package/dist/cjs/tsconfig.without-specs.cjs.tsbuildinfo +1 -1
- package/dist/esm/config/envConfig.js +12 -3
- package/dist/esm/services/lrsGateway/xapiUtils.d.ts +3 -1
- package/dist/esm/services/lrsGateway/xapiUtils.js +8 -2
- package/dist/esm/tsconfig.without-specs.esm.tsbuildinfo +1 -1
- package/package.json +1 -1
|
@@ -1,5 +1,4 @@
|
|
|
1
|
-
import {
|
|
2
|
-
import { ifDefined } from '../guards';
|
|
1
|
+
import { resolveConfigValue } from '.';
|
|
3
2
|
/**
|
|
4
3
|
* A list of environment variables that were requested at build time. Used by webpack to
|
|
5
4
|
* capture build-time environment variables values.
|
|
@@ -32,6 +31,16 @@ export const envConfig = (name, type = 'build', defaultValue) => {
|
|
|
32
31
|
// - https://github.com/webpack/webpack/issues/14800
|
|
33
32
|
// - https://github.com/webpack/webpack/issues/5392
|
|
34
33
|
const envs = { ...process.env, ...(typeof __PROCESS_ENV !== 'undefined' ? __PROCESS_ENV : {}) };
|
|
35
|
-
|
|
34
|
+
if (envs[name] === undefined) {
|
|
35
|
+
if (defaultValue === undefined) {
|
|
36
|
+
throw new Error(`expected to find environment variable with name: ${name}`);
|
|
37
|
+
}
|
|
38
|
+
else {
|
|
39
|
+
return resolveConfigValue(defaultValue);
|
|
40
|
+
}
|
|
41
|
+
}
|
|
42
|
+
else {
|
|
43
|
+
return envs[name];
|
|
44
|
+
}
|
|
36
45
|
};
|
|
37
46
|
};
|
|
@@ -1,6 +1,7 @@
|
|
|
1
1
|
import { AccountsGateway } from '../accountsGateway';
|
|
2
2
|
import { AuthProvider } from '../authProvider';
|
|
3
3
|
import { Logger } from '../logger';
|
|
4
|
+
import { ActivityState } from './attempt-utils';
|
|
4
5
|
import { LrsGateway } from '.';
|
|
5
6
|
export interface Grade {
|
|
6
7
|
scoreGiven: number;
|
|
@@ -13,7 +14,7 @@ export interface Grade {
|
|
|
13
14
|
export declare const getRegistrationAttemptInfo: (lrs: LrsGateway, registration: string, options?: {
|
|
14
15
|
anyUser?: boolean | undefined;
|
|
15
16
|
} | undefined) => Promise<{
|
|
16
|
-
[key: string]:
|
|
17
|
+
[key: string]: ActivityState;
|
|
17
18
|
}>;
|
|
18
19
|
export declare const getCurrentGrade: (services: {
|
|
19
20
|
lrs: LrsGateway;
|
|
@@ -27,6 +28,7 @@ export declare const getAllGradesForAssignment: (services: {
|
|
|
27
28
|
lrs: LrsGateway;
|
|
28
29
|
logger: Logger;
|
|
29
30
|
}, registration: string, options?: {
|
|
31
|
+
incompleteAttemptsCallback?: ((mappedInfo: [string, ActivityState][]) => Promise<Grade[]>) | undefined;
|
|
30
32
|
platformId?: string | undefined;
|
|
31
33
|
scoreMaximum?: number | undefined;
|
|
32
34
|
} | undefined) => Promise<Grade[]>;
|
|
@@ -1,3 +1,4 @@
|
|
|
1
|
+
import partition from 'lodash/fp/partition';
|
|
1
2
|
import { roundToPrecision } from '../..';
|
|
2
3
|
import { resolveAttemptInfo } from './attempt-utils';
|
|
3
4
|
export const getRegistrationAttemptInfo = async (lrs, registration, options) => {
|
|
@@ -50,6 +51,11 @@ export const getCurrentGrade = async (services, registration, options) => {
|
|
|
50
51
|
};
|
|
51
52
|
export const getAllGradesForAssignment = async (services, registration, options) => {
|
|
52
53
|
const infoPerUserUuid = await getRegistrationAttemptInfo(services.lrs, registration, { anyUser: true });
|
|
53
|
-
const
|
|
54
|
-
|
|
54
|
+
const mappedInfo = await services.accountsGateway.mapUserUuids(infoPerUserUuid, services.logger, options === null || options === void 0 ? void 0 : options.platformId);
|
|
55
|
+
const gradeCompletedAttemptsOnly = (results) => results.map(([userId, userInfo]) => getInfoGrade(userInfo, userId, options === null || options === void 0 ? void 0 : options.scoreMaximum));
|
|
56
|
+
if (!(options === null || options === void 0 ? void 0 : options.incompleteAttemptsCallback)) {
|
|
57
|
+
return gradeCompletedAttemptsOnly(mappedInfo);
|
|
58
|
+
}
|
|
59
|
+
const [incompleteInfo, completedInfo] = partition((info) => info[1].currentAttemptCompleted === undefined)(mappedInfo);
|
|
60
|
+
return gradeCompletedAttemptsOnly(completedInfo).concat(await options.incompleteAttemptsCallback(incompleteInfo));
|
|
55
61
|
};
|