diff --git a/.changeset/sharp-jars-sin.md b/.changeset/sharp-jars-sin.md new file mode 100644 index 00000000..3364895f --- /dev/null +++ b/.changeset/sharp-jars-sin.md @@ -0,0 +1,6 @@ +--- +"@xmtp/browser-sdk": patch +"@xmtp/node-sdk": patch +--- + +Add history sync URL to client diff --git a/sdks/browser-sdk/src/constants.ts b/sdks/browser-sdk/src/constants.ts index b64fd31d..fceac556 100644 --- a/sdks/browser-sdk/src/constants.ts +++ b/sdks/browser-sdk/src/constants.ts @@ -3,3 +3,9 @@ export const ApiUrls = { dev: "https://dev.xmtp.network", production: "https://production.xmtp.network", } as const; + +export const HistorySyncUrls = { + local: "http://localhost:5558", + dev: "https://message-history.dev.ephemera.network", + production: "https://message-history.production.ephemera.network", +} as const; diff --git a/sdks/browser-sdk/src/index.ts b/sdks/browser-sdk/src/index.ts index a2f049cd..136aa116 100644 --- a/sdks/browser-sdk/src/index.ts +++ b/sdks/browser-sdk/src/index.ts @@ -4,7 +4,7 @@ export { Conversation } from "./Conversation"; export type { MessageDeliveryStatus, MessageKind } from "./DecodedMessage"; export { DecodedMessage } from "./DecodedMessage"; export { Utils } from "./Utils"; -export { ApiUrls } from "./constants"; +export { ApiUrls, HistorySyncUrls } from "./constants"; export type * from "./types"; export * from "./utils/conversions"; export { diff --git a/sdks/browser-sdk/src/types/options.ts b/sdks/browser-sdk/src/types/options.ts index 625faae2..5de5f2f4 100644 --- a/sdks/browser-sdk/src/types/options.ts +++ b/sdks/browser-sdk/src/types/options.ts @@ -16,6 +16,18 @@ export type NetworkOptions = { * specific endpoint */ apiUrl?: string; + /** + * historySyncUrl can be used to override the `env` flag and connect to a + * specific endpoint for syncing history + */ + historySyncUrl?: string; +}; + +export type ContentOptions = { + /** + * Allow configuring codecs for additional content types + */ + codecs?: ContentCodec[]; }; /** @@ -28,13 +40,6 @@ export type StorageOptions = { dbPath?: string; }; -export type ContentOptions = { - /** - * Allow configuring codecs for additional content types - */ - codecs?: ContentCodec[]; -}; - export type OtherOptions = { /** * Enable structured JSON logging @@ -55,6 +60,6 @@ export type OtherOptions = { }; export type ClientOptions = NetworkOptions & - StorageOptions & ContentOptions & + StorageOptions & OtherOptions; diff --git a/sdks/browser-sdk/src/utils/createClient.ts b/sdks/browser-sdk/src/utils/createClient.ts index cd4ba6ab..9ad304b7 100644 --- a/sdks/browser-sdk/src/utils/createClient.ts +++ b/sdks/browser-sdk/src/utils/createClient.ts @@ -4,7 +4,7 @@ import init, { getInboxIdForAddress, LogOptions, } from "@xmtp/wasm-bindings"; -import { ApiUrls } from "@/constants"; +import { ApiUrls, HistorySyncUrls } from "@/constants"; import type { ClientOptions } from "@/types"; export const createClient = async ( @@ -16,10 +16,6 @@ export const createClient = async ( await init(); const host = options?.apiUrl ?? ApiUrls[options?.env ?? "dev"]; - // TODO: add db path validation - // - must end with .db3 - // - must not contain invalid characters - // - must not start with a dot const dbPath = options?.dbPath ?? `xmtp-${options?.env ?? "dev"}-${accountAddress}.db3`; @@ -33,13 +29,16 @@ export const createClient = async ( options.structuredLogging || options.performanceLogging); + const historySyncUrl = + options?.historySyncUrl ?? HistorySyncUrls[options?.env ?? "dev"]; + return createWasmClient( host, inboxId, accountAddress, dbPath, encryptionKey, - undefined, + historySyncUrl, isLogging ? new LogOptions( options.structuredLogging ?? false, diff --git a/sdks/node-sdk/src/Client.ts b/sdks/node-sdk/src/Client.ts index 71a0ce24..5e061151 100644 --- a/sdks/node-sdk/src/Client.ts +++ b/sdks/node-sdk/src/Client.ts @@ -35,6 +35,12 @@ export const ApiUrls = { production: "https://grpc.production.xmtp.network:443", } as const; +export const HistorySyncUrls = { + local: "http://localhost:5558", + dev: "https://message-history.dev.ephemera.network", + production: "https://message-history.production.ephemera.network", +} as const; + export type XmtpEnv = keyof typeof ApiUrls; /** @@ -50,6 +56,11 @@ export type NetworkOptions = { * specific endpoint */ apiUrl?: string; + /** + * historySyncUrl can be used to override the `env` flag and connect to a + * specific endpoint for syncing history + */ + historySyncUrl?: string; }; /** @@ -70,10 +81,6 @@ export type ContentOptions = { }; export type OtherOptions = { - /** - * Optionally set the request history sync URL - */ - requestHistorySync?: string; /** * Enable structured JSON logging */ @@ -132,6 +139,9 @@ export class Client { level: options?.loggingLevel ?? LogLevel.off, }; + const historySyncUrl = + options?.historySyncUrl ?? HistorySyncUrls[options?.env ?? "dev"]; + const client = new Client( await createClient( host, @@ -140,7 +150,7 @@ export class Client { inboxId, accountAddress, encryptionKey, - options?.requestHistorySync, + historySyncUrl, logOptions, ), signer, diff --git a/sdks/node-sdk/src/index.ts b/sdks/node-sdk/src/index.ts index b4cd0e24..45cc2d30 100644 --- a/sdks/node-sdk/src/index.ts +++ b/sdks/node-sdk/src/index.ts @@ -5,7 +5,7 @@ export type { StorageOptions, XmtpEnv, } from "./Client"; -export { Client, ApiUrls } from "./Client"; +export { Client, ApiUrls, HistorySyncUrls } from "./Client"; export { Conversation } from "./Conversation"; export { Conversations } from "./Conversations"; export { DecodedMessage } from "./DecodedMessage";