Skip to content

Commit

Permalink
Consume app_id on app registration + pass /w user-agent on request
Browse files Browse the repository at this point in the history
- 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
  • Loading branch information
token-cjg committed Nov 5, 2024
1 parent 3a9251d commit 091e70b
Show file tree
Hide file tree
Showing 2 changed files with 6 additions and 3 deletions.
3 changes: 2 additions & 1 deletion lib/client.js
Original file line number Diff line number Diff line change
Expand Up @@ -557,7 +557,8 @@ export default class Client {
options = { url: options }
}

options.headers = addUserAgent(options.headers)
const appId = this._metadata && this._metadata.appId
options.headers = addUserAgent(options.headers, appId)

const doneEventKey = `${requestKey}.done`
const failEventKey = `${requestKey}.fail`
Expand Down
6 changes: 4 additions & 2 deletions lib/utils.js
Original file line number Diff line number Diff line change
Expand Up @@ -3,11 +3,13 @@ import pkgJson from '../package.json'

const Promise = window.Promise || NativePromise

export function addUserAgent (headers) {
export function addUserAgent (headers, appId) {
const originalUserAgent = headers && headers['User-Agent'] ? headers['User-Agent'] : ''
const zafSdkUserAgentString = `zendesk_app_framework_sdk/sdk_version:${pkgJson.version}/app_id:${appId}`
const userAgent = originalUserAgent ? `${originalUserAgent} ${zafSdkUserAgentString}` : zafSdkUserAgentString
return {
...headers,
'User-Agent': originalUserAgent ? `${originalUserAgent} zendesk_app_framework_sdk/${pkgJson.version}` : `zendesk_app_framework_sdk/${pkgJson.version}`
'User-Agent': userAgent
}
}

Expand Down

0 comments on commit 091e70b

Please sign in to comment.