Skip to content

Commit

Permalink
Fix FramedClient not retrieving custom supported image MIME types (#33)
Browse files Browse the repository at this point in the history
* Pass custom supported image types array from parent page to AMS

* Update CHANGELOG.md
  • Loading branch information
xTEddie committed Feb 14, 2023
1 parent b1291d8 commit 06ca67a
Show file tree
Hide file tree
Showing 3 changed files with 22 additions and 19 deletions.
2 changes: 2 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,8 @@
All notable changes to this project will be documented in this file.

## [Unreleased]
### Fixed
- Fix `FramedClient` not retrieving custom supported image MIME types

## [0.1.4] - 2023-02-09
### Added
Expand Down
31 changes: 16 additions & 15 deletions src/API.ts
Original file line number Diff line number Diff line change
Expand Up @@ -65,6 +65,22 @@ const createDefaultHeaders = (token: string): AMSHeaders => {
}
}

const defineSupportedImagesMimeTypes = (supportedImagesMimeTypes?: string[]) => {
return (supportedImagesMimeTypes && supportedImagesMimeTypes.length > 0) ?
supportedImagesMimeTypes :
defaultSupportedImagesMimeTypes;
}

const defineTypeForOperation = (fileType: string, apiOperation: string, supportedImagesMimeTypes?: string[]) => {
const mimeTypes = defineSupportedImagesMimeTypes(supportedImagesMimeTypes);

if (mimeTypes.includes(fileType.toLowerCase())) {
return apiOperation === AmsApiOperation.Create ? DocumentTypes.CreateImageType : DocumentTypes.UploadImageType;
}

return apiOperation === AmsApiOperation.Create ? DocumentTypes.CreateDocumentType : DocumentTypes.UploadDocumentType;
}

const skypeTokenAuth = async (chatToken: OmnichannelChatToken): Promise<Response> => {
GlobalConfiguration.debug && console.log(`[API][skypeTokenAuth]`);

Expand Down Expand Up @@ -94,21 +110,6 @@ const skypeTokenAuth = async (chatToken: OmnichannelChatToken): Promise<Response
}
}

const defineSupportedImagesMimeTypes = (supportedImagesMimeTypes?: string[]) => {
return (supportedImagesMimeTypes && supportedImagesMimeTypes.length > 0) ?
supportedImagesMimeTypes :
defaultSupportedImagesMimeTypes;
}

const defineTypeForOperation = (fileType: string, apiOperation: string, supportedImagesMimeTypes?: string[]) => {
const mimeTypes = defineSupportedImagesMimeTypes(supportedImagesMimeTypes);

if (mimeTypes.includes(fileType.toLowerCase())) {
return apiOperation === AmsApiOperation.Create ? DocumentTypes.CreateImageType : DocumentTypes.UploadImageType;
}
return apiOperation === AmsApiOperation.Create ? DocumentTypes.CreateDocumentType : DocumentTypes.UploadDocumentType;
}

const createObject = async (id: string, file: File, chatToken: OmnichannelChatToken, supportedImagesMimeTypes?: string[]): Promise<AMSCreateObjectResponse> => {
GlobalConfiguration.debug && console.log(`[API][createObject]`);

Expand Down
8 changes: 4 additions & 4 deletions src/IframeCommunicator.ts
Original file line number Diff line number Diff line change
Expand Up @@ -126,7 +126,7 @@ class IframeCommunicator {
});

try {
const response = await API.createObject(data.id, data.file, data.chatToken);
const response = await API.createObject(data.id, data.file, data.chatToken, data.supportedImagesMimeTypes);
const postMessageData = {
requestId: data.requestId,
eventType: PostMessageEventType.Response,
Expand Down Expand Up @@ -165,7 +165,7 @@ class IframeCommunicator {
});

try {
const response = await API.uploadDocument(data.documentId, data.file, data.chatToken);
const response = await API.uploadDocument(data.documentId, data.file, data.chatToken, data.supportedImagesMimeTypes);
const postMessageData = {
requestId: data.requestId,
eventType: PostMessageEventType.Response,
Expand Down Expand Up @@ -206,7 +206,7 @@ class IframeCommunicator {
});

try {
const response = await API.getViewStatus(data.fileMetadata, data.chatToken);
const response = await API.getViewStatus(data.fileMetadata, data.chatToken, data.supportedImagesMimeTypes);
const postMessageData = {
requestId: data.requestId,
eventType: PostMessageEventType.Response,
Expand Down Expand Up @@ -247,7 +247,7 @@ class IframeCommunicator {
});

try {
const response = await API.getView(data.fileMetadata, data.viewLocation, data.chatToken);
const response = await API.getView(data.fileMetadata, data.viewLocation, data.chatToken, data.supportedImagesMimeTypes);
const postMessageData = {
requestId: data.requestId,
eventType: PostMessageEventType.Response,
Expand Down

0 comments on commit 06ca67a

Please sign in to comment.