Skip to content

Commit b060015

Browse files
authored
feat(PLT-1578): eu region option for live embed routing (#689)
* feat(eu): add EU region support for live embeds and update related tests * fix(ci): skip sonar scan
1 parent 6e43be3 commit b060015

File tree

6 files changed

+105
-18
lines changed

6 files changed

+105
-18
lines changed

.github/workflows/pull-request.yml

Lines changed: 11 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -44,15 +44,17 @@ jobs:
4444
- name: Verify coverage file ready
4545
run: find . | grep coverage
4646

47-
- name: SonarCloud Scan
48-
uses: SonarSource/sonarcloud-github-action@v2
49-
if: ${{ matrix.node_version == '22' }}
50-
with:
51-
args: >
52-
-Dsonar.projectVersion=${{ github.run_id }}
53-
env:
54-
GITHUB_TOKEN: ${{ secrets.GH_TOKEN }}
55-
SONAR_TOKEN: ${{ secrets.SONAR_CLOUD_TOKEN }}
47+
# Ongoing SonarCloud infrastructure changes are blocking us
48+
# from running this step at this time. Please activate the step again later.
49+
# - name: SonarCloud Scan
50+
# uses: SonarSource/sonarcloud-github-action@v2
51+
# if: ${{ matrix.node_version == '22' }}
52+
# with:
53+
# args: >
54+
# -Dsonar.projectVersion=${{ github.run_id }}
55+
# env:
56+
# GITHUB_TOKEN: ${{ secrets.GH_TOKEN }}
57+
# SONAR_TOKEN: ${{ secrets.SONAR_CLOUD_TOKEN }}
5658

5759
functional:
5860
runs-on: ubuntu-latest
Lines changed: 33 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,33 @@
1+
<!DOCTYPE html>
2+
<html lang="en">
3+
<head>
4+
<meta charset="utf-8" />
5+
<meta name="viewport" content="width=device-width, initial-scale=1" />
6+
<title>EU Region Forward Compatible Static HTML Demo</title>
7+
<style>
8+
#wrapper {
9+
width: 100%;
10+
max-width: 600px;
11+
height: 400px;
12+
margin: 0 auto;
13+
}
14+
.element {
15+
position: fixed;
16+
bottom: 0;
17+
right: 0;
18+
background: red;
19+
color: white;
20+
padding: 10px;
21+
width: 200px;
22+
height: 60px;
23+
line-height: 40px;
24+
z-index: 10000;
25+
}
26+
</style>
27+
</head>
28+
<body>
29+
<div class="element">I have z-index 10k</div>
30+
<div id="wrapper" data-tf-live="01JSXVEN52DVHSX0NDQAJNVAZ4" data-tf-region="eu" data-tf-hidden="[email protected]"></div>
31+
<script src="./lib/embed.js"></script>
32+
</body>
33+
</html>
Lines changed: 36 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,36 @@
1+
describe('Single Embed Code (EU Region)', () => {
2+
describe(`Should load`, () => {
3+
before(() => {
4+
cy.intercept('https://api.typeform.eu/single-embed/01JSXVEN52DVHSX0NDQAJNVAZ4', {
5+
statusCode: 200,
6+
body: {
7+
html: `<div
8+
id="wrapper"
9+
data-tf-domain="form.typeform.eu"
10+
data-tf-widget="Pq5DjtOF"
11+
data-tf-medium="demo-test"
12+
data-tf-transitive-search-params="foo,bar"
13+
data-tf-hidden="foo=foo value"
14+
data-tf-tracking="utm_source=facebook"
15+
data-tf-iframe-props="title=Foo Bar"
16+
></div>`,
17+
},
18+
})
19+
cy.visit(`/live-embed-eu.html?bar=transitive`)
20+
})
21+
22+
it('should display widget', () => {
23+
cy.wait(500)
24+
cy.get('.tf-v1-widget iframe').should('be.visible')
25+
cy.get('.tf-v1-widget iframe').invoke('attr', 'src').should('contain', 'form.typeform.eu/to/')
26+
})
27+
28+
it('should pass hidden fields as hash', () => {
29+
cy.get('.tf-v1-widget iframe').invoke('attr', 'src').should('contain', '#foo=foo+value&email=foo%40bar.com')
30+
})
31+
32+
it('should pass transitive search params', () => {
33+
cy.get('.tf-v1-widget iframe').invoke('attr', 'src').should('contain', '&bar=transitive')
34+
})
35+
})
36+
})

