Skip to content

Commit

Permalink
Auto add history sync URL to client (node)
Browse files Browse the repository at this point in the history
  • Loading branch information
rygine committed Jan 14, 2025
1 parent 230b743 commit d600df1
Show file tree
Hide file tree
Showing 2 changed files with 16 additions and 6 deletions.
20 changes: 15 additions & 5 deletions sdks/node-sdk/src/Client.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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;

/**
Expand All @@ -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;
};

/**
Expand All @@ -70,10 +81,6 @@ export type ContentOptions = {
};

export type OtherOptions = {
/**
* Optionally set the request history sync URL
*/
requestHistorySync?: string;
/**
* Enable structured JSON logging
*/
Expand Down Expand Up @@ -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,
Expand All @@ -140,7 +150,7 @@ export class Client {
inboxId,
accountAddress,
encryptionKey,
options?.requestHistorySync,
historySyncUrl,
logOptions,
),
signer,
Expand Down
2 changes: 1 addition & 1 deletion sdks/node-sdk/src/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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";
Expand Down

0 comments on commit d600df1

Please sign in to comment.