File tree Expand file tree Collapse file tree 3 files changed +27
-7
lines changed Expand file tree Collapse file tree 3 files changed +27
-7
lines changed Original file line number Diff line number Diff line change @@ -28,6 +28,14 @@ const commonBuildOptions = {
28
28
} ,
29
29
} ;
30
30
31
+ /**
32
+ * process.env.CLIENT_BUNDLE values:
33
+ *
34
+ * - index.js - browser-esm
35
+ * - index.browser.cjs - browser-cjs
36
+ * - index.node.cjs - node-cjs
37
+ */
38
+
31
39
// We build two CJS bundles: for browser and for node. The latter one can be
32
40
// used e.g. during SSR (although it makes little sence to SSR chat, but still
33
41
// nice for import not to break on server).
@@ -43,7 +51,7 @@ const bundles = [
43
51
platform,
44
52
define : {
45
53
...commonBuildOptions . define ,
46
- 'process.env.BUILD ' : JSON . stringify ( `${ platform } -cjs` ) ,
54
+ 'process.env.CLIENT_BUNDLE ' : JSON . stringify ( `${ platform } -cjs` ) ,
47
55
} ,
48
56
} ) ) ,
49
57
// ESM (browser only)
@@ -55,7 +63,7 @@ const bundles = [
55
63
platform : 'browser' ,
56
64
define : {
57
65
...commonBuildOptions . define ,
58
- 'process.env.BUILD ' : JSON . stringify ( ` browser-esm` ) ,
66
+ 'process.env.CLIENT_BUNDLE ' : JSON . stringify ( ' browser-esm' ) ,
59
67
} ,
60
68
} ,
61
69
]
Original file line number Diff line number Diff line change @@ -2923,12 +2923,23 @@ export class StreamChat<StreamChatGenerics extends ExtendableGenerics = DefaultG
2923
2923
if ( this . userAgent ) {
2924
2924
return this . userAgent ;
2925
2925
}
2926
+
2926
2927
const version = process . env . PKG_VERSION ;
2928
+ const clientBundle = process . env . CLIENT_BUNDLE ;
2929
+
2930
+ let userAgentString = '' ;
2927
2931
if ( this . sdkIdentifier ) {
2928
- return `stream-chat-${ this . sdkIdentifier . name } -v${ this . sdkIdentifier . version } -llc-v${ version } ` ;
2932
+ userAgentString = `stream-chat-${ this . sdkIdentifier . name } -v${ this . sdkIdentifier . version } -llc-v${ version } ` ;
2929
2933
} else {
2930
- return `stream-chat-js-v${ version } -${ this . node ? 'node' : 'browser' } ` ;
2934
+ userAgentString = `stream-chat-js-v${ version } -${ this . node ? 'node' : 'browser' } ` ;
2931
2935
}
2936
+
2937
+ const additionalOptions = ( [
2938
+ // reports which bundle is being picked from the exports
2939
+ [ 'client_bundle' , clientBundle ] ,
2940
+ ] as const ) . map ( ( [ key , value ] ) => `${ key } =${ value ?? '' } ` ) ;
2941
+
2942
+ return [ userAgentString , ...additionalOptions ] . join ( '|' ) ;
2932
2943
}
2933
2944
2934
2945
/**
Original file line number Diff line number Diff line change @@ -644,6 +644,7 @@ describe('StreamChat.queryChannels', async () => {
644
644
645
645
describe ( 'X-Stream-Client header' , ( ) => {
646
646
process . env . PKG_VERSION = '1.2.3' ;
647
+ process . env . CLIENT_BUNDLE = 'browser-esm' ;
647
648
let client ;
648
649
649
650
beforeEach ( async ( ) => {
@@ -653,21 +654,21 @@ describe('X-Stream-Client header', () => {
653
654
it ( 'server-side integration' , ( ) => {
654
655
const userAgent = client . getUserAgent ( ) ;
655
656
656
- expect ( userAgent ) . to . be . equal ( 'stream-chat-js-v1.2.3-node' ) ;
657
+ expect ( userAgent ) . to . be . equal ( 'stream-chat-js-v1.2.3-node|client_bundle=browser-esm ' ) ;
657
658
} ) ;
658
659
659
660
it ( 'client-side integration' , ( ) => {
660
661
client . node = false ;
661
662
const userAgent = client . getUserAgent ( ) ;
662
663
663
- expect ( userAgent ) . to . be . equal ( 'stream-chat-js-v1.2.3-browser' ) ;
664
+ expect ( userAgent ) . to . be . equal ( 'stream-chat-js-v1.2.3-browser|client_bundle=browser-esm ' ) ;
664
665
} ) ;
665
666
666
667
it ( 'SDK integration' , ( ) => {
667
668
client . sdkIdentifier = { name : 'react' , version : '2.3.4' } ;
668
669
const userAgent = client . getUserAgent ( ) ;
669
670
670
- expect ( userAgent ) . to . be . equal ( 'stream-chat-react-v2.3.4-llc-v1.2.3' ) ;
671
+ expect ( userAgent ) . to . be . equal ( 'stream-chat-react-v2.3.4-llc-v1.2.3|client_bundle=browser-esm ' ) ;
671
672
} ) ;
672
673
673
674
it ( 'setUserAgent is now deprecated' , ( ) => {
You can’t perform that action at this time.
0 commit comments