Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

pass Client-SDK HTTP header #1056

Merged
merged 5 commits into from
Mar 18, 2022
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 4 additions & 1 deletion hooks/templatedataformatter.js
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
const getCleanedJamboInjectedData = require('../static/webpack/getCleanedJamboInjectedData');
const packageJson = require('../package.json');

/**
* Formats the data sent to the handlebars templates during Jambo builds.
Expand All @@ -25,7 +26,8 @@ module.exports = function (pageMetadata, siteLevelAttributes, pageNameToConfig)
params: currentLocaleConfig.params || {},
relativePath,
env: {
JAMBO_INJECTED_DATA: env.JAMBO_INJECTED_DATA
JAMBO_INJECTED_DATA: env.JAMBO_INJECTED_DATA,
packageJsonVersion: packageJson.version
}
};
if (globalConfig.useJWT) {
oshi97 marked this conversation as resolved.
Show resolved Hide resolved
Expand Down Expand Up @@ -73,6 +75,7 @@ function getCleanedTemplateData(templateData) {
apiKey: undefined
},
env: {
...templateData.env,
JAMBO_INJECTED_DATA: getCleanedJamboInjectedData(jamboInjectedData)
}
}
Expand Down
84 changes: 38 additions & 46 deletions package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -47,7 +47,7 @@
"puppeteer": "^10.2.0",
"serve": "^11.3.2",
"simple-git": "^2.24.0",
"testcafe": "^1.18.3",
"testcafe": "^1.18.4",
"testcafe-browser-provider-browserstack": "^1.13.1",
"underscore.string": "^3.3.5",
"urijs": "1.18.12",
Expand Down
5 changes: 5 additions & 0 deletions script/core.hbs
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,11 @@
{{#with env.JAMBO_INJECTED_DATA}}
{{#if businessId}}businessId: "{{businessId}}",{{/if}}
{{/with}}
additionalHttpHeaders: {
'Client-SDK': {
ANSWERS_THEME: '{{{ env.packageJsonVersion }}}'
}
}
};
const userConfig = {
{{#with (deepMerge global_config (lookup verticalsToConfig verticalKey) pageSettings) }}
Expand Down
4 changes: 2 additions & 2 deletions test-site/config/global_config.json
Original file line number Diff line number Diff line change
@@ -1,10 +1,10 @@
{
"sdkVersion": "1.12", // The version of the Answers SDK to use
"sdkVersion": "develop", // The version of the Answers SDK to use
// "token": "<REPLACE ME>", // The auth token to access Answers experience.
"apiKey": "2d8c550071a64ea23e263118a2b0680b", // The answers api key found on the experiences page. This will be provided automatically by the Yext CI system
// "experienceVersion": "<REPLACE ME>", // the Answers Experience version to use for API requests. This will be provided automatically by the Yext CI system
// "environment": "production", // The environment to run on for this Answers Experience. (i.e. 'production' or 'sandbox')
// "businessId": "<REPLACE ME>", // The business ID of the account. This will be provided automatically by the Yext CI system
"businessId": "3350634", // The business ID of the account. This will be provided automatically by the Yext CI system
// "initializeManually": true, // If true, the experience must be started by calling AnswersExperience.init() or AnswersExperienceFrame.init() for iframe integrations.
// "useJWT": true, // Whether or not to enable JWT. If true, the apiKey will be hidden from the build and the token must be specified through the runtime config.
"sessionTrackingEnabled": true, // Whether or not session tracking is enabled for all pages
Expand Down
8 changes: 5 additions & 3 deletions tests/acceptance/constants.js
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
module.exports.PORT=9999;
module.exports.VERTICAL_SEARCH_URL_REGEX=/v2\/accounts\/me\/answers\/vertical\/query/;
module.exports.UNIVERSAL_SEARCH_URL_REGEX=/v2\/accounts\/me\/answers\/query/;
exports.PORT=9999;
exports.VERTICAL_SEARCH_URL_REGEX=/v2\/accounts\/me\/answers\/vertical\/query/;
exports.UNIVERSAL_SEARCH_URL_REGEX=/v2\/accounts\/me\/answers\/query/;
exports.UNIVERSAL_AUTOCOMPLETE_URL_REGEX=/v2\/accounts\/me\/answers\/autocomplete/;
exports.VERTICAL_AUTOCOMPLETE_URL_REGEX=/v2\/accounts\/me\/answers\/vertical\/autocomplete/;
44 changes: 38 additions & 6 deletions tests/acceptance/searchrequestlogger.js
Original file line number Diff line number Diff line change
@@ -1,10 +1,14 @@
import { VERTICAL_SEARCH_URL_REGEX, UNIVERSAL_SEARCH_URL_REGEX } from './constants';
import { VERTICAL_SEARCH_URL_REGEX, UNIVERSAL_SEARCH_URL_REGEX, VERTICAL_AUTOCOMPLETE_URL_REGEX, UNIVERSAL_AUTOCOMPLETE_URL_REGEX } from './constants';
import { RequestLogger } from 'testcafe';

const LOGGER_OPTIONS = {
logRequestHeaders: true
}

/**
* Handles request logger creation and request/response data received during test execution.
*/
class SearchRequestLogger {
export class SearchRequestLogger {

/**
* Create a RequestLogger that tracks vertical query requests to given test.
Expand All @@ -13,8 +17,9 @@ class SearchRequestLogger {
*/
createVerticalSearchLogger() {
this._queryRequestLogger = RequestLogger({
url: VERTICAL_SEARCH_URL_REGEX
});
url: VERTICAL_SEARCH_URL_REGEX,
method: 'get'
}, LOGGER_OPTIONS);
return this._queryRequestLogger;
}

Expand All @@ -25,8 +30,35 @@ class SearchRequestLogger {
*/
createUniversalSearchLogger() {
this._queryRequestLogger = RequestLogger({
url: UNIVERSAL_SEARCH_URL_REGEX
});
url: UNIVERSAL_SEARCH_URL_REGEX,
method: 'get'
}, LOGGER_OPTIONS);
return this._queryRequestLogger;
}

/**
* Create a RequestLogger that tracks vertical query requests to given test.
*
* @returns {import('testcafe').RequestLogger}
*/
createVerticalAutocompleteLogger() {
this._queryRequestLogger = RequestLogger({
url: VERTICAL_AUTOCOMPLETE_URL_REGEX,
method: 'get'
}, LOGGER_OPTIONS);
return this._queryRequestLogger;
}

/**
* Create a RequestLogger that tracks universal query requests to given test.
*
* @returns {import('testcafe').RequestLogger}
*/
createUniversalAutocompleteLogger() {
this._queryRequestLogger = RequestLogger({
url: UNIVERSAL_AUTOCOMPLETE_URL_REGEX,
method: 'get'
}, LOGGER_OPTIONS);
return this._queryRequestLogger;
}

Expand Down
Loading