Skip to content

Commit

Permalink
Version 1.31.0 (#1136)
Browse files Browse the repository at this point in the history
### Changes
A new cloudRegion config option was introduced which supports both "us" and "eu". This option determines which cloud region the search assets are loaded from. If sdkVersion 1.16 or greater is used, then the EU search endpoints will be used when the cloudRegion is set to "eu".
  • Loading branch information
cea2aj authored May 9, 2023
2 parents f87864a + 0b43256 commit 64b4730
Show file tree
Hide file tree
Showing 14 changed files with 2,256 additions and 3,700 deletions.
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -2,3 +2,4 @@ static/node_modules/
static/dist/
node_modules
**/.DS_Store
.idea/
3 changes: 2 additions & 1 deletion global_config.json
Original file line number Diff line number Diff line change
@@ -1,9 +1,10 @@
{
"sdkVersion": "1.15", // The version of the Answers SDK to use
"sdkVersion": "1.16", // The version of the Answers SDK to use
// "token": "<REPLACE ME>", // The auth token to access Answers experience.
// "apiKey": "<REPLACE ME>", // 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')
// "cloudRegion": "us", // The cloud region to use for this Answers Experience. (i.e. 'us' or 'eu')
// "businessId": "<REPLACE ME>", // 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 output and the token must be specified through manual initialization.
Expand Down
26 changes: 19 additions & 7 deletions hbshelpers/sdkAssetUrl.js
Original file line number Diff line number Diff line change
Expand Up @@ -2,17 +2,25 @@ const RELEASE_BRANCH_REGEX = /^release\/v[0-9.]+$/;
const HOTFIX_BRANCH_REGEX = /^hotfix\/v[0-9.]+$/;
const I18N_FEATURE_BRANCH_REGEX = /^feature\/.+-i18n$/;
const SEM_VER_REGEX = /^[1-9]+$|^[1-9]+\.[0-9]+$|^[1-9]+\.[0-9]+\.[0-9]+$/;
const US = 'us';
const EU = 'eu';

/**
* Given a branch (or release) of the SDK and a locale, this helper provides the correct
* URL in the CDN for the asset.
*
*
* @param {string} branch The branch (or release) of the SDK.
* @param {string} locale The locale to use.
* @param {string} assetName The name of the desired asset.
* @param {string} cloudRegion The cloud region to use.
* @returns {string} The CDN URL of the localized asset.
*/
module.exports = function sdkAssetUrl(branch, locale, assetName) {
module.exports = function sdkAssetUrl(
branch,
locale,
assetName,
cloudRegion = US
) {
const isReleasedBranch = SEM_VER_REGEX.test(branch);

let parsedBranch;
Expand All @@ -24,17 +32,21 @@ module.exports = function sdkAssetUrl(branch, locale, assetName) {
parsedBranch = `dev/${branch.replace(/\//g, '-')}`;
}

const isPreReleaseBranch =
const isPreReleaseBranch =
RELEASE_BRANCH_REGEX.test(branch) || HOTFIX_BRANCH_REGEX.test(branch);
const isI18nFeatureBranch = I18N_FEATURE_BRANCH_REGEX.test(branch);
const isDevelopBranch = branch === 'develop';
const isLocalizationSupported =
(isReleasedBranch || isPreReleaseBranch || isI18nFeatureBranch || isDevelopBranch) &&
const isLocalizationSupported =
(isReleasedBranch || isPreReleaseBranch || isI18nFeatureBranch || isDevelopBranch) &&
!(locale.startsWith('en') || assetName === 'answers.css') ;

const parsedAssetName = isLocalizationSupported ?
`${locale}-${assetName}` :
assetName;

return `https://assets.sitescdn.net/answers/${parsedBranch}/${parsedAssetName}`;
const domain = cloudRegion === EU
? 'assets.eu.sitescdn.net'
: 'assets.sitescdn.net';

return `https://${domain}/answers/${parsedBranch}/${parsedAssetName}`;
};
22 changes: 15 additions & 7 deletions layouts/html.hbs
Original file line number Diff line number Diff line change
Expand Up @@ -24,8 +24,12 @@
<link rel="dns-prefetch" href="//dynl.mktgcdn.com">
<link rel="dns-prefetch" href="//dynm.mktgcdn.com">
<link rel="dns-prefetch" href="//www.google-analytics.com">
<link rel="dns-prefetch" href="//assets.sitescdn.net">

{{#ifeq global_config.cloudRegion 'eu'}}
<link rel="dns-prefetch" href="//assets.eu.sitescdn.net">
{{else}}
<link rel="dns-prefetch" href="//assets.sitescdn.net">
{{/ifeq}}

{{> layouts/preload-fonts }}

<script>
Expand Down Expand Up @@ -115,23 +119,27 @@
{{/if}}

{{#if global_config.conversionTrackingEnabled}}
<script src="https://assets.sitescdn.net/ytag/ytag.min.js"></script>
{{#ifeq global_config.cloudRegion "eu"}}
<script src="https://assets.eu.sitescdn.net/ytag/ytag.min.js"></script>
{{else}}
<script src="https://assets.sitescdn.net/ytag/ytag.min.js"></script>
{{/ifeq}}
{{/if}}

<script>
{{#babel}}
function iframeGetSearchParams() {
const params = window.location.search.substr(1);
const verticalUrl = window.location.pathname.substr(1);
return verticalUrl
return verticalUrl
? params + '&verticalUrl=' + verticalUrl
: params;
}
let iframeLoadedResolve;
window.iframeLoaded = new Promise(resolve => {
iframeLoadedResolve = resolve;
});
window.iFrameResizer = {
onReady: function() {
window.parentIFrame.sendMessage(JSON.stringify({
Expand Down Expand Up @@ -164,9 +172,9 @@
<script src="https://cdnjs.cloudflare.com/ajax/libs/iframe-resizer/4.2.10/iframeResizer.contentWindow.min.js"></script>
<link rel="stylesheet" type="text/css"
{{#if (isRTL global_config.locale) }}
href="{{sdkAssetUrl global_config.sdkVersion 'en' 'answers.rtl.css'}}"
href="{{sdkAssetUrl global_config.sdkVersion 'en' 'answers.rtl.css' global_config.cloudRegion}}"
{{else}}
href="{{sdkAssetUrl global_config.sdkVersion 'en' 'answers.css'}}"
href="{{sdkAssetUrl global_config.sdkVersion 'en' 'answers.css' global_config.cloudRegion}}"
{{/if}}
>
<link rel="stylesheet" type="text/css"
Expand Down
Loading

0 comments on commit 64b4730

Please sign in to comment.