From fd9fde1fc6014c1dd8630db0db1e437211c0b545 Mon Sep 17 00:00:00 2001 From: Augusto Romero Vicente <41742354+augustovicente@users.noreply.github.com> Date: Wed, 15 May 2024 09:29:02 +0100 Subject: [PATCH] Refactor types 2 interfaces (#11) * REFACTOR: reorganise types and interfaces and fix some exports * FIX: @Sleepyblue suggestions --- package.json | 2 +- types/common.d.ts | 9 ++- types/document.d.ts | 84 +++++++++++++++++++++++ types/draft.d.ts | 131 ++++++++--------------------------- types/index.d.ts | 2 + types/publication.d.ts | 151 ++++++++++++++++------------------------- types/stack.d.ts | 56 +++++++-------- types/user.d.ts | 82 +++++++++++----------- 8 files changed, 252 insertions(+), 265 deletions(-) create mode 100644 types/document.d.ts diff --git a/package.json b/package.json index 77d972d..0fa55b4 100644 --- a/package.json +++ b/package.json @@ -1,6 +1,6 @@ { "name": "@issuu/issuu-api-sdk", - "version": "0.0.9", + "version": "0.0.10", "type": "module", "license": "MIT", "scripts": { diff --git a/types/common.d.ts b/types/common.d.ts index 3b71252..7607a37 100644 --- a/types/common.d.ts +++ b/types/common.d.ts @@ -12,11 +12,15 @@ type DocumentType = 'editorial' | 'book' | 'promotional' | 'other'; type DocumentFileInfoType = 'UNKNOWN' | 'DOC' | 'ODP' | 'ODT' | 'PDF' | 'PPT' | 'RTF' | 'SXI' | 'SXW' | 'WPD' | 'EPUB' | 'MOBI'; type DraftConversionStatus = 'DONE' | 'CONVERTING' | 'FAILED'; type PublishValidateError = 'file_too_big' | 'file_too_many_pages' | 'file_not_converted' | 'missing_license_download' | 'missing_license_scheduled_publishing' | 'missing_license_detected_links' | 'unknown' | 'unlisted_limit_exceeded' | 'missing_title' | 'missing_description' | 'missing_file' | 'missing_access' | 'incomplete_draft' | 'published_documents_limit_exceeded'; -type DraftStatus = 'DRAFT' | 'PUBLISHED' | 'SCHEDULED' | 'UNPUBLISHED' | 'QUARANTINED'; +type DocumentStatus = 'DRAFT' | 'PUBLISHED' | 'SCHEDULED' | 'UNPUBLISHED' | 'QUARANTINED'; // Stacks type StackAccessTypes = 'PUBLIC' | 'UNLISTED'; // User type Limit = number | 'unlimited'; +// Publication +type URLResult = { + url: string, +}; export type { Link, @@ -26,8 +30,9 @@ export type { DraftConversionStatus, PublishValidateError, StackAccessTypes, - DraftStatus, + DocumentStatus, CoverAsset, ImageFormat, Limit, + URLResult, }; diff --git a/types/document.d.ts b/types/document.d.ts new file mode 100644 index 0000000..8579b04 --- /dev/null +++ b/types/document.d.ts @@ -0,0 +1,84 @@ +import { + Access, + CoverAsset, + DocumentFileInfoType, + DocumentType, + DraftConversionStatus, + DocumentStatus +} from "./common"; + +interface DocumentInformation { + /** + * The identifier of the file that will be used in the next publish + */ + file?: number; + /** + * PUBLIC documents, once published, will be made searcheable and will appear in streams, recommendations, etc. PRIVATE documents, once published, are only accessible from users that knows their URL. + */ + access?: Access; + title?: string; + description?: string; + /** + * Set it to true to indicate that the document is a preview of a bigger content. + */ + preview?: boolean; + type?: DocumentType; + /** + * When set to true, the conversion procedure will search for hypermedia links inside the document text. + */ + showDetectedLinks?: boolean; + /** + * When set to true once published the readers will be allowed to download the original document. + */ + downloadable?: boolean; + /** + * Set the original publish date field to indicate that a document was previously published, e.g. to import older issues of your magazine. Set it to null to clear the backDate. + */ + originalPublishDate?: string; + /** + * This field schedules the date for Publication, until then the document will be at SCHEDULED state. + */ + scheduledTime?: string; +} + +interface Document { + /** + * The document identifier + */ + slug: string; + /** + * (User/Team)-name of the document owner + */ + owner: string; + cover: { + small: CoverAsset; + medium: CoverAsset; + large: CoverAsset; + }; + fileInfo: { + name: string; + type: DocumentFileInfoType; + size: number; + pageCount: number; + conversionStatus: DraftConversionStatus; + isCopyrightConfirmed: boolean; + }; + state: DocumentStatus; + /** + * The document edit page URL for the publisher + */ + location: string; + /** + * Changes to be apply on the next publish + */ + changes?: DocumentInformation; + /** + * Document created date + */ + created?: string; +} + +export type { + DocumentInformation, + Document, +}; \ No newline at end of file diff --git a/types/draft.d.ts b/types/draft.d.ts index 503c0d2..0c4bf6c 100644 --- a/types/draft.d.ts +++ b/types/draft.d.ts @@ -3,137 +3,68 @@ import { DocumentType, DraftConversionStatus, DocumentFileInfoType, - DraftStatus, + DocumentStatus, CoverAsset } from "./common"; +import { Document, DocumentInformation } from "./document"; -interface DocumentInformation { - /** - * The identifier of the file that will be used in the next publish - */ - file?: number; - /** - * PUBLIC documents, once published, will be made searcheable and will appear in streams, recommendations, etc. PRIVATE documents, once published, are only accessible from users that knows their URL. - */ - access?: Access; - title?: string; - description?: string; - /** - * Set it to true to indicate that the document is a preview of a bigger content. - */ - preview?: boolean; - type?: DocumentType; - /** - * When set to true, the conversion procedure will search for hypermedia links inside the document text. - */ - showDetectedLinks?: boolean; - /** - * When set to true once published the readers will be allowed to download the original document. - */ - downloadable?: boolean; - /** - * Set the original publish date field to indicate that a document was previously published, e.g. to import older issues of your magazine. Set it to null to clear the backDate. - */ - originalPublishDate?: string; - /** - * This field schedules the date for Publication, until then the document will be at SCHEDULED state. - */ - scheduledTime?: string; -} - -type CreateNewDraftRequest = { - confirmCopyright?: boolean, - fileUrl?: string, +interface CreateNewDraftRequest { + confirmCopyright?: boolean; + fileUrl?: string; /** * Metadata used to create documents in draft state and update changes that will be reflected on the next publish */ - info: DocumentInformation -}; + info: DocumentInformation; +} /** * A not-yet-published document. */ -type CreateNewDraftResponse = -{ - /** - * The document identifier - */ - slug: string, - /** - * (User/Team)-name of the document owner - */ - owner: string, - cover: { - small: CoverAsset, - medium: CoverAsset, - large: CoverAsset, - }, - fileInfo: { - name: string, - type: DocumentFileInfoType, - size: number, - pageCount: number, - conversionStatus: DraftConversionStatus, - isCopyrightConfirmed: boolean - }, +interface CreateNewDraftResponse extends Document { /** * DRAFTed documents have not been published yet */ - state: 'DRAFT', - /** - * The document edit page URL for the publisher - */ - location: string, - /** - * Changes to be apply on the next publish - */ - changes?: DocumentInformation, - /** - * Draft created date - */ - created?: string -}; + state: 'DRAFT'; +} /** * Represents a document. It is a discriminated union of DocumentDraft, DocumentPublished, DocumentScheduled, DocumentUnpublished and DocumentQuarantined structures. The discriminator is the state field. */ -type GetDraftBySlugResponse = CreateNewDraftResponse & { - state: DraftStatus -}; +interface GetDraftBySlugResponse extends Document {} -type UpdateDraftBySlugRequest = { - confirmCopyright?: boolean, - fileUrl?: string, - info?: DocumentInformation -}; -type UpdateDraftBySlugResponse = CreateNewDraftResponse; +interface UpdateDraftBySlugRequest { + confirmCopyright?: boolean; + fileUrl?: string; + info?: DocumentInformation; +} +interface UpdateDraftBySlugResponse extends CreateNewDraftResponse {}; -type UploadDocumentToDraftBySlugRequest = { - file: Blob, - confirmCopyright: 'true', -}; +interface UploadDocumentToDraftBySlugRequest { + file: Blob; + confirmCopyright: 'true'; +} /** * A not-yet-published document. */ -type UploadDocumentToDraftBySlugResponse = UpdateDraftBySlugResponse; +interface UploadDocumentToDraftBySlugResponse extends UpdateDraftBySlugResponse {} -type PublishDraftBySlugRequest = { +interface PublishDraftBySlugRequest { /** * The desired custom part of the document page url: https://issuu.com//docs/ If already taken by another document, a random string is appended. Must be URL-friendly. * This is ignored for team documents. */ - desiredName?: string -}; -type PublishDraftBySlugResponse = { + desiredName?: string; +} +interface PublishDraftBySlugResponse { /** * The document page URL */ - publicLocation: string, + publicLocation: string; /** * The document edit page URL for the publisher */ - location: string, - slug?: string, -}; + location: string; + slug?: string; +} type CreateAndPublishDraftResponse = PublishDraftBySlugResponse | { slug: string }; @@ -149,6 +80,4 @@ export type { UploadDocumentToDraftBySlugRequest, CreateAndPublishDraftResponse, PublishValidateError, - Access as DraftAccess, - DocumentInformation as DraftInformation, }; diff --git a/types/index.d.ts b/types/index.d.ts index 23facad..7c53bb3 100644 --- a/types/index.d.ts +++ b/types/index.d.ts @@ -2,3 +2,5 @@ export * from './draft'; export * from './publication'; export * from './user'; export * from './stack'; +export * from './document'; +export * from './common'; diff --git a/types/publication.d.ts b/types/publication.d.ts index 2bf912a..03ffff4 100644 --- a/types/publication.d.ts +++ b/types/publication.d.ts @@ -1,172 +1,139 @@ -import { DocumentType, Access, DraftStatus, Link, ImageFormat } from "./common"; -import { CreateNewDraftResponse } from "./draft"; +import { DocumentType, Access, DocumentStatus, Link, ImageFormat, URLResult } from "./common"; +import { Document, DocumentInformation } from "./document"; /** * Represents a document. It is a discriminated union of DocumentDraft, DocumentPublished, DocumentScheduled, DocumentUnpublished and DocumentQuarantined structures. The discriminator is the state field. */ -type GetPublicationBySlugResult = CreateNewDraftResponse & { - state: DraftStatus, - /** - * The identifier of the file that will be used in the next publish - */ - file?: number, - /** - * PUBLIC documents, once published, will be made searcheable and will appear in streams, recommendations, etc. PRIVATE documents, once published, are only accessible from users that knows their URL. - */ - access?: Access, - title?: string, - description?: string, - /** - * Set it to true to indicate that the document is a preview of a bigger content. - */ - preview?: boolean, - type?: DocumentType, - /** - * When set to true, the conversion procedure will search for hypermedia links inside the document text. - */ - showDetectedLinks?: boolean, - /** - * When set to true once published the readers will be allowed to download the original document. - */ - downloadable?: boolean, - /** - * Set the original publish date field to indicate that a document was previously published, e.g. to import older issues of your magazine. Set it to null to clear the backDate. - */ - originalPublishDate?: string, -}; +interface GetPublicationBySlugResult extends DocumentInformation, Document {}; -type GetPublicationAssetsBySlugResult1 = { +interface PublicationAssetsResult { assets: { text: { - [key: string]: string - } + [key: string]: string; + }; image: { - [key: string]: string - } - }, - pageNumber: number, -}; -type GetPublicationAssetsBySlugResult2 = { + [key: string]: string; + }; + }; + pageNumber: number; +} +interface PublicationThumbnailsResult { thumbnails: { - medium?: string, - large?: string, - small?: string, - }, - pageImage: string - pageNumber: number -}; -type GetPublicationAssetsBySlugResult = { - results: (GetPublicationAssetsBySlugResult1 | GetPublicationAssetsBySlugResult2)[], + medium?: string; + large?: string; + small?: string; + }; + pageImage: string; + pageNumber: number; +} +interface GetPublicationAssetsBySlugResult { + results: (PublicationAssetsResult | PublicationThumbnailsResult)[]; links: { next?: Link; self?: Link; previous?: Link; - }, - count?: number, - pageSize: number, -}; - -type URLResult = { - url: string, -}; + }; + count?: number; + pageSize: number; +} -type GetPublicationFullscreenShareBySlugRequest = { +interface GetPublicationFullscreenShareBySlugRequest { /** * Start page of the shared link. Default 1. */ - startPage?: number, + startPage?: number; /** * Page layout. Default double page. */ - pageLayout?: 'double' | 'single', + pageLayout?: 'double' | 'single'; /** * Instruct the reader to auto flip. Default false. */ - autoflip?: boolean, + autoflip?: boolean; /** * Reader background color. Default empty. */ - backgroundColor?: string, + backgroundColor?: string; /** * Custom logo location. Default empty. */ - logoUrl?: string, + logoUrl?: string; /** * Custom background image location. Default empty. */ - backgroundImageUrl?: string, + backgroundImageUrl?: string; /** * How to display the background image. Default top-left. */ - backgroundImagePosition?: 'topLeft' | 'stretch', + backgroundImagePosition?: 'topLeft' | 'stretch'; /** * Whether to show the publisher's other publications. Default false. */ - showOtherPublications?: boolean, + showOtherPublications?: boolean; /** * Whether to hide the sharing options. Default false. */ - hideShare?: boolean, -}; -type GetPublicationFullscreenShareBySlugResult = URLResult; + hideShare?: boolean; +} +interface GetPublicationFullscreenShareBySlugResult extends URLResult {} -type GetPublicationReaderShareBySlugResult = URLResult; +interface GetPublicationReaderShareBySlugResult extends URLResult {} /** * Request to generate a QR code for the publication. Include fullscreenSettings if a QR code for a shareable fullscreen reader is desired. The returned URL is valid for 7 days. */ -type GetPublicationQRCodeShareBySlugRequest = { +interface GetPublicationQRCodeShareBySlugRequest { /** * The image format. Default PNG */ - format: ImageFormat, + format: ImageFormat; /** * Settings for the fullscreen share link */ - fullscreenSettings: GetPublicationFullscreenShareBySlugRequest, -}; -type GetPublicationQRCodeShareBySlugResult = { - qrCodeUrl: string, - pointedUrl: string -}; + fullscreenSettings: GetPublicationFullscreenShareBySlugRequest; +} +interface GetPublicationQRCodeShareBySlugResult { + qrCodeUrl: string; + pointedUrl: string; +} -type GetPublicationEmbedCodeBySlugRequest = { +interface GetPublicationEmbedCodeBySlugRequest { /** * Default true. */ - responsive?: boolean, + responsive?: boolean; /** * Default 100%. */ - width?: number | string, + width?: number | string; /** * Default 100%. */ - height?: number | string, + height?: number | string; /** * Default false. */ - hideIssuuLogo?: boolean, + hideIssuuLogo?: boolean; /** * Default false. */ - hideShareButton?: boolean, + hideShareButton?: boolean; /** * Default false. */ - showOtherPublications?: boolean, + showOtherPublications?: boolean; /** * Determines the background color (hex) of the embed. */ - bgColor?: string, + bgColor?: string; /** * Determines the background color (hex) of the fullscreen share. */ - fullScreenShareBgColor?: string, -}; -type GetPublicationEmbedCodeBySlugResult = { - embed: string, -}; + fullScreenShareBgColor?: string; +} +interface GetPublicationEmbedCodeBySlugResult { + embed: string; +} export type { GetPublicationBySlugResult, diff --git a/types/stack.d.ts b/types/stack.d.ts index 2ccf8ee..f957180 100644 --- a/types/stack.d.ts +++ b/types/stack.d.ts @@ -1,53 +1,53 @@ import { Link, StackAccessTypes } from "./common"; -type CreateNewStackRequest = { - accessType: StackAccessTypes, - description: string, - title: string -}; +interface CreateNewStackRequest { + accessType: StackAccessTypes; + description: string; + title: string; +} type CreateNewStackResponse = string; -type GetStackResponse = CreateNewStackRequest & { - id: string -}; +interface GetStackResponse extends CreateNewStackRequest { + id: string; +} -type UpdateStackRequest = { - accessType?: StackAccessTypes, - description?: string, - title?: string -}; -type UpdateStackResponse = GetStackResponse; +interface UpdateStackRequest { + accessType?: StackAccessTypes; + description?: string; + title?: string; +} +interface UpdateStackResponse extends GetStackResponse {} -type GetStackItemsRequest = { +interface GetStackItemsRequest { /** * Include unlisted stacks in the list of stacks. * @default true */ - includeUnlisted?: boolean, + includeUnlisted?: boolean; /** * Number of items to return per page. * @minimum 1 * @maximum 100 * @default 10 */ - size?: number, + size?: number; /** * Specifies the page number to return. * @minimum 1 * @default 1 */ - page?: number, -}; -type GetStackItemsResponse = { - results: string[], - count?: number, - pageSize: number, + page?: number; +} +interface GetStackItemsResponse { + results: string[]; + count?: number; + pageSize: number; links: { - next?: Link, - previous?: Link, - self?: Link, - }, -}; + next?: Link; + previous?: Link; + self?: Link; + }; +} export type { CreateNewStackRequest, diff --git a/types/user.d.ts b/types/user.d.ts index 2a111cf..e0fe22c 100644 --- a/types/user.d.ts +++ b/types/user.d.ts @@ -1,56 +1,56 @@ import { Limit, Link } from "./common"; -import { GetDraftBySlugResponse } from "./draft"; +import { Document } from "./document"; import { GetStackResponse } from "./stack"; -type GetMyPublicationsResult = { - results: GetDraftBySlugResponse[], +interface GetMyPublicationsResult { + results: Document[]; links: { - [key: string]: Link, - }, - pageSize: number, - count?: number, -}; + [key: string]: Link; + }; + pageSize: number; + count?: number; +} -type GetMyDraftsResult = GetMyPublicationsResult; +interface GetMyDraftsResult extends GetMyPublicationsResult {} -type GetMyStatsResult = { - averageTimeSpent: number, - clicks: number, - impressions: number, - reads: number, -}; +interface GetMyStatsResult { + averageTimeSpent: number; + clicks: number; + impressions: number; + reads: number; +} -type GetMyProfileResult = { - userId: number, - username: string, - displayName: string, - ownerId: number, - ownerName?: string, - isTeams: boolean, +interface GetMyProfileResult { + userId: number; + username: string; + displayName: string; + ownerId: number; + ownerName?: string; + isTeams: boolean; profileImages: { - large: string, - thumbnail: string, - [key: string]: string, - } -}; + large: string; + thumbnail: string; + [key: string]: string; + }; +} -type GetMyStacksResult = { +interface GetMyStacksResult { results: GetStackResponse[]; links: { - [key: string]: Link, - }, - pageSize: number, - count?: number, -}; + [key: string]: Link; + }; + pageSize: number; + count?: number; +} -type GetMyFeaturesResult = { - fullscreenShare: boolean, - download: boolean, - detectedLinks: boolean, - publishedDocumentLimitLeft: Limit, - unlistedDocumentLimitLeft: Limit, - sizeUploadLimitMb: Limit, - pageUploadLimit: Limit, +interface GetMyFeaturesResult { + fullscreenShare: boolean; + download: boolean; + detectedLinks: boolean; + publishedDocumentLimitLeft: Limit; + unlistedDocumentLimitLeft: Limit; + sizeUploadLimitMb: Limit; + pageUploadLimit: Limit; publishedDocumentLimit: Limit; unlistedDocumentLimit: Limit; };