Skip to content

Commit 0630c35

Browse files
authored
feat(Agents): Merges xapi-agents service. (#469)
1 parent c161a7b commit 0630c35

File tree

285 files changed

+6889
-584
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

285 files changed

+6889
-584
lines changed

package-lock.json

Lines changed: 448 additions & 462 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

package.json

Lines changed: 18 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -38,22 +38,36 @@
3838
"npm": ">3.0.0"
3939
},
4040
"dependencies": {
41-
"@learninglocker/xapi-agents": "4.4.3",
41+
"@azure/storage-blob": "^10.3.0",
42+
"@google-cloud/storage": "^1.5.2",
43+
"@learninglocker/xapi-validation": "^2.1.10",
4244
"accept-language-parser": "^1.5.0",
45+
"atob": "^2.0.3",
46+
"aws-sdk": "^2.205.0",
47+
"bluebird": "3.5.0",
4348
"boolean": "^0.2.0",
49+
"btoa": "^1.1.2",
4450
"dotenv": "^5.0.0",
4551
"express": "^4.14.1",
52+
"fs-extra": "^5.0.0",
53+
"http-status-codes": "^1.3.0",
4654
"install": "^0.13.0",
4755
"ioredis": "^4.14.0",
48-
"jscommons": "^2.3.3",
56+
"jscommons": "^2.3.0",
4957
"jsonwebtoken": "^8.5.1",
5058
"lodash": "^4.17.4",
59+
"mime-types": "2.1.17",
5160
"mongodb": "^3.0.2",
61+
"node-fetch": "^2.0.0",
5262
"object-hash": "^1.3.1",
5363
"query-string": "^6.8.2",
5464
"redis": "^2.8.0",
65+
"rulr": "^4.0.0",
66+
"sha1": "^1.1.1",
5567
"source-map-support": "^0.5.0",
56-
"string-to-stream": "^2.0.0"
68+
"stream-to-string": "^1.2.0",
69+
"string-to-stream": "^2.0.0",
70+
"uuid": "^3.0.1"
5771
},
5872
"devDependencies": {
5973
"@ht2-labs/semantic-release": "1.1.90",
@@ -72,6 +86,7 @@
7286
"@types/mocha": "5.2.7",
7387
"@types/mongodb": "3.1.10",
7488
"@types/node": "9.6.51",
89+
"@types/node-fetch": "2.5.0",
7590
"@types/object-hash": "1.3.0",
7691
"@types/redis": "2.8.6",
7792
"@types/source-map-support": "0.5.0",

src/apps/activities/expressPresenter/index.ts

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,6 @@
11
import { Router } from 'express';
22
import mixinCors from 'jscommons/dist/expressPresenter/mixins/cors';
33
import mixinHelmet from 'jscommons/dist/expressPresenter/mixins/helmet';
4-
import mixinMorgan from 'jscommons/dist/expressPresenter/mixins/morgan';
54
import Config from './Config';
65
import deleteProfile from './deleteProfile';
76
import getProfiles from './getProfiles';
@@ -13,7 +12,6 @@ export default (config: Config): Router => {
1312

1413
router.use(mixinCors());
1514
router.use(mixinHelmet());
16-
router.use(mixinMorgan(config.morganDirectory));
1715

1816
router.delete('', deleteProfile(config));
1917
router.get('', getProfiles(config));

src/apps/activities/repo/storage/factory.ts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@ import {
55
StorageURL,
66
} from '@azure/storage-blob';
77
import Storage from '@google-cloud/storage';
8-
import { S3 } from 'aws-sdk';
8+
import S3 from 'aws-sdk/clients/s3';
99
import azureStorageRepo from '../../azureStorageRepo';
1010
import googleStorageRepo from '../../googleStorageRepo';
1111
import localStorageRepo from '../../localStorageRepo';
@@ -18,7 +18,7 @@ export default (factoryConfig: FactoryConfig): Repo => {
1818
case 's3':
1919
return s3StorageRepo({
2020
bucketName: factoryConfig.s3.bucketName,
21-
client: new S3(factoryConfig.s3.awsConfig),
21+
client: new S3(factoryConfig.s3.awsConfig) as any,
2222
subFolder: factoryConfig.s3.subFolder,
2323
});
2424
case 'google':

src/apps/activities/repoFactory/index.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -68,7 +68,7 @@ const getStorageRepo = (): StorageRepo => {
6868
case 's3':
6969
return s3StorageRepo({
7070
bucketName: config.s3StorageRepo.bucketName,
71-
client: new S3(config.s3StorageRepo.awsConfig),
71+
client: new S3(config.s3StorageRepo.awsConfig) as any,
7272
subFolder: config.storageSubFolders.activities,
7373
});
7474
case 'google':

src/apps/agents/app.ts

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,10 @@
11
/* tslint:disable:max-file-line-count */
2-
import presenterFactory from '@learninglocker/xapi-agents/dist/expressPresenter';
3-
import serviceFactory from '@learninglocker/xapi-agents/dist/service';
4-
import enTranslator from '@learninglocker/xapi-agents/dist/translatorFactory/en';
52
import { Router } from 'express';
63
import AppConfig from './AppConfig';
4+
import presenterFactory from './expressPresenter';
75
import repoFactory from './repo/factory';
6+
import serviceFactory from './service';
7+
import enTranslator from './translatorFactory/en';
88

99
export default (appConfig: AppConfig): Router => {
1010
const translator = enTranslator;
Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,6 @@
1+
import { ContainerURL } from '@azure/storage-blob';
2+
3+
export default interface Config {
4+
readonly containerUrl: ContainerURL;
5+
readonly subFolder: string;
6+
}
Lines changed: 27 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,27 @@
1+
import {
2+
Aborter,
3+
BlobURL,
4+
Models,
5+
} from '@azure/storage-blob';
6+
import Config from './Config';
7+
8+
export default (config: Config) => {
9+
return async (): Promise<void> => {
10+
// tslint:disable-next-line:no-let
11+
let marker;
12+
do {
13+
const listBlobsResponse: Models.ContainerListBlobFlatSegmentResponse =
14+
await config.containerUrl.listBlobFlatSegment(Aborter.none, marker);
15+
marker = listBlobsResponse.nextMarker;
16+
const deletePromises = listBlobsResponse.segment.blobItems.map(
17+
async (blobItem: Models.BlobItem) => {
18+
const blobUrl = BlobURL.fromContainerURL(config.containerUrl, blobItem.name);
19+
if (blobItem.name.startsWith(config.subFolder)) {
20+
await blobUrl.delete(Aborter.none);
21+
}
22+
},
23+
);
24+
await Promise.all(deletePromises);
25+
} while (marker !== '');
26+
};
27+
};
Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,18 @@
1+
import {
2+
Aborter,
3+
BlobURL,
4+
} from '@azure/storage-blob';
5+
import DeleteProfileContentOptions from '../repoFactory/options/DeleteProfileContentOptions';
6+
import getStorageDir from '../utils/getStorageDir';
7+
import Config from './Config';
8+
9+
export default (config: Config) => {
10+
return async (opts: DeleteProfileContentOptions): Promise<void> => {
11+
const profileDir = getStorageDir({ subfolder: config.subFolder, lrs_id: opts.lrs_id });
12+
const filePath = `${profileDir}/${opts.key}`;
13+
14+
const blobUrl = BlobURL.fromContainerURL(config.containerUrl, filePath);
15+
16+
await blobUrl.delete(Aborter.none);
17+
};
18+
};
Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,20 @@
1+
import { Aborter, BlobURL } from '@azure/storage-blob';
2+
import GetProfileContentOptions from '../repoFactory/options/GetProfileContentOptions';
3+
import GetProfileContentResult from '../repoFactory/results/GetProfileContentResult';
4+
import getStorageDir from '../utils/getStorageDir';
5+
import Config from './Config';
6+
7+
export default (config: Config) => {
8+
return async (opts: GetProfileContentOptions): Promise<GetProfileContentResult> => {
9+
const profileDir = getStorageDir({ subfolder: config.subFolder, lrs_id: opts.lrs_id });
10+
const filePath = `${profileDir}/${opts.key}`;
11+
12+
const blobUrl = BlobURL.fromContainerURL(config.containerUrl, filePath);
13+
const content = (await blobUrl.download(Aborter.none, 0)).readableStreamBody;
14+
if (content === undefined) {
15+
throw new Error('Blob not found');
16+
}
17+
18+
return { content };
19+
};
20+
};

0 commit comments

Comments
 (0)