From c66af0596d82347764eb747544d2c3f1414f8e73 Mon Sep 17 00:00:00 2001 From: Tomify Date: Tue, 14 Apr 2026 13:30:20 -0400 Subject: [PATCH] Added source and version request headers --- src/lib/http/index.js | 5 ++++- .../survey/cognitive/__snapshots__/index.test.js.snap | 4 ++++ .../survey/generic/__snapshots__/index.test.js.snap | 2 ++ test/jest.config.js | 1 + test/lib/http.test.js | 8 ++++++-- 5 files changed, 17 insertions(+), 3 deletions(-) diff --git a/src/lib/http/index.js b/src/lib/http/index.js index 5fb820d7..047d6585 100644 --- a/src/lib/http/index.js +++ b/src/lib/http/index.js @@ -1,3 +1,4 @@ +/* global SOURCE, VERSION */ import withRetry from "./retry"; import toQueryString from "../common/object/to-query-string"; import Listener from "../listener"; @@ -43,7 +44,9 @@ export default class Http { const headers = { "Accept": "application/json", "Authorization": `Basic ${btoa(`${this.authKey}:x`)}`, - "Content-Type": graphql ? "application/graphql" : "application/json" + "Content-Type": graphql ? "application/graphql" : "application/json", + "X-Traitify-Widgets-Source": SOURCE, + "X-Traitify-Widgets-Version": VERSION }; const options = {headers, method}; let url = [this.host, version === undefined ? this.version : version].filter(Boolean).join("/"); diff --git a/test/components/survey/cognitive/__snapshots__/index.test.js.snap b/test/components/survey/cognitive/__snapshots__/index.test.js.snap index 6208dcca..337081dd 100644 --- a/test/components/survey/cognitive/__snapshots__/index.test.js.snap +++ b/test/components/survey/cognitive/__snapshots__/index.test.js.snap @@ -351,6 +351,8 @@ exports[`Survey.Cognitive submit submits query 1`] = ` "Authorization": "Basic dW5kZWZpbmVkOng=", "Content-Type": "application/json", "X-Request-Id": "widget-test.aaaaaa", + "X-Traitify-Widgets-Source": "test", + "X-Traitify-Widgets-Version": "0.0.0-test", }, "method": "POST", }, @@ -367,6 +369,8 @@ exports[`Survey.Cognitive submit submits query with fallbacks 1`] = ` "Authorization": "Basic dW5kZWZpbmVkOng=", "Content-Type": "application/json", "X-Request-Id": "widget-test.aaaaaa", + "X-Traitify-Widgets-Source": "test", + "X-Traitify-Widgets-Version": "0.0.0-test", }, "method": "POST", }, diff --git a/test/components/survey/generic/__snapshots__/index.test.js.snap b/test/components/survey/generic/__snapshots__/index.test.js.snap index f98bc331..81f58b6d 100644 --- a/test/components/survey/generic/__snapshots__/index.test.js.snap +++ b/test/components/survey/generic/__snapshots__/index.test.js.snap @@ -179,6 +179,8 @@ exports[`Survey.Generic submit submits query 1`] = ` "Authorization": "Basic dW5kZWZpbmVkOng=", "Content-Type": "application/json", "X-Request-Id": "widget-test.aaaaaa", + "X-Traitify-Widgets-Source": "test", + "X-Traitify-Widgets-Version": "0.0.0-test", }, "method": "POST", }, diff --git a/test/jest.config.js b/test/jest.config.js index 9e90bcc7..f5a270f5 100644 --- a/test/jest.config.js +++ b/test/jest.config.js @@ -5,6 +5,7 @@ module.exports = { ], fakeTimers: {enableGlobally: true}, globals: { + SOURCE: "test", VERSION: "0.0.0-test" }, moduleFileExtensions: [ diff --git a/test/lib/http.test.js b/test/lib/http.test.js index f267912b..910868dd 100644 --- a/test/lib/http.test.js +++ b/test/lib/http.test.js @@ -88,7 +88,9 @@ describe("Http", () => { expect.objectContaining({ "Accept": "application/json", "Authorization": `Basic ${btoa("xyz:x")}`, - "Content-Type": "application/graphql" + "Content-Type": "application/graphql", + "X-Traitify-Widgets-Source": "test", + "X-Traitify-Widgets-Version": "0.0.0-test" }) ); }); @@ -108,7 +110,9 @@ describe("Http", () => { expect.objectContaining({ "Accept": "application/json", "Authorization": `Basic ${btoa("xyz:x")}`, - "Content-Type": "application/json" + "Content-Type": "application/json", + "X-Traitify-Widgets-Source": "test", + "X-Traitify-Widgets-Version": "0.0.0-test" }) ); });