Skip to content

Commit

Permalink
CCS-99643 Add max file size and file methods
Browse files Browse the repository at this point in the history
  • Loading branch information
Ivan Kudinov committed Jul 9, 2024
1 parent 4d0574e commit 246186d
Show file tree
Hide file tree
Showing 6 changed files with 91 additions and 15 deletions.
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "@expressms/smartapp-sdk",
"version": "1.8.2",
"version": "1.9.0-alpha.0",
"description": "Smartapp SDK",
"main": "build/main/index.js",
"typings": "build/main/index.d.ts",
Expand Down
11 changes: 7 additions & 4 deletions src/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,6 @@ import {
handleDeeplink,
openChatMessage,
openClientSettings,
openFile,
openGroupChat,
requestLocation,
searchCorporatePhonebook,
Expand All @@ -21,6 +20,7 @@ import {
subscribeClientEvents,
unsubscribeClientEvents,
} from './lib/client'
import { openFile, openFiles, uploadFile, uploadFiles } from './lib/client/file'
import {
addContact,
createPersonalChat,
Expand All @@ -30,9 +30,9 @@ import {
requestSelfProfile,
sendMessage,
} from './lib/contacts'
import {useQuery} from './lib/helpers/helpers'
import {ready} from './lib/logging'
import {onNotification} from './lib/notification'
import { useQuery } from './lib/helpers/helpers'
import { ready } from './lib/logging'
import { onNotification } from './lib/notification'
import {
closeSmartApp,
exitSmartAppToCatalog,
Expand All @@ -54,6 +54,9 @@ export {
sendMessage,
openSmartApp,
openFile,
openFiles,
uploadFile,
uploadFiles,
exitSmartAppToCatalog,
useQuery,
openClientSettings,
Expand Down
79 changes: 79 additions & 0 deletions src/lib/client/file.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,79 @@
import bridge from '@expressms/smartapp-bridge'
import {
ERROR_CODES,
File,
METHODS,
} from '../../types'

/**
* Download and open single file with client
* @param file File data to be opened
* @returns Promise that'll be fullfilled, otherwise rejected with reason
*/
const openFile = (file: File) => {
if (!bridge) return Promise.reject(ERROR_CODES.NO_BRIDGE)

return bridge.sendClientEvent({
method: METHODS.OPEN_FILE,
params: file,
})
}

/**
* Download file list with client
* @param files Files list to be opened
* @returns Promise that'll be fullfilled, otherwise rejected with reason
*/
const openFiles = (files: File[]) => {
if (!bridge) return Promise.reject(ERROR_CODES.NO_BRIDGE)

return bridge.sendClientEvent({
method: METHODS.OPEN_FILES,
params: files,
})
}



/**
* Upload single file with client
* @param mimeType Mime type of allowed files
* @param maxSize Max file size in bytes
* @returns Promise that'll be fullfilled with file metadata on success, otherwise rejected with reason
*/
const uploadFile = ({ mimeType, maxSize }: { mimeType: string, maxSize?: number }) => {
if (!bridge) return Promise.reject(ERROR_CODES.NO_BRIDGE)

return bridge.sendClientEvent({
method: METHODS.UPLOAD_FILE,
params: {
type: mimeType,
maxSize,
},
})
}

/**
* Upload files list with client
* @param mimeType Mime type of allowed files
* @param maxSize Max file size in bytes
* @returns Promise that'll be fullfilled with files metadata on success, otherwise rejected with reason
*/
const uploadFiles = ({ mimeType, maxSize }: { mimeType: string, maxSize?: number }) => {
if (!bridge) return Promise.reject(ERROR_CODES.NO_BRIDGE)

return bridge.sendClientEvent({
method: METHODS.UPLOAD_FILES,
params: {
type: mimeType,
maxSize,
},
})
}

export {
openFile,
openFiles,
uploadFile,
uploadFiles,
}
9 changes: 0 additions & 9 deletions src/lib/client/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,6 @@ import { EmitterEventPayload } from '@expressms/smartapp-bridge/build/main/types
import {
CreateDeeplinkResponse,
ERROR_CODES,
File,
GetConnectionStatusResponse,
GetLayoutTypeResponse,
GetUnreadCounterResponse,
Expand Down Expand Up @@ -43,13 +42,6 @@ const openGroupChat = ({ groupChatId }: { groupChatId: string }) => {
})
}

const openFile = (file: File) => {
return bridge?.sendClientEvent({
method: METHODS.OPEN_FILE,
params: file,
})
}

const sendBotCommand = ({
userHuid,
body,
Expand Down Expand Up @@ -199,7 +191,6 @@ const getLayoutType = async (): Promise<GetLayoutTypeResponse> => {
}

export {
openFile,
openClientSettings,
getChats,
searchCorporatePhonebook,
Expand Down
3 changes: 3 additions & 0 deletions src/types/bridge.ts
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,9 @@ export enum METHODS {
REQUEST_SELF_PROFILE = 'request_self_profile',
CLOSE_SMART_APP = 'close_smart_app',
OPEN_FILE = 'open_file',
OPEN_FILES = 'open_files',
UPLOAD_FILE = 'upload_file',
UPLOAD_FILES = 'upload_files',
SUBSCRIBE_CLIENT_EVENTS = 'subscribe_client_events',
UNSUBSCRIBE_CLIENT_EVENTS = 'unsubscribe_client_events',
GET_CONNECTION_STATUS = 'get_connection_status',
Expand Down
2 changes: 1 addition & 1 deletion src/types/client.ts
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,7 @@ export type CreateDeeplinkResponse = {
}
}

type LocalPhonebookEntry = {
export type LocalPhonebookEntry = {
avatar: string | null
name: string | null
contacts: {
Expand Down

0 comments on commit 246186d

Please sign in to comment.