@work-shape/catalyst-api-client 0.8.0-rc.17 → 0.8.0-rc.18
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/index.d.ts +9 -1
- package/dist/index.js +45 -16
- package/package.json +2 -2
package/dist/index.d.ts
CHANGED
|
@@ -100,6 +100,12 @@ declare function signOut(apiBaseUrl: string): Promise<void>;
|
|
|
100
100
|
*/
|
|
101
101
|
declare class ApiError extends Error {
|
|
102
102
|
readonly status: number;
|
|
103
|
+
/** Response location and category only; never response contents or URL credentials. */
|
|
104
|
+
responseInfo?: {
|
|
105
|
+
url: string;
|
|
106
|
+
contentType: string;
|
|
107
|
+
body: string;
|
|
108
|
+
};
|
|
103
109
|
readonly code?: ApiErrorCode;
|
|
104
110
|
readonly payload: unknown;
|
|
105
111
|
readonly correlationId?: string;
|
|
@@ -123,6 +129,8 @@ declare class ApiResponseShapeError extends ApiError {
|
|
|
123
129
|
readonly paths: readonly string[];
|
|
124
130
|
constructor(status: number, cause: z.ZodError);
|
|
125
131
|
}
|
|
132
|
+
/** Add diagnostics without retaining the response text, query parameters or credentials. */
|
|
133
|
+
declare function describeResponse(error: unknown, response: Response, url: string, text: string): unknown;
|
|
126
134
|
|
|
127
135
|
interface ApiClientOptions {
|
|
128
136
|
baseUrl: string;
|
|
@@ -296,4 +304,4 @@ declare function listAll<Item>(readPage: (paging: {
|
|
|
296
304
|
nextCursor?: string;
|
|
297
305
|
}>): Promise<Item[]>;
|
|
298
306
|
|
|
299
|
-
export { AUTH_MOUNT_PATH, type ApiClient, type ApiClientFor, type ApiClientOptions, ApiError, type ApiOperationMethods, ApiResponseShapeError, type AuthResult, type AuthSession, type OperationInput, type OperationOutcome, type SecondFactorKind, type SignInResult, type TwoFactorSetup, completedOutput, createApiClient, createApiClientFor, forgetTrustedBrowsers, getAuthSession, listAll, refusalError, regenerateBackupCodes, signInForSessionFetch, signInWithEmail, signOut, startTwoFactorSetup, transportError, turnOffTwoFactor, unreadableResponseError, verifySecondFactor };
|
|
307
|
+
export { AUTH_MOUNT_PATH, type ApiClient, type ApiClientFor, type ApiClientOptions, ApiError, type ApiOperationMethods, ApiResponseShapeError, type AuthResult, type AuthSession, type OperationInput, type OperationOutcome, type SecondFactorKind, type SignInResult, type TwoFactorSetup, completedOutput, createApiClient, createApiClientFor, describeResponse, forgetTrustedBrowsers, getAuthSession, listAll, refusalError, regenerateBackupCodes, signInForSessionFetch, signInWithEmail, signOut, startTwoFactorSetup, transportError, turnOffTwoFactor, unreadableResponseError, verifySecondFactor };
|
package/dist/index.js
CHANGED
|
@@ -140,6 +140,8 @@ import {
|
|
|
140
140
|
import { z as z2 } from "zod";
|
|
141
141
|
var ApiError = class extends Error {
|
|
142
142
|
status;
|
|
143
|
+
/** Response location and category only; never response contents or URL credentials. */
|
|
144
|
+
responseInfo;
|
|
143
145
|
code;
|
|
144
146
|
payload;
|
|
145
147
|
correlationId;
|
|
@@ -207,6 +209,28 @@ function readRetryAfterSeconds(payload) {
|
|
|
207
209
|
const parsed = z2.object({ error: z2.object({ details: rateLimitedDetailsSchema }) }).safeParse(payload);
|
|
208
210
|
return parsed.success ? parsed.data.error.details.retryAfterSeconds : void 0;
|
|
209
211
|
}
|
|
212
|
+
function describeResponse(error, response, url, text) {
|
|
213
|
+
if (!(error instanceof ApiError)) return error;
|
|
214
|
+
const address = new URL(response.url || url);
|
|
215
|
+
address.username = "";
|
|
216
|
+
address.password = "";
|
|
217
|
+
address.search = "";
|
|
218
|
+
address.hash = "";
|
|
219
|
+
const mediaType = response.headers.get("content-type")?.split(";")[0]?.trim();
|
|
220
|
+
const contentType = mediaType && /^[a-z0-9.+-]+\/[a-z0-9.+-]+$/iu.test(mediaType) ? mediaType : "unknown content type";
|
|
221
|
+
let body = "non-JSON text";
|
|
222
|
+
if (contentType === "text/html" || /^\s*(?:<!doctype html|<html)(?:\s|>)/iu.test(text)) {
|
|
223
|
+
body = "an HTML page instead of API JSON";
|
|
224
|
+
} else {
|
|
225
|
+
try {
|
|
226
|
+
JSON.parse(text);
|
|
227
|
+
body = "other JSON that does not match the API contract";
|
|
228
|
+
} catch {
|
|
229
|
+
}
|
|
230
|
+
}
|
|
231
|
+
error.responseInfo = { url: address.toString(), contentType, body };
|
|
232
|
+
return error;
|
|
233
|
+
}
|
|
210
234
|
|
|
211
235
|
// src/client.ts
|
|
212
236
|
import {
|
|
@@ -404,23 +428,27 @@ function callOperation(transport, operation, request) {
|
|
|
404
428
|
return void 0;
|
|
405
429
|
}
|
|
406
430
|
const text = await readBody(() => answer.text(), request);
|
|
407
|
-
|
|
408
|
-
|
|
431
|
+
try {
|
|
432
|
+
if (!accepted) {
|
|
433
|
+
return parseJson(transport, text, response.schema, answer.status);
|
|
434
|
+
}
|
|
435
|
+
const outcome = {
|
|
436
|
+
operationRunId: answer.headers.get("operation-run-id") ?? void 0,
|
|
437
|
+
replayed: answer.headers.get("idempotent-replayed") === "true"
|
|
438
|
+
};
|
|
439
|
+
return answer.status === 202 ? {
|
|
440
|
+
...outcome,
|
|
441
|
+
status: "pending_approval",
|
|
442
|
+
run: parseJson(transport, text, accepted, answer.status),
|
|
443
|
+
location: answer.headers.get("location") ?? void 0
|
|
444
|
+
} : {
|
|
445
|
+
...outcome,
|
|
446
|
+
status: "done",
|
|
447
|
+
output: parseJson(transport, text, response.schema, answer.status)
|
|
448
|
+
};
|
|
449
|
+
} catch (error) {
|
|
450
|
+
throw describeResponse(error, answer, transport.urlFor(operation, request), text);
|
|
409
451
|
}
|
|
410
|
-
const outcome = {
|
|
411
|
-
operationRunId: answer.headers.get("operation-run-id") ?? void 0,
|
|
412
|
-
replayed: answer.headers.get("idempotent-replayed") === "true"
|
|
413
|
-
};
|
|
414
|
-
return answer.status === 202 ? {
|
|
415
|
-
...outcome,
|
|
416
|
-
status: "pending_approval",
|
|
417
|
-
run: parseJson(transport, text, accepted, answer.status),
|
|
418
|
-
location: answer.headers.get("location") ?? void 0
|
|
419
|
-
} : {
|
|
420
|
-
...outcome,
|
|
421
|
-
status: "done",
|
|
422
|
-
output: parseJson(transport, text, response.schema, answer.status)
|
|
423
|
-
};
|
|
424
452
|
});
|
|
425
453
|
}
|
|
426
454
|
async function* streamEvents(transport, operation, response, request) {
|
|
@@ -495,6 +523,7 @@ export {
|
|
|
495
523
|
completedOutput,
|
|
496
524
|
createApiClient,
|
|
497
525
|
createApiClientFor,
|
|
526
|
+
describeResponse,
|
|
498
527
|
forgetTrustedBrowsers,
|
|
499
528
|
getAuthSession,
|
|
500
529
|
listAll,
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@work-shape/catalyst-api-client",
|
|
3
|
-
"version": "0.8.0-rc.
|
|
3
|
+
"version": "0.8.0-rc.18",
|
|
4
4
|
"license": "MIT",
|
|
5
5
|
"repository": {
|
|
6
6
|
"type": "git",
|
|
@@ -29,7 +29,7 @@
|
|
|
29
29
|
},
|
|
30
30
|
"dependencies": {
|
|
31
31
|
"zod": "4.4.3",
|
|
32
|
-
"@work-shape/catalyst-api-contract": "0.8.0-rc.
|
|
32
|
+
"@work-shape/catalyst-api-contract": "0.8.0-rc.18"
|
|
33
33
|
},
|
|
34
34
|
"devDependencies": {
|
|
35
35
|
"@types/node": "^24.13.1",
|