From 5fd1eb1bc1dd3af7ff47ccce32af144845ca1e2b Mon Sep 17 00:00:00 2001 From: "fern-api[bot]" <115122769+fern-api[bot]@users.noreply.github.com> Date: Fri, 17 Oct 2025 21:58:22 +0000 Subject: [PATCH] SDK regeneration --- .github/workflows/ci.yml | 25 +- package.json | 45 +- src/Client.ts | 52 +-- src/api/resources/index.ts | 4 +- .../client/requests/CreateOAuthTokenOpts.ts | 2 + src/api/resources/proxy/client/Client.ts | 410 ++++++++++-------- .../client/requests/ProxyDeleteRequest.ts | 27 +- .../proxy/client/requests/ProxyGetRequest.ts | 27 +- .../client/requests/ProxyPatchRequest.ts | 31 +- .../proxy/client/requests/ProxyPostRequest.ts | 31 +- .../proxy/client/requests/ProxyPutRequest.ts | 31 +- .../client/requests/DeployTriggerOpts.ts | 2 + src/api/resources/workflows/client/Client.ts | 278 ------------ src/api/resources/workflows/client/index.ts | 2 - .../InvokeWorkflowForExternalUserOpts.ts | 26 -- .../client/requests/InvokeWorkflowOpts.ts | 22 - .../workflows/client/requests/index.ts | 2 - src/api/resources/workflows/index.ts | 1 - src/api/types/BackendClientOpts.ts | 2 + src/api/types/ConfiguredProps.ts | 25 +- src/api/types/HTTPAuthType.ts | 12 - src/api/types/index.ts | 75 ++-- src/core/auth/ConnectTokenProvider.ts | 66 --- src/core/auth/StaticTokenProvider.ts | 13 - src/core/auth/TokenProvider.ts | 3 - src/core/auth/index.ts | 3 - .../client/requests/CreateOAuthTokenOpts.ts | 2 + .../client/requests/DeployTriggerOpts.ts | 2 + src/serialization/types/BackendClientOpts.ts | 2 + src/serialization/types/ConfiguredProps.ts | 6 +- src/version.ts | 2 +- 31 files changed, 348 insertions(+), 883 deletions(-) delete mode 100644 src/api/resources/workflows/client/Client.ts delete mode 100644 src/api/resources/workflows/client/index.ts delete mode 100644 src/api/resources/workflows/client/requests/InvokeWorkflowForExternalUserOpts.ts delete mode 100644 src/api/resources/workflows/client/requests/InvokeWorkflowOpts.ts delete mode 100644 src/api/resources/workflows/client/requests/index.ts delete mode 100644 src/api/resources/workflows/index.ts delete mode 100644 src/api/types/HTTPAuthType.ts delete mode 100644 src/core/auth/ConnectTokenProvider.ts delete mode 100644 src/core/auth/StaticTokenProvider.ts delete mode 100644 src/core/auth/TokenProvider.ts diff --git a/.github/workflows/ci.yml b/.github/workflows/ci.yml index 5d91b65..7f884ee 100644 --- a/.github/workflows/ci.yml +++ b/.github/workflows/ci.yml @@ -27,27 +27,4 @@ jobs: uses: actions/setup-node@v3 - name: Compile - run: yarn && yarn test - - publish: - needs: - - compile - - test - if: github.event_name == 'push' && contains(github.ref, 'refs/tags/') - runs-on: ubuntu-latest - - steps: - - name: Checkout repo - uses: actions/checkout@v4 - - - name: Set up node - uses: actions/setup-node@v3 - - name: Install dependencies - run: yarn install --frozen-lockfile --non-interactive - - - name: Build - run: yarn build - - name: Set up NPM authentication - run: echo "//registry.npmjs.org/:_authToken=${{ secrets.NPM_TOKEN }}" > .npmrc - - name: Publish - run: npm publish --access public --no-git-tag-version --tag latest + run: yarn && yarn test diff --git a/package.json b/package.json index f1d8e2d..037a219 100644 --- a/package.json +++ b/package.json @@ -1,6 +1,6 @@ { "name": "@pipedream/sdk", - "version": "2.0.13", + "version": "2.0.14", "private": false, "repository": "github:PipedreamHQ/pipedream-sdk-typescript", "type": "commonjs", @@ -10,11 +10,6 @@ "exports": { ".": { "types": "./dist/cjs/index.d.ts", - "browser": { - "types": "./dist/esm/browser/index.d.mts", - "import": "./dist/esm/browser/index.mjs", - "default": "./dist/esm/browser/index.mjs" - }, "import": { "types": "./dist/esm/index.d.mts", "default": "./dist/esm/index.mjs" @@ -25,18 +20,6 @@ }, "default": "./dist/cjs/index.js" }, - "./browser": { - "types": "./dist/esm/browser/index.d.mts", - "import": { - "types": "./dist/esm/browser/index.d.mts", - "default": "./dist/esm/browser/index.mjs" - }, - "require": { - "types": "./dist/cjs/browser/index.d.ts", - "default": "./dist/cjs/browser/index.js" - }, - "default": "./dist/esm/browser/index.mjs" - }, "./serialization": { "types": "./dist/cjs/serialization/index.d.ts", "import": { @@ -49,18 +32,6 @@ }, "default": "./dist/cjs/serialization/index.js" }, - "./server": { - "types": "./dist/cjs/index.d.ts", - "import": { - "types": "./dist/esm/index.d.mts", - "default": "./dist/esm/index.mjs" - }, - "require": { - "types": "./dist/cjs/index.d.ts", - "default": "./dist/cjs/index.js" - }, - "default": "./dist/cjs/index.js" - }, "./package.json": "./package.json" }, "files": [ @@ -80,21 +51,19 @@ "test:wire": "jest --selectProjects wire" }, "devDependencies": { + "webpack": "^5.97.1", + "ts-loader": "^9.5.1", + "jest": "^29.7.0", "@jest/globals": "^29.7.0", "@types/jest": "^29.5.14", - "@types/node": "^18.19.70", - "jest": "^29.7.0", + "ts-jest": "^29.3.4", "jest-environment-jsdom": "^29.7.0", "msw": "^2.8.4", + "@types/node": "^18.19.70", "prettier": "^3.4.2", - "ts-jest": "^29.3.4", - "ts-loader": "^9.5.1", - "typescript": "~5.7.2", - "webpack": "^5.97.1" + "typescript": "~5.7.2" }, "browser": { - "./dist/cjs/wrapper/utils/getBaseUrl.js": "./dist/cjs/wrapper/utils/getBaseUrl.browser.js", - "./dist/esm/wrapper/utils/getBaseUrl.mjs": "./dist/esm/wrapper/utils/getBaseUrl.browser.mjs", "fs": false, "os": false, "path": false, diff --git a/src/Client.ts b/src/Client.ts index decf4af..45976d1 100644 --- a/src/Client.ts +++ b/src/Client.ts @@ -15,11 +15,10 @@ import { Components } from "./api/resources/components/client/Client.js"; import { Actions } from "./api/resources/actions/client/Client.js"; import { Triggers } from "./api/resources/triggers/client/Client.js"; import { DeployedTriggers } from "./api/resources/deployedTriggers/client/Client.js"; -import { FileStash } from "./api/resources/fileStash/client/Client.js"; import { Projects } from "./api/resources/projects/client/Client.js"; +import { FileStash } from "./api/resources/fileStash/client/Client.js"; import { Proxy } from "./api/resources/proxy/client/Client.js"; import { Tokens } from "./api/resources/tokens/client/Client.js"; -import { SDK_VERSION } from "./version.js"; export declare namespace PipedreamClient { export interface Options { @@ -28,7 +27,6 @@ export declare namespace PipedreamClient { baseUrl?: core.Supplier; clientId?: core.Supplier; clientSecret?: core.Supplier; - tokenProvider?: core.TokenProvider; projectId: string; /** Override the x-pd-environment header */ projectEnvironment?: core.Supplier; @@ -54,7 +52,7 @@ export declare namespace PipedreamClient { export class PipedreamClient { protected readonly _options: PipedreamClient.Options; - protected readonly _tokenProvider: core.TokenProvider; + private readonly _oauthTokenProvider: core.OAuthTokenProvider; protected _appCategories: AppCategories | undefined; protected _apps: Apps | undefined; protected _accounts: Accounts | undefined; @@ -63,8 +61,8 @@ export class PipedreamClient { protected _actions: Actions | undefined; protected _triggers: Triggers | undefined; protected _deployedTriggers: DeployedTriggers | undefined; - protected _fileStash: FileStash | undefined; protected _projects: Projects | undefined; + protected _fileStash: FileStash | undefined; protected _proxy: Proxy | undefined; protected _tokens: Tokens | undefined; protected _oauthTokens: OauthTokens | undefined; @@ -77,8 +75,8 @@ export class PipedreamClient { "x-pd-environment": _options?.projectEnvironment, "X-Fern-Language": "JavaScript", "X-Fern-SDK-Name": "@pipedream/sdk", - "X-Fern-SDK-Version": SDK_VERSION, - "User-Agent": `@pipedream/sdk/${SDK_VERSION}`, + "X-Fern-SDK-Version": "2.0.14", + "User-Agent": "@pipedream/sdk/2.0.14", "X-Fern-Runtime": core.RUNTIME.type, "X-Fern-Runtime-Version": core.RUNTIME.version, }, @@ -86,10 +84,6 @@ export class PipedreamClient { ), }; - this._tokenProvider = this._options.tokenProvider ?? this.newOAuthTokenProvider(); - } - - private newOAuthTokenProvider(): core.OAuthTokenProvider { const clientId = this._options.clientId ?? process.env["PIPEDREAM_CLIENT_ID"]; if (clientId == null) { throw new Error( @@ -104,7 +98,7 @@ export class PipedreamClient { ); } - return new core.OAuthTokenProvider({ + this._oauthTokenProvider = new core.OAuthTokenProvider({ clientId, clientSecret, authClient: new OauthTokens({ @@ -117,91 +111,91 @@ export class PipedreamClient { public get appCategories(): AppCategories { return (this._appCategories ??= new AppCategories({ ...this._options, - token: async () => await this._tokenProvider.getToken(), + token: async () => await this._oauthTokenProvider.getToken(), })); } public get apps(): Apps { return (this._apps ??= new Apps({ ...this._options, - token: async () => await this._tokenProvider.getToken(), + token: async () => await this._oauthTokenProvider.getToken(), })); } public get accounts(): Accounts { return (this._accounts ??= new Accounts({ ...this._options, - token: async () => await this._tokenProvider.getToken(), + token: async () => await this._oauthTokenProvider.getToken(), })); } public get users(): Users { return (this._users ??= new Users({ ...this._options, - token: async () => await this._tokenProvider.getToken(), + token: async () => await this._oauthTokenProvider.getToken(), })); } public get components(): Components { return (this._components ??= new Components({ ...this._options, - token: async () => await this._tokenProvider.getToken(), + token: async () => await this._oauthTokenProvider.getToken(), })); } public get actions(): Actions { return (this._actions ??= new Actions({ ...this._options, - token: async () => await this._tokenProvider.getToken(), + token: async () => await this._oauthTokenProvider.getToken(), })); } public get triggers(): Triggers { return (this._triggers ??= new Triggers({ ...this._options, - token: async () => await this._tokenProvider.getToken(), + token: async () => await this._oauthTokenProvider.getToken(), })); } public get deployedTriggers(): DeployedTriggers { return (this._deployedTriggers ??= new DeployedTriggers({ ...this._options, - token: async () => await this._tokenProvider.getToken(), + token: async () => await this._oauthTokenProvider.getToken(), })); } - public get fileStash(): FileStash { - return (this._fileStash ??= new FileStash({ + public get projects(): Projects { + return (this._projects ??= new Projects({ ...this._options, - token: async () => await this._tokenProvider.getToken(), + token: async () => await this._oauthTokenProvider.getToken(), })); } - public get projects(): Projects { - return (this._projects ??= new Projects({ + public get fileStash(): FileStash { + return (this._fileStash ??= new FileStash({ ...this._options, - token: async () => await this._tokenProvider.getToken(), + token: async () => await this._oauthTokenProvider.getToken(), })); } public get proxy(): Proxy { return (this._proxy ??= new Proxy({ ...this._options, - token: async () => await this._tokenProvider.getToken(), + token: async () => await this._oauthTokenProvider.getToken(), })); } public get tokens(): Tokens { return (this._tokens ??= new Tokens({ ...this._options, - token: async () => await this._tokenProvider.getToken(), + token: async () => await this._oauthTokenProvider.getToken(), })); } public get oauthTokens(): OauthTokens { return (this._oauthTokens ??= new OauthTokens({ ...this._options, - token: async () => await this._tokenProvider.getToken(), + token: async () => await this._oauthTokenProvider.getToken(), })); } } diff --git a/src/api/resources/index.ts b/src/api/resources/index.ts index 28f80e8..f599d1e 100644 --- a/src/api/resources/index.ts +++ b/src/api/resources/index.ts @@ -7,12 +7,11 @@ export * as components from "./components/index.js"; export * as actions from "./actions/index.js"; export * as triggers from "./triggers/index.js"; export * as deployedTriggers from "./deployedTriggers/index.js"; -export * as fileStash from "./fileStash/index.js"; export * as projects from "./projects/index.js"; +export * as fileStash from "./fileStash/index.js"; export * as proxy from "./proxy/index.js"; export * as tokens from "./tokens/index.js"; export * as oauthTokens from "./oauthTokens/index.js"; -export * as workflows from "./workflows/index.js"; export * from "./apps/client/requests/index.js"; export * from "./accounts/client/requests/index.js"; export * from "./components/client/requests/index.js"; @@ -23,4 +22,3 @@ export * from "./fileStash/client/requests/index.js"; export * from "./proxy/client/requests/index.js"; export * from "./tokens/client/requests/index.js"; export * from "./oauthTokens/client/requests/index.js"; -export * from "./workflows/client/requests/index.js"; diff --git a/src/api/resources/oauthTokens/client/requests/CreateOAuthTokenOpts.ts b/src/api/resources/oauthTokens/client/requests/CreateOAuthTokenOpts.ts index 722d50b..5ffe576 100644 --- a/src/api/resources/oauthTokens/client/requests/CreateOAuthTokenOpts.ts +++ b/src/api/resources/oauthTokens/client/requests/CreateOAuthTokenOpts.ts @@ -12,4 +12,6 @@ export interface CreateOAuthTokenOpts { clientId: string; clientSecret: string; + /** Optional space-separated scopes for the access token. Defaults to '*'. */ + scope?: string; } diff --git a/src/api/resources/proxy/client/Client.ts b/src/api/resources/proxy/client/Client.ts index b5f71bc..d9d4c62 100644 --- a/src/api/resources/proxy/client/Client.ts +++ b/src/api/resources/proxy/client/Client.ts @@ -6,8 +6,8 @@ import * as environments from "../../../../environments.js"; import * as core from "../../../../core/index.js"; import * as Pipedream from "../../../index.js"; import { mergeHeaders, mergeOnlyDefinedHeaders } from "../../../../core/headers.js"; +import * as serializers from "../../../../serialization/index.js"; import * as errors from "../../../../errors/index.js"; -import { base64Encode } from "../../../../core/base64.js"; export declare namespace Proxy { export interface Options { @@ -31,6 +31,8 @@ export declare namespace Proxy { abortSignal?: AbortSignal; /** Override the x-pd-environment header */ projectEnvironment?: Pipedream.ProjectEnvironment | undefined; + /** Additional query string parameters to include in the request. */ + queryParams?: Record; /** Additional headers to include in the request. */ headers?: Record | null | undefined>; } @@ -44,52 +46,45 @@ export class Proxy { } /** - * Transform headers by prefixing each key with 'x-pd-proxy-' - */ - private transformProxyHeaders( - headers?: Record | null | undefined>, - ): Record | null | undefined> | undefined { - if (!headers) return undefined; - - const transformed: Record | null | undefined> = {}; - for (const [key, value] of Object.entries(headers)) { - transformed[`x-pd-proxy-${key}`] = value; - } - return transformed; - } - - /** + * Forward an authenticated GET request to an external API using an external user's account credentials + * + * @param {string} url64 - Base64-encoded target URL * @param {Pipedream.ProxyGetRequest} request * @param {Proxy.RequestOptions} requestOptions - Request-specific configuration. * + * @throws {@link Pipedream.TooManyRequestsError} + * * @example - * await client.proxy.get({ - * url: "https://api.example.com/endpoint", + * await client.proxy.get("url_64", { * externalUserId: "external_user_id", - * accountId: "account_id", - * params: { key: "value" }, - * headers: { "X-Custom-Header": "value" } + * accountId: "account_id" * }) */ public get( + url64: string, request: Pipedream.ProxyGetRequest, requestOptions?: Proxy.RequestOptions, ): core.HttpResponsePromise { - return core.HttpResponsePromise.fromPromise(this.__get(request, requestOptions)); + return core.HttpResponsePromise.fromPromise(this.__get(url64, request, requestOptions)); } private async __get( + url64: string, request: Pipedream.ProxyGetRequest, requestOptions?: Proxy.RequestOptions, ): Promise> { - const { url, externalUserId, accountId, params, headers } = request; - const url64 = base64Encode(url); - const transformedHeaders = this.transformProxyHeaders(headers); - const _queryParams: Record = { - external_user_id: externalUserId, - account_id: accountId, - ...(params || {}), - }; + const { externalUserId, accountId } = request; + const _queryParams: Record = {}; + _queryParams["external_user_id"] = externalUserId; + _queryParams["account_id"] = accountId; + let _headers: core.Fetcher.Args["headers"] = mergeHeaders( + this._options?.headers, + mergeOnlyDefinedHeaders({ + Authorization: await this._getAuthorizationHeader(), + "x-pd-environment": requestOptions?.projectEnvironment ?? this._options?.projectEnvironment, + }), + requestOptions?.headers, + ); const _response = await core.fetcher({ url: core.url.join( (await core.Supplier.get(this._options.baseUrl)) ?? @@ -98,30 +93,36 @@ export class Proxy { `v1/connect/${encodeURIComponent(this._options.projectId)}/proxy/${encodeURIComponent(url64)}`, ), method: "GET", - headers: mergeHeaders( - this._options?.headers, - mergeOnlyDefinedHeaders({ - Authorization: await this._getAuthorizationHeader(), - "x-pd-environment": requestOptions?.projectEnvironment, - }), - transformedHeaders, - requestOptions?.headers, - ), - queryParameters: _queryParams, + headers: _headers, + queryParameters: { ..._queryParams, ...requestOptions?.queryParams }, timeoutMs: requestOptions?.timeoutInSeconds != null ? requestOptions.timeoutInSeconds * 1000 : 60000, maxRetries: requestOptions?.maxRetries, abortSignal: requestOptions?.abortSignal, }); if (_response.ok) { - return { data: _response.body as Pipedream.ProxyResponse | undefined, rawResponse: _response.rawResponse }; + return { + data: serializers.ProxyResponse.parseOrThrow(_response.body, { + unrecognizedObjectKeys: "passthrough", + allowUnrecognizedUnionMembers: true, + allowUnrecognizedEnumValues: true, + skipValidation: true, + breadcrumbsPrefix: ["response"], + }), + rawResponse: _response.rawResponse, + }; } if (_response.error.reason === "status-code") { - throw new errors.PipedreamError({ - statusCode: _response.error.statusCode, - body: _response.error.body, - rawResponse: _response.rawResponse, - }); + switch (_response.error.statusCode) { + case 429: + throw new Pipedream.TooManyRequestsError(_response.error.body, _response.rawResponse); + default: + throw new errors.PipedreamError({ + statusCode: _response.error.statusCode, + body: _response.error.body, + rawResponse: _response.rawResponse, + }); + } } switch (_response.error.reason) { @@ -144,38 +145,48 @@ export class Proxy { } /** + * Forward an authenticated POST request to an external API using an external user's account credentials + * + * @param {string} url64 - Base64-encoded target URL * @param {Pipedream.ProxyPostRequest} request * @param {Proxy.RequestOptions} requestOptions - Request-specific configuration. * + * @throws {@link Pipedream.TooManyRequestsError} + * * @example - * await client.proxy.post({ - * url: "https://api.example.com/endpoint", + * await client.proxy.post("url_64", { * externalUserId: "external_user_id", * accountId: "account_id", - * body: { "key": "value" }, - * params: { key: "value" }, - * headers: { "X-Custom-Header": "value" } + * body: { + * "key": "value" + * } * }) */ public post( + url64: string, request: Pipedream.ProxyPostRequest, requestOptions?: Proxy.RequestOptions, ): core.HttpResponsePromise { - return core.HttpResponsePromise.fromPromise(this.__post(request, requestOptions)); + return core.HttpResponsePromise.fromPromise(this.__post(url64, request, requestOptions)); } private async __post( + url64: string, request: Pipedream.ProxyPostRequest, requestOptions?: Proxy.RequestOptions, ): Promise> { - const { url, externalUserId, accountId, body, params, headers } = request; - const url64 = base64Encode(url); - const transformedHeaders = this.transformProxyHeaders(headers); - const _queryParams: Record = { - external_user_id: externalUserId, - account_id: accountId, - ...(params || {}), - }; + const { externalUserId, accountId, body: _body } = request; + const _queryParams: Record = {}; + _queryParams["external_user_id"] = externalUserId; + _queryParams["account_id"] = accountId; + let _headers: core.Fetcher.Args["headers"] = mergeHeaders( + this._options?.headers, + mergeOnlyDefinedHeaders({ + Authorization: await this._getAuthorizationHeader(), + "x-pd-environment": requestOptions?.projectEnvironment ?? this._options?.projectEnvironment, + }), + requestOptions?.headers, + ); const _response = await core.fetcher({ url: core.url.join( (await core.Supplier.get(this._options.baseUrl)) ?? @@ -184,33 +195,42 @@ export class Proxy { `v1/connect/${encodeURIComponent(this._options.projectId)}/proxy/${encodeURIComponent(url64)}`, ), method: "POST", - headers: mergeHeaders( - this._options?.headers, - mergeOnlyDefinedHeaders({ - Authorization: await this._getAuthorizationHeader(), - "x-pd-environment": requestOptions?.projectEnvironment, - }), - transformedHeaders, - requestOptions?.headers, - ), + headers: _headers, contentType: "application/json", - queryParameters: _queryParams, + queryParameters: { ..._queryParams, ...requestOptions?.queryParams }, requestType: "json", - body, + body: serializers.proxy.post.Request.jsonOrThrow(_body, { + unrecognizedObjectKeys: "strip", + omitUndefined: true, + }), timeoutMs: requestOptions?.timeoutInSeconds != null ? requestOptions.timeoutInSeconds * 1000 : 60000, maxRetries: requestOptions?.maxRetries, abortSignal: requestOptions?.abortSignal, }); if (_response.ok) { - return { data: _response.body as Pipedream.ProxyResponse | undefined, rawResponse: _response.rawResponse }; + return { + data: serializers.ProxyResponse.parseOrThrow(_response.body, { + unrecognizedObjectKeys: "passthrough", + allowUnrecognizedUnionMembers: true, + allowUnrecognizedEnumValues: true, + skipValidation: true, + breadcrumbsPrefix: ["response"], + }), + rawResponse: _response.rawResponse, + }; } if (_response.error.reason === "status-code") { - throw new errors.PipedreamError({ - statusCode: _response.error.statusCode, - body: _response.error.body, - rawResponse: _response.rawResponse, - }); + switch (_response.error.statusCode) { + case 429: + throw new Pipedream.TooManyRequestsError(_response.error.body, _response.rawResponse); + default: + throw new errors.PipedreamError({ + statusCode: _response.error.statusCode, + body: _response.error.body, + rawResponse: _response.rawResponse, + }); + } } switch (_response.error.reason) { @@ -233,38 +253,48 @@ export class Proxy { } /** + * Forward an authenticated PUT request to an external API using an external user's account credentials + * + * @param {string} url64 - Base64-encoded target URL * @param {Pipedream.ProxyPutRequest} request * @param {Proxy.RequestOptions} requestOptions - Request-specific configuration. * + * @throws {@link Pipedream.TooManyRequestsError} + * * @example - * await client.proxy.put({ - * url: "https://api.example.com/endpoint", + * await client.proxy.put("url_64", { * externalUserId: "external_user_id", * accountId: "account_id", - * body: { "key": "value" }, - * params: { key: "value" }, - * headers: { "X-Custom-Header": "value" } + * body: { + * "key": "value" + * } * }) */ public put( + url64: string, request: Pipedream.ProxyPutRequest, requestOptions?: Proxy.RequestOptions, ): core.HttpResponsePromise { - return core.HttpResponsePromise.fromPromise(this.__put(request, requestOptions)); + return core.HttpResponsePromise.fromPromise(this.__put(url64, request, requestOptions)); } private async __put( + url64: string, request: Pipedream.ProxyPutRequest, requestOptions?: Proxy.RequestOptions, ): Promise> { - const { url, externalUserId, accountId, body, params, headers } = request; - const url64 = base64Encode(url); - const transformedHeaders = this.transformProxyHeaders(headers); - const _queryParams: Record = { - external_user_id: externalUserId, - account_id: accountId, - ...(params || {}), - }; + const { externalUserId, accountId, body: _body } = request; + const _queryParams: Record = {}; + _queryParams["external_user_id"] = externalUserId; + _queryParams["account_id"] = accountId; + let _headers: core.Fetcher.Args["headers"] = mergeHeaders( + this._options?.headers, + mergeOnlyDefinedHeaders({ + Authorization: await this._getAuthorizationHeader(), + "x-pd-environment": requestOptions?.projectEnvironment ?? this._options?.projectEnvironment, + }), + requestOptions?.headers, + ); const _response = await core.fetcher({ url: core.url.join( (await core.Supplier.get(this._options.baseUrl)) ?? @@ -273,33 +303,42 @@ export class Proxy { `v1/connect/${encodeURIComponent(this._options.projectId)}/proxy/${encodeURIComponent(url64)}`, ), method: "PUT", - headers: mergeHeaders( - this._options?.headers, - mergeOnlyDefinedHeaders({ - Authorization: await this._getAuthorizationHeader(), - "x-pd-environment": requestOptions?.projectEnvironment, - }), - transformedHeaders, - requestOptions?.headers, - ), + headers: _headers, contentType: "application/json", - queryParameters: _queryParams, + queryParameters: { ..._queryParams, ...requestOptions?.queryParams }, requestType: "json", - body, + body: serializers.proxy.put.Request.jsonOrThrow(_body, { + unrecognizedObjectKeys: "strip", + omitUndefined: true, + }), timeoutMs: requestOptions?.timeoutInSeconds != null ? requestOptions.timeoutInSeconds * 1000 : 60000, maxRetries: requestOptions?.maxRetries, abortSignal: requestOptions?.abortSignal, }); if (_response.ok) { - return { data: _response.body as Pipedream.ProxyResponse | undefined, rawResponse: _response.rawResponse }; + return { + data: serializers.ProxyResponse.parseOrThrow(_response.body, { + unrecognizedObjectKeys: "passthrough", + allowUnrecognizedUnionMembers: true, + allowUnrecognizedEnumValues: true, + skipValidation: true, + breadcrumbsPrefix: ["response"], + }), + rawResponse: _response.rawResponse, + }; } if (_response.error.reason === "status-code") { - throw new errors.PipedreamError({ - statusCode: _response.error.statusCode, - body: _response.error.body, - rawResponse: _response.rawResponse, - }); + switch (_response.error.statusCode) { + case 429: + throw new Pipedream.TooManyRequestsError(_response.error.body, _response.rawResponse); + default: + throw new errors.PipedreamError({ + statusCode: _response.error.statusCode, + body: _response.error.body, + rawResponse: _response.rawResponse, + }); + } } switch (_response.error.reason) { @@ -322,37 +361,45 @@ export class Proxy { } /** + * Forward an authenticated DELETE request to an external API using an external user's account credentials + * + * @param {string} url64 - Base64-encoded target URL * @param {Pipedream.ProxyDeleteRequest} request * @param {Proxy.RequestOptions} requestOptions - Request-specific configuration. * + * @throws {@link Pipedream.TooManyRequestsError} + * * @example - * await client.proxy.delete({ - * url: "https://api.example.com/endpoint", + * await client.proxy.delete("url_64", { * externalUserId: "external_user_id", - * accountId: "account_id", - * params: { key: "value" }, - * headers: { "X-Custom-Header": "value" } + * accountId: "account_id" * }) */ public delete( + url64: string, request: Pipedream.ProxyDeleteRequest, requestOptions?: Proxy.RequestOptions, ): core.HttpResponsePromise { - return core.HttpResponsePromise.fromPromise(this.__delete(request, requestOptions)); + return core.HttpResponsePromise.fromPromise(this.__delete(url64, request, requestOptions)); } private async __delete( + url64: string, request: Pipedream.ProxyDeleteRequest, requestOptions?: Proxy.RequestOptions, ): Promise> { - const { url, externalUserId, accountId, params, headers } = request; - const url64 = base64Encode(url); - const transformedHeaders = this.transformProxyHeaders(headers); - const _queryParams: Record = { - external_user_id: externalUserId, - account_id: accountId, - ...(params || {}), - }; + const { externalUserId, accountId } = request; + const _queryParams: Record = {}; + _queryParams["external_user_id"] = externalUserId; + _queryParams["account_id"] = accountId; + let _headers: core.Fetcher.Args["headers"] = mergeHeaders( + this._options?.headers, + mergeOnlyDefinedHeaders({ + Authorization: await this._getAuthorizationHeader(), + "x-pd-environment": requestOptions?.projectEnvironment ?? this._options?.projectEnvironment, + }), + requestOptions?.headers, + ); const _response = await core.fetcher({ url: core.url.join( (await core.Supplier.get(this._options.baseUrl)) ?? @@ -361,30 +408,36 @@ export class Proxy { `v1/connect/${encodeURIComponent(this._options.projectId)}/proxy/${encodeURIComponent(url64)}`, ), method: "DELETE", - headers: mergeHeaders( - this._options?.headers, - mergeOnlyDefinedHeaders({ - Authorization: await this._getAuthorizationHeader(), - "x-pd-environment": requestOptions?.projectEnvironment, - }), - transformedHeaders, - requestOptions?.headers, - ), - queryParameters: _queryParams, + headers: _headers, + queryParameters: { ..._queryParams, ...requestOptions?.queryParams }, timeoutMs: requestOptions?.timeoutInSeconds != null ? requestOptions.timeoutInSeconds * 1000 : 60000, maxRetries: requestOptions?.maxRetries, abortSignal: requestOptions?.abortSignal, }); if (_response.ok) { - return { data: _response.body as Pipedream.ProxyResponse | undefined, rawResponse: _response.rawResponse }; + return { + data: serializers.ProxyResponse.parseOrThrow(_response.body, { + unrecognizedObjectKeys: "passthrough", + allowUnrecognizedUnionMembers: true, + allowUnrecognizedEnumValues: true, + skipValidation: true, + breadcrumbsPrefix: ["response"], + }), + rawResponse: _response.rawResponse, + }; } if (_response.error.reason === "status-code") { - throw new errors.PipedreamError({ - statusCode: _response.error.statusCode, - body: _response.error.body, - rawResponse: _response.rawResponse, - }); + switch (_response.error.statusCode) { + case 429: + throw new Pipedream.TooManyRequestsError(_response.error.body, _response.rawResponse); + default: + throw new errors.PipedreamError({ + statusCode: _response.error.statusCode, + body: _response.error.body, + rawResponse: _response.rawResponse, + }); + } } switch (_response.error.reason) { @@ -407,38 +460,48 @@ export class Proxy { } /** + * Forward an authenticated PATCH request to an external API using an external user's account credentials + * + * @param {string} url64 - Base64-encoded target URL * @param {Pipedream.ProxyPatchRequest} request * @param {Proxy.RequestOptions} requestOptions - Request-specific configuration. * + * @throws {@link Pipedream.TooManyRequestsError} + * * @example - * await client.proxy.patch({ - * url: "https://api.example.com/endpoint", + * await client.proxy.patch("url_64", { * externalUserId: "external_user_id", * accountId: "account_id", - * body: { "key": "value" }, - * params: { key: "value" }, - * headers: { "X-Custom-Header": "value" } + * body: { + * "key": "value" + * } * }) */ public patch( + url64: string, request: Pipedream.ProxyPatchRequest, requestOptions?: Proxy.RequestOptions, ): core.HttpResponsePromise { - return core.HttpResponsePromise.fromPromise(this.__patch(request, requestOptions)); + return core.HttpResponsePromise.fromPromise(this.__patch(url64, request, requestOptions)); } private async __patch( + url64: string, request: Pipedream.ProxyPatchRequest, requestOptions?: Proxy.RequestOptions, ): Promise> { - const { url, externalUserId, accountId, body, params, headers } = request; - const url64 = base64Encode(url); - const transformedHeaders = this.transformProxyHeaders(headers); - const _queryParams: Record = { - external_user_id: externalUserId, - account_id: accountId, - ...(params || {}), - }; + const { externalUserId, accountId, body: _body } = request; + const _queryParams: Record = {}; + _queryParams["external_user_id"] = externalUserId; + _queryParams["account_id"] = accountId; + let _headers: core.Fetcher.Args["headers"] = mergeHeaders( + this._options?.headers, + mergeOnlyDefinedHeaders({ + Authorization: await this._getAuthorizationHeader(), + "x-pd-environment": requestOptions?.projectEnvironment ?? this._options?.projectEnvironment, + }), + requestOptions?.headers, + ); const _response = await core.fetcher({ url: core.url.join( (await core.Supplier.get(this._options.baseUrl)) ?? @@ -447,33 +510,42 @@ export class Proxy { `v1/connect/${encodeURIComponent(this._options.projectId)}/proxy/${encodeURIComponent(url64)}`, ), method: "PATCH", - headers: mergeHeaders( - this._options?.headers, - mergeOnlyDefinedHeaders({ - Authorization: await this._getAuthorizationHeader(), - "x-pd-environment": requestOptions?.projectEnvironment, - }), - transformedHeaders, - requestOptions?.headers, - ), + headers: _headers, contentType: "application/json", - queryParameters: _queryParams, + queryParameters: { ..._queryParams, ...requestOptions?.queryParams }, requestType: "json", - body, + body: serializers.proxy.patch.Request.jsonOrThrow(_body, { + unrecognizedObjectKeys: "strip", + omitUndefined: true, + }), timeoutMs: requestOptions?.timeoutInSeconds != null ? requestOptions.timeoutInSeconds * 1000 : 60000, maxRetries: requestOptions?.maxRetries, abortSignal: requestOptions?.abortSignal, }); if (_response.ok) { - return { data: _response.body as Pipedream.ProxyResponse | undefined, rawResponse: _response.rawResponse }; + return { + data: serializers.ProxyResponse.parseOrThrow(_response.body, { + unrecognizedObjectKeys: "passthrough", + allowUnrecognizedUnionMembers: true, + allowUnrecognizedEnumValues: true, + skipValidation: true, + breadcrumbsPrefix: ["response"], + }), + rawResponse: _response.rawResponse, + }; } if (_response.error.reason === "status-code") { - throw new errors.PipedreamError({ - statusCode: _response.error.statusCode, - body: _response.error.body, - rawResponse: _response.rawResponse, - }); + switch (_response.error.statusCode) { + case 429: + throw new Pipedream.TooManyRequestsError(_response.error.body, _response.rawResponse); + default: + throw new errors.PipedreamError({ + statusCode: _response.error.statusCode, + body: _response.error.body, + rawResponse: _response.rawResponse, + }); + } } switch (_response.error.reason) { diff --git a/src/api/resources/proxy/client/requests/ProxyDeleteRequest.ts b/src/api/resources/proxy/client/requests/ProxyDeleteRequest.ts index 2f22dd7..d22c45d 100644 --- a/src/api/resources/proxy/client/requests/ProxyDeleteRequest.ts +++ b/src/api/resources/proxy/client/requests/ProxyDeleteRequest.ts @@ -2,37 +2,16 @@ * This file was auto-generated by Fern from our API Definition. */ -import * as core from "../../../../../core/index.js"; - /** * @example * { - * url: "https://api.example.com/endpoint", * externalUserId: "external_user_id", - * accountId: "account_id", - * params: { page: "1", limit: "10" }, - * headers: { "X-Custom-Header": "value" } + * accountId: "account_id" * } */ export interface ProxyDeleteRequest { - /** - * Target URL to proxy request to - */ - url: string; - /** - * The external user ID for the proxy request - */ + /** The external user ID for the proxy request */ externalUserId: string; - /** - * The account ID to use for authentication - */ + /** The account ID to use for authentication */ accountId: string; - /** - * Query parameters to forward - */ - params?: Record; - /** - * Additional headers to include (will be prefixed with 'x-pd-proxy-') - */ - headers?: Record | undefined>; } diff --git a/src/api/resources/proxy/client/requests/ProxyGetRequest.ts b/src/api/resources/proxy/client/requests/ProxyGetRequest.ts index 9aa2ef1..bad54af 100644 --- a/src/api/resources/proxy/client/requests/ProxyGetRequest.ts +++ b/src/api/resources/proxy/client/requests/ProxyGetRequest.ts @@ -2,37 +2,16 @@ * This file was auto-generated by Fern from our API Definition. */ -import * as core from "../../../../../core/index.js"; - /** * @example * { - * url: "https://api.example.com/endpoint", * externalUserId: "external_user_id", - * accountId: "account_id", - * params: { page: "1", limit: "10" }, - * headers: { "X-Custom-Header": "value" } + * accountId: "account_id" * } */ export interface ProxyGetRequest { - /** - * Target URL to proxy request to - */ - url: string; - /** - * The external user ID for the proxy request - */ + /** The external user ID for the proxy request */ externalUserId: string; - /** - * The account ID to use for authentication - */ + /** The account ID to use for authentication */ accountId: string; - /** - * Query parameters to forward - */ - params?: Record; - /** - * Additional headers to include (will be prefixed with 'x-pd-proxy-') - */ - headers?: Record | undefined>; } diff --git a/src/api/resources/proxy/client/requests/ProxyPatchRequest.ts b/src/api/resources/proxy/client/requests/ProxyPatchRequest.ts index 0d4e46a..f8fc217 100644 --- a/src/api/resources/proxy/client/requests/ProxyPatchRequest.ts +++ b/src/api/resources/proxy/client/requests/ProxyPatchRequest.ts @@ -2,44 +2,21 @@ * This file was auto-generated by Fern from our API Definition. */ -import * as core from "../../../../../core/index.js"; - /** * @example * { - * url: "https://api.example.com/endpoint", * externalUserId: "external_user_id", * accountId: "account_id", * body: { * "key": "value" - * }, - * params: { page: "1", limit: "10" }, - * headers: { "X-Custom-Header": "value" } + * } * } */ export interface ProxyPatchRequest { - /** - * Target URL to proxy request to - */ - url: string; - /** - * The external user ID for the proxy request - */ + /** The external user ID for the proxy request */ externalUserId: string; - /** - * The account ID to use for authentication - */ + /** The account ID to use for authentication */ accountId: string; - /** - * Request body to forward to the target API - */ + /** Request body to forward to the target API */ body: Record; - /** - * Query parameters to forward - */ - params?: Record; - /** - * Additional headers to include (will be prefixed with 'x-pd-proxy-') - */ - headers?: Record | undefined>; } diff --git a/src/api/resources/proxy/client/requests/ProxyPostRequest.ts b/src/api/resources/proxy/client/requests/ProxyPostRequest.ts index c0e8f2e..7da8023 100644 --- a/src/api/resources/proxy/client/requests/ProxyPostRequest.ts +++ b/src/api/resources/proxy/client/requests/ProxyPostRequest.ts @@ -2,44 +2,21 @@ * This file was auto-generated by Fern from our API Definition. */ -import * as core from "../../../../../core/index.js"; - /** * @example * { - * url: "https://api.example.com/endpoint", * externalUserId: "external_user_id", * accountId: "account_id", * body: { * "key": "value" - * }, - * params: { page: "1", limit: "10" }, - * headers: { "X-Custom-Header": "value" } + * } * } */ export interface ProxyPostRequest { - /** - * Target URL to proxy request to - */ - url: string; - /** - * The external user ID for the proxy request - */ + /** The external user ID for the proxy request */ externalUserId: string; - /** - * The account ID to use for authentication - */ + /** The account ID to use for authentication */ accountId: string; - /** - * Request body to forward to the target API - */ + /** Request body to forward to the target API */ body: Record; - /** - * Query parameters to forward - */ - params?: Record; - /** - * Additional headers to include (will be prefixed with 'x-pd-proxy-') - */ - headers?: Record | undefined>; } diff --git a/src/api/resources/proxy/client/requests/ProxyPutRequest.ts b/src/api/resources/proxy/client/requests/ProxyPutRequest.ts index a850506..76ce488 100644 --- a/src/api/resources/proxy/client/requests/ProxyPutRequest.ts +++ b/src/api/resources/proxy/client/requests/ProxyPutRequest.ts @@ -2,44 +2,21 @@ * This file was auto-generated by Fern from our API Definition. */ -import * as core from "../../../../../core/index.js"; - /** * @example * { - * url: "https://api.example.com/endpoint", * externalUserId: "external_user_id", * accountId: "account_id", * body: { * "key": "value" - * }, - * params: { page: "1", limit: "10" }, - * headers: { "X-Custom-Header": "value" } + * } * } */ export interface ProxyPutRequest { - /** - * Target URL to proxy request to - */ - url: string; - /** - * The external user ID for the proxy request - */ + /** The external user ID for the proxy request */ externalUserId: string; - /** - * The account ID to use for authentication - */ + /** The account ID to use for authentication */ accountId: string; - /** - * Request body to forward to the target API - */ + /** Request body to forward to the target API */ body: Record; - /** - * Query parameters to forward - */ - params?: Record; - /** - * Additional headers to include (will be prefixed with 'x-pd-proxy-') - */ - headers?: Record | undefined>; } diff --git a/src/api/resources/triggers/client/requests/DeployTriggerOpts.ts b/src/api/resources/triggers/client/requests/DeployTriggerOpts.ts index 70e5b40..5a041f5 100644 --- a/src/api/resources/triggers/client/requests/DeployTriggerOpts.ts +++ b/src/api/resources/triggers/client/requests/DeployTriggerOpts.ts @@ -19,6 +19,8 @@ export interface DeployTriggerOpts { configuredProps?: Pipedream.ConfiguredProps; /** The ID for dynamic props */ dynamicPropsId?: string; + /** Optional ID of a workflow to receive trigger events */ + workflowId?: string; /** Optional webhook URL to receive trigger events */ webhookUrl?: string; } diff --git a/src/api/resources/workflows/client/Client.ts b/src/api/resources/workflows/client/Client.ts deleted file mode 100644 index 5cc8bf1..0000000 --- a/src/api/resources/workflows/client/Client.ts +++ /dev/null @@ -1,278 +0,0 @@ -/** - * This file was auto-generated by Fern from our API Definition. - */ - -import * as environments from "../../../../environments.js"; -import * as core from "../../../../core/index.js"; -import * as Pipedream from "../../../index.js"; -import { mergeHeaders, mergeOnlyDefinedHeaders } from "../../../../core/headers.js"; -import * as errors from "../../../../errors/index.js"; - -export declare namespace Workflows { - export interface Options { - environment?: core.Supplier; - /** Specify a custom URL to connect the client to. */ - baseUrl?: core.Supplier; - projectId: string; - token?: core.Supplier; - /** Override the x-pd-environment header */ - projectEnvironment?: core.Supplier; - /** Additional headers to include in requests. */ - headers?: Record | null | undefined>; - /** Base domain for workflows. Used for custom domains. */ - workflowDomain?: string; - } - - export interface RequestOptions { - /** The maximum time to wait for a response in seconds. */ - timeoutInSeconds?: number; - /** The number of times to retry the request. Defaults to 2. */ - maxRetries?: number; - /** A hook to abort the request. */ - abortSignal?: AbortSignal; - /** Override the x-pd-environment header */ - projectEnvironment?: Pipedream.ProjectEnvironment | undefined; - /** Additional query string parameters to include in the request. */ - queryParams?: Record; - /** Additional headers to include in the request. */ - headers?: Record | null | undefined>; - } -} - -export class Workflows { - protected readonly _options: Workflows.Options; - private readonly workflowDomain: string; - - constructor(_options: Workflows.Options) { - this._options = _options; - this.workflowDomain = _options.workflowDomain ?? this._defaultWorkflowDomain; - } - - private get _defaultWorkflowDomain(): string { - return this._options.environment !== environments.PipedreamEnvironment.Prod && - this._options.environment !== environments.PipedreamEnvironment.Canary - ? "m.d.pipedream.net" - : "m.pipedream.net"; - } - - private get _urlProtocol(): string { - return this._options.environment !== environments.PipedreamEnvironment.Prod && - this._options.environment !== environments.PipedreamEnvironment.Canary - ? "http" - : "https"; - } - - /** - * Invokes a workflow using the URL of its HTTP interface(s), by sending an - * HTTP request. - * - * @param {Pipedream.InvokeWorkflowOpts} request - * @param {Pipedream.HTTPAuthType} authType - The type of authorization to use - * for the request (defaults to None). - * @param {Workflows.RequestOptions} requestOptions - Request-specific - * configuration. - * - * @example - * await client.workflows.invoke({ - * urlOrEndpoint: "https://en-your-endpoint.m.pipedream.net", - * body: { - * foo: 123, - * bar: "abc", - * baz: null - * }, - * headers: { - * "Accept": "application/json" - * } - * }, Pipedream.HTTPAuthType.OAuth) - */ - public invoke( - request: Pipedream.InvokeWorkflowOpts, - authType: Pipedream.HTTPAuthType = Pipedream.HTTPAuthType.None, - requestOptions?: Workflows.RequestOptions, - ): core.HttpResponsePromise { - return core.HttpResponsePromise.fromPromise(this.__invoke(request, authType, requestOptions)); - } - - private async __invoke( - request: Pipedream.InvokeWorkflowOpts, - authType: Pipedream.HTTPAuthType = Pipedream.HTTPAuthType.None, - requestOptions?: Workflows.RequestOptions, - ): Promise> { - const { urlOrEndpoint, body, method = "POST", headers = {} } = request; - - const url = this._buildWorkflowUrl(urlOrEndpoint); - - let authHeader: string | undefined; - switch (authType) { - case Pipedream.HTTPAuthType.StaticBearer: - // It's expected that users will pass their own Authorization header in - // the static bearer case - authHeader = headers["Authorization"]; - break; - case Pipedream.HTTPAuthType.OAuth: - authHeader = await this._getAuthorizationHeader(); - break; - default: - break; - } - - const _response = await core.fetcher({ - url, - method: method.toUpperCase(), - headers: mergeHeaders( - this._options?.headers, - mergeOnlyDefinedHeaders({ - Authorization: authHeader, - "x-pd-environment": requestOptions?.projectEnvironment, - }), - headers, - requestOptions?.headers, - ), - contentType: body != null ? "application/json" : undefined, - queryParameters: requestOptions?.queryParams, - requestType: body != null ? "json" : undefined, - body, - timeoutMs: requestOptions?.timeoutInSeconds != null ? requestOptions.timeoutInSeconds * 1000 : 60000, - maxRetries: requestOptions?.maxRetries, - abortSignal: requestOptions?.abortSignal, - }); - - if (!_response.ok) { - throw new errors.PipedreamError({ - message: _response.error.reason, - statusCode: _response.rawResponse.status, - rawResponse: _response.rawResponse, - }); - } - - return { - data: _response.rawResponse, - rawResponse: _response.rawResponse, - }; - } - - /** - * Invokes a workflow for a Pipedream Connect user in a project. - * - * @param {Pipedream.InvokeWorkflowForExternalUserOpts} request - * @param {Workflows.RequestOptions} requestOptions - Request-specific - * configuration. - * - * @example - * await client.workflows.invokeForExternalUser({ - * urlOrEndpoint: "https://your-workflow-url.m.pipedream.net", - * externalUserId: "your-external-user-id", - * body: { - * foo: 123, - * bar: "abc", - * baz: null - * }, - * headers: { - * "Accept": "application/json" - * } - * }) - */ - public invokeForExternalUser( - request: Pipedream.InvokeWorkflowForExternalUserOpts, - requestOptions?: Workflows.RequestOptions, - ): core.HttpResponsePromise { - return core.HttpResponsePromise.fromPromise(this.__invokeForExternalUser(request, requestOptions)); - } - - private async __invokeForExternalUser( - request: Pipedream.InvokeWorkflowForExternalUserOpts, - requestOptions?: Workflows.RequestOptions, - ): Promise> { - const { urlOrEndpoint, externalUserId, body, method, headers = {} } = request; - - if (!externalUserId?.trim()) { - throw new Error("External user ID is required"); - } - - if (!urlOrEndpoint.trim()) { - throw new Error("Workflow URL or endpoint ID is required"); - } - - const authHeader = await this._getAuthorizationHeader(); - if (!authHeader) { - throw new Error( - "OAuth or token is required for invoking workflows for external users. Please pass credentials for a valid OAuth client", - ); - } - - // Delegate to invoke method with external user ID header and OAuth auth - return this.__invoke( - { - urlOrEndpoint, - body, - method, - headers: { - ...headers, - "X-PD-External-User-ID": externalUserId, - }, - }, - Pipedream.HTTPAuthType.OAuth, - requestOptions, - ); - } - - /** - * Builds a full workflow URL based on the input. - * - * @param input - Either a full URL (with or without protocol) or just an - * endpoint ID. - * @returns The fully constructed URL. - * @throws If the input is a malformed URL, throws an error with a clear - * message. - */ - private _buildWorkflowUrl(input: string): string { - const sanitizedInput = input - .trim() - .replace(/[^\w-./:]/g, "") - .toLowerCase(); - if (!sanitizedInput) { - throw new Error("URL or endpoint ID is required"); - } - - let url: string; - const isUrl = sanitizedInput.includes(".") || sanitizedInput.startsWith("http"); - - if (isUrl) { - // Try to parse the input as a URL - let parsedUrl: URL; - try { - const urlString = sanitizedInput.startsWith("http") ? sanitizedInput : `https://${sanitizedInput}`; - parsedUrl = new URL(urlString); - } catch { - throw new Error(`The provided URL is malformed: "${sanitizedInput}". Please provide a valid URL.`); - } - - // Validate the hostname to prevent potential DNS rebinding attacks - if (!parsedUrl.hostname.endsWith(this.workflowDomain)) { - throw new Error(`Invalid workflow domain. URL must end with ${this.workflowDomain}`); - } - - url = parsedUrl.href; - } else { - // If the input is an ID, construct the full URL using the base domain - if (!/^e(n|o)[a-z0-9-]+$/i.test(sanitizedInput)) { - throw new Error( - `Invalid endpoint ID format. Must contain only letters, numbers, and hyphens, and start with either "en" or "eo".`, - ); - } - - url = `${this._urlProtocol}://${sanitizedInput}.${this.workflowDomain}`; - } - - return url; - } - - protected async _getAuthorizationHeader(): Promise { - const bearer = await core.Supplier.get(this._options.token); - if (bearer != null) { - return `Bearer ${bearer}`; - } - - return undefined; - } -} diff --git a/src/api/resources/workflows/client/index.ts b/src/api/resources/workflows/client/index.ts deleted file mode 100644 index 10df5b2..0000000 --- a/src/api/resources/workflows/client/index.ts +++ /dev/null @@ -1,2 +0,0 @@ -export * from "./Client.js"; -export * from "./requests/index.js"; diff --git a/src/api/resources/workflows/client/requests/InvokeWorkflowForExternalUserOpts.ts b/src/api/resources/workflows/client/requests/InvokeWorkflowForExternalUserOpts.ts deleted file mode 100644 index 52ce1d7..0000000 --- a/src/api/resources/workflows/client/requests/InvokeWorkflowForExternalUserOpts.ts +++ /dev/null @@ -1,26 +0,0 @@ -/** - * This file was auto-generated by Fern from our API Definition. - */ - -export interface InvokeWorkflowForExternalUserOpts { - /** - * The URL of the workflow's HTTP interface, or the ID of the endpoint. - */ - urlOrEndpoint: string; - /** - * Your end user ID, for whom you're invoking the workflow. - */ - externalUserId: string; - /** - * The body of the request. It must be a JSON-serializable value (e.g. an object, null, a string, etc.). - */ - body?: unknown; - /** - * HTTP method to use for the request (defaults to POST if not specified). - */ - method?: string; - /** - * Additional headers to include in the request. - */ - headers?: Record; -} diff --git a/src/api/resources/workflows/client/requests/InvokeWorkflowOpts.ts b/src/api/resources/workflows/client/requests/InvokeWorkflowOpts.ts deleted file mode 100644 index 0613d8d..0000000 --- a/src/api/resources/workflows/client/requests/InvokeWorkflowOpts.ts +++ /dev/null @@ -1,22 +0,0 @@ -/** - * This file was auto-generated by Fern from our API Definition. - */ - -export interface InvokeWorkflowOpts { - /** - * The URL of the workflow's HTTP interface, or the ID of the endpoint. - */ - urlOrEndpoint: string; - /** - * The body of the request. It must be a JSON-serializable value (e.g. an object, null, a string, etc.). - */ - body?: unknown; - /** - * HTTP method to use for the request (defaults to POST if not specified). - */ - method?: string; - /** - * Additional headers to include in the request. - */ - headers?: Record; -} diff --git a/src/api/resources/workflows/client/requests/index.ts b/src/api/resources/workflows/client/requests/index.ts deleted file mode 100644 index 99a5d0a..0000000 --- a/src/api/resources/workflows/client/requests/index.ts +++ /dev/null @@ -1,2 +0,0 @@ -export { type InvokeWorkflowOpts } from "./InvokeWorkflowOpts.js"; -export { type InvokeWorkflowForExternalUserOpts } from "./InvokeWorkflowForExternalUserOpts.js"; diff --git a/src/api/resources/workflows/index.ts b/src/api/resources/workflows/index.ts deleted file mode 100644 index 914b8c3..0000000 --- a/src/api/resources/workflows/index.ts +++ /dev/null @@ -1 +0,0 @@ -export * from "./client/index.js"; diff --git a/src/api/types/BackendClientOpts.ts b/src/api/types/BackendClientOpts.ts index c2bdd90..9af6602 100644 --- a/src/api/types/BackendClientOpts.ts +++ b/src/api/types/BackendClientOpts.ts @@ -12,4 +12,6 @@ export interface BackendClientOpts { clientSecret?: string; /** The API URL to use */ apiUrl?: string; + /** Optional space-separated scopes for the access token. Defaults to '*'. */ + scope?: string; } diff --git a/src/api/types/ConfiguredProps.ts b/src/api/types/ConfiguredProps.ts index bd0aacd..1684ba8 100644 --- a/src/api/types/ConfiguredProps.ts +++ b/src/api/types/ConfiguredProps.ts @@ -1,25 +1,10 @@ -import type * as Pipedream from "./index.js"; - -export type ConfigurableProps = Readonly; +/** + * This file was auto-generated by Fern from our API Definition. + */ -export type PropTypeMap = { - alert: never; - any: Pipedream.ConfiguredPropValueAny; - app: Pipedream.ConfiguredPropValueApp; - boolean: Pipedream.ConfiguredPropValueBoolean; - integer: Pipedream.ConfiguredPropValueInteger; - object: Pipedream.ConfiguredPropValueObject; - string: Pipedream.ConfiguredPropValueString; - "string[]": Pipedream.ConfiguredPropValueStringArray; - sql: Pipedream.ConfiguredPropValueSql; -}; -export type PropValue = T extends keyof PropTypeMap - ? PropTypeMap[T] - : never; +import * as Pipedream from "../index.js"; /** * The configured properties of the component */ -export type ConfiguredProps = { - [K in T[number] as K["name"]]?: PropValue; -}; +export type ConfiguredProps = Record; diff --git a/src/api/types/HTTPAuthType.ts b/src/api/types/HTTPAuthType.ts deleted file mode 100644 index 19998a8..0000000 --- a/src/api/types/HTTPAuthType.ts +++ /dev/null @@ -1,12 +0,0 @@ -/** - * This file was auto-generated by Fern from our API Definition. - */ - -/** - * Different ways in which customers can authorize requests to HTTP endpoints - */ -export enum HTTPAuthType { - None = "none", - StaticBearer = "static_bearer_token", - OAuth = "oauth", -} diff --git a/src/api/types/index.ts b/src/api/types/index.ts index 586b98b..34f8dda 100644 --- a/src/api/types/index.ts +++ b/src/api/types/index.ts @@ -1,51 +1,53 @@ -export * from "./Account.js"; +export * from "./TooManyRequestsErrorBody.js"; export * from "./AccountId.js"; +export * from "./Account.js"; export * from "./App.js"; export * from "./AppAuthType.js"; export * from "./AppCategory.js"; export * from "./BackendClientOpts.js"; export * from "./ClientOpts.js"; export * from "./Component.js"; +export * from "./ToolAnnotations.js"; export * from "./ComponentStash.js"; export * from "./ComponentType.js"; +export * from "./TimerInterval.js"; +export * from "./TimerCron.js"; +export * from "./ConfigurablePropType.js"; export * from "./ConfigurableProp.js"; -export * from "./ConfigurablePropAirtableBaseId.js"; -export * from "./ConfigurablePropAirtableFieldId.js"; -export * from "./ConfigurablePropAirtableTableId.js"; -export * from "./ConfigurablePropAirtableViewId.js"; export * from "./ConfigurablePropAlert.js"; export * from "./ConfigurablePropAlertType.js"; -export * from "./ConfigurablePropAny.js"; export * from "./ConfigurablePropAnyOptionsItem.js"; +export * from "./ConfigurablePropAny.js"; export * from "./ConfigurablePropApp.js"; -export * from "./ConfigurablePropApphook.js"; -export * from "./ConfigurablePropBoolean.js"; export * from "./ConfigurablePropBooleanOptionsItem.js"; +export * from "./ConfigurablePropBoolean.js"; +export * from "./ConfigurablePropTimer.js"; +export * from "./ConfigurablePropTimerDefault.js"; +export * from "./ConfigurablePropTimerOption.js"; +export * from "./ConfigurablePropTimerStatic.js"; +export * from "./ConfigurablePropApphook.js"; +export * from "./ConfigurablePropIntegerArrayOptionsItem.js"; +export * from "./ConfigurablePropIntegerArray.js"; +export * from "./ConfigurablePropHttp.js"; export * from "./ConfigurablePropDb.js"; -export * from "./ConfigurablePropDiscord.js"; +export * from "./ConfigurablePropSqlOptionsItem.js"; +export * from "./ConfigurablePropSql.js"; +export * from "./ConfigurablePropSqlAuth.js"; +export * from "./ConfigurablePropAirtableBaseId.js"; +export * from "./ConfigurablePropAirtableTableId.js"; +export * from "./ConfigurablePropAirtableViewId.js"; +export * from "./ConfigurablePropAirtableFieldId.js"; export * from "./ConfigurablePropDiscordChannel.js"; export * from "./ConfigurablePropDiscordChannelArray.js"; -export * from "./ConfigurablePropHttp.js"; -export * from "./ConfigurablePropInteger.js"; +export * from "./ConfigurablePropDiscord.js"; export * from "./ConfigurablePropIntegerOptionsItem.js"; -export * from "./ConfigurablePropIntegerArray.js"; -export * from "./ConfigurablePropIntegerArrayOptionsItem.js"; -export * from "./ConfigurablePropObject.js"; +export * from "./ConfigurablePropInteger.js"; export * from "./ConfigurablePropObjectOptionsItem.js"; -export * from "./ConfigurablePropSql.js"; -export * from "./ConfigurablePropSqlAuth.js"; -export * from "./ConfigurablePropSqlOptionsItem.js"; -export * from "./ConfigurablePropString.js"; +export * from "./ConfigurablePropObject.js"; export * from "./ConfigurablePropStringOptionsItem.js"; -export * from "./ConfigurablePropStringArray.js"; +export * from "./ConfigurablePropString.js"; export * from "./ConfigurablePropStringArrayOptionsItem.js"; -export * from "./ConfigurablePropTimer.js"; -export * from "./ConfigurablePropTimerDefault.js"; -export * from "./ConfigurablePropTimerOption.js"; -export * from "./ConfigurablePropTimerStatic.js"; -export * from "./ConfigurablePropType.js"; -export * from "./ConfiguredProps.js"; -export * from "./ConfiguredPropValue.js"; +export * from "./ConfigurablePropStringArray.js"; export * from "./ConfiguredPropValueAny.js"; export * from "./ConfiguredPropValueApp.js"; export * from "./ConfiguredPropValueBoolean.js"; @@ -54,37 +56,38 @@ export * from "./ConfiguredPropValueObject.js"; export * from "./ConfiguredPropValueSql.js"; export * from "./ConfiguredPropValueString.js"; export * from "./ConfiguredPropValueStringArray.js"; -export * from "./ConfigurePropOptions.js"; +export * from "./ConfiguredProps.js"; export * from "./ConfigurePropOptionsItem.js"; +export * from "./ConfigurePropOptions.js"; export * from "./ConfigurePropOpts.js"; export * from "./ConfigurePropResponse.js"; +export * from "./ConfiguredPropValue.js"; export * from "./ConnectToken.js"; export * from "./CreateOAuthTokenResponse.js"; export * from "./CreateTokenResponse.js"; export * from "./DeleteTriggerOpts.js"; export * from "./DeployedComponent.js"; -export * from "./DeployTriggerResponse.js"; export * from "./DeployTriggerResponseData.js"; +export * from "./DeployTriggerResponse.js"; export * from "./DynamicProps.js"; export * from "./EmittedEvent.js"; export * from "./ErrorResponse.js"; export * from "./GetAccountsResponse.js"; -export * from "./GetAppCategoryResponse.js"; export * from "./GetAppResponse.js"; +export * from "./GetAppCategoryResponse.js"; export * from "./GetAppsResponse.js"; export * from "./GetComponentResponse.js"; export * from "./GetComponentsResponse.js"; export * from "./GetTriggerEventsResponse.js"; -export * from "./GetTriggerResponse.js"; export * from "./GetTriggerResponseData.js"; -export * from "./GetTriggersResponse.js"; +export * from "./GetTriggerResponse.js"; export * from "./GetTriggerWebhooksResponse.js"; export * from "./GetTriggerWorkflowsResponse.js"; -export * from "./HTTPAuthType.js"; +export * from "./GetTriggersResponse.js"; export * from "./HttpInterface.js"; export * from "./ListAccountsResponse.js"; -export * from "./ListAppCategoriesResponse.js"; export * from "./ListAppsResponse.js"; +export * from "./ListAppCategoriesResponse.js"; export * from "./Observation.js"; export * from "./ObservationError.js"; export * from "./PageInfo.js"; @@ -92,8 +95,8 @@ export * from "./ProjectEnvironment.js"; export * from "./ProjectInfoResponse.js"; export * from "./ProjectInfoResponseApp.js"; export * from "./PropOption.js"; -export * from "./PropOptionValue.js"; export * from "./PropOptionNested.js"; +export * from "./PropOptionValue.js"; export * from "./ProxyResponse.js"; export * from "./ReloadPropsOpts.js"; export * from "./ReloadPropsResponse.js"; @@ -101,9 +104,5 @@ export * from "./RunActionOptsStashId.js"; export * from "./RunActionResponse.js"; export * from "./StartConnectOpts.js"; export * from "./StashId.js"; -export * from "./TimerCron.js"; export * from "./TimerInterface.js"; -export * from "./TimerInterval.js"; -export * from "./ToolAnnotations.js"; -export * from "./TooManyRequestsErrorBody.js"; export * from "./ValidateTokenResponse.js"; diff --git a/src/core/auth/ConnectTokenProvider.ts b/src/core/auth/ConnectTokenProvider.ts deleted file mode 100644 index bd02209..0000000 --- a/src/core/auth/ConnectTokenProvider.ts +++ /dev/null @@ -1,66 +0,0 @@ -import type { CreateTokenResponse } from "../../api/index.js"; -import type { TokenProvider } from "./TokenProvider.js"; - -export type TokenCallback = (opts: { externalUserId: string }) => Promise; - -export class ConnectTokenProvider implements TokenProvider { - private readonly _tokenCallback: TokenCallback; - private _externalUserId?: string; - private _token?: string; - private _tokenExpiresAt?: Date; - private _tokenRequest?: Promise; - - constructor({ tokenCallback, externalUserId }: { tokenCallback: TokenCallback; externalUserId: string }) { - if (!externalUserId) { - throw new Error("The external user ID cannot be blank"); - } - - if (typeof tokenCallback !== "function") { - throw new Error("The token callback must be a function"); - } - - this._externalUserId = externalUserId; - this._tokenCallback = tokenCallback; - } - - get externalUserId(): string | undefined { - return this._externalUserId; - } - - public async getToken(): Promise { - if (this._token && this._tokenExpiresAt && this._tokenExpiresAt > new Date()) { - return this._token; - } - - if (this._tokenRequest) { - return this._tokenRequest; - } - - const tokenCallback = this._tokenCallback; - const externalUserId = this._externalUserId; - - if (!tokenCallback) { - throw new Error("No token callback provided"); - } - if (!externalUserId) { - throw new Error("No external user ID provided"); - } - - // Ensure only one token request is in-flight at a time. - this._tokenRequest = (async () => { - const { token, expiresAt } = await tokenCallback({ - externalUserId, - }); - this._token = token; - this._tokenExpiresAt = expiresAt; - this._tokenRequest = undefined; - return token; - })(); - - return this._tokenRequest; - } - - public refresh() { - this._token = undefined; - } -} diff --git a/src/core/auth/StaticTokenProvider.ts b/src/core/auth/StaticTokenProvider.ts deleted file mode 100644 index b5b2beb..0000000 --- a/src/core/auth/StaticTokenProvider.ts +++ /dev/null @@ -1,13 +0,0 @@ -import type { TokenProvider } from "./TokenProvider.js"; - -export class StaticTokenProvider implements TokenProvider { - private readonly _token: string; - - constructor(token: string) { - this._token = token; - } - - public async getToken(): Promise { - return this._token; - } -} diff --git a/src/core/auth/TokenProvider.ts b/src/core/auth/TokenProvider.ts deleted file mode 100644 index f648c39..0000000 --- a/src/core/auth/TokenProvider.ts +++ /dev/null @@ -1,3 +0,0 @@ -export interface TokenProvider { - getToken(): Promise; -} diff --git a/src/core/auth/index.ts b/src/core/auth/index.ts index 4fa3620..1ec5eb4 100644 --- a/src/core/auth/index.ts +++ b/src/core/auth/index.ts @@ -1,6 +1,3 @@ export { BasicAuth } from "./BasicAuth.js"; export { BearerToken } from "./BearerToken.js"; -export { ConnectTokenProvider, TokenCallback } from "./ConnectTokenProvider.js"; export { OAuthTokenProvider } from "./OAuthTokenProvider.js"; -export { StaticTokenProvider } from "./StaticTokenProvider.js"; -export { TokenProvider } from "./TokenProvider.js"; diff --git a/src/serialization/resources/oauthTokens/client/requests/CreateOAuthTokenOpts.ts b/src/serialization/resources/oauthTokens/client/requests/CreateOAuthTokenOpts.ts index 8811d51..39c6ab0 100644 --- a/src/serialization/resources/oauthTokens/client/requests/CreateOAuthTokenOpts.ts +++ b/src/serialization/resources/oauthTokens/client/requests/CreateOAuthTokenOpts.ts @@ -12,11 +12,13 @@ export const CreateOAuthTokenOpts: core.serialization.Schema< > = core.serialization.object({ clientId: core.serialization.property("client_id", core.serialization.string()), clientSecret: core.serialization.property("client_secret", core.serialization.string()), + scope: core.serialization.string().optional(), }); export declare namespace CreateOAuthTokenOpts { export interface Raw { client_id: string; client_secret: string; + scope?: string | null; } } diff --git a/src/serialization/resources/triggers/client/requests/DeployTriggerOpts.ts b/src/serialization/resources/triggers/client/requests/DeployTriggerOpts.ts index 58f6260..ca18786 100644 --- a/src/serialization/resources/triggers/client/requests/DeployTriggerOpts.ts +++ b/src/serialization/resources/triggers/client/requests/DeployTriggerOpts.ts @@ -16,6 +16,7 @@ export const DeployTriggerOpts: core.serialization.Schema< externalUserId: core.serialization.property("external_user_id", core.serialization.string()), configuredProps: core.serialization.property("configured_props", ConfiguredProps.optional()), dynamicPropsId: core.serialization.property("dynamic_props_id", core.serialization.string().optional()), + workflowId: core.serialization.property("workflow_id", core.serialization.string().optional()), webhookUrl: core.serialization.property("webhook_url", core.serialization.string().optional()), }); @@ -25,6 +26,7 @@ export declare namespace DeployTriggerOpts { external_user_id: string; configured_props?: ConfiguredProps.Raw | null; dynamic_props_id?: string | null; + workflow_id?: string | null; webhook_url?: string | null; } } diff --git a/src/serialization/types/BackendClientOpts.ts b/src/serialization/types/BackendClientOpts.ts index 8427ba3..1861fef 100644 --- a/src/serialization/types/BackendClientOpts.ts +++ b/src/serialization/types/BackendClientOpts.ts @@ -13,6 +13,7 @@ export const BackendClientOpts: core.serialization.ObjectSchema< clientId: core.serialization.property("client_id", core.serialization.string().optional()), clientSecret: core.serialization.property("client_secret", core.serialization.string().optional()), apiUrl: core.serialization.property("api_url", core.serialization.string().optional()), + scope: core.serialization.string().optional(), }); export declare namespace BackendClientOpts { @@ -20,5 +21,6 @@ export declare namespace BackendClientOpts { client_id?: string | null; client_secret?: string | null; api_url?: string | null; + scope?: string | null; } } diff --git a/src/serialization/types/ConfiguredProps.ts b/src/serialization/types/ConfiguredProps.ts index e3e63fd..f0ec7ea 100644 --- a/src/serialization/types/ConfiguredProps.ts +++ b/src/serialization/types/ConfiguredProps.ts @@ -7,10 +7,8 @@ import * as Pipedream from "../../api/index.js"; import * as core from "../../core/index.js"; import { ConfiguredPropValue } from "./ConfiguredPropValue.js"; -export const ConfiguredProps: core.serialization.Schema< - serializers.ConfiguredProps.Raw, - Pipedream.ConfiguredProps -> = core.serialization.record(core.serialization.string(), ConfiguredPropValue) as any; +export const ConfiguredProps: core.serialization.Schema = + core.serialization.record(core.serialization.string(), ConfiguredPropValue); export declare namespace ConfiguredProps { export type Raw = Record; diff --git a/src/version.ts b/src/version.ts index fd97750..c40290c 100644 --- a/src/version.ts +++ b/src/version.ts @@ -1 +1 @@ -export const SDK_VERSION = "2.0.13"; +export const SDK_VERSION = "2.0.14";