Commit 4b79489f authored by Robert Knight's avatar Robert Knight

Make `page` and `index` fields as optional

These fields may not be missing from the response of VitalSource's
`getCurrentPage` API if the book is an EPUB that does not have page numbers. As
far as I know all PDF-based books should have page numbers.
parent 0265b75f
......@@ -405,7 +405,7 @@ describe('annotator/integrations/vitalsource', () => {
});
});
['absoluteURL', 'cfi', 'index', 'page'].forEach(field => {
['absoluteURL', 'cfi'].forEach(field => {
it(`throws if page info field "${field}" is missing`, async () => {
fakeBookElement.selectPDFBook();
......@@ -428,7 +428,7 @@ describe('annotator/integrations/vitalsource', () => {
assert.instanceOf(error, Error);
assert.equal(
error.message,
`Chapter metadata field "${field}" is missing`
`Page metadata field "${field}" is missing`
);
});
});
......
......@@ -337,7 +337,7 @@ export class VitalSourceContentIntegration
// currently limit page number selectors to PDFs until more is understood
// about when EPUB page numbers are reliable/likely to remain stable.
const bookInfo = this._bookElement.getBookInfo();
if (bookInfo.format === 'pbk') {
if (bookInfo.format === 'pbk' && typeof pageIndex === 'number') {
extraSelectors.push({
type: 'PageSelector',
index: pageIndex,
......@@ -433,12 +433,12 @@ export class VitalSourceContentIntegration
// If changes in VitalSource ever mean that critical chapter/page metadata
// fields are missing, fail loudly. Otherwise we might create annotations
// that cannot be re-anchored in future.
const expectedFields = ['absoluteURL', 'cfi', 'index', 'page'];
for (const field of expectedFields) {
const requiredFields = ['absoluteURL', 'cfi'];
for (const field of requiredFields) {
// nb. We intentionally allow properties anywhere on the prototype chain,
// rather than requiring `hasOwnProperty`.
if (!(field in pageInfo)) {
throw new Error(`Chapter metadata field "${field}" is missing`);
throw new Error(`Page metadata field "${field}" is missing`);
}
}
......
......@@ -65,13 +65,13 @@ export type PageInfo = {
* that is displayed in the VitalSource navigation controls when the
* chapter is scrolled to the top.
*/
page: string;
page?: string;
/**
* Index of the current segment within the sequence of pages or content
* documents that make up the book.
*/
index: number;
index?: number;
/**
* Title of the entry in the table of contents that refers to the current
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment