@studyportals/domain-client 6.0.0-10 → 6.0.0-12
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/package.json +2 -3
- package/src/domain-client.d.ts +1 -1
- package/src/domain-client.js +13 -11
- package/src/factories/InternalLinkFactory.js +1 -0
- package/test.js +3 -1
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@studyportals/domain-client",
|
|
3
|
-
"version": "6.0.0-
|
|
3
|
+
"version": "6.0.0-12",
|
|
4
4
|
"description": "Responsible for fetching data from the Domain API",
|
|
5
5
|
"main": "index.js",
|
|
6
6
|
"author": "StudyPortals B.V.",
|
|
@@ -21,7 +21,7 @@
|
|
|
21
21
|
"publish-major": "npm version major && npm run prepare-dist && npm publish ./bin",
|
|
22
22
|
"publish-minor": "npm version minor && npm run prepare-dist && npm publish ./bin",
|
|
23
23
|
"publish-patch": "npm version patch && npm run prepare-dist && npm publish ./bin",
|
|
24
|
-
"publish-current": "npm run prepare-dist && npm publish ./bin --tag
|
|
24
|
+
"publish-current": "npm run prepare-dist && npm publish ./bin --tag=beta"
|
|
25
25
|
},
|
|
26
26
|
"husky": {
|
|
27
27
|
"hooks": {
|
|
@@ -33,7 +33,6 @@
|
|
|
33
33
|
"typescript": "^5.9.2"
|
|
34
34
|
},
|
|
35
35
|
"devDependencies": {
|
|
36
|
-
"@bufbuild/protobuf": "^2.6.2",
|
|
37
36
|
"@studyportals/code-style": "^2.0.4",
|
|
38
37
|
"@testdeck/mocha": "^0.3.3",
|
|
39
38
|
"@types/axios": "^0.14.0",
|
package/src/domain-client.d.ts
CHANGED
|
@@ -7,7 +7,7 @@ export declare class DomainClient<T> {
|
|
|
7
7
|
readonly seed: number;
|
|
8
8
|
constructor(baseUrl: string, apiKey: string | undefined, model: string, version: string, isPublic: boolean, seed: number);
|
|
9
9
|
doRequest(ids: number[]): Promise<T[]>;
|
|
10
|
-
private
|
|
10
|
+
private decompressModelData;
|
|
11
11
|
private handleErrors;
|
|
12
12
|
private buildUrl;
|
|
13
13
|
private shouldAddPublicPrefix;
|
package/src/domain-client.js
CHANGED
|
@@ -25,27 +25,27 @@ export class DomainClient {
|
|
|
25
25
|
}
|
|
26
26
|
try {
|
|
27
27
|
const response = await fetch(url, { headers });
|
|
28
|
+
// eslint-disable-next-line @typescript-eslint/no-unsafe-assignment
|
|
28
29
|
const data = await response.json();
|
|
29
30
|
if (!response.ok || data.status !== 200) {
|
|
30
31
|
this.handleErrors(data);
|
|
31
32
|
}
|
|
32
33
|
const models = [];
|
|
33
34
|
for (const id of ids) {
|
|
34
|
-
|
|
35
|
+
const modelData = data.data[id];
|
|
36
|
+
if (!modelData) {
|
|
37
|
+
continue;
|
|
38
|
+
}
|
|
35
39
|
if (typeof modelData === 'string') {
|
|
36
40
|
try {
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
modelData = JSON.parse(decoder.decode(decompressedBytes));
|
|
41
|
+
models.push(await this.decompressModelData(modelData));
|
|
42
|
+
continue;
|
|
40
43
|
}
|
|
41
44
|
catch (error) {
|
|
42
45
|
console.error(error);
|
|
43
46
|
continue;
|
|
44
47
|
}
|
|
45
48
|
}
|
|
46
|
-
if (!modelData) {
|
|
47
|
-
continue;
|
|
48
|
-
}
|
|
49
49
|
models.push(modelData);
|
|
50
50
|
}
|
|
51
51
|
return models;
|
|
@@ -58,11 +58,13 @@ export class DomainClient {
|
|
|
58
58
|
throw new InternalServerException('Unable to fetch data from the API', error);
|
|
59
59
|
}
|
|
60
60
|
}
|
|
61
|
-
async
|
|
61
|
+
async decompressModelData(compressedData) {
|
|
62
|
+
const bytes = Uint8Array.from(atob(compressedData), c => c.charCodeAt(0));
|
|
62
63
|
const stream = new DecompressionStream('deflate');
|
|
63
|
-
const response = new Response(
|
|
64
|
-
const
|
|
65
|
-
|
|
64
|
+
const response = new Response(bytes);
|
|
65
|
+
const decompressedStream = response.body?.pipeThrough(stream);
|
|
66
|
+
const decompressedBytes = new Uint8Array(await new Response(decompressedStream).arrayBuffer());
|
|
67
|
+
return JSON.parse(decoder.decode(decompressedBytes));
|
|
66
68
|
}
|
|
67
69
|
handleErrors(response) {
|
|
68
70
|
if (!response.status) {
|
|
@@ -3,6 +3,7 @@ export class InternalLinkFactory {
|
|
|
3
3
|
constructor(portalMap) {
|
|
4
4
|
this.portalMap = portalMap;
|
|
5
5
|
}
|
|
6
|
+
// eslint-disable-next-line @typescript-eslint/no-unused-vars
|
|
6
7
|
create(link, parameters) {
|
|
7
8
|
const getPortalType = link['getPortalType'];
|
|
8
9
|
const portalType = getPortalType ? getPortalType() : null;
|
package/test.js
CHANGED
|
@@ -1,5 +1,7 @@
|
|
|
1
|
-
import { PublicMiniProgrammeCardClient } from "./";
|
|
1
|
+
import { PublicMiniProgrammeCardClient, PublicScholarshipCardClient } from "./";
|
|
2
2
|
const client = new PublicMiniProgrammeCardClient('https://681.domain-api.tst.prtl.co', 1, undefined, new Map());
|
|
3
|
+
const client2 = new PublicScholarshipCardClient('https://681.domain-api.tst.prtl.co', undefined, 1, new Map());
|
|
3
4
|
(async () => {
|
|
4
5
|
console.log(await client.fetch(70942));
|
|
6
|
+
console.log(await client2.fetch(2842));
|
|
5
7
|
})();
|