Add a Module API for accessing storage helper functions. (#34284)
* Add a Module API for accessing the Platform. * Drop overkill module test * drop unused sample file * fix import * Update module API * fix typo * fix typo again * and again * update api
This commit is contained in:
@@ -34,6 +34,7 @@ import { WidgetLifecycleApi } from "./WidgetLifecycleApi.ts";
|
||||
import { WidgetApi } from "./WidgetApi.ts";
|
||||
import { CustomisationsApi } from "./customisationsApi.ts";
|
||||
import { ComposerApi } from "./ComposerApi.ts";
|
||||
import { StorageHelperApi } from "./StorageHelperApi.ts";
|
||||
import { SettingsApi } from "./SettingsApi.ts";
|
||||
import defaultDispatcher from "../dispatcher/dispatcher.ts";
|
||||
|
||||
@@ -97,6 +98,7 @@ export class ModuleApi implements Api {
|
||||
public readonly client = new ClientApi();
|
||||
public readonly stores = new StoresApi();
|
||||
public readonly composer = new ComposerApi(defaultDispatcher);
|
||||
public readonly storageHelper = new StorageHelperApi();
|
||||
public readonly settings = new SettingsApi();
|
||||
|
||||
public createRoot(element: Element): Root {
|
||||
|
||||
@@ -0,0 +1,32 @@
|
||||
/*
|
||||
Copyright 2026 Element Creations Ltd.
|
||||
|
||||
SPDX-License-Identifier: AGPL-3.0-only OR GPL-3.0-only OR LicenseRef-Element-Commercial
|
||||
Please see LICENSE files in the repository root for full details.
|
||||
*/
|
||||
|
||||
// @vitest-environment happy-dom
|
||||
|
||||
import { describe, it, expect, vi } from "vitest";
|
||||
import { mockPlatformPeg } from "test-utils";
|
||||
|
||||
import { StorageHelperApi } from "./StorageHelperApi";
|
||||
|
||||
describe("StorageHelperApi", () => {
|
||||
it("should return the pickle key from the platform", async () => {
|
||||
const mockPlatform = mockPlatformPeg();
|
||||
vi.spyOn(mockPlatform, "getPickleKey").mockResolvedValue("test-pickle-key");
|
||||
|
||||
const api = new StorageHelperApi();
|
||||
await expect(api.getPickleKey("@alice:example.org", "DEVICE123")).resolves.toBe("test-pickle-key");
|
||||
expect(mockPlatform.getPickleKey).toHaveBeenCalledWith("@alice:example.org", "DEVICE123");
|
||||
});
|
||||
|
||||
it("should return null if the platform has no pickle key stored", async () => {
|
||||
const mockPlatform = mockPlatformPeg();
|
||||
vi.spyOn(mockPlatform, "getPickleKey").mockResolvedValue(null);
|
||||
|
||||
const api = new StorageHelperApi();
|
||||
await expect(api.getPickleKey("@alice:example.org", "DEVICE123")).resolves.toBeNull();
|
||||
});
|
||||
});
|
||||
@@ -0,0 +1,15 @@
|
||||
/*
|
||||
Copyright 2026 Element Creations Ltd.
|
||||
|
||||
SPDX-License-Identifier: AGPL-3.0-only OR GPL-3.0-only OR LicenseRef-Element-Commercial
|
||||
Please see LICENSE files in the repository root for full details.
|
||||
*/
|
||||
|
||||
import type { StorageHelperApi as IStorageHelperApi } from "@element-hq/element-web-module-api";
|
||||
import PlatformPeg from "../PlatformPeg";
|
||||
|
||||
export class StorageHelperApi implements IStorageHelperApi {
|
||||
public async getPickleKey(userId: string, deviceId: string): Promise<string | null> {
|
||||
return PlatformPeg.get()!.getPickleKey(userId, deviceId);
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user