-
Couldn't load subscription status.
- Fork 5.5k
Fixes DJ-2470 #14106
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
Fixes DJ-2470 #14106
Changes from 1 commit
6d24e66
9b7dcf1
975d669
651d41b
71dd92f
ad1804d
4385093
87d8d86
ce22436
d4a8394
1b02d65
0bce50e
075e400
7c7b4ac
ccf848e
9a4af88
faf0f8d
5e85ef5
85748a4
06a17b5
e63a89f
bfbc249
314b644
1a1faf0
0e9866f
cf31cda
fe7a66d
0c20e6c
6d23fb9
2db68e3
aa7fb1a
9999664
89ff7c1
7964dde
3429a92
1886bd9
d27a9b1
e775d04
60ac2da
4695be5
a97736d
003aea7
9525871
0e0b7b3
0f4f1a3
4d89d5c
866efdd
60e9e81
3025cf5
7ec1156
a33b75f
6596349
7994412
0c7ca6f
29ab565
401522c
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 |
|---|---|---|
|
|
@@ -21,6 +21,18 @@ describe("ServerClient", () => { | |
| const client = createClient(params); | ||
| expect(client).toBeInstanceOf(ServerClient); | ||
| }); | ||
|
|
||
| it("should mock the createClient method with a project object and return a ServerClient instance", () => { | ||
| const params = { | ||
| project: { | ||
| publicKey: "test-public-key", | ||
| secretKey: "test-secret", | ||
| }, | ||
| }; | ||
|
|
||
| const client = createClient(params); | ||
| expect(client).toBeInstanceOf(ServerClient); | ||
| }); | ||
| }); | ||
|
|
||
| describe("makeRequest", () => { | ||
|
|
@@ -534,12 +546,16 @@ describe("ServerClient", () => { | |
| } as unknown as ClientCredentials; | ||
|
|
||
| // Inject the mock oauthClient into the ServerClient instance | ||
| client = new ServerClient( | ||
| const client = new ServerClient( | ||
| { | ||
| publicKey: "test-public-key", | ||
| secretKey: "test-secret-key", | ||
| oauthClientId: "test-client-id", | ||
| oauthClientSecret: "test-client-secret", | ||
| project: { | ||
| publicKey: "test-public-key", | ||
| secretKey: "test", | ||
| }, | ||
| oauth: { | ||
| clientId: "test-client-id", | ||
| clientSecret: "test-client-secret", | ||
| }, | ||
| }, | ||
| oauthClientMock, | ||
| ); | ||
|
||
|
|
@@ -607,10 +623,14 @@ describe("ServerClient", () => { | |
|
|
||
| const client = new ServerClient( | ||
| { | ||
| publicKey: "test-public-key", | ||
| secretKey: "test-secret-key", | ||
| oauthClientId: "test-client-id", | ||
| oauthClientSecret: "test-client-secret", | ||
| project: { | ||
| publicKey: "test-public-key", | ||
| secretKey: "test", | ||
| }, | ||
| oauth: { | ||
| clientId: "test-client-id", | ||
| clientSecret: "test-client-secret", | ||
| }, | ||
| }, | ||
| oauthClientMock, | ||
| ); | ||
|
|
@@ -643,4 +663,102 @@ describe("ServerClient", () => { | |
| ); | ||
| }); | ||
| }); | ||
|
|
||
| describe("invokeWorkflowForExternalUser", () => { | ||
|
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. New tests for |
||
| let client: ServerClient; | ||
|
|
||
| beforeEach(() => { | ||
| fetchMock.resetMocks(); | ||
dylburger marked this conversation as resolved.
Outdated
Show resolved
Hide resolved
|
||
| // Create mock AccessToken objects | ||
| const expiredTokenMock = { | ||
| token: { | ||
| access_token: "expired-oauth-token", | ||
| }, | ||
| expired: jest.fn().mockReturnValue(true), | ||
| }; | ||
|
|
||
| const newTokenMock = { | ||
| token: { | ||
| access_token: "new-oauth-token", | ||
| }, | ||
| expired: jest.fn().mockReturnValue(false), | ||
| }; | ||
|
|
||
| const getTokenMock = jest | ||
| .fn() | ||
| .mockResolvedValueOnce(expiredTokenMock) | ||
| .mockResolvedValueOnce(newTokenMock); | ||
|
|
||
| const oauthClientMock = { | ||
| getToken: getTokenMock, | ||
| } as unknown as ClientCredentials; | ||
| client = new ServerClient( | ||
| { | ||
| project: { | ||
| publicKey: "test-public-key", | ||
| secretKey: "test", | ||
| }, | ||
| oauth: { | ||
| clientId: "test-client-id", | ||
| clientSecret: "test-client-secret", | ||
| }, | ||
| }, | ||
| oauthClientMock, | ||
| ); | ||
| }); | ||
|
|
||
| it("should include externalUserId and publicKey headers", async () => { | ||
| fetchMock.mockResponseOnce( | ||
| JSON.stringify({ | ||
| result: "workflow-response", | ||
| }), | ||
| { | ||
| headers: { | ||
| "Content-Type": "application/json", | ||
| }, | ||
| }, | ||
| ); | ||
|
|
||
| const result = await client.invokeWorkflowForExternalUser("https://example.com/workflow", "external-user-id", { | ||
| body: { | ||
| foo: "bar", | ||
| }, | ||
| }); | ||
|
|
||
| expect(result).toEqual({ | ||
| result: "workflow-response", | ||
| }); | ||
|
|
||
| expect(fetchMock).toHaveBeenCalledWith( | ||
| "https://example.com/workflow", | ||
| expect.objectContaining({ | ||
| headers: expect.objectContaining({ | ||
| "X-PD-External-User-ID": "external-user-id", | ||
| "X-PD-Project-Public-Key": "test-public-key", | ||
| }), | ||
| }), | ||
| ); | ||
| }); | ||
|
|
||
| it("should throw error when externalUserId is missing", async () => { | ||
| await expect(client.invokeWorkflowForExternalUser("https://example.com/workflow", "", { | ||
| body: { | ||
| foo: "bar", | ||
| }, | ||
| })).rejects.toThrow("External user ID is required"); | ||
| }); | ||
|
|
||
| it("should throw error when publicKey is missing", async () => { | ||
| const clientWithoutPublicKey = new ServerClient({ | ||
| secretKey: "test-secret-key", | ||
| }); | ||
|
|
||
| await expect(clientWithoutPublicKey.invokeWorkflowForExternalUser("https://example.com/workflow", "external-user-id", { | ||
| body: { | ||
| foo: "bar", | ||
| }, | ||
| })).rejects.toThrow("Project public key is required to map the external user ID to the correct project"); | ||
| }); | ||
| }); | ||
|
|
||
| }); | ||
| Original file line number | Diff line number | Diff line change | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|
|
|
@@ -7,31 +7,55 @@ import { | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| ClientCredentials, | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| } from "simple-oauth2"; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| export type ProjectKeys = { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| publicKey: string; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| secretKey: string; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| }; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| export type PipedreamOAuthClient = { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| clientId: string; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| clientSecret: string; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| }; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| /** | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| * Options for creating a server-side client. | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| * This is used to configure the ServerClient instance. | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| */ | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| export type CreateServerClientOpts = { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| /** | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| * @deprecated Use the `project` object instead. | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| * The public API key for accessing the service. | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| */ | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| publicKey?: string; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| /** | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| * @deprecated Use the `project` object instead. | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| * The secret API key for accessing the service. | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| */ | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| secretKey?: string; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| /** | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| * @deprecated Use the `oauth` object instead. | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| * The client ID of your workspace's OAuth application. | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| */ | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| oauthClientId?: string; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| /** | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| * @deprecated Use the `oauth` object instead. | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| * The client secret of your workspace's OAuth application. | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| */ | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| oauthClientSecret?: string; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| /** | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| * The project object, containing publicKey and secretKey. | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| */ | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| project?: ProjectKeys; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| /** | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| * The OAuth object, containing client ID and client secret. | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| */ | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| oauth?: PipedreamOAuthClient; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| /** | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| * The API host URL. Used by Pipedream employees. Defaults to "api.pipedream.com" if not provided. | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| */ | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
|
@@ -310,6 +334,10 @@ export class ServerClient { | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| ) { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| this.secretKey = opts.secretKey; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| this.publicKey = opts.publicKey; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| if (opts.project) { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| this.publicKey = opts.project.publicKey; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| this.secretKey = opts.project.secretKey; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| const { apiHost = "api.pipedream.com" } = opts; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| this.baseURL = `https://${apiHost}/v1`; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
|
@@ -327,18 +355,21 @@ export class ServerClient { | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| oauthClientId: id, | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| oauthClientSecret: secret, | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| oauth, | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| }: CreateServerClientOpts, | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| tokenHost: string, | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| ) { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| if (!id || !secret) { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| if (!oauth || !id || !secret) { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| return; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| const client = { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| id: id ?? oauth.clientId, | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| secret: secret ?? oauth.clientSecret, | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| }; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| if (!oauth || !id || !secret) { | |
| return; | |
| } | |
| const client = { | |
| id: id ?? oauth.clientId, | |
| secret: secret ?? oauth.clientSecret, | |
| }; | |
| if (!(oauth || (id && secret))) { | |
| return; | |
| } | |
| const client = { | |
| id: oauth?.clientId ?? id, | |
| secret: oauth?.clientSecret ?? secret, | |
| }; |
dylburger marked this conversation as resolved.
Outdated
Show resolved
Hide resolved
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
Add input validation for the url parameter
In the invokeWorkflowForExternalUser method, the url parameter is used without validation. To prevent runtime errors and enhance security, consider validating the url to ensure it is a well-formed URL.
Add URL validation:
public async invokeWorkflowForExternalUser(
url: string,
externalUserId: string,
opts: RequestOptions = {},
): Promise<unknown> {
+ try {
+ new URL(url);
+ } catch {
+ throw new Error(`Invalid URL provided: ${url}`);
+ }
const {
body,
headers = {},
} = opts;📝 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 async invokeWorkflowForExternalUser(url: string, externalUserId: string, opts: RequestOptions = {}): Promise<unknown> { | |
| const { | |
| body, | |
| headers = {}, | |
| } = opts; | |
| if (!externalUserId) { | |
| throw new Error("External user ID is required"); | |
| } | |
| if (!this.publicKey) { | |
| throw new Error("Project public key is required to map the external user ID to the correct project"); | |
| } | |
| return this.makeRequest("", { | |
| ...opts, | |
| baseURL: url, | |
| method: opts.method || "POST", // Default to POST if not specified | |
| headers: { | |
| ...headers, | |
| "Authorization": await this.oauthAuthorizationHeader(), | |
| "X-PD-External-User-ID": externalUserId, | |
| "X-PD-Project-Public-Key": this.publicKey, | |
| }, | |
| body, | |
| }); | |
| } | |
| public async invokeWorkflowForExternalUser(url: string, externalUserId: string, opts: RequestOptions = {}): Promise<unknown> { | |
| try { | |
| new URL(url); | |
| } catch { | |
| throw new Error(`Invalid URL provided: ${url}`); | |
| } | |
| const { | |
| body, | |
| headers = {}, | |
| } = opts; | |
| if (!externalUserId) { | |
| throw new Error("External user ID is required"); | |
| } | |
| if (!this.publicKey) { | |
| throw new Error("Project public key is required to map the external user ID to the correct project"); | |
| } | |
| return this.makeRequest("", { | |
| ...opts, | |
| baseURL: url, | |
| method: opts.method || "POST", // Default to POST if not specified | |
| headers: { | |
| ...headers, | |
| "Authorization": await this.oauthAuthorizationHeader(), | |
| "X-PD-External-User-ID": externalUserId, | |
| "X-PD-Project-Public-Key": this.publicKey, | |
| }, | |
| body, | |
| }); | |
| } |
Uh oh!
There was an error while loading. Please reload this page.