From d27a7fa8d6e9ca1bc8bb594b547d8948c2e32ddc Mon Sep 17 00:00:00 2001 From: Alex-Palad Date: Fri, 28 Jun 2024 13:35:28 -0400 Subject: [PATCH] Add UI Extensions StorageAPI --- .../src/surfaces/point-of-sale/api.ts | 5 ++++ .../api/standard/standard-api.ts | 2 ++ .../api/storage-api/storage-api.ts | 23 +++++++++++++++++++ 3 files changed, 30 insertions(+) create mode 100644 packages/ui-extensions/src/surfaces/point-of-sale/api/storage-api/storage-api.ts diff --git a/packages/ui-extensions/src/surfaces/point-of-sale/api.ts b/packages/ui-extensions/src/surfaces/point-of-sale/api.ts index d86bc85dd1..83ba067528 100644 --- a/packages/ui-extensions/src/surfaces/point-of-sale/api.ts +++ b/packages/ui-extensions/src/surfaces/point-of-sale/api.ts @@ -100,3 +100,8 @@ export type { export type {CountryCode} from './api/types/country-code'; export type {Session} from './api/types/session'; + +export type { + StorageApi, + StorageApiContent, +} from './api/storage-api/storage-api'; diff --git a/packages/ui-extensions/src/surfaces/point-of-sale/api/standard/standard-api.ts b/packages/ui-extensions/src/surfaces/point-of-sale/api/standard/standard-api.ts index 0f8bab667c..7e32d64738 100644 --- a/packages/ui-extensions/src/surfaces/point-of-sale/api/standard/standard-api.ts +++ b/packages/ui-extensions/src/surfaces/point-of-sale/api/standard/standard-api.ts @@ -4,6 +4,7 @@ import type {LocaleApi} from '../locale-api/locale-api'; import type {SessionApi} from '../session-api/session-api'; import type {ToastApi} from '../toast-api/toast-api'; import type {ProductSearchApi} from '../product-search-api/product-search-api'; +import {StorageApi} from '../storage-api/storage-api'; export type StandardApi = {[key: string]: any} & { extensionPoint: T; @@ -12,4 +13,5 @@ export type StandardApi = {[key: string]: any} & { SessionApi & ProductSearchApi & DeviceApi & + StorageApi & ConnectivityApi; diff --git a/packages/ui-extensions/src/surfaces/point-of-sale/api/storage-api/storage-api.ts b/packages/ui-extensions/src/surfaces/point-of-sale/api/storage-api/storage-api.ts new file mode 100644 index 0000000000..1198e816e9 --- /dev/null +++ b/packages/ui-extensions/src/surfaces/point-of-sale/api/storage-api/storage-api.ts @@ -0,0 +1,23 @@ +export interface StorageApi { + storage: StorageApiContent; +} + +export interface StorageApiContent { + /** + * Get the value of a key from the storage + * @throws Error if the storage operation fails + * @param key + * @returns the value of the key or undefined if the key does not exist + */ + get(key: string): Promise; + + /** + * Set the value of a key in the storage + * Value must be encoded as a string + * @throws StorageApiError if the data size limit is exceeded + * @throws Error if the storage operation fails + * @param key + * @param value + */ + set(key: string, value: string): Promise; +}