Skip to content

Commit 40d70c7

Browse files
committed
Port browser-specific logic from the old SDK
1 parent 3b62461 commit 40d70c7

File tree

5 files changed

+582
-4
lines changed

5 files changed

+582
-4
lines changed

.fernignore

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -19,6 +19,7 @@ MIGRATE.md
1919
# Custom Pipedream client files
2020
src/api/resources/index.ts
2121
src/api/types/index.ts
22+
src/browser/index.ts
2223
src/index.ts
2324
src/wrapper
2425

MIGRATE.md

Lines changed: 96 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -59,6 +59,9 @@ the latest version.
5959
- [Request options](#request-options)
6060
- [Abort signals](#abort-signals)
6161
- [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)
6265
- [Additional namespaces](#additional-namespaces)
6366
- [Partial migration](#partial-migration)
6467
- [Important removed functionality](#important-removed-functionality)
@@ -148,6 +151,11 @@ const frontendClient = createFrontendClient({
148151

149152
#### v2.x (new)
150153

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+
151159
```javascript
152160
import { PipedreamClient } from '@pipedream/sdk';
153161

@@ -158,6 +166,44 @@ const frontendClient = new PipedreamClient({
158166
});
159167
```
160168

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+
161207
### Environment variables
162208

163209
The v2.x SDK supports automatic configuration via environment variables:
@@ -715,6 +761,55 @@ console.log(response.data); // Parsed response data
715761
console.log(response.rawResponse); // Original Response object
716762
```
717763

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+
718813
## Additional namespaces
719814

720815
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
740835
install the new SDK with an alias:
741836

742837
```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
744839
```
745840

746841
Then, in your code, you can import the new SDK with the alias:

package.json

Lines changed: 23 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
{
22
"name": "@pipedream/sdk",
3-
"version": "2.0.0-rc.3",
3+
"version": "2.0.0-rc.4",
44
"private": false,
55
"repository": "github:PipedreamHQ/pipedream-sdk-typescript",
66
"type": "commonjs",
@@ -9,6 +9,28 @@
99
"types": "./dist/cjs/index.d.ts",
1010
"exports": {
1111
".": {
12+
"types": "./dist/cjs/index.d.ts",
13+
"browser": {
14+
"types": "./dist/esm/browser/index.d.mts",
15+
"import": "./dist/esm/browser/index.mjs",
16+
"default": "./dist/esm/browser/index.mjs"
17+
},
18+
"import": {
19+
"types": "./dist/esm/index.d.mts",
20+
"default": "./dist/esm/index.mjs"
21+
},
22+
"require": {
23+
"types": "./dist/cjs/index.d.ts",
24+
"default": "./dist/cjs/index.js"
25+
},
26+
"default": "./dist/cjs/index.js"
27+
},
28+
"./browser": {
29+
"types": "./dist/esm/browser/index.d.mts",
30+
"import": "./dist/esm/browser/index.mjs",
31+
"default": "./dist/esm/browser/index.mjs"
32+
},
33+
"./server": {
1234
"types": "./dist/cjs/index.d.ts",
1335
"import": {
1436
"types": "./dist/esm/index.d.mts",

src/Client.ts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -73,8 +73,8 @@ export class PipedreamClient {
7373
"x-pd-environment": _options?.projectEnvironment,
7474
"X-Fern-Language": "JavaScript",
7575
"X-Fern-SDK-Name": "@pipedream/sdk",
76-
"X-Fern-SDK-Version": "2.0.0-rc.3",
77-
"User-Agent": "@pipedream/sdk/2.0.0-rc.3",
76+
"X-Fern-SDK-Version": "2.0.0-rc.4",
77+
"User-Agent": "@pipedream/sdk/2.0.0-rc.4",
7878
"X-Fern-Runtime": core.RUNTIME.type,
7979
"X-Fern-Runtime-Version": core.RUNTIME.version,
8080
},

0 commit comments

Comments
 (0)