Skip to content

Commit

Permalink
Update SDK from 2 to 3
Browse files Browse the repository at this point in the history
  • Loading branch information
bryans99 committed Jan 10, 2025
1 parent eb94899 commit d848f1b
Show file tree
Hide file tree
Showing 4 changed files with 38 additions and 38 deletions.
2 changes: 1 addition & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -108,7 +108,7 @@ Embed SDK 2.0.0 will sanitize the URL if necessary:

```html
/embed/looks/4?embed_domain=https://mywebsite.com =>
/embed/looks/4?embed_domain=https://mywebsite.com&sdk=2
/embed/looks/4?embed_domain=https://mywebsite.com&sdk=3
```

## Signed URL Auth Endpoint
Expand Down
4 changes: 2 additions & 2 deletions src/v2/EmbedClientEx.ts
Original file line number Diff line number Diff line change
Expand Up @@ -122,13 +122,13 @@ export class EmbedClientEx implements IEmbedClient {
requiredParams = {
embed_domain: `${prefix}${this._sdk.apiHost}`,
sandboxed_host: 'true',
sdk: '2',
sdk: '3',
}
} else {
const embedDomain = window.location.origin
requiredParams = {
embed_domain: embedDomain,
sdk: '2',
sdk: '3',
}
}
const tempOrigin = urlString.startsWith('https://') ? '' : 'http://abc'
Expand Down
32 changes: 16 additions & 16 deletions tests/v2/EmbedClientEx.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -109,7 +109,7 @@ describe('EmbedClientEx', () => {
const client = getClient()
await client.connect()
expect(mockHostBuilder._url).toBe(
'https://myhost.com/embed/preload/?embed_domain=http%3A%2F%2Flocalhost%3A9876&sdk=2'
'https://myhost.com/embed/preload/?embed_domain=http%3A%2F%2Flocalhost%3A9876&sdk=3'
)
expect(mockHostBuilder.countHandlersOfType('session:tokens:request')).toBe(
0
Expand All @@ -130,7 +130,7 @@ describe('EmbedClientEx', () => {
const client = getClient({ sandboxedHost: true })
await client.connect()
expect(mockHostBuilder._url).toBe(
'https://myhost.com/embed/preload/?embed_domain=https%3A%2F%2Fmyhost.com&sandboxed_host=true&sdk=2'
'https://myhost.com/embed/preload/?embed_domain=https%3A%2F%2Fmyhost.com&sandboxed_host=true&sdk=3'
)
})

Expand All @@ -141,7 +141,7 @@ describe('EmbedClientEx', () => {
})
await client.connect()
expect(mockHostBuilder._url).toBe(
'https://mylooker.com/embed/preload/?embed_domain=https%3A%2F%2Fmylooker.com&sandboxed_host=true&sdk=2'
'https://mylooker.com/embed/preload/?embed_domain=https%3A%2F%2Fmylooker.com&sandboxed_host=true&sdk=3'
)
})

Expand All @@ -151,7 +151,7 @@ describe('EmbedClientEx', () => {
})
await client.connect()
expect(mockHostBuilder._url).toBe(
'https://mylooker.com/embed/preload/?embed_domain=http%3A%2F%2Flocalhost%3A9876&sdk=2'
'https://mylooker.com/embed/preload/?embed_domain=http%3A%2F%2Flocalhost%3A9876&sdk=3'
)
})

Expand All @@ -161,7 +161,7 @@ describe('EmbedClientEx', () => {
})
const connectPromise = client.connect(true)
expect(mockHostBuilder._url).toBe(
'https://mylooker.com/embed/preload/?embed_domain=http%3A%2F%2Flocalhost%3A9876&sdk=2'
'https://mylooker.com/embed/preload/?embed_domain=http%3A%2F%2Flocalhost%3A9876&sdk=3'
)
mockHostBuilder.fireEventForHandler('page:changed', {})
await connectPromise
Expand All @@ -174,31 +174,31 @@ describe('EmbedClientEx', () => {
})
await client.connect()
expect(mockHostBuilder._url).toBe(
'https://mylooker.com/embed/dashboards/42?my_filter=123&embed_domain=http%3A%2F%2Flocalhost%3A9876&sdk=2'
'https://mylooker.com/embed/dashboards/42?my_filter=123&embed_domain=http%3A%2F%2Flocalhost%3A9876&sdk=3'
)
})

