Skip to content

Commit 93815b4

Browse files
authored
Merge pull request #2945 from Shopify/compliance/update-StorageError-interface
Convert Refactor StorageError into Interface
2 parents e437dc9 + 8d99f44 commit 93815b4

File tree

3 files changed

+15
-10
lines changed

3 files changed

+15
-10
lines changed

.changeset/fair-news-dance.md

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
---
2+
'@shopify/ui-extensions': patch
3+
---
4+
5+
Update StorageError interface

packages/ui-extensions/src/surfaces/point-of-sale/api.ts

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -126,5 +126,4 @@ export type {
126126
export type {CountryCode} from './types/country-code';
127127

128128
export type {Session} from './types/session';
129-
export type {Storage} from './types/storage';
130-
export {StorageError} from './types/storage';
129+
export type {Storage, StorageError} from './types/storage';

packages/ui-extensions/src/surfaces/point-of-sale/types/storage.ts

Lines changed: 9 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -1,12 +1,8 @@
1-
export class StorageError extends Error {
2-
public name = 'StorageError';
3-
constructor(
4-
public code: 'RecordsCount' | 'RecordSize' | 'KeyType' | 'KeySize',
5-
message: string,
6-
) {
7-
super(message);
8-
}
1+
export interface StorageError extends Error {
2+
name: 'StorageError';
3+
code: 'RecordsCount' | 'RecordSize' | 'KeyType' | 'KeySize';
94
}
5+
106
export interface Storage<
117
BaseStorageTypes extends Record<string, any> = Record<string, unknown>,
128
> {
@@ -16,6 +12,7 @@ export interface Storage<
1612
* @param key - The key to set the value for.
1713
* @param value - The value to set for the key.
1814
* Can be any primitive type supported by `JSON.stringify`.
15+
* @throws Error when the API version is lower than 2025-04.
1916
* @throws StorageError when:
2017
* the extension exceeds its allotted storage limit.
2118
* the value exceeds its allotted storage limit.
@@ -35,6 +32,7 @@ export interface Storage<
3532
* @param key - The key to get the value for.
3633
* @returns The value of the key.
3734
* If no value for the key exists, the resolved value is undefined.
35+
* @throws Error when the API version is lower than 2025-04.
3836
* @throws StorageError when the key is not a string or exceeds its allotted size.
3937
*/
4038
get<
@@ -46,12 +44,14 @@ export interface Storage<
4644

4745
/**
4846
* Clears the storage.
47+
* @throws Error when the API version is lower than 2025-04.
4948
*/
5049
clear: () => Promise<void>;
5150

5251
/**
5352
* Deletes a key from the storage.
5453
*
54+
* @throws Error when the API version is lower than 2025-04.
5555
* @param key - The key to delete.
5656
*/
5757
delete<
@@ -64,6 +64,7 @@ export interface Storage<
6464
/**
6565
* Gets all the keys and values in the storage.
6666
*
67+
* @throws Error when the API version is lower than 2025-04.
6768
* @returns An array containing all the keys and values in the storage.
6869
*/
6970
entries<

0 commit comments

Comments
 (0)