@gyldendalas/gyldendal-divine-api 0.1.2 → 0.1.4

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 CHANGED
@@ -20,9 +20,17 @@ var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: tru
20
20
  // src/index.ts
21
21
  var index_exports = {};
22
22
  __export(index_exports, {
23
+ CookieConsentLog: () => CookieConsentLog,
24
+ HighlightResultType: () => HighlightResultType,
25
+ HighlightService: () => HighlightService,
26
+ PollyService: () => PollyService,
27
+ SSMLSpeechSpeeds: () => SSMLSpeechSpeeds,
23
28
  TaggingService: () => TaggingService,
24
29
  UserFolders: () => UserFolders,
25
- UserSettings: () => UserSettings
30
+ UserSettingsBookmarks: () => UserSettingsBookmarks,
31
+ UserSettingsClientSettings: () => UserSettingsClientSettings,
32
+ UserSettingsContinue: () => UserSettingsContinue,
33
+ UserSettingsMRU: () => UserSettingsMRU
26
34
  });
27
35
  module.exports = __toCommonJS(index_exports);
28
36
 
@@ -77,52 +85,55 @@ var BaseService = class {
77
85
  async getAsync({
78
86
  url,
79
87
  headers,
88
+ addAuthHeaders = true,
80
89
  timeout
81
90
  }) {
82
91
  const method = "GET";
83
- const response = await this.callAsync({ url, body: null, method, headers, timeout });
84
- return response.json();
92
+ return await this.callAsync({ url, body: null, method, headers, addAuthHeaders, timeout });
85
93
  }
86
94
  async putAsync({
87
95
  url,
88
96
  headers,
97
+ addAuthHeaders = true,
89
98
  body,
90
99
  timeout
91
100
  }) {
92
101
  const method = "PUT";
93
- const response = await this.callAsync({ url, body, method, headers, timeout });
94
- return response.json();
102
+ return await this.callAsync({ url, body, method, headers, addAuthHeaders, timeout });
95
103
  }
96
104
  async postAsync({
97
105
  url,
98
106
  headers,
107
+ addAuthHeaders = true,
99
108
  body,
100
109
  timeout
101
110
  }) {
102
111
  const method = "POST";
103
- const response = await this.callAsync({ url, body, method, headers, timeout });
104
- return response.json();
112
+ return await this.callAsync({ url, body, method, headers, addAuthHeaders, timeout });
105
113
  }
106
114
  async deleteAsync({
107
115
  url,
108
116
  headers,
117
+ addAuthHeaders = true,
109
118
  timeout
110
119
  }) {
111
120
  const method = "DELETE";
112
- const response = await this.callAsync({ url, body: null, method, headers, timeout });
113
- return response.json();
121
+ return await this.callAsync({ url, body: null, method, headers, addAuthHeaders, timeout });
114
122
  }
115
123
  async callAsync({
116
124
  url,
117
125
  body,
118
126
  method,
119
127
  headers,
120
- timeout
128
+ timeout,
129
+ addAuthHeaders
121
130
  }) {
122
131
  if (!headers) {
123
132
  headers = new Headers();
124
133
  }
125
- headers = await this.addAuthHeaders(headers);
134
+ if (addAuthHeaders) {
135
+ headers = await this.addAuthHeaders(headers);
136
+ }
126
137
  const response = await fetch(url, {
127
138
  method,
128
139
  body,
@@ -159,7 +170,8 @@ var TaggingService = class extends base_service_default {
159
170
  }) {
160
171
  const url = `${this.getUrlPrefix()}/tags/by_resource/${identity}${resource_type ? `/${resource_type}` : ""}${resource_name ? `/${resource_name}` : ""}${tag_name ? `/${tag_name}` : ""}`;
161
172
  const headers = new Headers();
162
- return await this.getAsync({ url, headers, timeout });
173
+ const response = await this.getAsync({ url, headers, timeout });
174
+ return response.json();
163
175
  }
164
176
  async getTagsByName({
165
177
  identity,
@@ -170,7 +182,8 @@ var TaggingService = class extends base_service_default {
170
182
  }) {
171
183
  const url = `${this.getUrlPrefix()}/tags/by_tag_name/${identity}/${tag_name}${resource_type ? `/${resource_type}` : ""}${resource_name ? `/${resource_name}` : ""}`;
172
184
  const headers = new Headers();
173
- return await this.getAsync({ url, headers, timeout });
185
+ const response = await this.getAsync({ url, headers, timeout });
186
+ return await response.json();
174
187
  }
175
188
  async createTag({
176
189
  tag,
@@ -179,7 +192,8 @@ var TaggingService = class extends base_service_default {
179
192
  const url = `${this.getUrlPrefix()}/tags`;
180
193
  const headers = new Headers();
181
194
  headers.append("Content-Type", "application/json");
182
- return await this.postAsync({ url, headers, body: JSON.stringify(tag), timeout });
195
+ const response = await this.postAsync({ url, headers, body: JSON.stringify(tag), timeout });
196
+ return await response.json();
183
197
  }
184
198
  async updateTag({
185
199
  tag,
@@ -188,7 +202,8 @@ var TaggingService = class extends base_service_default {
188
202
  const url = `${this.getUrlPrefix()}/tags`;
189
203
  const headers = new Headers();
190
204
  headers.append("Content-Type", "application/json");
191
- return await this.putAsync({ url, headers, body: JSON.stringify(tag), timeout });
205
+ const response = await this.putAsync({ url, headers, body: JSON.stringify(tag), timeout });
206
+ return await response.json();
192
207
  }
193
208
  async deleteTag({
194
209
  identity,
@@ -199,31 +214,197 @@ var TaggingService = class extends base_service_default {
199
214
  }) {
200
215
  const url = `${this.getUrlPrefix()}/tags/${identity}${resource_type ? `/${resource_type}` : ""}${resource_name ? `/${resource_name}` : ""}${tag_name ? `/${tag_name}` : ""}`;
201
216
  const headers = new Headers();
202
- await this.deleteAsync({ url, headers, timeout });
217
+ const response = await this.deleteAsync({ url, headers, timeout });
218
+ await response.json();
219
+ return;
203
220
  }
204
221
  };
205
222
  var tagging_service_default = TaggingService;
206
223
 
207
- // src/services/user_settings.ts
208
- var UserSettings = class extends base_service_default {
224
+ // src/services/polly_service.ts
225
+ var SSMLSpeechSpeeds = /* @__PURE__ */ ((SSMLSpeechSpeeds2) => {
226
+ SSMLSpeechSpeeds2[SSMLSpeechSpeeds2["X_SLOW"] = 1] = "X_SLOW";
227
+ SSMLSpeechSpeeds2[SSMLSpeechSpeeds2["SLOW"] = 2] = "SLOW";
228
+ SSMLSpeechSpeeds2[SSMLSpeechSpeeds2["MEDIUM"] = 3] = "MEDIUM";
229
+ SSMLSpeechSpeeds2[SSMLSpeechSpeeds2["FAST"] = 4] = "FAST";
230
+ SSMLSpeechSpeeds2[SSMLSpeechSpeeds2["X_FAST"] = 5] = "X_FAST";
231
+ return SSMLSpeechSpeeds2;
232
+ })(SSMLSpeechSpeeds || {});
233
+ var PollyService = class extends base_service_default {
234
+ discoverUrlPrefix() {
235
+ switch (this.environment) {
236
+ case "production":
237
+ return `https://appear-polly.services.${this.baseDomain}`;
238
+ case "development":
239
+ case "local":
240
+ return `https://staging-appear-polly.services.${this.baseDomain}`;
241
+ default:
242
+ throw new Error(`Unknown environment: ${this.environment}`);
243
+ }
244
+ }
245
+ async synthesize({
246
+ body,
247
+ timeout = 3e3
248
+ }) {
249
+ const url = `${this.getUrlPrefix()}/synthesizeSpeech`;
250
+ const headers = new Headers();
251
+ headers.append("Content-Type", "application/json");
252
+ const response = await this.postAsync({ url, headers, body: JSON.stringify(body), timeout });
253
+ return response.json();
254
+ }
255
+ };
256
+
257
+ // src/services/cookie_consent_log.ts
258
+ var CookieConsentLog = class extends base_service_default {
259
+ discoverUrlPrefix() {
260
+ switch (this.environment) {
261
+ case "production":
262
+ return `https://cookieconsentlog.services.${this.baseDomain}`;
263
+ case "development":
264
+ case "local":
265
+ return `https://staging-cookieconsentlog.services.${this.baseDomain}`;
266
+ default:
267
+ throw new Error(`Unknown environment: ${this.environment}`);
268
+ }
269
+ }
270
+ async logCookieConsent({
271
+ body,
272
+ timeout = 3e3
273
+ }) {
274
+ const url = `${this.getUrlPrefix()}/log`;
275
+ const headers = new Headers();
276
+ headers.append("Content-Type", "application/json");
277
+ const response = await this.postAsync({ url, headers, body: JSON.stringify(body), addAuthHeaders: false, timeout });
278
+ return response.text();
279
+ }
280
+ };
281
+
282
+ // src/services/highlight_service.ts
283
+ var HighlightResultType = /* @__PURE__ */ ((HighlightResultType2) => {
284
+ HighlightResultType2["highlight"] = "highlight";
285
+ HighlightResultType2["note"] = "note";
286
+ return HighlightResultType2;
287
+ })(HighlightResultType || {});
288
+ var HighlightService = class extends base_service_default {
289
+ discoverUrlPrefix() {
290
+ switch (this.environment) {
291
+ case "production":
292
+ return `https://highlights.services.${this.baseDomain}`;
293
+ case "development":
294
+ case "local":
295
+ return `https://staging-highlights.services.${this.baseDomain}`;
296
+ default:
297
+ throw new Error(`Unknown environment: ${this.environment}`);
298
+ }
299
+ }
300
+ async search({
301
+ search,
302
+ timeout = 3e3
303
+ }) {
304
+ const url = `${this.getUrlPrefix()}/v2/search`;
305
+ const headers = new Headers();
306
+ headers.append("Content-Type", "application/json");
307
+ const response = await this.postAsync({ url, headers, body: JSON.stringify(search), timeout });
308
+ return response.json();
309
+ }
310
+ async deleteHighlightOrNote({
311
+ isbn,
312
+ pid,
313
+ key,
314
+ timeout = 3e3
315
+ }) {
316
+ const url = `${this.getUrlPrefix()}/v2/isbn/${isbn}/pid/${pid}/key/${key}`;
317
+ const headers = new Headers();
318
+ headers.append("Content-Type", "application/json");
319
+ const response = await this.deleteAsync({ url, headers, timeout });
320
+ return response.json();
321
+ }
322
+ async getHighlightOrNote({
323
+ isbn,
324
+ pid,
325
+ timeout = 3e3
326
+ }) {
327
+ let url = `${this.getUrlPrefix()}/v2/isbn/${isbn}`;
328
+ if (pid) {
329
+ url += `/pid/${pid}`;
330
+ }
331
+ const headers = new Headers();
332
+ const response = await this.getAsync({ url, headers, timeout });
333
+ return response.json();
334
+ }
335
+ async getHighlightOrNoteCounts({
336
+ noteType,
337
+ timeout = 3e3
338
+ }) {
339
+ let url = `${this.getUrlPrefix()}/v2/count`;
340
+ if (noteType) {
341
+ url += `/${noteType}`;
342
+ }
343
+ const headers = new Headers();
344
+ const response = await this.getAsync({ url, headers, timeout });
345
+ return response.json();
346
+ }
347
+ async updateHighlightOrNote({
348
+ payload,
349
+ isbn,
350
+ pid,
351
+ key,
352
+ timeout = 5e3
353
+ }) {
354
+ const url = `${this.getUrlPrefix()}/v2/isbn/${isbn}/pid/${pid}/key/${key}`;
355
+ const headers = new Headers();
356
+ headers.set("Content-Type", "application/json");
357
+ const response = await this.putAsync({ url, headers, body: JSON.stringify(payload), timeout });
358
+ return response.json();
359
+ }
360
+ async addHighlightOrNote({
361
+ payload,
362
+ isbn,
363
+ pid,
364
+ timeout = 5e3
365
+ }) {
366
+ const url = `${this.getUrlPrefix()}/v2/isbn/${isbn}/pid/${pid}`;
367
+ const headers = new Headers();
368
+ headers.set("Content-Type", "application/json");
369
+ const response = await this.postAsync({ url, headers, body: JSON.stringify(payload), timeout });
370
+ return response.json();
371
+ }
372
+ };
373
+
374
+ // src/services/user_settings_base.ts
375
+ var UserSettingsBase = class extends base_service_default {
209
376
  discoverUrlPrefix() {
210
377
  switch (this.environment) {
211
378
  case "production":
212
379
  return `https://user-settings-service.services.${this.baseDomain}`;
213
380
  case "development":
214
381
  case "local":
215
- return `https://${this.environment}-user-settings-service.services.${this.baseDomain}`;
382
+ return `https://staging-user-settings-service.services.${this.baseDomain}`;
216
383
  default:
217
384
  throw new Error(`Unknown environment: ${this.environment}`);
218
385
  }
219
386
  }
387
+ };
388
+ var user_settings_base_default = UserSettingsBase;
389
+
390
+ // src/services/user_settings_clientsettings.ts
391
+ var UserSettingsClientSettings = class extends user_settings_base_default {
220
392
  async getSettings({
221
393
  isbn,
222
394
  timeout = 5e3
223
395
  }) {
224
396
  const url = `${this.getUrlPrefix()}/clientsettings/isbn/${isbn}`;
225
397
  const headers = new Headers();
226
- return await this.getAsync({ url, headers, timeout });
398
+ try {
399
+ const response = await this.getAsync({ url, headers, timeout });
400
+ return response.json();
401
+ } catch (Error2) {
402
+ if (Error2 instanceof HTTPError && Error2.response.status === 404) {
403
+ return {};
404
+ } else {
405
+ throw HTTPError;
406
+ }
407
+ }
227
408
  }
228
409
  async setSettings({
229
410
  isbn,
@@ -233,7 +414,157 @@ var UserSettings = class extends base_service_default {
233
414
  const url = `${this.getUrlPrefix()}/clientsettings/isbn/${isbn}`;
234
415
  const headers = new Headers();
235
416
  headers.set("Content-Type", "application/json");
236
- return await this.putAsync({ url, headers, body: JSON.stringify(settings), timeout });
417
+ const response = await this.putAsync({ url, headers, body: JSON.stringify(settings), timeout });
418
+ return response.json();
419
+ }
420
+ async deleteSettings({
421
+ isbn,
422
+ timeout = 5e3
423
+ }) {
424
+ const url = `${this.getUrlPrefix()}/clientsettings/isbn/${isbn}`;
425
+ const headers = new Headers();
426
+ await this.deleteAsync({ url, headers, timeout });
427
+ return;
428
+ }
429
+ };
430
+
431
+ // src/services/user_settings_bookmarks.ts
432
+ var UserSettingsBookmarks = class extends user_settings_base_default {
433
+ async setBookmark({
434
+ isbn,
435
+ bookmark,
436
+ externalUserId,
437
+ timeout = 5e3
438
+ }) {
439
+ const url = `${this.getUrlPrefix()}/bookmark/isbn/${isbn}`;
440
+ const headers = new Headers();
441
+ if (externalUserId) {
442
+ headers.set("external-user-id", externalUserId);
443
+ }
444
+ headers.set("Content-Type", "application/json");
445
+ const response = await this.putAsync({ url, headers, body: JSON.stringify(bookmark), timeout });
446
+ return response.json();
447
+ }
448
+ async deleteBookmark({
449
+ isbn,
450
+ pageId,
451
+ contentId,
452
+ timeout = 5e3
453
+ }) {
454
+ const url = `${this.getUrlPrefix()}/bookmark/isbn/${isbn}/page/${pageId}/content/${contentId}`;
455
+ const headers = new Headers();
456
+ await this.deleteAsync({ url, headers, timeout });
457
+ return;
458
+ }
459
+ async getBookmark({
460
+ isbn,
461
+ pageId,
462
+ timeout = 5e3
463
+ }) {
464
+ if (!isbn && pageId) {
465
+ throw new Error("The isbn parameter is required if pageId is provided.");
466
+ }
467
+ let url = `${this.getUrlPrefix()}/bookmark/`;
468
+ if (isbn) {
469
+ url += `isbn/${isbn}`;
470
+ }
471
+ if (pageId) {
472
+ url += `/page/${pageId}`;
473
+ }
474
+ const headers = new Headers();
475
+ const response = await this.getAsync({ url, headers, timeout });
476
+ return response.json();
477
+ }
478
+ // Favourites are bookmarks that are ISBN specific, with a pageId of 0.
479
+ async getFavourite({
480
+ timeout = 5e3
481
+ }) {
482
+ let url = `${this.getUrlPrefix()}/bookmark/favourite`;
483
+ const headers = new Headers();
484
+ const response = await this.getAsync({ url, headers, timeout });
485
+ return response.json();
486
+ }
487
+ };
488
+
489
+ // src/services/user_settings_continue.ts
490
+ var UserSettingsContinue = class extends user_settings_base_default {
491
+ async setContinue({
492
+ isbn,
493
+ pageId,
494
+ externalUserId,
495
+ timeout = 5e3
496
+ }) {
497
+ const continueBody = {
498
+ pageId
499
+ };
500
+ const url = `${this.getUrlPrefix()}/continue/isbn/${isbn}`;
501
+ const headers = new Headers();
502
+ if (externalUserId) {
503
+ headers.set("external-user-id", externalUserId);
504
+ }
505
+ headers.set("Content-Type", "application/json");
506
+ const response = await this.putAsync({ url, headers, body: JSON.stringify(continueBody), timeout });
507
+ return response.json();
508
+ }
509
+ async deleteContinue({
510
+ isbn,
511
+ timeout = 5e3
512
+ }) {
513
+ const url = `${this.getUrlPrefix()}/continue/isbn/${isbn}`;
514
+ const headers = new Headers();
515
+ await this.deleteAsync({ url, headers, timeout });
516
+ return;
517
+ }
518
+ async getContinue({
519
+ isbn,
520
+ timeout = 5e3
521
+ }) {
522
+ let url = `${this.getUrlPrefix()}/continue/isbn/${isbn}`;
523
+ const headers = new Headers();
524
+ try {
525
+ const response = await this.getAsync({ url, headers, timeout });
526
+ return response.json();
527
+ } catch (Error2) {
528
+ if (Error2 instanceof HTTPError && Error2.response.status === 404) {
529
+ return {};
530
+ } else {
531
+ throw HTTPError;
532
+ }
533
+ }
534
+ }
535
+ };
536
+
537
+ // src/services/user_settings_mru.ts
538
+ var UserSettingsMRU = class extends user_settings_base_default {
539
+ async setMRU({
540
+ mru,
541
+ externalUserId,
542
+ timeout = 5e3
543
+ }) {
544
+ const url = `${this.getUrlPrefix()}/mru`;
545
+ const headers = new Headers();
546
+ if (externalUserId) {
547
+ headers.set("external-user-id", externalUserId);
548
+ }
549
+ headers.set("Content-Type", "application/json");
550
+ const response = await this.postAsync({ url, headers, body: JSON.stringify(mru), timeout });
551
+ return response.json();
552
+ }
553
+ async clearMRU({
554
+ timeout = 5e3
555
+ }) {
556
+ const url = `${this.getUrlPrefix()}/mru`;
557
+ const headers = new Headers();
558
+ await this.deleteAsync({ url, headers, timeout });
559
+ return;
560
+ }
561
+ async getMRU({
562
+ timeout = 5e3
563
+ }) {
564
+ let url = `${this.getUrlPrefix()}/mru`;
565
+ const headers = new Headers();
566
+ const response = await this.getAsync({ url, headers, timeout });
567
+ return response.json();
237
568
  }
238
569
  };
239
570
 
@@ -589,8 +920,16 @@ var UserFolders = class extends tagging_service_default {
589
920
  };
590
921
  // Annotate the CommonJS export names for ESM import in node:
591
922
  0 && (module.exports = {
923
+ CookieConsentLog,
924
+ HighlightResultType,
925
+ HighlightService,
926
+ PollyService,
927
+ SSMLSpeechSpeeds,
592
928
  TaggingService,
593
929
  UserFolders,
594
- UserSettings
930
+ UserSettingsBookmarks,
931
+ UserSettingsClientSettings,
932
+ UserSettingsContinue,
933
+ UserSettingsMRU
595
934
  });
596
935
  //# sourceMappingURL=index.cjs.map