@@ -59,6 +59,9 @@ the latest version.
59
59
- [ Request options] ( #request-options )
60
60
- [ Abort signals] ( #abort-signals )
61
61
- [ Raw response access] ( #raw-response-access )
62
+ - [ Browser/Server Environment Separation] ( #browserserver-environment-separation )
63
+ - [ Package.json Export Structure] ( #packagejson-export-structure )
64
+ - [ Import Recommendations] ( #import-recommendations )
62
65
- [ Additional namespaces] ( #additional-namespaces )
63
66
- [ Partial migration] ( #partial-migration )
64
67
- [ Important removed functionality] ( #important-removed-functionality )
@@ -148,6 +151,11 @@ const frontendClient = createFrontendClient({
148
151
149
152
#### v2.x (new)
150
153
154
+ The v2.x SDK provides two options for browser-side usage:
155
+
156
+ ** Option 1: Using PipedreamClient with connect token (for simple token-based
157
+ auth)**
158
+
151
159
``` javascript
152
160
import { PipedreamClient } from ' @pipedream/sdk' ;
153
161
@@ -158,6 +166,44 @@ const frontendClient = new PipedreamClient({
158
166
});
159
167
```
160
168
169
+ ** Option 2: Using BrowserClient with token callback (for dynamic token
170
+ management)**
171
+
172
+ ``` javascript
173
+ // Explicit browser import (recommended for browser apps)
174
+ import { createFrontendClient , BrowserClient } from ' @pipedream/sdk/browser' ;
175
+
176
+ // Or automatic browser resolution
177
+ import { createFrontendClient , BrowserClient } from ' @pipedream/sdk' ;
178
+
179
+ const client = createFrontendClient ({
180
+ tokenCallback: async ({ externalUserId }) => {
181
+ // Call your backend to get a connect token
182
+ const response = await fetch (' /api/pipedream/token' , {
183
+ method: ' POST' ,
184
+ headers: { ' Content-Type' : ' application/json' },
185
+ body: JSON .stringify ({ externalUserId })
186
+ });
187
+ return response .json ();
188
+ },
189
+ externalUserId: ' user-123'
190
+ });
191
+
192
+ // Connect an account using Pipedream Connect
193
+ client .connectAccount ({
194
+ app: ' github' ,
195
+ onSuccess : (result ) => {
196
+ console .log (' Account connected:' , result .id );
197
+ },
198
+ onError : (error ) => {
199
+ console .error (' Connection failed:' , error);
200
+ }
201
+ });
202
+
203
+ // Get user's accounts
204
+ const accounts = await client .getAccounts ();
205
+ ```
206
+
161
207
### Environment variables
162
208
163
209
The v2.x SDK supports automatic configuration via environment variables:
@@ -715,6 +761,55 @@ console.log(response.data); // Parsed response data
715
761
console .log (response .rawResponse ); // Original Response object
716
762
```
717
763
764
+ ## Browser/Server Environment Separation
765
+
766
+ The v2.x SDK provides proper environment separation to ensure browser-safe
767
+ imports without Node.js dependencies.
768
+
769
+ ### Package.json Export Structure
770
+
771
+ The SDK uses conditional exports to automatically serve the right code:
772
+
773
+ ``` json
774
+ {
775
+ "exports" : {
776
+ "." : {
777
+ "browser" : " ./dist/esm/browser/index.mjs" , // Browser gets browser-only code
778
+ "import" : " ./dist/esm/index.mjs" , // Node.js gets full functionality
779
+ "require" : " ./dist/cjs/index.js"
780
+ },
781
+ "./browser" : {
782
+ "import" : " ./dist/esm/browser/index.mjs" // Explicit browser import
783
+ },
784
+ "./server" : {
785
+ "import" : " ./dist/esm/index.mjs" , // Explicit server import
786
+ "require" : " ./dist/cjs/index.js"
787
+ }
788
+ }
789
+ }
790
+ ```
791
+
792
+ ### Import Recommendations
793
+
794
+ ``` typescript
795
+ // For browser applications - avoids Node.js dependencies
796
+ import { BrowserClient , createFrontendClient } from ' @pipedream/sdk/browser' ;
797
+
798
+ // For server applications - includes full functionality
799
+ import { Pipedream } from ' @pipedream/sdk/server' ;
800
+
801
+ // Automatic resolution (recommended for most cases)
802
+ import { Pipedream } from ' @pipedream/sdk' ; // Server environments
803
+ import { BrowserClient } from ' @pipedream/sdk' ; // Browser environments
804
+ ```
805
+
806
+ This ensures:
807
+
808
+ - ** Browser bundlers** automatically get the browser-safe version
809
+ - ** Node.js environments** get the full SDK with all server functionality
810
+ - ** Smaller bundle sizes** for browser applications
811
+ - ** No Node.js dependency errors** in browser builds
812
+
718
813
## Additional namespaces
719
814
720
815
The v2.x SDK includes several new namespaces not available in v1.x:
@@ -740,7 +835,7 @@ incrementally without breaking your existing codebase. To do this, you can
740
835
install the new SDK with an alias:
741
836
742
837
``` bash
743
- npm install @pipedream/sdk-v2@npm:@pipedream/sdk@^2.0.0-rc.3 --save
838
+ npm install @pipedream/sdk-v2@npm:@pipedream/sdk@^2.0.0-rc.4 --save
744
839
```
745
840
746
841
Then, in your code, you can import the new SDK with the alias:
0 commit comments