From 091e70b3cd2f0888a79589310d0823d62cbdb785 Mon Sep 17 00:00:00 2001 From: Christopher Goddard Date: Mon, 4 Nov 2024 17:50:13 +1100 Subject: [PATCH] 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 --- lib/client.js | 3 ++- lib/utils.js | 6 ++++-- 2 files changed, 6 insertions(+), 3 deletions(-) diff --git a/lib/client.js b/lib/client.js index cdf0a45..4beedfe 100644 --- a/lib/client.js +++ b/lib/client.js @@ -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` diff --git a/lib/utils.js b/lib/utils.js index b34418f..5ade59c 100644 --- a/lib/utils.js +++ b/lib/utils.js @@ -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 } }