@openstax/ts-utils 1.43.1 → 1.44.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/dist/cjs/aws/ssmService.js +2 -2
- package/dist/cjs/config/awsParameterConfig.d.ts +1 -1
- package/dist/cjs/config/awsParameterConfig.js +3 -3
- package/dist/cjs/config/envConfig.d.ts +1 -1
- package/dist/cjs/config/lambdaParameterConfig.d.ts +1 -1
- package/dist/cjs/config/lambdaParameterConfig.js +6 -6
- package/dist/cjs/config/replaceConfig.d.ts +1 -1
- package/dist/cjs/config/resolveConfigValue.d.ts +1 -1
- package/dist/cjs/errors/index.d.ts +1 -1
- package/dist/cjs/fetch/fetchStatusRetry.d.ts +1 -1
- package/dist/cjs/fetch/index.d.ts +1 -1
- package/dist/cjs/index.d.ts +3 -2
- package/dist/cjs/index.js +3 -2
- package/dist/cjs/middleware/apiErrorHandler.d.ts +3 -3
- package/dist/cjs/middleware/apiErrorHandler.js +12 -12
- package/dist/cjs/middleware/apiSlowResponseMiddleware.d.ts +3 -3
- package/dist/cjs/middleware/apiSlowResponseMiddleware.js +5 -5
- package/dist/cjs/middleware/lambdaCorsResponseMiddleware.d.ts +2 -2
- package/dist/cjs/middleware/lambdaCorsResponseMiddleware.js +2 -2
- package/dist/cjs/middleware/throwNotFoundMiddleware.js +2 -2
- package/dist/cjs/misc/helpers.d.ts +1 -1
- package/dist/cjs/misc/merge.js +2 -2
- package/dist/cjs/misc/timingSafeCompareStrings.d.ts +5 -0
- package/dist/cjs/misc/timingSafeCompareStrings.js +15 -0
- package/dist/cjs/pagination/index.d.ts +1 -1
- package/dist/cjs/pagination/index.js +10 -10
- package/dist/cjs/routing/helpers.d.ts +1 -1
- package/dist/cjs/routing/helpers.js +7 -7
- package/dist/cjs/routing/index.d.ts +1 -1
- package/dist/cjs/routing/lambdaBatchRequestHandler.d.ts +2 -2
- package/dist/cjs/routing/lambdaBatchRequestHandler.js +2 -2
- package/dist/cjs/routing/validators/zod.js +2 -2
- package/dist/cjs/services/accountsGateway/index.d.ts +5 -5
- package/dist/cjs/services/accountsGateway/index.js +17 -17
- package/dist/cjs/services/apiGateway/index.d.ts +4 -4
- package/dist/cjs/services/apiGateway/index.js +10 -10
- package/dist/cjs/services/authProvider/browser.d.ts +3 -3
- package/dist/cjs/services/authProvider/browser.js +9 -9
- package/dist/cjs/services/authProvider/decryption.d.ts +3 -3
- package/dist/cjs/services/authProvider/decryption.js +7 -7
- package/dist/cjs/services/authProvider/index.d.ts +3 -3
- package/dist/cjs/services/authProvider/launchToken.d.ts +3 -3
- package/dist/cjs/services/authProvider/launchToken.js +3 -3
- package/dist/cjs/services/authProvider/subrequest.d.ts +3 -3
- package/dist/cjs/services/authProvider/subrequest.js +10 -10
- package/dist/cjs/services/authProvider/utils/decryptAndVerify.d.ts +1 -1
- package/dist/cjs/services/authProvider/utils/decryptAndVerify.js +3 -3
- package/dist/cjs/services/authProvider/utils/embeddedAuthProvider.d.ts +1 -1
- package/dist/cjs/services/authProvider/utils/userRoleValidator.d.ts +3 -3
- package/dist/cjs/services/authProvider/utils/userRoleValidator.js +4 -4
- package/dist/cjs/services/authProvider/utils/userSubrequest.d.ts +2 -2
- package/dist/cjs/services/documentStore/dynamoEncoding.d.ts +1 -1
- package/dist/cjs/services/documentStore/dynamoEncoding.js +2 -2
- package/dist/cjs/services/documentStore/unversioned/dynamodb.d.ts +2 -2
- package/dist/cjs/services/documentStore/unversioned/dynamodb.js +14 -14
- package/dist/cjs/services/documentStore/unversioned/file-system.d.ts +2 -2
- package/dist/cjs/services/documentStore/unversioned/file-system.js +13 -13
- package/dist/cjs/services/documentStore/versioned/dynamodb.d.ts +3 -3
- package/dist/cjs/services/documentStore/versioned/dynamodb.js +6 -6
- package/dist/cjs/services/documentStore/versioned/file-system.d.ts +3 -3
- package/dist/cjs/services/documentStore/versioned/index.d.ts +1 -1
- package/dist/cjs/services/exercisesGateway/index.d.ts +2 -2
- package/dist/cjs/services/exercisesGateway/index.js +14 -14
- package/dist/cjs/services/fileServer/index.js +3 -3
- package/dist/cjs/services/fileServer/localFileServer.d.ts +2 -2
- package/dist/cjs/services/fileServer/localFileServer.js +9 -9
- package/dist/cjs/services/fileServer/s3FileServer.d.ts +2 -2
- package/dist/cjs/services/fileServer/s3FileServer.js +13 -13
- package/dist/cjs/services/httpMessageVerifier/index.d.ts +1 -1
- package/dist/cjs/services/httpMessageVerifier/index.js +16 -16
- package/dist/cjs/services/launchParams/signer.d.ts +2 -2
- package/dist/cjs/services/launchParams/signer.js +9 -9
- package/dist/cjs/services/launchParams/verifier.d.ts +1 -1
- package/dist/cjs/services/launchParams/verifier.js +8 -8
- package/dist/cjs/services/logger/console.d.ts +1 -1
- package/dist/cjs/services/logger/console.js +2 -2
- package/dist/cjs/services/logger/index.d.ts +1 -1
- package/dist/cjs/services/lrsGateway/addStatementDefaultFields.d.ts +1 -1
- package/dist/cjs/services/lrsGateway/attempt-utils.d.ts +7 -7
- package/dist/cjs/services/lrsGateway/batching.d.ts +2 -2
- package/dist/cjs/services/lrsGateway/batching.js +2 -2
- package/dist/cjs/services/lrsGateway/file-system.d.ts +3 -3
- package/dist/cjs/services/lrsGateway/file-system.js +8 -8
- package/dist/cjs/services/lrsGateway/index.d.ts +4 -4
- package/dist/cjs/services/lrsGateway/index.js +15 -15
- package/dist/cjs/services/lrsGateway/xapiUtils.d.ts +3 -3
- package/dist/cjs/services/lrsGateway/xapiUtils.js +2 -2
- package/dist/cjs/services/postgresConnection/index.d.ts +2 -2
- package/dist/cjs/services/postgresConnection/index.js +10 -10
- package/dist/cjs/services/queueProvider/local.d.ts +2 -2
- package/dist/cjs/services/queueProvider/local.js +5 -5
- package/dist/cjs/services/queueProvider/sqs.d.ts +2 -2
- package/dist/cjs/services/queueProvider/sqs.js +5 -5
- package/dist/cjs/services/searchProvider/memorySearchTheBadWay.d.ts +1 -1
- package/dist/cjs/services/searchProvider/memorySearchTheBadWay.js +9 -9
- package/dist/cjs/services/searchProvider/openSearch.d.ts +2 -2
- package/dist/cjs/services/searchProvider/openSearch.js +6 -6
- package/dist/cjs/services/searchProvider/streamIndexer.d.ts +2 -2
- package/dist/cjs/services/searchProvider/streamIndexer.js +3 -3
- package/dist/cjs/tsconfig.without-specs.cjs.tsbuildinfo +1 -1
- package/dist/esm/aws/ssmService.js +1 -1
- package/dist/esm/config/awsParameterConfig.d.ts +1 -1
- package/dist/esm/config/awsParameterConfig.js +1 -1
- package/dist/esm/config/envConfig.d.ts +1 -1
- package/dist/esm/config/lambdaParameterConfig.d.ts +1 -1
- package/dist/esm/config/lambdaParameterConfig.js +2 -2
- package/dist/esm/config/replaceConfig.d.ts +1 -1
- package/dist/esm/config/resolveConfigValue.d.ts +1 -1
- package/dist/esm/errors/index.d.ts +1 -1
- package/dist/esm/fetch/fetchStatusRetry.d.ts +1 -1
- package/dist/esm/fetch/index.d.ts +1 -1
- package/dist/esm/index.d.ts +3 -2
- package/dist/esm/index.js +3 -2
- package/dist/esm/middleware/apiErrorHandler.d.ts +3 -3
- package/dist/esm/middleware/apiErrorHandler.js +3 -3
- package/dist/esm/middleware/apiSlowResponseMiddleware.d.ts +3 -3
- package/dist/esm/middleware/apiSlowResponseMiddleware.js +2 -2
- package/dist/esm/middleware/lambdaCorsResponseMiddleware.d.ts +2 -2
- package/dist/esm/middleware/lambdaCorsResponseMiddleware.js +1 -1
- package/dist/esm/middleware/throwNotFoundMiddleware.js +1 -1
- package/dist/esm/misc/helpers.d.ts +1 -1
- package/dist/esm/misc/merge.js +1 -1
- package/dist/esm/misc/timingSafeCompareStrings.d.ts +5 -0
- package/dist/esm/misc/timingSafeCompareStrings.js +11 -0
- package/dist/esm/pagination/index.d.ts +1 -1
- package/dist/esm/pagination/index.js +3 -3
- package/dist/esm/routing/helpers.d.ts +1 -1
- package/dist/esm/routing/helpers.js +3 -3
- package/dist/esm/routing/index.d.ts +1 -1
- package/dist/esm/routing/lambdaBatchRequestHandler.d.ts +2 -2
- package/dist/esm/routing/lambdaBatchRequestHandler.js +1 -1
- package/dist/esm/routing/validators/zod.js +1 -1
- package/dist/esm/services/accountsGateway/index.d.ts +5 -5
- package/dist/esm/services/accountsGateway/index.js +4 -4
- package/dist/esm/services/apiGateway/index.d.ts +4 -4
- package/dist/esm/services/apiGateway/index.js +4 -4
- package/dist/esm/services/authProvider/browser.d.ts +3 -3
- package/dist/esm/services/authProvider/browser.js +4 -4
- package/dist/esm/services/authProvider/decryption.d.ts +3 -3
- package/dist/esm/services/authProvider/decryption.js +3 -3
- package/dist/esm/services/authProvider/index.d.ts +3 -3
- package/dist/esm/services/authProvider/launchToken.d.ts +3 -3
- package/dist/esm/services/authProvider/launchToken.js +1 -1
- package/dist/esm/services/authProvider/subrequest.d.ts +3 -3
- package/dist/esm/services/authProvider/subrequest.js +4 -4
- package/dist/esm/services/authProvider/utils/decryptAndVerify.d.ts +1 -1
- package/dist/esm/services/authProvider/utils/decryptAndVerify.js +1 -1
- package/dist/esm/services/authProvider/utils/embeddedAuthProvider.d.ts +1 -1
- package/dist/esm/services/authProvider/utils/userRoleValidator.d.ts +3 -3
- package/dist/esm/services/authProvider/utils/userRoleValidator.js +2 -2
- package/dist/esm/services/authProvider/utils/userSubrequest.d.ts +2 -2
- package/dist/esm/services/documentStore/dynamoEncoding.d.ts +1 -1
- package/dist/esm/services/documentStore/dynamoEncoding.js +1 -1
- package/dist/esm/services/documentStore/unversioned/dynamodb.d.ts +2 -2
- package/dist/esm/services/documentStore/unversioned/dynamodb.js +4 -4
- package/dist/esm/services/documentStore/unversioned/file-system.d.ts +2 -2
- package/dist/esm/services/documentStore/unversioned/file-system.js +4 -4
- package/dist/esm/services/documentStore/versioned/dynamodb.d.ts +3 -3
- package/dist/esm/services/documentStore/versioned/dynamodb.js +3 -3
- package/dist/esm/services/documentStore/versioned/file-system.d.ts +3 -3
- package/dist/esm/services/documentStore/versioned/index.d.ts +1 -1
- package/dist/esm/services/exercisesGateway/index.d.ts +2 -2
- package/dist/esm/services/exercisesGateway/index.js +5 -5
- package/dist/esm/services/fileServer/index.js +1 -1
- package/dist/esm/services/fileServer/localFileServer.d.ts +2 -2
- package/dist/esm/services/fileServer/localFileServer.js +3 -3
- package/dist/esm/services/fileServer/s3FileServer.d.ts +2 -2
- package/dist/esm/services/fileServer/s3FileServer.js +4 -4
- package/dist/esm/services/httpMessageVerifier/index.d.ts +1 -1
- package/dist/esm/services/httpMessageVerifier/index.js +3 -3
- package/dist/esm/services/launchParams/signer.d.ts +2 -2
- package/dist/esm/services/launchParams/signer.js +3 -3
- package/dist/esm/services/launchParams/verifier.d.ts +1 -1
- package/dist/esm/services/launchParams/verifier.js +3 -3
- package/dist/esm/services/logger/console.d.ts +1 -1
- package/dist/esm/services/logger/console.js +1 -1
- package/dist/esm/services/logger/index.d.ts +1 -1
- package/dist/esm/services/lrsGateway/addStatementDefaultFields.d.ts +1 -1
- package/dist/esm/services/lrsGateway/attempt-utils.d.ts +7 -7
- package/dist/esm/services/lrsGateway/batching.d.ts +2 -2
- package/dist/esm/services/lrsGateway/batching.js +1 -1
- package/dist/esm/services/lrsGateway/file-system.d.ts +3 -3
- package/dist/esm/services/lrsGateway/file-system.js +4 -4
- package/dist/esm/services/lrsGateway/index.d.ts +4 -4
- package/dist/esm/services/lrsGateway/index.js +6 -6
- package/dist/esm/services/lrsGateway/xapiUtils.d.ts +3 -3
- package/dist/esm/services/lrsGateway/xapiUtils.js +1 -1
- package/dist/esm/services/postgresConnection/index.d.ts +2 -2
- package/dist/esm/services/postgresConnection/index.js +3 -3
- package/dist/esm/services/queueProvider/local.d.ts +2 -2
- package/dist/esm/services/queueProvider/local.js +2 -2
- package/dist/esm/services/queueProvider/sqs.d.ts +2 -2
- package/dist/esm/services/queueProvider/sqs.js +2 -2
- package/dist/esm/services/searchProvider/memorySearchTheBadWay.d.ts +1 -1
- package/dist/esm/services/searchProvider/memorySearchTheBadWay.js +3 -3
- package/dist/esm/services/searchProvider/openSearch.d.ts +2 -2
- package/dist/esm/services/searchProvider/openSearch.js +2 -2
- package/dist/esm/services/searchProvider/streamIndexer.d.ts +2 -2
- package/dist/esm/services/searchProvider/streamIndexer.js +1 -1
- package/dist/esm/tsconfig.without-specs.esm.tsbuildinfo +1 -1
- package/package.json +1 -1
- package/script/bin/.init-params-script.bash.swp +0 -0
|
@@ -39,16 +39,16 @@ Object.defineProperty(exports, "__esModule", { value: true });
|
|
|
39
39
|
exports.fileSystemUnversionedDocumentStore = void 0;
|
|
40
40
|
const fsModule = __importStar(require("fs"));
|
|
41
41
|
const path_1 = __importDefault(require("path"));
|
|
42
|
-
const
|
|
43
|
-
const
|
|
44
|
-
const
|
|
45
|
-
const
|
|
42
|
+
const __1 = require("../../..");
|
|
43
|
+
const config_1 = require("../../../config");
|
|
44
|
+
const errors_1 = require("../../../errors");
|
|
45
|
+
const guards_1 = require("../../../guards");
|
|
46
46
|
const fileSystemUnversionedDocumentStore = (initializer) => () => (configProvider) => (_, hashKey, options) => {
|
|
47
|
-
const tableName = (0,
|
|
47
|
+
const tableName = (0, config_1.resolveConfigValue)(configProvider[initializer.configSpace || 'fileSystem'].tableName);
|
|
48
48
|
const tablePath = tableName.then((table) => path_1.default.join(initializer.dataDir, table));
|
|
49
|
-
const { mkdir, readdir, readFile, writeFile } = (0,
|
|
49
|
+
const { mkdir, readdir, readFile, writeFile } = (0, guards_1.ifDefined)(initializer.fs, fsModule);
|
|
50
50
|
const mkTableDir = new Promise((resolve, reject) => tablePath.then((path) => mkdir(path, { recursive: true }, (err) => err && err.code !== 'EEXIST' ? reject(err) : resolve())));
|
|
51
|
-
const hashFilename = (value) => `${(0,
|
|
51
|
+
const hashFilename = (value) => `${(0, __1.hashValue)(value)}.json`;
|
|
52
52
|
const filePath = async (filename) => path_1.default.join(await tablePath, filename);
|
|
53
53
|
const load = async (filename) => {
|
|
54
54
|
const path = await filePath(filename);
|
|
@@ -76,7 +76,7 @@ const fileSystemUnversionedDocumentStore = (initializer) => () => (configProvide
|
|
|
76
76
|
return new Promise((resolve, reject) => readdir(path, (err, files) => err ?
|
|
77
77
|
reject(err) :
|
|
78
78
|
Promise.all(files.map((file) => load(file)))
|
|
79
|
-
.then((allData) => resolve(allData.filter(
|
|
79
|
+
.then((allData) => resolve(allData.filter(guards_1.isDefined)), (err) => reject(err))));
|
|
80
80
|
};
|
|
81
81
|
return {
|
|
82
82
|
loadAllDocumentsTheBadWay,
|
|
@@ -95,7 +95,7 @@ const fileSystemUnversionedDocumentStore = (initializer) => () => (configProvide
|
|
|
95
95
|
const items = await Promise.all(ids.map((id) => {
|
|
96
96
|
return load(hashFilename(id));
|
|
97
97
|
}));
|
|
98
|
-
return items.filter(
|
|
98
|
+
return items.filter(guards_1.isDefined);
|
|
99
99
|
},
|
|
100
100
|
getItem: (id) => {
|
|
101
101
|
return load(hashFilename(id));
|
|
@@ -106,7 +106,7 @@ const fileSystemUnversionedDocumentStore = (initializer) => () => (configProvide
|
|
|
106
106
|
await mkTableDir;
|
|
107
107
|
const data = await load(filename);
|
|
108
108
|
if (!data) {
|
|
109
|
-
throw new
|
|
109
|
+
throw new errors_1.NotFoundError(`Item with ${hashKey.toString()} "${id}" does not exist`);
|
|
110
110
|
}
|
|
111
111
|
const newValue = typeof data[attribute] === 'number' ? data[attribute] + 1 : 1;
|
|
112
112
|
const newItem = { ...data, [hashKey]: id, [attribute]: newValue };
|
|
@@ -128,7 +128,7 @@ const fileSystemUnversionedDocumentStore = (initializer) => () => (configProvide
|
|
|
128
128
|
await mkTableDir;
|
|
129
129
|
const data = await load(filename);
|
|
130
130
|
if (!data) {
|
|
131
|
-
throw new
|
|
131
|
+
throw new errors_1.NotFoundError(`Item with ${hashKey.toString()} "${id}" does not exist`);
|
|
132
132
|
}
|
|
133
133
|
const newItem = { ...data, ...item };
|
|
134
134
|
return new Promise((resolve, reject) => {
|
|
@@ -146,7 +146,7 @@ const fileSystemUnversionedDocumentStore = (initializer) => () => (configProvide
|
|
|
146
146
|
const hashed = hashFilename(item[hashKey]);
|
|
147
147
|
const existingItem = await load(hashed);
|
|
148
148
|
if (existingItem) {
|
|
149
|
-
throw new
|
|
149
|
+
throw new errors_1.ConflictError(`Item with ${String(hashKey)} "${item[hashKey]}" already exists`);
|
|
150
150
|
}
|
|
151
151
|
const path = await filePath(hashed);
|
|
152
152
|
await mkTableDir;
|
|
@@ -167,7 +167,7 @@ const fileSystemUnversionedDocumentStore = (initializer) => () => (configProvide
|
|
|
167
167
|
const hashed = hashFilename(item[hashKey]);
|
|
168
168
|
const existingItem = await load(hashed);
|
|
169
169
|
if (existingItem) {
|
|
170
|
-
throw new
|
|
170
|
+
throw new errors_1.ConflictError(`Item with ${String(hashKey)} "${item[hashKey]}" already exists`);
|
|
171
171
|
}
|
|
172
172
|
const path = await filePath(hashed);
|
|
173
173
|
await mkTableDir;
|
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
import { DynamoDB } from '@aws-sdk/client-dynamodb';
|
|
2
|
-
import { Config } from '
|
|
3
|
-
import { ConfigProviderForConfig } from '../../../config
|
|
4
|
-
import { VersionedDocumentAuthor, VersionedTDocument } from '
|
|
2
|
+
import { Config } from '..';
|
|
3
|
+
import { ConfigProviderForConfig } from '../../../config';
|
|
4
|
+
import { VersionedDocumentAuthor, VersionedTDocument } from '.';
|
|
5
5
|
interface Initializer<C> {
|
|
6
6
|
configSpace?: C;
|
|
7
7
|
dynamoClient?: DynamoDB;
|
|
@@ -2,16 +2,16 @@
|
|
|
2
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
3
|
exports.dynamoVersionedDocumentStore = void 0;
|
|
4
4
|
const client_dynamodb_1 = require("@aws-sdk/client-dynamodb");
|
|
5
|
-
const
|
|
6
|
-
const
|
|
7
|
-
const
|
|
5
|
+
const __1 = require("../../..");
|
|
6
|
+
const config_1 = require("../../../config");
|
|
7
|
+
const guards_1 = require("../../../guards");
|
|
8
8
|
const dynamoEncoding_1 = require("../dynamoEncoding");
|
|
9
9
|
// i'm not really excited about getAuthor being required, but ts is getting confused about the type when unspecified
|
|
10
10
|
const dynamoVersionedDocumentStore = (initializer) => {
|
|
11
|
-
const init = (0,
|
|
12
|
-
const dynamodb = (0,
|
|
11
|
+
const init = (0, guards_1.ifDefined)(initializer, {});
|
|
12
|
+
const dynamodb = (0, __1.once)(() => { var _a; return (_a = init.dynamoClient) !== null && _a !== void 0 ? _a : new client_dynamodb_1.DynamoDB({ apiVersion: '2012-08-10' }); });
|
|
13
13
|
return () => (configProvider) => (_, hashKey, options) => {
|
|
14
|
-
const tableName = (0,
|
|
14
|
+
const tableName = (0, __1.once)(() => (0, config_1.resolveConfigValue)(configProvider[(0, guards_1.ifDefined)(init.configSpace, 'dynamodb')].tableName));
|
|
15
15
|
return {
|
|
16
16
|
loadAllDocumentsTheBadWay: async () => {
|
|
17
17
|
const loadAllResults = async (ExclusiveStartKey) => {
|
|
@@ -1,6 +1,6 @@
|
|
|
1
|
-
import { Config } from '
|
|
2
|
-
import { ConfigProviderForConfig } from '../../../config
|
|
3
|
-
import { VersionedDocumentAuthor, VersionedTDocument } from '
|
|
1
|
+
import { Config } from '..';
|
|
2
|
+
import { ConfigProviderForConfig } from '../../../config';
|
|
3
|
+
import { VersionedDocumentAuthor, VersionedTDocument } from '.';
|
|
4
4
|
interface Initializer<C> {
|
|
5
5
|
dataDir: string;
|
|
6
6
|
fs?: Pick<typeof import('fs'), 'mkdir' | 'readdir' | 'readFile' | 'writeFile'>;
|
|
@@ -1,5 +1,5 @@
|
|
|
1
|
-
import { ConfigProviderForConfig } from '../../config
|
|
2
|
-
import { GenericFetch } from '../../fetch
|
|
1
|
+
import { ConfigProviderForConfig } from '../../config';
|
|
2
|
+
import { GenericFetch } from '../../fetch';
|
|
3
3
|
export type Config = {
|
|
4
4
|
defaultCorrectness?: string;
|
|
5
5
|
exercisesHost: string;
|
|
@@ -35,16 +35,16 @@ var __importStar = (this && this.__importStar) || (function () {
|
|
|
35
35
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
36
36
|
exports.exercisesGateway = void 0;
|
|
37
37
|
const queryString = __importStar(require("query-string"));
|
|
38
|
-
const
|
|
39
|
-
const
|
|
40
|
-
const
|
|
41
|
-
const
|
|
42
|
-
const
|
|
38
|
+
const __1 = require("../..");
|
|
39
|
+
const assertions_1 = require("../../assertions");
|
|
40
|
+
const config_1 = require("../../config");
|
|
41
|
+
const guards_1 = require("../../guards");
|
|
42
|
+
const routing_1 = require("../../routing");
|
|
43
43
|
const exercisesGateway = (initializer) => (configProvider) => {
|
|
44
|
-
const config = configProvider[(0,
|
|
45
|
-
const exercisesHost = (0,
|
|
46
|
-
const exercisesAuthToken = (0,
|
|
47
|
-
const defaultCorrectness = (0,
|
|
44
|
+
const config = configProvider[(0, guards_1.ifDefined)(initializer.configSpace, 'exercises')];
|
|
45
|
+
const exercisesHost = (0, __1.once)(() => (0, config_1.resolveConfigValue)(config.exercisesHost));
|
|
46
|
+
const exercisesAuthToken = (0, __1.once)(() => (0, config_1.resolveConfigValue)(config.exercisesAuthToken));
|
|
47
|
+
const defaultCorrectness = (0, __1.once)(() => (0, config_1.resolveConfigValue)(config.defaultCorrectness || ''));
|
|
48
48
|
const doDefaultCorrectness = async (exercise) => {
|
|
49
49
|
if (await defaultCorrectness() !== 'true') {
|
|
50
50
|
return exercise;
|
|
@@ -82,17 +82,17 @@ const exercisesGateway = (initializer) => (configProvider) => {
|
|
|
82
82
|
});
|
|
83
83
|
};
|
|
84
84
|
const searchDigest = async (query, page = 1, per_page = 100) => {
|
|
85
|
-
const response = await request(
|
|
86
|
-
return (0,
|
|
85
|
+
const response = await request(routing_1.METHOD.HEAD, 'exercises', { query, page, per_page });
|
|
86
|
+
return (0, assertions_1.assertString)(response.headers.get('X-Digest'), 'OpenStax Exercises search endpoint HEAD did not return an X-Digest header');
|
|
87
87
|
};
|
|
88
88
|
const search = async (query, page = 1, per_page = 100) => {
|
|
89
|
-
const response = await request(
|
|
90
|
-
const digest = (0,
|
|
89
|
+
const response = await request(routing_1.METHOD.GET, 'exercises', { query, page, per_page });
|
|
90
|
+
const digest = (0, assertions_1.assertString)(response.headers.get('X-Digest'), 'OpenStax Exercises search endpoint GET did not return an X-Digest header');
|
|
91
91
|
const { items, total_count } = await response.json();
|
|
92
92
|
return { digest, items: await Promise.all(items.map(doDefaultCorrectness)), total_count };
|
|
93
93
|
};
|
|
94
94
|
const get = async (uuid) => {
|
|
95
|
-
const response = await request(
|
|
95
|
+
const response = await request(routing_1.METHOD.GET, `exercises/${uuid}`);
|
|
96
96
|
return response.status === 404
|
|
97
97
|
? undefined
|
|
98
98
|
: response.json().then(doDefaultCorrectness);
|
|
@@ -1,15 +1,15 @@
|
|
|
1
1
|
"use strict";
|
|
2
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
3
|
exports.isFileOrFolder = exports.isFolderValue = exports.isFileValue = void 0;
|
|
4
|
-
const
|
|
5
|
-
const isFileValue = (thing) => (0,
|
|
4
|
+
const guards_1 = require("../../guards");
|
|
5
|
+
const isFileValue = (thing) => (0, guards_1.isPlainObject)(thing)
|
|
6
6
|
&& Object.keys(thing).every(key => ['dataType', 'path', 'label', 'mimeType'].includes(key))
|
|
7
7
|
&& thing.dataType === 'file'
|
|
8
8
|
&& typeof thing.mimeType === 'string'
|
|
9
9
|
&& typeof thing.path === 'string'
|
|
10
10
|
&& typeof thing.label === 'string';
|
|
11
11
|
exports.isFileValue = isFileValue;
|
|
12
|
-
const isFolderValue = (thing) => (0,
|
|
12
|
+
const isFolderValue = (thing) => (0, guards_1.isPlainObject)(thing)
|
|
13
13
|
&& Object.keys(thing).every(key => ['dataType', 'files'].includes(key))
|
|
14
14
|
&& thing.dataType === 'folder'
|
|
15
15
|
&& thing.files instanceof Array
|
|
@@ -13,9 +13,9 @@ const cors_1 = __importDefault(require("cors"));
|
|
|
13
13
|
const express_1 = __importDefault(require("express"));
|
|
14
14
|
const multer_1 = __importDefault(require("multer"));
|
|
15
15
|
const uuid_1 = require("uuid");
|
|
16
|
-
const
|
|
17
|
-
const
|
|
18
|
-
const
|
|
16
|
+
const assertions_1 = require("../../assertions");
|
|
17
|
+
const config_1 = require("../../config");
|
|
18
|
+
const guards_1 = require("../../guards");
|
|
19
19
|
const helpers_1 = require("../../misc/helpers");
|
|
20
20
|
/* istanbul ignore next */
|
|
21
21
|
const startServer = (0, helpers_1.memoize)((port, uploadDir) => {
|
|
@@ -37,8 +37,8 @@ const startServer = (0, helpers_1.memoize)((port, uploadDir) => {
|
|
|
37
37
|
res.status(201).send();
|
|
38
38
|
});
|
|
39
39
|
const server = https_1.default.createServer({
|
|
40
|
-
key: fs_1.default.readFileSync((0,
|
|
41
|
-
cert: fs_1.default.readFileSync((0,
|
|
40
|
+
key: fs_1.default.readFileSync((0, assertions_1.assertString)(process.env.SSL_KEY_FILE, new Error('ssl key is required for localFileServer')), 'utf8'),
|
|
41
|
+
cert: fs_1.default.readFileSync((0, assertions_1.assertString)(process.env.SSL_CRT_FILE, new Error('ssl key is required for localFileServer')), 'utf8'),
|
|
42
42
|
}, fileServerApp);
|
|
43
43
|
server.once('error', function (err) {
|
|
44
44
|
if (err.code === 'EADDRINUSE') {
|
|
@@ -53,10 +53,10 @@ const startServer = (0, helpers_1.memoize)((port, uploadDir) => {
|
|
|
53
53
|
return true;
|
|
54
54
|
});
|
|
55
55
|
const localFileServer = (initializer) => (configProvider) => {
|
|
56
|
-
const config = configProvider[(0,
|
|
57
|
-
const port = (0,
|
|
58
|
-
const host = (0,
|
|
59
|
-
const storagePrefix = (0,
|
|
56
|
+
const config = configProvider[(0, guards_1.ifDefined)(initializer.configSpace, 'local')];
|
|
57
|
+
const port = (0, config_1.resolveConfigValue)(config.port || '');
|
|
58
|
+
const host = (0, config_1.resolveConfigValue)(config.host || '');
|
|
59
|
+
const storagePrefix = (0, config_1.resolveConfigValue)(config.storagePrefix);
|
|
60
60
|
const fileDir = storagePrefix.then((prefix) => path_1.default.join(initializer.dataDir, prefix));
|
|
61
61
|
Promise.all([port, fileDir])
|
|
62
62
|
.then(([port, fileDir]) => port && startServer(port, fileDir));
|
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
import { S3Client } from '@aws-sdk/client-s3';
|
|
2
|
-
import { ConfigProviderForConfig } from '../../config
|
|
3
|
-
import { FileServerAdapter } from '
|
|
2
|
+
import { ConfigProviderForConfig } from '../../config';
|
|
3
|
+
import { FileServerAdapter } from '.';
|
|
4
4
|
export type Config = {
|
|
5
5
|
bucketName: string;
|
|
6
6
|
bucketRegion: string;
|
|
@@ -10,18 +10,18 @@ const client_s3_1 = require("@aws-sdk/client-s3");
|
|
|
10
10
|
const s3_presigned_post_1 = require("@aws-sdk/s3-presigned-post");
|
|
11
11
|
const s3_request_presigner_1 = require("@aws-sdk/s3-request-presigner");
|
|
12
12
|
const uuid_1 = require("uuid");
|
|
13
|
-
const
|
|
14
|
-
const
|
|
15
|
-
const
|
|
16
|
-
const
|
|
13
|
+
const __1 = require("../..");
|
|
14
|
+
const assertions_1 = require("../../assertions");
|
|
15
|
+
const config_1 = require("../../config");
|
|
16
|
+
const guards_1 = require("../../guards");
|
|
17
17
|
const s3FileServer = (initializer) => (configProvider) => {
|
|
18
|
-
const config = configProvider[(0,
|
|
19
|
-
const bucketName = (0,
|
|
20
|
-
const bucketRegion = (0,
|
|
21
|
-
const publicViewerDomain = (0,
|
|
22
|
-
? (0,
|
|
18
|
+
const config = configProvider[(0, guards_1.ifDefined)(initializer.configSpace, 'deployed')];
|
|
19
|
+
const bucketName = (0, __1.once)(() => (0, config_1.resolveConfigValue)(config.bucketName));
|
|
20
|
+
const bucketRegion = (0, __1.once)(() => (0, config_1.resolveConfigValue)(config.bucketRegion));
|
|
21
|
+
const publicViewerDomain = (0, __1.once)(() => 'publicViewerDomain' in config && config.publicViewerDomain
|
|
22
|
+
? (0, config_1.resolveConfigValue)(config.publicViewerDomain)
|
|
23
23
|
: undefined);
|
|
24
|
-
const s3Service = (0,
|
|
24
|
+
const s3Service = (0, __1.once)(async () => {
|
|
25
25
|
var _a, _b;
|
|
26
26
|
const args = { apiVersion: '2012-08-10', region: await bucketRegion() };
|
|
27
27
|
return (_b = (_a = initializer.getS3Client) === null || _a === void 0 ? void 0 : _a.call(initializer, args)) !== null && _b !== void 0 ? _b : new client_s3_1.S3Client(args);
|
|
@@ -37,14 +37,14 @@ const s3FileServer = (initializer) => (configProvider) => {
|
|
|
37
37
|
});
|
|
38
38
|
};
|
|
39
39
|
const getPublicViewerUrl = async (source) => {
|
|
40
|
-
const host = (0,
|
|
40
|
+
const host = (0, assertions_1.assertDefined)(await publicViewerDomain(), new Error(`Tried to get public viewer URL for ${source.path} but no publicViewerDomain configured`));
|
|
41
41
|
return `https://${host}/${source.path}`;
|
|
42
42
|
};
|
|
43
43
|
const getFileContent = async (source) => {
|
|
44
44
|
const bucket = await bucketName();
|
|
45
45
|
const command = new client_s3_1.GetObjectCommand({ Bucket: bucket, Key: source.path });
|
|
46
46
|
const response = await (await s3Service()).send(command);
|
|
47
|
-
return Buffer.from(await (0,
|
|
47
|
+
return Buffer.from(await (0, assertions_1.assertDefined)(response.Body, new Error('Invalid Response from s3')).transformToByteArray());
|
|
48
48
|
};
|
|
49
49
|
const putFileContent = async (source, content) => {
|
|
50
50
|
const bucket = await bucketName();
|
|
@@ -110,7 +110,7 @@ const s3FileServer = (initializer) => (configProvider) => {
|
|
|
110
110
|
const bucket = (await bucketName());
|
|
111
111
|
const command = new client_s3_1.HeadObjectCommand({ Bucket: bucket, Key: source.path });
|
|
112
112
|
const response = await (await s3Service()).send(command);
|
|
113
|
-
return (0,
|
|
113
|
+
return (0, assertions_1.assertDefined)(response.ETag);
|
|
114
114
|
};
|
|
115
115
|
const filesEqual = async (sourceA, sourceB) => {
|
|
116
116
|
const [aSum, bSum] = await Promise.all([getFileChecksum(sourceA), getFileChecksum(sourceB)]);
|
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
import { APIGatewayProxyEventV2 } from 'aws-lambda';
|
|
2
2
|
import { VerifyConfig } from 'http-message-signatures';
|
|
3
3
|
import { JWK } from 'node-jose';
|
|
4
|
-
import { ConfigProviderForConfig } from '../../config
|
|
4
|
+
import { ConfigProviderForConfig } from '../../config';
|
|
5
5
|
type Config = {
|
|
6
6
|
apiHost: string;
|
|
7
7
|
bypassSignatureVerification: string;
|
|
@@ -6,15 +6,15 @@ const crypto_1 = require("crypto");
|
|
|
6
6
|
const http_message_signatures_1 = require("http-message-signatures");
|
|
7
7
|
const jwks_rsa_1 = require("jwks-rsa");
|
|
8
8
|
const structured_headers_1 = require("structured-headers");
|
|
9
|
-
const
|
|
10
|
-
const
|
|
11
|
-
const
|
|
9
|
+
const assertions_1 = require("../../assertions");
|
|
10
|
+
const config_1 = require("../../config");
|
|
11
|
+
const errors_1 = require("../../errors");
|
|
12
12
|
const helpers_1 = require("../../misc/helpers");
|
|
13
13
|
const jwks_1 = require("../../misc/jwks");
|
|
14
14
|
const createHttpMessageVerifier = ({ configSpace, fetcher }) => (configProvider) => {
|
|
15
15
|
const config = configProvider[configSpace !== null && configSpace !== void 0 ? configSpace : 'verifier'];
|
|
16
|
-
const getApiHost = (0, helpers_1.once)(async () => await (0,
|
|
17
|
-
const getBypassSignatureVerification = (0, helpers_1.once)(async () => (await (0,
|
|
16
|
+
const getApiHost = (0, helpers_1.once)(async () => await (0, config_1.resolveConfigValue)(config.apiHost));
|
|
17
|
+
const getBypassSignatureVerification = (0, helpers_1.once)(async () => (await (0, config_1.resolveConfigValue)(config.bypassSignatureVerification)) === 'true');
|
|
18
18
|
return ({ request }) => ({
|
|
19
19
|
verify: async ({ configOverride, signatureAgentVerifier }) => {
|
|
20
20
|
var _a;
|
|
@@ -46,14 +46,14 @@ const createHttpMessageVerifier = ({ configSpace, fetcher }) => (configProvider)
|
|
|
46
46
|
if (bareItem instanceof structured_headers_1.Token) {
|
|
47
47
|
return bareItem.toString();
|
|
48
48
|
}
|
|
49
|
-
return (0,
|
|
49
|
+
return (0, assertions_1.assertString)(bareItem, new errors_1.InvalidRequestError('Signature-Agent values must be strings or tokens'));
|
|
50
50
|
}))];
|
|
51
51
|
if (signatureAgents.length === 0) {
|
|
52
|
-
throw new
|
|
52
|
+
throw new errors_1.InvalidRequestError('Signature-Agent header is required');
|
|
53
53
|
}
|
|
54
54
|
const keys = (await Promise.all(signatureAgents.map(async (signatureAgent) => {
|
|
55
55
|
if (!await signatureAgentVerifier(signatureAgent)) {
|
|
56
|
-
throw new
|
|
56
|
+
throw new errors_1.InvalidRequestError('Signature-Agent verification failed');
|
|
57
57
|
}
|
|
58
58
|
return (0, jwks_1.getJwksClient)(signatureAgent, fetcher).getSigningKeys();
|
|
59
59
|
}))).flat();
|
|
@@ -79,7 +79,7 @@ const createHttpMessageVerifier = ({ configSpace, fetcher }) => (configProvider)
|
|
|
79
79
|
throw new jwks_rsa_1.SigningKeyNotFoundError(`Unable to find a signing key that matches "${keyid}"`);
|
|
80
80
|
const alg = (_a = parameters.alg) !== null && _a !== void 0 ? _a : key.alg;
|
|
81
81
|
if (!alg) {
|
|
82
|
-
throw new
|
|
82
|
+
throw new errors_1.InvalidRequestError('Signature algorithm must be specified either as a signature param or in the JWKS key');
|
|
83
83
|
}
|
|
84
84
|
return {
|
|
85
85
|
id: key.kid,
|
|
@@ -91,7 +91,7 @@ const createHttpMessageVerifier = ({ configSpace, fetcher }) => (configProvider)
|
|
|
91
91
|
tolerance: 300,
|
|
92
92
|
...configOverride,
|
|
93
93
|
}, verificationRequest))
|
|
94
|
-
throw new
|
|
94
|
+
throw new errors_1.InvalidRequestError('Signature verification failed');
|
|
95
95
|
// For example, if a GET request uses configOverride to make content-digest not required
|
|
96
96
|
if (!headers['content-digest'])
|
|
97
97
|
return true;
|
|
@@ -100,10 +100,10 @@ const createHttpMessageVerifier = ({ configSpace, fetcher }) => (configProvider)
|
|
|
100
100
|
contentDigest = (0, structured_headers_1.parseDictionary)(headers['content-digest']);
|
|
101
101
|
}
|
|
102
102
|
catch {
|
|
103
|
-
throw new
|
|
103
|
+
throw new errors_1.InvalidRequestError('Unsupported Content-Digest header format');
|
|
104
104
|
}
|
|
105
105
|
if (contentDigest.size === 0) {
|
|
106
|
-
throw new
|
|
106
|
+
throw new errors_1.InvalidRequestError('Content-Digest header is required');
|
|
107
107
|
}
|
|
108
108
|
// Map Content-Digest algorithm names to Node's crypto algorithm names
|
|
109
109
|
const algorithmMap = {
|
|
@@ -115,16 +115,16 @@ const createHttpMessageVerifier = ({ configSpace, fetcher }) => (configProvider)
|
|
|
115
115
|
// Convert ByteSequence to string, or assert it's already a string
|
|
116
116
|
const hashValue = bareItem instanceof structured_headers_1.ByteSequence
|
|
117
117
|
? bareItem.toBase64()
|
|
118
|
-
: (0,
|
|
118
|
+
: (0, assertions_1.assertString)(bareItem, new errors_1.InvalidRequestError('Content-Digest values must be strings'));
|
|
119
119
|
const cryptoAlgorithm = algorithmMap[algorithm];
|
|
120
120
|
if (!cryptoAlgorithm) {
|
|
121
|
-
throw new
|
|
121
|
+
throw new errors_1.InvalidRequestError(`Unsupported Content-Digest algorithm: ${algorithm}`);
|
|
122
122
|
}
|
|
123
123
|
// Calculate the hash
|
|
124
|
-
const calculatedHash = (0, crypto_1.createHash)(cryptoAlgorithm).update((0,
|
|
124
|
+
const calculatedHash = (0, crypto_1.createHash)(cryptoAlgorithm).update((0, assertions_1.assertString)(body, new errors_1.InvalidRequestError('Request body is required when Content-Digest is present'))).digest('base64');
|
|
125
125
|
// Compare with the provided hash
|
|
126
126
|
if (calculatedHash !== hashValue) {
|
|
127
|
-
throw new
|
|
127
|
+
throw new errors_1.InvalidRequestError(`Calculated Content-Digest value did not match header for algorithm ${algorithm}`);
|
|
128
128
|
}
|
|
129
129
|
}
|
|
130
130
|
return true;
|
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
import { JWK } from 'node-jose';
|
|
2
|
-
import { ConfigProviderForConfig } from '../../config
|
|
3
|
-
import type { JsonCompatibleStruct } from '../../routing
|
|
2
|
+
import { ConfigProviderForConfig } from '../../config';
|
|
3
|
+
import type { JsonCompatibleStruct } from '../../routing';
|
|
4
4
|
type Config = {
|
|
5
5
|
alg: string;
|
|
6
6
|
expiresIn: string;
|
|
@@ -7,9 +7,9 @@ exports.createLaunchSigner = void 0;
|
|
|
7
7
|
const jsonwebtoken_1 = __importDefault(require("jsonwebtoken"));
|
|
8
8
|
const ms_1 = __importDefault(require("ms"));
|
|
9
9
|
const node_jose_1 = require("node-jose");
|
|
10
|
-
const
|
|
11
|
-
const
|
|
12
|
-
const
|
|
10
|
+
const __1 = require("../..");
|
|
11
|
+
const config_1 = require("../../config");
|
|
12
|
+
const guards_1 = require("../../guards");
|
|
13
13
|
const SUPPORTED_ALGORITHMS = [
|
|
14
14
|
'RS256', 'RS384', 'RS512', 'ES256', 'ES384', 'ES512', 'HS256', 'HS384', 'HS512', 'PS256', 'PS384', 'PS512'
|
|
15
15
|
];
|
|
@@ -23,12 +23,12 @@ const assertAlg = (alg) => {
|
|
|
23
23
|
* Creates a class that can sign launch params
|
|
24
24
|
*/
|
|
25
25
|
const createLaunchSigner = ({ configSpace }) => (configProvider) => {
|
|
26
|
-
const config = configProvider[(0,
|
|
27
|
-
const getAlg = (0,
|
|
28
|
-
const getExpiresIn = (0,
|
|
29
|
-
const getIss = (0,
|
|
30
|
-
const getPrivateKey = (0,
|
|
31
|
-
const getKeyStore = (0,
|
|
26
|
+
const config = configProvider[(0, guards_1.ifDefined)(configSpace, 'launch')];
|
|
27
|
+
const getAlg = (0, __1.once)(async () => assertAlg(await (0, config_1.resolveConfigValue)(config.alg)));
|
|
28
|
+
const getExpiresIn = (0, __1.once)(() => (0, config_1.resolveConfigValue)(config.expiresIn));
|
|
29
|
+
const getIss = (0, __1.once)(() => (0, config_1.resolveConfigValue)(config.iss));
|
|
30
|
+
const getPrivateKey = (0, __1.once)(() => (0, config_1.resolveConfigValue)(config.privateKey));
|
|
31
|
+
const getKeyStore = (0, __1.once)(async () => {
|
|
32
32
|
const keystore = node_jose_1.JWK.createKeyStore();
|
|
33
33
|
await keystore.add(await getPrivateKey(), 'pem');
|
|
34
34
|
return keystore;
|
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
import jwt from 'jsonwebtoken';
|
|
2
2
|
import type { JWK } from 'node-jose';
|
|
3
|
-
import { ConfigProviderForConfig } from '../../config
|
|
3
|
+
import { ConfigProviderForConfig } from '../../config';
|
|
4
4
|
type Config = {
|
|
5
5
|
trustedDomain: string;
|
|
6
6
|
bypassSignatureVerification: string;
|
|
@@ -35,18 +35,18 @@ var __importStar = (this && this.__importStar) || (function () {
|
|
|
35
35
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
36
36
|
exports.createLaunchVerifier = void 0;
|
|
37
37
|
const jsonwebtoken_1 = __importStar(require("jsonwebtoken"));
|
|
38
|
-
const
|
|
39
|
-
const
|
|
40
|
-
const
|
|
38
|
+
const config_1 = require("../../config");
|
|
39
|
+
const errors_1 = require("../../errors");
|
|
40
|
+
const guards_1 = require("../../guards");
|
|
41
41
|
const helpers_1 = require("../../misc/helpers");
|
|
42
42
|
const jwks_1 = require("../../misc/jwks");
|
|
43
43
|
/**
|
|
44
44
|
* Creates a class that can verify launch params
|
|
45
45
|
*/
|
|
46
46
|
const createLaunchVerifier = ({ configSpace, fetcher }) => (configProvider) => {
|
|
47
|
-
const config = configProvider[(0,
|
|
48
|
-
const getTrustedDomain = (0, helpers_1.once)(() => (0,
|
|
49
|
-
const getBypassSignatureVerification = (0, helpers_1.once)(async () => (await (0,
|
|
47
|
+
const config = configProvider[(0, guards_1.ifDefined)(configSpace, 'launch')];
|
|
48
|
+
const getTrustedDomain = (0, helpers_1.once)(() => (0, config_1.resolveConfigValue)(config.trustedDomain));
|
|
49
|
+
const getBypassSignatureVerification = (0, helpers_1.once)(async () => (await (0, config_1.resolveConfigValue)(config.bypassSignatureVerification)) === 'true');
|
|
50
50
|
const getKey = async (header, callback) => {
|
|
51
51
|
// The JWT spec allows iss in the header as a copy of the iss claim, but we require it
|
|
52
52
|
const { iss, kid } = header;
|
|
@@ -77,11 +77,11 @@ const createLaunchVerifier = ({ configSpace, fetcher }) => (configProvider) => {
|
|
|
77
77
|
return new Promise((resolve, reject) => {
|
|
78
78
|
const token = inputToken !== null && inputToken !== void 0 ? inputToken : getDefaultToken === null || getDefaultToken === void 0 ? void 0 : getDefaultToken();
|
|
79
79
|
if (!token) {
|
|
80
|
-
return reject(new
|
|
80
|
+
return reject(new errors_1.InvalidRequestError('Missing token for launch verification'));
|
|
81
81
|
}
|
|
82
82
|
const resolvePayload = (err, payload) => {
|
|
83
83
|
if (err && err instanceof jsonwebtoken_1.TokenExpiredError) {
|
|
84
|
-
reject(new
|
|
84
|
+
reject(new errors_1.SessionExpiredError());
|
|
85
85
|
}
|
|
86
86
|
else if (err) {
|
|
87
87
|
reject(err);
|
|
@@ -1,11 +1,11 @@
|
|
|
1
1
|
"use strict";
|
|
2
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
3
|
exports.createConsoleLogger = void 0;
|
|
4
|
-
const
|
|
4
|
+
const _1 = require(".");
|
|
5
5
|
/**
|
|
6
6
|
* Creates a logger that logs to the console.
|
|
7
7
|
*/
|
|
8
|
-
const createConsoleLogger = () => (0,
|
|
8
|
+
const createConsoleLogger = () => (0, _1.createCoreLogger)((level, event) => console[level](JSON.stringify({
|
|
9
9
|
eventType: level.toUpperCase(),
|
|
10
10
|
...event,
|
|
11
11
|
})));
|
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import { EagerXapiStatement, UXapiStatement, XapiStatement } from '
|
|
1
|
+
import { EagerXapiStatement, UXapiStatement, XapiStatement } from '.';
|
|
2
2
|
export declare const addStatementDefaultFields: (statement: (Pick<XapiStatement, "object" | "verb" | "context" | "result"> & {
|
|
3
3
|
id?: string;
|
|
4
4
|
}) | UXapiStatement, user: {
|
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import { LrsGateway, UXapiStatement } from '
|
|
1
|
+
import { LrsGateway, UXapiStatement } from '.';
|
|
2
2
|
export declare const EXT_PENDING_SCORING = "https://openstax.org/xapi/extensions/pending-scoring";
|
|
3
3
|
export type AttemptEntry = {
|
|
4
4
|
attempt: UXapiStatement;
|
|
@@ -40,7 +40,7 @@ export declare const loadStatementsForActivityAndFirstChildren: (gateway: LrsGat
|
|
|
40
40
|
attempt?: string;
|
|
41
41
|
ensureSync?: boolean;
|
|
42
42
|
user?: string;
|
|
43
|
-
}) => Promise<import("
|
|
43
|
+
}) => Promise<import(".").XapiStatement[]>;
|
|
44
44
|
export declare const loadActivityAttemptInfo: (gateway: LrsGateway, activityIRI: string, options?: {
|
|
45
45
|
currentAttempt?: string;
|
|
46
46
|
parentActivityAttempt?: string;
|
|
@@ -75,12 +75,12 @@ export declare const putAttemptStatement: (gateway: LrsGateway, activity: {
|
|
|
75
75
|
}, parentActivity?: {
|
|
76
76
|
iri?: string;
|
|
77
77
|
attempt?: string;
|
|
78
|
-
}) => Promise<import("
|
|
78
|
+
}) => Promise<import(".").EagerXapiStatement>;
|
|
79
79
|
export declare const createAttemptActivityStatement: (attemptStatement: UXapiStatement, verb: UXapiStatement["verb"], result?: UXapiStatement["result"]) => Pick<UXapiStatement, "object" | "verb" | "context" | "result">;
|
|
80
|
-
export declare const putAttemptActivityStatement: (gateway: LrsGateway, attemptStatement: UXapiStatement, verb: UXapiStatement["verb"], result?: UXapiStatement["result"]) => Promise<import("
|
|
80
|
+
export declare const putAttemptActivityStatement: (gateway: LrsGateway, attemptStatement: UXapiStatement, verb: UXapiStatement["verb"], result?: UXapiStatement["result"]) => Promise<import(".").EagerXapiStatement>;
|
|
81
81
|
export declare const createCompletedStatement: (attemptStatement: UXapiStatement, result?: UXapiStatement["result"]) => Pick<UXapiStatement, "object" | "verb" | "context" | "result">;
|
|
82
|
-
export declare const putCompletedStatement: (gateway: LrsGateway, attemptStatement: UXapiStatement, result: UXapiStatement["result"], user?: string) => Promise<import("
|
|
82
|
+
export declare const putCompletedStatement: (gateway: LrsGateway, attemptStatement: UXapiStatement, result: UXapiStatement["result"], user?: string) => Promise<import(".").EagerXapiStatement>;
|
|
83
83
|
export declare const createCompletedPendingScoringStatement: (attemptStatement: UXapiStatement) => Pick<UXapiStatement, "object" | "verb" | "context" | "result">;
|
|
84
|
-
export declare const putCompletedPendingScoringStatement: (gateway: LrsGateway, attemptStatement: UXapiStatement, user?: string) => Promise<import("
|
|
84
|
+
export declare const putCompletedPendingScoringStatement: (gateway: LrsGateway, attemptStatement: UXapiStatement, user?: string) => Promise<import(".").EagerXapiStatement>;
|
|
85
85
|
export declare const createScoredStatement: (attemptStatement: UXapiStatement, result: UXapiStatement["result"]) => Pick<UXapiStatement, "object" | "verb" | "context" | "result">;
|
|
86
|
-
export declare const putScoredStatement: (gateway: LrsGateway, attemptStatement: UXapiStatement, result: UXapiStatement["result"], user?: string) => Promise<import("
|
|
86
|
+
export declare const putScoredStatement: (gateway: LrsGateway, attemptStatement: UXapiStatement, result: UXapiStatement["result"], user?: string) => Promise<import(".").EagerXapiStatement>;
|
|
@@ -1,5 +1,5 @@
|
|
|
1
|
-
import { GenericFetch, Response } from '../../fetch
|
|
2
|
-
import { METHOD } from '../../routing
|
|
1
|
+
import { GenericFetch, Response } from '../../fetch';
|
|
2
|
+
import { METHOD } from '../../routing';
|
|
3
3
|
export interface BatchRequest {
|
|
4
4
|
id: string;
|
|
5
5
|
path: string;
|