File tree Expand file tree Collapse file tree 3 files changed +34
-9
lines changed
packages/browser/src/plugins/remote-loader Expand file tree Collapse file tree 3 files changed +34
-9
lines changed Original file line number Diff line number Diff line change 1+ ---
2+ ' @segment/analytics-next ' : patch
3+ ---
4+
5+ Fix staging-only bug where integrations URL would not respect CDN URL overrides
Original file line number Diff line number Diff line change @@ -89,6 +89,31 @@ describe('Remote Loader', () => {
8989 expect ( loader . loadScript ) . toHaveBeenCalledWith ( 'foo.com/actions/file.js' )
9090 } )
9191
92+ it ( 'should work if the cdn is staging' , async ( ) => {
93+ const stagingURL = 'https://cdn.segment.build/actions/foo.js'
94+
95+ window . analytics = { }
96+ window . analytics . _cdn = 'foo.com'
97+ await remoteLoader (
98+ {
99+ integrations : { } ,
100+ remotePlugins : [
101+ {
102+ name : 'remote plugin' ,
103+ creationName : 'remote plugin' ,
104+ url : stagingURL ,
105+ libraryName : 'testPlugin' ,
106+ settings : { } ,
107+ } ,
108+ ] ,
109+ } ,
110+ { } ,
111+ { }
112+ )
113+
114+ expect ( loader . loadScript ) . toHaveBeenCalledWith ( 'foo.com/actions/foo.js' )
115+ } )
116+
92117 it ( 'should attempt calling the library' , async ( ) => {
93118 await remoteLoader (
94119 {
Original file line number Diff line number Diff line change @@ -175,6 +175,7 @@ export async function remoteLoader(
175175 async ( remotePlugin ) => {
176176 if ( isPluginDisabled ( userIntegrations , remotePlugin ) ) return
177177 try {
178+ const defaultCdn = new RegExp ( 'https://cdn.segment.(com|build)' )
178179 if ( obfuscate ) {
179180 const urlSplit = remotePlugin . url . split ( '/' )
180181 const name = urlSplit [ urlSplit . length - 2 ]
@@ -183,20 +184,14 @@ export async function remoteLoader(
183184 btoa ( name ) . replace ( / = / g, '' )
184185 )
185186 try {
186- await loadScript (
187- obfuscatedURL . replace ( 'https://cdn.segment.com' , cdn )
188- )
187+ await loadScript ( obfuscatedURL . replace ( defaultCdn , cdn ) )
189188 } catch ( error ) {
190189 // Due to syncing concerns it is possible that the obfuscated action destination (or requested version) might not exist.
191190 // We should use the unobfuscated version as a fallback.
192- await loadScript (
193- remotePlugin . url . replace ( 'https://cdn.segment.com' , cdn )
194- )
191+ await loadScript ( remotePlugin . url . replace ( defaultCdn , cdn ) )
195192 }
196193 } else {
197- await loadScript (
198- remotePlugin . url . replace ( 'https://cdn.segment.com' , cdn )
199- )
194+ await loadScript ( remotePlugin . url . replace ( defaultCdn , cdn ) )
200195 }
201196
202197 const libraryName = remotePlugin . libraryName
You can’t perform that action at this time.
0 commit comments