Skip to content

Commit 88045ea

Browse files
authored
Require project environment in SDK (#14679)
* Require project environment in SDK * Refactor environment check into its own method * Define a new type for project environment * Fix comment and update CHANGELOG.md * Fix linter errors * Fix linter errors * Update package lock * Update gitignore * Add eslint config * Apply eslint * Apply linter suggestions * Fix markdown syntax errors * Fix tests * Update pnpm lock * Remove pnpm lock changes * Remove eslint configs * Undo eslint change * Revert reversion of eslint changes
1 parent 8e93258 commit 88045ea

File tree

6 files changed

+34
-5
lines changed

6 files changed

+34
-5
lines changed

.gitignore

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -16,3 +16,5 @@ docs/.vuepress/dist
1616

1717
./package-lock.json
1818
components/**/package-lock.json
19+
/packages/evals/
20+
/packages/sdk/examples/.next/

packages/sdk/CHANGELOG.md

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,12 +1,21 @@
11
<!-- markdownlint-disable MD024 -->
22
# Changelog
33

4+
## [1.0.5] - 2024-11-18
5+
6+
### Changed
7+
8+
- The backend client used to default to `production` if the environment was not
9+
specified. Now `environment` is a required argument for `createBackendClient`
10+
and must be one of `production` or `development`.
11+
412
## [1.0.4] - 2024-11-15
513

614
### Changed
715

816
- Improved the docs of the `getAccountById` method in the backend client to
917
clarify the behavior of the new argument.
18+
1019
- Fixed the exported `HTTPAuthType` enum so that it can be used by the consumers
1120
of the SDK.
1221

packages/sdk/package-lock.json

Lines changed: 2 additions & 2 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

packages/sdk/package.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
{
22
"name": "@pipedream/sdk",
3-
"version": "1.0.4",
3+
"version": "1.0.5",
44
"description": "Pipedream SDK",
55
"main": "dist/server/index.js",
66
"module": "dist/server/index.js",

packages/sdk/src/server/__tests__/server.test.ts

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,7 @@ import {
1010

1111
const projectId = "proj_abc123";
1212
const clientParams: BackendClientOpts = {
13+
environment: "production",
1314
credentials: {
1415
clientId: "test-client-id",
1516
clientSecret: "test-client-secret",
@@ -175,6 +176,7 @@ describe("BackendClient", () => {
175176
clientId: "test-client-id",
176177
clientSecret: "test-client-secret",
177178
},
179+
environment: "production",
178180
projectId,
179181
},
180182
);
@@ -677,6 +679,7 @@ describe("BackendClient", () => {
677679
clientId: "test-client-id",
678680
clientSecret: "test-client-secret",
679681
},
682+
environment: "production",
680683
projectId: "proj_abc123",
681684
},
682685
);

packages/sdk/src/server/index.ts

Lines changed: 17 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,11 @@ export type OAuthCredentials = {
1616
clientSecret: string;
1717
};
1818

19+
/**
20+
* The environment in which the server client is running.
21+
*/
22+
export type ProjectEnvironment = "development" | "production";
23+
1924
/**
2025
* Options for creating a server-side client.
2126
* This is used to configure the BackendClient instance.
@@ -25,7 +30,7 @@ export type BackendClientOpts = {
2530
* The environment in which the server client is running (e.g., "production",
2631
* "development").
2732
*/
28-
environment?: string;
33+
environment?: ProjectEnvironment;
2934

3035
/**
3136
* The credentials to use for authentication against the Pipedream API.
@@ -353,7 +358,8 @@ export class BackendClient {
353358
* @param opts - The options for configuring the server client.
354359
*/
355360
constructor(opts: BackendClientOpts) {
356-
this.environment = opts.environment ?? "production";
361+
this.ensureValidEnvironment(opts.environment);
362+
this.environment = opts.environment!;
357363

358364
this.projectId = opts.projectId;
359365
if (!this.projectId) {
@@ -370,6 +376,15 @@ export class BackendClient {
370376
this.oauthClient = this.newOauthClient(opts.credentials, this.baseApiUrl);
371377
}
372378

379+
private ensureValidEnvironment(environment?: string) {
380+
if (!environment || ![
381+
"development",
382+
"production",
383+
].includes(environment)) {
384+
throw new Error("Project environment is required. Supported environments are development and production.");
385+
}
386+
}
387+
373388
private newOauthClient(
374389
{
375390
clientId,

0 commit comments

Comments
 (0)