it('does not add embed domain and sdk to URL when they are present', async () => {
const client = getClient({
apiHost: 'https://mylooker.com',
createUrl:
'/embed/dashboards/42?embed_domain=http%3A%2F%2Flocalhost%3A9876&sdk=2&my_filter=123',
'/embed/dashboards/42?embed_domain=http%3A%2F%2Flocalhost%3A9876&sdk=3&my_filter=123',
})
await client.connect()
expect(mockHostBuilder._url).toBe(
'https://mylooker.com/embed/dashboards/42?embed_domain=http%3A%2F%2Flocalhost%3A9876&sdk=2&my_filter=123'
'https://mylooker.com/embed/dashboards/42?embed_domain=http%3A%2F%2Flocalhost%3A9876&sdk=3&my_filter=123'
)
})

it('adds /embed to url when missing', async () => {
const client = getClient({
apiHost: 'https://mylooker.com',
createUrl:
'/dashboards/42?embed_domain=http%3A%2F%2Flocalhost%3A9876&sdk=2&my_filter=123',
'/dashboards/42?embed_domain=http%3A%2F%2Flocalhost%3A9876&sdk=3&my_filter=123',
})
await client.connect()
expect(mockHostBuilder._url).toBe(
'https://mylooker.com/embed/dashboards/42?embed_domain=http%3A%2F%2Flocalhost%3A9876&sdk=2&my_filter=123'
'https://mylooker.com/embed/dashboards/42?embed_domain=http%3A%2F%2Flocalhost%3A9876&sdk=3&my_filter=123'
)
})

Expand All @@ -209,7 +209,7 @@ describe('EmbedClientEx', () => {
})
await client.connect()
expect(mockHostBuilder._url).toBe(
'https://mylooker.com/embed/dashboards/42?my_filter=123&embed_domain=http%3A%2F%2Flocalhost%3A9876&sdk=2'
'https://mylooker.com/embed/dashboards/42?my_filter=123&embed_domain=http%3A%2F%2Flocalhost%3A9876&sdk=3'
)
})

Expand All @@ -220,7 +220,7 @@ describe('EmbedClientEx', () => {
})
await client.connect()
expect(mockHostBuilder._url).toBe(
'https://mylooker.com/embed/dashboards/42?my_filter=123&embed_domain=http%3A%2F%2Flocalhost%3A9876&sdk=2'
'https://mylooker.com/embed/dashboards/42?my_filter=123&embed_domain=http%3A%2F%2Flocalhost%3A9876&sdk=3'
)
})

