From 71b8d1078871399341ce95102ba942c54abf50fd Mon Sep 17 00:00:00 2001 From: Ry Racherbaumer Date: Fri, 11 Oct 2024 14:59:56 -0500 Subject: [PATCH] Add inboxStateFromInboxIds and logging to client --- sdks/node-sdk/src/Client.ts | 37 ++++++++++++++++++++++--------- sdks/node-sdk/src/index.ts | 2 +- sdks/node-sdk/test/Client.test.ts | 17 ++++++++++++++ sdks/node-sdk/vitest.config.ts | 2 +- 4 files changed, 46 insertions(+), 12 deletions(-) diff --git a/sdks/node-sdk/src/Client.ts b/sdks/node-sdk/src/Client.ts index 3b83a2a72..9699be569 100644 --- a/sdks/node-sdk/src/Client.ts +++ b/sdks/node-sdk/src/Client.ts @@ -45,19 +45,13 @@ export type NetworkOptions = { }; /** - * Encryption options + * Storage options */ -export type EncryptionOptions = { +export type StorageOptions = { /** * Encryption key to use for the local DB */ encryptionKey?: Uint8Array | null; -}; - -/** - * Storage options - */ -export type StorageOptions = { /** * Path to the local DB */ @@ -71,10 +65,21 @@ export type ContentOptions = { codecs?: ContentCodec[]; }; +export type OtherOptions = { + /** + * Optionally set the request history sync URL + */ + requestHistorySync?: string; + /** + * Optionally set the logging level (default: 'off') + */ + logging?: "debug" | "info" | "warn" | "error" | "off"; +}; + export type ClientOptions = NetworkOptions & - EncryptionOptions & StorageOptions & - ContentOptions; + ContentOptions & + OtherOptions; export class Client { #innerClient: NapiClient; @@ -107,6 +112,8 @@ export class Client { inboxId, accountAddress, options?.encryptionKey, + options?.requestHistorySync, + options?.logging ?? "off", ), [new GroupUpdatedCodec(), new TextCodec(), ...(options?.codecs ?? [])], ); @@ -201,4 +208,14 @@ export class Client { async inboxState(refreshFromNetwork: boolean = false) { return this.#innerClient.inboxState(refreshFromNetwork); } + + async inboxStateFromInboxIds( + inboxIds: string[], + refreshFromNetwork?: boolean, + ) { + return this.#innerClient.addressesFromInboxId( + refreshFromNetwork ?? false, + inboxIds, + ); + } } diff --git a/sdks/node-sdk/src/index.ts b/sdks/node-sdk/src/index.ts index 09ca1b8af..1093c0bf1 100644 --- a/sdks/node-sdk/src/index.ts +++ b/sdks/node-sdk/src/index.ts @@ -1,6 +1,6 @@ export type { ClientOptions, - EncryptionOptions, + OtherOptions, NetworkOptions, StorageOptions, XmtpEnv, diff --git a/sdks/node-sdk/test/Client.test.ts b/sdks/node-sdk/test/Client.test.ts index 8eb61b85e..9a7be644d 100644 --- a/sdks/node-sdk/test/Client.test.ts +++ b/sdks/node-sdk/test/Client.test.ts @@ -47,4 +47,21 @@ describe("Client", () => { ]); expect(inboxState.recoveryAddress).toBe(user.account.address.toLowerCase()); }); + + it("should get inbox states from inbox IDs", async () => { + const user = createUser(); + const client = await createRegisteredClient(user); + const inboxStates = await client.inboxStateFromInboxIds([client.inboxId]); + expect(inboxStates.length).toBe(1); + expect(inboxStates[0].inboxId).toBe(client.inboxId); + expect(inboxStates[0].installations.map((install) => install.id)).toEqual([ + client.installationId, + ]); + expect(inboxStates[0].accountAddresses).toEqual([ + user.account.address.toLowerCase(), + ]); + expect(inboxStates[0].recoveryAddress).toBe( + user.account.address.toLowerCase(), + ); + }); }); diff --git a/sdks/node-sdk/vitest.config.ts b/sdks/node-sdk/vitest.config.ts index 34aab3ef7..d6b1e8b9b 100644 --- a/sdks/node-sdk/vitest.config.ts +++ b/sdks/node-sdk/vitest.config.ts @@ -1,7 +1,7 @@ /// import { defineConfig, mergeConfig } from "vite"; import tsconfigPaths from "vite-tsconfig-paths"; -import { defineConfig as defineVitestConfig } from "vitest/config.js"; +import { defineConfig as defineVitestConfig } from "vitest/config"; // https://vitejs.dev/config/ const viteConfig = defineConfig({