@crossdelta/platform-sdk 0.18.0 → 0.18.2
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
|
@@ -129,14 +129,8 @@ const envSchema = z.object({
|
|
|
129
129
|
MY_SERVICE_PORT: z.string().optional(),
|
|
130
130
|
})
|
|
131
131
|
|
|
132
|
-
|
|
133
|
-
|
|
134
|
-
console.error('❌ Environment validation failed:')
|
|
135
|
-
console.error(result.error.format())
|
|
136
|
-
process.exit(1)
|
|
137
|
-
}
|
|
138
|
-
|
|
139
|
-
export const env = result.data
|
|
132
|
+
// Use .parse() - throws ZodError if validation fails
|
|
133
|
+
export const env = envSchema.parse(process.env)
|
|
140
134
|
```
|
|
141
135
|
|
|
142
136
|
**Add required environment variables:**
|
|
@@ -154,21 +148,16 @@ const envSchema = z.object({
|
|
|
154
148
|
REDIS_URL: z.string().url().optional(),
|
|
155
149
|
})
|
|
156
150
|
|
|
157
|
-
|
|
158
|
-
|
|
159
|
-
console.error('❌ Environment validation failed:')
|
|
160
|
-
console.error(result.error.format())
|
|
161
|
-
process.exit(1)
|
|
162
|
-
}
|
|
163
|
-
|
|
164
|
-
export const env = result.data
|
|
151
|
+
// Use .parse() - throws ZodError if validation fails
|
|
152
|
+
export const env = envSchema.parse(process.env)
|
|
165
153
|
```
|
|
166
154
|
|
|
167
155
|
**Rules:**
|
|
168
|
-
- ✅ Use
|
|
156
|
+
- ✅ Use `.parse()` - throws error automatically (better separation of concerns)
|
|
169
157
|
- ✅ Export validated `env` object for type-safe access
|
|
170
158
|
- ✅ Use Zod v4 syntax (no params on `.email()`, `.url()`, etc.)
|
|
171
159
|
- ✅ Port is always optional (has fallback in index.ts)
|
|
160
|
+
- ❌ DO NOT use `safeParse()` + `process.exit()` - breaks testability
|
|
172
161
|
- ❌ DO NOT add PORT to env schema - it's read directly from process.env
|
|
173
162
|
|
|
174
163
|
---
|
|
@@ -193,15 +182,9 @@ const envSchema = z.object({
|
|
|
193
182
|
|
|
194
183
|
export type Env = z.infer<typeof envSchema>
|
|
195
184
|
|
|
196
|
-
//
|
|
197
|
-
|
|
198
|
-
|
|
199
|
-
console.error('❌ Environment validation failed:')
|
|
200
|
-
console.error(result.error.format())
|
|
201
|
-
process.exit(1) // ← Force crash with exit code 1
|
|
202
|
-
}
|
|
203
|
-
|
|
204
|
-
export const env = result.data
|
|
185
|
+
// Use .parse() - throws ZodError if validation fails
|
|
186
|
+
// Let the caller (index.ts) decide how to handle the error
|
|
187
|
+
export const env = envSchema.parse(process.env)
|
|
205
188
|
```
|
|
206
189
|
|
|
207
190
|
### 2️⃣ **CRITICAL: Import in `src/index.ts` early!**
|
|
@@ -235,8 +218,9 @@ console.log(`Service running on http://localhost:${port}`)
|
|
|
235
218
|
**CRITICAL:**
|
|
236
219
|
- ✅ **MUST import `env` in `src/index.ts`** - without import, validation never runs!
|
|
237
220
|
- ✅ Import early (after telemetry, before everything else)
|
|
238
|
-
- ✅ Use
|
|
239
|
-
- ✅
|
|
221
|
+
- ✅ Use `.parse()` - throws ZodError automatically (better than process.exit!)
|
|
222
|
+
- ✅ Uncaught error causes process to crash with proper stack trace
|
|
223
|
+
- ❌ **DO NOT** use `safeParse()` + `process.exit()` - breaks separation of concerns
|
|
240
224
|
- ❌ **DO NOT** include `SERVICE_NAME_PORT` in env schema - already handled by CLI template
|
|
241
225
|
- ❌ **DO NOT** validate inside handlers or use-cases
|
|
242
226
|
|
|
@@ -134,14 +134,8 @@ const envSchema = z.object({
|
|
|
134
134
|
MY_SERVICE_PORT: z.string().optional(),
|
|
135
135
|
})
|
|
136
136
|
|
|
137
|
-
|
|
138
|
-
|
|
139
|
-
console.error('❌ Environment validation failed:')
|
|
140
|
-
console.error(result.error.format())
|
|
141
|
-
process.exit(1)
|
|
142
|
-
}
|
|
143
|
-
|
|
144
|
-
export const env = result.data
|
|
137
|
+
// Use .parse() - throws ZodError if validation fails
|
|
138
|
+
export const env = envSchema.parse(process.env)
|
|
145
139
|
```
|
|
146
140
|
|
|
147
141
|
**Add required environment variables:**
|
|
@@ -159,21 +153,16 @@ const envSchema = z.object({
|
|
|
159
153
|
REDIS_URL: z.string().url().optional(),
|
|
160
154
|
})
|
|
161
155
|
|
|
162
|
-
|
|
163
|
-
|
|
164
|
-
console.error('❌ Environment validation failed:')
|
|
165
|
-
console.error(result.error.format())
|
|
166
|
-
process.exit(1)
|
|
167
|
-
}
|
|
168
|
-
|
|
169
|
-
export const env = result.data
|
|
156
|
+
// Use .parse() - throws ZodError if validation fails
|
|
157
|
+
export const env = envSchema.parse(process.env)
|
|
170
158
|
```
|
|
171
159
|
|
|
172
160
|
**Rules:**
|
|
173
|
-
- ✅ Use
|
|
161
|
+
- ✅ Use `.parse()` - throws error automatically (better separation of concerns)
|
|
174
162
|
- ✅ Export validated `env` object for type-safe access
|
|
175
163
|
- ✅ Use Zod v4 syntax (no params on `.email()`, `.url()`, etc.)
|
|
176
164
|
- ✅ Port is always optional (has fallback in index.ts)
|
|
165
|
+
- ❌ DO NOT use `safeParse()` + `process.exit()` - breaks testability
|
|
177
166
|
- ❌ DO NOT add PORT to env schema - it's read directly from process.env
|
|
178
167
|
|
|
179
168
|
---
|
|
@@ -197,15 +186,9 @@ const envSchema = z.object({
|
|
|
197
186
|
|
|
198
187
|
export type Env = z.infer<typeof envSchema>
|
|
199
188
|
|
|
200
|
-
//
|
|
201
|
-
|
|
202
|
-
|
|
203
|
-
console.error('❌ Environment validation failed:')
|
|
204
|
-
console.error(result.error.format())
|
|
205
|
-
process.exit(1) // ← Force crash with exit code 1
|
|
206
|
-
}
|
|
207
|
-
|
|
208
|
-
export const env = result.data
|
|
189
|
+
// Use .parse() - throws ZodError if validation fails
|
|
190
|
+
// Let the caller (index.ts) decide how to handle the error
|
|
191
|
+
export const env = envSchema.parse(process.env)
|
|
209
192
|
```
|
|
210
193
|
|
|
211
194
|
### 2️⃣ **CRITICAL: Import in `src/index.ts` early!**
|
|
@@ -215,7 +198,7 @@ export const env = result.data
|
|
|
215
198
|
import '@crossdelta/telemetry' // ← MUST be first!
|
|
216
199
|
|
|
217
200
|
// ⚠️ CRITICAL: Import env IMMEDIATELY after telemetry
|
|
218
|
-
// This executes validation and
|
|
201
|
+
// This executes validation and throws ZodError if invalid
|
|
219
202
|
import { env } from './config/env' // ← THIS LINE IS REQUIRED!
|
|
220
203
|
|
|
221
204
|
import { serve } from '@hono/node-server'
|
|
@@ -248,8 +231,9 @@ serve({ fetch: app.fetch, port }, (info) => {
|
|
|
248
231
|
**CRITICAL:**
|
|
249
232
|
- ✅ **MUST import `env` in `src/index.ts`** - without import, validation never runs!
|
|
250
233
|
- ✅ Import early (after telemetry, before everything else)
|
|
251
|
-
- ✅ Use
|
|
252
|
-
- ✅
|
|
234
|
+
- ✅ Use `.parse()` - throws ZodError automatically (better than process.exit!)
|
|
235
|
+
- ✅ Uncaught error causes process to crash with proper stack trace
|
|
236
|
+
- ❌ **DO NOT** use `safeParse()` + `process.exit()` - breaks separation of concerns
|
|
253
237
|
- ❌ **DO NOT** include `SERVICE_NAME_PORT` in env schema - already handled by CLI template
|
|
254
238
|
- ❌ **DO NOT** validate inside handlers or use-cases
|
|
255
239
|
|
|
File without changes
|