Skip to content

Commit

Permalink
Refactor types 2 interfaces (#11)
Browse files Browse the repository at this point in the history
* REFACTOR: reorganise types and interfaces and fix some exports

* FIX: @Sleepyblue suggestions
  • Loading branch information
augustovicente authored May 15, 2024
1 parent 579bab2 commit fd9fde1
Show file tree
Hide file tree
Showing 8 changed files with 252 additions and 265 deletions.
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "@issuu/issuu-api-sdk",
"version": "0.0.9",
"version": "0.0.10",
"type": "module",
"license": "MIT",
"scripts": {
Expand Down
9 changes: 7 additions & 2 deletions types/common.d.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand All @@ -26,8 +30,9 @@ export type {
DraftConversionStatus,
PublishValidateError,
StackAccessTypes,
DraftStatus,
DocumentStatus,
CoverAsset,
ImageFormat,
Limit,
URLResult,
};
84 changes: 84 additions & 0 deletions types/document.d.ts
Original file line number Diff line number Diff line change
@@ -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,
};
131 changes: 30 additions & 101 deletions types/draft.d.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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/<username>/docs/<desiredName> 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 };

Expand All @@ -149,6 +80,4 @@ export type {
UploadDocumentToDraftBySlugRequest,
CreateAndPublishDraftResponse,
PublishValidateError,
Access as DraftAccess,
DocumentInformation as DraftInformation,
};
2 changes: 2 additions & 0 deletions types/index.d.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,3 +2,5 @@ export * from './draft';
export * from './publication';
export * from './user';
export * from './stack';
export * from './document';
export * from './common';
Loading

0 comments on commit fd9fde1

Please sign in to comment.