Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
8 changes: 8 additions & 0 deletions packages/sdk/CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,6 +1,14 @@
<!-- markdownlint-disable MD024 -->
# Changelog

## [1.0.6] - 2024-11-20

### Changed

- Use client Connect tokens to make api calls directly from the client.
- Deprecated the `environments` property on `createFrontendClient` since it is now
stored in the token

Comment on lines +8 to +11
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

🛠️ Refactor suggestion

Enhance the deprecation notice with migration guidance

The deprecation notice for the environments property should include:

  • The rationale behind the deprecation
  • Migration steps for existing users
  • Timeline for removal (if planned)

Consider updating the changelog entry like this:

- Deprecated the `environments` property on `createFrontendClient` since it is now
  stored in the token
+ Deprecated the `environments` property on `createFrontendClient`. The environment
+ configuration is now embedded in the Connect token for improved security and
+ simplified setup. To migrate:
+ 1. Remove the environments property from createFrontendClient calls
+ 2. Ensure your Connect tokens are configured with the correct environment
+ This property will be removed in version 2.0.0
📝 Committable suggestion

‼️ IMPORTANT
Carefully review the code before committing. Ensure that it accurately replaces the highlighted code, contains no missing lines, and has no issues with indentation. Thoroughly test & benchmark the code to ensure it meets the requirements.

Suggested change
- Use client Connect tokens to make api calls directly from the client.
- Deprecated the `environments` property on `createFrontendClient` since it is now
stored in the token
- Use client Connect tokens to make api calls directly from the client.
- Deprecated the `environments` property on `createFrontendClient`. The environment
configuration is now embedded in the Connect token for improved security and
simplified setup. To migrate:
1. Remove the environments property from createFrontendClient calls
2. Ensure your Connect tokens are configured with the correct environment
This property will be removed in version 2.0.0

## [1.0.5] - 2024-11-18

### Changed
Expand Down
80 changes: 70 additions & 10 deletions packages/sdk/package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

41 changes: 29 additions & 12 deletions packages/sdk/package.json
Original file line number Diff line number Diff line change
@@ -1,17 +1,27 @@
{
"name": "@pipedream/sdk",
"version": "1.0.5",
"version": "1.0.6",
"description": "Pipedream SDK",
"main": "dist/server/index.js",
"module": "dist/server/index.js",
"types": "dist/server/index.d.ts",
"browser": "./dist/browser/index.js",
"main": "dist/server/server/index.js",
"module": "dist/server/server/index.js",
"types": "dist/server/server/index.d.ts",
"browser": "./dist/browser/browser/index.js",
"exports": {
".": {
"browser": "./dist/browser/index.js",
"import": "./dist/server/index.js",
"require": "./dist/server/index.js",
"default": "./dist/server/index.js"
"browser": "./dist/browser/browser/index.js",
"import": "./dist/server/server/index.js",
"require": "./dist/server/server/index.js",
"default": "./dist/server/server/index.js"
},
"./server": {
"import": "./dist/server/server/index.js",
"require": "./dist/server/server/index.js",
"types": "./dist/server/server/index.d.ts"
},
"./browser": {
"import": "./dist/browser/browser/index.js",
"require": "./dist/browser/browser/index.js",
"types": "./dist/browser/browser/index.d.ts"
}
},
"engines": {
Expand All @@ -25,28 +35,35 @@
"access": "public"
},
"scripts": {
"lint": "eslint --fix --ext .ts src",
"prepublish": "rm -rf dist && npm run build",
"build": "npm run build:node && npm run build:browser",
"build:node": "tsc -p tsconfig.node.json",
"build:browser": "tsc -p tsconfig.browser.json",
"test": "jest",
"watch": "nodemon --watch src --ext ts --exec 'npm run build'"
"watch": "nodemon --watch src --ext ts --exec 'npm run build'",
"cli": "node dist/server/server/cli.js"
},
"files": [
"dist"
],
"devDependencies": {
"@types/fetch-mock": "^7.3.8",
"@types/jest": "^29.5.13",
"@types/node": "^20.14.9",
"@types/node": "^20.17.6",
"@types/rails__actioncable": "^6.1.11",
"@types/simple-oauth2": "^5.0.7",
"@types/ws": "^8.5.13",
"jest": "^29.7.0",
"jest-fetch-mock": "^3.0.3",
"nodemon": "^3.1.7",
"ts-jest": "^29.2.5",
"typescript": "^5.5.2"
},
"dependencies": {
"simple-oauth2": "^5.1.0"
"@rails/actioncable": "^8.0.0",
"commander": "^12.1.0",
"simple-oauth2": "^5.1.0",
"ws": "^8.18.0"
}
}
24 changes: 24 additions & 0 deletions packages/sdk/src/browser/async.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
import { AsyncResponseManager } from "../shared/async";
import type { AsyncResponseManagerOpts } from "../shared/async";

export type BrowserAsyncResponseManagerOpts = {
apiHost: string;
getConnectToken: () => Promise<string>;
};

export class BrowserAsyncResponseManager extends AsyncResponseManager {
private browserOpts: BrowserAsyncResponseManagerOpts;

constructor(opts: BrowserAsyncResponseManagerOpts) {
super();
this.browserOpts = opts;
}

protected override async getOpts(): Promise<AsyncResponseManagerOpts> {
const token = await this.browserOpts.getConnectToken();
const url = `wss://${this.browserOpts.apiHost}/websocket?ctok=${token}`;
return {
url,
};
}
Comment on lines +17 to +23
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

⚠️ Potential issue

Add error handling and security enhancements

The WebSocket URL construction and token handling could benefit from additional security measures and error handling:

  1. Token retrieval should have proper error handling
  2. Consider moving token to WebSocket headers instead of URL query parameters to prevent logging exposure
  3. Add token format validation before use

Here's a suggested implementation:

  protected override async getOpts(): Promise<AsyncResponseManagerOpts> {
-   const token = await this.browserOpts.getConnectToken();
-   const url = `wss://${this.browserOpts.apiHost}/websocket?ctok=${token}`;
+   let token: string;
+   try {
+     token = await this.browserOpts.getConnectToken();
+     if (!token?.trim()) {
+       throw new Error('Invalid token received');
+     }
+   } catch (error) {
+     throw new Error(`Failed to retrieve connect token: ${error.message}`);
+   }
+   
+   const url = new URL(`wss://${this.browserOpts.apiHost}/websocket`);
    return {
      url,
+     headers: {
+       'Authorization': `Bearer ${token}`
+     }
    };
  }

Committable suggestion skipped: line range outside the PR's diff.

}
Loading
Loading