Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 2 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -16,3 +16,5 @@ docs/.vuepress/dist

./package-lock.json
components/**/package-lock.json
/packages/evals/
/packages/sdk/examples/.next/
9 changes: 9 additions & 0 deletions packages/sdk/CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,12 +1,21 @@
<!-- markdownlint-disable MD024 -->
# Changelog

## [1.0.5] - 2024-11-18

### Changed

- The backend client used to default to `production` if the environment was not
specified. Now `environment` is a required argument for `createBackendClient`
and must be one of `production` or `development`.

## [1.0.4] - 2024-11-15

### Changed

- Improved the docs of the `getAccountById` method in the backend client to
clarify the behavior of the new argument.

- Fixed the exported `HTTPAuthType` enum so that it can be used by the consumers
of the SDK.

Expand Down
4 changes: 2 additions & 2 deletions packages/sdk/package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion packages/sdk/package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "@pipedream/sdk",
"version": "1.0.4",
"version": "1.0.5",
"description": "Pipedream SDK",
"main": "dist/server/index.js",
"module": "dist/server/index.js",
Expand Down
3 changes: 3 additions & 0 deletions packages/sdk/src/server/__tests__/server.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@ import {

const projectId = "proj_abc123";
const clientParams: BackendClientOpts = {
environment: "production",
credentials: {
clientId: "test-client-id",
clientSecret: "test-client-secret",
Expand Down Expand Up @@ -175,6 +176,7 @@ describe("BackendClient", () => {
clientId: "test-client-id",
clientSecret: "test-client-secret",
},
environment: "production",
projectId,
},
);
Expand Down Expand Up @@ -677,6 +679,7 @@ describe("BackendClient", () => {
clientId: "test-client-id",
clientSecret: "test-client-secret",
},
environment: "production",
projectId: "proj_abc123",
},
);
Expand Down
19 changes: 17 additions & 2 deletions packages/sdk/src/server/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,11 @@ export type OAuthCredentials = {
clientSecret: string;
};

/**
* The environment in which the server client is running.
*/
export type ProjectEnvironment = "development" | "production";

/**
* Options for creating a server-side client.
* This is used to configure the BackendClient instance.
Expand All @@ -25,7 +30,7 @@ export type BackendClientOpts = {
* The environment in which the server client is running (e.g., "production",
* "development").
*/
environment?: string;
environment?: ProjectEnvironment;

/**
* The credentials to use for authentication against the Pipedream API.
Expand Down Expand Up @@ -353,7 +358,8 @@ export class BackendClient {
* @param opts - The options for configuring the server client.
*/
constructor(opts: BackendClientOpts) {
this.environment = opts.environment ?? "production";
this.ensureValidEnvironment(opts.environment);
this.environment = opts.environment!;

this.projectId = opts.projectId;
if (!this.projectId) {
Expand All @@ -370,6 +376,15 @@ export class BackendClient {
this.oauthClient = this.newOauthClient(opts.credentials, this.baseApiUrl);
}

private ensureValidEnvironment(environment?: string) {
if (!environment || ![
"development",
"production",
].includes(environment)) {
throw new Error("Project environment is required. Supported environments are development and production.");
}
}

private newOauthClient(
{
clientId,
Expand Down
Loading