@pantoia/auth-client 0.1.1 → 0.1.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.
package/README.md CHANGED
@@ -55,7 +55,7 @@ await auth.fetch("/v1/auth/login", { method: "POST", body: { email, password },
55
55
  - 쿠키를 포함해서 보낸다.
56
56
  - `body`가 객체면 JSON으로 보내고, `FormData`, `Blob`, `URLSearchParams`, 문자열은 그대로 보낸다.
57
57
  - 실패 응답은 `ApiError`로, 서버에 닿지 못하면 `NetworkError`로 던진다. `signal`로 중단하면 `AbortError`를 그대로 던진다.
58
- - `ApiError`에는 `status`, `code`, `message`(응답의 `detail`), `errors`(필드 오류), `retryAfterSeconds`가 있다.
58
+ - `ApiError`에는 `status`, `code`, `message`(응답의 `detail`), `errors`(필드 오류), `retryAfterSeconds`, `data`(응답의 `data`, 타입은 `unknown`)가 있다. `data`의 모양은 오류 코드마다 다르고, 쓰는 앱이 코드를 보고 확인해서 쓴다.
59
59
  - 로그인이 필요 없는 API는 `auth: false`로 부른다. 재발급을 기다리지 않고, 401이어도 재발급하지 않는다.
60
60
 
61
61
  ## 재발급
package/dist/problem.d.ts CHANGED
@@ -8,7 +8,8 @@ export declare class ApiError extends Error {
8
8
  readonly code: string | undefined;
9
9
  readonly errors: FieldViolation[];
10
10
  readonly retryAfterSeconds: number | undefined;
11
- constructor(status: number, code: string | undefined, detail: string | undefined, errors: FieldViolation[], retryAfterSeconds: number | undefined);
11
+ readonly data: unknown;
12
+ constructor(status: number, code: string | undefined, detail: string | undefined, errors: FieldViolation[], retryAfterSeconds: number | undefined, data?: unknown);
12
13
  }
13
14
  export declare class NetworkError extends Error {
14
15
  constructor();
package/dist/problem.js CHANGED
@@ -3,13 +3,15 @@ export class ApiError extends Error {
3
3
  code;
4
4
  errors;
5
5
  retryAfterSeconds;
6
- constructor(status, code, detail, errors, retryAfterSeconds) {
6
+ data;
7
+ constructor(status, code, detail, errors, retryAfterSeconds, data) {
7
8
  super(detail ?? "");
8
9
  this.name = "ApiError";
9
10
  this.status = status;
10
11
  this.code = code;
11
12
  this.errors = errors;
12
13
  this.retryAfterSeconds = retryAfterSeconds;
14
+ this.data = data;
13
15
  }
14
16
  }
15
17
  export class NetworkError extends Error {
@@ -43,5 +45,5 @@ export async function readProblem(response) {
43
45
  const code = typeof body.code === "string" ? body.code : undefined;
44
46
  const detail = typeof body.detail === "string" ? body.detail : undefined;
45
47
  const errors = Array.isArray(body.errors) ? body.errors.filter(isViolation) : [];
46
- return new ApiError(response.status, code, detail, errors, readRetryAfter(response));
48
+ return new ApiError(response.status, code, detail, errors, readRetryAfter(response), body.data);
47
49
  }
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@pantoia/auth-client",
3
- "version": "0.1.1",
3
+ "version": "0.1.2",
4
4
  "description": "쿠키 인증 API 클라이언트. 토큰 재발급, 내 정보, 권한 확인, 로그아웃",
5
5
  "repository": {
6
6
  "type": "git",