Skip to content

Commit

Permalink
Backend request improvements
Browse files Browse the repository at this point in the history
* Add the `fullResponse` flag as an option for `makeRequest` to return
  the raw HTTP response
* Deprecate the `environment_name` field when creating a Connect token,
  in favour of the `environment` name in the client's constructor
  • Loading branch information
jverce committed Nov 13, 2024
1 parent 70aca9e commit eb039dd
Show file tree
Hide file tree
Showing 3 changed files with 18 additions and 3 deletions.
4 changes: 2 additions & 2 deletions packages/sdk/package-lock.json

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

2 changes: 1 addition & 1 deletion packages/sdk/package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "@pipedream/sdk",
"version": "1.0.0",
"version": "1.0.1",
"description": "Pipedream SDK",
"main": "dist/server/index.js",
"module": "dist/server/index.js",
Expand Down
15 changes: 15 additions & 0 deletions packages/sdk/src/server/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -87,6 +87,9 @@ export type ConnectTokenOpts = {
/**
* Specify the environment ("production" or "development") to use for the
* account connection flow. Defaults to "production".
*
* @deprecated in favor of the `environment` field in `BackendClientOpts`.
* This field is completely ignored.
*/
environment_name?: string;
};
Expand Down Expand Up @@ -292,6 +295,14 @@ interface RequestOptions extends Omit<RequestInit, "headers" | "body"> {
* The body of the request.
*/
body?: Record<string, unknown> | string | FormData | URLSearchParams | null;

/**
* A flag to indicate that you want to get the full response object, not just
* the body. Note that when this flag is set, responses with unsuccessful HTTP
* statuses won't throw exceptions. Instead, you'll need to check the status
* code in the response object. Defaults to false.
*/
fullResponse?: boolean;
}

/**
Expand Down Expand Up @@ -422,6 +433,7 @@ export class BackendClient {
body,
method = "GET",
baseURL = this.baseApiUrl,
fullResponse = false,
...fetchOpts
} = opts;

Expand Down Expand Up @@ -472,6 +484,9 @@ export class BackendClient {
}

const response: Response = await fetch(url.toString(), requestOptions);
if (fullResponse) {
return response as unknown as T;
}

if (!response.ok) {
const errorBody = await response.text();
Expand Down

0 comments on commit eb039dd

Please sign in to comment.