@devorash/core 0.1.0 → 0.1.1
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 +26 -32
- package/dist/constants/index.d.ts +1 -1
- package/dist/constants/index.js +1 -1
- package/package.json +1 -1
package/README.md
CHANGED
|
@@ -41,14 +41,9 @@ console.log(DEVORA_ENDPOINTS.TERMINATE) // "/impersonate/:id/terminate"
|
|
|
41
41
|
### Security Utilities
|
|
42
42
|
|
|
43
43
|
```typescript
|
|
44
|
-
import {
|
|
45
|
-
validateTimestamp,
|
|
46
|
-
extractSecurityHeaders,
|
|
47
|
-
timingSafeEqual,
|
|
48
|
-
isWriteMethod,
|
|
49
|
-
} from "@devorash/core"
|
|
44
|
+
import { validateTimestamp, isWriteMethod } from "@devorash/core"
|
|
50
45
|
|
|
51
|
-
// Validate request timestamp
|
|
46
|
+
// Validate a request timestamp (Unix seconds) against a tolerance (default 300 s)
|
|
52
47
|
const { valid, error } = validateTimestamp(requestTimestamp)
|
|
53
48
|
|
|
54
49
|
// Check if HTTP method is a write operation (blocked in read-only mode)
|
|
@@ -57,6 +52,11 @@ if (isWriteMethod("POST")) {
|
|
|
57
52
|
}
|
|
58
53
|
```
|
|
59
54
|
|
|
55
|
+
Request signing (v3) helpers such as `buildCanonicalString`,
|
|
56
|
+
`parseSignatureHeaders` and `SIGNED_HEADER_PATTERNS` are exported too; see
|
|
57
|
+
[SIGNING.md](https://github.com/getdevora/devora-sdks/blob/main/SIGNING.md).
|
|
58
|
+
`@devorash/node` builds on them to sign and verify requests.
|
|
59
|
+
|
|
60
60
|
### Utility Functions
|
|
61
61
|
|
|
62
62
|
```typescript
|
|
@@ -76,16 +76,16 @@ console.log(params) // { id: "user123" }
|
|
|
76
76
|
const success = createSuccessResponse({ users: [] })
|
|
77
77
|
const error = createErrorResponse("Not found", "NOT_FOUND")
|
|
78
78
|
|
|
79
|
-
//
|
|
79
|
+
// Check the shape of a public key ID
|
|
80
80
|
const validation = validateApiKeyFormat("pk_server_live_abc123")
|
|
81
|
-
console.log(validation) // { valid: true, type: "server"
|
|
81
|
+
console.log(validation) // { valid: true, type: "server" }
|
|
82
82
|
```
|
|
83
83
|
|
|
84
84
|
## Exports
|
|
85
85
|
|
|
86
86
|
### Subpath Exports
|
|
87
87
|
|
|
88
|
-
|
|
88
|
+
Besides the root export, types and constants have their own entry points:
|
|
89
89
|
|
|
90
90
|
```typescript
|
|
91
91
|
// Import only types
|
|
@@ -93,12 +93,6 @@ import type { DevoraRequest } from "@devorash/core/types"
|
|
|
93
93
|
|
|
94
94
|
// Import only constants
|
|
95
95
|
import { DEVORA_ENDPOINTS } from "@devorash/core/constants"
|
|
96
|
-
|
|
97
|
-
// Import only security utilities
|
|
98
|
-
import { validateTimestamp } from "@devorash/core/security"
|
|
99
|
-
|
|
100
|
-
// Import only utility functions
|
|
101
|
-
import { matchPath } from "@devorash/core/utils"
|
|
102
96
|
```
|
|
103
97
|
|
|
104
98
|
## API Reference
|
|
@@ -128,13 +122,12 @@ import { matchPath } from "@devorash/core/utils"
|
|
|
128
122
|
|
|
129
123
|
### Security Functions
|
|
130
124
|
|
|
131
|
-
| Function
|
|
132
|
-
|
|
|
133
|
-
| `validateTimestamp()`
|
|
134
|
-
| `
|
|
135
|
-
| `
|
|
136
|
-
| `
|
|
137
|
-
| `isWriteMethod()` | Check if method is a write operation |
|
|
125
|
+
| Function | Description |
|
|
126
|
+
| -------------------------- | -------------------------------------------------- |
|
|
127
|
+
| `validateTimestamp()` | Validate a request timestamp against a tolerance |
|
|
128
|
+
| `parseSignatureHeaders()` | Parse and validate the v3 signature headers |
|
|
129
|
+
| `buildCanonicalString()` | Build the v3 canonical string that is signed |
|
|
130
|
+
| `isWriteMethod()` | Check if method is a write operation |
|
|
138
131
|
|
|
139
132
|
### Utility Functions
|
|
140
133
|
|
|
@@ -143,7 +136,7 @@ import { matchPath } from "@devorash/core/utils"
|
|
|
143
136
|
| `matchPath()` | Match path pattern with parameters |
|
|
144
137
|
| `createSuccessResponse()` | Create success response |
|
|
145
138
|
| `createErrorResponse()` | Create error response |
|
|
146
|
-
| `validateApiKeyFormat()` |
|
|
139
|
+
| `validateApiKeyFormat()` | Check the shape of a public key ID |
|
|
147
140
|
|
|
148
141
|
### Logger Service
|
|
149
142
|
|
|
@@ -157,30 +150,31 @@ configureLogger({
|
|
|
157
150
|
level: LogLevel.DEBUG, // DEBUG, INFO, WARN, ERROR, SILENT
|
|
158
151
|
enabled: true, // Override auto-detection
|
|
159
152
|
includeTimestamp: true, // Add timestamps to log messages
|
|
153
|
+
// handler: { debug, info, warn, error } routes output to your own logger
|
|
160
154
|
})
|
|
161
155
|
|
|
162
156
|
// Create a logger instance
|
|
163
157
|
const logger = createLogger("MyComponent")
|
|
164
158
|
|
|
165
|
-
logger.debug("Verbose debugging info") // Only
|
|
159
|
+
logger.debug("Verbose debugging info") // Only if level <= DEBUG
|
|
166
160
|
logger.info("General information") // Only if level <= INFO
|
|
167
161
|
logger.warn("Warning message") // Only if level <= WARN
|
|
168
|
-
logger.error("Error message") //
|
|
162
|
+
logger.error("Error message") // Logged at every level unless enabled: false
|
|
169
163
|
```
|
|
170
164
|
|
|
171
165
|
**Environment Auto-Detection:**
|
|
172
166
|
|
|
173
|
-
- Development: `NODE_ENV=development` or
|
|
174
|
-
- Production: All other cases (logging disabled by default)
|
|
167
|
+
- Development: `NODE_ENV=development` (or `dev`), or a browser page on `localhost`, `127.0.0.1` or `*.local`
|
|
168
|
+
- Production: All other cases (logging disabled by default, except errors)
|
|
175
169
|
|
|
176
170
|
**Log Levels:**
|
|
177
171
|
| Level | Value | Description |
|
|
178
172
|
|-------|-------|-------------|
|
|
179
|
-
| `DEBUG` | 0 | Verbose debugging (dev
|
|
173
|
+
| `DEBUG` | 0 | Verbose debugging (default in dev) |
|
|
180
174
|
| `INFO` | 1 | General information |
|
|
181
|
-
| `WARN` | 2 | Warnings (default in
|
|
182
|
-
| `ERROR` | 3 | Errors only
|
|
183
|
-
| `SILENT` | 4 |
|
|
175
|
+
| `WARN` | 2 | Warnings (default level in prod) |
|
|
176
|
+
| `ERROR` | 3 | Errors only |
|
|
177
|
+
| `SILENT` | 4 | Nothing except `error()`; `enabled: false` silences errors too |
|
|
184
178
|
|
|
185
179
|
## License
|
|
186
180
|
|
package/dist/constants/index.js
CHANGED
|
@@ -181,7 +181,7 @@ export const SDK_PACKAGES = {
|
|
|
181
181
|
/**
|
|
182
182
|
* Current SDK version (synced across all packages)
|
|
183
183
|
*/
|
|
184
|
-
export const SDK_VERSION = "0.1.
|
|
184
|
+
export const SDK_VERSION = "0.1.1";
|
|
185
185
|
// ============================================================================
|
|
186
186
|
// Error Codes
|
|
187
187
|
// ============================================================================
|