Skip to content

Commit

Permalink
Merge pull request #678 from xmtp/rygine/node-sdk
Browse files Browse the repository at this point in the history
Upgrade Node SDK
  • Loading branch information
rygine authored Oct 11, 2024
2 parents ee9da40 + 5f02a9b commit 0683b16
Show file tree
Hide file tree
Showing 25 changed files with 76 additions and 40 deletions.
5 changes: 5 additions & 0 deletions .changeset/new-steaks-pull.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
---
"@xmtp/node-sdk": patch
---

Upgrade Node SDK
12 changes: 6 additions & 6 deletions .github/workflows/mls-client.yml
Original file line number Diff line number Diff line change
Expand Up @@ -7,8 +7,8 @@ on:

pull_request:
paths:
- "sdks/mls-client/**"
- ".github/workflows/mls-client.yml"
- "sdks/node-sdk/**"
- ".github/workflows/node-sdk.yml"
- "dev/**"
- ".node-version"
- ".nvmrc"
Expand All @@ -33,7 +33,7 @@ jobs:
- name: Install dependencies
run: yarn
- name: Typecheck
run: yarn turbo run typecheck --filter='./sdks/mls-client'
run: yarn turbo run typecheck --filter='./sdks/node-sdk'

lint:
name: Lint
Expand All @@ -51,7 +51,7 @@ jobs:
- name: Install dependencies
run: yarn
- name: Lint
run: yarn turbo run lint --filter='./sdks/mls-client'
run: yarn turbo run lint --filter='./sdks/node-sdk'

test:
name: Test
Expand All @@ -73,7 +73,7 @@ jobs:
- name: Sleep for 5 seconds
run: sleep 5s
- name: Run tests
run: yarn turbo run test --filter='./sdks/mls-client'
run: yarn turbo run test --filter='./sdks/node-sdk'

build:
name: Build
Expand All @@ -91,4 +91,4 @@ jobs:
- name: Install dependencies
run: yarn
- name: Build
run: yarn turbo run build --filter='./sdks/mls-client'
run: yarn turbo run build --filter='./sdks/node-sdk'
2 changes: 1 addition & 1 deletion .github/workflows/noop.yml
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ on:
- ".changeset/config.json"
- ".github/**"
- "!.github/workflows/js-sdk.yml"
- "!.github/workflows/mls-client.yml"
- "!.github/workflows/node-sdk.yml"
- "!.github/workflows/content-types.yml"
- ".vscode/**"
- ".yarn/**"
Expand Down
File renamed without changes.
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
# @xmtp/mls-client
# @xmtp/node-sdk

## 0.0.16

Expand Down
File renamed without changes.
File renamed without changes.
8 changes: 4 additions & 4 deletions sdks/mls-client/package.json → sdks/node-sdk/package.json
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
{
"name": "@xmtp/mls-client",
"name": "@xmtp/node-sdk",
"version": "0.0.16",
"description": "XMTP MLS client for interacting with XMTP networks",
"description": "XMTP Node client SDK for interacting with XMTP networks",
"keywords": [
"xmtp",
"messaging",
Expand All @@ -18,7 +18,7 @@
"repository": {
"type": "git",
"url": "git+https://[email protected]/xmtp/xmtp-js.git",
"directory": "packages/mls-client"
"directory": "packages/node-sdk"
},
"license": "MIT",
"author": "XMTP Labs <[email protected]>",
Expand Down Expand Up @@ -51,7 +51,7 @@
"dependencies": {
"@xmtp/content-type-primitives": "^1.0.1",
"@xmtp/content-type-text": "^1.0.0",
"@xmtp/mls-client-bindings-node": "^0.0.12",
"@xmtp/node-bindings": "^0.0.13",
"@xmtp/proto": "^3.62.1"
},
"devDependencies": {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ const external = [
"node:process",
"@xmtp/content-type-text",
"@xmtp/content-type-primitives",
"@xmtp/mls-client-bindings-node",
"@xmtp/node-bindings",
"@xmtp/proto",
"@xmtp/xmtp-js",
];
Expand Down
File renamed without changes.
39 changes: 28 additions & 11 deletions sdks/mls-client/src/Client.ts → sdks/node-sdk/src/Client.ts
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ import {
NapiSignatureRequestType,
type NapiClient,
type NapiMessage,
} from "@xmtp/mls-client-bindings-node";
} from "@xmtp/node-bindings";
import {
ContentTypeGroupUpdated,
GroupUpdatedCodec,
Expand Down 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,
);
}
}
Original file line number Diff line number Diff line change
@@ -1,9 +1,6 @@
import type { ContentTypeId } from "@xmtp/content-type-primitives";
import { ContentTypeText } from "@xmtp/content-type-text";
import type {
NapiGroup,
NapiListMessagesOptions,
} from "@xmtp/mls-client-bindings-node";
import type { NapiGroup, NapiListMessagesOptions } from "@xmtp/node-bindings";
import { AsyncStream, type StreamCallback } from "@/AsyncStream";
import type { Client } from "@/Client";
import { DecodedMessage } from "@/DecodedMessage";
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ import type {
NapiConversations,
NapiCreateGroupOptions,
NapiListMessagesOptions,
} from "@xmtp/mls-client-bindings-node";
} from "@xmtp/node-bindings";
import { AsyncStream, type StreamCallback } from "@/AsyncStream";
import type { Client } from "@/Client";
import { Conversation } from "@/Conversation";
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ import {
NapiDeliveryStatus,
NapiGroupMessageKind,
type NapiMessage,
} from "@xmtp/mls-client-bindings-node";
} from "@xmtp/node-bindings";
import type { Client } from "@/Client";
import { nsToDate } from "@/helpers/date";

