Skip to content

Commit

Permalink
Add UI Extensions StorageAPI
Browse files Browse the repository at this point in the history
  • Loading branch information
Alex-Palad committed Jun 28, 2024
1 parent 227af2b commit 07e7d05
Show file tree
Hide file tree
Showing 3 changed files with 43 additions and 0 deletions.
9 changes: 9 additions & 0 deletions packages/ui-extensions/src/surfaces/point-of-sale/api.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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';
Original file line number Diff line number Diff line change
Expand Up @@ -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<T> = {[key: string]: any} & {
extensionPoint: T;
Expand All @@ -12,4 +13,5 @@ export type StandardApi<T> = {[key: string]: any} & {
SessionApi &
ProductSearchApi &
DeviceApi &
StorageApi &
ConnectivityApi;
Original file line number Diff line number Diff line change
@@ -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<string | undefined>;

/**
* 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<void>;
}

0 comments on commit 07e7d05

Please sign in to comment.