orizu 0.0.8 → 0.1.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/dist/credentials.js +10 -2
- package/dist/error-response.js +20 -0
- package/dist/index.js +324 -38
- package/dist/task-create-error.js +60 -0
- package/package.json +1 -1
- package/src/credentials.ts +11 -2
- package/src/error-response.ts +27 -0
- package/src/index.ts +469 -44
- package/src/task-create-error.ts +115 -0
package/src/credentials.ts
CHANGED
|
@@ -82,7 +82,15 @@ export function loadCredentialsConfig(): StoredCredentialsV2 | null {
|
|
|
82
82
|
}
|
|
83
83
|
|
|
84
84
|
const raw = readFileSync(path, 'utf-8')
|
|
85
|
-
|
|
85
|
+
|
|
86
|
+
let parsed: unknown
|
|
87
|
+
try {
|
|
88
|
+
parsed = JSON.parse(raw)
|
|
89
|
+
} catch {
|
|
90
|
+
console.warn('Warning: credentials file contains invalid JSON — please re-login with `orizu login`')
|
|
91
|
+
return null
|
|
92
|
+
}
|
|
93
|
+
|
|
86
94
|
if (isStoredCredentialsV2(parsed)) {
|
|
87
95
|
return parsed
|
|
88
96
|
}
|
|
@@ -91,7 +99,8 @@ export function loadCredentialsConfig(): StoredCredentialsV2 | null {
|
|
|
91
99
|
return migrateToV2(parsed)
|
|
92
100
|
}
|
|
93
101
|
|
|
94
|
-
|
|
102
|
+
console.warn('Warning: credentials file has unrecognized format — please re-login with `orizu login`')
|
|
103
|
+
return null
|
|
95
104
|
}
|
|
96
105
|
|
|
97
106
|
export function getServerCredentials(baseUrl: string): ServerCredentials | null {
|
|
@@ -0,0 +1,27 @@
|
|
|
1
|
+
interface ErrorResponsePayload {
|
|
2
|
+
error?: string
|
|
3
|
+
}
|
|
4
|
+
|
|
5
|
+
export async function extractErrorMessage(response: Response): Promise<string> {
|
|
6
|
+
const contentType = response.headers.get('content-type') || ''
|
|
7
|
+
const rawBody = await response.text()
|
|
8
|
+
|
|
9
|
+
if (contentType.includes('application/json')) {
|
|
10
|
+
try {
|
|
11
|
+
const payload = JSON.parse(rawBody) as ErrorResponsePayload | null
|
|
12
|
+
if (
|
|
13
|
+
payload &&
|
|
14
|
+
typeof payload === 'object' &&
|
|
15
|
+
!Array.isArray(payload) &&
|
|
16
|
+
typeof payload.error === 'string' &&
|
|
17
|
+
payload.error.length > 0
|
|
18
|
+
) {
|
|
19
|
+
return payload.error
|
|
20
|
+
}
|
|
21
|
+
} catch {
|
|
22
|
+
// Fall through to raw body
|
|
23
|
+
}
|
|
24
|
+
}
|
|
25
|
+
|
|
26
|
+
return rawBody
|
|
27
|
+
}
|