@goatlab/node-backend 0.1.1 → 0.2.0
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.
- package/README.md +67 -2
- package/dist/tsconfig.tsbuildinfo +1 -1
- package/package.json +12 -12
package/README.md
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
# @goatlab/node-backend
|
|
2
2
|
|
|
3
|
-
|
|
3
|
+
Common tools for Node.js backend applications, including caching, secret management, Express/tRPC integration, and testing utilities.
|
|
4
4
|
|
|
5
5
|
## Installation
|
|
6
6
|
|
|
@@ -58,4 +58,69 @@ const result = await cache.remember('expensive-op', 300000, async () => {
|
|
|
58
58
|
- **Cache Helpers**: Laravel-inspired helper methods like `remember()`, `rememberForever()`, and `pull()`
|
|
59
59
|
- **Namespace Operations**: Delete or retrieve values by key prefix with `deleteWhereStartsWith()` and `getValueWhereKeyStartsWith()`
|
|
60
60
|
- **Type Safety**: Full TypeScript support with generic types
|
|
61
|
-
- **Automatic Validation**: Skips caching of null, undefined, empty strings, empty arrays, and empty objects
|
|
61
|
+
- **Automatic Validation**: Skips caching of null, undefined, empty strings, empty arrays, and empty objects
|
|
62
|
+
|
|
63
|
+
## Secret Management
|
|
64
|
+
|
|
65
|
+
The `SecretService` provides secure secret management with support for multiple backends:
|
|
66
|
+
|
|
67
|
+
```typescript
|
|
68
|
+
import { SecretService } from '@goatlab/node-backend'
|
|
69
|
+
|
|
70
|
+
// File-based encrypted secrets
|
|
71
|
+
const fileSecrets = new SecretService('FILE', '/path/to/secrets.json')
|
|
72
|
+
|
|
73
|
+
// HashiCorp Vault integration
|
|
74
|
+
const vaultSecrets = new SecretService('VAULT', 'my-app/secrets')
|
|
75
|
+
|
|
76
|
+
// Environment variables (new!)
|
|
77
|
+
const envSecrets = new SecretService('ENV', 'APP') // Loads APP_* env vars
|
|
78
|
+
const allEnvSecrets = new SecretService('ENV', '') // Loads all env vars
|
|
79
|
+
|
|
80
|
+
// Usage
|
|
81
|
+
await fileSecrets.loadSecrets()
|
|
82
|
+
const apiKey = await fileSecrets.getSecret('API_KEY')
|
|
83
|
+
const config = await fileSecrets.getSecretJson('CONFIG')
|
|
84
|
+
|
|
85
|
+
// Store secrets (FILE and VAULT providers)
|
|
86
|
+
await fileSecrets.storeSecrets({ API_KEY: 'secret-value' })
|
|
87
|
+
```
|
|
88
|
+
|
|
89
|
+
### Secret Provider Features
|
|
90
|
+
|
|
91
|
+
- **FILE**: Encrypted local file storage using AES encryption
|
|
92
|
+
- **VAULT**: HashiCorp Vault integration with automatic token management
|
|
93
|
+
- **ENV**: Runtime environment variable access with optional prefix filtering
|
|
94
|
+
- **Caching**: Automatic in-memory caching for improved performance
|
|
95
|
+
- **Type Safety**: Generic type support for JSON secrets
|
|
96
|
+
|
|
97
|
+
## Express + tRPC Integration
|
|
98
|
+
|
|
99
|
+
Helper for creating Express applications with tRPC integration:
|
|
100
|
+
|
|
101
|
+
```typescript
|
|
102
|
+
import { getExpressTrpcApp } from '@goatlab/node-backend'
|
|
103
|
+
import { initTRPC } from '@trpc/server'
|
|
104
|
+
|
|
105
|
+
const t = initTRPC.create()
|
|
106
|
+
const appRouter = t.router({
|
|
107
|
+
hello: t.procedure.query(() => 'Hello World!')
|
|
108
|
+
})
|
|
109
|
+
|
|
110
|
+
const app = getExpressTrpcApp({
|
|
111
|
+
trpcRouter: appRouter,
|
|
112
|
+
port: 3000,
|
|
113
|
+
sentryService,
|
|
114
|
+
expressResources: [customRouter], // Optional Express routers
|
|
115
|
+
customHandlers: [middleware1, middleware2], // Optional middleware
|
|
116
|
+
shouldInitOpenApiDocs: true, // Optional OpenAPI documentation
|
|
117
|
+
})
|
|
118
|
+
```
|
|
119
|
+
|
|
120
|
+
## Testing Utilities
|
|
121
|
+
|
|
122
|
+
Comprehensive testing setup with testcontainers support:
|
|
123
|
+
|
|
124
|
+
- **Vitest Configuration**: Pre-configured vitest setup without globals
|
|
125
|
+
- **Testcontainers**: Redis and Vault containers for integration testing
|
|
126
|
+
- **Real Service Testing**: Test utilities that avoid mocking in favor of real services
|