@openstax/ts-utils 1.5.3 → 1.5.5
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/accountsGateway/index.d.ts +7 -1
- package/dist/cjs/services/accountsGateway/index.js +12 -5
- package/dist/cjs/services/authProvider/index.d.ts +5 -0
- package/dist/cjs/services/lrsGateway/attempt-utils.d.ts +2 -0
- package/dist/cjs/services/lrsGateway/index.js +1 -1
- package/dist/cjs/services/lrsGateway/xapiUtils.d.ts +18 -5
- package/dist/cjs/services/lrsGateway/xapiUtils.js +25 -17
- package/dist/cjs/tsconfig.without-specs.cjs.tsbuildinfo +1 -1
- package/dist/esm/services/accountsGateway/index.d.ts +7 -1
- package/dist/esm/services/accountsGateway/index.js +12 -5
- package/dist/esm/services/authProvider/index.d.ts +5 -0
- package/dist/esm/services/lrsGateway/attempt-utils.d.ts +2 -0
- package/dist/esm/services/lrsGateway/index.js +1 -1
- package/dist/esm/services/lrsGateway/xapiUtils.d.ts +18 -5
- package/dist/esm/services/lrsGateway/xapiUtils.js +25 -17
- package/dist/esm/tsconfig.without-specs.esm.tsbuildinfo +1 -1
- package/package.json +1 -1
|
@@ -60,6 +60,12 @@ export declare type SearchUsersResponse = {
|
|
|
60
60
|
} & JsonCompatibleStruct>;
|
|
61
61
|
total_count: number;
|
|
62
62
|
};
|
|
63
|
+
export declare type MappedUserInfo<T> = {
|
|
64
|
+
data: T;
|
|
65
|
+
fullName: string;
|
|
66
|
+
platformUserId?: string;
|
|
67
|
+
uuid: string;
|
|
68
|
+
};
|
|
63
69
|
export declare const accountsGateway: <C extends string = "accounts">(initializer: Initializer<C>) => (configProvider: { [key in C]: {
|
|
64
70
|
accountsBase: import("../../config").ConfigValueProvider<string>;
|
|
65
71
|
accountsAuthToken: import("../../config").ConfigValueProvider<string>;
|
|
@@ -70,7 +76,7 @@ export declare const accountsGateway: <C extends string = "accounts">(initialize
|
|
|
70
76
|
linkUser: (body: LinkUserPayload) => Promise<LinkUserResponse>;
|
|
71
77
|
mapUserUuids: <T>(userUuidsMap: {
|
|
72
78
|
[uuid: string]: T;
|
|
73
|
-
}, logger: Logger, platformId?: string | undefined) => Promise<
|
|
79
|
+
}, logger: Logger, platformId?: string | undefined) => Promise<MappedUserInfo<T>[]>;
|
|
74
80
|
searchUsers: (payload: SearchUsersPayload) => Promise<SearchUsersResponse>;
|
|
75
81
|
};
|
|
76
82
|
export declare type AccountsGateway = ReturnType<ReturnType<typeof accountsGateway>>;
|
|
@@ -85,16 +85,23 @@ export const accountsGateway = (initializer) => (configProvider) => {
|
|
|
85
85
|
});
|
|
86
86
|
}
|
|
87
87
|
items.forEach((user) => {
|
|
88
|
-
const
|
|
89
|
-
if (!
|
|
90
|
-
const missing = platformId ? 'external_id matching the given platformId' : 'full_name';
|
|
88
|
+
const platformUserId = platformId ? getPlatformUserId(user.external_ids, platformId) : undefined;
|
|
89
|
+
if (platformId && !platformUserId) {
|
|
91
90
|
logger.logEvent(Level.Warn, {
|
|
92
|
-
message:
|
|
91
|
+
message: 'Accounts user has no external_id matching the given platformId',
|
|
93
92
|
accountsUuid: user.uuid,
|
|
94
93
|
platformId,
|
|
95
94
|
});
|
|
96
95
|
}
|
|
97
|
-
|
|
96
|
+
if (!user.full_name) {
|
|
97
|
+
logger.logEvent(Level.Warn, {
|
|
98
|
+
message: 'Accounts user has no full_name',
|
|
99
|
+
accountsUuid: user.uuid,
|
|
100
|
+
});
|
|
101
|
+
}
|
|
102
|
+
results.push({
|
|
103
|
+
data: userUuidsMap[user.uuid], fullName: user.full_name, platformUserId, uuid: user.uuid,
|
|
104
|
+
});
|
|
98
105
|
});
|
|
99
106
|
}));
|
|
100
107
|
return results;
|
|
@@ -18,6 +18,11 @@ export interface ApiUser extends TokenUser {
|
|
|
18
18
|
is_verified: boolean;
|
|
19
19
|
is_guessed_preferred: boolean;
|
|
20
20
|
}>;
|
|
21
|
+
applications: Array<{
|
|
22
|
+
id: number;
|
|
23
|
+
name: string;
|
|
24
|
+
roles: string[];
|
|
25
|
+
}>;
|
|
21
26
|
external_ids: string[];
|
|
22
27
|
is_not_gdpr_location: boolean;
|
|
23
28
|
signed_contract_names: string[];
|
|
@@ -24,8 +24,10 @@ export declare const resolveAttemptInfo: (statements: XapiStatement[], options?:
|
|
|
24
24
|
currentPreference?: "latest" | "oldest" | undefined;
|
|
25
25
|
} | undefined) => ActivityState;
|
|
26
26
|
export declare const loadStatementsForActivityAndFirstChildren: (gateway: LrsGateway, activityIRI: string, options?: {
|
|
27
|
+
anyUser?: boolean | undefined;
|
|
27
28
|
attempt?: string | undefined;
|
|
28
29
|
ensureSync?: boolean | undefined;
|
|
30
|
+
user?: string | undefined;
|
|
29
31
|
} | undefined) => Promise<XapiStatement[]>;
|
|
30
32
|
export declare const loadActivityAttemptInfo: (gateway: LrsGateway, activityIRI: string, options?: {
|
|
31
33
|
currentAttempt?: string | undefined;
|
|
@@ -88,7 +88,7 @@ ${await response.text()}`);
|
|
|
88
88
|
throw new Error(`xAPI consistent through ${consistentThrough}; not in sync with current date ${date}.`);
|
|
89
89
|
}
|
|
90
90
|
return formatGetXapiStatementsResponse(responsePromise);
|
|
91
|
-
});
|
|
91
|
+
}, { retries: 4 });
|
|
92
92
|
}
|
|
93
93
|
else {
|
|
94
94
|
return formatGetXapiStatementsResponse(fetchXapiStatements(fetchParams));
|
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import { AccountsGateway } from '../accountsGateway';
|
|
1
|
+
import { AccountsGateway, MappedUserInfo } from '../accountsGateway';
|
|
2
2
|
import { AuthProvider } from '../authProvider';
|
|
3
3
|
import { Logger } from '../logger';
|
|
4
4
|
import { ActivityState } from './attempt-utils';
|
|
@@ -13,6 +13,7 @@ export interface Grade {
|
|
|
13
13
|
}
|
|
14
14
|
export declare const getRegistrationAttemptInfo: (lrs: LrsGateway, registration: string, options?: {
|
|
15
15
|
anyUser?: boolean | undefined;
|
|
16
|
+
currentPreference?: "latest" | "oldest" | undefined;
|
|
16
17
|
user?: string | undefined;
|
|
17
18
|
} | undefined) => Promise<{
|
|
18
19
|
[key: string]: ActivityState;
|
|
@@ -23,22 +24,34 @@ export declare const getScoreGrade: (score: {
|
|
|
23
24
|
min?: number;
|
|
24
25
|
max?: number;
|
|
25
26
|
}, completed: boolean, userId: string, maxScore?: number | undefined) => Grade;
|
|
27
|
+
export declare type Progress = {
|
|
28
|
+
scaled: number;
|
|
29
|
+
max?: number;
|
|
30
|
+
raw?: number;
|
|
31
|
+
};
|
|
32
|
+
export declare type GradeAndProgress = {
|
|
33
|
+
grade: Grade;
|
|
34
|
+
progress: Progress;
|
|
35
|
+
};
|
|
26
36
|
export declare const getCurrentGrade: (services: {
|
|
27
37
|
lrs: LrsGateway;
|
|
28
38
|
ltiAuthProvider: AuthProvider;
|
|
29
39
|
}, registration: string, options?: {
|
|
30
|
-
|
|
40
|
+
currentPreference?: "latest" | "oldest" | undefined;
|
|
41
|
+
incompleteAttemptCallback?: ((info: ActivityState) => Promise<GradeAndProgress>) | undefined;
|
|
31
42
|
scoreMaximum?: number | undefined;
|
|
32
43
|
userId?: string | undefined;
|
|
33
|
-
} | undefined) => Promise<
|
|
44
|
+
} | undefined) => Promise<GradeAndProgress | null>;
|
|
45
|
+
export declare type UserActivityInfo = MappedUserInfo<ActivityState>;
|
|
34
46
|
export declare const getAssignmentGrades: (services: {
|
|
35
47
|
accountsGateway: AccountsGateway;
|
|
36
48
|
lrs: LrsGateway;
|
|
37
49
|
logger: Logger;
|
|
38
50
|
}, registration: string, options?: {
|
|
39
51
|
anyUser?: boolean | undefined;
|
|
40
|
-
|
|
52
|
+
currentPreference?: "latest" | "oldest" | undefined;
|
|
53
|
+
incompleteAttemptsCallback?: ((mappedInfo: UserActivityInfo[]) => Promise<GradeAndProgress[]>) | undefined;
|
|
41
54
|
platformId?: string | undefined;
|
|
42
55
|
scoreMaximum?: number | undefined;
|
|
43
56
|
user?: string | undefined;
|
|
44
|
-
} | undefined) => Promise<
|
|
57
|
+
} | undefined) => Promise<GradeAndProgress[]>;
|
|
@@ -2,7 +2,8 @@ import partition from 'lodash/fp/partition';
|
|
|
2
2
|
import { roundToPrecision } from '../..';
|
|
3
3
|
import { resolveAttemptInfo } from './attempt-utils';
|
|
4
4
|
export const getRegistrationAttemptInfo = async (lrs, registration, options) => {
|
|
5
|
-
const
|
|
5
|
+
const { currentPreference, ...xapiOptions } = options !== null && options !== void 0 ? options : {};
|
|
6
|
+
const allStatements = await lrs.getAllXapiStatements({ ...xapiOptions, registration, ensureSync: true });
|
|
6
7
|
// Partition statements for each user
|
|
7
8
|
const statementsPerUser = {};
|
|
8
9
|
allStatements.forEach((statement) => {
|
|
@@ -14,7 +15,7 @@ export const getRegistrationAttemptInfo = async (lrs, registration, options) =>
|
|
|
14
15
|
});
|
|
15
16
|
const result = {};
|
|
16
17
|
for (const [userUuid, userStatements] of Object.entries(statementsPerUser)) {
|
|
17
|
-
result[userUuid] = resolveAttemptInfo(userStatements, { currentPreference
|
|
18
|
+
result[userUuid] = resolveAttemptInfo(userStatements, { currentPreference });
|
|
18
19
|
}
|
|
19
20
|
return result;
|
|
20
21
|
};
|
|
@@ -37,10 +38,17 @@ export const getScoreGrade = (score, completed, userId, maxScore) => {
|
|
|
37
38
|
scoreGiven: roundToPrecision(scoreGiven, -2),
|
|
38
39
|
};
|
|
39
40
|
};
|
|
40
|
-
|
|
41
|
+
// These methods assigns 0's to incomplete activities
|
|
42
|
+
const getCompletedActivityStateGradeAndProgress = (state, userId, maxScore) => {
|
|
41
43
|
var _a, _b;
|
|
42
|
-
return
|
|
44
|
+
return ({
|
|
45
|
+
grade: getScoreGrade(((_b = (_a = state.currentAttemptCompleted) === null || _a === void 0 ? void 0 : _a.result) === null || _b === void 0 ? void 0 : _b.score) || {}, !!state.currentAttemptCompleted, userId, maxScore),
|
|
46
|
+
progress: {
|
|
47
|
+
scaled: state.currentAttemptCompleted ? 1 : 0,
|
|
48
|
+
},
|
|
49
|
+
});
|
|
43
50
|
};
|
|
51
|
+
const getCompletedUserInfosGradeAndProgress = (infos, scoreMaximum) => infos.map(({ data, fullName, platformUserId }) => getCompletedActivityStateGradeAndProgress(data, platformUserId !== null && platformUserId !== void 0 ? platformUserId : fullName, scoreMaximum));
|
|
44
52
|
export const getCurrentGrade = async (services, registration, options) => {
|
|
45
53
|
var _a;
|
|
46
54
|
const user = await services.ltiAuthProvider.getUser();
|
|
@@ -48,24 +56,24 @@ export const getCurrentGrade = async (services, registration, options) => {
|
|
|
48
56
|
return null;
|
|
49
57
|
}
|
|
50
58
|
const userId = (_a = options === null || options === void 0 ? void 0 : options.userId) !== null && _a !== void 0 ? _a : user.uuid;
|
|
51
|
-
const scoreMaximum = options
|
|
52
|
-
const infoPerUser = await getRegistrationAttemptInfo(services.lrs, registration);
|
|
59
|
+
const { currentPreference, incompleteAttemptCallback, scoreMaximum } = options !== null && options !== void 0 ? options : {};
|
|
60
|
+
const infoPerUser = await getRegistrationAttemptInfo(services.lrs, registration, { currentPreference });
|
|
53
61
|
const userInfo = infoPerUser[user.uuid];
|
|
54
62
|
if (!userInfo) {
|
|
55
|
-
return
|
|
63
|
+
return getCompletedActivityStateGradeAndProgress(resolveAttemptInfo([]), userId, scoreMaximum);
|
|
56
64
|
}
|
|
57
|
-
if (userInfo.currentAttemptCompleted || !
|
|
58
|
-
return
|
|
65
|
+
if (userInfo.currentAttemptCompleted || !incompleteAttemptCallback) {
|
|
66
|
+
return getCompletedActivityStateGradeAndProgress(userInfo, userId, scoreMaximum);
|
|
59
67
|
}
|
|
60
|
-
return
|
|
68
|
+
return incompleteAttemptCallback(userInfo);
|
|
61
69
|
};
|
|
62
70
|
export const getAssignmentGrades = async (services, registration, options) => {
|
|
63
|
-
const
|
|
64
|
-
const
|
|
65
|
-
const
|
|
66
|
-
if (!
|
|
67
|
-
return
|
|
71
|
+
const { anyUser, currentPreference, incompleteAttemptsCallback, platformId, scoreMaximum, user } = options !== null && options !== void 0 ? options : {};
|
|
72
|
+
const infoPerUserUuid = await getRegistrationAttemptInfo(services.lrs, registration, { anyUser, currentPreference, user });
|
|
73
|
+
const mappedInfo = await services.accountsGateway.mapUserUuids(infoPerUserUuid, services.logger, platformId);
|
|
74
|
+
if (!incompleteAttemptsCallback) {
|
|
75
|
+
return getCompletedUserInfosGradeAndProgress(mappedInfo, scoreMaximum);
|
|
68
76
|
}
|
|
69
|
-
const [incompleteInfo, completedInfo] = partition((info) => info
|
|
70
|
-
return
|
|
77
|
+
const [incompleteInfo, completedInfo] = partition((info) => info.data.currentAttemptCompleted === undefined)(mappedInfo);
|
|
78
|
+
return getCompletedUserInfosGradeAndProgress(completedInfo, scoreMaximum).concat(await incompleteAttemptsCallback(incompleteInfo));
|
|
71
79
|
};
|