@openstax/ts-utils 1.29.0 → 1.30.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/assertions/index.d.ts +7 -3
- package/dist/cjs/config/envConfig.d.ts +1 -1
- package/dist/cjs/config/index.d.ts +7 -7
- package/dist/cjs/config/resolveConfigValue.d.ts +2 -2
- package/dist/cjs/fetch/index.d.ts +16 -16
- package/dist/cjs/fetch/index.js +1 -1
- package/dist/cjs/middleware/apiErrorHandler.d.ts +3 -3
- package/dist/cjs/middleware/apiSlowResponseMiddleware.d.ts +1 -1
- package/dist/cjs/middleware/index.d.ts +7 -7
- package/dist/cjs/middleware/lambdaCorsResponseMiddleware.d.ts +1 -1
- package/dist/cjs/misc/hashValue.d.ts +2 -2
- package/dist/cjs/misc/helpers.d.ts +11 -11
- package/dist/cjs/misc/merge.d.ts +2 -2
- package/dist/cjs/misc/partitionSequence.d.ts +2 -2
- package/dist/cjs/pagination/index.d.ts +1 -1
- package/dist/cjs/routing/index.d.ts +30 -30
- package/dist/cjs/routing/index.js +18 -8
- package/dist/cjs/routing/validators/zod.d.ts +1 -1
- package/dist/cjs/routing/validators/zod.js +3 -1
- package/dist/cjs/services/accountsGateway/index.d.ts +17 -20
- package/dist/cjs/services/apiGateway/index.d.ts +10 -10
- package/dist/cjs/services/apiGateway/index.js +17 -7
- package/dist/cjs/services/authProvider/browser.d.ts +5 -7
- package/dist/cjs/services/authProvider/decryption.d.ts +3 -7
- package/dist/cjs/services/authProvider/index.d.ts +8 -8
- package/dist/cjs/services/authProvider/subrequest.d.ts +2 -5
- package/dist/cjs/services/authProvider/utils/decryptAndVerify.d.ts +1 -2
- package/dist/cjs/services/authProvider/utils/embeddedAuthProvider.d.ts +4 -4
- package/dist/cjs/services/authProvider/utils/embeddedAuthProvider.js +1 -1
- package/dist/cjs/services/authProvider/utils/userRoleValidator.d.ts +2 -2
- package/dist/cjs/services/documentStore/index.d.ts +7 -7
- package/dist/cjs/services/documentStore/unversioned/dynamodb.d.ts +7 -9
- package/dist/cjs/services/documentStore/unversioned/file-system.d.ts +7 -9
- package/dist/cjs/services/documentStore/unversioned/file-system.js +17 -7
- package/dist/cjs/services/documentStore/unversioned/index.d.ts +1 -1
- package/dist/cjs/services/documentStore/versioned/dynamodb.d.ts +7 -9
- package/dist/cjs/services/documentStore/versioned/file-system.d.ts +6 -8
- package/dist/cjs/services/documentStore/versioned/index.d.ts +4 -4
- package/dist/cjs/services/exercisesGateway/index.d.ts +9 -13
- package/dist/cjs/services/exercisesGateway/index.js +17 -7
- package/dist/cjs/services/fileServer/index.d.ts +13 -3
- package/dist/cjs/services/fileServer/localFileServer.d.ts +2 -6
- package/dist/cjs/services/fileServer/localFileServer.js +47 -0
- package/dist/cjs/services/fileServer/s3FileServer.d.ts +2 -5
- package/dist/cjs/services/fileServer/s3FileServer.js +70 -0
- package/dist/cjs/services/launchParams/signer.d.ts +4 -9
- package/dist/cjs/services/launchParams/verifier.d.ts +4 -7
- package/dist/cjs/services/launchParams/verifier.js +17 -7
- package/dist/cjs/services/logger/index.d.ts +2 -2
- package/dist/cjs/services/logger/index.js +1 -1
- package/dist/cjs/services/lrsGateway/addStatementDefaultFields.d.ts +1 -1
- package/dist/cjs/services/lrsGateway/attempt-utils.d.ts +34 -34
- package/dist/cjs/services/lrsGateway/file-system.d.ts +2 -4
- package/dist/cjs/services/lrsGateway/file-system.js +17 -7
- package/dist/cjs/services/lrsGateway/index.d.ts +29 -32
- package/dist/cjs/services/lrsGateway/index.js +17 -7
- package/dist/cjs/services/lrsGateway/xapiUtils.d.ts +23 -23
- package/dist/cjs/services/postgresConnection/index.d.ts +3 -10
- package/dist/cjs/services/searchProvider/index.d.ts +7 -7
- package/dist/cjs/services/searchProvider/memorySearchTheBadWay.d.ts +1 -1
- package/dist/cjs/services/searchProvider/openSearch.d.ts +3 -6
- package/dist/cjs/services/searchProvider/openSearch.js +7 -3
- package/dist/cjs/tsconfig.without-specs.cjs.tsbuildinfo +1 -1
- package/dist/cjs/types.d.ts +5 -5
- package/dist/esm/assertions/index.d.ts +7 -3
- package/dist/esm/config/envConfig.d.ts +1 -1
- package/dist/esm/config/index.d.ts +7 -7
- package/dist/esm/config/resolveConfigValue.d.ts +2 -2
- package/dist/esm/fetch/index.d.ts +16 -16
- package/dist/esm/middleware/apiErrorHandler.d.ts +3 -3
- package/dist/esm/middleware/apiSlowResponseMiddleware.d.ts +1 -1
- package/dist/esm/middleware/index.d.ts +7 -7
- package/dist/esm/middleware/lambdaCorsResponseMiddleware.d.ts +1 -1
- package/dist/esm/misc/hashValue.d.ts +2 -2
- package/dist/esm/misc/helpers.d.ts +11 -11
- package/dist/esm/misc/merge.d.ts +2 -2
- package/dist/esm/misc/partitionSequence.d.ts +2 -2
- package/dist/esm/pagination/index.d.ts +1 -1
- package/dist/esm/routing/index.d.ts +30 -30
- package/dist/esm/routing/validators/zod.d.ts +1 -1
- package/dist/esm/routing/validators/zod.js +3 -1
- package/dist/esm/services/accountsGateway/index.d.ts +17 -20
- package/dist/esm/services/apiGateway/index.d.ts +10 -10
- package/dist/esm/services/authProvider/browser.d.ts +5 -7
- package/dist/esm/services/authProvider/decryption.d.ts +3 -7
- package/dist/esm/services/authProvider/index.d.ts +8 -8
- package/dist/esm/services/authProvider/subrequest.d.ts +2 -5
- package/dist/esm/services/authProvider/utils/decryptAndVerify.d.ts +1 -2
- package/dist/esm/services/authProvider/utils/embeddedAuthProvider.d.ts +4 -4
- package/dist/esm/services/authProvider/utils/userRoleValidator.d.ts +2 -2
- package/dist/esm/services/documentStore/index.d.ts +7 -7
- package/dist/esm/services/documentStore/unversioned/dynamodb.d.ts +7 -9
- package/dist/esm/services/documentStore/unversioned/file-system.d.ts +7 -9
- package/dist/esm/services/documentStore/unversioned/index.d.ts +1 -1
- package/dist/esm/services/documentStore/versioned/dynamodb.d.ts +7 -9
- package/dist/esm/services/documentStore/versioned/file-system.d.ts +6 -8
- package/dist/esm/services/documentStore/versioned/index.d.ts +4 -4
- package/dist/esm/services/exercisesGateway/index.d.ts +9 -13
- package/dist/esm/services/fileServer/index.d.ts +13 -3
- package/dist/esm/services/fileServer/localFileServer.d.ts +2 -6
- package/dist/esm/services/fileServer/localFileServer.js +47 -0
- package/dist/esm/services/fileServer/s3FileServer.d.ts +2 -5
- package/dist/esm/services/fileServer/s3FileServer.js +68 -1
- package/dist/esm/services/launchParams/signer.d.ts +4 -9
- package/dist/esm/services/launchParams/verifier.d.ts +4 -7
- package/dist/esm/services/logger/index.d.ts +2 -2
- package/dist/esm/services/lrsGateway/addStatementDefaultFields.d.ts +1 -1
- package/dist/esm/services/lrsGateway/attempt-utils.d.ts +34 -34
- package/dist/esm/services/lrsGateway/file-system.d.ts +2 -4
- package/dist/esm/services/lrsGateway/index.d.ts +29 -32
- package/dist/esm/services/lrsGateway/xapiUtils.d.ts +23 -23
- package/dist/esm/services/postgresConnection/index.d.ts +3 -10
- package/dist/esm/services/searchProvider/index.d.ts +7 -7
- package/dist/esm/services/searchProvider/memorySearchTheBadWay.d.ts +1 -1
- package/dist/esm/services/searchProvider/openSearch.d.ts +3 -6
- package/dist/esm/services/searchProvider/openSearch.js +7 -3
- package/dist/esm/tsconfig.without-specs.esm.tsbuildinfo +1 -1
- package/dist/esm/types.d.ts +5 -5
- package/package.json +10 -9
- package/script/bin/.init-params-script.bash.swp +0 -0
- package/script/bin/copy-from-template.bash +6 -1
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
import { ConfigProviderForConfig } from '../../config';
|
|
2
2
|
import { GenericFetch } from '../../fetch';
|
|
3
|
-
export
|
|
3
|
+
export type Config = {
|
|
4
4
|
defaultCorrectness?: string;
|
|
5
5
|
exercisesHost: string;
|
|
6
6
|
exercisesAuthToken: string;
|
|
@@ -9,18 +9,18 @@ interface Initializer<C> {
|
|
|
9
9
|
configSpace?: C;
|
|
10
10
|
fetch: GenericFetch;
|
|
11
11
|
}
|
|
12
|
-
export
|
|
12
|
+
export type Answer = {
|
|
13
13
|
id: number;
|
|
14
14
|
content_html: string;
|
|
15
15
|
correctness?: string;
|
|
16
16
|
feedback_html?: string;
|
|
17
17
|
};
|
|
18
|
-
export
|
|
18
|
+
export type Solution = {
|
|
19
19
|
images: any[];
|
|
20
20
|
solution_type: string;
|
|
21
21
|
content_html: string;
|
|
22
22
|
};
|
|
23
|
-
export
|
|
23
|
+
export type Question = {
|
|
24
24
|
id: number;
|
|
25
25
|
is_answer_order_important: boolean;
|
|
26
26
|
stimulus_html: string;
|
|
@@ -32,7 +32,7 @@ export declare type Question = {
|
|
|
32
32
|
collaborator_solutions?: Solution[];
|
|
33
33
|
community_solutions?: Solution[];
|
|
34
34
|
};
|
|
35
|
-
export
|
|
35
|
+
export type Exercise = {
|
|
36
36
|
images: any[];
|
|
37
37
|
tags: string[];
|
|
38
38
|
uuid: string;
|
|
@@ -51,21 +51,17 @@ export declare type Exercise = {
|
|
|
51
51
|
versions: number[];
|
|
52
52
|
stimulus_html: string;
|
|
53
53
|
};
|
|
54
|
-
export
|
|
54
|
+
export type ExercisesSearchResults = {
|
|
55
55
|
total_count: number;
|
|
56
56
|
items: Exercise[];
|
|
57
57
|
};
|
|
58
|
-
export
|
|
58
|
+
export type ExercisesSearchResultsWithDigest = ExercisesSearchResults & {
|
|
59
59
|
digest: string;
|
|
60
60
|
};
|
|
61
|
-
export declare const exercisesGateway: <C extends string = "exercises">(initializer: Initializer<C>) => (configProvider: { [
|
|
62
|
-
defaultCorrectness?: import("../../config").ConfigValueProvider<string> | undefined;
|
|
63
|
-
exercisesHost: import("../../config").ConfigValueProvider<string>;
|
|
64
|
-
exercisesAuthToken: import("../../config").ConfigValueProvider<string>;
|
|
65
|
-
}; }) => (_: {}) => {
|
|
61
|
+
export declare const exercisesGateway: <C extends string = "exercises">(initializer: Initializer<C>) => (configProvider: { [_key in C]: ConfigProviderForConfig<Config>; }) => (_: {}) => {
|
|
66
62
|
searchDigest: (query: string, page?: number, per_page?: number) => Promise<string>;
|
|
67
63
|
get: (uuid: string) => Promise<Exercise | undefined>;
|
|
68
64
|
search: (query: string, page?: number, per_page?: number) => Promise<ExercisesSearchResultsWithDigest>;
|
|
69
65
|
};
|
|
70
|
-
export
|
|
66
|
+
export type ExercisesGateway = ReturnType<ReturnType<ReturnType<typeof exercisesGateway>>>;
|
|
71
67
|
export {};
|
|
@@ -15,13 +15,23 @@ var __setModuleDefault = (this && this.__setModuleDefault) || (Object.create ? (
|
|
|
15
15
|
}) : function(o, v) {
|
|
16
16
|
o["default"] = v;
|
|
17
17
|
});
|
|
18
|
-
var __importStar = (this && this.__importStar) || function (
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
};
|
|
18
|
+
var __importStar = (this && this.__importStar) || (function () {
|
|
19
|
+
var ownKeys = function(o) {
|
|
20
|
+
ownKeys = Object.getOwnPropertyNames || function (o) {
|
|
21
|
+
var ar = [];
|
|
22
|
+
for (var k in o) if (Object.prototype.hasOwnProperty.call(o, k)) ar[ar.length] = k;
|
|
23
|
+
return ar;
|
|
24
|
+
};
|
|
25
|
+
return ownKeys(o);
|
|
26
|
+
};
|
|
27
|
+
return function (mod) {
|
|
28
|
+
if (mod && mod.__esModule) return mod;
|
|
29
|
+
var result = {};
|
|
30
|
+
if (mod != null) for (var k = ownKeys(mod), i = 0; i < k.length; i++) if (k[i] !== "default") __createBinding(result, mod, k[i]);
|
|
31
|
+
__setModuleDefault(result, mod);
|
|
32
|
+
return result;
|
|
33
|
+
};
|
|
34
|
+
})();
|
|
25
35
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
26
36
|
exports.exercisesGateway = void 0;
|
|
27
37
|
const queryString = __importStar(require("query-string"));
|
|
@@ -1,11 +1,10 @@
|
|
|
1
|
-
|
|
2
|
-
export declare type FileValue = {
|
|
1
|
+
export type FileValue = {
|
|
3
2
|
dataType: 'file';
|
|
4
3
|
mimeType: string;
|
|
5
4
|
path: string;
|
|
6
5
|
label: string;
|
|
7
6
|
};
|
|
8
|
-
export
|
|
7
|
+
export type FolderValue = {
|
|
9
8
|
dataType: 'folder';
|
|
10
9
|
files: FileValue[];
|
|
11
10
|
};
|
|
@@ -15,5 +14,16 @@ export interface FileServerAdapter {
|
|
|
15
14
|
putFileContent: (source: FileValue, content: string) => Promise<FileValue>;
|
|
16
15
|
getSignedViewerUrl: (source: FileValue) => Promise<string>;
|
|
17
16
|
getFileContent: (source: FileValue) => Promise<Buffer>;
|
|
17
|
+
getSignedFileUploadConfig: () => Promise<{
|
|
18
|
+
url: string;
|
|
19
|
+
payload: {
|
|
20
|
+
[key: string]: string;
|
|
21
|
+
};
|
|
22
|
+
}>;
|
|
23
|
+
copyFileTo: (source: FileValue, destinationPath: string) => Promise<FileValue>;
|
|
24
|
+
copyFileToDirectory: (source: FileValue, destinationDirectory: string) => Promise<FileValue>;
|
|
25
|
+
isTemporaryUpload: (source: FileValue) => boolean;
|
|
26
|
+
getFileChecksum: (source: FileValue) => Promise<string>;
|
|
27
|
+
filesEqual: (sourceA: FileValue, sourceB: FileValue) => Promise<boolean>;
|
|
18
28
|
}
|
|
19
29
|
export declare const isFileOrFolder: (thing: any) => thing is FileValue | FolderValue;
|
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
import { ConfigProviderForConfig } from '../../config';
|
|
2
2
|
import { FileServerAdapter } from '.';
|
|
3
|
-
export
|
|
3
|
+
export type Config = {
|
|
4
4
|
port?: string;
|
|
5
5
|
host?: string;
|
|
6
6
|
storagePrefix: string;
|
|
@@ -9,9 +9,5 @@ interface Initializer<C> {
|
|
|
9
9
|
dataDir: string;
|
|
10
10
|
configSpace?: C;
|
|
11
11
|
}
|
|
12
|
-
export declare const localFileServer: <C extends string = "local">(initializer: Initializer<C>) => (configProvider: { [
|
|
13
|
-
port?: import("../../config").ConfigValueProvider<string> | undefined;
|
|
14
|
-
host?: import("../../config").ConfigValueProvider<string> | undefined;
|
|
15
|
-
storagePrefix: import("../../config").ConfigValueProvider<string>;
|
|
16
|
-
}; }) => FileServerAdapter;
|
|
12
|
+
export declare const localFileServer: <C extends string = "local">(initializer: Initializer<C>) => (configProvider: { [_key in C]: ConfigProviderForConfig<Config>; }) => FileServerAdapter;
|
|
17
13
|
export {};
|
|
@@ -5,12 +5,14 @@ var __importDefault = (this && this.__importDefault) || function (mod) {
|
|
|
5
5
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
6
6
|
exports.localFileServer = void 0;
|
|
7
7
|
/* cspell:ignore originalname */
|
|
8
|
+
const crypto_1 = __importDefault(require("crypto"));
|
|
8
9
|
const fs_1 = __importDefault(require("fs"));
|
|
9
10
|
const https_1 = __importDefault(require("https"));
|
|
10
11
|
const path_1 = __importDefault(require("path"));
|
|
11
12
|
const cors_1 = __importDefault(require("cors"));
|
|
12
13
|
const express_1 = __importDefault(require("express"));
|
|
13
14
|
const multer_1 = __importDefault(require("multer"));
|
|
15
|
+
const uuid_1 = require("uuid");
|
|
14
16
|
const assertions_1 = require("../../assertions");
|
|
15
17
|
const config_1 = require("../../config");
|
|
16
18
|
const guards_1 = require("../../guards");
|
|
@@ -72,10 +74,55 @@ const localFileServer = (initializer) => (configProvider) => {
|
|
|
72
74
|
await fs_1.default.promises.writeFile(filePath, content);
|
|
73
75
|
return source;
|
|
74
76
|
};
|
|
77
|
+
const getSignedFileUploadConfig = async () => {
|
|
78
|
+
const prefix = 'uploads/' + (0, uuid_1.v4)();
|
|
79
|
+
return {
|
|
80
|
+
url: `https://${await host}:${await port}/`,
|
|
81
|
+
payload: {
|
|
82
|
+
key: prefix + '/${filename}',
|
|
83
|
+
}
|
|
84
|
+
};
|
|
85
|
+
};
|
|
86
|
+
const copyFileTo = async (source, destinationPath) => {
|
|
87
|
+
const sourcePath = path_1.default.join(await fileDir, source.path);
|
|
88
|
+
const destPath = path_1.default.join(await fileDir, destinationPath);
|
|
89
|
+
const destDirectory = path_1.default.dirname(destPath);
|
|
90
|
+
await fs_1.default.promises.mkdir(destDirectory, { recursive: true });
|
|
91
|
+
await fs_1.default.promises.copyFile(sourcePath, destPath);
|
|
92
|
+
return {
|
|
93
|
+
...source,
|
|
94
|
+
path: destinationPath
|
|
95
|
+
};
|
|
96
|
+
};
|
|
97
|
+
const copyFileToDirectory = async (source, destination) => {
|
|
98
|
+
const destinationPath = path_1.default.join(destination, source.label);
|
|
99
|
+
return copyFileTo(source, destinationPath);
|
|
100
|
+
};
|
|
101
|
+
const isTemporaryUpload = (source) => {
|
|
102
|
+
return source.path.indexOf('uploads/') === 0;
|
|
103
|
+
};
|
|
104
|
+
const getFileChecksum = async (source) => {
|
|
105
|
+
const filePath = path_1.default.join(await fileDir, source.path);
|
|
106
|
+
const fileContent = await fs_1.default.promises.readFile(filePath);
|
|
107
|
+
return crypto_1.default.createHash('md5').update(fileContent).digest('hex');
|
|
108
|
+
};
|
|
109
|
+
const filesEqual = async (sourceA, sourceB) => {
|
|
110
|
+
const [aSum, bSum] = await Promise.all([
|
|
111
|
+
getFileChecksum(sourceA),
|
|
112
|
+
getFileChecksum(sourceB)
|
|
113
|
+
]);
|
|
114
|
+
return aSum === bSum;
|
|
115
|
+
};
|
|
75
116
|
return {
|
|
76
117
|
getSignedViewerUrl,
|
|
77
118
|
getFileContent,
|
|
78
119
|
putFileContent,
|
|
120
|
+
getSignedFileUploadConfig,
|
|
121
|
+
copyFileTo,
|
|
122
|
+
copyFileToDirectory,
|
|
123
|
+
isTemporaryUpload,
|
|
124
|
+
getFileChecksum,
|
|
125
|
+
filesEqual,
|
|
79
126
|
};
|
|
80
127
|
};
|
|
81
128
|
exports.localFileServer = localFileServer;
|
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
import { S3Client } from '@aws-sdk/client-s3';
|
|
2
2
|
import { ConfigProviderForConfig } from '../../config';
|
|
3
3
|
import { FileServerAdapter } from '.';
|
|
4
|
-
export
|
|
4
|
+
export type Config = {
|
|
5
5
|
bucketName: string;
|
|
6
6
|
bucketRegion: string;
|
|
7
7
|
};
|
|
@@ -9,8 +9,5 @@ interface Initializer<C> {
|
|
|
9
9
|
configSpace?: C;
|
|
10
10
|
getS3Client?: (...args: ConstructorParameters<typeof S3Client>) => S3Client;
|
|
11
11
|
}
|
|
12
|
-
export declare const s3FileServer: <C extends string = "deployed">(initializer: Initializer<C>) => (configProvider: { [
|
|
13
|
-
bucketName: import("../../config").ConfigValueProvider<string>;
|
|
14
|
-
bucketRegion: import("../../config").ConfigValueProvider<string>;
|
|
15
|
-
}; }) => FileServerAdapter;
|
|
12
|
+
export declare const s3FileServer: <C extends string = "deployed">(initializer: Initializer<C>) => (configProvider: { [_key in C]: ConfigProviderForConfig<Config>; }) => FileServerAdapter;
|
|
16
13
|
export {};
|
|
@@ -1,9 +1,15 @@
|
|
|
1
1
|
"use strict";
|
|
2
|
+
var __importDefault = (this && this.__importDefault) || function (mod) {
|
|
3
|
+
return (mod && mod.__esModule) ? mod : { "default": mod };
|
|
4
|
+
};
|
|
2
5
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
6
|
exports.s3FileServer = void 0;
|
|
4
7
|
/* cspell:ignore presigner */
|
|
5
8
|
const client_s3_1 = require("@aws-sdk/client-s3");
|
|
9
|
+
const s3_presigned_post_1 = require("@aws-sdk/s3-presigned-post");
|
|
6
10
|
const s3_request_presigner_1 = require("@aws-sdk/s3-request-presigner");
|
|
11
|
+
const path_1 = __importDefault(require("path"));
|
|
12
|
+
const uuid_1 = require("uuid");
|
|
7
13
|
const __1 = require("../..");
|
|
8
14
|
const assertions_1 = require("../../assertions");
|
|
9
15
|
const config_1 = require("../../config");
|
|
@@ -44,10 +50,74 @@ const s3FileServer = (initializer) => (configProvider) => {
|
|
|
44
50
|
await (await s3Service()).send(command);
|
|
45
51
|
return source;
|
|
46
52
|
};
|
|
53
|
+
/*
|
|
54
|
+
* https://docs.aws.amazon.com/AWSJavaScriptSDK/v3/latest/modules/_aws_sdk_s3_presigned_post.html
|
|
55
|
+
* https://docs.aws.amazon.com/AmazonS3/latest/userguide/HTTPPOSTExamples.html
|
|
56
|
+
* https://docs.aws.amazon.com/AmazonS3/latest/API/sigv4-post-example.html
|
|
57
|
+
*/
|
|
58
|
+
const getSignedFileUploadConfig = async () => {
|
|
59
|
+
const prefix = 'uploads/' + (0, uuid_1.v4)();
|
|
60
|
+
const bucket = (await bucketName());
|
|
61
|
+
const Conditions = [
|
|
62
|
+
{ acl: 'private' },
|
|
63
|
+
{ bucket },
|
|
64
|
+
['starts-with', '$key', prefix]
|
|
65
|
+
];
|
|
66
|
+
const defaultFields = {
|
|
67
|
+
acl: 'private',
|
|
68
|
+
};
|
|
69
|
+
const { url, fields } = await (0, s3_presigned_post_1.createPresignedPost)(await s3Service(), {
|
|
70
|
+
Bucket: bucket,
|
|
71
|
+
Key: prefix + '/${filename}',
|
|
72
|
+
Conditions,
|
|
73
|
+
Fields: defaultFields,
|
|
74
|
+
Expires: 3600, // 1 hour
|
|
75
|
+
});
|
|
76
|
+
return {
|
|
77
|
+
url, payload: fields
|
|
78
|
+
};
|
|
79
|
+
};
|
|
80
|
+
const copyFileTo = async (source, destinationPath) => {
|
|
81
|
+
const bucket = (await bucketName());
|
|
82
|
+
const destinationPathWithoutLeadingSlash = destinationPath.replace(/^\//, '');
|
|
83
|
+
const command = new client_s3_1.CopyObjectCommand({
|
|
84
|
+
Bucket: bucket,
|
|
85
|
+
Key: destinationPathWithoutLeadingSlash,
|
|
86
|
+
CopySource: path_1.default.join(bucket, source.path),
|
|
87
|
+
});
|
|
88
|
+
await (await s3Service()).send(command);
|
|
89
|
+
return {
|
|
90
|
+
...source,
|
|
91
|
+
path: destinationPathWithoutLeadingSlash
|
|
92
|
+
};
|
|
93
|
+
};
|
|
94
|
+
const copyFileToDirectory = async (source, destination) => {
|
|
95
|
+
const destinationPath = path_1.default.join(destination, source.label);
|
|
96
|
+
return copyFileTo(source, destinationPath);
|
|
97
|
+
};
|
|
98
|
+
const isTemporaryUpload = (source) => {
|
|
99
|
+
return source.path.indexOf('uploads/') === 0;
|
|
100
|
+
};
|
|
101
|
+
const getFileChecksum = async (source) => {
|
|
102
|
+
const bucket = (await bucketName());
|
|
103
|
+
const command = new client_s3_1.HeadObjectCommand({ Bucket: bucket, Key: source.path });
|
|
104
|
+
const response = await (await s3Service()).send(command);
|
|
105
|
+
return (0, assertions_1.assertDefined)(response.ETag);
|
|
106
|
+
};
|
|
107
|
+
const filesEqual = async (sourceA, sourceB) => {
|
|
108
|
+
const [aSum, bSum] = await Promise.all([getFileChecksum(sourceA), getFileChecksum(sourceB)]);
|
|
109
|
+
return aSum === bSum;
|
|
110
|
+
};
|
|
47
111
|
return {
|
|
48
112
|
getFileContent,
|
|
49
113
|
putFileContent,
|
|
50
114
|
getSignedViewerUrl,
|
|
115
|
+
getSignedFileUploadConfig,
|
|
116
|
+
copyFileTo,
|
|
117
|
+
copyFileToDirectory,
|
|
118
|
+
isTemporaryUpload,
|
|
119
|
+
getFileChecksum,
|
|
120
|
+
filesEqual,
|
|
51
121
|
};
|
|
52
122
|
};
|
|
53
123
|
exports.s3FileServer = s3FileServer;
|
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
import { JWK } from 'node-jose';
|
|
2
2
|
import { ConfigProviderForConfig } from '../../config';
|
|
3
3
|
import type { JsonCompatibleValue } from '../../routing';
|
|
4
|
-
|
|
4
|
+
type Config = {
|
|
5
5
|
alg: string;
|
|
6
6
|
expiresIn: string;
|
|
7
7
|
iss: string;
|
|
@@ -13,16 +13,11 @@ interface Initializer<C> {
|
|
|
13
13
|
/**
|
|
14
14
|
* Creates a class that can sign launch params
|
|
15
15
|
*/
|
|
16
|
-
export declare const createLaunchSigner: <C extends string = "launch">({ configSpace }: Initializer<C>) => (configProvider: { [
|
|
17
|
-
alg: import("../../config").ConfigValueProvider<string>;
|
|
18
|
-
expiresIn: import("../../config").ConfigValueProvider<string>;
|
|
19
|
-
iss: import("../../config").ConfigValueProvider<string>;
|
|
20
|
-
privateKey: import("../../config").ConfigValueProvider<string>;
|
|
21
|
-
}; }) => {
|
|
16
|
+
export declare const createLaunchSigner: <C extends string = "launch">({ configSpace }: Initializer<C>) => (configProvider: { [_key in C]: ConfigProviderForConfig<Config>; }) => {
|
|
22
17
|
jwks: () => Promise<{
|
|
23
18
|
keys: JWK.RawKey[];
|
|
24
19
|
}>;
|
|
25
|
-
sign: (data: Record<string, JsonCompatibleValue>, subject: string, maxExp?: number | null
|
|
20
|
+
sign: (data: Record<string, JsonCompatibleValue>, subject: string, maxExp?: number | null) => Promise<string>;
|
|
26
21
|
};
|
|
27
|
-
export
|
|
22
|
+
export type LaunchSigner = ReturnType<ReturnType<typeof createLaunchSigner>>;
|
|
28
23
|
export {};
|
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
import jwt from 'jsonwebtoken';
|
|
2
2
|
import type { JWK } from 'node-jose';
|
|
3
3
|
import { ConfigProviderForConfig } from '../../config';
|
|
4
|
-
|
|
4
|
+
type Config = {
|
|
5
5
|
trustedDomain: string;
|
|
6
6
|
bypassSignatureVerification: string;
|
|
7
7
|
};
|
|
@@ -14,11 +14,8 @@ interface Initializer<C> {
|
|
|
14
14
|
/**
|
|
15
15
|
* Creates a class that can verify launch params
|
|
16
16
|
*/
|
|
17
|
-
export declare const createLaunchVerifier: <C extends string = "launch">({ configSpace, fetcher }: Initializer<C>) => (configProvider: { [
|
|
18
|
-
|
|
19
|
-
bypassSignatureVerification: import("../../config").ConfigValueProvider<string>;
|
|
20
|
-
}; }) => (_services: {}, getDefaultToken?: (() => string) | undefined) => {
|
|
21
|
-
verify: <T = undefined>(...args: T extends undefined ? [] | [string] : [(input: any) => T] | [string, (input: any) => T]) => Promise<T extends undefined ? jwt.JwtPayload : T>;
|
|
17
|
+
export declare const createLaunchVerifier: <C extends string = "launch">({ configSpace, fetcher }: Initializer<C>) => (configProvider: { [_key in C]: ConfigProviderForConfig<Config>; }) => (_services: {}, getDefaultToken?: () => string) => {
|
|
18
|
+
verify: <T = undefined>(...args: T extends undefined ? ([] | [string]) : ([(input: any) => T] | [string, (input: any) => T])) => Promise<T extends undefined ? jwt.JwtPayload : T>;
|
|
22
19
|
};
|
|
23
|
-
export
|
|
20
|
+
export type LaunchVerifier = ReturnType<ReturnType<ReturnType<typeof createLaunchVerifier>>>;
|
|
24
21
|
export {};
|
|
@@ -15,13 +15,23 @@ var __setModuleDefault = (this && this.__setModuleDefault) || (Object.create ? (
|
|
|
15
15
|
}) : function(o, v) {
|
|
16
16
|
o["default"] = v;
|
|
17
17
|
});
|
|
18
|
-
var __importStar = (this && this.__importStar) || function (
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
};
|
|
18
|
+
var __importStar = (this && this.__importStar) || (function () {
|
|
19
|
+
var ownKeys = function(o) {
|
|
20
|
+
ownKeys = Object.getOwnPropertyNames || function (o) {
|
|
21
|
+
var ar = [];
|
|
22
|
+
for (var k in o) if (Object.prototype.hasOwnProperty.call(o, k)) ar[ar.length] = k;
|
|
23
|
+
return ar;
|
|
24
|
+
};
|
|
25
|
+
return ownKeys(o);
|
|
26
|
+
};
|
|
27
|
+
return function (mod) {
|
|
28
|
+
if (mod && mod.__esModule) return mod;
|
|
29
|
+
var result = {};
|
|
30
|
+
if (mod != null) for (var k = ownKeys(mod), i = 0; i < k.length; i++) if (k[i] !== "default") __createBinding(result, mod, k[i]);
|
|
31
|
+
__setModuleDefault(result, mod);
|
|
32
|
+
return result;
|
|
33
|
+
};
|
|
34
|
+
})();
|
|
25
35
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
26
36
|
exports.createLaunchVerifier = void 0;
|
|
27
37
|
const jsonwebtoken_1 = __importStar(require("jsonwebtoken"));
|
|
@@ -13,7 +13,7 @@ export declare enum Level {
|
|
|
13
13
|
* @param level - log level
|
|
14
14
|
* @param event - event to log
|
|
15
15
|
*/
|
|
16
|
-
export
|
|
16
|
+
export type LogEvent = (level: Level, event: JsonCompatibleStruct) => void;
|
|
17
17
|
/**
|
|
18
18
|
* A logger that can be used to log events.
|
|
19
19
|
*
|
|
@@ -36,4 +36,4 @@ export interface Logger {
|
|
|
36
36
|
* (the context is returned when messages are logged with the logger)
|
|
37
37
|
* @returns a Logger
|
|
38
38
|
*/
|
|
39
|
-
export declare const createCoreLogger: (driver: LogEvent, getParentContext?: (
|
|
39
|
+
export declare const createCoreLogger: (driver: LogEvent, getParentContext?: () => JsonCompatibleStruct) => Logger;
|
|
@@ -9,7 +9,7 @@ var Level;
|
|
|
9
9
|
Level["Info"] = "info";
|
|
10
10
|
Level["Warn"] = "warn";
|
|
11
11
|
Level["Error"] = "error";
|
|
12
|
-
})(Level
|
|
12
|
+
})(Level || (exports.Level = Level = {}));
|
|
13
13
|
/**
|
|
14
14
|
* Creates a logger that logs events using the given driver and context provider.
|
|
15
15
|
*
|
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
import { User } from '../authProvider';
|
|
2
2
|
import { EagerXapiStatement, UXapiStatement, XapiStatement } from '.';
|
|
3
|
-
export declare const addStatementDefaultFields: (statement: (Pick<XapiStatement,
|
|
3
|
+
export declare const addStatementDefaultFields: (statement: (Pick<XapiStatement, "object" | "verb" | "context" | "result"> & {
|
|
4
4
|
id?: string;
|
|
5
5
|
}) | UXapiStatement, user: User) => EagerXapiStatement;
|
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
import { LrsGateway, UXapiStatement } from '.';
|
|
2
|
-
export
|
|
2
|
+
export type ActivityState = {
|
|
3
3
|
attempts: number;
|
|
4
4
|
completedAttempts: number;
|
|
5
5
|
currentAttempt?: UXapiStatement;
|
|
@@ -11,60 +11,60 @@ export declare type ActivityState = {
|
|
|
11
11
|
export declare const matchAttempt: (statement: UXapiStatement) => boolean;
|
|
12
12
|
export declare const matchAttemptCompleted: (attempt: UXapiStatement) => (statement: UXapiStatement) => boolean;
|
|
13
13
|
export declare const resolveAttempts: (statements: UXapiStatement[], options?: {
|
|
14
|
-
activityIRI?: string
|
|
15
|
-
parentActivityAttempt?: string
|
|
16
|
-
}
|
|
17
|
-
export declare const resolveCompletedForAttempt: (statements: UXapiStatement[], attempt: UXapiStatement, activityIRI?: string
|
|
14
|
+
activityIRI?: string;
|
|
15
|
+
parentActivityAttempt?: string;
|
|
16
|
+
}) => UXapiStatement[];
|
|
17
|
+
export declare const resolveCompletedForAttempt: (statements: UXapiStatement[], attempt: UXapiStatement, activityIRI?: string) => UXapiStatement | undefined;
|
|
18
18
|
export declare const oldestStatement: (statements: UXapiStatement[]) => UXapiStatement | undefined;
|
|
19
19
|
export declare const mostRecentStatement: (statements: UXapiStatement[]) => UXapiStatement | undefined;
|
|
20
20
|
export declare const resolveAttemptInfo: (statements: UXapiStatement[], options?: {
|
|
21
|
-
activityIRI?: string
|
|
22
|
-
currentAttempt?: string
|
|
23
|
-
parentActivityAttempt?: string
|
|
24
|
-
currentPreference?: "latest" | "oldest"
|
|
25
|
-
}
|
|
21
|
+
activityIRI?: string;
|
|
22
|
+
currentAttempt?: string;
|
|
23
|
+
parentActivityAttempt?: string;
|
|
24
|
+
currentPreference?: "latest" | "oldest";
|
|
25
|
+
}) => ActivityState;
|
|
26
26
|
export declare const loadStatementsForActivityAndFirstChildren: (gateway: LrsGateway, activityIRI: string, options?: {
|
|
27
|
-
anyUser?: boolean
|
|
28
|
-
attempt?: string
|
|
29
|
-
ensureSync?: boolean
|
|
30
|
-
user?: string
|
|
31
|
-
}
|
|
27
|
+
anyUser?: boolean;
|
|
28
|
+
attempt?: string;
|
|
29
|
+
ensureSync?: boolean;
|
|
30
|
+
user?: string;
|
|
31
|
+
}) => Promise<import(".").XapiStatement[]>;
|
|
32
32
|
export declare const loadActivityAttemptInfo: (gateway: LrsGateway, activityIRI: string, options?: {
|
|
33
|
-
currentAttempt?: string
|
|
34
|
-
parentActivityAttempt?: string
|
|
35
|
-
ensureSync?: boolean
|
|
36
|
-
}
|
|
37
|
-
export declare const createStatement: (verb: UXapiStatement[
|
|
33
|
+
currentAttempt?: string;
|
|
34
|
+
parentActivityAttempt?: string;
|
|
35
|
+
ensureSync?: boolean;
|
|
36
|
+
}) => Promise<ActivityState>;
|
|
37
|
+
export declare const createStatement: (verb: UXapiStatement["verb"], activity: {
|
|
38
38
|
iri: string;
|
|
39
39
|
type: string;
|
|
40
40
|
name: string;
|
|
41
41
|
extensions?: {
|
|
42
42
|
[key: string]: string;
|
|
43
|
-
}
|
|
44
|
-
}, attempt: string, parentActivityIRI?: string
|
|
43
|
+
};
|
|
44
|
+
}, attempt: string, parentActivityIRI?: string) => Pick<UXapiStatement, "object" | "verb" | "context">;
|
|
45
45
|
export declare const createAttemptStatement: (activity: {
|
|
46
46
|
iri: string;
|
|
47
47
|
type: string;
|
|
48
48
|
name: string;
|
|
49
49
|
extensions?: {
|
|
50
50
|
[key: string]: string;
|
|
51
|
-
}
|
|
51
|
+
};
|
|
52
52
|
}, parentActivity?: {
|
|
53
|
-
iri?: string
|
|
54
|
-
attempt?: string
|
|
55
|
-
}
|
|
53
|
+
iri?: string;
|
|
54
|
+
attempt?: string;
|
|
55
|
+
}) => Pick<UXapiStatement, "object" | "verb" | "context">;
|
|
56
56
|
export declare const putAttemptStatement: (gateway: LrsGateway, activity: {
|
|
57
57
|
iri: string;
|
|
58
58
|
type: string;
|
|
59
59
|
name: string;
|
|
60
60
|
extensions?: {
|
|
61
61
|
[key: string]: string;
|
|
62
|
-
}
|
|
62
|
+
};
|
|
63
63
|
}, parentActivity?: {
|
|
64
|
-
iri?: string
|
|
65
|
-
attempt?: string
|
|
66
|
-
}
|
|
67
|
-
export declare const createAttemptActivityStatement: (attemptStatement: UXapiStatement, verb: UXapiStatement[
|
|
68
|
-
export declare const putAttemptActivityStatement: (gateway: LrsGateway, attemptStatement: UXapiStatement, verb: UXapiStatement[
|
|
69
|
-
export declare const createCompletedStatement: (attemptStatement: UXapiStatement, result?: UXapiStatement[
|
|
70
|
-
export declare const putCompletedStatement: (gateway: LrsGateway, attemptStatement: UXapiStatement, result: UXapiStatement[
|
|
64
|
+
iri?: string;
|
|
65
|
+
attempt?: string;
|
|
66
|
+
}) => Promise<import(".").EagerXapiStatement>;
|
|
67
|
+
export declare const createAttemptActivityStatement: (attemptStatement: UXapiStatement, verb: UXapiStatement["verb"], result?: UXapiStatement["result"]) => Pick<UXapiStatement, "object" | "verb" | "context" | "result">;
|
|
68
|
+
export declare const putAttemptActivityStatement: (gateway: LrsGateway, attemptStatement: UXapiStatement, verb: UXapiStatement["verb"], result?: UXapiStatement["result"]) => Promise<import(".").EagerXapiStatement>;
|
|
69
|
+
export declare const createCompletedStatement: (attemptStatement: UXapiStatement, result?: UXapiStatement["result"]) => Pick<UXapiStatement, "object" | "verb" | "context" | "result">;
|
|
70
|
+
export declare const putCompletedStatement: (gateway: LrsGateway, attemptStatement: UXapiStatement, result: UXapiStatement["result"]) => Promise<import(".").EagerXapiStatement>;
|
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
import { ConfigProviderForConfig } from '../../config';
|
|
2
2
|
import { AuthProvider } from '../authProvider';
|
|
3
3
|
import { LrsGateway } from '.';
|
|
4
|
-
|
|
4
|
+
type Config = {
|
|
5
5
|
name: string;
|
|
6
6
|
};
|
|
7
7
|
interface Initializer<C> {
|
|
@@ -9,9 +9,7 @@ interface Initializer<C> {
|
|
|
9
9
|
fs?: Pick<typeof import('fs'), 'readFile' | 'writeFile'>;
|
|
10
10
|
configSpace?: C;
|
|
11
11
|
}
|
|
12
|
-
export declare const fileSystemLrsGateway: <C extends string = "fileSystem">(initializer: Initializer<C>) => (configProvider: { [
|
|
13
|
-
name: import("../../config").ConfigValueProvider<string>;
|
|
14
|
-
}; }) => ({ authProvider }: {
|
|
12
|
+
export declare const fileSystemLrsGateway: <C extends string = "fileSystem">(initializer: Initializer<C>) => (configProvider: { [_key in C]: ConfigProviderForConfig<Config>; }) => ({ authProvider }: {
|
|
15
13
|
authProvider: AuthProvider;
|
|
16
14
|
}) => LrsGateway;
|
|
17
15
|
export {};
|
|
@@ -15,13 +15,23 @@ var __setModuleDefault = (this && this.__setModuleDefault) || (Object.create ? (
|
|
|
15
15
|
}) : function(o, v) {
|
|
16
16
|
o["default"] = v;
|
|
17
17
|
});
|
|
18
|
-
var __importStar = (this && this.__importStar) || function (
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
};
|
|
18
|
+
var __importStar = (this && this.__importStar) || (function () {
|
|
19
|
+
var ownKeys = function(o) {
|
|
20
|
+
ownKeys = Object.getOwnPropertyNames || function (o) {
|
|
21
|
+
var ar = [];
|
|
22
|
+
for (var k in o) if (Object.prototype.hasOwnProperty.call(o, k)) ar[ar.length] = k;
|
|
23
|
+
return ar;
|
|
24
|
+
};
|
|
25
|
+
return ownKeys(o);
|
|
26
|
+
};
|
|
27
|
+
return function (mod) {
|
|
28
|
+
if (mod && mod.__esModule) return mod;
|
|
29
|
+
var result = {};
|
|
30
|
+
if (mod != null) for (var k = ownKeys(mod), i = 0; i < k.length; i++) if (k[i] !== "default") __createBinding(result, mod, k[i]);
|
|
31
|
+
__setModuleDefault(result, mod);
|
|
32
|
+
return result;
|
|
33
|
+
};
|
|
34
|
+
})();
|
|
25
35
|
var __importDefault = (this && this.__importDefault) || function (mod) {
|
|
26
36
|
return (mod && mod.__esModule) ? mod : { "default": mod };
|
|
27
37
|
};
|