-
Couldn't load subscription status.
- Fork 5.5k
Je/connect proxy support #15495
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Je/connect proxy support #15495
Changes from 6 commits
e560380
37320f8
5e45ac5
8b8a8b4
3ec43b5
1e87d88
f73fe79
9ab1113
76a8ff7
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|
|
|
@@ -4,7 +4,7 @@ | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| import * as oauth from "oauth4webapi"; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| import { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| Account, BaseClient, type AppInfo, type ConnectTokenResponse, | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| Account, BaseClient, type AppInfo, type ConnectTokenResponse, type RequestOptions | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| Account, BaseClient, type AppInfo, type ConnectTokenResponse, type RequestOptions | |
| Account, BaseClient, type AppInfo, type ConnectTokenResponse, type RequestOptions, |
🧰 Tools
🪛 GitHub Check: Lint Code Base
[failure] 7-7:
Missing trailing comma
🪛 ESLint
[error] 7-8: Missing trailing comma.
(comma-dangle)
🪛 GitHub Actions: Pull Request Checks
[error] 7-7: Missing trailing comma
Outdated
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I think we should list all supported methods as a type like get | post | put | delete
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
🛠️ Refactor suggestion
Fix type definition issues.
The MakeProxyRequestOpts type definition has several issues:
- The JSDoc comment is incorrect (copied from GetAccountByIdOpts)
- Contains commented out code
- Uses
anytype which should be properly typed
/**
- * Parameters for the retrieval of an account from the Connect API
+ * Options for making a proxy request through the Connect API
*/
export type MakeProxyRequestOpts = {
/**
- * Whether to retrieve the account's credentials or not.
+ * The HTTP method to use for the proxy request
*/
method: string;
+ /**
+ * Headers to include in the proxy request
+ */
headers?: Record<string, string>;
- //headers: Record<string, string>;
+ /**
+ * The request body
+ */
- body?: any
+ body?: Record<string, unknown> | string | FormData | URLSearchParams | null;
};📝 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.
| /** | |
| * Parameters for the retrieval of an account from the Connect API | |
| */ | |
| export type MakeProxyRequestOpts = { | |
| /** | |
| * Whether to retrieve the account's credentials or not. | |
| */ | |
| method: string; | |
| headers?: Record<string, string>; | |
| //headers: Record<string, string>; | |
| body?: any | |
| }; | |
| /** | |
| * Options for making a proxy request through the Connect API | |
| */ | |
| export type MakeProxyRequestOpts = { | |
| /** | |
| * The HTTP method to use for the proxy request | |
| */ | |
| method: string; | |
| /** | |
| * Headers to include in the proxy request | |
| */ | |
| headers?: Record<string, string>; | |
| /** | |
| * The request body | |
| */ | |
| body?: Record<string, unknown> | string | FormData | URLSearchParams | null; | |
| }; |
🧰 Tools
🪛 GitHub Check: Lint Code Base
[failure] 120-120:
Unexpected any. Specify a different type
🪛 ESLint
[error] 120-120: Unexpected any. Specify a different type.
(@typescript-eslint/no-explicit-any)
Check failure on line 396 in packages/sdk/src/server/index.ts
GitHub Actions / Lint Code Base
Unexpected any. Specify a different type
Outdated
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
🛠️ Refactor suggestion
Improve type safety and error handling in proxy request implementation.
The implementation should:
- Use proper types instead of
any - Add input validation
- Handle potential base64 encoding errors
- Fix indentation
- public makeProxyRequest(url: string, query: any, opts: MakeProxyRequestOpts): Promise<any> {
+ public makeProxyRequest(
+ url: string,
+ query: Record<string, string | number | boolean | null>,
+ opts: MakeProxyRequestOpts
+ ): Promise<unknown> {
+ if (!url?.trim()) {
+ throw new Error("URL is required");
+ }
+ let url64: string;
+ try {
url64 = btoa(url).replace(/\+/g, "-")
- .replace(/\//g, "_")
- .replace(/=+$/, "");
+ .replace(/\//g, "_")
+ .replace(/=+$/, "");
+ } catch (error) {
+ throw new Error(`Failed to encode URL: ${error.message}`);
+ }
const headers = opts.headers || {};
const newHeaders = Object.keys(headers).reduce<{ [key: string]: string }>((acc, key) => {
acc[`x-pd-proxy-${key}`] = headers[key];
return acc;
}, {});
const newOpts: RequestOptions = {
method: opts.method,
headers: newHeaders,
params: query,
}
if (opts.body) {
newOpts.body = opts.body
}
return this.makeConnectRequest(`/proxy/${url64}`, newOpts);
}📝 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.
| public makeProxyRequest(url: string, query: any, opts: MakeProxyRequestOpts): Promise<any> { | |
| const url64 = btoa(url).replace(/\+/g, "-") | |
| .replace(/\//g, "_") | |
| .replace(/=+$/, ""); | |
| const headers = opts.headers || {}; | |
| const newHeaders = Object.keys(headers).reduce<{ [key: string]: string }>((acc, key) => { | |
| acc[`x-pd-proxy-${key}`] = headers[key]; | |
| return acc; | |
| }, {}); | |
| const newOpts: RequestOptions = { | |
| method: opts.method, | |
| headers: newHeaders, | |
| params: query, | |
| } | |
| if (opts.body) { | |
| newOpts.body = opts.body | |
| } | |
| return this.makeConnectRequest(`/proxy/${url64}`, newOpts); | |
| } | |
| public makeProxyRequest( | |
| url: string, | |
| query: Record<string, string | number | boolean | null>, | |
| opts: MakeProxyRequestOpts | |
| ): Promise<unknown> { | |
| if (!url?.trim()) { | |
| throw new Error("URL is required"); | |
| } | |
| let url64: string; | |
| try { | |
| url64 = btoa(url).replace(/\+/g, "-") | |
| .replace(/\//g, "_") | |
| .replace(/=+$/, ""); | |
| } catch (error: any) { | |
| throw new Error(`Failed to encode URL: ${error.message}`); | |
| } | |
| const headers = opts.headers || {}; | |
| const newHeaders = Object.keys(headers).reduce<{ [key: string]: string }>((acc, key) => { | |
| acc[`x-pd-proxy-${key}`] = headers[key]; | |
| return acc; | |
| }, {}); | |
| const newOpts: RequestOptions = { | |
| method: opts.method, | |
| headers: newHeaders, | |
| params: query, | |
| } | |
| if (opts.body) { | |
| newOpts.body = opts.body; | |
| } | |
| return this.makeConnectRequest(`/proxy/${url64}`, newOpts); | |
| } |
🧰 Tools
🪛 GitHub Check: Lint Code Base
[failure] 396-396:
Unexpected any. Specify a different type
[failure] 396-396:
Unexpected any. Specify a different type
[failure] 398-398:
Expected indentation of 6 spaces but found 4
[failure] 399-399:
Expected indentation of 6 spaces but found 4
🪛 ESLint
[error] 396-396: Unexpected any. Specify a different type.
(@typescript-eslint/no-explicit-any)
[error] 396-396: Unexpected any. Specify a different type.
(@typescript-eslint/no-explicit-any)
[error] 398-398: Expected indentation of 6 spaces but found 4.
(indent)
[error] 399-399: Expected indentation of 6 spaces but found 4.
(indent)
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Missing version update and CHANGELOG