import * as DAISY from '@nota/daisyparserjs'; import { Stream } from 'stream'; export interface logOnRequest { username: string; password: string; } export interface logOnResponse { logOnResult: boolean; } export interface logOffRequest { } export interface logOffResponse { logOffResult: boolean; } export interface Audio { Uri?: string; RangeBegin: number; RangeEnd: number; } export interface Label { attributes: { 'xml:lang': string; 'dir': string; }; text?: string; audio?: Audio; } export interface ServiceProvider { attributes: { id: string; }; label: Label; } export interface Service { attributes: { id: string; }; label: Label; } export interface SupportedContentSelectionMethods { method: string[]; } export interface SupportedUplinkAudioCodecs { codec: string[]; } export interface SupportedOptionalOperations { operation: string[]; } export interface ServiceAttributes { serviceProvider?: ServiceProvider; service?: Service; supportedContentSelectionMethods?: SupportedContentSelectionMethods; supportsServerSideBack?: boolean; supportsSearch?: boolean; supportedUplinkAudioCodecs?: SupportedUplinkAudioCodecs; supportsAudioLabels?: boolean; supportedOptionalOperations?: SupportedOptionalOperations; } export interface getServiceAttributesRequest { } export interface getServiceAttributesResponse { serviceAttributes: ServiceAttributes; } export interface SupportedContentFormats { contentFormat: string; } export interface SupportedContentProtectionFormats { protectionFormat: string; } export interface KeyRing { item: string; } export interface MimeType { attributes: { type: string; }; } export interface SupportedMimeTypes { mimeType: MimeType; } export interface Input { attributes: { type: string; }; } export interface SupportedInputTypes { input: Input; } export interface AdditionalTransferProtocols { protocol: string; } export interface Config { supportsMultipleSelections: boolean; preferredUILanguage?: string; bandwidth: number; supportedContentFormats?: SupportedContentFormats; supportedContentProtectionFormats?: SupportedContentProtectionFormats; keyRing?: KeyRing; supportedMimeTypes?: SupportedMimeTypes; supportedInputTypes?: SupportedInputTypes; requiresAudioLabels: boolean; additionalTransferProtocols?: AdditionalTransferProtocols; } export interface ReadingSystemAttributes { manufacturer?: string; model?: string; serialNumber?: string; version?: string; config?: Config; } export interface setReadingSystemAttributesRequest { readingSystemAttributes: ReadingSystemAttributes; } export interface setReadingSystemAttributesResponse { setReadingSystemAttributesResult: boolean; } export interface getContentListRequest { id: string; firstItem: number; lastItem: number; } export interface ContentItem { attributes: { id: string; }; label: Label; } export interface ContentList { label: Label; contentItem?: ContentItem[]; attributes: { id: string; firstItem: number; lastItem: number; totalItems: number; }; } export interface getContentListResponse { label: Label; contentList: ContentList; } export interface issueContentRequest { contentID: string; } export interface issueContentResponse { issueContentResult: boolean; } export interface getContentResourcesRequest { contentID: string; } export interface Resource { attributes: { uri: string; mimeType: string; size: number | string; localURI: string; lastModifiedDate: Date | string; }; } export interface Resources { resource: Resource[]; attributes: { returnBy: Date | string; lastModifiedDate: Date | string; }; } export interface getContentResourcesResponse { resources: Resources; } export interface getServiceAnnouncementsRequest { } export interface Announcement { label: Label; attributes: { id: string; type: string; priority: number; }; } export interface Announcements { announcement: Announcement; } export interface getServiceAnnouncementsResponse { announcements: Announcements[]; } export interface markAnnouncementsAsReadRequest { read?: { item: string[]; }; } export interface markAnnouncementsAsReadResponse { markAnnouncementsAsReadResult: boolean; } export interface returnContentRequest { contentID: string; } export interface returnContentResponse { returnContentResult: boolean; } export interface Note { text: string; audio: BookmarkAudio; } export interface BookmarkLocation { ncxRef?: string; URI?: string; timeOffset?: string; charOffset: number; } export interface Bookmark extends BookmarkLocation { label: string; note?: Note; } export interface Lastmark extends BookmarkLocation { } export interface BookmarkAudio { src: string; } export interface Title { audio: BookmarkAudio; text: string; } export interface HilitePoint extends BookmarkLocation { } export interface Hilite { note?: Note; hiliteStart?: HilitePoint; hiliteEnd?: HilitePoint; attributes: { label: string; }; } export interface BookmarkSet { title: Title; uid: string; bookmark: Bookmark[]; lastmark?: Lastmark; hilite?: Hilite[]; } export interface setBookmarksRequest { contentID: string; bookmarkSet: BookmarkSet; } export interface setBookmarksResponse { setBookmarksResult: boolean; } export interface getBookmarksRequest { contentID: string; } export interface getBookmarksResponse { bookmarkSet: BookmarkSet; } export interface UserResponses { data?: string; } export interface getQuestionsRequest { userResponses?: UserResponses; } export interface Questions { [name: string]: any; } export interface getQuestionsResponse { questions?: Questions; } export interface getKeyExchangeObjectRequest { requestedKeyName?: string; } export interface KeyExchange { [name: string]: any; } export interface getKeyExchangeObjectResponse { KeyExchange: KeyExchange; } export interface getContentMetadataRequest { contentID: string; } export interface Sample { attributes: { id: string; }; } export interface Meta { attributes: { name: string; content: string; }; } export interface Metadata { title?: string; identifier?: string; publisher?: string; format?: string; date?: string; source?: string; type?: string; subject?: string; rights?: string; relation?: string; language?: string; description?: string; creator?: string; coverage?: string; contributor?: string; narrator?: string; size: number | string; meta?: Meta[]; } export interface ContentMetadata { sample: Sample; metadata: Metadata; attributes: { category: string; requiresReturn: boolean | string; }; } export interface getContentMetadataResponse { contentMetadata?: ContentMetadata; } export interface DODPCallback { (err: any, result: T): void; } export interface DODPFunction { (args: RequestType, cb: DODPCallback): void; } import * as soap from 'soap'; export interface Client extends soap.Client { logOn: DODPFunction; logOff: DODPFunction; getServiceAttributes: DODPFunction; setReadingSystemAttributes: DODPFunction; getContentList: DODPFunction; issueContent: DODPFunction; returnContent: DODPFunction; getContentResources: DODPFunction; getServiceAnnouncements: DODPFunction; markAnnouncementsAsRead: DODPFunction; setBookmarks: DODPFunction; getBookmarks: DODPFunction; getQuestions: DODPFunction; getKeyExchangeObject: DODPFunction; getContentMetadata: DODPFunction; } import { EventEmitter } from 'events'; export interface DODPClientAPI { clientIp: string; /** * logOn to the DODP-service. * http://www.daisy.org/projects/daisy-online-delivery/drafts/20100402/do-spec-20100402.html#op_logOn * * NOTE: logOn is just the first step of the Session Initialization. * You need to call getServiceAttributes and setReadingSystemAttributes after this * * @param username * @param password * * @returns Promise for when log in has successed, rejects if not. */ logOn(username: string, password: string): Promise; /** * http://www.daisy.org/projects/daisy-online-delivery/drafts/20100402/do-spec-20100402.html#op_logOff * * @returns Promise for when log out has successed, rejects if not. */ logOff(): Promise; /** * http://www.daisy.org/projects/daisy-online-delivery/drafts/20100402/do-spec-20100402.html#op_getServiceAttributes * Retrieves Service properties, including information on which optional Operations the Service supports * * NOTE: This is step two of the Session Initialization Sequence, after logOn and before setReadingSystemAttributes * * * @returns Promise containing ServiceAttributes */ getServiceAttributes(): Promise; /** * http://www.daisy.org/projects/daisy-online-delivery/drafts/20100402/do-spec-20100402.html#op_setReadingSystemAttributes * Sends Reading System properties to a Service. * * NOTE: This is the third and final step in the Session Initialization Sequence, after logOn and after getServiceAttributes * * @param readingSystemAttributes * * @return Promise after reading attributes have been set */ setReadingSystemAttributes(readingSystemAttributes: ReadingSystemAttributes): Promise; /** * http://www.daisy.org/projects/daisy-online-delivery/drafts/20100402/do-spec-20100402.html#op_getServiceAnnouncements * Retrieves any announcements from the Service that a User has not yet read * * @returns Promise containing all unread announcements from the DODP-service */ getServiceAnnouncements(): Promise; /** * http://www.daisy.org/projects/daisy-online-delivery/drafts/20100402/do-spec-20100402.html#op_markAnnouncementsAsRead * Marks the specified announcement(s) as read. * * @param items A list of annoucement IDs to be marked as read * @return Promise for when finished */ markAnnouncementsAsRead(item: string[]): Promise; /** * http://www.daisy.org/projects/daisy-online-delivery/drafts/20100402/do-spec-20100402.html#op_getContentList * Retrieves a list of Content items * * @param listId * @param firstItem used for paging * @param lastItem used for paging, if -1 return all the rest of the items * @return Promise with the ContentList */ getContentList(listId: string, firstItem?: number, lastItem?: number): Promise; /** * http://www.daisy.org/projects/daisy-online-delivery/drafts/20100402/do-spec-20100402.html#op_getContentMetadata * * NOTE: First step in the Content Retrieval Sequence, should be followed by issueContent * * @param contentID * @return ContentMetadata */ getContentMetadata(contentID: string): Promise; /** * http://www.daisy.org/projects/daisy-online-delivery/drafts/20100402/do-spec-20100402.html#op_issueContent * * NOTE: Second step in the Content Retrieval Sequence, should be followed by getContentResources * * @param contentID * @return Promise for when book have been issue */ issueContent(contentID: string): Promise; /** * http://www.daisy.org/projects/daisy-online-delivery/drafts/20100402/do-spec-20100402.html#op_returnContent * Remove the book from the contentList * * @param contentID * @return Promise for when finished */ returnContent(contentID: string): Promise; /** * http://www.daisy.org/projects/daisy-online-delivery/drafts/20100402/do-spec-20100402.html#op_getContentResources * * NOTE: Third and final step in the Content Retrieval Sequence * * @param contentID * @return Promise for when book have been issue */ getContentResources(contentID: string): Promise; /** * http://www.daisy.org/projects/daisy-online-delivery/drafts/20100402/do-spec-20100402.html#op_getBookmarkshttp://www.daisy.org/projects/daisy-online-delivery/drafts/20100402/do-spec-20100402.html#op_getBookmarks * * @param contentID * @returns Promise containing the bookmark response */ getBookmarks(contentID: string): Promise; /** * http://www.daisy.org/projects/daisy-online-delivery/drafts/20100402/do-spec-20100402.html#op_setBookmarks * Store bookmarks on the book * * @param contentID * @param title Title of the section in the book * @param audio audio src * @param uid ????? * @param bookmarks Array of all the bookmarks on the book * @param lastmark Bookmark item for current position in the book * * @returns Promise for when finised */ setBookmarks(contentID: string, title: string, audio: string, uid: string, bookmarks: Bookmark[], lastmark: Lastmark): Promise; /** * http://www.daisy.org/projects/daisy-online-delivery/drafts/20100402/do-spec-20100402.html#op_getQuestions * Retrieves a question from the series of questions that comprise the dynamic menu system. * * @optional data * @return Promise containing the reply to the question */ getQuestions(data?: string): Promise; /** * http://www.daisy.org/projects/daisy-online-delivery/drafts/20100402/do-spec-20100402.html#op_getKeyExchangeObject * Requests a PDTB2 Key Exchange Object from a Service - http://www.daisy.org/projects/pdtb/daisy-pdtb-spec.html * * @param requestedKeyName The identifier of the requested key * @return A PDTB2 Key Exchange Object, containing the requested key encrypted using one of the keys identified in the Reading System's key ring. */ getKeyExchangeObject(requestedKeyName: string): Promise; on(eventName: string, cb: Function): EventEmitter; } export interface DODPServiceAPI { /** * Current client */ client: DODPClientAPI; /** * Promise that resolved with this object once it has an active session on the DODP-server */ ready: Promise; /** * Helper function for ensuring logOn, if DODP fails with a no session, this function will attempt to login again */ withLogOn(worker: () => Promise): Promise; /** * Wrapper function for logOn * * @return Promise containing true if successful, rejects if not. */ logOn(): Promise; /** * Wrapper for issueContent, issues the book on the DODP-server and creates a Book-object * * @param contentID * @return Promise containing the book-object, rejects if book can't be issued */ issueContent(contentID: string): Promise; /** * Wrapper for returnContent, removes the book from the users bookshelf * @param contentID * @return */ returnContent(contentID: string): Promise; /** * Wraps issueContent and Book.exportStructure() * * @param contentID * @return Promise containing the book export */ loadBookStructure(contentID: string): Promise; /** * Wraps getContentResources - get a list of resources for a book, this call should be cached * * @param contentID * @return Promise containing the book Resources list */ getContentResources(contentID: string): Promise; /** * Loads metadata about content file * * @param uri Full URI for the resource file * @return Promise with metadata */ getResourceMetadata(uri: string): Promise; /** * Open a stream for the content file * * @param uri Full URI for the resource file * @optional start bytes start offset for the stream * @optional end end bytes for the stream * @return Promise with the Stream */ getResourceStream(uri: string, start?: number, end?: number): Stream; /** * Helper function for loading book files, e.g NCCs, SMILs, html etc. * * @param contentID * @param localUri Relative path within the book to the content-file * @param uri Real uri for the file * @return Promise with a Buffer of the loaded file */ loadResource(contentID: string, localUri: string, uri: string): Promise; /** * Wraps getContentMetadata - result should be cached * * @param contentID * @return Promise containing the Metadata */ getContentMetadata(contentID: string): Promise; /** * Wraps getContentList followed by getContentMetadata. * * @param listId Name of the content list, e.g. new, issued, expired * @param firstItem start offset defaults to 0 * @param lastItem end offset defaults to -1 e.g rest * @return Promise containing Metadata for each book on the content list */ getContentList(listId?: string, firstItem?: number, lastItem?: number): Promise; on(eventName: string, cb: Function): EventEmitter; }