Skip to content

Commit c673fb7

Browse files
authored
Fix issues with rails/actioncable in the server sdk (#14714)
* Fix issues with long running asynchronous calls in the server sdk
1 parent e515be2 commit c673fb7

File tree

4 files changed

+29
-4
lines changed

4 files changed

+29
-4
lines changed

packages/sdk/CHANGELOG.md

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,15 @@
11
<!-- markdownlint-disable MD024 -->
22
# Changelog
33

4+
## [1.0.7] - 2024-11-21
5+
6+
### Changed
7+
8+
- The backend client now correctly uses asynchronous messaging to handle long running
9+
operations.
10+
- Updated the backend command line tool to respect the `ENVIRONMENT` env variable
11+
if set.
12+
413
## [1.0.6] - 2024-11-20
514

615
### Changed

packages/sdk/package.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
{
22
"name": "@pipedream/sdk",
3-
"version": "1.0.6",
3+
"version": "1.0.7",
44
"description": "Pipedream SDK",
55
"main": "dist/server/server/index.js",
66
"module": "dist/server/server/index.js",

packages/sdk/src/server/async.ts

Lines changed: 15 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,11 @@ import type { AsyncResponseManagerOpts } from "../shared/async";
44
import { adapters } from "@rails/actioncable";
55
import * as WS from "ws";
66

7+
declare global {
8+
function addEventListener(type: string, listener: () => void): void;
9+
function removeEventListener(type: string, listener: () => void): void;
10+
}
11+
712
export type ServerAsyncResponseManagerOpts = {
813
apiHost: string;
914
getOauthToken: () => Promise<AccessToken> | AccessToken;
@@ -16,12 +21,20 @@ export class ServerAsyncResponseManager extends AsyncResponseManager {
1621
constructor(opts: ServerAsyncResponseManagerOpts) {
1722
super();
1823
this.serverOpts = opts;
24+
// eslint-disable-next-line @typescript-eslint/no-empty-function
25+
global.addEventListener = () => {};
26+
// eslint-disable-next-line @typescript-eslint/no-empty-function
27+
global.removeEventListener = () => {};
1928
if (typeof adapters.WebSocket === "undefined")
20-
adapters.WebSocket == WS;
29+
adapters.WebSocket = WS as unknown as WebSocket;
2130
}
2231

2332
protected override async getOpts(): Promise<AsyncResponseManagerOpts> {
24-
const token = await this.serverOpts.getOauthToken();
33+
const oauthToken = await this.serverOpts.getOauthToken();
34+
if (!oauthToken?.token?.access_token) {
35+
throw new Error("Invalid OAuth token structure");
36+
}
37+
const token = oauthToken.token.access_token;
2538
const projectId = await this.serverOpts.getProjectId();
2639
return {
2740
url: `wss://${this.serverOpts.apiHost}/websocket?oauth_token=${token}`,

packages/sdk/src/server/cli.ts

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@ import { createBackendClient } from "./index";
22
import { program } from "commander";
33

44
const {
5-
CLIENT_ID, CLIENT_SECRET, PROJECT_ID, API_HOST,
5+
CLIENT_ID, CLIENT_SECRET, PROJECT_ID, API_HOST, ENVIRONMENT,
66
} = process.env;
77

88
if (!CLIENT_ID || !CLIENT_SECRET || !PROJECT_ID) {
@@ -17,6 +17,9 @@ const client = createBackendClient({
1717
},
1818
projectId: PROJECT_ID,
1919
apiHost: API_HOST,
20+
environment: ENVIRONMENT === "production"
21+
? "production"
22+
: "development",
2023
});
2124

2225
program

0 commit comments

Comments
 (0)