Skip to content

Commit

Permalink
Merge pull request #688 from xmtp/rygine/ct-group-updated
Browse files Browse the repository at this point in the history
Add content-type-group-updated
  • Loading branch information
rygine authored Oct 21, 2024
2 parents c34654f + 9186777 commit 6ad0e5b
Show file tree
Hide file tree
Showing 9 changed files with 300 additions and 1 deletion.
21 changes: 21 additions & 0 deletions content-types/content-type-group-updated/LICENSE
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
MIT License

Copyright (c) 2024 XMTP (xmtp.org)

Permission is hereby granted, free of charge, to any person obtaining a copy
of this software and associated documentation files (the "Software"), to deal
in the Software without restriction, including without limitation the rights
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
copies of the Software, and to permit persons to whom the Software is
furnished to do so, subject to the following conditions:

The above copyright notice and this permission notice shall be included in all
copies or substantial portions of the Software.

THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
SOFTWARE.
39 changes: 39 additions & 0 deletions content-types/content-type-group-updated/README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,39 @@
# Group updated content type

This package provides an XMTP content type to support group updated messages.

## Install the package

```bash
# npm
npm i @xmtp/content-type-group-updated

# yarn
yarn add @xmtp/content-type-group-updated

# pnpm
pnpm i @xmtp/content-type-group-updated
```

## Notes

This content type is included by default in official XMTP SDKs.

## Developing

Run `yarn dev` to build the content type and watch for changes, which will trigger a rebuild.

## Testing