Expand All @@ -239,12 +239,12 @@ describe('EmbedClientEx', () => {
it('creates a signed url connection', async () => {
const authResponse = {
url: `https://mylooker.com/login/embed${encodeURIComponent(
'/embed/preload/?embed_domain=http%3A%2F%2Flocalhost%3A9876&sdk=2'
'/embed/preload/?embed_domain=http%3A%2F%2Flocalhost%3A9876&sdk=3'
)}?external_user_id=postmanpat&signature=1234567890abcdef`,
}
mock.get(/\/auth\?src=/, (req, res) => {
expect(req.url().toString()).toBe(
'/auth?src=%2Fembed%2Fpreload%2F%3Fembed_domain%3Dhttp%253A%252F%252Flocalhost%253A9876%26sdk%3D2&param_1=value_1&param_2=value_2'
'/auth?src=%2Fembed%2Fpreload%2F%3Fembed_domain%3Dhttp%253A%252F%252Flocalhost%253A9876%26sdk%3D3&param_1=value_1&param_2=value_2'
)
expect(req.header('Cache-Control')).toEqual('no-cache')
expect(req.header('header_1')).toEqual('header_value_1')
Expand Down Expand Up @@ -312,7 +312,7 @@ describe('EmbedClientEx', () => {
).and.callThrough()
expect(fetchSpy).toHaveBeenCalledWith('/acquire-session', undefined)
expect(mockHostBuilder._url).toBe(
'https://myhost.com/login/embed/%2Fembed%2Fpreload%2F%3Fembed_domain%3Dhttp%253A%252F%252Flocalhost%253A9876%26sdk%3D2%26embed_navigation_token%3Dabcdef-nav?embed_authentication_token=abcdef-auth'
'https://myhost.com/login/embed/%2Fembed%2Fpreload%2F%3Fembed_domain%3Dhttp%253A%252F%252Flocalhost%253A9876%26sdk%3D3%26embed_navigation_token%3Dabcdef-nav?embed_authentication_token=abcdef-auth'
)
expect(mockHostBuilder.countHandlersOfType('session:tokens:request')).toBe(
1
Expand Down Expand Up @@ -525,7 +525,7 @@ describe('EmbedClientEx', () => {
'send'
).and.callThrough()
expect(mockHostBuilder._url).toBe(
'https://myhost.com/login/embed/%2Fembed%2Fpreload%2F%3Fembed_domain%3Dhttp%253A%252F%252Flocalhost%253A9876%26sdk%3D2%26embed_navigation_token%3Dabcdef-nav?embed_authentication_token=abcdef-auth'
'https://myhost.com/login/embed/%2Fembed%2Fpreload%2F%3Fembed_domain%3Dhttp%253A%252F%252Flocalhost%253A9876%26sdk%3D3%26embed_navigation_token%3Dabcdef-nav?embed_authentication_token=abcdef-auth'
)
expect(mockHostBuilder.countHandlersOfType('session:tokens:request')).toBe(
1
Expand Down
38 changes: 19 additions & 19 deletions tests/v2/EmbedConnection.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -92,7 +92,7 @@ describe('EmmbedConnection', () => {
await connection.loadDashboard('42', false, false)
expect(chattySendAndReceiveSpy).toHaveBeenCalledWith('page:load', {
pushHistory: false,
url: '/embed/dashboards/42?embed_domain=http%3A%2F%2Flocalhost%3A9876&sdk=2',
url: '/embed/dashboards/42?embed_domain=http%3A%2F%2Flocalhost%3A9876&sdk=3',
})
})

Expand All @@ -107,7 +107,7 @@ describe('EmmbedConnection', () => {
await loadPromise
expect(chattySendAndReceiveSpy).toHaveBeenCalledWith('page:load', {
pushHistory: false,
url: '/embed/dashboards/42?embed_domain=http%3A%2F%2Flocalhost%3A9876&sdk=2',
url: '/embed/dashboards/42?embed_domain=http%3A%2F%2Flocalhost%3A9876&sdk=3',
})
})

Expand All @@ -120,7 +120,7 @@ describe('EmmbedConnection', () => {
await connection.loadExplore('mymodel::myview', false, false)
expect(chattySendAndReceiveSpy).toHaveBeenCalledWith('page:load', {
pushHistory: false,
url: '/embed/explore/mymodel/myview?embed_domain=http%3A%2F%2Flocalhost%3A9876&sdk=2',
url: '/embed/explore/mymodel/myview?embed_domain=http%3A%2F%2Flocalhost%3A9876&sdk=3',
})
})

Expand All @@ -135,7 +135,7 @@ describe('EmmbedConnection', () => {
await loadPromise
expect(chattySendAndReceiveSpy).toHaveBeenCalledWith('page:load', {
pushHistory: false,
url: '/embed/explore/mymodel/myview?embed_domain=http%3A%2F%2Flocalhost%3A9876&sdk=2',
url: '/embed/explore/mymodel/myview?embed_domain=http%3A%2F%2Flocalhost%3A9876&sdk=3',
})
})

Expand All @@ -148,7 +148,7 @@ describe('EmmbedConnection', () => {
await connection.loadLook('42', false, false)
expect(chattySendAndReceiveSpy).toHaveBeenCalledWith('page:load', {
pushHistory: false,
url: '/embed/looks/42?embed_domain=http%3A%2F%2Flocalhost%3A9876&sdk=2',
url: '/embed/looks/42?embed_domain=http%3A%2F%2Flocalhost%3A9876&sdk=3',
})
})

Expand All @@ -163,7 +163,7 @@ describe('EmmbedConnection', () => {
await loadPromise
expect(chattySendAndReceiveSpy).toHaveBeenCalledWith('page:load', {
pushHistory: false,
url: '/embed/looks/42?embed_domain=http%3A%2F%2Flocalhost%3A9876&sdk=2',
url: '/embed/looks/42?embed_domain=http%3A%2F%2Flocalhost%3A9876&sdk=3',
})
})

Expand All @@ -176,7 +176,7 @@ describe('EmmbedConnection', () => {
await connection.loadExtension('myproj::myext', false, false)
expect(chattySendAndReceiveSpy).toHaveBeenCalledWith('page:load', {
pushHistory: false,
url: '/embed/extensions/myproj::myext?embed_domain=http%3A%2F%2Flocalhost%3A9876&sdk=2',
url: '/embed/extensions/myproj::myext?embed_domain=http%3A%2F%2Flocalhost%3A9876&sdk=3',
})
})

Expand All @@ -191,7 +191,7 @@ describe('EmmbedConnection', () => {
await loadPromise
expect(chattySendAndReceiveSpy).toHaveBeenCalledWith('page:load', {
pushHistory: false,
url: '/embed/extensions/myproj::myext?embed_domain=http%3A%2F%2Flocalhost%3A9876&sdk=2',
url: '/embed/extensions/myproj::myext?embed_domain=http%3A%2F%2Flocalhost%3A9876&sdk=3',
})
})

Expand All @@ -204,7 +204,7 @@ describe('EmmbedConnection', () => {
await connection.preload(false, false)
expect(chattySendAndReceiveSpy).toHaveBeenCalledWith('page:load', {
pushHistory: false,
url: '/embed/preload?embed_domain=http%3A%2F%2Flocalhost%3A9876&sdk=2',
url: '/embed/preload?embed_domain=http%3A%2F%2Flocalhost%3A9876&sdk=3',
})
})

Expand All @@ -219,7 +219,7 @@ describe('EmmbedConnection', () => {
await loadPromise
expect(chattySendAndReceiveSpy).toHaveBeenCalledWith('page:load', {
pushHistory: false,
url: '/embed/preload?embed_domain=http%3A%2F%2Flocalhost%3A9876&sdk=2',
url: '/embed/preload?embed_domain=http%3A%2F%2Flocalhost%3A9876&sdk=3',
})
})

Expand All @@ -228,32 +228,32 @@ describe('EmmbedConnection', () => {
const loadPromise = connection.loadExplore('mymodel/myview')
mockHostBuilder.fireEventForHandler('page:changed', {
page: {
url: '/embed/explore/mymodel/myview?embed_domain=http%3A%2F%2Flocalhost%3A9876&sdk=2',
url: '/embed/explore/mymodel/myview?embed_domain=http%3A%2F%2Flocalhost%3A9876&sdk=3',
},
})
await loadPromise
expect(connection.getPageType()).toBe('explore')
mockHostBuilder.fireEventForHandler('page:changed', {
page: {
url: '/embed/dashboards/42?embed_domain=http%3A%2F%2Flocalhost%3A9876&sdk=2',
url: '/embed/dashboards/42?embed_domain=http%3A%2F%2Flocalhost%3A9876&sdk=3',
},
})
expect(connection.getPageType()).toBe('dashboards')
mockHostBuilder.fireEventForHandler('page:changed', {
page: {
url: '/embed/looks/42?embed_domain=http%3A%2F%2Flocalhost%3A9876&sdk=2',
url: '/embed/looks/42?embed_domain=http%3A%2F%2Flocalhost%3A9876&sdk=3',
},
})
expect(connection.getPageType()).toBe('looks')
mockHostBuilder.fireEventForHandler('page:changed', {
page: {
url: '/embed/extensions/myproj::myapp?embed_domain=http%3A%2F%2Flocalhost%3A9876&sdk=2',
url: '/embed/extensions/myproj::myapp?embed_domain=http%3A%2F%2Flocalhost%3A9876&sdk=3',
},
})
expect(connection.getPageType()).toBe('extensions')
mockHostBuilder.fireEventForHandler('page:changed', {
page: {
url: '/embed/preload?embed_domain=http%3A%2F%2Flocalhost%3A9876&sdk=2',
url: '/embed/preload?embed_domain=http%3A%2F%2Flocalhost%3A9876&sdk=3',
},
})
expect(connection.getPageType()).toBe('preload')
Expand All @@ -274,18 +274,18 @@ describe('EmmbedConnection', () => {
let loadPromise = connection.loadDashboard('42')
mockHostBuilder.fireEventForHandler('page:changed', {
page: {
url: '/embed/dashboards/42?embed_domain=http%3A%2F%2Flocalhost%3A9876&sdk=2',
url: '/embed/dashboards/42?embed_domain=http%3A%2F%2Flocalhost%3A9876&sdk=3',
},
})
await loadPromise
expect(chattySendAndReceiveSpy).toHaveBeenCalledWith('page:load', {
pushHistory: false,
url: '/embed/dashboards/42?embed_domain=http%3A%2F%2Flocalhost%3A9876&sdk=2',
url: '/embed/dashboards/42?embed_domain=http%3A%2F%2Flocalhost%3A9876&sdk=3',
})
loadPromise = connection.loadDashboard('43')
mockHostBuilder.fireEventForHandler('page:changed', {
page: {
url: '/embed/dashboards/43?embed_domain=http%3A%2F%2Flocalhost%3A9876&sdk=2',
url: '/embed/dashboards/43?embed_domain=http%3A%2F%2Flocalhost%3A9876&sdk=3',
},
})
await loadPromise
Expand All @@ -297,7 +297,7 @@ describe('EmmbedConnection', () => {
const loadPromise = connection.loadDashboard('42')
mockHostBuilder.fireEventForHandler('page:changed', {
page: {
url: '/embed/dashboards/42?embed_domain=http%3A%2F%2Flocalhost%3A9876&sdk=2',
url: '/embed/dashboards/42?embed_domain=http%3A%2F%2Flocalhost%3A9876&sdk=3',
},
})
await loadPromise
Expand Down

0 comments on commit d848f1b

Please sign in to comment.