Skip to content

Commit

Permalink
Add zaf_sdk user agent to headers for requests
Browse files Browse the repository at this point in the history
- To assist with debugging the source of various requests it would be helpful
  to indicate whether requests have been touched by the zaf_sdk at any point
- This will help operationally for various things that need to be done to
  monitor things of an api related nature
- Knowing that a request has been touched by zaf_sdk helps to pinpoint the
  source + narrow down where things need fixing and/or patching
- It would be good to get the appId too but this is a good first port of call
  • Loading branch information
token-cjg committed Nov 4, 2024
1 parent 0a86f34 commit 8c28579
Show file tree
Hide file tree
Showing 2 changed files with 13 additions and 0 deletions.
3 changes: 3 additions & 0 deletions lib/client.js
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@ import { when, isObject, isString, debounce } from './utils'
import IdleState from './utils/idleState'
import Tracker from './tracker'
import NativePromise from 'native-promise-only'
import { addUserAgent } from './utils'

const Promise = window.Promise || NativePromise

Expand Down Expand Up @@ -557,6 +558,8 @@ export default class Client {
options = { url: options }
}

options.headers = addUserAgent(options.headers)

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

Expand Down
10 changes: 10 additions & 0 deletions lib/utils.js
Original file line number Diff line number Diff line change
@@ -1,6 +1,16 @@
import NativePromise from 'native-promise-only'
import pkgJson from '../package.json'

const Promise = window.Promise || NativePromise

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

export function isObject (obj) {
return (obj !== null && typeof obj === 'object')
}
Expand Down

0 comments on commit 8c28579

Please sign in to comment.