this repo has no description
at main 44 lines 1.6 kB view raw
1/** 2 * `AppStoreKit` `Storage` implementation for the "web" client 3 * 4 * Note: The `AppStoreKit` `Storage` interface is declared as a global, which has the (presumably 5 * accidental) side-effect of implicitly being merged with the DOM library's own `Storage` interface 6 * (like `localStorage`), since interfaces declared in the same scope are merged together by TypeScript. 7 * There's no way to tell TypeScript that we only care about the `AppStoreKit` part of it, so 8 * satifying TypeScript here means that we need to implement both interfaces. 9 */ 10export class WebStorage extends Map<string, string> implements Storage { 11 /* == "DOM" `Storage` Interface == */ 12 13 get length() { 14 return this.size; 15 } 16 17 getItem(key: string): string | null { 18 return this.get(key) ?? null; 19 } 20 21 key(_index: number): string | null { 22 throw new Error('Method not implemented.'); 23 } 24 25 removeItem(key: string): void { 26 this.delete(key); 27 } 28 29 setItem(key: string, value: string): void { 30 this.set(key, value); 31 } 32 33 /* == AppStoreKit `Storage` Interface == */ 34 35 storeString(aString: string, key: string): void { 36 this.set(key, aString); 37 } 38 39 retrieveString(key: string): string { 40 // Fallback value designed based on how the ObjectGraph `StorageWrapper` handles that specific value 41 // https://github.pie.apple.com/app-store/ios-appstore-app/blob/1761d575b8dc3d7a63e7e36f3320cf9245be9f37/src/foundation/wrappers/storage.ts#L13 42 return this.get(key) ?? '<null>'; 43 } 44}