Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add UI Extensions StorageAPI #2143

Draft
wants to merge 1 commit into
base: unstable
Choose a base branch
from
Draft
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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>;
}
Loading