From 41f01698f9a5965f6756d57961e2d1cc0801ff09 Mon Sep 17 00:00:00 2001 From: "fern-api[bot]" <115122769+fern-api[bot]@users.noreply.github.com> Date: Wed, 10 Dec 2025 21:32:01 +0000 Subject: [PATCH 1/3] SDK regeneration --- package.json | 33 +- src/Client.ts | 54 +- src/api/errors/BadRequestError.ts | 16 + src/api/errors/NotFoundError.ts | 16 + src/api/errors/index.ts | 2 + src/api/resources/accounts/client/Client.ts | 2 +- src/api/resources/actions/client/Client.ts | 5 +- .../resources/appCategories/client/Client.ts | 2 +- src/api/resources/apps/client/Client.ts | 2 +- src/api/resources/components/client/Client.ts | 5 +- .../deployedTriggers/client/Client.ts | 2 +- src/api/resources/fileStash/client/Client.ts | 2 +- src/api/resources/index.ts | 37 +- .../resources/oauthTokens/client/Client.ts | 2 +- src/api/resources/projects/client/Client.ts | 575 +++++++++++++++++- src/api/resources/projects/client/index.ts | 2 +- .../client/requests/CreateProjectOpts.ts | 16 + .../client/requests/ProjectsListRequest.ts | 21 + .../client/requests/UpdateProjectLogoOpts.ts | 12 + .../client/requests/UpdateProjectOpts.ts | 14 + .../projects/client/requests/index.ts | 4 + src/api/resources/tokens/client/Client.ts | 2 +- src/api/resources/triggers/client/Client.ts | 5 +- src/api/resources/users/client/Client.ts | 2 +- src/api/types/ConfigurableProp.ts | 19 +- src/api/types/ConfigurablePropDataStore.ts | 5 + src/api/types/ConfigurablePropDir.ts | 5 + src/api/types/ConfigurablePropHttpRequest.ts | 7 + src/api/types/ConfigurablePropType.ts | 28 - src/api/types/HTTPAuthType.ts | 12 - src/api/types/HttpRequestAuth.ts | 14 + src/api/types/HttpRequestAuthType.ts | 9 + src/api/types/HttpRequestBody.ts | 14 + src/api/types/HttpRequestBodyMode.ts | 7 + src/api/types/HttpRequestBodyType.ts | 7 + src/api/types/HttpRequestConfig.ts | 16 + src/api/types/HttpRequestField.ts | 11 + src/api/types/ListProjectsResponse.ts | 11 + src/api/types/Project.ts | 15 + src/api/types/ProxyResponseBinary.ts | 6 + src/api/types/index.ts | 22 +- src/browser/index.ts | 324 ---------- src/core/auth/ConnectTokenProvider.ts | 66 -- src/core/auth/StaticTokenProvider.ts | 13 - src/core/auth/TokenProvider.ts | 3 - src/core/auth/index.ts | 3 - src/index.ts | 8 +- src/serialization/resources/index.ts | 2 + .../resources/projects/client/index.ts | 1 + .../client/requests/CreateProjectOpts.ts | 22 + .../client/requests/UpdateProjectLogoOpts.ts | 18 + .../client/requests/UpdateProjectOpts.ts | 22 + .../projects/client/requests/index.ts | 3 + src/serialization/resources/projects/index.ts | 1 + src/serialization/types/ConfigurableProp.ts | 21 + .../types/ConfigurablePropDataStore.ts | 15 + .../types/ConfigurablePropDir.ts | 15 + .../types/ConfigurablePropHttpRequest.ts | 22 + src/serialization/types/HttpRequestAuth.ts | 25 + .../types/HttpRequestAuthType.ts | 14 + src/serialization/types/HttpRequestBody.ts | 29 + .../types/HttpRequestBodyMode.ts | 14 + .../types/HttpRequestBodyType.ts | 14 + src/serialization/types/HttpRequestConfig.ts | 33 + src/serialization/types/HttpRequestField.ts | 20 + .../types/ListProjectsResponse.ts | 22 + src/serialization/types/Project.ts | 22 + .../types/ProxyResponseBinary.ts | 14 + src/serialization/types/index.ts | 13 + src/version.ts | 2 +- src/wrapper/Pipedream.ts | 121 ---- src/wrapper/utils/getBaseUrl.browser.ts | 9 - src/wrapper/utils/getBaseUrl.ts | 12 - src/wrapper/utils/index.ts | 1 - 74 files changed, 1268 insertions(+), 697 deletions(-) create mode 100644 src/api/errors/BadRequestError.ts create mode 100644 src/api/errors/NotFoundError.ts create mode 100644 src/api/resources/projects/client/requests/CreateProjectOpts.ts create mode 100644 src/api/resources/projects/client/requests/ProjectsListRequest.ts create mode 100644 src/api/resources/projects/client/requests/UpdateProjectLogoOpts.ts create mode 100644 src/api/resources/projects/client/requests/UpdateProjectOpts.ts create mode 100644 src/api/resources/projects/client/requests/index.ts create mode 100644 src/api/types/ConfigurablePropDataStore.ts create mode 100644 src/api/types/ConfigurablePropDir.ts create mode 100644 src/api/types/ConfigurablePropHttpRequest.ts delete mode 100644 src/api/types/ConfigurablePropType.ts delete mode 100644 src/api/types/HTTPAuthType.ts create mode 100644 src/api/types/HttpRequestAuth.ts create mode 100644 src/api/types/HttpRequestAuthType.ts create mode 100644 src/api/types/HttpRequestBody.ts create mode 100644 src/api/types/HttpRequestBodyMode.ts create mode 100644 src/api/types/HttpRequestBodyType.ts create mode 100644 src/api/types/HttpRequestConfig.ts create mode 100644 src/api/types/HttpRequestField.ts create mode 100644 src/api/types/ListProjectsResponse.ts create mode 100644 src/api/types/Project.ts create mode 100644 src/api/types/ProxyResponseBinary.ts delete mode 100644 src/browser/index.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 create mode 100644 src/serialization/resources/projects/client/index.ts create mode 100644 src/serialization/resources/projects/client/requests/CreateProjectOpts.ts create mode 100644 src/serialization/resources/projects/client/requests/UpdateProjectLogoOpts.ts create mode 100644 src/serialization/resources/projects/client/requests/UpdateProjectOpts.ts create mode 100644 src/serialization/resources/projects/client/requests/index.ts create mode 100644 src/serialization/resources/projects/index.ts create mode 100644 src/serialization/types/ConfigurablePropDataStore.ts create mode 100644 src/serialization/types/ConfigurablePropDir.ts create mode 100644 src/serialization/types/ConfigurablePropHttpRequest.ts create mode 100644 src/serialization/types/HttpRequestAuth.ts create mode 100644 src/serialization/types/HttpRequestAuthType.ts create mode 100644 src/serialization/types/HttpRequestBody.ts create mode 100644 src/serialization/types/HttpRequestBodyMode.ts create mode 100644 src/serialization/types/HttpRequestBodyType.ts create mode 100644 src/serialization/types/HttpRequestConfig.ts create mode 100644 src/serialization/types/HttpRequestField.ts create mode 100644 src/serialization/types/ListProjectsResponse.ts create mode 100644 src/serialization/types/Project.ts create mode 100644 src/serialization/types/ProxyResponseBinary.ts delete mode 100644 src/wrapper/Pipedream.ts delete mode 100644 src/wrapper/utils/getBaseUrl.browser.ts delete mode 100644 src/wrapper/utils/getBaseUrl.ts delete mode 100644 src/wrapper/utils/index.ts diff --git a/package.json b/package.json index fd1f118..9a25bfc 100644 --- a/package.json +++ b/package.json @@ -1,6 +1,6 @@ { "name": "@pipedream/sdk", - "version": "2.3.2", + "version": "2.3.3", "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": [ @@ -93,8 +64,6 @@ "@biomejs/biome": "2.2.5" }, "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 0ec2bab..f84e9f2 100644 --- a/src/Client.ts +++ b/src/Client.ts @@ -1,7 +1,5 @@ -// This file was initially auto-generated by Fern from our API Definition. -// It was later customized by the Pipedream team. +// This file was auto-generated by Fern from our API Definition. -import { SDK_VERSION } from "./version.js"; import { Accounts } from "./api/resources/accounts/client/Client.js"; import { Actions } from "./api/resources/actions/client/Client.js"; import { AppCategories } from "./api/resources/appCategories/client/Client.js"; @@ -23,7 +21,6 @@ export declare namespace PipedreamClient { export interface Options extends BaseClientOptions { clientId?: core.Supplier; clientSecret?: core.Supplier; - tokenProvider?: core.TokenProvider; } export interface RequestOptions extends BaseRequestOptions {} @@ -31,7 +28,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; @@ -40,8 +37,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; @@ -54,8 +51,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.3.3", + "User-Agent": "@pipedream/sdk/2.3.3", "X-Fern-Runtime": core.RUNTIME.type, "X-Fern-Runtime-Version": core.RUNTIME.version, }, @@ -63,10 +60,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( @@ -81,8 +74,9 @@ export class PipedreamClient { ); } - return new core.OAuthTokenProvider({ + this._oauthTokenProvider = new core.OAuthTokenProvider({ clientId, + clientSecret, authClient: new OauthTokens({ ...this._options, @@ -94,91 +88,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/errors/BadRequestError.ts b/src/api/errors/BadRequestError.ts new file mode 100644 index 0000000..d7a5556 --- /dev/null +++ b/src/api/errors/BadRequestError.ts @@ -0,0 +1,16 @@ +// This file was auto-generated by Fern from our API Definition. + +import type * as core from "../../core/index.js"; +import * as errors from "../../errors/index.js"; + +export class BadRequestError extends errors.PipedreamError { + constructor(body?: unknown, rawResponse?: core.RawResponse) { + super({ + message: "BadRequestError", + statusCode: 400, + body: body, + rawResponse: rawResponse, + }); + Object.setPrototypeOf(this, BadRequestError.prototype); + } +} diff --git a/src/api/errors/NotFoundError.ts b/src/api/errors/NotFoundError.ts new file mode 100644 index 0000000..c83739d --- /dev/null +++ b/src/api/errors/NotFoundError.ts @@ -0,0 +1,16 @@ +// This file was auto-generated by Fern from our API Definition. + +import type * as core from "../../core/index.js"; +import * as errors from "../../errors/index.js"; + +export class NotFoundError extends errors.PipedreamError { + constructor(body?: unknown, rawResponse?: core.RawResponse) { + super({ + message: "NotFoundError", + statusCode: 404, + body: body, + rawResponse: rawResponse, + }); + Object.setPrototypeOf(this, NotFoundError.prototype); + } +} diff --git a/src/api/errors/index.ts b/src/api/errors/index.ts index 06b0452..e6e1fe8 100644 --- a/src/api/errors/index.ts +++ b/src/api/errors/index.ts @@ -1 +1,3 @@ +export * from "./BadRequestError.js"; +export * from "./NotFoundError.js"; export * from "./TooManyRequestsError.js"; diff --git a/src/api/resources/accounts/client/Client.ts b/src/api/resources/accounts/client/Client.ts index 5020985..7958a1a 100644 --- a/src/api/resources/accounts/client/Client.ts +++ b/src/api/resources/accounts/client/Client.ts @@ -10,7 +10,7 @@ import * as Pipedream from "../../../index.js"; export declare namespace Accounts { export interface Options extends BaseClientOptions { - token?: core.Supplier; + token?: core.Supplier; } export interface RequestOptions extends BaseRequestOptions {} diff --git a/src/api/resources/actions/client/Client.ts b/src/api/resources/actions/client/Client.ts index bd6bbe8..44cc41a 100644 --- a/src/api/resources/actions/client/Client.ts +++ b/src/api/resources/actions/client/Client.ts @@ -10,7 +10,7 @@ import * as Pipedream from "../../../index.js"; export declare namespace Actions { export interface Options extends BaseClientOptions { - token?: core.Supplier; + token?: core.Supplier; } export interface RequestOptions extends BaseRequestOptions {} @@ -29,6 +29,7 @@ export class Actions { * @param {Pipedream.ActionsListRequest} request * @param {Actions.RequestOptions} requestOptions - Request-specific configuration. * + * @throws {@link Pipedream.BadRequestError} * @throws {@link Pipedream.TooManyRequestsError} * * @example @@ -108,6 +109,8 @@ export class Actions { } if (_response.error.reason === "status-code") { switch (_response.error.statusCode) { + case 400: + throw new Pipedream.BadRequestError(_response.error.body, _response.rawResponse); case 429: throw new Pipedream.TooManyRequestsError(_response.error.body, _response.rawResponse); default: diff --git a/src/api/resources/appCategories/client/Client.ts b/src/api/resources/appCategories/client/Client.ts index c7db14c..7102fe2 100644 --- a/src/api/resources/appCategories/client/Client.ts +++ b/src/api/resources/appCategories/client/Client.ts @@ -10,7 +10,7 @@ import type * as Pipedream from "../../../index.js"; export declare namespace AppCategories { export interface Options extends BaseClientOptions { - token?: core.Supplier; + token?: core.Supplier; } export interface RequestOptions extends BaseRequestOptions {} diff --git a/src/api/resources/apps/client/Client.ts b/src/api/resources/apps/client/Client.ts index 2598a5f..3877f49 100644 --- a/src/api/resources/apps/client/Client.ts +++ b/src/api/resources/apps/client/Client.ts @@ -10,7 +10,7 @@ import type * as Pipedream from "../../../index.js"; export declare namespace Apps { export interface Options extends BaseClientOptions { - token?: core.Supplier; + token?: core.Supplier; } export interface RequestOptions extends BaseRequestOptions {} diff --git a/src/api/resources/components/client/Client.ts b/src/api/resources/components/client/Client.ts index d29f658..cdb2a4f 100644 --- a/src/api/resources/components/client/Client.ts +++ b/src/api/resources/components/client/Client.ts @@ -10,7 +10,7 @@ import * as Pipedream from "../../../index.js"; export declare namespace Components { export interface Options extends BaseClientOptions { - token?: core.Supplier; + token?: core.Supplier; } export interface RequestOptions extends BaseRequestOptions {} @@ -29,6 +29,7 @@ export class Components { * @param {Pipedream.ComponentsListRequest} request * @param {Components.RequestOptions} requestOptions - Request-specific configuration. * + * @throws {@link Pipedream.BadRequestError} * @throws {@link Pipedream.TooManyRequestsError} * * @example @@ -115,6 +116,8 @@ export class Components { } if (_response.error.reason === "status-code") { switch (_response.error.statusCode) { + case 400: + throw new Pipedream.BadRequestError(_response.error.body, _response.rawResponse); case 429: throw new Pipedream.TooManyRequestsError(_response.error.body, _response.rawResponse); default: diff --git a/src/api/resources/deployedTriggers/client/Client.ts b/src/api/resources/deployedTriggers/client/Client.ts index dd2e0be..3590e65 100644 --- a/src/api/resources/deployedTriggers/client/Client.ts +++ b/src/api/resources/deployedTriggers/client/Client.ts @@ -10,7 +10,7 @@ import * as Pipedream from "../../../index.js"; export declare namespace DeployedTriggers { export interface Options extends BaseClientOptions { - token?: core.Supplier; + token?: core.Supplier; } export interface RequestOptions extends BaseRequestOptions {} diff --git a/src/api/resources/fileStash/client/Client.ts b/src/api/resources/fileStash/client/Client.ts index 6031153..5cf95d4 100644 --- a/src/api/resources/fileStash/client/Client.ts +++ b/src/api/resources/fileStash/client/Client.ts @@ -9,7 +9,7 @@ import * as Pipedream from "../../../index.js"; export declare namespace FileStash { export interface Options extends BaseClientOptions { - token?: core.Supplier; + token?: core.Supplier; } export interface RequestOptions extends BaseRequestOptions {} diff --git a/src/api/resources/index.ts b/src/api/resources/index.ts index 4c55785..cfdfa3f 100644 --- a/src/api/resources/index.ts +++ b/src/api/resources/index.ts @@ -1,29 +1,28 @@ +export * from "./accounts/client/requests/index.js"; +export * as accounts from "./accounts/index.js"; +export * from "./actions/client/requests/index.js"; +export * as actions from "./actions/index.js"; +export * from "./actions/types/index.js"; +export * as appCategories from "./appCategories/index.js"; +export * from "./apps/client/requests/index.js"; export * as apps from "./apps/index.js"; export * from "./apps/types/index.js"; -export * as appCategories from "./appCategories/index.js"; -export * as accounts from "./accounts/index.js"; -export * as users from "./users/index.js"; +export * from "./components/client/requests/index.js"; export * as components from "./components/index.js"; export * from "./components/types/index.js"; -export * as actions from "./actions/index.js"; -export * from "./actions/types/index.js"; -export * as triggers from "./triggers/index.js"; -export * from "./triggers/types/index.js"; +export * from "./deployedTriggers/client/requests/index.js"; export * as deployedTriggers from "./deployedTriggers/index.js"; +export * from "./fileStash/client/requests/index.js"; export * as fileStash from "./fileStash/index.js"; +export * from "./oauthTokens/client/requests/index.js"; +export * as oauthTokens from "./oauthTokens/index.js"; +export * from "./projects/client/requests/index.js"; export * as projects from "./projects/index.js"; +export * from "./proxy/client/requests/index.js"; export * as proxy from "./proxy/index.js"; +export * from "./tokens/client/requests/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"; -export * from "./actions/client/requests/index.js"; export * from "./triggers/client/requests/index.js"; -export * from "./deployedTriggers/client/requests/index.js"; -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"; +export * as triggers from "./triggers/index.js"; +export * from "./triggers/types/index.js"; +export * as users from "./users/index.js"; diff --git a/src/api/resources/oauthTokens/client/Client.ts b/src/api/resources/oauthTokens/client/Client.ts index 34bfef5..3775bc0 100644 --- a/src/api/resources/oauthTokens/client/Client.ts +++ b/src/api/resources/oauthTokens/client/Client.ts @@ -10,7 +10,7 @@ import type * as Pipedream from "../../../index.js"; export declare namespace OauthTokens { export interface Options extends BaseClientOptions { - token?: core.Supplier; + token?: core.Supplier; } export interface RequestOptions extends BaseRequestOptions {} diff --git a/src/api/resources/projects/client/Client.ts b/src/api/resources/projects/client/Client.ts index 0e68abc..ade501e 100644 --- a/src/api/resources/projects/client/Client.ts +++ b/src/api/resources/projects/client/Client.ts @@ -10,7 +10,7 @@ import * as Pipedream from "../../../index.js"; export declare namespace Projects { export interface Options extends BaseClientOptions { - token?: core.Supplier; + token?: core.Supplier; } export interface RequestOptions extends BaseRequestOptions {} @@ -23,6 +23,579 @@ export class Projects { this._options = _options; } + /** + * List the projects that are available to the authenticated Connect client + * + * @param {Pipedream.ProjectsListRequest} request + * @param {Projects.RequestOptions} requestOptions - Request-specific configuration. + * + * @throws {@link Pipedream.NotFoundError} + * @throws {@link Pipedream.TooManyRequestsError} + * + * @example + * await client.projects.list({ + * after: "after", + * before: "before", + * limit: 1, + * q: "q" + * }) + */ + public async list( + request: Pipedream.ProjectsListRequest = {}, + requestOptions?: Projects.RequestOptions, + ): Promise> { + const list = core.HttpResponsePromise.interceptFunction( + async ( + request: Pipedream.ProjectsListRequest, + ): Promise> => { + const { after, before, limit, q } = request; + const _queryParams: Record = {}; + if (after != null) { + _queryParams.after = after; + } + if (before != null) { + _queryParams.before = before; + } + if (limit != null) { + _queryParams.limit = limit.toString(); + } + if (q != null) { + _queryParams.q = q; + } + const _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)) ?? + (await core.Supplier.get(this._options.environment)) ?? + environments.PipedreamEnvironment.Prod, + "v1/connect/projects", + ), + method: "GET", + headers: _headers, + queryParameters: { ..._queryParams, ...requestOptions?.queryParams }, + timeoutMs: (requestOptions?.timeoutInSeconds ?? this._options?.timeoutInSeconds ?? 60) * 1000, + maxRetries: requestOptions?.maxRetries ?? this._options?.maxRetries, + abortSignal: requestOptions?.abortSignal, + }); + if (_response.ok) { + return { + data: serializers.ListProjectsResponse.parseOrThrow(_response.body, { + unrecognizedObjectKeys: "passthrough", + allowUnrecognizedUnionMembers: true, + allowUnrecognizedEnumValues: true, + skipValidation: true, + breadcrumbsPrefix: ["response"], + }), + rawResponse: _response.rawResponse, + }; + } + if (_response.error.reason === "status-code") { + switch (_response.error.statusCode) { + case 404: + throw new Pipedream.NotFoundError(_response.error.body, _response.rawResponse); + 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) { + case "non-json": + throw new errors.PipedreamError({ + statusCode: _response.error.statusCode, + body: _response.error.rawBody, + rawResponse: _response.rawResponse, + }); + case "timeout": + throw new errors.PipedreamTimeoutError( + "Timeout exceeded when calling GET /v1/connect/projects.", + ); + case "unknown": + throw new errors.PipedreamError({ + message: _response.error.errorMessage, + rawResponse: _response.rawResponse, + }); + } + }, + ); + const dataWithRawResponse = await list(request).withRawResponse(); + return new core.Pageable({ + response: dataWithRawResponse.data, + rawResponse: dataWithRawResponse.rawResponse, + hasNextPage: (response) => + response?.pageInfo.endCursor != null && + !(typeof response?.pageInfo.endCursor === "string" && response?.pageInfo.endCursor === ""), + getItems: (response) => response?.data ?? [], + loadPage: (response) => { + return list(core.setObjectProperty(request, "after", response?.pageInfo.endCursor)); + }, + }); + } + + /** + * Create a new project for the authenticated workspace + * + * @param {Pipedream.CreateProjectOpts} request + * @param {Projects.RequestOptions} requestOptions - Request-specific configuration. + * + * @throws {@link Pipedream.TooManyRequestsError} + * + * @example + * await client.projects.create({ + * name: "name" + * }) + */ + public create( + request: Pipedream.CreateProjectOpts, + requestOptions?: Projects.RequestOptions, + ): core.HttpResponsePromise { + return core.HttpResponsePromise.fromPromise(this.__create(request, requestOptions)); + } + + private async __create( + request: Pipedream.CreateProjectOpts, + requestOptions?: Projects.RequestOptions, + ): Promise> { + const _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)) ?? + (await core.Supplier.get(this._options.environment)) ?? + environments.PipedreamEnvironment.Prod, + "v1/connect/projects", + ), + method: "POST", + headers: _headers, + contentType: "application/json", + queryParameters: requestOptions?.queryParams, + requestType: "json", + body: serializers.CreateProjectOpts.jsonOrThrow(request, { + unrecognizedObjectKeys: "strip", + omitUndefined: true, + }), + timeoutMs: (requestOptions?.timeoutInSeconds ?? this._options?.timeoutInSeconds ?? 60) * 1000, + maxRetries: requestOptions?.maxRetries ?? this._options?.maxRetries, + abortSignal: requestOptions?.abortSignal, + }); + if (_response.ok) { + return { + data: serializers.Project.parseOrThrow(_response.body, { + unrecognizedObjectKeys: "passthrough", + allowUnrecognizedUnionMembers: true, + allowUnrecognizedEnumValues: true, + skipValidation: true, + breadcrumbsPrefix: ["response"], + }), + rawResponse: _response.rawResponse, + }; + } + + if (_response.error.reason === "status-code") { + 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) { + case "non-json": + throw new errors.PipedreamError({ + statusCode: _response.error.statusCode, + body: _response.error.rawBody, + rawResponse: _response.rawResponse, + }); + case "timeout": + throw new errors.PipedreamTimeoutError("Timeout exceeded when calling POST /v1/connect/projects."); + case "unknown": + throw new errors.PipedreamError({ + message: _response.error.errorMessage, + rawResponse: _response.rawResponse, + }); + } + } + + /** + * Get the project details for a specific project + * + * @param {string} projectId - The project ID, which starts with `proj_`. + * @param {Projects.RequestOptions} requestOptions - Request-specific configuration. + * + * @throws {@link Pipedream.TooManyRequestsError} + * + * @example + * await client.projects.retrieve("project_id") + */ + public retrieve( + projectId: string, + requestOptions?: Projects.RequestOptions, + ): core.HttpResponsePromise { + return core.HttpResponsePromise.fromPromise(this.__retrieve(projectId, requestOptions)); + } + + private async __retrieve( + projectId: string, + requestOptions?: Projects.RequestOptions, + ): Promise> { + const _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)) ?? + (await core.Supplier.get(this._options.environment)) ?? + environments.PipedreamEnvironment.Prod, + `v1/connect/projects/${core.url.encodePathParam(projectId)}`, + ), + method: "GET", + headers: _headers, + queryParameters: requestOptions?.queryParams, + timeoutMs: (requestOptions?.timeoutInSeconds ?? this._options?.timeoutInSeconds ?? 60) * 1000, + maxRetries: requestOptions?.maxRetries ?? this._options?.maxRetries, + abortSignal: requestOptions?.abortSignal, + }); + if (_response.ok) { + return { + data: serializers.Project.parseOrThrow(_response.body, { + unrecognizedObjectKeys: "passthrough", + allowUnrecognizedUnionMembers: true, + allowUnrecognizedEnumValues: true, + skipValidation: true, + breadcrumbsPrefix: ["response"], + }), + rawResponse: _response.rawResponse, + }; + } + + if (_response.error.reason === "status-code") { + 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) { + case "non-json": + throw new errors.PipedreamError({ + statusCode: _response.error.statusCode, + body: _response.error.rawBody, + rawResponse: _response.rawResponse, + }); + case "timeout": + throw new errors.PipedreamTimeoutError( + "Timeout exceeded when calling GET /v1/connect/projects/{project_id}.", + ); + case "unknown": + throw new errors.PipedreamError({ + message: _response.error.errorMessage, + rawResponse: _response.rawResponse, + }); + } + } + + /** + * Delete a project owned by the authenticated workspace + * + * @param {string} projectId - The project ID, which starts with `proj_`. + * @param {Projects.RequestOptions} requestOptions - Request-specific configuration. + * + * @throws {@link Pipedream.TooManyRequestsError} + * + * @example + * await client.projects.delete("project_id") + */ + public delete(projectId: string, requestOptions?: Projects.RequestOptions): core.HttpResponsePromise { + return core.HttpResponsePromise.fromPromise(this.__delete(projectId, requestOptions)); + } + + private async __delete( + projectId: string, + requestOptions?: Projects.RequestOptions, + ): Promise> { + const _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)) ?? + (await core.Supplier.get(this._options.environment)) ?? + environments.PipedreamEnvironment.Prod, + `v1/connect/projects/${core.url.encodePathParam(projectId)}`, + ), + method: "DELETE", + headers: _headers, + queryParameters: requestOptions?.queryParams, + timeoutMs: (requestOptions?.timeoutInSeconds ?? this._options?.timeoutInSeconds ?? 60) * 1000, + maxRetries: requestOptions?.maxRetries ?? this._options?.maxRetries, + abortSignal: requestOptions?.abortSignal, + }); + if (_response.ok) { + return { data: undefined, rawResponse: _response.rawResponse }; + } + + if (_response.error.reason === "status-code") { + 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) { + case "non-json": + throw new errors.PipedreamError({ + statusCode: _response.error.statusCode, + body: _response.error.rawBody, + rawResponse: _response.rawResponse, + }); + case "timeout": + throw new errors.PipedreamTimeoutError( + "Timeout exceeded when calling DELETE /v1/connect/projects/{project_id}.", + ); + case "unknown": + throw new errors.PipedreamError({ + message: _response.error.errorMessage, + rawResponse: _response.rawResponse, + }); + } + } + + /** + * Update project details or application information + * + * @param {string} projectId - The project ID, which starts with `proj_`. + * @param {Pipedream.UpdateProjectOpts} request + * @param {Projects.RequestOptions} requestOptions - Request-specific configuration. + * + * @throws {@link Pipedream.TooManyRequestsError} + * + * @example + * await client.projects.update("project_id") + */ + public update( + projectId: string, + request: Pipedream.UpdateProjectOpts = {}, + requestOptions?: Projects.RequestOptions, + ): core.HttpResponsePromise { + return core.HttpResponsePromise.fromPromise(this.__update(projectId, request, requestOptions)); + } + + private async __update( + projectId: string, + request: Pipedream.UpdateProjectOpts = {}, + requestOptions?: Projects.RequestOptions, + ): Promise> { + const _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)) ?? + (await core.Supplier.get(this._options.environment)) ?? + environments.PipedreamEnvironment.Prod, + `v1/connect/projects/${core.url.encodePathParam(projectId)}`, + ), + method: "PATCH", + headers: _headers, + contentType: "application/json", + queryParameters: requestOptions?.queryParams, + requestType: "json", + body: serializers.UpdateProjectOpts.jsonOrThrow(request, { + unrecognizedObjectKeys: "strip", + omitUndefined: true, + }), + timeoutMs: (requestOptions?.timeoutInSeconds ?? this._options?.timeoutInSeconds ?? 60) * 1000, + maxRetries: requestOptions?.maxRetries ?? this._options?.maxRetries, + abortSignal: requestOptions?.abortSignal, + }); + if (_response.ok) { + return { + data: serializers.Project.parseOrThrow(_response.body, { + unrecognizedObjectKeys: "passthrough", + allowUnrecognizedUnionMembers: true, + allowUnrecognizedEnumValues: true, + skipValidation: true, + breadcrumbsPrefix: ["response"], + }), + rawResponse: _response.rawResponse, + }; + } + + if (_response.error.reason === "status-code") { + 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) { + case "non-json": + throw new errors.PipedreamError({ + statusCode: _response.error.statusCode, + body: _response.error.rawBody, + rawResponse: _response.rawResponse, + }); + case "timeout": + throw new errors.PipedreamTimeoutError( + "Timeout exceeded when calling PATCH /v1/connect/projects/{project_id}.", + ); + case "unknown": + throw new errors.PipedreamError({ + message: _response.error.errorMessage, + rawResponse: _response.rawResponse, + }); + } + } + + /** + * Upload or replace the project logo + * + * @param {string} projectId - The project ID, which starts with `proj_`. + * @param {Pipedream.UpdateProjectLogoOpts} request + * @param {Projects.RequestOptions} requestOptions - Request-specific configuration. + * + * @throws {@link Pipedream.BadRequestError} + * @throws {@link Pipedream.TooManyRequestsError} + * + * @example + * await client.projects.updateLogo("project_id", { + * logo: "data:image/png;base64,AAAAAA..." + * }) + */ + public updateLogo( + projectId: string, + request: Pipedream.UpdateProjectLogoOpts, + requestOptions?: Projects.RequestOptions, + ): core.HttpResponsePromise { + return core.HttpResponsePromise.fromPromise(this.__updateLogo(projectId, request, requestOptions)); + } + + private async __updateLogo( + projectId: string, + request: Pipedream.UpdateProjectLogoOpts, + requestOptions?: Projects.RequestOptions, + ): Promise> { + const _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)) ?? + (await core.Supplier.get(this._options.environment)) ?? + environments.PipedreamEnvironment.Prod, + `v1/connect/projects/${core.url.encodePathParam(projectId)}/logo`, + ), + method: "POST", + headers: _headers, + contentType: "application/json", + queryParameters: requestOptions?.queryParams, + requestType: "json", + body: serializers.UpdateProjectLogoOpts.jsonOrThrow(request, { + unrecognizedObjectKeys: "strip", + omitUndefined: true, + }), + timeoutMs: (requestOptions?.timeoutInSeconds ?? this._options?.timeoutInSeconds ?? 60) * 1000, + maxRetries: requestOptions?.maxRetries ?? this._options?.maxRetries, + abortSignal: requestOptions?.abortSignal, + }); + if (_response.ok) { + return { data: undefined, rawResponse: _response.rawResponse }; + } + + if (_response.error.reason === "status-code") { + switch (_response.error.statusCode) { + case 400: + throw new Pipedream.BadRequestError(_response.error.body, _response.rawResponse); + 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) { + case "non-json": + throw new errors.PipedreamError({ + statusCode: _response.error.statusCode, + body: _response.error.rawBody, + rawResponse: _response.rawResponse, + }); + case "timeout": + throw new errors.PipedreamTimeoutError( + "Timeout exceeded when calling POST /v1/connect/projects/{project_id}/logo.", + ); + case "unknown": + throw new errors.PipedreamError({ + message: _response.error.errorMessage, + rawResponse: _response.rawResponse, + }); + } + } + /** * Retrieve project configuration and environment details * diff --git a/src/api/resources/projects/client/index.ts b/src/api/resources/projects/client/index.ts index cb0ff5c..195f9aa 100644 --- a/src/api/resources/projects/client/index.ts +++ b/src/api/resources/projects/client/index.ts @@ -1 +1 @@ -export {}; +export * from "./requests/index.js"; diff --git a/src/api/resources/projects/client/requests/CreateProjectOpts.ts b/src/api/resources/projects/client/requests/CreateProjectOpts.ts new file mode 100644 index 0000000..7499c3b --- /dev/null +++ b/src/api/resources/projects/client/requests/CreateProjectOpts.ts @@ -0,0 +1,16 @@ +// This file was auto-generated by Fern from our API Definition. + +/** + * @example + * { + * name: "name" + * } + */ +export interface CreateProjectOpts { + /** Name of the project */ + name: string; + /** Display name for the Connect application */ + appName?: string; + /** Support email displayed to end users */ + supportEmail?: string; +} diff --git a/src/api/resources/projects/client/requests/ProjectsListRequest.ts b/src/api/resources/projects/client/requests/ProjectsListRequest.ts new file mode 100644 index 0000000..a61bc3f --- /dev/null +++ b/src/api/resources/projects/client/requests/ProjectsListRequest.ts @@ -0,0 +1,21 @@ +// This file was auto-generated by Fern from our API Definition. + +/** + * @example + * { + * after: "after", + * before: "before", + * limit: 1, + * q: "q" + * } + */ +export interface ProjectsListRequest { + /** The cursor to start from for pagination */ + after?: string; + /** The cursor to end before for pagination */ + before?: string; + /** The maximum number of results to return */ + limit?: number; + /** A search query to filter the projects */ + q?: string; +} diff --git a/src/api/resources/projects/client/requests/UpdateProjectLogoOpts.ts b/src/api/resources/projects/client/requests/UpdateProjectLogoOpts.ts new file mode 100644 index 0000000..afab4e0 --- /dev/null +++ b/src/api/resources/projects/client/requests/UpdateProjectLogoOpts.ts @@ -0,0 +1,12 @@ +// This file was auto-generated by Fern from our API Definition. + +/** + * @example + * { + * logo: "data:image/png;base64,AAAAAA..." + * } + */ +export interface UpdateProjectLogoOpts { + /** Data URI containing the new Base64 encoded image */ + logo: string; +} diff --git a/src/api/resources/projects/client/requests/UpdateProjectOpts.ts b/src/api/resources/projects/client/requests/UpdateProjectOpts.ts new file mode 100644 index 0000000..5a5ba1e --- /dev/null +++ b/src/api/resources/projects/client/requests/UpdateProjectOpts.ts @@ -0,0 +1,14 @@ +// This file was auto-generated by Fern from our API Definition. + +/** + * @example + * {} + */ +export interface UpdateProjectOpts { + /** Name of the project */ + name?: string; + /** Display name for the Connect application */ + appName?: string; + /** Support email displayed to end users */ + supportEmail?: string; +} diff --git a/src/api/resources/projects/client/requests/index.ts b/src/api/resources/projects/client/requests/index.ts new file mode 100644 index 0000000..523a354 --- /dev/null +++ b/src/api/resources/projects/client/requests/index.ts @@ -0,0 +1,4 @@ +export type { CreateProjectOpts } from "./CreateProjectOpts.js"; +export type { ProjectsListRequest } from "./ProjectsListRequest.js"; +export type { UpdateProjectLogoOpts } from "./UpdateProjectLogoOpts.js"; +export type { UpdateProjectOpts } from "./UpdateProjectOpts.js"; diff --git a/src/api/resources/tokens/client/Client.ts b/src/api/resources/tokens/client/Client.ts index 1515718..c6cf133 100644 --- a/src/api/resources/tokens/client/Client.ts +++ b/src/api/resources/tokens/client/Client.ts @@ -10,7 +10,7 @@ import * as Pipedream from "../../../index.js"; export declare namespace Tokens { export interface Options extends BaseClientOptions { - token?: core.Supplier; + token?: core.Supplier; } export interface RequestOptions extends BaseRequestOptions {} diff --git a/src/api/resources/triggers/client/Client.ts b/src/api/resources/triggers/client/Client.ts index eccecd9..2826439 100644 --- a/src/api/resources/triggers/client/Client.ts +++ b/src/api/resources/triggers/client/Client.ts @@ -10,7 +10,7 @@ import * as Pipedream from "../../../index.js"; export declare namespace Triggers { export interface Options extends BaseClientOptions { - token?: core.Supplier; + token?: core.Supplier; } export interface RequestOptions extends BaseRequestOptions {} @@ -29,6 +29,7 @@ export class Triggers { * @param {Pipedream.TriggersListRequest} request * @param {Triggers.RequestOptions} requestOptions - Request-specific configuration. * + * @throws {@link Pipedream.BadRequestError} * @throws {@link Pipedream.TooManyRequestsError} * * @example @@ -108,6 +109,8 @@ export class Triggers { } if (_response.error.reason === "status-code") { switch (_response.error.statusCode) { + case 400: + throw new Pipedream.BadRequestError(_response.error.body, _response.rawResponse); case 429: throw new Pipedream.TooManyRequestsError(_response.error.body, _response.rawResponse); default: diff --git a/src/api/resources/users/client/Client.ts b/src/api/resources/users/client/Client.ts index c4a16e0..3b1e5f4 100644 --- a/src/api/resources/users/client/Client.ts +++ b/src/api/resources/users/client/Client.ts @@ -9,7 +9,7 @@ import * as Pipedream from "../../../index.js"; export declare namespace Users { export interface Options extends BaseClientOptions { - token?: core.Supplier; + token?: core.Supplier; } export interface RequestOptions extends BaseRequestOptions {} diff --git a/src/api/types/ConfigurableProp.ts b/src/api/types/ConfigurableProp.ts index 9ace9cf..759d749 100644 --- a/src/api/types/ConfigurableProp.ts +++ b/src/api/types/ConfigurableProp.ts @@ -10,10 +10,13 @@ export type ConfigurableProp = | Pipedream.ConfigurableProp.Any | Pipedream.ConfigurableProp.App | Pipedream.ConfigurableProp.Boolean + | Pipedream.ConfigurableProp.DataStore + | Pipedream.ConfigurableProp.Dir | Pipedream.ConfigurableProp.InterfaceTimer | Pipedream.ConfigurableProp.InterfaceApphook | Pipedream.ConfigurableProp.IntegerArray | Pipedream.ConfigurableProp.InterfaceHttp + | Pipedream.ConfigurableProp.HttpRequest | Pipedream.ConfigurableProp.ServiceDb | Pipedream.ConfigurableProp.Sql | Pipedream.ConfigurableProp.AirtableBaseId @@ -23,7 +26,7 @@ export type ConfigurableProp = | Pipedream.ConfigurableProp.DiscordChannel | Pipedream.ConfigurableProp.DiscordChannelArray | Pipedream.ConfigurableProp.Integer - | Pipedream.ConfigurableProp.Object + | Pipedream.ConfigurableProp.Object_ | Pipedream.ConfigurableProp.String | Pipedream.ConfigurableProp.StringArray; @@ -44,6 +47,14 @@ export namespace ConfigurableProp { type: "boolean"; } + export interface DataStore extends Pipedream.ConfigurablePropDataStore { + type: "data_store"; + } + + export interface Dir extends Pipedream.ConfigurablePropDir { + type: "dir"; + } + export interface InterfaceTimer extends Pipedream.ConfigurablePropTimer { type: "$.interface.timer"; } @@ -60,6 +71,10 @@ export namespace ConfigurableProp { type: "$.interface.http"; } + export interface HttpRequest extends Pipedream.ConfigurablePropHttpRequest { + type: "http_request"; + } + export interface ServiceDb extends Pipedream.ConfigurablePropDb { type: "$.service.db"; } @@ -96,7 +111,7 @@ export namespace ConfigurableProp { type: "integer"; } - export interface Object extends Pipedream.ConfigurablePropObject { + export interface Object_ extends Pipedream.ConfigurablePropObject { type: "object"; } diff --git a/src/api/types/ConfigurablePropDataStore.ts b/src/api/types/ConfigurablePropDataStore.ts new file mode 100644 index 0000000..1e42ac9 --- /dev/null +++ b/src/api/types/ConfigurablePropDataStore.ts @@ -0,0 +1,5 @@ +// This file was auto-generated by Fern from our API Definition. + +import type * as Pipedream from "../index.js"; + +export interface ConfigurablePropDataStore extends Pipedream.ConfigurablePropBase {} diff --git a/src/api/types/ConfigurablePropDir.ts b/src/api/types/ConfigurablePropDir.ts new file mode 100644 index 0000000..3a70520 --- /dev/null +++ b/src/api/types/ConfigurablePropDir.ts @@ -0,0 +1,5 @@ +// This file was auto-generated by Fern from our API Definition. + +import type * as Pipedream from "../index.js"; + +export interface ConfigurablePropDir extends Pipedream.ConfigurablePropBase {} diff --git a/src/api/types/ConfigurablePropHttpRequest.ts b/src/api/types/ConfigurablePropHttpRequest.ts new file mode 100644 index 0000000..8622e48 --- /dev/null +++ b/src/api/types/ConfigurablePropHttpRequest.ts @@ -0,0 +1,7 @@ +// This file was auto-generated by Fern from our API Definition. + +import type * as Pipedream from "../index.js"; + +export interface ConfigurablePropHttpRequest extends Pipedream.ConfigurablePropBase { + default?: Pipedream.HttpRequestConfig; +} diff --git a/src/api/types/ConfigurablePropType.ts b/src/api/types/ConfigurablePropType.ts deleted file mode 100644 index 0153c34..0000000 --- a/src/api/types/ConfigurablePropType.ts +++ /dev/null @@ -1,28 +0,0 @@ -// This file was auto-generated by Fern from our API Definition. - -export const ConfigurablePropType = { - AirtableBaseId: "$.airtable.baseId", - AirtableFieldId: "$.airtable.fieldId", - AirtableTableId: "$.airtable.tableId", - AirtableViewId: "$.airtable.viewId", - DiscordChannel: "$.discord.channel", - DiscordChannelArray: "$.discord.channel[]", - InterfaceApphook: "$.interface.apphook", - InterfaceHttp: "$.interface.http", - InterfaceTimer: "$.interface.timer", - ServiceDb: "$.service.db", - Alert: "alert", - Any: "any", - App: "app", - Boolean: "boolean", - DataStore: "data_store", - Dir: "dir", - HttpRequest: "http_request", - Integer: "integer", - IntegerArray: "integer[]", - Object: "object", - Sql: "sql", - String: "string", - StringArray: "string[]", -} as const; -export type ConfigurablePropType = (typeof ConfigurablePropType)[keyof typeof ConfigurablePropType]; 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/HttpRequestAuth.ts b/src/api/types/HttpRequestAuth.ts new file mode 100644 index 0000000..eeb8558 --- /dev/null +++ b/src/api/types/HttpRequestAuth.ts @@ -0,0 +1,14 @@ +// This file was auto-generated by Fern from our API Definition. + +import type * as Pipedream from "../index.js"; + +/** + * Authentication configuration for HTTP request + */ +export interface HttpRequestAuth { + /** The authentication type */ + type?: Pipedream.HttpRequestAuthType; + username?: string; + password?: string; + token?: string; +} diff --git a/src/api/types/HttpRequestAuthType.ts b/src/api/types/HttpRequestAuthType.ts new file mode 100644 index 0000000..923fb6c --- /dev/null +++ b/src/api/types/HttpRequestAuthType.ts @@ -0,0 +1,9 @@ +// This file was auto-generated by Fern from our API Definition. + +/** The authentication type */ +export const HttpRequestAuthType = { + Basic: "basic", + Bearer: "bearer", + None: "none", +} as const; +export type HttpRequestAuthType = (typeof HttpRequestAuthType)[keyof typeof HttpRequestAuthType]; diff --git a/src/api/types/HttpRequestBody.ts b/src/api/types/HttpRequestBody.ts new file mode 100644 index 0000000..1b8726d --- /dev/null +++ b/src/api/types/HttpRequestBody.ts @@ -0,0 +1,14 @@ +// This file was auto-generated by Fern from our API Definition. + +import type * as Pipedream from "../index.js"; + +/** + * Body configuration for HTTP request + */ +export interface HttpRequestBody { + type?: Pipedream.HttpRequestBodyType; + contentType?: string; + fields?: Pipedream.HttpRequestField[]; + mode?: Pipedream.HttpRequestBodyMode; + raw?: string; +} diff --git a/src/api/types/HttpRequestBodyMode.ts b/src/api/types/HttpRequestBodyMode.ts new file mode 100644 index 0000000..062c738 --- /dev/null +++ b/src/api/types/HttpRequestBodyMode.ts @@ -0,0 +1,7 @@ +// This file was auto-generated by Fern from our API Definition. + +export const HttpRequestBodyMode = { + Fields: "fields", + Raw: "raw", +} as const; +export type HttpRequestBodyMode = (typeof HttpRequestBodyMode)[keyof typeof HttpRequestBodyMode]; diff --git a/src/api/types/HttpRequestBodyType.ts b/src/api/types/HttpRequestBodyType.ts new file mode 100644 index 0000000..2f97528 --- /dev/null +++ b/src/api/types/HttpRequestBodyType.ts @@ -0,0 +1,7 @@ +// This file was auto-generated by Fern from our API Definition. + +export const HttpRequestBodyType = { + Fields: "fields", + Raw: "raw", +} as const; +export type HttpRequestBodyType = (typeof HttpRequestBodyType)[keyof typeof HttpRequestBodyType]; diff --git a/src/api/types/HttpRequestConfig.ts b/src/api/types/HttpRequestConfig.ts new file mode 100644 index 0000000..775ac67 --- /dev/null +++ b/src/api/types/HttpRequestConfig.ts @@ -0,0 +1,16 @@ +// This file was auto-generated by Fern from our API Definition. + +import type * as Pipedream from "../index.js"; + +/** + * Configuration for an HTTP request prop + */ +export interface HttpRequestConfig { + auth?: Pipedream.HttpRequestAuth; + body?: Pipedream.HttpRequestBody; + headers?: Pipedream.HttpRequestField[]; + params?: Pipedream.HttpRequestField[]; + tab?: string; + method?: string; + url?: string; +} diff --git a/src/api/types/HttpRequestField.ts b/src/api/types/HttpRequestField.ts new file mode 100644 index 0000000..e794273 --- /dev/null +++ b/src/api/types/HttpRequestField.ts @@ -0,0 +1,11 @@ +// This file was auto-generated by Fern from our API Definition. + +/** + * A name-value field for HTTP request configuration + */ +export interface HttpRequestField { + /** The field name */ + name: string; + /** The field value */ + value: string; +} diff --git a/src/api/types/ListProjectsResponse.ts b/src/api/types/ListProjectsResponse.ts new file mode 100644 index 0000000..aa422dd --- /dev/null +++ b/src/api/types/ListProjectsResponse.ts @@ -0,0 +1,11 @@ +// This file was auto-generated by Fern from our API Definition. + +import type * as Pipedream from "../index.js"; + +/** + * Response received when listing Connect projects + */ +export interface ListProjectsResponse { + data: Pipedream.Project[]; + pageInfo: Pipedream.PageInfo; +} diff --git a/src/api/types/Project.ts b/src/api/types/Project.ts new file mode 100644 index 0000000..5fc26df --- /dev/null +++ b/src/api/types/Project.ts @@ -0,0 +1,15 @@ +// This file was auto-generated by Fern from our API Definition. + +/** + * Project that can be accessed via the Connect API + */ +export interface Project { + /** Hash ID for the project */ + id: string; + /** Display name of the project */ + name: string; + /** App name shown to Connect users */ + appName?: string; + /** Support email configured for the project */ + supportEmail?: string; +} diff --git a/src/api/types/ProxyResponseBinary.ts b/src/api/types/ProxyResponseBinary.ts new file mode 100644 index 0000000..e9d59fa --- /dev/null +++ b/src/api/types/ProxyResponseBinary.ts @@ -0,0 +1,6 @@ +// This file was auto-generated by Fern from our API Definition. + +/** + * Binary response from the proxied API + */ +export type ProxyResponseBinary = string; diff --git a/src/api/types/index.ts b/src/api/types/index.ts index 985eaf3..b000db2 100644 --- a/src/api/types/index.ts +++ b/src/api/types/index.ts @@ -9,7 +9,6 @@ export * from "./Component.js"; export * from "./ComponentStash.js"; export * from "./ComponentType.js"; export * from "./ConfigurableProp.js"; -export * from "./ConfigurablePropBase.js"; export * from "./ConfigurablePropAirtableBaseId.js"; export * from "./ConfigurablePropAirtableFieldId.js"; export * from "./ConfigurablePropAirtableTableId.js"; @@ -20,26 +19,30 @@ export * from "./ConfigurablePropAny.js"; export * from "./ConfigurablePropAnyOptionsItem.js"; export * from "./ConfigurablePropApp.js"; export * from "./ConfigurablePropApphook.js"; +export * from "./ConfigurablePropBase.js"; export * from "./ConfigurablePropBoolean.js"; export * from "./ConfigurablePropBooleanOptionsItem.js"; +export * from "./ConfigurablePropDataStore.js"; export * from "./ConfigurablePropDb.js"; +export * from "./ConfigurablePropDir.js"; export * from "./ConfigurablePropDiscord.js"; export * from "./ConfigurablePropDiscordChannel.js"; export * from "./ConfigurablePropDiscordChannelArray.js"; export * from "./ConfigurablePropHttp.js"; +export * from "./ConfigurablePropHttpRequest.js"; export * from "./ConfigurablePropInteger.js"; -export * from "./ConfigurablePropIntegerOptionsItem.js"; export * from "./ConfigurablePropIntegerArray.js"; export * from "./ConfigurablePropIntegerArrayOptionsItem.js"; +export * from "./ConfigurablePropIntegerOptionsItem.js"; export * from "./ConfigurablePropObject.js"; export * from "./ConfigurablePropObjectOptionsItem.js"; export * from "./ConfigurablePropSql.js"; export * from "./ConfigurablePropSqlAuth.js"; export * from "./ConfigurablePropSqlOptionsItem.js"; export * from "./ConfigurablePropString.js"; -export * from "./ConfigurablePropStringOptionsItem.js"; export * from "./ConfigurablePropStringArray.js"; export * from "./ConfigurablePropStringArrayOptionsItem.js"; +export * from "./ConfigurablePropStringOptionsItem.js"; export * from "./ConfigurablePropTimer.js"; export * from "./ConfigurablePropTimerDefault.js"; export * from "./ConfigurablePropTimerOption.js"; @@ -80,21 +83,30 @@ export * from "./GetTriggerResponse.js"; export * from "./GetTriggersResponse.js"; export * from "./GetTriggerWebhooksResponse.js"; export * from "./GetTriggerWorkflowsResponse.js"; -export * from "./HTTPAuthType.js"; export * from "./HttpInterface.js"; +export * from "./HttpRequestAuth.js"; +export * from "./HttpRequestAuthType.js"; +export * from "./HttpRequestBody.js"; +export * from "./HttpRequestBodyMode.js"; +export * from "./HttpRequestBodyType.js"; +export * from "./HttpRequestConfig.js"; +export * from "./HttpRequestField.js"; export * from "./ListAccountsResponse.js"; export * from "./ListAppCategoriesResponse.js"; export * from "./ListAppsResponse.js"; +export * from "./ListProjectsResponse.js"; export * from "./Observation.js"; export * from "./ObservationError.js"; export * from "./PageInfo.js"; +export * from "./Project.js"; 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 "./ProxyResponseBinary.js"; export * from "./ReloadPropsOpts.js"; export * from "./ReloadPropsResponse.js"; export * from "./RunActionOptsStashId.js"; diff --git a/src/browser/index.ts b/src/browser/index.ts deleted file mode 100644 index 5ff230b..0000000 --- a/src/browser/index.ts +++ /dev/null @@ -1,324 +0,0 @@ -// This code is meant to be run client-side. Never provide project keys to the -// browser client, or make API requests to the Pipedream API to fetch -// credentials. The browser client is meant for initiating browser-specific -// operations, like connecting accounts via Pipedream Connect. - -// Browser-specific imports that avoid Node.js dependencies -export type * from "../api/types/index.js"; -export * from "../index.js"; - -import { ConnectTokenProvider, type TokenCallback } from "../core/auth/index.js"; -import { type Account, type App, PipedreamClient as BackendClient, PipedreamEnvironment } from "../index.js"; -import type { PipedreamClientOpts as BackendClientOpts } from "../wrapper/Pipedream.js"; - -if (typeof process === "undefined") { - // We're in the browser - globalThis.process ||= { - env: {}, - } as NodeJS.Process; -} - -/** - * Options for creating a browser-side client. This is used to configure the - * PipedreamClient instance. - */ -export type PipedreamClientOpts = Omit & { - /** - * The frontend host URL. Used by Pipedream employees only. Defaults to - * "pipedream.com" if not provided. - */ - frontendHost?: string; - - /** - * Will be called whenever we need a new token. - * - * The callback function should return the response from - * `serverClient.tokens.create`. - */ - tokenCallback: TokenCallback; - - /** - * An external user ID associated with the token. - */ - externalUserId: string; -}; - -/** - * The result of a successful connection. - */ -export type ConnectResult = { - /** - * The unique identifier of the connected account. - */ - id: Account["id"]; -}; - -/** - * The status when the Connect dialog is closed. - */ -export type ConnectStatus = { - /** - * Whether the connection was successful (account was connected). - */ - successful: boolean; - - /** - * Whether the connection process was completed (vs user closing early). - */ - completed: boolean; -}; - -/** - * Custom error class for handling connection errors. - */ -export class ConnectError extends Error {} - -/** - * Options for starting the connection process. - */ -export type StartConnectOpts = { - /** - * The token used for authenticating the connection. - * - * Optional if the client was already initialized with a token - */ - token?: string; - - /** - * The app to connect to - */ - app: App["nameSlug"]; - - /** - * The OAuth app ID to connect to. - */ - oauthAppId?: App["id"]; - - /** - * Callback function to be called upon successful connection. - * - * @param res - The result of the connection. - */ - onSuccess?: (res: ConnectResult) => void; - - /** - * Callback function to be called if an error occurs during the connection. - * - * @param err - The error that occurred during the connection. - */ - onError?: (err: ConnectError) => void; - - /** - * Callback function to be called when the Connect iFrame is closed. - * - * @param status - The status of the connection when closed. - */ - onClose?: (status: ConnectStatus) => void; -}; - -/** - * Creates a new instance of `PipedreamClient` with the provided options. - * - * @example - * ```typescript - const client = createFrontendClient({ - tokenCallback, - externalUserId, - }); - * ``` - * @param opts - The options for creating the browser client. - * @returns A new instance of `PipedreamClient`. - */ -export function createFrontendClient( - opts: PipedreamClientOpts & { - /** - * The Connect token used for authenticating the connection. Useful if you - * don't need to refresh it (e.g. if the client will be used in read-only - * requests). - */ - token?: string; - }, -): PipedreamClient { - const { - // These are some dummy values that would produce a blank Connect token, - // in case the user does not need to make any API requests other than - // connecting an external user's account. - externalUserId = "", - token = "", - tokenCallback = () => Promise.resolve({ token, expiresAt: new Date(), connectLinkUrl: "" }), - } = opts || {}; - return new PipedreamClient({ - ...opts, - externalUserId, - tokenCallback, - }); -} - -/** - * A client for interacting with the Pipedream Connect API from the browser. - */ -export class PipedreamClient extends BackendClient { - private baseURL: string; - private iframeURL: string; - private iframe?: HTMLIFrameElement; - private iframeId = 0; - - /** - * Constructs a new `PipedreamClient` instance. - * - * @param opts - The options for configuring the browser client. - */ - constructor(opts: PipedreamClientOpts) { - const { - environment = PipedreamEnvironment.Prod, - externalUserId, - projectEnvironment, - tokenCallback, - workflowDomain, - } = opts || {}; - - 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"); - } - - const tokenProvider = new ConnectTokenProvider({ - externalUserId, - tokenCallback, - }); - - super({ - environment, - projectEnvironment, - projectId: "", - tokenProvider, - workflowDomain, - }); - - this.baseURL = `https://${opts.frontendHost || "pipedream.com"}`; - this.iframeURL = `${this.baseURL}/_static/connect.html`; - } - - get externalUserId(): string | undefined { - return (this._tokenProvider as ConnectTokenProvider).externalUserId; - } - - /** - * Initiates the process of connecting an account. - * - * @param opts - The options for starting the connection process. - * - * @example - * ```typescript - * client.connectAccount({ - * token: "your-token", - * app: "your-app-id", - * onSuccess: (res) => { - * console.log("Connected account ID:", res.id); - * }, - * onError: (err) => { - * console.error("Connection error:", err); - * }, - * onClose: (status) => { - * if (!status.successful) { - * console.log("User closed without connecting"); - * } - * }, - * }); - * ``` - */ - public async connectAccount(opts: StartConnectOpts): Promise { - let connectionSuccessful = false; - let connectionCompleted = false; - - const onMessage = (e: MessageEvent) => { - switch (e.data?.type) { - case "success": - connectionSuccessful = true; - connectionCompleted = true; - opts.onSuccess?.({ - id: e.data?.authProvisionId, - }); - break; - case "error": - connectionCompleted = true; - opts.onError?.(new ConnectError(e.data.error)); - break; - case "close": - this.cleanup(onMessage); - opts.onClose?.({ - successful: connectionSuccessful, - completed: connectionCompleted, - }); - break; - default: - break; - } - }; - - window.addEventListener("message", onMessage); - - try { - await this.createIframe(opts); - } catch (err) { - opts.onError?.(err as ConnectError); - } - - // The token expires once it's used to create a connected account. We - // need to get a new token for the next requests. - (this._tokenProvider as ConnectTokenProvider).refresh(); - } - - /** - * Cleans up the iframe and message event listener after the connection - * process is complete. - * - * @param onMessage - The message event handler to remove. - */ - private cleanup(onMessage: (e: MessageEvent) => void) { - this.iframe?.remove(); - window.removeEventListener("message", onMessage); - } - - /** - * Creates an iframe for the connection process and appends it to the document - * body. - * - * @param opts - The options for starting the connection process. - * - * @throws {ConnectError} If the app option is not a string. - */ - private async createIframe(opts: StartConnectOpts) { - const token = opts.token || (await this._tokenProvider.getToken()); - const qp = new URLSearchParams({ - token, - }); - - if (typeof opts.app === "string") { - qp.set("app", opts.app); - } else { - throw new ConnectError("Object app not yet supported"); - } - - if (opts.oauthAppId) { - qp.set("oauthAppId", opts.oauthAppId); - } - - const iframe = document.createElement("iframe"); - iframe.id = `pipedream-connect-iframe-${this.iframeId++}`; - iframe.title = "Pipedream Connect"; - iframe.src = `${this.iframeURL}?${qp.toString()}`; - iframe.style.cssText = "position:fixed;inset:0;z-index:2147483647;border:0;display:block;overflow:hidden auto"; - iframe.width = "100%"; - iframe.height = "100%"; - - iframe.onload = () => { - this.iframe = iframe; - }; - - document.body.appendChild(iframe); - } -} diff --git a/src/core/auth/ConnectTokenProvider.ts b/src/core/auth/ConnectTokenProvider.ts deleted file mode 100644 index 7ec3487..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(): void { - 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 fede199..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, type TokenCallback } from "./ConnectTokenProvider.js"; export { OAuthTokenProvider } from "./OAuthTokenProvider.js"; -export { StaticTokenProvider } from "./StaticTokenProvider.js"; -export type { TokenProvider } from "./TokenProvider.js"; diff --git a/src/index.ts b/src/index.ts index 4a94d36..73733f5 100644 --- a/src/index.ts +++ b/src/index.ts @@ -1,4 +1,6 @@ -export * from "./api/index.js"; -export { PipedreamError, PipedreamTimeoutError } from "./errors/index.js"; +export * as Pipedream from "./api/index.js"; +export type { BaseClientOptions, BaseRequestOptions } from "./BaseClient.js"; +export { PipedreamClient } from "./Client.js"; export { PipedreamEnvironment } from "./environments.js"; -export { Pipedream as PipedreamClient, type PipedreamClientOpts } from "./wrapper/Pipedream.js"; +export { PipedreamError, PipedreamTimeoutError } from "./errors/index.js"; +export * as serialization from "./serialization/index.js"; diff --git a/src/serialization/resources/index.ts b/src/serialization/resources/index.ts index a9046bd..7de83b8 100644 --- a/src/serialization/resources/index.ts +++ b/src/serialization/resources/index.ts @@ -11,6 +11,8 @@ export * from "./deployedTriggers/client/requests/index.js"; export * as deployedTriggers from "./deployedTriggers/index.js"; export * from "./oauthTokens/client/requests/index.js"; export * as oauthTokens from "./oauthTokens/index.js"; +export * from "./projects/client/requests/index.js"; +export * as projects from "./projects/index.js"; export * as proxy from "./proxy/index.js"; export * from "./tokens/client/requests/index.js"; export * as tokens from "./tokens/index.js"; diff --git a/src/serialization/resources/projects/client/index.ts b/src/serialization/resources/projects/client/index.ts new file mode 100644 index 0000000..195f9aa --- /dev/null +++ b/src/serialization/resources/projects/client/index.ts @@ -0,0 +1 @@ +export * from "./requests/index.js"; diff --git a/src/serialization/resources/projects/client/requests/CreateProjectOpts.ts b/src/serialization/resources/projects/client/requests/CreateProjectOpts.ts new file mode 100644 index 0000000..82d09e8 --- /dev/null +++ b/src/serialization/resources/projects/client/requests/CreateProjectOpts.ts @@ -0,0 +1,22 @@ +// This file was auto-generated by Fern from our API Definition. + +import type * as Pipedream from "../../../../../api/index.js"; +import * as core from "../../../../../core/index.js"; +import type * as serializers from "../../../../index.js"; + +export const CreateProjectOpts: core.serialization.Schema< + serializers.CreateProjectOpts.Raw, + Pipedream.CreateProjectOpts +> = core.serialization.object({ + name: core.serialization.string(), + appName: core.serialization.property("app_name", core.serialization.string().optional()), + supportEmail: core.serialization.property("support_email", core.serialization.string().optional()), +}); + +export declare namespace CreateProjectOpts { + export interface Raw { + name: string; + app_name?: string | null; + support_email?: string | null; + } +} diff --git a/src/serialization/resources/projects/client/requests/UpdateProjectLogoOpts.ts b/src/serialization/resources/projects/client/requests/UpdateProjectLogoOpts.ts new file mode 100644 index 0000000..afdc37c --- /dev/null +++ b/src/serialization/resources/projects/client/requests/UpdateProjectLogoOpts.ts @@ -0,0 +1,18 @@ +// This file was auto-generated by Fern from our API Definition. + +import type * as Pipedream from "../../../../../api/index.js"; +import * as core from "../../../../../core/index.js"; +import type * as serializers from "../../../../index.js"; + +export const UpdateProjectLogoOpts: core.serialization.Schema< + serializers.UpdateProjectLogoOpts.Raw, + Pipedream.UpdateProjectLogoOpts +> = core.serialization.object({ + logo: core.serialization.string(), +}); + +export declare namespace UpdateProjectLogoOpts { + export interface Raw { + logo: string; + } +} diff --git a/src/serialization/resources/projects/client/requests/UpdateProjectOpts.ts b/src/serialization/resources/projects/client/requests/UpdateProjectOpts.ts new file mode 100644 index 0000000..5f3060d --- /dev/null +++ b/src/serialization/resources/projects/client/requests/UpdateProjectOpts.ts @@ -0,0 +1,22 @@ +// This file was auto-generated by Fern from our API Definition. + +import type * as Pipedream from "../../../../../api/index.js"; +import * as core from "../../../../../core/index.js"; +import type * as serializers from "../../../../index.js"; + +export const UpdateProjectOpts: core.serialization.Schema< + serializers.UpdateProjectOpts.Raw, + Pipedream.UpdateProjectOpts +> = core.serialization.object({ + name: core.serialization.string().optional(), + appName: core.serialization.property("app_name", core.serialization.string().optional()), + supportEmail: core.serialization.property("support_email", core.serialization.string().optional()), +}); + +export declare namespace UpdateProjectOpts { + export interface Raw { + name?: string | null; + app_name?: string | null; + support_email?: string | null; + } +} diff --git a/src/serialization/resources/projects/client/requests/index.ts b/src/serialization/resources/projects/client/requests/index.ts new file mode 100644 index 0000000..26cf1f9 --- /dev/null +++ b/src/serialization/resources/projects/client/requests/index.ts @@ -0,0 +1,3 @@ +export { CreateProjectOpts } from "./CreateProjectOpts.js"; +export { UpdateProjectLogoOpts } from "./UpdateProjectLogoOpts.js"; +export { UpdateProjectOpts } from "./UpdateProjectOpts.js"; diff --git a/src/serialization/resources/projects/index.ts b/src/serialization/resources/projects/index.ts new file mode 100644 index 0000000..914b8c3 --- /dev/null +++ b/src/serialization/resources/projects/index.ts @@ -0,0 +1 @@ +export * from "./client/index.js"; diff --git a/src/serialization/types/ConfigurableProp.ts b/src/serialization/types/ConfigurableProp.ts index 289256c..6ba1283 100644 --- a/src/serialization/types/ConfigurableProp.ts +++ b/src/serialization/types/ConfigurableProp.ts @@ -12,10 +12,13 @@ import { ConfigurablePropAny } from "./ConfigurablePropAny.js"; import { ConfigurablePropApp } from "./ConfigurablePropApp.js"; import { ConfigurablePropApphook } from "./ConfigurablePropApphook.js"; import { ConfigurablePropBoolean } from "./ConfigurablePropBoolean.js"; +import { ConfigurablePropDataStore } from "./ConfigurablePropDataStore.js"; import { ConfigurablePropDb } from "./ConfigurablePropDb.js"; +import { ConfigurablePropDir } from "./ConfigurablePropDir.js"; import { ConfigurablePropDiscordChannel } from "./ConfigurablePropDiscordChannel.js"; import { ConfigurablePropDiscordChannelArray } from "./ConfigurablePropDiscordChannelArray.js"; import { ConfigurablePropHttp } from "./ConfigurablePropHttp.js"; +import { ConfigurablePropHttpRequest } from "./ConfigurablePropHttpRequest.js"; import { ConfigurablePropInteger } from "./ConfigurablePropInteger.js"; import { ConfigurablePropIntegerArray } from "./ConfigurablePropIntegerArray.js"; import { ConfigurablePropObject } from "./ConfigurablePropObject.js"; @@ -31,10 +34,13 @@ export const ConfigurableProp: core.serialization.Schema = core.serialization.object({}).extend(ConfigurablePropBase); + +export declare namespace ConfigurablePropDataStore { + export interface Raw extends ConfigurablePropBase.Raw {} +} diff --git a/src/serialization/types/ConfigurablePropDir.ts b/src/serialization/types/ConfigurablePropDir.ts new file mode 100644 index 0000000..90238cb --- /dev/null +++ b/src/serialization/types/ConfigurablePropDir.ts @@ -0,0 +1,15 @@ +// This file was auto-generated by Fern from our API Definition. + +import type * as Pipedream from "../../api/index.js"; +import * as core from "../../core/index.js"; +import type * as serializers from "../index.js"; +import { ConfigurablePropBase } from "./ConfigurablePropBase.js"; + +export const ConfigurablePropDir: core.serialization.ObjectSchema< + serializers.ConfigurablePropDir.Raw, + Pipedream.ConfigurablePropDir +> = core.serialization.object({}).extend(ConfigurablePropBase); + +export declare namespace ConfigurablePropDir { + export interface Raw extends ConfigurablePropBase.Raw {} +} diff --git a/src/serialization/types/ConfigurablePropHttpRequest.ts b/src/serialization/types/ConfigurablePropHttpRequest.ts new file mode 100644 index 0000000..0ce0cec --- /dev/null +++ b/src/serialization/types/ConfigurablePropHttpRequest.ts @@ -0,0 +1,22 @@ +// This file was auto-generated by Fern from our API Definition. + +import type * as Pipedream from "../../api/index.js"; +import * as core from "../../core/index.js"; +import type * as serializers from "../index.js"; +import { ConfigurablePropBase } from "./ConfigurablePropBase.js"; +import { HttpRequestConfig } from "./HttpRequestConfig.js"; + +export const ConfigurablePropHttpRequest: core.serialization.ObjectSchema< + serializers.ConfigurablePropHttpRequest.Raw, + Pipedream.ConfigurablePropHttpRequest +> = core.serialization + .object({ + default: HttpRequestConfig.optional(), + }) + .extend(ConfigurablePropBase); + +export declare namespace ConfigurablePropHttpRequest { + export interface Raw extends ConfigurablePropBase.Raw { + default?: HttpRequestConfig.Raw | null; + } +} diff --git a/src/serialization/types/HttpRequestAuth.ts b/src/serialization/types/HttpRequestAuth.ts new file mode 100644 index 0000000..9152dc1 --- /dev/null +++ b/src/serialization/types/HttpRequestAuth.ts @@ -0,0 +1,25 @@ +// This file was auto-generated by Fern from our API Definition. + +import type * as Pipedream from "../../api/index.js"; +import * as core from "../../core/index.js"; +import type * as serializers from "../index.js"; +import { HttpRequestAuthType } from "./HttpRequestAuthType.js"; + +export const HttpRequestAuth: core.serialization.ObjectSchema< + serializers.HttpRequestAuth.Raw, + Pipedream.HttpRequestAuth +> = core.serialization.object({ + type: HttpRequestAuthType.optional(), + username: core.serialization.string().optional(), + password: core.serialization.string().optional(), + token: core.serialization.string().optional(), +}); + +export declare namespace HttpRequestAuth { + export interface Raw { + type?: HttpRequestAuthType.Raw | null; + username?: string | null; + password?: string | null; + token?: string | null; + } +} diff --git a/src/serialization/types/HttpRequestAuthType.ts b/src/serialization/types/HttpRequestAuthType.ts new file mode 100644 index 0000000..776553c --- /dev/null +++ b/src/serialization/types/HttpRequestAuthType.ts @@ -0,0 +1,14 @@ +// This file was auto-generated by Fern from our API Definition. + +import type * as Pipedream from "../../api/index.js"; +import * as core from "../../core/index.js"; +import type * as serializers from "../index.js"; + +export const HttpRequestAuthType: core.serialization.Schema< + serializers.HttpRequestAuthType.Raw, + Pipedream.HttpRequestAuthType +> = core.serialization.enum_(["basic", "bearer", "none"]); + +export declare namespace HttpRequestAuthType { + export type Raw = "basic" | "bearer" | "none"; +} diff --git a/src/serialization/types/HttpRequestBody.ts b/src/serialization/types/HttpRequestBody.ts new file mode 100644 index 0000000..a87a7f4 --- /dev/null +++ b/src/serialization/types/HttpRequestBody.ts @@ -0,0 +1,29 @@ +// This file was auto-generated by Fern from our API Definition. + +import type * as Pipedream from "../../api/index.js"; +import * as core from "../../core/index.js"; +import type * as serializers from "../index.js"; +import { HttpRequestBodyMode } from "./HttpRequestBodyMode.js"; +import { HttpRequestBodyType } from "./HttpRequestBodyType.js"; +import { HttpRequestField } from "./HttpRequestField.js"; + +export const HttpRequestBody: core.serialization.ObjectSchema< + serializers.HttpRequestBody.Raw, + Pipedream.HttpRequestBody +> = core.serialization.object({ + type: HttpRequestBodyType.optional(), + contentType: core.serialization.string().optional(), + fields: core.serialization.list(HttpRequestField).optional(), + mode: HttpRequestBodyMode.optional(), + raw: core.serialization.string().optional(), +}); + +export declare namespace HttpRequestBody { + export interface Raw { + type?: HttpRequestBodyType.Raw | null; + contentType?: string | null; + fields?: HttpRequestField.Raw[] | null; + mode?: HttpRequestBodyMode.Raw | null; + raw?: string | null; + } +} diff --git a/src/serialization/types/HttpRequestBodyMode.ts b/src/serialization/types/HttpRequestBodyMode.ts new file mode 100644 index 0000000..193d2b2 --- /dev/null +++ b/src/serialization/types/HttpRequestBodyMode.ts @@ -0,0 +1,14 @@ +// This file was auto-generated by Fern from our API Definition. + +import type * as Pipedream from "../../api/index.js"; +import * as core from "../../core/index.js"; +import type * as serializers from "../index.js"; + +export const HttpRequestBodyMode: core.serialization.Schema< + serializers.HttpRequestBodyMode.Raw, + Pipedream.HttpRequestBodyMode +> = core.serialization.enum_(["fields", "raw"]); + +export declare namespace HttpRequestBodyMode { + export type Raw = "fields" | "raw"; +} diff --git a/src/serialization/types/HttpRequestBodyType.ts b/src/serialization/types/HttpRequestBodyType.ts new file mode 100644 index 0000000..5880ba8 --- /dev/null +++ b/src/serialization/types/HttpRequestBodyType.ts @@ -0,0 +1,14 @@ +// This file was auto-generated by Fern from our API Definition. + +import type * as Pipedream from "../../api/index.js"; +import * as core from "../../core/index.js"; +import type * as serializers from "../index.js"; + +export const HttpRequestBodyType: core.serialization.Schema< + serializers.HttpRequestBodyType.Raw, + Pipedream.HttpRequestBodyType +> = core.serialization.enum_(["fields", "raw"]); + +export declare namespace HttpRequestBodyType { + export type Raw = "fields" | "raw"; +} diff --git a/src/serialization/types/HttpRequestConfig.ts b/src/serialization/types/HttpRequestConfig.ts new file mode 100644 index 0000000..3e6eefb --- /dev/null +++ b/src/serialization/types/HttpRequestConfig.ts @@ -0,0 +1,33 @@ +// This file was auto-generated by Fern from our API Definition. + +import type * as Pipedream from "../../api/index.js"; +import * as core from "../../core/index.js"; +import type * as serializers from "../index.js"; +import { HttpRequestAuth } from "./HttpRequestAuth.js"; +import { HttpRequestBody } from "./HttpRequestBody.js"; +import { HttpRequestField } from "./HttpRequestField.js"; + +export const HttpRequestConfig: core.serialization.ObjectSchema< + serializers.HttpRequestConfig.Raw, + Pipedream.HttpRequestConfig +> = core.serialization.object({ + auth: HttpRequestAuth.optional(), + body: HttpRequestBody.optional(), + headers: core.serialization.list(HttpRequestField).optional(), + params: core.serialization.list(HttpRequestField).optional(), + tab: core.serialization.string().optional(), + method: core.serialization.string().optional(), + url: core.serialization.string().optional(), +}); + +export declare namespace HttpRequestConfig { + export interface Raw { + auth?: HttpRequestAuth.Raw | null; + body?: HttpRequestBody.Raw | null; + headers?: HttpRequestField.Raw[] | null; + params?: HttpRequestField.Raw[] | null; + tab?: string | null; + method?: string | null; + url?: string | null; + } +} diff --git a/src/serialization/types/HttpRequestField.ts b/src/serialization/types/HttpRequestField.ts new file mode 100644 index 0000000..e390b56 --- /dev/null +++ b/src/serialization/types/HttpRequestField.ts @@ -0,0 +1,20 @@ +// This file was auto-generated by Fern from our API Definition. + +import type * as Pipedream from "../../api/index.js"; +import * as core from "../../core/index.js"; +import type * as serializers from "../index.js"; + +export const HttpRequestField: core.serialization.ObjectSchema< + serializers.HttpRequestField.Raw, + Pipedream.HttpRequestField +> = core.serialization.object({ + name: core.serialization.string(), + value: core.serialization.string(), +}); + +export declare namespace HttpRequestField { + export interface Raw { + name: string; + value: string; + } +} diff --git a/src/serialization/types/ListProjectsResponse.ts b/src/serialization/types/ListProjectsResponse.ts new file mode 100644 index 0000000..97af4a0 --- /dev/null +++ b/src/serialization/types/ListProjectsResponse.ts @@ -0,0 +1,22 @@ +// This file was auto-generated by Fern from our API Definition. + +import type * as Pipedream from "../../api/index.js"; +import * as core from "../../core/index.js"; +import type * as serializers from "../index.js"; +import { PageInfo } from "./PageInfo.js"; +import { Project } from "./Project.js"; + +export const ListProjectsResponse: core.serialization.ObjectSchema< + serializers.ListProjectsResponse.Raw, + Pipedream.ListProjectsResponse +> = core.serialization.object({ + data: core.serialization.list(Project), + pageInfo: core.serialization.property("page_info", PageInfo), +}); + +export declare namespace ListProjectsResponse { + export interface Raw { + data: Project.Raw[]; + page_info: PageInfo.Raw; + } +} diff --git a/src/serialization/types/Project.ts b/src/serialization/types/Project.ts new file mode 100644 index 0000000..f8c83fe --- /dev/null +++ b/src/serialization/types/Project.ts @@ -0,0 +1,22 @@ +// This file was auto-generated by Fern from our API Definition. + +import type * as Pipedream from "../../api/index.js"; +import * as core from "../../core/index.js"; +import type * as serializers from "../index.js"; + +export const Project: core.serialization.ObjectSchema = + core.serialization.object({ + id: core.serialization.string(), + name: core.serialization.string(), + appName: core.serialization.property("app_name", core.serialization.string().optional()), + supportEmail: core.serialization.property("support_email", core.serialization.string().optional()), + }); + +export declare namespace Project { + export interface Raw { + id: string; + name: string; + app_name?: string | null; + support_email?: string | null; + } +} diff --git a/src/serialization/types/ProxyResponseBinary.ts b/src/serialization/types/ProxyResponseBinary.ts new file mode 100644 index 0000000..8a05a96 --- /dev/null +++ b/src/serialization/types/ProxyResponseBinary.ts @@ -0,0 +1,14 @@ +// This file was auto-generated by Fern from our API Definition. + +import type * as Pipedream from "../../api/index.js"; +import * as core from "../../core/index.js"; +import type * as serializers from "../index.js"; + +export const ProxyResponseBinary: core.serialization.Schema< + serializers.ProxyResponseBinary.Raw, + Pipedream.ProxyResponseBinary +> = core.serialization.string(); + +export declare namespace ProxyResponseBinary { + export type Raw = string; +} diff --git a/src/serialization/types/index.ts b/src/serialization/types/index.ts index 4ebd911..b000db2 100644 --- a/src/serialization/types/index.ts +++ b/src/serialization/types/index.ts @@ -22,11 +22,14 @@ export * from "./ConfigurablePropApphook.js"; export * from "./ConfigurablePropBase.js"; export * from "./ConfigurablePropBoolean.js"; export * from "./ConfigurablePropBooleanOptionsItem.js"; +export * from "./ConfigurablePropDataStore.js"; export * from "./ConfigurablePropDb.js"; +export * from "./ConfigurablePropDir.js"; export * from "./ConfigurablePropDiscord.js"; export * from "./ConfigurablePropDiscordChannel.js"; export * from "./ConfigurablePropDiscordChannelArray.js"; export * from "./ConfigurablePropHttp.js"; +export * from "./ConfigurablePropHttpRequest.js"; export * from "./ConfigurablePropInteger.js"; export * from "./ConfigurablePropIntegerArray.js"; export * from "./ConfigurablePropIntegerArrayOptionsItem.js"; @@ -81,12 +84,21 @@ export * from "./GetTriggersResponse.js"; export * from "./GetTriggerWebhooksResponse.js"; export * from "./GetTriggerWorkflowsResponse.js"; export * from "./HttpInterface.js"; +export * from "./HttpRequestAuth.js"; +export * from "./HttpRequestAuthType.js"; +export * from "./HttpRequestBody.js"; +export * from "./HttpRequestBodyMode.js"; +export * from "./HttpRequestBodyType.js"; +export * from "./HttpRequestConfig.js"; +export * from "./HttpRequestField.js"; export * from "./ListAccountsResponse.js"; export * from "./ListAppCategoriesResponse.js"; export * from "./ListAppsResponse.js"; +export * from "./ListProjectsResponse.js"; export * from "./Observation.js"; export * from "./ObservationError.js"; export * from "./PageInfo.js"; +export * from "./Project.js"; export * from "./ProjectEnvironment.js"; export * from "./ProjectInfoResponse.js"; export * from "./ProjectInfoResponseApp.js"; @@ -94,6 +106,7 @@ export * from "./PropOption.js"; export * from "./PropOptionNested.js"; export * from "./PropOptionValue.js"; export * from "./ProxyResponse.js"; +export * from "./ProxyResponseBinary.js"; export * from "./ReloadPropsOpts.js"; export * from "./ReloadPropsResponse.js"; export * from "./RunActionOptsStashId.js"; diff --git a/src/version.ts b/src/version.ts index 7812a79..3003e8d 100644 --- a/src/version.ts +++ b/src/version.ts @@ -1 +1 @@ -export const SDK_VERSION = "2.3.2"; +export const SDK_VERSION = "2.3.3"; diff --git a/src/wrapper/Pipedream.ts b/src/wrapper/Pipedream.ts deleted file mode 100644 index 6d6198d..0000000 --- a/src/wrapper/Pipedream.ts +++ /dev/null @@ -1,121 +0,0 @@ -import type { TokenProvider } from "../core/auth/TokenProvider.js"; -import { ProjectEnvironment } from "../api/index.js"; -import { Workflows } from "../api/resources/workflows/client/Client.js"; -import { PipedreamClient } from "../Client.js"; -import { PipedreamEnvironment } from "../environments.js"; -import { getBaseUrl } from "./utils/getBaseUrl.js"; - -export type PipedreamClientOpts = { - /** - * Optional client ID for authentication. - */ - clientId?: string; - - /** - * Optional client secret for authentication. - */ - clientSecret?: string; - - /** - * The Pipedream environment to connect to. - */ - environment?: PipedreamEnvironment; - - /** - * The project environment configuration. - */ - projectEnvironment?: ProjectEnvironment; - - /** - * The unique identifier for the project. This field is required, passed - * either explicitly or by setting the `PIPEDREAM_PROJECT_ID` environment - * variable. - */ - projectId?: string; - - /** - * Optional token provider for authentication. - */ - tokenProvider?: TokenProvider; - - /** - * Optional custom domain for workflow execution. - */ - workflowDomain?: string; -}; - -export class Pipedream extends PipedreamClient { - private _workflowDomain?: string; - private _workflows: Workflows | undefined; - - public constructor(opts: PipedreamClientOpts = {}) { - const { - environment = PipedreamEnvironment.Prod, - projectEnvironment = process.env.PIPEDREAM_PROJECT_ENVIRONMENT ?? ProjectEnvironment.Production, - projectId = process.env.PIPEDREAM_PROJECT_ID, - workflowDomain, - } = opts || {}; - - if (!projectEnvironment) { - throw new Error("Project environment cannot be empty"); - } - if ( - projectEnvironment !== ProjectEnvironment.Production && - projectEnvironment !== ProjectEnvironment.Development - ) { - throw new Error( - `Project environment must be either '${ProjectEnvironment.Production}' or '${ProjectEnvironment.Development}'`, - ); - } - - const baseUrl = getBaseUrl(environment); - const clientOpts: PipedreamClient.Options = { - baseUrl, - environment, - projectEnvironment, - projectId: projectId ?? "", - }; - - if ("tokenProvider" in opts) { - clientOpts.tokenProvider = opts.tokenProvider; - } else { - const { clientId = process.env.PIPEDREAM_CLIENT_ID, clientSecret = process.env.PIPEDREAM_CLIENT_SECRET } = - opts || {}; - - if (!clientId || !clientSecret) { - throw new Error("Client ID and secret are both required and cannot be blank"); - } - - if (!projectId) { - // Project ID is required here because it cannot be inferred - // from the client ID/secret, as opposed to the case with access - // tokens. - throw new Error("Project ID cannot be blank"); - } - - clientOpts.clientId = clientId; - clientOpts.clientSecret = clientSecret; - } - - super(clientOpts); - - this._workflowDomain = workflowDomain; - } - - /** - * Returns an access token that can be used to authenticate API requests - * - * @returns A promise that resolves to the access token string. - */ - public get rawAccessToken(): Promise { - return this._tokenProvider.getToken(); - } - - public get workflows(): Workflows { - return (this._workflows ??= new Workflows({ - ...this._options, - token: async () => await this._tokenProvider.getToken(), - workflowDomain: this._workflowDomain, - })); - } -} diff --git a/src/wrapper/utils/getBaseUrl.browser.ts b/src/wrapper/utils/getBaseUrl.browser.ts deleted file mode 100644 index dff6586..0000000 --- a/src/wrapper/utils/getBaseUrl.browser.ts +++ /dev/null @@ -1,9 +0,0 @@ -import { PipedreamEnvironment } from "../../environments.js"; - -/** - * Returns the base URL for the Pipedream API based on the provided environment. - * Browser-optimized version that returns the production environment directly. - * - * @returns The base URL for the Pipedream API. - */ -export const getBaseUrl = (): string => PipedreamEnvironment.Prod; diff --git a/src/wrapper/utils/getBaseUrl.ts b/src/wrapper/utils/getBaseUrl.ts deleted file mode 100644 index d8bf07e..0000000 --- a/src/wrapper/utils/getBaseUrl.ts +++ /dev/null @@ -1,12 +0,0 @@ -import { PipedreamEnvironment } from "../../environments.js"; - -/** - * Returns the base URL for the Pipedream API based on the provided environment. - * It replaces any placeholders in the environment string with corresponding - * environment variables. - * - * @param environment - The Pipedream environment string. - * @returns The base URL for the Pipedream API. - */ -export const getBaseUrl = (environment: PipedreamEnvironment): string => - environment.replace(/\$\{(\w+)\}/g, (_, name) => process.env[name] ?? ""); diff --git a/src/wrapper/utils/index.ts b/src/wrapper/utils/index.ts deleted file mode 100644 index 9675021..0000000 --- a/src/wrapper/utils/index.ts +++ /dev/null @@ -1 +0,0 @@ -export { getBaseUrl } from "./getBaseUrl.js"; From a5513e1142782fdff8114c60f3d542d5903967e1 Mon Sep 17 00:00:00 2001 From: Jay Vercellone Date: Wed, 10 Dec 2025 18:40:46 -0300 Subject: [PATCH 2/3] Revert "Temporarily make custom files updateable" This reverts commit 9102f381b4e570032e7afc26d365fd309a659245. --- .fernignore | 11 +++++++++++ 1 file changed, 11 insertions(+) diff --git a/.fernignore b/.fernignore index 261dfc3..e9f73aa 100644 --- a/.fernignore +++ b/.fernignore @@ -18,11 +18,21 @@ reference.md MIGRATE.md # Custom Pipedream client files +src/api/resources/index.ts +src/api/types/index.ts +src/browser/index.ts +src/index.ts +src/wrapper # Ideally, we shouldn't. But until Fern supports the changes that we've made we # have to override some parts. +src/Client.ts # Custom auth files +src/core/auth/index.ts +src/core/auth/ConnectTokenProvider.ts +src/core/auth/StaticTokenProvider.ts +src/core/auth/TokenProvider.ts # Custom configuration props files src/api/types/ConfiguredProps.ts @@ -45,3 +55,4 @@ src/api/resources/workflows/client/requests/InvokeWorkflowOpts.ts src/api/resources/workflows/client/Client.ts src/api/resources/workflows/client/index.ts src/api/resources/workflows/index.ts +src/api/types/HTTPAuthType.ts From 27dc1502cd1605edadc386864767366e8387d0d1 Mon Sep 17 00:00:00 2001 From: Jay Vercellone Date: Wed, 10 Dec 2025 18:52:46 -0300 Subject: [PATCH 3/3] Bring back temporarily deleted files --- package.json | 31 +++ src/Client.ts | 54 ++-- src/api/resources/index.ts | 2 + src/api/types/HTTPAuthType.ts | 12 + src/api/types/index.ts | 1 + src/browser/index.ts | 324 ++++++++++++++++++++++++ src/core/auth/ConnectTokenProvider.ts | 66 +++++ src/core/auth/StaticTokenProvider.ts | 13 + src/core/auth/TokenProvider.ts | 3 + src/core/auth/index.ts | 3 + src/index.ts | 3 +- src/wrapper/Pipedream.ts | 121 +++++++++ src/wrapper/utils/getBaseUrl.browser.ts | 9 + src/wrapper/utils/getBaseUrl.ts | 12 + src/wrapper/utils/index.ts | 1 + 15 files changed, 630 insertions(+), 25 deletions(-) create mode 100644 src/api/types/HTTPAuthType.ts create mode 100644 src/browser/index.ts create mode 100644 src/core/auth/ConnectTokenProvider.ts create mode 100644 src/core/auth/StaticTokenProvider.ts create mode 100644 src/core/auth/TokenProvider.ts create mode 100644 src/wrapper/Pipedream.ts create mode 100644 src/wrapper/utils/getBaseUrl.browser.ts create mode 100644 src/wrapper/utils/getBaseUrl.ts create mode 100644 src/wrapper/utils/index.ts diff --git a/package.json b/package.json index 9a25bfc..7c23760 100644 --- a/package.json +++ b/package.json @@ -10,6 +10,11 @@ "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" @@ -20,6 +25,18 @@ }, "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": { @@ -32,6 +49,18 @@ }, "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": [ @@ -64,6 +93,8 @@ "@biomejs/biome": "2.2.5" }, "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 f84e9f2..0ec2bab 100644 --- a/src/Client.ts +++ b/src/Client.ts @@ -1,5 +1,7 @@ -// This file was auto-generated by Fern from our API Definition. +// This file was initially auto-generated by Fern from our API Definition. +// It was later customized by the Pipedream team. +import { SDK_VERSION } from "./version.js"; import { Accounts } from "./api/resources/accounts/client/Client.js"; import { Actions } from "./api/resources/actions/client/Client.js"; import { AppCategories } from "./api/resources/appCategories/client/Client.js"; @@ -21,6 +23,7 @@ export declare namespace PipedreamClient { export interface Options extends BaseClientOptions { clientId?: core.Supplier; clientSecret?: core.Supplier; + tokenProvider?: core.TokenProvider; } export interface RequestOptions extends BaseRequestOptions {} @@ -28,7 +31,7 @@ export declare namespace PipedreamClient { export class PipedreamClient { protected readonly _options: PipedreamClient.Options; - private readonly _oauthTokenProvider: core.OAuthTokenProvider; + protected readonly _tokenProvider: core.TokenProvider; protected _appCategories: AppCategories | undefined; protected _apps: Apps | undefined; protected _accounts: Accounts | undefined; @@ -37,8 +40,8 @@ export class PipedreamClient { protected _actions: Actions | undefined; protected _triggers: Triggers | undefined; protected _deployedTriggers: DeployedTriggers | undefined; - protected _projects: Projects | undefined; protected _fileStash: FileStash | undefined; + protected _projects: Projects | undefined; protected _proxy: Proxy | undefined; protected _tokens: Tokens | undefined; protected _oauthTokens: OauthTokens | undefined; @@ -51,8 +54,8 @@ export class PipedreamClient { "x-pd-environment": _options?.projectEnvironment, "X-Fern-Language": "JavaScript", "X-Fern-SDK-Name": "@pipedream/sdk", - "X-Fern-SDK-Version": "2.3.3", - "User-Agent": "@pipedream/sdk/2.3.3", + "X-Fern-SDK-Version": SDK_VERSION, + "User-Agent": `@pipedream/sdk/${SDK_VERSION}`, "X-Fern-Runtime": core.RUNTIME.type, "X-Fern-Runtime-Version": core.RUNTIME.version, }, @@ -60,6 +63,10 @@ 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( @@ -74,9 +81,8 @@ export class PipedreamClient { ); } - this._oauthTokenProvider = new core.OAuthTokenProvider({ + return new core.OAuthTokenProvider({ clientId, - clientSecret, authClient: new OauthTokens({ ...this._options, @@ -88,91 +94,91 @@ export class PipedreamClient { public get appCategories(): AppCategories { return (this._appCategories ??= new AppCategories({ ...this._options, - token: async () => await this._oauthTokenProvider.getToken(), + token: async () => await this._tokenProvider.getToken(), })); } public get apps(): Apps { return (this._apps ??= new Apps({ ...this._options, - token: async () => await this._oauthTokenProvider.getToken(), + token: async () => await this._tokenProvider.getToken(), })); } public get accounts(): Accounts { return (this._accounts ??= new Accounts({ ...this._options, - token: async () => await this._oauthTokenProvider.getToken(), + token: async () => await this._tokenProvider.getToken(), })); } public get users(): Users { return (this._users ??= new Users({ ...this._options, - token: async () => await this._oauthTokenProvider.getToken(), + token: async () => await this._tokenProvider.getToken(), })); } public get components(): Components { return (this._components ??= new Components({ ...this._options, - token: async () => await this._oauthTokenProvider.getToken(), + token: async () => await this._tokenProvider.getToken(), })); } public get actions(): Actions { return (this._actions ??= new Actions({ ...this._options, - token: async () => await this._oauthTokenProvider.getToken(), + token: async () => await this._tokenProvider.getToken(), })); } public get triggers(): Triggers { return (this._triggers ??= new Triggers({ ...this._options, - token: async () => await this._oauthTokenProvider.getToken(), + token: async () => await this._tokenProvider.getToken(), })); } public get deployedTriggers(): DeployedTriggers { return (this._deployedTriggers ??= new DeployedTriggers({ ...this._options, - token: async () => await this._oauthTokenProvider.getToken(), + token: async () => await this._tokenProvider.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._oauthTokenProvider.getToken(), + token: async () => await this._tokenProvider.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._oauthTokenProvider.getToken(), + token: async () => await this._tokenProvider.getToken(), })); } public get proxy(): Proxy { return (this._proxy ??= new Proxy({ ...this._options, - token: async () => await this._oauthTokenProvider.getToken(), + token: async () => await this._tokenProvider.getToken(), })); } public get tokens(): Tokens { return (this._tokens ??= new Tokens({ ...this._options, - token: async () => await this._oauthTokenProvider.getToken(), + token: async () => await this._tokenProvider.getToken(), })); } public get oauthTokens(): OauthTokens { return (this._oauthTokens ??= new OauthTokens({ ...this._options, - token: async () => await this._oauthTokenProvider.getToken(), + token: async () => await this._tokenProvider.getToken(), })); } } diff --git a/src/api/resources/index.ts b/src/api/resources/index.ts index cfdfa3f..c9bfa5f 100644 --- a/src/api/resources/index.ts +++ b/src/api/resources/index.ts @@ -26,3 +26,5 @@ export * from "./triggers/client/requests/index.js"; export * as triggers from "./triggers/index.js"; export * from "./triggers/types/index.js"; export * as users from "./users/index.js"; +export * as workflows from "./workflows/index.js"; +export * from "./workflows/client/requests/index.js"; diff --git a/src/api/types/HTTPAuthType.ts b/src/api/types/HTTPAuthType.ts new file mode 100644 index 0000000..19998a8 --- /dev/null +++ b/src/api/types/HTTPAuthType.ts @@ -0,0 +1,12 @@ +/** + * 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 b000db2..ceebb86 100644 --- a/src/api/types/index.ts +++ b/src/api/types/index.ts @@ -83,6 +83,7 @@ export * from "./GetTriggerResponse.js"; export * from "./GetTriggersResponse.js"; export * from "./GetTriggerWebhooksResponse.js"; export * from "./GetTriggerWorkflowsResponse.js"; +export * from "./HTTPAuthType.js"; export * from "./HttpInterface.js"; export * from "./HttpRequestAuth.js"; export * from "./HttpRequestAuthType.js"; diff --git a/src/browser/index.ts b/src/browser/index.ts new file mode 100644 index 0000000..5ff230b --- /dev/null +++ b/src/browser/index.ts @@ -0,0 +1,324 @@ +// This code is meant to be run client-side. Never provide project keys to the +// browser client, or make API requests to the Pipedream API to fetch +// credentials. The browser client is meant for initiating browser-specific +// operations, like connecting accounts via Pipedream Connect. + +// Browser-specific imports that avoid Node.js dependencies +export type * from "../api/types/index.js"; +export * from "../index.js"; + +import { ConnectTokenProvider, type TokenCallback } from "../core/auth/index.js"; +import { type Account, type App, PipedreamClient as BackendClient, PipedreamEnvironment } from "../index.js"; +import type { PipedreamClientOpts as BackendClientOpts } from "../wrapper/Pipedream.js"; + +if (typeof process === "undefined") { + // We're in the browser + globalThis.process ||= { + env: {}, + } as NodeJS.Process; +} + +/** + * Options for creating a browser-side client. This is used to configure the + * PipedreamClient instance. + */ +export type PipedreamClientOpts = Omit & { + /** + * The frontend host URL. Used by Pipedream employees only. Defaults to + * "pipedream.com" if not provided. + */ + frontendHost?: string; + + /** + * Will be called whenever we need a new token. + * + * The callback function should return the response from + * `serverClient.tokens.create`. + */ + tokenCallback: TokenCallback; + + /** + * An external user ID associated with the token. + */ + externalUserId: string; +}; + +/** + * The result of a successful connection. + */ +export type ConnectResult = { + /** + * The unique identifier of the connected account. + */ + id: Account["id"]; +}; + +/** + * The status when the Connect dialog is closed. + */ +export type ConnectStatus = { + /** + * Whether the connection was successful (account was connected). + */ + successful: boolean; + + /** + * Whether the connection process was completed (vs user closing early). + */ + completed: boolean; +}; + +/** + * Custom error class for handling connection errors. + */ +export class ConnectError extends Error {} + +/** + * Options for starting the connection process. + */ +export type StartConnectOpts = { + /** + * The token used for authenticating the connection. + * + * Optional if the client was already initialized with a token + */ + token?: string; + + /** + * The app to connect to + */ + app: App["nameSlug"]; + + /** + * The OAuth app ID to connect to. + */ + oauthAppId?: App["id"]; + + /** + * Callback function to be called upon successful connection. + * + * @param res - The result of the connection. + */ + onSuccess?: (res: ConnectResult) => void; + + /** + * Callback function to be called if an error occurs during the connection. + * + * @param err - The error that occurred during the connection. + */ + onError?: (err: ConnectError) => void; + + /** + * Callback function to be called when the Connect iFrame is closed. + * + * @param status - The status of the connection when closed. + */ + onClose?: (status: ConnectStatus) => void; +}; + +/** + * Creates a new instance of `PipedreamClient` with the provided options. + * + * @example + * ```typescript + const client = createFrontendClient({ + tokenCallback, + externalUserId, + }); + * ``` + * @param opts - The options for creating the browser client. + * @returns A new instance of `PipedreamClient`. + */ +export function createFrontendClient( + opts: PipedreamClientOpts & { + /** + * The Connect token used for authenticating the connection. Useful if you + * don't need to refresh it (e.g. if the client will be used in read-only + * requests). + */ + token?: string; + }, +): PipedreamClient { + const { + // These are some dummy values that would produce a blank Connect token, + // in case the user does not need to make any API requests other than + // connecting an external user's account. + externalUserId = "", + token = "", + tokenCallback = () => Promise.resolve({ token, expiresAt: new Date(), connectLinkUrl: "" }), + } = opts || {}; + return new PipedreamClient({ + ...opts, + externalUserId, + tokenCallback, + }); +} + +/** + * A client for interacting with the Pipedream Connect API from the browser. + */ +export class PipedreamClient extends BackendClient { + private baseURL: string; + private iframeURL: string; + private iframe?: HTMLIFrameElement; + private iframeId = 0; + + /** + * Constructs a new `PipedreamClient` instance. + * + * @param opts - The options for configuring the browser client. + */ + constructor(opts: PipedreamClientOpts) { + const { + environment = PipedreamEnvironment.Prod, + externalUserId, + projectEnvironment, + tokenCallback, + workflowDomain, + } = opts || {}; + + 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"); + } + + const tokenProvider = new ConnectTokenProvider({ + externalUserId, + tokenCallback, + }); + + super({ + environment, + projectEnvironment, + projectId: "", + tokenProvider, + workflowDomain, + }); + + this.baseURL = `https://${opts.frontendHost || "pipedream.com"}`; + this.iframeURL = `${this.baseURL}/_static/connect.html`; + } + + get externalUserId(): string | undefined { + return (this._tokenProvider as ConnectTokenProvider).externalUserId; + } + + /** + * Initiates the process of connecting an account. + * + * @param opts - The options for starting the connection process. + * + * @example + * ```typescript + * client.connectAccount({ + * token: "your-token", + * app: "your-app-id", + * onSuccess: (res) => { + * console.log("Connected account ID:", res.id); + * }, + * onError: (err) => { + * console.error("Connection error:", err); + * }, + * onClose: (status) => { + * if (!status.successful) { + * console.log("User closed without connecting"); + * } + * }, + * }); + * ``` + */ + public async connectAccount(opts: StartConnectOpts): Promise { + let connectionSuccessful = false; + let connectionCompleted = false; + + const onMessage = (e: MessageEvent) => { + switch (e.data?.type) { + case "success": + connectionSuccessful = true; + connectionCompleted = true; + opts.onSuccess?.({ + id: e.data?.authProvisionId, + }); + break; + case "error": + connectionCompleted = true; + opts.onError?.(new ConnectError(e.data.error)); + break; + case "close": + this.cleanup(onMessage); + opts.onClose?.({ + successful: connectionSuccessful, + completed: connectionCompleted, + }); + break; + default: + break; + } + }; + + window.addEventListener("message", onMessage); + + try { + await this.createIframe(opts); + } catch (err) { + opts.onError?.(err as ConnectError); + } + + // The token expires once it's used to create a connected account. We + // need to get a new token for the next requests. + (this._tokenProvider as ConnectTokenProvider).refresh(); + } + + /** + * Cleans up the iframe and message event listener after the connection + * process is complete. + * + * @param onMessage - The message event handler to remove. + */ + private cleanup(onMessage: (e: MessageEvent) => void) { + this.iframe?.remove(); + window.removeEventListener("message", onMessage); + } + + /** + * Creates an iframe for the connection process and appends it to the document + * body. + * + * @param opts - The options for starting the connection process. + * + * @throws {ConnectError} If the app option is not a string. + */ + private async createIframe(opts: StartConnectOpts) { + const token = opts.token || (await this._tokenProvider.getToken()); + const qp = new URLSearchParams({ + token, + }); + + if (typeof opts.app === "string") { + qp.set("app", opts.app); + } else { + throw new ConnectError("Object app not yet supported"); + } + + if (opts.oauthAppId) { + qp.set("oauthAppId", opts.oauthAppId); + } + + const iframe = document.createElement("iframe"); + iframe.id = `pipedream-connect-iframe-${this.iframeId++}`; + iframe.title = "Pipedream Connect"; + iframe.src = `${this.iframeURL}?${qp.toString()}`; + iframe.style.cssText = "position:fixed;inset:0;z-index:2147483647;border:0;display:block;overflow:hidden auto"; + iframe.width = "100%"; + iframe.height = "100%"; + + iframe.onload = () => { + this.iframe = iframe; + }; + + document.body.appendChild(iframe); + } +} diff --git a/src/core/auth/ConnectTokenProvider.ts b/src/core/auth/ConnectTokenProvider.ts new file mode 100644 index 0000000..7ec3487 --- /dev/null +++ b/src/core/auth/ConnectTokenProvider.ts @@ -0,0 +1,66 @@ +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(): void { + this._token = undefined; + } +} diff --git a/src/core/auth/StaticTokenProvider.ts b/src/core/auth/StaticTokenProvider.ts new file mode 100644 index 0000000..b5b2beb --- /dev/null +++ b/src/core/auth/StaticTokenProvider.ts @@ -0,0 +1,13 @@ +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 new file mode 100644 index 0000000..f648c39 --- /dev/null +++ b/src/core/auth/TokenProvider.ts @@ -0,0 +1,3 @@ +export interface TokenProvider { + getToken(): Promise; +} diff --git a/src/core/auth/index.ts b/src/core/auth/index.ts index 1ec5eb4..fede199 100644 --- a/src/core/auth/index.ts +++ b/src/core/auth/index.ts @@ -1,3 +1,6 @@ export { BasicAuth } from "./BasicAuth.js"; export { BearerToken } from "./BearerToken.js"; +export { ConnectTokenProvider, type TokenCallback } from "./ConnectTokenProvider.js"; export { OAuthTokenProvider } from "./OAuthTokenProvider.js"; +export { StaticTokenProvider } from "./StaticTokenProvider.js"; +export type { TokenProvider } from "./TokenProvider.js"; diff --git a/src/index.ts b/src/index.ts index 73733f5..b06997c 100644 --- a/src/index.ts +++ b/src/index.ts @@ -1,6 +1,7 @@ +export * from "./api/index.js"; export * as Pipedream from "./api/index.js"; export type { BaseClientOptions, BaseRequestOptions } from "./BaseClient.js"; -export { PipedreamClient } from "./Client.js"; export { PipedreamEnvironment } from "./environments.js"; +export { Pipedream as PipedreamClient, type PipedreamClientOpts } from "./wrapper/Pipedream.js"; export { PipedreamError, PipedreamTimeoutError } from "./errors/index.js"; export * as serialization from "./serialization/index.js"; diff --git a/src/wrapper/Pipedream.ts b/src/wrapper/Pipedream.ts new file mode 100644 index 0000000..6d6198d --- /dev/null +++ b/src/wrapper/Pipedream.ts @@ -0,0 +1,121 @@ +import type { TokenProvider } from "../core/auth/TokenProvider.js"; +import { ProjectEnvironment } from "../api/index.js"; +import { Workflows } from "../api/resources/workflows/client/Client.js"; +import { PipedreamClient } from "../Client.js"; +import { PipedreamEnvironment } from "../environments.js"; +import { getBaseUrl } from "./utils/getBaseUrl.js"; + +export type PipedreamClientOpts = { + /** + * Optional client ID for authentication. + */ + clientId?: string; + + /** + * Optional client secret for authentication. + */ + clientSecret?: string; + + /** + * The Pipedream environment to connect to. + */ + environment?: PipedreamEnvironment; + + /** + * The project environment configuration. + */ + projectEnvironment?: ProjectEnvironment; + + /** + * The unique identifier for the project. This field is required, passed + * either explicitly or by setting the `PIPEDREAM_PROJECT_ID` environment + * variable. + */ + projectId?: string; + + /** + * Optional token provider for authentication. + */ + tokenProvider?: TokenProvider; + + /** + * Optional custom domain for workflow execution. + */ + workflowDomain?: string; +}; + +export class Pipedream extends PipedreamClient { + private _workflowDomain?: string; + private _workflows: Workflows | undefined; + + public constructor(opts: PipedreamClientOpts = {}) { + const { + environment = PipedreamEnvironment.Prod, + projectEnvironment = process.env.PIPEDREAM_PROJECT_ENVIRONMENT ?? ProjectEnvironment.Production, + projectId = process.env.PIPEDREAM_PROJECT_ID, + workflowDomain, + } = opts || {}; + + if (!projectEnvironment) { + throw new Error("Project environment cannot be empty"); + } + if ( + projectEnvironment !== ProjectEnvironment.Production && + projectEnvironment !== ProjectEnvironment.Development + ) { + throw new Error( + `Project environment must be either '${ProjectEnvironment.Production}' or '${ProjectEnvironment.Development}'`, + ); + } + + const baseUrl = getBaseUrl(environment); + const clientOpts: PipedreamClient.Options = { + baseUrl, + environment, + projectEnvironment, + projectId: projectId ?? "", + }; + + if ("tokenProvider" in opts) { + clientOpts.tokenProvider = opts.tokenProvider; + } else { + const { clientId = process.env.PIPEDREAM_CLIENT_ID, clientSecret = process.env.PIPEDREAM_CLIENT_SECRET } = + opts || {}; + + if (!clientId || !clientSecret) { + throw new Error("Client ID and secret are both required and cannot be blank"); + } + + if (!projectId) { + // Project ID is required here because it cannot be inferred + // from the client ID/secret, as opposed to the case with access + // tokens. + throw new Error("Project ID cannot be blank"); + } + + clientOpts.clientId = clientId; + clientOpts.clientSecret = clientSecret; + } + + super(clientOpts); + + this._workflowDomain = workflowDomain; + } + + /** + * Returns an access token that can be used to authenticate API requests + * + * @returns A promise that resolves to the access token string. + */ + public get rawAccessToken(): Promise { + return this._tokenProvider.getToken(); + } + + public get workflows(): Workflows { + return (this._workflows ??= new Workflows({ + ...this._options, + token: async () => await this._tokenProvider.getToken(), + workflowDomain: this._workflowDomain, + })); + } +} diff --git a/src/wrapper/utils/getBaseUrl.browser.ts b/src/wrapper/utils/getBaseUrl.browser.ts new file mode 100644 index 0000000..dff6586 --- /dev/null +++ b/src/wrapper/utils/getBaseUrl.browser.ts @@ -0,0 +1,9 @@ +import { PipedreamEnvironment } from "../../environments.js"; + +/** + * Returns the base URL for the Pipedream API based on the provided environment. + * Browser-optimized version that returns the production environment directly. + * + * @returns The base URL for the Pipedream API. + */ +export const getBaseUrl = (): string => PipedreamEnvironment.Prod; diff --git a/src/wrapper/utils/getBaseUrl.ts b/src/wrapper/utils/getBaseUrl.ts new file mode 100644 index 0000000..d8bf07e --- /dev/null +++ b/src/wrapper/utils/getBaseUrl.ts @@ -0,0 +1,12 @@ +import { PipedreamEnvironment } from "../../environments.js"; + +/** + * Returns the base URL for the Pipedream API based on the provided environment. + * It replaces any placeholders in the environment string with corresponding + * environment variables. + * + * @param environment - The Pipedream environment string. + * @returns The base URL for the Pipedream API. + */ +export const getBaseUrl = (environment: PipedreamEnvironment): string => + environment.replace(/\$\{(\w+)\}/g, (_, name) => process.env[name] ?? ""); diff --git a/src/wrapper/utils/index.ts b/src/wrapper/utils/index.ts new file mode 100644 index 0000000..9675021 --- /dev/null +++ b/src/wrapper/utils/index.ts @@ -0,0 +1 @@ +export { getBaseUrl } from "./getBaseUrl.js";