From 2bdb6b5041c2f6ed94ee17b5462b0b18748c3c8e Mon Sep 17 00:00:00 2001 From: Biz Melesse Date: Mon, 3 Feb 2025 15:00:13 -0600 Subject: [PATCH 1/7] Add getEnvironment to BaseClient --- packages/sdk/CHANGELOG.md | 6 ++++++ packages/sdk/package.json | 2 +- packages/sdk/src/shared/index.ts | 8 ++++++++ 3 files changed, 15 insertions(+), 1 deletion(-) diff --git a/packages/sdk/CHANGELOG.md b/packages/sdk/CHANGELOG.md index 453f666b98c9e..3bc01d2347fab 100644 --- a/packages/sdk/CHANGELOG.md +++ b/packages/sdk/CHANGELOG.md @@ -2,6 +2,12 @@ # Changelog +## [1.3.2] - 2025-02-3 + +### Changed + +- Add getEnvironment function to BaseClient + ## [1.3.1] - 2025-01-30 ### Changed diff --git a/packages/sdk/package.json b/packages/sdk/package.json index 8a0657e7989f6..309b91cf8607f 100644 --- a/packages/sdk/package.json +++ b/packages/sdk/package.json @@ -1,7 +1,7 @@ { "name": "@pipedream/sdk", "type": "module", - "version": "1.3.1", + "version": "1.3.2", "description": "Pipedream SDK", "main": "./dist/server.js", "module": "./dist/server.js", diff --git a/packages/sdk/src/shared/index.ts b/packages/sdk/src/shared/index.ts index 2ee4ebdf31b87..7fcf185e742d0 100644 --- a/packages/sdk/src/shared/index.ts +++ b/packages/sdk/src/shared/index.ts @@ -871,6 +871,14 @@ export abstract class BaseClient { this.workflowDomain = workflowDomain; } + /** + * Retrieves the current environment the client is configured to use. + * @returns {string} The current environment. + */ + public getEnvironment(): string { + return this.environment; + } + /** * Makes an HTTP request * From 13c76b1d5b6a4b7ba5ad23009548ceff4b6be752 Mon Sep 17 00:00:00 2001 From: TJ Koblentz Date: Mon, 3 Feb 2025 15:18:55 -0800 Subject: [PATCH 2/7] fix not running tests --- packages/sdk/package.json | 2 +- pnpm-lock.yaml | 2 -- 2 files changed, 1 insertion(+), 3 deletions(-) diff --git a/packages/sdk/package.json b/packages/sdk/package.json index 309b91cf8607f..48e6c0ae07cd4 100644 --- a/packages/sdk/package.json +++ b/packages/sdk/package.json @@ -40,7 +40,7 @@ "prepublish": "pnpm run build", "prebuild": "node scripts/updateVersion.js", "build": "rm -rf dist && pnpm run prebuild && tsup --config tsup.server.cjs.config.js && tsup --config tsup.server.esm.config.js && tsup --config tsup.browser.config.js", - "test": "node --experimental-vm-modules node_modules/.bin/jest", + "test": "NODE_OPTIONS=--experimental-vm-modules jest", "watch": "nodemon --watch src --exec 'pnpm run build'", "cli": "node dist/server/cli.js" }, diff --git a/pnpm-lock.yaml b/pnpm-lock.yaml index b711ee2c35128..28c2172f9ad0e 100644 --- a/pnpm-lock.yaml +++ b/pnpm-lock.yaml @@ -32125,8 +32125,6 @@ snapshots: '@putout/operator-filesystem': 5.0.0(putout@36.13.1(eslint@8.57.1)(typescript@5.6.3)) '@putout/operator-json': 2.2.0 putout: 36.13.1(eslint@8.57.1)(typescript@5.6.3) - transitivePeerDependencies: - - supports-color '@putout/operator-regexp@1.0.0(putout@36.13.1(eslint@8.57.1)(typescript@5.6.3))': dependencies: From d0ac161e68bf9e8d2e1be335e6e1d95a40c6ea2f Mon Sep 17 00:00:00 2001 From: TJ Koblentz Date: Mon, 3 Feb 2025 15:27:39 -0800 Subject: [PATCH 3/7] try this --- packages/sdk/package.json | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/packages/sdk/package.json b/packages/sdk/package.json index 48e6c0ae07cd4..13ad64555d8b7 100644 --- a/packages/sdk/package.json +++ b/packages/sdk/package.json @@ -40,7 +40,7 @@ "prepublish": "pnpm run build", "prebuild": "node scripts/updateVersion.js", "build": "rm -rf dist && pnpm run prebuild && tsup --config tsup.server.cjs.config.js && tsup --config tsup.server.esm.config.js && tsup --config tsup.browser.config.js", - "test": "NODE_OPTIONS=--experimental-vm-modules jest", + "test": "NODE_OPTIONS=\"$NODE_OPTIONS --experimental-vm-modules\" jest", "watch": "nodemon --watch src --exec 'pnpm run build'", "cli": "node dist/server/cli.js" }, From 642295e7b888f187dd50a751eac8c3b43b8602c3 Mon Sep 17 00:00:00 2001 From: TJ Koblentz Date: Mon, 3 Feb 2025 16:19:17 -0800 Subject: [PATCH 4/7] jest and type stuff --- packages/sdk/jest.config.js | 5 ++++- packages/sdk/src/server/__tests__/server.test.ts | 16 +++++++++++----- packages/sdk/src/server/index.ts | 2 +- 3 files changed, 16 insertions(+), 7 deletions(-) diff --git a/packages/sdk/jest.config.js b/packages/sdk/jest.config.js index 3285aae08c7e6..67e93f088a952 100644 --- a/packages/sdk/jest.config.js +++ b/packages/sdk/jest.config.js @@ -1,5 +1,4 @@ export default { - preset: "ts-jest", testEnvironment: "node", roots: [ "/src", @@ -15,6 +14,9 @@ export default { moduleNameMapper: { "^(.+)\\.js$": "$1", }, + extensionsToTreatAsEsm: [ + ".ts", + ], transform: { // '^.+\\.[tj]sx?$' to process ts,js,tsx,jsx with `ts-jest` // '^.+\\.m?[tj]sx?$' to process ts,js,tsx,jsx,mts,mjs,mtsx,mjsx with `ts-jest` @@ -22,6 +24,7 @@ export default { "ts-jest", { tsconfig: "tsconfig.node.json", + useESM: true, }, ], }, diff --git a/packages/sdk/src/server/__tests__/server.test.ts b/packages/sdk/src/server/__tests__/server.test.ts index 2b471f7f13292..a7ff3c6c373f2 100644 --- a/packages/sdk/src/server/__tests__/server.test.ts +++ b/packages/sdk/src/server/__tests__/server.test.ts @@ -1,3 +1,4 @@ +import { jest } from "@jest/globals" import { BackendClient, BackendClientOpts, @@ -726,17 +727,22 @@ function setupFetchMock() { beforeEach(() => { intercepts = []; - jest.spyOn(global, "fetch").mockImplementation(jest.fn((url: string, init: RequestInit) => { + // without these generics this fails typecheck and can't figure out why + jest.spyOn(global, "fetch").mockImplementation(jest.fn(async (...args: Parameters) => { + const [url, init] = args let json: any - if (init.body && typeof init.body === "string") { + if (init?.body && typeof init.body === "string") { try { json = JSON.parse(init.body) } catch {} } + if (url instanceof Request) { + throw new Error("not supported") + } const ifOpts: IfOpts = { - method: init.method || "GET", - url, - headers: init.headers as Record || {}, + method: init?.method || "GET", + url: url.toString(), + headers: init?.headers as Record || {}, json, } for (let i = 0; i < intercepts.length; i++) { diff --git a/packages/sdk/src/server/index.ts b/packages/sdk/src/server/index.ts index d9c43e42f9a4e..a54ee28468961 100644 --- a/packages/sdk/src/server/index.ts +++ b/packages/sdk/src/server/index.ts @@ -143,7 +143,7 @@ export class BackendClient extends BaseClient { token: string expiresAt: number }; - protected override projectId: string; + protected override projectId: string = ""; /** * Constructs a new ServerClient instance. From e2af32ec3ec5d57c7e3073368449883943b65572 Mon Sep 17 00:00:00 2001 From: Biz Melesse Date: Tue, 4 Feb 2025 11:29:54 -0600 Subject: [PATCH 5/7] Fix linter errors --- .../sdk/src/server/__tests__/server.test.ts | 91 +++++++++++++------ packages/sdk/src/server/index.ts | 10 +- pnpm-lock.yaml | 2 + 3 files changed, 71 insertions(+), 32 deletions(-) diff --git a/packages/sdk/src/server/__tests__/server.test.ts b/packages/sdk/src/server/__tests__/server.test.ts index a7ff3c6c373f2..47cd178cf4643 100644 --- a/packages/sdk/src/server/__tests__/server.test.ts +++ b/packages/sdk/src/server/__tests__/server.test.ts @@ -51,7 +51,9 @@ describe("BackendClient", () => { url: "https://api.pipedream.com/v1/test-path", }, response: { - json: { data: "test-response" }, + json: { + data: "test-response", + }, }, }) @@ -73,7 +75,9 @@ describe("BackendClient", () => { }, }, response: { - json: { success: true }, + json: { + success: true, + }, }, }) @@ -117,7 +121,9 @@ describe("BackendClient", () => { }, }, response: { - json: { success: true }, + json: { + success: true, + }, }, }) @@ -145,7 +151,9 @@ describe("BackendClient", () => { }, }, response: { - json: { success: true }, + json: { + success: true, + }, }, }) @@ -312,10 +320,12 @@ describe("BackendClient", () => { url: `https://api.pipedream.com/v1/connect/${projectId}/accounts?app=app-1`, }, response: { - json: [{ - id: "account-1", - name: "Test Account", - }], + json: [ + { + id: "account-1", + name: "Test Account", + }, + ], }, }); @@ -340,10 +350,12 @@ describe("BackendClient", () => { url: `https://api.pipedream.com/v1/connect/${projectId}/accounts?external_user_id=external-id-1`, }, response: { - json: [{ - id: "account-1", - name: "Test Account", - }], + json: [ + { + id: "account-1", + name: "Test Account", + }, + ], }, }); @@ -465,7 +477,9 @@ describe("BackendClient", () => { }, }, response: { - json: { result: "workflow-response" }, + json: { + result: "workflow-response", + }, }, }) @@ -481,8 +495,10 @@ describe("BackendClient", () => { }); it("should invoke a workflow with OAuth auth type", async () => { - const token = ""+Math.random() - fetchMock.expectAccessTokenSuccess({ accessToken: token }); + const token = "" + Math.random() + fetchMock.expectAccessTokenSuccess({ + accessToken: token, + }); fetchMock.expect({ request: { url: "https://example.com/workflow", @@ -491,7 +507,9 @@ describe("BackendClient", () => { }, }, response: { - json: { result: "workflow-response" }, + json: { + result: "workflow-response", + }, }, }) @@ -503,7 +521,7 @@ describe("BackendClient", () => { }); it("should invoke a workflow with static bearer auth type", async () => { - const token = ""+Math.random() + const token = "" + Math.random() fetchMock.expect({ request: { url: "https://example.com/workflow", @@ -512,7 +530,9 @@ describe("BackendClient", () => { }, }, response: { - json: { result: "workflow-response" }, + json: { + result: "workflow-response", + }, }, }) @@ -538,7 +558,9 @@ describe("BackendClient", () => { url: "https://api.pipedream.com/v1/test-path", }, response: { - json: { success: true }, + json: { + success: true, + }, }, }) @@ -571,7 +593,9 @@ describe("BackendClient", () => { }, }, response: { - json: { result: "workflow-response" }, + json: { + result: "workflow-response", + }, }, }) @@ -697,17 +721,17 @@ describe("BackendClient", () => { type ExpectRequest = { method?: string url?: string | RegExp - json?: Record + json?: Record headersContaining?: Record } type MockResponse = | Response - | { status?: number; json?: any } + | { status?: number; json?: never } type IfOpts = { method: string url: string headers: Record // NonNullable - json?: any // body json + json?: never // body json // XXX etc. } function setupFetchMock() { @@ -716,7 +740,7 @@ function setupFetchMock() { response: () => Response }[] = [] - const jsonResponse = (o: any, opts?: { status?: number }) => { + const jsonResponse = (o: never, opts?: { status?: number }) => { return new Response(JSON.stringify(o), { status: opts?.status, headers: { @@ -728,13 +752,18 @@ function setupFetchMock() { beforeEach(() => { intercepts = []; // without these generics this fails typecheck and can't figure out why - jest.spyOn(global, "fetch").mockImplementation(jest.fn(async (...args: Parameters) => { - const [url, init] = args - let json: any + jest.spyOn(global, "fetch").mockImplementation(jest.fn(async (...args: Parameters) => { + const [ + url, + init, + ] = args + let json: never if (init?.body && typeof init.body === "string") { try { json = JSON.parse(init.body) - } catch {} + } catch { + // pass + } } if (url instanceof Request) { throw new Error("not supported") @@ -764,7 +793,9 @@ function setupFetchMock() { // const _expect = (opts: { if: (opts: IfOpts) => boolean, jsonResponse?: any, response?: Response }) => { const _expect = (opts: { request: ExpectRequest, response: MockResponse }) => { - const { method, url, headersContaining, json } = opts.request + const { + method, url, headersContaining, json, + } = opts.request intercepts.push({ if: (ifOpts) => { if (method && ifOpts.method !== method) return false @@ -806,7 +837,7 @@ function setupFetchMock() { } const expectAccessTokenSuccess = (opts?: { accessToken?: string; expiresIn?: number }) => { - const accessToken = opts?.accessToken || ""+Math.random() + const accessToken = opts?.accessToken || "" + Math.random() _expect({ request: { url: /\/v1\/oauth\/token$/, diff --git a/packages/sdk/src/server/index.ts b/packages/sdk/src/server/index.ts index a54ee28468961..c61003fff8b58 100644 --- a/packages/sdk/src/server/index.ts +++ b/packages/sdk/src/server/index.ts @@ -199,7 +199,11 @@ export class BackendClient extends BaseClient { } private async ensureValidOauthAccessToken(): Promise { - const { client, clientAuth, as } = this.oauthClient + const { + client, + clientAuth, + as, + } = this.oauthClient let attempts = 0; const maxAttempts = 2; @@ -221,7 +225,9 @@ export class BackendClient extends BaseClient { token: oauthTokenResponse.access_token, expiresAt: Date.now() + (oauthTokenResponse.expires_in || 0) * 1000, }; - } catch {} + } catch { + // pass + } attempts++; } diff --git a/pnpm-lock.yaml b/pnpm-lock.yaml index 28c2172f9ad0e..b711ee2c35128 100644 --- a/pnpm-lock.yaml +++ b/pnpm-lock.yaml @@ -32125,6 +32125,8 @@ snapshots: '@putout/operator-filesystem': 5.0.0(putout@36.13.1(eslint@8.57.1)(typescript@5.6.3)) '@putout/operator-json': 2.2.0 putout: 36.13.1(eslint@8.57.1)(typescript@5.6.3) + transitivePeerDependencies: + - supports-color '@putout/operator-regexp@1.0.0(putout@36.13.1(eslint@8.57.1)(typescript@5.6.3))': dependencies: From 98af366d5b2222583251a538590e4bdee89c3168 Mon Sep 17 00:00:00 2001 From: Biz Melesse Date: Tue, 4 Feb 2025 11:41:47 -0600 Subject: [PATCH 6/7] Fix type error --- packages/sdk/src/server/__tests__/server.test.ts | 12 ++++++------ 1 file changed, 6 insertions(+), 6 deletions(-) diff --git a/packages/sdk/src/server/__tests__/server.test.ts b/packages/sdk/src/server/__tests__/server.test.ts index 47cd178cf4643..18efed23bcc54 100644 --- a/packages/sdk/src/server/__tests__/server.test.ts +++ b/packages/sdk/src/server/__tests__/server.test.ts @@ -721,17 +721,17 @@ describe("BackendClient", () => { type ExpectRequest = { method?: string url?: string | RegExp - json?: Record + json?: Record headersContaining?: Record } type MockResponse = | Response - | { status?: number; json?: never } + | { status?: number; json?: unknown } type IfOpts = { method: string url: string headers: Record // NonNullable - json?: never // body json + json?: unknown // body json // XXX etc. } function setupFetchMock() { @@ -740,7 +740,7 @@ function setupFetchMock() { response: () => Response }[] = [] - const jsonResponse = (o: never, opts?: { status?: number }) => { + const jsonResponse = (o: unknown, opts?: { status?: number }) => { return new Response(JSON.stringify(o), { status: opts?.status, headers: { @@ -752,12 +752,12 @@ function setupFetchMock() { beforeEach(() => { intercepts = []; // without these generics this fails typecheck and can't figure out why - jest.spyOn(global, "fetch").mockImplementation(jest.fn(async (...args: Parameters) => { + jest.spyOn(global, "fetch").mockImplementation(jest.fn(async (...args: Parameters) => { // eslint-disable-line @typescript-eslint/no-explicit-any const [ url, init, ] = args - let json: never + let json: unknown if (init?.body && typeof init.body === "string") { try { json = JSON.parse(init.body) From 69e1260223330f21882b3ae79cd15fb38f9d66d4 Mon Sep 17 00:00:00 2001 From: Biz Melesse Date: Tue, 4 Feb 2025 11:44:12 -0600 Subject: [PATCH 7/7] Update pnpm-lock.yaml --- pnpm-lock.yaml | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-) diff --git a/pnpm-lock.yaml b/pnpm-lock.yaml index 81b7c4b942d68..a64aa7c24e9c3 100644 --- a/pnpm-lock.yaml +++ b/pnpm-lock.yaml @@ -5312,8 +5312,7 @@ importers: specifier: ^1.5.1 version: 1.6.6 - components/instant: - specifiers: {} + components/instant: {} components/instantly: dependencies: