@openstax/ts-utils 1.44.3 → 1.45.1
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/index.d.ts +0 -1
- package/dist/cjs/index.js +0 -1
- package/dist/cjs/services/accountsGateway/index.d.ts +8 -4
- package/dist/cjs/services/accountsGateway/index.js +10 -2
- package/dist/cjs/services/authProvider/index.d.ts +6 -1
- package/dist/cjs/services/lrsGateway/xapiUtils.d.ts +1 -1
- package/dist/cjs/tsconfig.without-specs.cjs.tsbuildinfo +1 -1
- package/dist/esm/index.d.ts +0 -1
- package/dist/esm/index.js +0 -1
- package/dist/esm/services/accountsGateway/index.d.ts +8 -4
- package/dist/esm/services/accountsGateway/index.js +8 -1
- package/dist/esm/services/authProvider/index.d.ts +6 -1
- package/dist/esm/services/lrsGateway/xapiUtils.d.ts +1 -1
- package/dist/esm/tsconfig.without-specs.esm.tsbuildinfo +1 -1
- package/package.json +16 -1
- package/script/bin/.init-params-script.bash.swp +0 -0
package/dist/cjs/index.d.ts
CHANGED
package/dist/cjs/index.js
CHANGED
|
@@ -18,4 +18,3 @@ __exportStar(require("./misc/hashValue.js"), exports);
|
|
|
18
18
|
__exportStar(require("./misc/helpers.js"), exports);
|
|
19
19
|
__exportStar(require("./misc/merge.js"), exports);
|
|
20
20
|
__exportStar(require("./misc/partitionSequence.js"), exports);
|
|
21
|
-
__exportStar(require("./misc/timingSafeCompareStrings.js"), exports);
|
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
import { ConfigProviderForConfig } from '../../config/index.js';
|
|
2
2
|
import { GenericFetch } from '../../fetch/index.js';
|
|
3
3
|
import { JsonCompatibleStruct } from '../../routing/index.js';
|
|
4
|
-
import { ApiUser } from '../authProvider/index.js';
|
|
4
|
+
import { ApiUser, ExternalId } from '../authProvider/index.js';
|
|
5
5
|
import { Logger } from '../logger/index.js';
|
|
6
6
|
export type Config = {
|
|
7
7
|
accountsBase: string;
|
|
@@ -36,12 +36,12 @@ export type FindOrCreateUserPayload = {
|
|
|
36
36
|
export type FindOrCreateUserResponse = {
|
|
37
37
|
id: number;
|
|
38
38
|
uuid: string;
|
|
39
|
-
external_ids:
|
|
39
|
+
external_ids: ExternalId[];
|
|
40
40
|
is_test: boolean;
|
|
41
41
|
sso: string;
|
|
42
42
|
};
|
|
43
43
|
export type FindUserResponse = (FindOrCreateUserResponse & {
|
|
44
|
-
external_ids:
|
|
44
|
+
external_ids: ExternalId[];
|
|
45
45
|
}) | undefined;
|
|
46
46
|
export type LinkUserPayload = {
|
|
47
47
|
userId: number;
|
|
@@ -59,7 +59,7 @@ export type SearchUsersPayload = {
|
|
|
59
59
|
};
|
|
60
60
|
export type SearchUsersResponse = {
|
|
61
61
|
items: Array<ApiUser & {
|
|
62
|
-
external_ids:
|
|
62
|
+
external_ids: ExternalId[];
|
|
63
63
|
} & JsonCompatibleStruct>;
|
|
64
64
|
total_count: number;
|
|
65
65
|
};
|
|
@@ -72,6 +72,10 @@ export type MappedUserInfo<T> = {
|
|
|
72
72
|
platformUserId?: string;
|
|
73
73
|
uuid: string;
|
|
74
74
|
};
|
|
75
|
+
/**
|
|
76
|
+
* Normalize an external_id to always return the string representation.
|
|
77
|
+
*/
|
|
78
|
+
export declare const normalizeExternalId: (externalId: ExternalId) => string;
|
|
75
79
|
export declare const accountsGateway: <C extends string = "accounts">(initializer: Initializer<C>) => (configProvider: { [_key in C]: ConfigProviderForConfig<Config>; }) => ({ logger }: {
|
|
76
80
|
logger: Logger;
|
|
77
81
|
}) => {
|
|
@@ -3,7 +3,7 @@ var __importDefault = (this && this.__importDefault) || function (mod) {
|
|
|
3
3
|
return (mod && mod.__esModule) ? mod : { "default": mod };
|
|
4
4
|
};
|
|
5
5
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
6
|
-
exports.accountsGateway = void 0;
|
|
6
|
+
exports.accountsGateway = exports.normalizeExternalId = void 0;
|
|
7
7
|
const lodash_1 = require("lodash");
|
|
8
8
|
const query_string_1 = __importDefault(require("query-string"));
|
|
9
9
|
const index_js_1 = require("../../config/index.js");
|
|
@@ -17,6 +17,13 @@ class ApiError extends Error {
|
|
|
17
17
|
this.status = status;
|
|
18
18
|
}
|
|
19
19
|
}
|
|
20
|
+
/**
|
|
21
|
+
* Normalize an external_id to always return the string representation.
|
|
22
|
+
*/
|
|
23
|
+
const normalizeExternalId = (externalId) => {
|
|
24
|
+
return typeof externalId === 'string' ? externalId : externalId.external_id;
|
|
25
|
+
};
|
|
26
|
+
exports.normalizeExternalId = normalizeExternalId;
|
|
20
27
|
const accountsGateway = (initializer) => (configProvider) => {
|
|
21
28
|
const config = configProvider[(0, index_js_2.ifDefined)(initializer.configSpace, 'accounts')];
|
|
22
29
|
const accountsBase = (0, helpers_js_1.once)(() => (0, index_js_1.resolveConfigValue)(config.accountsBase));
|
|
@@ -65,7 +72,8 @@ const accountsGateway = (initializer) => (configProvider) => {
|
|
|
65
72
|
const searchUsers = async (payload) => request(index_js_3.METHOD.GET, `users?${query_string_1.default.stringify(payload)}`, {});
|
|
66
73
|
const updateUser = async (token, body) => request(index_js_3.METHOD.PUT, 'user', { body, token });
|
|
67
74
|
const getPlatformUserId = (externalIds, platformId) => {
|
|
68
|
-
|
|
75
|
+
const normalizedIds = externalIds.map(exports.normalizeExternalId);
|
|
76
|
+
for (const externalId of normalizedIds) {
|
|
69
77
|
const [userPlatformId, userId] = externalId.split('/', 2);
|
|
70
78
|
if (userPlatformId === platformId) {
|
|
71
79
|
return userId;
|
|
@@ -11,6 +11,11 @@ export type TokenUser = {
|
|
|
11
11
|
name: string;
|
|
12
12
|
uuid: string;
|
|
13
13
|
};
|
|
14
|
+
export type ExternalId = string | {
|
|
15
|
+
external_id: string;
|
|
16
|
+
user_id?: number;
|
|
17
|
+
role: string;
|
|
18
|
+
};
|
|
14
19
|
export type ApiUser = TokenUser & {
|
|
15
20
|
id: number;
|
|
16
21
|
first_name: string;
|
|
@@ -27,7 +32,7 @@ export type ApiUser = TokenUser & {
|
|
|
27
32
|
name: string;
|
|
28
33
|
roles: string[];
|
|
29
34
|
}>;
|
|
30
|
-
external_ids:
|
|
35
|
+
external_ids: ExternalId[];
|
|
31
36
|
faculty_status: string;
|
|
32
37
|
is_admin: boolean;
|
|
33
38
|
is_not_gdpr_location: boolean;
|
|
@@ -3,7 +3,7 @@ import { AuthProvider } from '../authProvider/index.js';
|
|
|
3
3
|
import { ActivityState, AttemptEntry } from './attempt-utils.js';
|
|
4
4
|
import { LrsGateway } from './index.js';
|
|
5
5
|
export interface Grade {
|
|
6
|
-
activityProgress: 'Initialized' | 'Started' | '
|
|
6
|
+
activityProgress: 'Initialized' | 'Started' | 'InProgress' | 'Submitted' | 'Completed';
|
|
7
7
|
comment?: string;
|
|
8
8
|
gradingProgress: 'FullyGraded' | 'Pending' | 'PendingManual' | 'Failed' | 'NotReady';
|
|
9
9
|
scoreGiven: number;
|