-
Notifications
You must be signed in to change notification settings - Fork 42
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #688 from xmtp/rygine/ct-group-updated
Add content-type-group-updated
- Loading branch information
Showing
9 changed files
with
300 additions
and
1 deletion.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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. |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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` |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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/" | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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
22
content-types/content-type-group-updated/src/GroupUpdated.test.ts
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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
43
content-types/content-type-group-updated/src/GroupUpdated.ts
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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; | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1 @@ | ||
export * from "./GroupUpdated"; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,4 @@ | ||
{ | ||
"extends": "tsconfig/build.json", | ||
"include": ["src", "rollup.config.js"] | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters