Skip to content

Commit 538e344

Browse files
authored
fix: pass client metadata to server (#95)
1 parent 4471932 commit 538e344

File tree

3 files changed

+19
-3
lines changed

3 files changed

+19
-3
lines changed

src/lib/ClientError.ts

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,4 @@
1+
import { CLIENT_METADATA } from './constants';
12
export enum ErrorCode {
23
CLIENT_ERROR_CODE_USAGE_LIMIT_REACHED = 'CLIENT_ERROR_CODE_USAGE_LIMIT_REACHED',
34
CLIENT_ERROR_CODE_VALIDATION_ERROR = 'CLIENT_ERROR_CODE_VALIDATION_ERROR',
@@ -72,6 +73,7 @@ export class ClientError extends Error {
7273
sendErrorMetric('client_error', code, {
7374
details,
7475
statusCode,
76+
...CLIENT_METADATA,
7577
});
7678
}
7779
}

src/lib/constants.ts

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,5 @@
1+
import { version } from '../../package.json';
2+
13
// Core API
24
export const DEFAULT_HEADERS = {
35
'Content-Type': 'application/json',
@@ -14,3 +16,8 @@ export const CONNECTION_CLOSED_CODE_SIGNALLING_CLIENT_CONNECTION_FAILURE =
1416
'CONNECTION_CLOSED_CODE_SIGNALLING_CLIENT_CONNECTION_FAILURE';
1517
export const CONNECTION_CLOSED_CODE_WEBRTC_FAILURE =
1618
'CONNECTION_CLOSED_CODE_WEBRTC_FAILURE';
19+
20+
export const CLIENT_METADATA = {
21+
client: 'js-sdk',
22+
version,
23+
};

src/modules/CoreApiRestClient.ts

Lines changed: 10 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,9 @@
11
import { ClientError, ErrorCode } from '../lib/ClientError';
2-
import { DEFAULT_API_BASE_URL, DEFAULT_API_VERSION } from '../lib/constants';
2+
import {
3+
CLIENT_METADATA,
4+
DEFAULT_API_BASE_URL,
5+
DEFAULT_API_VERSION,
6+
} from '../lib/constants';
37
import {
48
CoreApiRestClientOptions,
59
PersonaConfig,
@@ -40,7 +44,6 @@ export class CoreApiRestClient {
4044
400,
4145
);
4246
}
43-
// TODO: why do we need to get the unsafe session token here?
4447
this.sessionToken = await this.unsafe_getSessionToken(personaConfig);
4548
}
4649

@@ -51,7 +54,11 @@ export class CoreApiRestClient {
5154
'Content-Type': 'application/json',
5255
Authorization: `Bearer ${this.sessionToken}`,
5356
},
54-
body: JSON.stringify({ personaConfig, sessionOptions }),
57+
body: JSON.stringify({
58+
personaConfig,
59+
sessionOptions,
60+
clientMetadata: CLIENT_METADATA,
61+
}),
5562
});
5663

5764
const data = await response.json();

0 commit comments

Comments
 (0)