-
Notifications
You must be signed in to change notification settings - Fork 5.3k
/
Copy pathpd-client.ts
47 lines (43 loc) · 1.48 KB
/
pd-client.ts
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
import { createBackendClient } from "@pipedream/sdk/server"
import { z } from "zod"
import { config } from "./config.js"
// Pipedream API client
export const createPdClient = () => {
try {
const clientId = z.string().parse(config.pipedream.clientId)
const clientSecret = z.string().parse(config.pipedream.clientSecret)
const projectId = z.string().parse(config.pipedream.projectId)
const environment = z
.enum([
"development",
"production",
])
.parse(config.pipedream.environment)
return createBackendClient({
credentials: {
clientId,
clientSecret,
},
projectId,
environment,
})
} catch (error) {
console.error(
"Failed to create Pipedream client:",
error instanceof Error
? error.message
: "Unknown error",
)
console.error("Make sure you've set all required environment variables:")
console.error("- PIPEDREAM_CLIENT_ID (not shown for security)")
console.error("- PIPEDREAM_CLIENT_SECRET (not shown for security)")
console.error("- PIPEDREAM_PROJECT_ID (not shown for security)")
console.error("- PIPEDREAM_PROJECT_ENVIRONMENT (defaults to 'development')")
// Create a more descriptive error message that includes original error
const errorMessage =
error instanceof Error
? `Missing or invalid Pipedream configuration: ${error.message}`
: "Missing or invalid Pipedream configuration"
throw new Error(errorMessage)
}
}