Skip to content

Commit

Permalink
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Auto add history sync URL to client (browser)
Browse files Browse the repository at this point in the history
rygine committed Jan 14, 2025
1 parent 84f045c commit 0816bc0
Showing 4 changed files with 17 additions and 21 deletions.
6 changes: 6 additions & 0 deletions sdks/browser-sdk/src/constants.ts
Original file line number Diff line number Diff line change
@@ -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;
2 changes: 1 addition & 1 deletion sdks/browser-sdk/src/index.ts
Original file line number Diff line number Diff line change
@@ -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 {
16 changes: 4 additions & 12 deletions sdks/browser-sdk/src/types/options.ts
Original file line number Diff line number Diff line change
@@ -16,16 +16,11 @@ export type NetworkOptions = {
* specific endpoint
*/
apiUrl?: string;
};

/**
* Storage options
*/
export type StorageOptions = {
/**
* Path to the local DB
* historySyncUrl can be used to override the `env` flag and connect to a
* specific endpoint for syncing history
*/
dbPath?: string;
historySyncUrl?: string;
};

export type ContentOptions = {
@@ -54,7 +49,4 @@ export type OtherOptions = {
disableAutoRegister?: boolean;
};

export type ClientOptions = NetworkOptions &
StorageOptions &
ContentOptions &
OtherOptions;
export type ClientOptions = NetworkOptions & ContentOptions & OtherOptions;
14 changes: 6 additions & 8 deletions sdks/browser-sdk/src/utils/createClient.ts
Original file line number Diff line number Diff line change
@@ -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,12 +16,7 @@ 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`;
const dbPath = `xmtp-${options?.env ?? "dev"}-${accountAddress}.db3`;

const inboxId =
(await getInboxIdForAddress(host, accountAddress)) ||
@@ -33,13 +28,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,

0 comments on commit 0816bc0

Please sign in to comment.