Skip to content

Commit 8dd8619

Browse files
committed
feat: expose client version on ApiClient.version
1 parent 85cc249 commit 8dd8619

File tree

1 file changed

+5
-5
lines changed

1 file changed

+5
-5
lines changed

src/ApiClient.ts

+5-5
Original file line numberDiff line numberDiff line change
@@ -10,8 +10,6 @@ export const { MessageApi, SortDirection } = messageApi
1010
const RETRY_SLEEP_TIME = 100
1111
const ERR_CODE_UNAUTHENTICATED = 16
1212

13-
const getClientVersion = () => 'xmtp-js/' + getPackageVersion()
14-
1513
const clientVersionHeaderKey = 'X-Client-Version'
1614

1715
export type GrpcError = Error & { code?: number }
@@ -82,10 +80,12 @@ export default class ApiClient {
8280
pathPrefix: string
8381
maxRetries: number
8482
private authCache?: AuthCache
83+
version: string
8584

8685
constructor(pathPrefix: string, opts?: ApiClientOptions) {
8786
this.pathPrefix = pathPrefix
8887
this.maxRetries = opts?.maxRetries || 5
88+
this.version = 'xmtp-js/' + getPackageVersion()
8989
}
9090

9191
// Raw method for querying the API
@@ -100,7 +100,7 @@ export default class ApiClient {
100100
pathPrefix: this.pathPrefix,
101101
mode: 'cors',
102102
headers: new Headers({
103-
[clientVersionHeaderKey]: getClientVersion(),
103+
[clientVersionHeaderKey]: this.version,
104104
}),
105105
},
106106
],
@@ -125,7 +125,7 @@ export default class ApiClient {
125125
mode: 'cors',
126126
headers: new Headers({
127127
Authorization: `Bearer ${authToken}`,
128-
[clientVersionHeaderKey]: getClientVersion(),
128+
[clientVersionHeaderKey]: this.version,
129129
}),
130130
},
131131
],
@@ -161,7 +161,7 @@ export default class ApiClient {
161161
signal: abortController.signal,
162162
mode: 'cors',
163163
headers: new Headers({
164-
[clientVersionHeaderKey]: getClientVersion(),
164+
[clientVersionHeaderKey]: this.version,
165165
}),
166166
}).catch(async (err: GrpcError) => {
167167
if (isAbortError(err)) {

0 commit comments

Comments
 (0)