-
Notifications
You must be signed in to change notification settings - Fork 1
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Ivan Kudinov
committed
Jan 17, 2024
1 parent
0406b7b
commit 2012007
Showing
9 changed files
with
115 additions
and
658 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,68 @@ | ||
import bridge from '@expressms/smartapp-bridge' | ||
import { ClientStorageGetResponse, ERROR_CODES, METHODS, StatusResponse, StorageValueType } from '../../types' | ||
|
||
/** | ||
* Get value for key from client storage | ||
* @param key Key | ||
* @returns Promise that'll be fullfilled with `payload.value` on success, otherwise rejected with reason | ||
*/ | ||
const clientStorageGet = ({ key }: { key: string }): Promise<ClientStorageGetResponse> => { | ||
if (!bridge) return Promise.reject(ERROR_CODES.NO_BRIDGE) | ||
|
||
return bridge | ||
.sendClientEvent({ | ||
method: METHODS.CLIENT_STORAGE_GET, | ||
params: { key }, | ||
}) | ||
.then(event => event as ClientStorageGetResponse) | ||
} | ||
|
||
/** | ||
* Save value in client storage | ||
* @param key Key | ||
* @param value Data to be stored | ||
* @returns Promise that'll be fullfilled on success or rejected with reason | ||
*/ | ||
const clientStorageSet = ({ key, value }: { key: string; value: StorageValueType }): Promise<StatusResponse> => { | ||
if (!bridge) return Promise.reject(ERROR_CODES.NO_BRIDGE) | ||
|
||
return bridge | ||
.sendClientEvent({ | ||
method: METHODS.CLIENT_STORAGE_SET, | ||
params: { key, value }, | ||
}) | ||
.then(event => event as StatusResponse) | ||
} | ||
|
||
/** | ||
* Remove record from client storage | ||
* @param key Key | ||
* @returns Promise that'll be fullfilled on success or rejected with reason | ||
*/ | ||
const clientStorageRemove = ({ key }: { key: string }): Promise<StatusResponse> => { | ||
if (!bridge) return Promise.reject(ERROR_CODES.NO_BRIDGE) | ||
|
||
return bridge | ||
.sendClientEvent({ | ||
method: METHODS.CLIENT_STORAGE_REMOVE, | ||
params: { key }, | ||
}) | ||
.then(event => event as StatusResponse) | ||
} | ||
|
||
/** | ||
* Clear all records from client storage | ||
* @returns Promise that'll be fullfilled on success or rejected with reason | ||
*/ | ||
const clientStorageClear = (): Promise<StatusResponse> => { | ||
if (!bridge) return Promise.reject(ERROR_CODES.NO_BRIDGE) | ||
|
||
return bridge | ||
.sendClientEvent({ | ||
method: METHODS.CLIENT_STORAGE_CLEAR, | ||
params: {}, | ||
}) | ||
.then(event => event as StatusResponse) | ||
} | ||
|
||
export { clientStorageGet, clientStorageSet, clientStorageRemove, clientStorageClear } |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,19 @@ | ||
import { EmitterEventPayload } from '@expressms/smartapp-bridge/build/main/types/eventEmitter' | ||
import { STATUS } from './bridge' | ||
|
||
export enum CLIENT_STORAGE_ERROR_CODES { | ||
keyNotFound = 'key_not_found', | ||
valueSizeExceeded = 'value_size_exceeded', | ||
storageLimitReached = 'storage_limit_reached', | ||
} | ||
|
||
export type StorageValueType = string | number | null | object | boolean | [] | ||
export type StorageErrorType = CLIENT_STORAGE_ERROR_CODES | null | ||
|
||
export interface ClientStorageGetResponse extends EmitterEventPayload { | ||
payload: { | ||
status: STATUS, | ||
errorCode?: string | null, | ||
value: StorageValueType | ||
} | ||
} |