Skip to content

Commit

Permalink
Merge pull request #628 from xmtp/rygine/content-type-decouple
Browse files Browse the repository at this point in the history
Decouple content types from the JS SDK, remove ContentTypeComposite
  • Loading branch information
rygine authored Jun 14, 2024
2 parents 0e75750 + 9619322 commit d36e8f3
Show file tree
Hide file tree
Showing 22 changed files with 85 additions and 456 deletions.
16 changes: 16 additions & 0 deletions .changeset/twenty-eggs-protect.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
---
"@xmtp/xmtp-js": major
---

### BREAKING CHANGES

- Removed internal content types and their primitives
- Added content types and primitives from their respective packages
- Removed `ContentTypeComposite`, see [XIP-19](https://community.xmtp.org/t/xip-19-deprecate-the-composite-codec/525) for more details
- Removed `ContentTypeFallback`

With this update, the following are no longer exported from the JS SDK: `ContentTypeId`, `CodecRegistry`, `ContentCodec`, `EncodedContent`, `ContentTypeFallback`, `TextCodec`, `ContentTypeText`, `Composite`, `CompositeCodec`, `ContentTypeComposite`

For content type primitives, use the new `@xmtp/content-type-primitives` package. It exports `ContentTypeId`, `CodecRegistry`, `ContentCodec`, and `EncodedContent`.

The text content type and codec can now be found at `@xmtp/content-type-text`. It exports `ContentTypeText`, `Encoding`, and `TextCodec`.
9 changes: 1 addition & 8 deletions packages/js-sdk/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -318,7 +318,7 @@ To learn more about content types, see [Content types with XMTP](https://xmtp.or

Support for other types of content can be added by registering additional `ContentCodecs` with the `Client`. Every codec is associated with a content type identifier, `ContentTypeId`, which is used to signal to the client which codec should be used to process the content that is being sent or received.

For example, see the [Codecs](https://github.com/xmtp/xmtp-js/tree/main/src/codecs) available in `xmtp-js`.
For examples, see the [content types](https://github.com/xmtp/xmtp-js-content-types/tree/main/packages) available in the `xmtp-js-content-types` repository.

If there is a concern that the recipient may not be able to handle a non-standard content type, the sender can use the `contentFallback` option to provide a string that describes the content being sent. If the recipient fails to decode the original content, the fallback will replace it and can be used to inform the recipient what the original content was.

Expand All @@ -340,13 +340,6 @@ As shown in the example above, you must provide a `contentFallback` value. Use i
Additional codecs can be configured through the `ClientOptions` parameter of `Client.create`. The `codecs` option is a list of codec instances that should be added to the default set of codecs (currently only the `TextCodec`). If a codec is added for a content type that is already in the default set, it will replace the original codec.

```ts
// Adding support for `xmtp.org/composite` content type
import { CompositeCodec } from '@xmtp/xmtp-js'

const xmtp = Client.create(wallet, { codecs: [new CompositeCodec()] })
```

To learn more about how to build a custom content type, see [Build a custom content type](https://xmtp.org/docs/content-types/introduction#create-custom-content-types).

Custom codecs and content types may be proposed as interoperable standards through XRCs. To learn about the custom content type proposal process, see [XIP-5](https://github.com/xmtp/XIPs/blob/main/XIPs/xip-5-message-content-types.md).
Expand Down
2 changes: 2 additions & 0 deletions packages/js-sdk/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -99,6 +99,8 @@
"dependencies": {
"@noble/secp256k1": "1.7.1",
"@xmtp/consent-proof-signature": "^0.1.3",
"@xmtp/content-type-primitives": "^1.0.1",
"@xmtp/content-type-text": "^1.0.0",
"@xmtp/proto": "3.54.0",
"@xmtp/user-preferences-bindings-wasm": "^0.3.6",
"async-mutex": "^0.5.0",
Expand Down
2 changes: 2 additions & 0 deletions packages/js-sdk/rollup.config.js
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,8 @@ import tsConfigPaths from 'rollup-plugin-tsconfig-paths'
const external = [
'@noble/secp256k1',
'@xmtp/consent-proof-signature',
'@xmtp/content-type-text',
'@xmtp/content-type-primitives',
'@xmtp/proto',
'@xmtp/user-preferences-bindings-wasm',
'@xmtp/user-preferences-bindings-wasm/web',
Expand Down
12 changes: 6 additions & 6 deletions packages/js-sdk/src/Client.ts
Original file line number Diff line number Diff line change
@@ -1,3 +1,9 @@
import {
ContentTypeId,
type ContentCodec,
type EncodedContent,
} from '@xmtp/content-type-primitives'
import { ContentTypeText, TextCodec } from '@xmtp/content-type-text'
import { messageApi, content as proto } from '@xmtp/proto'
import { getAddress, type WalletClient } from 'viem'
import KeystoreAuthenticator from '@/authn/KeystoreAuthenticator'
Expand Down Expand Up @@ -29,7 +35,6 @@ import HttpApiClient, {
type ApiClient,
type PublishParams,
} from './ApiClient'
import { ContentTypeText, TextCodec } from './codecs/Text'
import { compress, decompress } from './Compression'
import { decodeContactBundle, encodeContactBundle } from './ContactBundle'
import { Contacts } from './Contacts'
Expand All @@ -40,11 +45,6 @@ import { hasMetamaskWithSnaps } from './keystore/snapHelpers'
import type BackupClient from './message-backup/BackupClient'
import { BackupType } from './message-backup/BackupClient'
import { createBackupClient } from './message-backup/BackupClientFactory'
import {
ContentTypeId,
type ContentCodec,
type EncodedContent,
} from './MessageContent'
import { packageName, version } from './snapInfo.json'
import type { ExtractDecodedType } from './types/client'
import type { Signer } from './types/Signer'
Expand Down
2 changes: 1 addition & 1 deletion packages/js-sdk/src/Message.ts
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
import type { ContentTypeId } from '@xmtp/content-type-primitives'
import { message as proto, type conversationReference } from '@xmtp/proto'
import Long from 'long'
import { PublicKey } from '@/crypto/PublicKey'
Expand All @@ -12,7 +13,6 @@ import Ciphertext from './crypto/Ciphertext'
import { sha256 } from './crypto/encryption'
import { bytesToHex } from './crypto/utils'
import type { KeystoreInterfaces } from './keystore/rpcDefinitions'
import type { ContentTypeId } from './MessageContent'
import { dateToNs, nsToDate } from './utils/date'
import { buildDecryptV1Request, getResultOrThrow } from './utils/keystore'

Expand Down
75 changes: 0 additions & 75 deletions packages/js-sdk/src/MessageContent.ts

This file was deleted.

118 changes: 0 additions & 118 deletions packages/js-sdk/src/codecs/Composite.ts

This file was deleted.

50 changes: 0 additions & 50 deletions packages/js-sdk/src/codecs/Text.ts

This file was deleted.

2 changes: 1 addition & 1 deletion packages/js-sdk/src/conversations/Conversation.ts
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
import { ContentTypeText } from '@xmtp/content-type-text'
import {
message,
content as proto,
Expand All @@ -13,7 +14,6 @@ import type {
SendOptions,
} from '@/Client'
import type Client from '@/Client'
import { ContentTypeText } from '@/codecs/Text'
import type { ConsentState } from '@/Contacts'
import { sha256 } from '@/crypto/encryption'
import { SignedPublicKey } from '@/crypto/PublicKey'
Expand Down
9 changes: 0 additions & 9 deletions packages/js-sdk/src/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -43,15 +43,6 @@ export {
export type { Conversation } from '@/conversations/Conversation'
export { ConversationV1, ConversationV2 } from '@/conversations/Conversation'
export { default as Conversations } from '@/conversations/Conversations'
export type {
CodecRegistry,
ContentCodec,
EncodedContent,
} from './MessageContent'
export { ContentTypeId, ContentTypeFallback } from './MessageContent'
export { TextCodec, ContentTypeText } from './codecs/Text'
export type { Composite } from './codecs/Composite'
export { CompositeCodec, ContentTypeComposite } from './codecs/Composite'
export type {
ApiClient,
QueryParams,
Expand Down
2 changes: 1 addition & 1 deletion packages/js-sdk/src/types/client.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import type { ContentCodec } from '@xmtp/content-type-primitives'
import type Client from '@/Client'
import type { ContentCodec } from '@/MessageContent'

export type GetMessageContentTypeFromClient<C> =
C extends Client<infer T> ? T : never
Expand Down
Loading

0 comments on commit d36e8f3

Please sign in to comment.