Before running unit tests, start the required Docker container at the root of this repository. For more info, see [Running tests](../../README.md#running-tests).

## Useful commands

- `yarn build`: Builds the content type
- `yarn clean`: Removes `node_modules`, `dist`, and `.turbo` folders
- `yarn dev`: Builds the content type and watches for changes, which will trigger a rebuild
- `yarn lint`: Runs ESLint
- `yarn test:setup`: Starts a necessary docker container for testing
- `yarn test:teardown`: Stops docker container for testing
- `yarn test`: Runs all unit tests
- `yarn typecheck`: Runs `tsc`
89 changes: 89 additions & 0 deletions content-types/content-type-group-updated/package.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,89 @@
{
"name": "@xmtp/content-type-group-updated",
"version": "1.0.0",
"description": "An XMTP content type to support group updated messages",
"keywords": [
"xmtp",
"messaging",
"web3",
"js",
"ts",
"javascript",
"typescript",
"content-types"
],
"homepage": "https://github.com/xmtp/xmtp-js",
"bugs": {
"url": "https://github.com/xmtp/xmtp-js/issues"
},
"repository": {
"type": "git",
"url": "git+ssh://[email protected]/xmtp/xmtp-js.git",
"directory": "content-types/content-type-group-updated"
},
"license": "MIT",
"author": "XMTP Labs <[email protected]>",
"sideEffects": false,
"type": "module",
"exports": {
".": {
"types": "./dist/index.d.ts",
"browser": "./dist/browser/index.js",
"import": "./dist/index.js",
"require": "./dist/index.cjs"
}
},
"main": "dist/index.cjs",
"module": "dist/index.js",
"browser": "dist/browser/index.js",
"types": "dist/index.d.ts",
"files": [
"dist"
],
"scripts": {
"build": "yarn clean:dist && yarn rollup -c",
"clean": "yarn clean:dist && rimraf .turbo node_modules",
"clean:dist": "rimraf dist",
"dev": "yarn clean:dist && yarn rollup -c --watch",
"test": "yarn test:node && yarn test:jsdom",
"test:jsdom": "NODE_TLS_REJECT_UNAUTHORIZED=0 vitest run --environment happy-dom",
"test:node": "NODE_TLS_REJECT_UNAUTHORIZED=0 vitest run --environment node",
"typecheck": "tsc --noEmit"
},
"browserslist": {
"production": [
">0.2%",
"not dead",
"not op_mini all"
],
"development": [
"last 3 chrome versions",
"last 3 firefox versions",
"last 3 safari versions"
]
},
"dependencies": {
"@xmtp/content-type-primitives": "^1.0.1",
"@xmtp/proto": "^3.71.0"
},
"devDependencies": {
"@rollup/plugin-terser": "^0.4.4",
"@rollup/plugin-typescript": "^12.1.1",
"@types/node": "^20.16.12",
"buffer": "^6.0.3",
"ethers": "^6.11.1",
"happy-dom": "^15.7.4",
"rimraf": "^6.0.1",
"rollup": "^4.24.0",
"rollup-plugin-dts": "^6.1.1",
"rollup-plugin-filesize": "^10.0.0",
"typescript": "^5.6.3",
"vite": "^5.4.9",
"vitest": "^2.1.3"
},
"publishConfig": {
"access": "public",
"provenance": true,
"registry": "https://registry.npmjs.org/"
}
}
58 changes: 58 additions & 0 deletions content-types/content-type-group-updated/rollup.config.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,58 @@
import terser from "@rollup/plugin-terser";
import typescript from "@rollup/plugin-typescript";
import { defineConfig } from "rollup";
import { dts } from "rollup-plugin-dts";
import filesize from "rollup-plugin-filesize";

const plugins = [
typescript({
declaration: false,
declarationMap: false,
}),
filesize({
showMinifiedSize: false,
}),
];

const external = ["@xmtp/content-type-primitives", "@xmtp/proto"];

export default defineConfig([
{
input: "src/index.ts",
output: {
file: "dist/index.js",
format: "es",
sourcemap: true,
},
plugins,
external,
},
{
input: "src/index.ts",
output: {
file: "dist/browser/index.js",
format: "es",
sourcemap: true,
},
plugins: [...plugins, terser()],
external,
},
{
input: "src/index.ts",
output: {
file: "dist/index.cjs",
format: "cjs",
sourcemap: true,
},
plugins,
external,
},
{
input: "src/index.ts",
output: {
file: "dist/index.d.ts",
format: "es",
},
plugins: [dts()],
},
]);
22 changes: 22 additions & 0 deletions content-types/content-type-group-updated/src/GroupUpdated.test.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
import { describe, expect, it } from "vitest";
import {
ContentTypeGroupUpdated,
GroupUpdatedCodec,
type GroupUpdated,
} from "./GroupUpdated";

describe("ContentTypeGroupUpdated", () => {
it("can encode/decode group updated data", () => {
const groupUpdated: GroupUpdated = {
initiatedByInboxId: "inbox-id",
addedInboxes: [],
removedInboxes: [],
metadataFieldChanges: [],
};
const codec = new GroupUpdatedCodec();
const ec = codec.encode(groupUpdated);
expect(ec.type.sameAs(ContentTypeGroupUpdated)).toBe(true);
const groupUpdated2 = codec.decode(ec);
expect(groupUpdated2).toEqual(groupUpdated);
});
});
43 changes: 43 additions & 0 deletions content-types/content-type-group-updated/src/GroupUpdated.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,43 @@
import {
ContentTypeId,
type ContentCodec,
type EncodedContent,
} from "@xmtp/content-type-primitives";
import { mlsTranscriptMessages } from "@xmtp/proto";

export const ContentTypeGroupUpdated = new ContentTypeId({
authorityId: "xmtp.org",
typeId: "group_updated",
versionMajor: 1,
versionMinor: 0,
});

export type GroupUpdated = mlsTranscriptMessages.GroupUpdated;

export class GroupUpdatedCodec
implements ContentCodec<GroupUpdated, Record<string, never>>
{
get contentType(): ContentTypeId {
return ContentTypeGroupUpdated;
}

encode(content: GroupUpdated) {
return {
type: this.contentType,
parameters: {},
content: mlsTranscriptMessages.GroupUpdated.encode(content).finish(),
};
}

decode(content: EncodedContent) {
return mlsTranscriptMessages.GroupUpdated.decode(content.content);
}

fallback(): undefined {
return undefined;
}

shouldPush() {
return false;
}
}
1 change: 1 addition & 0 deletions content-types/content-type-group-updated/src/index.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
export * from "./GroupUpdated";
4 changes: 4 additions & 0 deletions content-types/content-type-group-updated/tsconfig.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
{
"extends": "tsconfig/build.json",
"include": ["src", "rollup.config.js"]
}
24 changes: 23 additions & 1 deletion yarn.lock
Original file line number Diff line number Diff line change
Expand Up @@ -2563,6 +2563,28 @@ __metadata:
languageName: unknown
linkType: soft

"@xmtp/content-type-group-updated@workspace:content-types/content-type-group-updated":
version: 0.0.0-use.local
resolution: "@xmtp/content-type-group-updated@workspace:content-types/content-type-group-updated"
dependencies:
"@rollup/plugin-terser": "npm:^0.4.4"
"@rollup/plugin-typescript": "npm:^12.1.1"
"@types/node": "npm:^20.16.12"
"@xmtp/content-type-primitives": "npm:^1.0.1"
"@xmtp/proto": "npm:^3.71.0"
buffer: "npm:^6.0.3"
ethers: "npm:^6.11.1"
happy-dom: "npm:^15.7.4"
rimraf: "npm:^6.0.1"
rollup: "npm:^4.24.0"
rollup-plugin-dts: "npm:^6.1.1"
rollup-plugin-filesize: "npm:^10.0.0"
typescript: "npm:^5.6.3"
vite: "npm:^5.4.9"
vitest: "npm:^2.1.3"
languageName: unknown
linkType: soft

"@xmtp/content-type-primitives@npm:^1.0.1, @xmtp/content-type-primitives@npm:^1.0.2, @xmtp/content-type-primitives@workspace:content-types/content-type-primitives":
version: 0.0.0-use.local
resolution: "@xmtp/content-type-primitives@workspace:content-types/content-type-primitives"
Expand Down Expand Up @@ -2837,7 +2859,7 @@ __metadata:
languageName: node
linkType: hard

"@xmtp/proto@npm:^3.61.1, @xmtp/proto@npm:^3.62.1, @xmtp/proto@npm:^3.68.0":
"@xmtp/proto@npm:^3.61.1, @xmtp/proto@npm:^3.62.1, @xmtp/proto@npm:^3.68.0, @xmtp/proto@npm:^3.71.0":
version: 3.71.0
resolution: "@xmtp/proto@npm:3.71.0"
dependencies:
Expand Down

0 comments on commit 6ad0e5b

Please sign in to comment.