From 07e7d0599b6226a19346ad20c6bee7511146b857 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 | 9 ++++++ .../api/standard/standard-api.ts | 2 ++ .../api/storage-api/storage-api.ts | 32 +++++++++++++++++++ 3 files changed, 43 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 d86bc85dd..48051e4d3 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,12 @@ 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'; +export { + StorageApiError, + StorageApiErrorCode, +} 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 0f8bab667..7e32d6473 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 000000000..e9777deff --- /dev/null +++ b/packages/ui-extensions/src/surfaces/point-of-sale/api/storage-api/storage-api.ts @@ -0,0 +1,32 @@ +export interface StorageApi { + storage: StorageApiContent; +} + +export enum StorageApiErrorCode { + DataSizeLimitExceeded = 'DATA_SIZE_LIMIT_EXCEEDED', +} +export class StorageApiError extends Error { + constructor(message: string, public code: StorageApiErrorCode) { + super(message); + this.name = 'StorageApiError'; + this.code = code; + } +} + +export interface StorageApiContent { + /** + * Get the value of a key from the storage + * @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 with code=StorageApiErrorCode.DataSizeLimitExceeded if the data size limit is exceeded + * @param key + * @param value + */ + set(key: string, value: string): Promise; +}