packages/embed/src/constants.ts

Lines changed: 7 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,12 @@
1+
export const DEFAULT_DOMAIN = 'form.typeform.com'
2+
export const LIVE_EMBED_ATTRIBUTE = 'data-tf-live'
3+
export const LIVE_EMBED_DATA_REGION_ATTRIBUTE = 'data-tf-region'
4+
export const LIVE_EMBED_DATA_REGION_EU = 'eu'
15
export const POPOVER_ATTRIBUTE = 'data-tf-popover'
26
export const POPUP_ATTRIBUTE = 'data-tf-popup'
3-
export const SLIDER_ATTRIBUTE = 'data-tf-slider'
4-
export const WIDGET_ATTRIBUTE = 'data-tf-widget'
7+
export const POPUP_SIZE = 100
58
export const SIDETAB_ATTRIBUTE = 'data-tf-sidetab'
6-
export const LIVE_EMBED_ATTRIBUTE = 'data-tf-live'
9+
export const SLIDER_ATTRIBUTE = 'data-tf-slider'
710
export const SLIDER_POSITION = 'right'
811
export const SLIDER_WIDTH = 800
9-
export const POPUP_SIZE = 100
10-
export const DEFAULT_DOMAIN = 'form.typeform.com'
12+
export const WIDGET_ATTRIBUTE = 'data-tf-widget'

packages/embed/src/initializers/initialize-live-embeds.ts

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
import { LIVE_EMBED_ATTRIBUTE } from '../constants'
1+
import { LIVE_EMBED_ATTRIBUTE, LIVE_EMBED_DATA_REGION_ATTRIBUTE } from '../constants'
22
import { fetchLiveEmbed } from '../live-embed/fetch-live-embed'
33

44
export const initializeLiveEmbeds = ({
@@ -20,7 +20,9 @@ export const initializeLiveEmbeds = ({
2020
}
2121
element.dataset.tfLoading = 'true'
2222

23-
fetchLiveEmbed(embedId).then(({ html }) => {
23+
const dataRegion = element.getAttribute(LIVE_EMBED_DATA_REGION_ATTRIBUTE) ?? undefined
24+
25+
fetchLiveEmbed(embedId, dataRegion).then(({ html }) => {
2426
element.innerHTML = html
2527
onLiveEmbedLoad(element)
2628
delete element.dataset.tfLoading
Lines changed: 14 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,21 @@
1-
export const fetchLiveEmbed = async (embedId: string) => {
2-
const response = await fetch(`https://api.typeform.com/single-embed/${embedId}`)
1+
import { LIVE_EMBED_DATA_REGION_EU } from '../constants'
2+
3+
export const fetchLiveEmbed = async (embedId: string, region?: string) => {
4+
const baseUrl = resolveBaseUrl(region)
5+
const response = await fetch(`${baseUrl}/single-embed/${embedId}`)
36

47
if (!response.ok) {
58
throw new Error(`Cannot fetch embed ${embedId}`)
69
}
710

811
return await response.json()
912
}
13+
14+
function resolveBaseUrl(region?: string) {
15+
switch (region) {
16+
case LIVE_EMBED_DATA_REGION_EU:
17+
return 'https://api.typeform.eu'
18+
default:
19+
return 'https://api.typeform.com'
20+
}
21+
}

0 commit comments

Comments
 (0)