Expand Down
File renamed without changes.
4 changes: 2 additions & 2 deletions sdks/mls-client/src/index.ts → 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 All @@ -14,4 +14,4 @@ export {
GroupUpdatedCodec,
} from "./codecs/GroupUpdatedCodec";
export type { StreamCallback } from "./AsyncStream";
export type * from "@xmtp/mls-client-bindings-node";
export type * from "@xmtp/node-bindings";
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(),
);
});
});
File renamed without changes.
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import { NapiGroupPermissionsOptions } from "@xmtp/mls-client-bindings-node";
import { NapiGroupPermissionsOptions } from "@xmtp/node-bindings";
import { describe, expect, it } from "vitest";
import { createRegisteredClient, createUser } from "@test/helpers";

Expand Down
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
14 changes: 7 additions & 7 deletions yarn.lock
Original file line number Diff line number Diff line change
Expand Up @@ -2697,16 +2697,16 @@ __metadata:
languageName: unknown
linkType: soft

"@xmtp/mls-client-bindings-node@npm:^0.0.12":
version: 0.0.12
resolution: "@xmtp/mls-client-bindings-node@npm:0.0.12"
checksum: 10/90d48198dc7419c3365a55a0227d6aafbe70580e7a5a5c240a40f500fbcbb939c88bc4280c2ec85e9ef046064507f2818ef124f0fa3449c82bedbd0fc308214e
"@xmtp/node-bindings@npm:^0.0.13":
version: 0.0.13
resolution: "@xmtp/node-bindings@npm:0.0.13"
checksum: 10/98c8a26cdc56c9b0dab794ca933a0be002bdf8d7e7ebdf1ad7ed33c015eeb7ffa5773185b077dd68e6f53509b12e30971a3963e611a8f42693fd11493fe4d802
languageName: node
linkType: hard

"@xmtp/mls-client@workspace:sdks/mls-client":
"@xmtp/node-sdk@workspace:sdks/node-sdk":
version: 0.0.0-use.local
resolution: "@xmtp/mls-client@workspace:sdks/mls-client"
resolution: "@xmtp/node-sdk@workspace:sdks/node-sdk"
dependencies:
"@rollup/plugin-json": "npm:^6.1.0"
"@rollup/plugin-typescript": "npm:^12.1.0"
Expand All @@ -2716,7 +2716,7 @@ __metadata:
"@vitest/coverage-v8": "npm:^2.1.2"
"@xmtp/content-type-primitives": "npm:^1.0.1"
"@xmtp/content-type-text": "npm:^1.0.0"
"@xmtp/mls-client-bindings-node": "npm:^0.0.12"
"@xmtp/node-bindings": "npm:^0.0.13"
"@xmtp/proto": "npm:^3.62.1"
"@xmtp/xmtp-js": "workspace:^"
eslint: "npm:^8.57.0"
Expand Down

0 comments on commit 0683b16

Please sign in to comment.