@gyldendalas/gyldendal-divine-api 2.0.0 → 2.3.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/index.cjs +97 -18
- package/dist/index.cjs.map +1 -1
- package/dist/index.d.cts +68 -8
- package/dist/index.d.mts +68 -8
- package/dist/index.mjs +97 -18
- package/dist/index.mjs.map +1 -1
- package/package.json +18 -11
package/dist/index.cjs
CHANGED
|
@@ -351,14 +351,15 @@ var BaseService = class {
|
|
|
351
351
|
timeout
|
|
352
352
|
});
|
|
353
353
|
}
|
|
354
|
-
async postAsync({ url, headers, addAuthHeaders = true, body, timeout }) {
|
|
354
|
+
async postAsync({ url, headers, addAuthHeaders = true, body, timeout, signal }) {
|
|
355
355
|
return await this.callAsync({
|
|
356
356
|
url,
|
|
357
357
|
body,
|
|
358
358
|
method: "POST",
|
|
359
359
|
headers,
|
|
360
360
|
addAuthHeaders,
|
|
361
|
-
timeout
|
|
361
|
+
timeout,
|
|
362
|
+
signal
|
|
362
363
|
});
|
|
363
364
|
}
|
|
364
365
|
async deleteAsync({ url, headers, addAuthHeaders = true, timeout }) {
|
|
@@ -381,14 +382,14 @@ var BaseService = class {
|
|
|
381
382
|
timeout
|
|
382
383
|
});
|
|
383
384
|
}
|
|
384
|
-
async callAsync({ url, body, method, headers, timeout, addAuthHeaders }) {
|
|
385
|
+
async callAsync({ url, body, method, headers, timeout, addAuthHeaders, signal }) {
|
|
385
386
|
if (!headers) headers = new Headers();
|
|
386
387
|
if (addAuthHeaders) headers = await this.addAuthHeaders(headers);
|
|
387
388
|
const response = await fetch(url, {
|
|
388
389
|
method,
|
|
389
390
|
body,
|
|
390
391
|
headers,
|
|
391
|
-
signal: AbortSignal.timeout(timeout)
|
|
392
|
+
signal: signal ? AbortSignal.any([AbortSignal.timeout(timeout), signal]) : AbortSignal.timeout(timeout)
|
|
392
393
|
});
|
|
393
394
|
if (!response.ok) throw new HTTPError(`Got ${response.status} while calling ${response.url}`, response);
|
|
394
395
|
return response;
|
|
@@ -633,7 +634,7 @@ var UserSettingsBookmarks = class extends UserSettingsBase {
|
|
|
633
634
|
})).json();
|
|
634
635
|
}
|
|
635
636
|
async getFavourite({ timeout = 5e3 }) {
|
|
636
|
-
|
|
637
|
+
const url = `${this.getUrlPrefix()}/bookmark/favourite`;
|
|
637
638
|
const headers = new Headers();
|
|
638
639
|
return (await this.getAsync({
|
|
639
640
|
url,
|
|
@@ -668,7 +669,7 @@ var UserSettingsContinue = class extends UserSettingsBase {
|
|
|
668
669
|
});
|
|
669
670
|
}
|
|
670
671
|
async getContinue({ isbn, timeout = 5e3 }) {
|
|
671
|
-
|
|
672
|
+
const url = `${this.getUrlPrefix()}/continue/isbn/${isbn}`;
|
|
672
673
|
const headers = new Headers();
|
|
673
674
|
try {
|
|
674
675
|
return (await this.getAsync({
|
|
@@ -707,7 +708,7 @@ var UserSettingsMRU = class extends UserSettingsBase {
|
|
|
707
708
|
});
|
|
708
709
|
}
|
|
709
710
|
async getMRU({ timeout = 5e3 }) {
|
|
710
|
-
|
|
711
|
+
const url = `${this.getUrlPrefix()}/mru`;
|
|
711
712
|
const headers = new Headers();
|
|
712
713
|
return (await this.getAsync({
|
|
713
714
|
url,
|
|
@@ -872,7 +873,7 @@ var UserFolders = class extends TaggingService {
|
|
|
872
873
|
resource_type: "myaccount_user_folder",
|
|
873
874
|
timeout
|
|
874
875
|
});
|
|
875
|
-
|
|
876
|
+
const folders = [];
|
|
876
877
|
for (const tag of tags) {
|
|
877
878
|
const folder_payload = JSON.parse(Buffer.from(tag["tag_value"], "base64").toString());
|
|
878
879
|
folders.push({
|
|
@@ -894,15 +895,14 @@ var UserFolders = class extends TaggingService {
|
|
|
894
895
|
* @return Folder[]
|
|
895
896
|
**/
|
|
896
897
|
async listNextFolderLevel({ parent_folder_uuid, timeout = 3e3 }) {
|
|
897
|
-
let tags;
|
|
898
898
|
if (!parent_folder_uuid) parent_folder_uuid = this.hasNoParent;
|
|
899
|
-
tags = await this.getTagsByName({
|
|
899
|
+
const tags = await this.getTagsByName({
|
|
900
900
|
identity: await this.getIdentity(),
|
|
901
901
|
resource_type: "myaccount_user_folder",
|
|
902
902
|
tag_name: parent_folder_uuid,
|
|
903
903
|
timeout
|
|
904
904
|
});
|
|
905
|
-
|
|
905
|
+
const folders = [];
|
|
906
906
|
for (const tag of tags) {
|
|
907
907
|
const folder_payload = JSON.parse(Buffer.from(tag["tag_value"], "base64").toString());
|
|
908
908
|
folders.push({
|
|
@@ -924,12 +924,12 @@ var UserFolders = class extends TaggingService {
|
|
|
924
924
|
* @return (Folder | FolderContent)[]
|
|
925
925
|
**/
|
|
926
926
|
async getFolderContent({ folder_uuid, timeout = 3e3 }) {
|
|
927
|
-
|
|
927
|
+
const tags = await this.getTagsByName({
|
|
928
928
|
identity: await this.getIdentity(),
|
|
929
929
|
tag_name: folder_uuid,
|
|
930
930
|
timeout
|
|
931
931
|
});
|
|
932
|
-
|
|
932
|
+
const content = [];
|
|
933
933
|
for (const tag of tags) if (tag["resource_type"] === "myaccount_user_folder") {
|
|
934
934
|
const folder_payload = JSON.parse(Buffer.from(tag["tag_value"], "base64").toString());
|
|
935
935
|
content.push({
|
|
@@ -1060,6 +1060,12 @@ var UserFolders = class extends TaggingService {
|
|
|
1060
1060
|
};
|
|
1061
1061
|
//#endregion
|
|
1062
1062
|
//#region src/services/ai_bot_service.ts
|
|
1063
|
+
/**
|
|
1064
|
+
* A turn runs an agent through many searches and tool calls, so it takes
|
|
1065
|
+
* minutes where a plain chat takes seconds. The timeout covers reading the
|
|
1066
|
+
* whole stream, not just its first byte.
|
|
1067
|
+
*/
|
|
1068
|
+
const COURSE_GENERATOR_TIMEOUT = 3e5;
|
|
1063
1069
|
var AIBotService = class extends BaseService {
|
|
1064
1070
|
serviceName = "aiBot";
|
|
1065
1071
|
async constructChatUrl({ interactivityId, isbn, stream }) {
|
|
@@ -1103,6 +1109,32 @@ var AIBotService = class extends BaseService {
|
|
|
1103
1109
|
if (!responseBody) throw new Error("Response body is null");
|
|
1104
1110
|
return responseBody;
|
|
1105
1111
|
}
|
|
1112
|
+
async courseGeneratorChat({ body, timeout = COURSE_GENERATOR_TIMEOUT }) {
|
|
1113
|
+
const headers = new Headers();
|
|
1114
|
+
headers.append("Content-Type", "application/json");
|
|
1115
|
+
return (await this.postAsync({
|
|
1116
|
+
url: `${this.getUrlPrefix()}/v1/course_generator/chat`,
|
|
1117
|
+
headers,
|
|
1118
|
+
body: JSON.stringify(body),
|
|
1119
|
+
timeout
|
|
1120
|
+
})).json();
|
|
1121
|
+
}
|
|
1122
|
+
/**
|
|
1123
|
+
* Streams the turn as NDJSON, one `CourseGeneratorStreamEvent` (from
|
|
1124
|
+
* divine-contracts) per line.
|
|
1125
|
+
*/
|
|
1126
|
+
async streamingCourseGeneratorChat({ body, timeout = COURSE_GENERATOR_TIMEOUT }) {
|
|
1127
|
+
const headers = new Headers();
|
|
1128
|
+
headers.append("Content-Type", "application/json");
|
|
1129
|
+
const responseBody = (await this.postAsync({
|
|
1130
|
+
url: `${this.getUrlPrefix()}/v1/course_generator/chat/stream`,
|
|
1131
|
+
headers,
|
|
1132
|
+
body: JSON.stringify(body),
|
|
1133
|
+
timeout
|
|
1134
|
+
})).body;
|
|
1135
|
+
if (!responseBody) throw new Error("Response body is null");
|
|
1136
|
+
return responseBody;
|
|
1137
|
+
}
|
|
1106
1138
|
};
|
|
1107
1139
|
//#endregion
|
|
1108
1140
|
//#region src/services/quiz_service.ts
|
|
@@ -1331,6 +1363,58 @@ var QuizService = class extends BaseService {
|
|
|
1331
1363
|
}
|
|
1332
1364
|
};
|
|
1333
1365
|
//#endregion
|
|
1366
|
+
//#region src/services/solr_proxy_service.ts
|
|
1367
|
+
/**
|
|
1368
|
+
* The v2 search API: typed search endpoints, where v1 passed raw search
|
|
1369
|
+
* queries through.
|
|
1370
|
+
*
|
|
1371
|
+
* Authenticate with the book's search token as `bearerToken` (a browser:
|
|
1372
|
+
* the user's groups come from the token) or with an `apiKey` (a server; it
|
|
1373
|
+
* may state the user's groups in the request only if its configuration
|
|
1374
|
+
* allows it). Every call is a POST, so the query never lands in a URL, and
|
|
1375
|
+
* with it in proxy and access logs.
|
|
1376
|
+
*/
|
|
1377
|
+
var SolrProxyService = class extends BaseService {
|
|
1378
|
+
serviceName = "solrProxy";
|
|
1379
|
+
/**
|
|
1380
|
+
* Searches one book. `hostname` is the book's primary hostname or any of
|
|
1381
|
+
* its aliases; the hits' URLs use the one given. Rejects with a 404 for a
|
|
1382
|
+
* book that does not exist or is outside the client's scope alike.
|
|
1383
|
+
*/
|
|
1384
|
+
async searchBook({ hostname, search, timeout = 1e4, signal }) {
|
|
1385
|
+
const url = `${this.getUrlPrefix()}/api/v2/books/${encodeURIComponent(hostname)}/search`;
|
|
1386
|
+
return this.post(url, search, timeout, signal);
|
|
1387
|
+
}
|
|
1388
|
+
/**
|
|
1389
|
+
* Searches many books: every book the client may search, or those in
|
|
1390
|
+
* `search.books`. With `group_by_book`, pages over books instead of hits.
|
|
1391
|
+
*/
|
|
1392
|
+
async searchBooks({ search, timeout = 1e4, signal }) {
|
|
1393
|
+
const url = `${this.getUrlPrefix()}/api/v2/search`;
|
|
1394
|
+
return this.post(url, search, timeout, signal);
|
|
1395
|
+
}
|
|
1396
|
+
/**
|
|
1397
|
+
* Completions of the word being typed, from the book's headings. Pass a
|
|
1398
|
+
* `signal` and abort it on the next keystroke, so a slow answer for an
|
|
1399
|
+
* earlier prefix cannot overwrite a newer one.
|
|
1400
|
+
*/
|
|
1401
|
+
async suggestBook({ hostname, suggest, timeout = 3e3, signal }) {
|
|
1402
|
+
const url = `${this.getUrlPrefix()}/api/v2/books/${encodeURIComponent(hostname)}/suggest`;
|
|
1403
|
+
return this.post(url, suggest, timeout, signal);
|
|
1404
|
+
}
|
|
1405
|
+
async post(url, body, timeout, signal) {
|
|
1406
|
+
const headers = new Headers();
|
|
1407
|
+
headers.set("Content-Type", "application/json");
|
|
1408
|
+
return (await this.postAsync({
|
|
1409
|
+
url,
|
|
1410
|
+
headers,
|
|
1411
|
+
body: JSON.stringify(body),
|
|
1412
|
+
timeout,
|
|
1413
|
+
signal
|
|
1414
|
+
})).json();
|
|
1415
|
+
}
|
|
1416
|
+
};
|
|
1417
|
+
//#endregion
|
|
1334
1418
|
//#region src/services/writing_task_service.ts
|
|
1335
1419
|
/**
|
|
1336
1420
|
* The writing task service authenticates on the bearer token but still reads
|
|
@@ -1398,11 +1482,6 @@ var WritingTaskService = class extends BaseService {
|
|
|
1398
1482
|
}
|
|
1399
1483
|
};
|
|
1400
1484
|
//#endregion
|
|
1401
|
-
//#region src/services/solr_proxy_service.ts
|
|
1402
|
-
var SolrProxyService = class extends BaseService {
|
|
1403
|
-
serviceName = "solrProxy";
|
|
1404
|
-
};
|
|
1405
|
-
//#endregion
|
|
1406
1485
|
exports.AIBotService = AIBotService;
|
|
1407
1486
|
exports.CookieConsentLog = CookieConsentLog;
|
|
1408
1487
|
exports.ENVIRONMENTS = ENVIRONMENTS;
|