diff --git a/package.json b/package.json index e7a71cc..8fccad1 100644 --- a/package.json +++ b/package.json @@ -1,6 +1,6 @@ { "name": "@issuu/issuu-api-sdk", - "version": "0.0.19", + "version": "0.0.20", "type": "module", "license": "MIT", "scripts": { diff --git a/src/controllers/draft.controller.ts b/src/controllers/draft.controller.ts index a74c642..3cfdae6 100644 --- a/src/controllers/draft.controller.ts +++ b/src/controllers/draft.controller.ts @@ -269,19 +269,19 @@ export const draft = { abortController?: AbortController, ): Promise { - let savedDraft: CreateNewDraftResponse | UpdateDraftBySlugResponse, result: PublishDraftBySlugResponse, isAborted = false; + let savedDraft: CreateNewDraftResponse | UpdateDraftBySlugResponse, result: PublishDraftBySlugResponse, isAborted = false, isPublished = false; progressCallback?.(0); // setup abort controller if(abortController) { abortController.signal.addEventListener('abort', async () => { if(!savedDraft) return; - else if(savedDraft && !result) { + else if(savedDraft && !isPublished) { if (!!options?.shouldDeleteOnAbort && !!savedDraft.slug) { await this.deleteDraftBySlug(savedDraft.slug, abortController); } isAborted = true; - } else if(savedDraft && result) { + } else if(savedDraft && isPublished) { if (!!options?.shouldDeleteOnAbort && !!result.slug) { await publication.deletePublicationBySlug(result.slug, abortController); } @@ -298,6 +298,10 @@ export const draft = { } progressCallback?.(20); + if (savedDraft.state === 'PUBLISHED') { + isPublished = true; + } + // Until 70% if(isAborted) return progressCallback?.(100); await this.uploadDocumentToDraftBySlug( @@ -329,6 +333,7 @@ export const draft = { options, abortController ); + isPublished = true; // Until 100% progressCallback?.(100); diff --git a/types/draft.d.ts b/types/draft.d.ts index 0c4bf6c..6c552e9 100644 --- a/types/draft.d.ts +++ b/types/draft.d.ts @@ -36,7 +36,7 @@ interface UpdateDraftBySlugRequest { fileUrl?: string; info?: DocumentInformation; } -interface UpdateDraftBySlugResponse extends CreateNewDraftResponse {}; +interface UpdateDraftBySlugResponse extends Document {}; interface UploadDocumentToDraftBySlugRequest { file: Blob;