Skip to content

Commit

Permalink
Add inboxStateFromInboxIds and logging to client
Browse files Browse the repository at this point in the history
  • Loading branch information
rygine committed Oct 11, 2024
1 parent e0fbc33 commit 71b8d10
Show file tree
Hide file tree
Showing 4 changed files with 46 additions and 12 deletions.
37 changes: 27 additions & 10 deletions sdks/node-sdk/src/Client.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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
*/
Expand All @@ -71,10 +65,21 @@ export type ContentOptions = {
codecs?: ContentCodec<any>[];
};

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;
Expand Down Expand Up @@ -107,6 +112,8 @@ export class Client {
inboxId,
accountAddress,
options?.encryptionKey,
options?.requestHistorySync,
options?.logging ?? "off",
),
[new GroupUpdatedCodec(), new TextCodec(), ...(options?.codecs ?? [])],
);
Expand Down Expand Up @@ -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,
);
}
}
2 changes: 1 addition & 1 deletion sdks/node-sdk/src/index.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
export type {
ClientOptions,
EncryptionOptions,
OtherOptions,
NetworkOptions,
StorageOptions,
XmtpEnv,
Expand Down
17 changes: 17 additions & 0 deletions sdks/node-sdk/test/Client.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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(),
);
});
});
2 changes: 1 addition & 1 deletion sdks/node-sdk/vitest.config.ts
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
/// <reference types="vitest" />
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({
Expand Down

0 comments on commit 71b8d10

Please sign in to comment.