Skip to content

Commit 091e70b

Browse files
author
Christopher Goddard
committed
Consume app_id on app registration + pass /w user-agent on request
- Let's ensure that we know which app made a given request by encoding within the user-agent - This will help /w ascertaining who is making a given request
1 parent 3a9251d commit 091e70b

File tree

2 files changed

+6
-3
lines changed

2 files changed

+6
-3
lines changed

lib/client.js

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -557,7 +557,8 @@ export default class Client {
557557
options = { url: options }
558558
}
559559

560-
options.headers = addUserAgent(options.headers)
560+
const appId = this._metadata && this._metadata.appId
561+
options.headers = addUserAgent(options.headers, appId)
561562

562563
const doneEventKey = `${requestKey}.done`
563564
const failEventKey = `${requestKey}.fail`

lib/utils.js

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -3,11 +3,13 @@ import pkgJson from '../package.json'
33

44
const Promise = window.Promise || NativePromise
55

6-
export function addUserAgent (headers) {
6+
export function addUserAgent (headers, appId) {
77
const originalUserAgent = headers && headers['User-Agent'] ? headers['User-Agent'] : ''
8+
const zafSdkUserAgentString = `zendesk_app_framework_sdk/sdk_version:${pkgJson.version}/app_id:${appId}`
9+
const userAgent = originalUserAgent ? `${originalUserAgent} ${zafSdkUserAgentString}` : zafSdkUserAgentString
810
return {
911
...headers,
10-
'User-Agent': originalUserAgent ? `${originalUserAgent} zendesk_app_framework_sdk/${pkgJson.version}` : `zendesk_app_framework_sdk/${pkgJson.version}`
12+
'User-Agent': userAgent
1113
}
1214
}
1315

0 commit comments

Comments
 (0)