@ipetsadmin/api-client 1.1.0 → 1.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/CHANGELOG.md CHANGED
@@ -19,6 +19,34 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0
19
19
 
20
20
  ### Security
21
21
 
22
+ ## [1.1.2] - 2026-04-25
23
+
24
+ ### Added
25
+
26
+ - **User profile** ([`src/endpoints/user.ts`](./src/endpoints/user.ts)):
27
+ - **`getUserProfile`** — `GET /api/v1/users/me/profile` — `IApiResponse<UserProfileResponse>`; requires **Bearer** `accessToken` (same pattern as **`getMe`**).
28
+ - **`patchUserProfile`** — `PATCH /api/v1/users/me/profile` — body **`PatchUserProfileInput`** (no **`avatar`**); **Bearer** `accessToken`.
29
+ - **`createApiClient`** exposes a **`users`** namespace: **`getProfile(accessToken)`** and **`patchProfile(accessToken, body)`** (delegates to the helpers above) — see [`src/create-api-client.ts`](./src/create-api-client.ts).
30
+ - Re-exports **`UserProfileResponse`** and **`PatchUserProfileInput`** from `@ipetsadmin/contracts` (barrel [`src/index.ts`](./src/index.ts)).
31
+
32
+ ### Changed
33
+
34
+ - **Peer dependency** on **`@ipetsadmin/contracts`** is now **≥ 1.1.9** (types for profile DTOs). Dev dependency aligned for local development.
35
+
36
+ ## [1.1.1] - 2026-04-25
37
+
38
+ ### Added
39
+
40
+ - **`HttpPatch`** and **`HttpClient.patch`** for JSON bodies (Axios-compatible), used by email verification.
41
+ - **`patchVerifyEmail`** — `PATCH /api/v1/auth/verify-email` (`VerifyEmailRequest` from `@ipetsadmin/contracts`). Exposed as **`api.auth.verifyEmail`** and as a named export.
42
+ - **`fetchHealthCheck`** (`src/endpoints/health-check.ts`) — `GET /api/v1/health-check` returning **`IApiResponse<HealthCheck>`**.
43
+ - **`createApiClient`** exposes **`healthCheck()`** delegating to **`fetchHealthCheck`**.
44
+
45
+ ### Changed
46
+
47
+ - **`HttpClient`** now requires **`patch`** in addition to **`get`** and **`post`** (breaking for custom HTTP adapters that only implemented **`get`** / **`post`**).
48
+ - **Dev dependency** on **`@ipetsadmin/contracts`** raised to **1.1.7** for typings (`VerifyEmailRequest`, etc.). **Peer dependency** remains **`>= 1.1.1`**; use a contracts version that includes **`VerifyEmailRequest`** if you call **`patchVerifyEmail`**.
49
+
22
50
  ## [1.1.0] - 2026-04-04
23
51
 
24
52
  ### Added
package/README.md CHANGED
@@ -5,7 +5,7 @@ Typed HTTP client for the Truffa API. Consumed by web and mobile apps. **No bake
5
5
  ## Requirements
6
6
 
7
7
  - **Node.js** ≥ 18.18
8
- - **Peer dependency:** `@ipetsadmin/contracts` **≥ 1.1.0** (auth types and shared envelopes)
8
+ - **Peer dependency:** `@ipetsadmin/contracts` **≥ 1.1.9** (auth and user types: `VerifyEmailRequest`, `UserProfileResponse`, `PatchUserProfileInput`, `IApiResponse`, etc.). Use a contracts version that includes any DTO you call.
9
9
 
10
10
  ## Installation
11
11
 
@@ -17,28 +17,43 @@ npm install @ipetsadmin/api-client @ipetsadmin/contracts
17
17
 
18
18
  ## What ships today
19
19
 
20
- | Export | Description |
21
- | -------------------------------------- | ------------------------------------------------------------------------------------------------------------------------------------------------- |
22
- | `createApiClient(options)` | Factory returning `healthCheck` + **`auth`** namespace |
23
- | `ApiClient` / `CreateApiClientOptions` | Typed client and `{ http: HttpClient }` options |
24
- | `HttpClient` | **`get`** and **`post`** (minimal surface compatible with Axios) |
25
- | `HttpGet` / `HttpPost` | Method signatures |
26
- | Named auth helpers | `postRegister`, `postLogin`, `getGoogleOAuthStart`, `postGoogleOAuthCallback`, `postRefresh`, `postLogout`, `getMe` (see `src/endpoints/auth.ts`) |
27
-
28
- ### Endpoints implemented
29
-
30
- | HTTP | Path | Client |
31
- | ------ | ------------------------------------------------- | ------------------------------------------------------------------------------------------ |
32
- | `GET` | `/api/v1/health-check` | `client.healthCheck()` |
33
- | `POST` | `/api/v1/auth/register` | `client.auth.register(body)` or `postRegister(http, body)` |
34
- | `POST` | `/api/v1/auth/login` | `client.auth.login(body)` or `postLogin(http, body)` |
35
- | `GET` | `/api/v1/auth/oauth/google/start?redirectUri=...` | `client.auth.getGoogleOAuthStart(redirectUri)` or `getGoogleOAuthStart(http, redirectUri)` |
36
- | `POST` | `/api/v1/auth/oauth/google/callback` | `client.auth.postGoogleOAuthCallback(body)` or `postGoogleOAuthCallback(http, body)` |
37
- | `POST` | `/api/v1/auth/refresh` | `client.auth.refresh(body)` or `postRefresh(http, body)` |
38
- | `POST` | `/api/v1/auth/logout` | `client.auth.logout(body)` or `postLogout(http, body)` |
39
- | `GET` | `/api/v1/auth/me` | `client.auth.me(accessToken)` or `getMe(http, accessToken)` |
40
-
41
- Responses follow **`IApiResponse<T>`** from contracts (`success`, `data`, etc.). Auth session payloads are **`AuthSessionResponse`** (`TokenPair` + `user`). **`logout`** returns **204** with no JSON body.
20
+ | Export | Description |
21
+ | -------------------------------------- | ---------------------------------------------------------------------------------------------------------------------------------------------------------------- |
22
+ | `createApiClient(options)` | Factory returning **`healthCheck`**, **`auth`**, and **`users`** (profile) namespaces |
23
+ | `ApiClient` / `CreateApiClientOptions` | Typed client and `{ http: HttpClient }` options |
24
+ | `HttpClient` | **`get`**, **`post`**, and **`patch`** (minimal surface compatible with Axios) |
25
+ | `HttpGet` / `HttpPost` / `HttpPatch` | Method signatures |
26
+ | Named helpers | Same calls as the factory — see [`auth.ts`](./src/endpoints/auth.ts), [`health-check.ts`](./src/endpoints/health-check.ts), [`user.ts`](./src/endpoints/user.ts) |
27
+
28
+ ### Parity with `@ipetsadmin/api-main`
29
+
30
+ The API surfaces below are covered by this client (see `api-main` `server.ts` and route modules under `routes/`):
31
+
32
+ | Area | Server routes this client implements |
33
+ | ---------- | ------------------------------------------------------------------------------ |
34
+ | **Health** | `GET /api/v1/health-check` |
35
+ | **Auth** | Routes under `/api/v1/auth/…` |
36
+ | **Users** | `GET` / `PATCH` `/api/v1/users/me/profile` (`client.users.…` or named helpers) |
37
+
38
+ `api-main` also serves **OpenAPI** (`/api-docs`, `/api-docs.json`) when enabled; that is not wrapped here.
39
+
40
+ ### Endpoints
41
+
42
+ | HTTP | Path | `createApiClient` | Named helper |
43
+ | ------- | ------------------------------------------------- | ---------------------------------------------- | ------------------------------------------- |
44
+ | `GET` | `/api/v1/health-check` | `client.healthCheck()` | `fetchHealthCheck(http)` |
45
+ | `POST` | `/api/v1/auth/register` | `client.auth.register(body)` | `postRegister(http, body)` |
46
+ | `POST` | `/api/v1/auth/login` | `client.auth.login(body)` | `postLogin(http, body)` |
47
+ | `GET` | `/api/v1/auth/oauth/google/start?redirectUri=...` | `client.auth.getGoogleOAuthStart(redirectUri)` | `getGoogleOAuthStart(http, redirectUri)` |
48
+ | `POST` | `/api/v1/auth/oauth/google/callback` | `client.auth.postGoogleOAuthCallback(body)` | `postGoogleOAuthCallback(http, body)` |
49
+ | `POST` | `/api/v1/auth/refresh` | `client.auth.refresh(body)` | `postRefresh(http, body)` |
50
+ | `POST` | `/api/v1/auth/logout` | `client.auth.logout(body)` | `postLogout(http, body)` |
51
+ | `PATCH` | `/api/v1/auth/verify-email` | `client.auth.verifyEmail(body)` | `patchVerifyEmail(http, body)` |
52
+ | `GET` | `/api/v1/auth/me` | `client.auth.me(accessToken)` | `getMe(http, accessToken)` |
53
+ | `GET` | `/api/v1/users/me/profile` | `client.users.getProfile(accessToken)` | `getUserProfile(http, accessToken)` |
54
+ | `PATCH` | `/api/v1/users/me/profile` | `client.users.patchProfile(accessToken, body)` | `patchUserProfile(http, accessToken, body)` |
55
+
56
+ Responses use **`IApiResponse<T>`** from contracts (`success`, `data`, etc.). Auth session payloads are **`AuthSessionResponse`** (`TokenPair` + `user`). **`logout`** returns **204** with no JSON body. **`verifyEmail`** success envelope matches the server (typically `data` may be empty). **User profile** responses use **`IApiResponse<UserProfileResponse>`**; **PATCH** must not send **`avatar`** (API rejects it).
42
57
 
43
58
  ### Usage example (Axios)
44
59
 
@@ -58,16 +73,36 @@ const api = createApiClient({ http });
58
73
 
59
74
  const health = await api.healthCheck();
60
75
  const session = await api.auth.login({ email: 'user@example.com', password: '********' });
61
- // session.data — IApiResponse<AuthSessionResponse>; use session.data?.data for the inner payload when using Axios default response shape
76
+ // session — IApiResponse<AuthSessionResponse>; with Axios, the HTTP body is axiosResponse.data
62
77
  ```
63
78
 
64
- Axios returns `{ data: body }` where `body` is the full JSON from the server. For `IApiResponse<AuthSessionResponse>`, the **envelope** is in `response.data`; the **`AuthSessionResponse`** is typically `response.data.data` (depending on your typings).
79
+ For **`IApiResponse<AuthSessionResponse>`**, the **envelope** is the JSON body; the **`AuthSessionResponse`** is usually **`response.data.data`** (outer `data` = Axios, inner `data` = API payload), depending on typings.
65
80
 
66
81
  ### OAuth (mobile / web)
67
82
 
68
83
  1. Call **`getGoogleOAuthStart`** with the same **`redirectUri`** you registered in Auth0 and in the API’s `OAUTH_ALLOWED_REDIRECT_URIS`.
69
84
  2. Open **`authorizationUrl`** in a browser / `ASWebAuthenticationSession`.
70
- 3. After redirect, **`POST`** the **`code`**, **`state`**, and **`redirectUri`** to **`postGoogleOAuthCallback`**.
85
+ 3. After redirect, send **`code`**, **`state`**, and **`redirectUri`** with **`postGoogleOAuthCallback`**.
86
+
87
+ ### Email verification
88
+
89
+ Call **`api.auth.verifyEmail({ token })`** (or **`patchVerifyEmail`**) with the one-time token from the verification link your backend emails. Shapes: **`VerifyEmailRequest`** from `@ipetsadmin/contracts`.
90
+
91
+ ### User profile (authenticated)
92
+
93
+ After you have an **access** JWT (e.g. from login or register), read or update the persisted profile (**not** the same shape as lightweight **`/auth/me`** — includes **`role`**, **`isActive`**, full **`profile`** object):
94
+
95
+ ```typescript
96
+ // Via the client (same `api` as other sections):
97
+ const prof = await api.users.getProfile(accessToken);
98
+ // prof — IApiResponse<UserProfileResponse>
99
+
100
+ await api.users.patchProfile(accessToken, { firstName: 'Alex', lastName: 'Kim' });
101
+ ```
102
+
103
+ Or use the named helpers with your **`http`** instance: **`getUserProfile(http, accessToken)`**, **`patchUserProfile(http, accessToken, body)`**.
104
+
105
+ Types: **`UserProfileResponse`**, **`PatchUserProfileInput`** (re-exported from this package, defined in `@ipetsadmin/contracts`).
71
106
 
72
107
  ### Why a factory?
73
108
 
@@ -77,20 +112,20 @@ Axios returns `{ data: body }` where `body` is the full JSON from the server. Fo
77
112
 
78
113
  ## Architecture
79
114
 
80
- 1. **`HttpClient`** — abstraction over GET/POST (`{ data: T }` shape, Axios-compatible).
115
+ 1. **`HttpClient`** — abstraction over **`get` / `post` / `patch`** (`{ data: T }` response shape, Axios-compatible).
81
116
  2. **`src/endpoints/*.ts`** — thin functions: `(http, …args) => Promise<…>`.
82
- 3. **`createApiClient`** — wires `http` into endpoints.
83
- 4. **`@ipetsadmin/contracts`** — DTOs (`RegisterRequest`, `AuthSessionResponse`, …).
117
+ 3. **`createApiClient`** — wires `http` into those endpoints under **`healthCheck`**, **`auth`**, and **`users`**.
118
+ 4. **`@ipetsadmin/contracts`** — DTOs (`RegisterRequest`, `AuthSessionResponse`, `VerifyEmailRequest`, `UserProfileResponse`, `PatchUserProfileInput`, …).
84
119
 
85
120
  ### Extending further
86
121
 
87
- If you add PATCH/PUT/DELETE, extend **`HttpClient`** in `src/http-client.ts` and add endpoint modules. For request config (query params, headers), align types with your adapter (Axios uses a second `config` argument on `get`/`post`).
122
+ Add methods on **`HttpClient`** in `src/http-client.ts`, then new endpoint modules. For query params, headers, and `Authorization`, align with your adapter (Axios passes a `config` object to **`get`**, **`post`**, and **`patch`**; **`getMe`** already sets `Authorization: Bearer` for the access token argument).
88
123
 
89
124
  ---
90
125
 
91
126
  ## Testing
92
127
 
93
- Inject a fake **`HttpClient`** with **`get`** and **`post`** mocks and assert URLs and payloads.
128
+ Inject a fake **`HttpClient`** with **`get`**, **`post`**, and **`patch`** mocks and assert URLs and payloads.
94
129
 
95
130
  ```typescript
96
131
  import type { HttpClient } from '@ipetsadmin/api-client';
@@ -99,11 +134,17 @@ import { createApiClient } from '@ipetsadmin/api-client';
99
134
  const http: HttpClient = {
100
135
  get: jest.fn().mockResolvedValue({ data: { success: true, data: {} } }),
101
136
  post: jest.fn().mockResolvedValue({ data: { success: true, data: {} } }),
137
+ patch: jest.fn().mockResolvedValue({ data: { success: true } }),
102
138
  };
103
139
 
104
140
  const api = createApiClient({ http });
105
141
  await api.healthCheck();
106
142
  expect(http.get).toHaveBeenCalledWith('/api/v1/health-check', undefined);
143
+
144
+ await api.users.getProfile('token');
145
+ expect(http.get).toHaveBeenCalledWith('/api/v1/users/me/profile', {
146
+ headers: { Authorization: 'Bearer token' },
147
+ });
107
148
  ```
108
149
 
109
150
  ---
package/dist/index.d.mts CHANGED
@@ -1,4 +1,4 @@
1
- import { RegisterRequest, IApiResponse, AuthSessionResponse, LoginRequest, OAuthGoogleStartResponse, OAuthGoogleCallbackRequest, RefreshRequest, LogoutRequest, AuthUserResponse, HealthCheck } from '@ipetsadmin/contracts';
1
+ import { RegisterRequest, IApiResponse, AuthSessionResponse, LoginRequest, OAuthGoogleStartResponse, OAuthGoogleCallbackRequest, RefreshRequest, LogoutRequest, VerifyEmailRequest, AuthUserResponse, UserProfileResponse, PatchUserProfileInput, HealthCheck } from '@ipetsadmin/contracts';
2
2
 
3
3
  type HttpGet = <TResponse>(url: string, config?: unknown) => Promise<{
4
4
  data: TResponse;
@@ -6,9 +6,13 @@ type HttpGet = <TResponse>(url: string, config?: unknown) => Promise<{
6
6
  type HttpPost = <TResponse, TBody = unknown>(url: string, body?: TBody, config?: unknown) => Promise<{
7
7
  data: TResponse;
8
8
  }>;
9
+ type HttpPatch = <TResponse, TBody = unknown>(url: string, body?: TBody, config?: unknown) => Promise<{
10
+ data: TResponse;
11
+ }>;
9
12
  interface HttpClient {
10
13
  readonly get: HttpGet;
11
14
  readonly post: HttpPost;
15
+ readonly patch: HttpPatch;
12
16
  }
13
17
 
14
18
  declare function postRegister(http: HttpClient, body: RegisterRequest): Promise<IApiResponse<AuthSessionResponse>>;
@@ -18,6 +22,10 @@ declare function postGoogleOAuthCallback(http: HttpClient, body: OAuthGoogleCall
18
22
  declare function postRefresh(http: HttpClient, body: RefreshRequest): Promise<IApiResponse<AuthSessionResponse>>;
19
23
  declare function postLogout(http: HttpClient, body: LogoutRequest): Promise<void>;
20
24
  declare function getMe(http: HttpClient, accessToken: string): Promise<IApiResponse<AuthUserResponse>>;
25
+ declare function patchVerifyEmail(http: HttpClient, body: VerifyEmailRequest): Promise<IApiResponse<void>>;
26
+
27
+ declare function getUserProfile(http: HttpClient, accessToken: string): Promise<IApiResponse<UserProfileResponse>>;
28
+ declare function patchUserProfile(http: HttpClient, accessToken: string, body: PatchUserProfileInput): Promise<IApiResponse<UserProfileResponse>>;
21
29
 
22
30
  declare function fetchHealthCheck(http: HttpClient): Promise<IApiResponse<HealthCheck>>;
23
31
 
@@ -33,9 +41,14 @@ interface ApiClient {
33
41
  readonly postGoogleOAuthCallback: (body: Parameters<typeof postGoogleOAuthCallback>[1]) => ReturnType<typeof postGoogleOAuthCallback>;
34
42
  readonly refresh: (body: Parameters<typeof postRefresh>[1]) => ReturnType<typeof postRefresh>;
35
43
  readonly logout: (body: Parameters<typeof postLogout>[1]) => ReturnType<typeof postLogout>;
44
+ readonly verifyEmail: (body: Parameters<typeof patchVerifyEmail>[1]) => ReturnType<typeof patchVerifyEmail>;
36
45
  readonly me: (accessToken: string) => ReturnType<typeof getMe>;
37
46
  };
47
+ readonly users: {
48
+ readonly getProfile: (accessToken: string) => ReturnType<typeof getUserProfile>;
49
+ readonly patchProfile: (accessToken: string, body: Parameters<typeof patchUserProfile>[2]) => ReturnType<typeof patchUserProfile>;
50
+ };
38
51
  }
39
52
  declare function createApiClient(options: CreateApiClientOptions): ApiClient;
40
53
 
41
- export { type ApiClient, type CreateApiClientOptions, type HttpClient, type HttpGet, type HttpPost, createApiClient, getGoogleOAuthStart, getMe, postGoogleOAuthCallback, postLogin, postLogout, postRefresh, postRegister };
54
+ export { type ApiClient, type CreateApiClientOptions, type HttpClient, type HttpGet, type HttpPatch, type HttpPost, createApiClient, getGoogleOAuthStart, getMe, getUserProfile, patchUserProfile, patchVerifyEmail, postGoogleOAuthCallback, postLogin, postLogout, postRefresh, postRegister };
package/dist/index.d.ts CHANGED
@@ -1,4 +1,4 @@
1
- import { RegisterRequest, IApiResponse, AuthSessionResponse, LoginRequest, OAuthGoogleStartResponse, OAuthGoogleCallbackRequest, RefreshRequest, LogoutRequest, AuthUserResponse, HealthCheck } from '@ipetsadmin/contracts';
1
+ import { RegisterRequest, IApiResponse, AuthSessionResponse, LoginRequest, OAuthGoogleStartResponse, OAuthGoogleCallbackRequest, RefreshRequest, LogoutRequest, VerifyEmailRequest, AuthUserResponse, UserProfileResponse, PatchUserProfileInput, HealthCheck } from '@ipetsadmin/contracts';
2
2
 
3
3
  type HttpGet = <TResponse>(url: string, config?: unknown) => Promise<{
4
4
  data: TResponse;
@@ -6,9 +6,13 @@ type HttpGet = <TResponse>(url: string, config?: unknown) => Promise<{
6
6
  type HttpPost = <TResponse, TBody = unknown>(url: string, body?: TBody, config?: unknown) => Promise<{
7
7
  data: TResponse;
8
8
  }>;
9
+ type HttpPatch = <TResponse, TBody = unknown>(url: string, body?: TBody, config?: unknown) => Promise<{
10
+ data: TResponse;
11
+ }>;
9
12
  interface HttpClient {
10
13
  readonly get: HttpGet;
11
14
  readonly post: HttpPost;
15
+ readonly patch: HttpPatch;
12
16
  }
13
17
 
14
18
  declare function postRegister(http: HttpClient, body: RegisterRequest): Promise<IApiResponse<AuthSessionResponse>>;
@@ -18,6 +22,10 @@ declare function postGoogleOAuthCallback(http: HttpClient, body: OAuthGoogleCall
18
22
  declare function postRefresh(http: HttpClient, body: RefreshRequest): Promise<IApiResponse<AuthSessionResponse>>;
19
23
  declare function postLogout(http: HttpClient, body: LogoutRequest): Promise<void>;
20
24
  declare function getMe(http: HttpClient, accessToken: string): Promise<IApiResponse<AuthUserResponse>>;
25
+ declare function patchVerifyEmail(http: HttpClient, body: VerifyEmailRequest): Promise<IApiResponse<void>>;
26
+
27
+ declare function getUserProfile(http: HttpClient, accessToken: string): Promise<IApiResponse<UserProfileResponse>>;
28
+ declare function patchUserProfile(http: HttpClient, accessToken: string, body: PatchUserProfileInput): Promise<IApiResponse<UserProfileResponse>>;
21
29
 
22
30
  declare function fetchHealthCheck(http: HttpClient): Promise<IApiResponse<HealthCheck>>;
23
31
 
@@ -33,9 +41,14 @@ interface ApiClient {
33
41
  readonly postGoogleOAuthCallback: (body: Parameters<typeof postGoogleOAuthCallback>[1]) => ReturnType<typeof postGoogleOAuthCallback>;
34
42
  readonly refresh: (body: Parameters<typeof postRefresh>[1]) => ReturnType<typeof postRefresh>;
35
43
  readonly logout: (body: Parameters<typeof postLogout>[1]) => ReturnType<typeof postLogout>;
44
+ readonly verifyEmail: (body: Parameters<typeof patchVerifyEmail>[1]) => ReturnType<typeof patchVerifyEmail>;
36
45
  readonly me: (accessToken: string) => ReturnType<typeof getMe>;
37
46
  };
47
+ readonly users: {
48
+ readonly getProfile: (accessToken: string) => ReturnType<typeof getUserProfile>;
49
+ readonly patchProfile: (accessToken: string, body: Parameters<typeof patchUserProfile>[2]) => ReturnType<typeof patchUserProfile>;
50
+ };
38
51
  }
39
52
  declare function createApiClient(options: CreateApiClientOptions): ApiClient;
40
53
 
41
- export { type ApiClient, type CreateApiClientOptions, type HttpClient, type HttpGet, type HttpPost, createApiClient, getGoogleOAuthStart, getMe, postGoogleOAuthCallback, postLogin, postLogout, postRefresh, postRegister };
54
+ export { type ApiClient, type CreateApiClientOptions, type HttpClient, type HttpGet, type HttpPatch, type HttpPost, createApiClient, getGoogleOAuthStart, getMe, getUserProfile, patchUserProfile, patchVerifyEmail, postGoogleOAuthCallback, postLogin, postLogout, postRefresh, postRegister };
package/dist/index.js CHANGED
@@ -46,6 +46,32 @@ async function getMe(http, accessToken) {
46
46
  });
47
47
  return data;
48
48
  }
49
+ async function patchVerifyEmail(http, body) {
50
+ const { data } = await http.patch(
51
+ `${AUTH_BASE}/verify-email`,
52
+ body
53
+ );
54
+ return data;
55
+ }
56
+
57
+ // src/endpoints/user.ts
58
+ var USERS_BASE = "/api/v1/users";
59
+ async function getUserProfile(http, accessToken) {
60
+ const { data } = await http.get(`${USERS_BASE}/me/profile`, {
61
+ headers: { Authorization: `Bearer ${accessToken}` }
62
+ });
63
+ return data;
64
+ }
65
+ async function patchUserProfile(http, accessToken, body) {
66
+ const { data } = await http.patch(
67
+ `${USERS_BASE}/me/profile`,
68
+ body,
69
+ {
70
+ headers: { Authorization: `Bearer ${accessToken}` }
71
+ }
72
+ );
73
+ return data;
74
+ }
49
75
 
50
76
  // src/endpoints/health-check.ts
51
77
  var HEALTH_CHECK_PATH = "/api/v1/health-check";
@@ -66,7 +92,12 @@ function createApiClient(options) {
66
92
  postGoogleOAuthCallback: (body) => postGoogleOAuthCallback(http, body),
67
93
  refresh: (body) => postRefresh(http, body),
68
94
  logout: (body) => postLogout(http, body),
95
+ verifyEmail: (body) => patchVerifyEmail(http, body),
69
96
  me: (accessToken) => getMe(http, accessToken)
97
+ },
98
+ users: {
99
+ getProfile: (accessToken) => getUserProfile(http, accessToken),
100
+ patchProfile: (accessToken, body) => patchUserProfile(http, accessToken, body)
70
101
  }
71
102
  };
72
103
  }
@@ -74,6 +105,9 @@ function createApiClient(options) {
74
105
  exports.createApiClient = createApiClient;
75
106
  exports.getGoogleOAuthStart = getGoogleOAuthStart;
76
107
  exports.getMe = getMe;
108
+ exports.getUserProfile = getUserProfile;
109
+ exports.patchUserProfile = patchUserProfile;
110
+ exports.patchVerifyEmail = patchVerifyEmail;
77
111
  exports.postGoogleOAuthCallback = postGoogleOAuthCallback;
78
112
  exports.postLogin = postLogin;
79
113
  exports.postLogout = postLogout;
package/dist/index.js.map CHANGED
@@ -1 +1 @@
1
- {"version":3,"sources":["../src/endpoints/auth.ts","../src/endpoints/health-check.ts","../src/create-api-client.ts"],"names":[],"mappings":";;;AAcA,IAAM,SAAA,GAAY,cAAA;AAKlB,eAAsB,YAAA,CACpB,MACA,IAAA,EAC4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,\n OAuthGoogleCallbackRequest,\n OAuthGoogleStartResponse,\n RefreshRequest,\n RegisterRequest,\n} from '@ipetsadmin/contracts';\n\nimport type { HttpClient } from '../http-client';\n\nconst AUTH_BASE = '/api/v1/auth' as const;\n\n/**\n * POST /api/v1/auth/register\n */\nexport async function postRegister(\n http: HttpClient,\n body: RegisterRequest,\n): Promise<IApiResponse<AuthSessionResponse>> {\n const { data } = await http.post<IApiResponse<AuthSessionResponse>, RegisterRequest>(\n `${AUTH_BASE}/register`,\n body,\n );\n return data;\n}\n\n/**\n * POST /api/v1/auth/login\n */\nexport async function postLogin(\n http: HttpClient,\n body: LoginRequest,\n): Promise<IApiResponse<AuthSessionResponse>> {\n const { data } = await http.post<IApiResponse<AuthSessionResponse>, LoginRequest>(\n `${AUTH_BASE}/login`,\n body,\n );\n return data;\n}\n\n/**\n * GET /api/v1/auth/oauth/google/start?redirectUri=...\n */\nexport async function getGoogleOAuthStart(\n http: HttpClient,\n redirectUri: string,\n): Promise<IApiResponse<OAuthGoogleStartResponse>> {\n const q = new URLSearchParams({ redirectUri });\n const { data } = await http.get<IApiResponse<OAuthGoogleStartResponse>>(\n `${AUTH_BASE}/oauth/google/start?${q.toString()}`,\n );\n return data;\n}\n\n/**\n * POST /api/v1/auth/oauth/google/callback\n */\nexport async function postGoogleOAuthCallback(\n http: HttpClient,\n body: OAuthGoogleCallbackRequest,\n): Promise<IApiResponse<AuthSessionResponse>> {\n const { data } = await http.post<IApiResponse<AuthSessionResponse>, OAuthGoogleCallbackRequest>(\n `${AUTH_BASE}/oauth/google/callback`,\n body,\n );\n return data;\n}\n\n/**\n * POST /api/v1/auth/refresh\n */\nexport async function postRefresh(\n http: HttpClient,\n body: RefreshRequest,\n): Promise<IApiResponse<AuthSessionResponse>> {\n const { data } = await http.post<IApiResponse<AuthSessionResponse>, RefreshRequest>(\n `${AUTH_BASE}/refresh`,\n body,\n );\n return data;\n}\n\n/**\n * POST /api/v1/auth/logout — 204 No Content (no JSON body).\n */\nexport async function postLogout(http: HttpClient, body: LogoutRequest): Promise<void> {\n await http.post<undefined, LogoutRequest>(`${AUTH_BASE}/logout`, body);\n}\n\n/**\n * GET /api/v1/auth/me — requires `Authorization: Bearer <accessToken>`.\n */\nexport async function getMe(\n http: HttpClient,\n accessToken: string,\n): Promise<IApiResponse<AuthUserResponse>> {\n const { data } = await http.get<IApiResponse<AuthUserResponse>>(`${AUTH_BASE}/me`, {\n headers: { Authorization: `Bearer ${accessToken}` },\n });\n return data;\n}\n","import type { IApiResponse, HealthCheck } from '@ipetsadmin/contracts';\nimport type { HttpClient } from '../http-client';\n\n/** Same path as `/api/${v1}/health-check` on the server when `v1` is the string `'v1'`. */\nconst HEALTH_CHECK_PATH = '/api/v1/health-check' as const;\n\n/**\n * GET /api/v1/health-check — server liveness.\n *\n * Returns the full JSON the server sends (`IApiResponse<HealthCheck>`).\n *\n * **Why not `data.data` here?** Adapters like Axios wrap the HTTP body in a property also\n * called `data`. That outer `data` is the entire `res.json(...)` object. The inner\n * `IApiResponse.data` is the `HealthCheck` payload — use `.data` on the **returned** value,\n * e.g. `(await fetchHealthCheck(http)).data`.\n */\nexport async function fetchHealthCheck(http: HttpClient): Promise<IApiResponse<HealthCheck>> {\n const { data: body } = await http.get<IApiResponse<HealthCheck>>(HEALTH_CHECK_PATH);\n\n return body;\n}\n","import {\n getGoogleOAuthStart,\n getMe,\n postGoogleOAuthCallback,\n postLogin,\n postLogout,\n postRefresh,\n postRegister,\n} from './endpoints/auth';\nimport { fetchHealthCheck } from './endpoints/health-check';\nimport type { HttpClient } from './http-client';\n\nexport interface CreateApiClientOptions {\n /**\n * Preconfigured HTTP client (e.g. Axios instance with `baseURL` set).\n * Paths in this library are relative to that base (e.g. `/api/v1/...`).\n * Both `get` and `post` are required for auth flows.\n */\n readonly http: HttpClient;\n}\n\nexport interface ApiClient {\n readonly healthCheck: () => ReturnType<typeof fetchHealthCheck>;\n readonly auth: {\n readonly register: (\n body: Parameters<typeof postRegister>[1],\n ) => ReturnType<typeof postRegister>;\n readonly login: (body: Parameters<typeof postLogin>[1]) => ReturnType<typeof postLogin>;\n readonly getGoogleOAuthStart: (redirectUri: string) => ReturnType<typeof getGoogleOAuthStart>;\n readonly postGoogleOAuthCallback: (\n body: Parameters<typeof postGoogleOAuthCallback>[1],\n ) => ReturnType<typeof postGoogleOAuthCallback>;\n readonly refresh: (body: Parameters<typeof postRefresh>[1]) => ReturnType<typeof postRefresh>;\n readonly logout: (body: Parameters<typeof postLogout>[1]) => ReturnType<typeof postLogout>;\n readonly me: (accessToken: string) => ReturnType<typeof getMe>;\n };\n}\n\n/**\n * Creates a typed API client backed by the provided HTTP implementation.\n */\nexport function createApiClient(options: CreateApiClientOptions): ApiClient {\n const { http } = options;\n\n return {\n healthCheck: () => fetchHealthCheck(http),\n auth: {\n register: (body) => postRegister(http, body),\n login: (body) => postLogin(http, body),\n getGoogleOAuthStart: (redirectUri) => getGoogleOAuthStart(http, redirectUri),\n postGoogleOAuthCallback: (body) => postGoogleOAuthCallback(http, body),\n refresh: (body) => postRefresh(http, body),\n logout: (body) => postLogout(http, body),\n me: (accessToken) => getMe(http, accessToken),\n },\n };\n}\n"]}
1
+ {"version":3,"sources":["../src/endpoints/auth.ts","../src/endpoints/user.ts","../src/endpoints/health-check.ts","../src/create-api-client.ts"],"names":[],"mappings":";;;AAeA,IAAM,SAAA,GAAY,cAAA;AAKlB,eAAsB,YAAA,CACpB,MACA,IAAA,EAC4C;AAC5C,EAAA,MAAM,EAAE,IAAA,EAAK,GAAI,MAAM,IAAA,CAAK,IAAA;AAAA,IAC1B,GAAG,SAAS,CAAA,SAAA,CAAA;AAAA,IACZ;AAAA,GACF;AACA,EAAA,OAAO,IAAA;AACT;AAKA,eAAsB,SAAA,CACpB,MACA,IAAA,EAC4C;AAC5C,EAAA,MAAM,EAAE,IAAA,EAAK,GAAI,MAAM,IAAA,CAAK,IAAA;AAAA,IAC1B,GAAG,SAAS,CAAA,MAAA,CAAA;AAAA,IACZ;AAAA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A,CAAU,MAAM,IAAI,CAAA;AAAA,MACrC,mBAAA,EAAqB,CAAC,WAAA,KAAgB,mBAAA,CAAoB,MAAM,WAAW,CAAA;AAAA,MAC3E,uBAAA,EAAyB,CAAC,IAAA,KAAS,uBAAA,CAAwB,MAAM,IAAI,CAAA;AAAA,MACrE,OAAA,EAAS,CAAC,IAAA,KAAS,WAAA,CAAY,MAAM,IAAI,CAAA;AAAA,MACzC,MAAA,EAAQ,CAAC,IAAA,KAAS,UAAA,CAAW,MAAM,IAAI,CAAA;AAAA,MACvC,WAAA,EAAa,CAAC,IAAA,KAAS,gBAAA,CAAiB,MAAM,IAAI,CAAA;AAAA,MAClD,EAAA,EAAI,CAAC,WAAA,KAAgB,KAAA,CAAM,MAAM,WAAW;AAAA,KAC9C;AAAA,IACA,KAAA,EAAO;AAAA,MACL,UAAA,EAAY,CAAC,WAAA,KAAgB,cAAA,CAAe,MAAM,WAAW,CAAA;AAAA,MAC7D,cAAc,CAAC,WAAA,EAAa,SAAS,gBAAA,CAAiB,IAAA,EAAM,aAAa,IAAI;AAAA;AAC/E,GACF;AACF","file":"index.js","sourcesContent":["import type {\n AuthSessionResponse,\n AuthUserResponse,\n IApiResponse,\n LoginRequest,\n LogoutRequest,\n OAuthGoogleCallbackRequest,\n OAuthGoogleStartResponse,\n RefreshRequest,\n RegisterRequest,\n VerifyEmailRequest,\n} from '@ipetsadmin/contracts';\n\nimport type { HttpClient } from '../http-client';\n\nconst AUTH_BASE = '/api/v1/auth' as const;\n\n/**\n * POST /api/v1/auth/register\n */\nexport async function postRegister(\n http: HttpClient,\n body: RegisterRequest,\n): Promise<IApiResponse<AuthSessionResponse>> {\n const { data } = await http.post<IApiResponse<AuthSessionResponse>, RegisterRequest>(\n `${AUTH_BASE}/register`,\n body,\n );\n return data;\n}\n\n/**\n * POST /api/v1/auth/login\n */\nexport async function postLogin(\n http: HttpClient,\n body: LoginRequest,\n): Promise<IApiResponse<AuthSessionResponse>> {\n const { data } = await http.post<IApiResponse<AuthSessionResponse>, LoginRequest>(\n `${AUTH_BASE}/login`,\n body,\n );\n return data;\n}\n\n/**\n * GET /api/v1/auth/oauth/google/start?redirectUri=...\n */\nexport async function getGoogleOAuthStart(\n http: HttpClient,\n redirectUri: string,\n): Promise<IApiResponse<OAuthGoogleStartResponse>> {\n const q = new URLSearchParams({ redirectUri });\n const { data } = await http.get<IApiResponse<OAuthGoogleStartResponse>>(\n `${AUTH_BASE}/oauth/google/start?${q.toString()}`,\n );\n return data;\n}\n\n/**\n * POST /api/v1/auth/oauth/google/callback\n */\nexport async function postGoogleOAuthCallback(\n http: HttpClient,\n body: OAuthGoogleCallbackRequest,\n): Promise<IApiResponse<AuthSessionResponse>> {\n const { data } = await http.post<IApiResponse<AuthSessionResponse>, OAuthGoogleCallbackRequest>(\n `${AUTH_BASE}/oauth/google/callback`,\n body,\n );\n return data;\n}\n\n/**\n * POST /api/v1/auth/refresh\n */\nexport async function postRefresh(\n http: HttpClient,\n body: RefreshRequest,\n): Promise<IApiResponse<AuthSessionResponse>> {\n const { data } = await http.post<IApiResponse<AuthSessionResponse>, RefreshRequest>(\n `${AUTH_BASE}/refresh`,\n body,\n );\n return data;\n}\n\n/**\n * POST /api/v1/auth/logout — 204 No Content (no JSON body).\n */\nexport async function postLogout(http: HttpClient, body: LogoutRequest): Promise<void> {\n await http.post<undefined, LogoutRequest>(`${AUTH_BASE}/logout`, body);\n}\n\n/**\n * GET /api/v1/auth/me — requires `Authorization: Bearer <accessToken>`.\n */\nexport async function getMe(\n http: HttpClient,\n accessToken: string,\n): Promise<IApiResponse<AuthUserResponse>> {\n const { data } = await http.get<IApiResponse<AuthUserResponse>>(`${AUTH_BASE}/me`, {\n headers: { Authorization: `Bearer ${accessToken}` },\n });\n return data;\n}\n\n/**\n * PATCH /api/v1/auth/verify-email\n */\nexport async function patchVerifyEmail(\n http: HttpClient,\n body: VerifyEmailRequest,\n): Promise<IApiResponse<void>> {\n const { data } = await http.patch<IApiResponse<void>, VerifyEmailRequest>(\n `${AUTH_BASE}/verify-email`,\n body,\n );\n return data;\n}\n","import type {\n IApiResponse,\n PatchUserProfileInput,\n UserProfileResponse,\n} from '@ipetsadmin/contracts';\n\nimport type { HttpClient } from '../http-client';\n\nconst USERS_BASE = '/api/v1/users' as const;\n\n/**\n * GET /api/v1/users/me/profile — requires `Authorization: Bearer <accessToken>`.\n */\nexport async function getUserProfile(\n http: HttpClient,\n accessToken: string,\n): Promise<IApiResponse<UserProfileResponse>> {\n const { data } = await http.get<IApiResponse<UserProfileResponse>>(`${USERS_BASE}/me/profile`, {\n headers: { Authorization: `Bearer ${accessToken}` },\n });\n return data;\n}\n\n/**\n * PATCH /api/v1/users/me/profile — requires `Authorization: Bearer <accessToken>`.\n * Body must not include `avatar` (API rejects unknown keys in strict mode).\n */\nexport async function patchUserProfile(\n http: HttpClient,\n accessToken: string,\n body: PatchUserProfileInput,\n): Promise<IApiResponse<UserProfileResponse>> {\n const { data } = await http.patch<IApiResponse<UserProfileResponse>, PatchUserProfileInput>(\n `${USERS_BASE}/me/profile`,\n body,\n {\n headers: { Authorization: `Bearer ${accessToken}` },\n },\n );\n return data;\n}\n","import type { IApiResponse, HealthCheck } from '@ipetsadmin/contracts';\nimport type { HttpClient } from '../http-client';\n\n/** Same path as `/api/${v1}/health-check` on the server when `v1` is the string `'v1'`. */\nconst HEALTH_CHECK_PATH = '/api/v1/health-check' as const;\n\n/**\n * GET /api/v1/health-check — server liveness.\n *\n * Returns the full JSON the server sends (`IApiResponse<HealthCheck>`).\n *\n * **Why not `data.data` here?** Adapters like Axios wrap the HTTP body in a property also\n * called `data`. That outer `data` is the entire `res.json(...)` object. The inner\n * `IApiResponse.data` is the `HealthCheck` payload — use `.data` on the **returned** value,\n * e.g. `(await fetchHealthCheck(http)).data`.\n */\nexport async function fetchHealthCheck(http: HttpClient): Promise<IApiResponse<HealthCheck>> {\n const { data: body } = await http.get<IApiResponse<HealthCheck>>(HEALTH_CHECK_PATH);\n\n return body;\n}\n","import {\n getGoogleOAuthStart,\n getMe,\n patchVerifyEmail,\n postGoogleOAuthCallback,\n postLogin,\n postLogout,\n postRefresh,\n postRegister,\n} from './endpoints/auth';\nimport { getUserProfile, patchUserProfile } from './endpoints/user';\nimport { fetchHealthCheck } from './endpoints/health-check';\nimport type { HttpClient } from './http-client';\n\nexport interface CreateApiClientOptions {\n /**\n * Preconfigured HTTP client (e.g. Axios instance with `baseURL` set).\n * Paths in this library are relative to that base (e.g. `/api/v1/...`).\n * Both `get` and `post` are required for auth flows.\n */\n readonly http: HttpClient;\n}\n\nexport interface ApiClient {\n readonly healthCheck: () => ReturnType<typeof fetchHealthCheck>;\n readonly auth: {\n readonly register: (\n body: Parameters<typeof postRegister>[1],\n ) => ReturnType<typeof postRegister>;\n readonly login: (body: Parameters<typeof postLogin>[1]) => ReturnType<typeof postLogin>;\n readonly getGoogleOAuthStart: (redirectUri: string) => ReturnType<typeof getGoogleOAuthStart>;\n readonly postGoogleOAuthCallback: (\n body: Parameters<typeof postGoogleOAuthCallback>[1],\n ) => ReturnType<typeof postGoogleOAuthCallback>;\n readonly refresh: (body: Parameters<typeof postRefresh>[1]) => ReturnType<typeof postRefresh>;\n readonly logout: (body: Parameters<typeof postLogout>[1]) => ReturnType<typeof postLogout>;\n readonly verifyEmail: (\n body: Parameters<typeof patchVerifyEmail>[1],\n ) => ReturnType<typeof patchVerifyEmail>;\n readonly me: (accessToken: string) => ReturnType<typeof getMe>;\n };\n readonly users: {\n readonly getProfile: (accessToken: string) => ReturnType<typeof getUserProfile>;\n readonly patchProfile: (\n accessToken: string,\n body: Parameters<typeof patchUserProfile>[2],\n ) => ReturnType<typeof patchUserProfile>;\n };\n}\n\n/**\n * Creates a typed API client backed by the provided HTTP implementation.\n */\nexport function createApiClient(options: CreateApiClientOptions): ApiClient {\n const { http } = options;\n\n return {\n healthCheck: () => fetchHealthCheck(http),\n auth: {\n register: (body) => postRegister(http, body),\n login: (body) => postLogin(http, body),\n getGoogleOAuthStart: (redirectUri) => getGoogleOAuthStart(http, redirectUri),\n postGoogleOAuthCallback: (body) => postGoogleOAuthCallback(http, body),\n refresh: (body) => postRefresh(http, body),\n logout: (body) => postLogout(http, body),\n verifyEmail: (body) => patchVerifyEmail(http, body),\n me: (accessToken) => getMe(http, accessToken),\n },\n users: {\n getProfile: (accessToken) => getUserProfile(http, accessToken),\n patchProfile: (accessToken, body) => patchUserProfile(http, accessToken, body),\n },\n };\n}\n"]}
package/dist/index.mjs CHANGED
@@ -44,6 +44,32 @@ async function getMe(http, accessToken) {
44
44
  });
45
45
  return data;
46
46
  }
47
+ async function patchVerifyEmail(http, body) {
48
+ const { data } = await http.patch(
49
+ `${AUTH_BASE}/verify-email`,
50
+ body
51
+ );
52
+ return data;
53
+ }
54
+
55
+ // src/endpoints/user.ts
56
+ var USERS_BASE = "/api/v1/users";
57
+ async function getUserProfile(http, accessToken) {
58
+ const { data } = await http.get(`${USERS_BASE}/me/profile`, {
59
+ headers: { Authorization: `Bearer ${accessToken}` }
60
+ });
61
+ return data;
62
+ }
63
+ async function patchUserProfile(http, accessToken, body) {
64
+ const { data } = await http.patch(
65
+ `${USERS_BASE}/me/profile`,
66
+ body,
67
+ {
68
+ headers: { Authorization: `Bearer ${accessToken}` }
69
+ }
70
+ );
71
+ return data;
72
+ }
47
73
 
48
74
  // src/endpoints/health-check.ts
49
75
  var HEALTH_CHECK_PATH = "/api/v1/health-check";
@@ -64,11 +90,16 @@ function createApiClient(options) {
64
90
  postGoogleOAuthCallback: (body) => postGoogleOAuthCallback(http, body),
65
91
  refresh: (body) => postRefresh(http, body),
66
92
  logout: (body) => postLogout(http, body),
93
+ verifyEmail: (body) => patchVerifyEmail(http, body),
67
94
  me: (accessToken) => getMe(http, accessToken)
95
+ },
96
+ users: {
97
+ getProfile: (accessToken) => getUserProfile(http, accessToken),
98
+ patchProfile: (accessToken, body) => patchUserProfile(http, accessToken, body)
68
99
  }
69
100
  };
70
101
  }
71
102
 
72
- export { createApiClient, getGoogleOAuthStart, getMe, postGoogleOAuthCallback, postLogin, postLogout, postRefresh, postRegister };
103
+ export { createApiClient, getGoogleOAuthStart, getMe, getUserProfile, patchUserProfile, patchVerifyEmail, postGoogleOAuthCallback, postLogin, postLogout, postRefresh, postRegister };
73
104
  //# sourceMappingURL=index.mjs.map
74
105
  //# sourceMappingURL=index.mjs.map
@@ -1 +1 @@
1
- {"version":3,"sources":["../src/endpoints/auth.ts","../src/endpoints/health-check.ts","../src/create-api-client.ts"],"names":[],"mappings":";AAcA,IAAM,SAAA,GAAY,cAAA;AAKlB,eAAsB,YAAA,CACpB,MACA,IAAA,EAC4C;AAC5C,EAAA,MAAM,EAAE,IAAA,EAAK,GAAI,MAAM,IAAA,CAAK,IAAA;AAAA,IAC1B,GAAG,SAAS,CAAA,SAAA,CAAA;AAAA,IACZ;AAAA,GACF;AACA,EAAA,OAAO,IAAA;AACT;AAKA,eAAsB,SAAA,CACpB,MACA,IAAA,EAC4C;AAC5C,EAAA,MAAM,EAAE,IAAA,EAAK,GAAI,MAAM,IAAA,CAAK,IAAA;AAAA,IAC1B,GAAG,SAAS,CAAA,MAAA,CAAA;AAAA,IACZ;AAAA,GACF;AACA,EAAA,OAAO,IAAA;AACT;AAKA,eAAsB,mBAAA,CACpB,MACA,WAAA,EACiD;AACjD,EAAA,MAAM,CAAA,GAAI,IAAI,eAAA,CAAgB,EAAE,aAAa,CAAA;AAC7C,EAAA,MAAM,EAAE,IAAA,EAAK,GAAI,MAAM,IAAA,CAAK,GAAA;AAAA,IAC1B,CAAA,EAAG,SAAS,CAAA,oBAAA,EAAuB,CAAA,CAAE,UAAU,CAAA;AAAA,GACjD;AACA,EAAA,OAAO,IAAA;AACT;AAKA,eAAsB,uBAAA,CACpB,MACA,IAAA,EAC4C;AAC5C,EAAA,MAAM,EAAE,IAAA,EAAK,GAAI,MAAM,IAAA,CAAK,IAAA;AAAA,IAC1B,GAAG,SAAS,CAAA,sBAAA,CAAA;AAAA,IACZ;AAAA,GACF;AACA,EAAA,OAAO,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AAyB,CAAC,IAAA,KAAS,uBAAA,CAAwB,MAAM,IAAI,CAAA;AAAA,MACrE,OAAA,EAAS,CAAC,IAAA,KAAS,WAAA,CAAY,MAAM,IAAI,CAAA;AAAA,MACzC,MAAA,EAAQ,CAAC,IAAA,KAAS,UAAA,CAAW,MAAM,IAAI,CAAA;AAAA,MACvC,EAAA,EAAI,CAAC,WAAA,KAAgB,KAAA,CAAM,MAAM,WAAW;AAAA;AAC9C,GACF;AACF","file":"index.mjs","sourcesContent":["import type {\n AuthSessionResponse,\n AuthUserResponse,\n IApiResponse,\n LoginRequest,\n LogoutRequest,\n OAuthGoogleCallbackRequest,\n OAuthGoogleStartResponse,\n RefreshRequest,\n RegisterRequest,\n} from '@ipetsadmin/contracts';\n\nimport type { HttpClient } from '../http-client';\n\nconst AUTH_BASE = '/api/v1/auth' as const;\n\n/**\n * POST /api/v1/auth/register\n */\nexport async function postRegister(\n http: HttpClient,\n body: RegisterRequest,\n): Promise<IApiResponse<AuthSessionResponse>> {\n const { data } = await http.post<IApiResponse<AuthSessionResponse>, RegisterRequest>(\n `${AUTH_BASE}/register`,\n body,\n );\n return data;\n}\n\n/**\n * POST /api/v1/auth/login\n */\nexport async function postLogin(\n http: HttpClient,\n body: LoginRequest,\n): Promise<IApiResponse<AuthSessionResponse>> {\n const { data } = await http.post<IApiResponse<AuthSessionResponse>, LoginRequest>(\n `${AUTH_BASE}/login`,\n body,\n );\n return data;\n}\n\n/**\n * GET /api/v1/auth/oauth/google/start?redirectUri=...\n */\nexport async function getGoogleOAuthStart(\n http: HttpClient,\n redirectUri: string,\n): Promise<IApiResponse<OAuthGoogleStartResponse>> {\n const q = new URLSearchParams({ redirectUri });\n const { data } = await http.get<IApiResponse<OAuthGoogleStartResponse>>(\n `${AUTH_BASE}/oauth/google/start?${q.toString()}`,\n );\n return data;\n}\n\n/**\n * POST /api/v1/auth/oauth/google/callback\n */\nexport async function postGoogleOAuthCallback(\n http: HttpClient,\n body: OAuthGoogleCallbackRequest,\n): Promise<IApiResponse<AuthSessionResponse>> {\n const { data } = await http.post<IApiResponse<AuthSessionResponse>, OAuthGoogleCallbackRequest>(\n `${AUTH_BASE}/oauth/google/callback`,\n body,\n );\n return data;\n}\n\n/**\n * POST /api/v1/auth/refresh\n */\nexport async function postRefresh(\n http: HttpClient,\n body: RefreshRequest,\n): Promise<IApiResponse<AuthSessionResponse>> {\n const { data } = await http.post<IApiResponse<AuthSessionResponse>, RefreshRequest>(\n `${AUTH_BASE}/refresh`,\n body,\n );\n return data;\n}\n\n/**\n * POST /api/v1/auth/logout — 204 No Content (no JSON body).\n */\nexport async function postLogout(http: HttpClient, body: LogoutRequest): Promise<void> {\n await http.post<undefined, LogoutRequest>(`${AUTH_BASE}/logout`, body);\n}\n\n/**\n * GET /api/v1/auth/me — requires `Authorization: Bearer <accessToken>`.\n */\nexport async function getMe(\n http: HttpClient,\n accessToken: string,\n): Promise<IApiResponse<AuthUserResponse>> {\n const { data } = await http.get<IApiResponse<AuthUserResponse>>(`${AUTH_BASE}/me`, {\n headers: { Authorization: `Bearer ${accessToken}` },\n });\n return data;\n}\n","import type { IApiResponse, HealthCheck } from '@ipetsadmin/contracts';\nimport type { HttpClient } from '../http-client';\n\n/** Same path as `/api/${v1}/health-check` on the server when `v1` is the string `'v1'`. */\nconst HEALTH_CHECK_PATH = '/api/v1/health-check' as const;\n\n/**\n * GET /api/v1/health-check — server liveness.\n *\n * Returns the full JSON the server sends (`IApiResponse<HealthCheck>`).\n *\n * **Why not `data.data` here?** Adapters like Axios wrap the HTTP body in a property also\n * called `data`. That outer `data` is the entire `res.json(...)` object. The inner\n * `IApiResponse.data` is the `HealthCheck` payload — use `.data` on the **returned** value,\n * e.g. `(await fetchHealthCheck(http)).data`.\n */\nexport async function fetchHealthCheck(http: HttpClient): Promise<IApiResponse<HealthCheck>> {\n const { data: body } = await http.get<IApiResponse<HealthCheck>>(HEALTH_CHECK_PATH);\n\n return body;\n}\n","import {\n getGoogleOAuthStart,\n getMe,\n postGoogleOAuthCallback,\n postLogin,\n postLogout,\n postRefresh,\n postRegister,\n} from './endpoints/auth';\nimport { fetchHealthCheck } from './endpoints/health-check';\nimport type { HttpClient } from './http-client';\n\nexport interface CreateApiClientOptions {\n /**\n * Preconfigured HTTP client (e.g. Axios instance with `baseURL` set).\n * Paths in this library are relative to that base (e.g. `/api/v1/...`).\n * Both `get` and `post` are required for auth flows.\n */\n readonly http: HttpClient;\n}\n\nexport interface ApiClient {\n readonly healthCheck: () => ReturnType<typeof fetchHealthCheck>;\n readonly auth: {\n readonly register: (\n body: Parameters<typeof postRegister>[1],\n ) => ReturnType<typeof postRegister>;\n readonly login: (body: Parameters<typeof postLogin>[1]) => ReturnType<typeof postLogin>;\n readonly getGoogleOAuthStart: (redirectUri: string) => ReturnType<typeof getGoogleOAuthStart>;\n readonly postGoogleOAuthCallback: (\n body: Parameters<typeof postGoogleOAuthCallback>[1],\n ) => ReturnType<typeof postGoogleOAuthCallback>;\n readonly refresh: (body: Parameters<typeof postRefresh>[1]) => ReturnType<typeof postRefresh>;\n readonly logout: (body: Parameters<typeof postLogout>[1]) => ReturnType<typeof postLogout>;\n readonly me: (accessToken: string) => ReturnType<typeof getMe>;\n };\n}\n\n/**\n * Creates a typed API client backed by the provided HTTP implementation.\n */\nexport function createApiClient(options: CreateApiClientOptions): ApiClient {\n const { http } = options;\n\n return {\n healthCheck: () => fetchHealthCheck(http),\n auth: {\n register: (body) => postRegister(http, body),\n login: (body) => postLogin(http, body),\n getGoogleOAuthStart: (redirectUri) => getGoogleOAuthStart(http, redirectUri),\n postGoogleOAuthCallback: (body) => postGoogleOAuthCallback(http, body),\n refresh: (body) => postRefresh(http, body),\n logout: (body) => postLogout(http, body),\n me: (accessToken) => getMe(http, accessToken),\n },\n };\n}\n"]}
1
+ {"version":3,"sources":["../src/endpoints/auth.ts","../src/endpoints/user.ts","../src/endpoints/health-check.ts","../src/create-api-client.ts"],"names":[],"mappings":";AAeA,IAAM,SAAA,GAAY,cAAA;AA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,KAAS,MAAM,IAAA,CAAK,IAA+B,iBAAiB,CAAA;AAElF,EAAA,OAAO,IAAA;AACT;;;ACiCO,SAAS,gBAAgB,OAAA,EAA4C;AAC1E,EAAA,MAAM,EAAE,MAAK,GAAI,OAAA;AAEjB,EAAA,OAAO;AAAA,IACL,WAAA,EAAa,MAAM,gBAAA,CAAiB,IAAI,CAAA;AAAA,IACxC,IAAA,EAAM;AAAA,MACJ,QAAA,EAAU,CAAC,IAAA,KAAS,YAAA,CAAa,MAAM,IAAI,CAAA;AAAA,MAC3C,KAAA,EAAO,CAAC,IAAA,KAAS,SAAA,CAAU,MAAM,IAAI,CAAA;AAAA,MACrC,mBAAA,EAAqB,CAAC,WAAA,KAAgB,mBAAA,CAAoB,MAAM,WAAW,CAAA;AAAA,MAC3E,uBAAA,EAAyB,CAAC,IAAA,KAAS,uBAAA,CAAwB,MAAM,IAAI,CAAA;AAAA,MACrE,OAAA,EAAS,CAAC,IAAA,KAAS,WAAA,CAAY,MAAM,IAAI,CAAA;AAAA,MACzC,MAAA,EAAQ,CAAC,IAAA,KAAS,UAAA,CAAW,MAAM,IAAI,CAAA;AAAA,MACvC,WAAA,EAAa,CAAC,IAAA,KAAS,gBAAA,CAAiB,MAAM,IAAI,CAAA;AAAA,MAClD,EAAA,EAAI,CAAC,WAAA,KAAgB,KAAA,CAAM,MAAM,WAAW;AAAA,KAC9C;AAAA,IACA,KAAA,EAAO;AAAA,MACL,UAAA,EAAY,CAAC,WAAA,KAAgB,cAAA,CAAe,MAAM,WAAW,CAAA;AAAA,MAC7D,cAAc,CAAC,WAAA,EAAa,SAAS,gBAAA,CAAiB,IAAA,EAAM,aAAa,IAAI;AAAA;AAC/E,GACF;AACF","file":"index.mjs","sourcesContent":["import type {\n AuthSessionResponse,\n AuthUserResponse,\n IApiResponse,\n LoginRequest,\n LogoutRequest,\n OAuthGoogleCallbackRequest,\n OAuthGoogleStartResponse,\n RefreshRequest,\n RegisterRequest,\n VerifyEmailRequest,\n} from '@ipetsadmin/contracts';\n\nimport type { HttpClient } from '../http-client';\n\nconst AUTH_BASE = '/api/v1/auth' as const;\n\n/**\n * POST /api/v1/auth/register\n */\nexport async function postRegister(\n http: HttpClient,\n body: RegisterRequest,\n): Promise<IApiResponse<AuthSessionResponse>> {\n const { data } = await http.post<IApiResponse<AuthSessionResponse>, RegisterRequest>(\n `${AUTH_BASE}/register`,\n body,\n );\n return data;\n}\n\n/**\n * POST /api/v1/auth/login\n */\nexport async function postLogin(\n http: HttpClient,\n body: LoginRequest,\n): Promise<IApiResponse<AuthSessionResponse>> {\n const { data } = await http.post<IApiResponse<AuthSessionResponse>, LoginRequest>(\n `${AUTH_BASE}/login`,\n body,\n );\n return data;\n}\n\n/**\n * GET /api/v1/auth/oauth/google/start?redirectUri=...\n */\nexport async function getGoogleOAuthStart(\n http: HttpClient,\n redirectUri: string,\n): Promise<IApiResponse<OAuthGoogleStartResponse>> {\n const q = new URLSearchParams({ redirectUri });\n const { data } = await http.get<IApiResponse<OAuthGoogleStartResponse>>(\n `${AUTH_BASE}/oauth/google/start?${q.toString()}`,\n );\n return data;\n}\n\n/**\n * POST /api/v1/auth/oauth/google/callback\n */\nexport async function postGoogleOAuthCallback(\n http: HttpClient,\n body: OAuthGoogleCallbackRequest,\n): Promise<IApiResponse<AuthSessionResponse>> {\n const { data } = await http.post<IApiResponse<AuthSessionResponse>, OAuthGoogleCallbackRequest>(\n `${AUTH_BASE}/oauth/google/callback`,\n body,\n );\n return data;\n}\n\n/**\n * POST /api/v1/auth/refresh\n */\nexport async function postRefresh(\n http: HttpClient,\n body: RefreshRequest,\n): Promise<IApiResponse<AuthSessionResponse>> {\n const { data } = await http.post<IApiResponse<AuthSessionResponse>, RefreshRequest>(\n `${AUTH_BASE}/refresh`,\n body,\n );\n return data;\n}\n\n/**\n * POST /api/v1/auth/logout — 204 No Content (no JSON body).\n */\nexport async function postLogout(http: HttpClient, body: LogoutRequest): Promise<void> {\n await http.post<undefined, LogoutRequest>(`${AUTH_BASE}/logout`, body);\n}\n\n/**\n * GET /api/v1/auth/me — requires `Authorization: Bearer <accessToken>`.\n */\nexport async function getMe(\n http: HttpClient,\n accessToken: string,\n): Promise<IApiResponse<AuthUserResponse>> {\n const { data } = await http.get<IApiResponse<AuthUserResponse>>(`${AUTH_BASE}/me`, {\n headers: { Authorization: `Bearer ${accessToken}` },\n });\n return data;\n}\n\n/**\n * PATCH /api/v1/auth/verify-email\n */\nexport async function patchVerifyEmail(\n http: HttpClient,\n body: VerifyEmailRequest,\n): Promise<IApiResponse<void>> {\n const { data } = await http.patch<IApiResponse<void>, VerifyEmailRequest>(\n `${AUTH_BASE}/verify-email`,\n body,\n );\n return data;\n}\n","import type {\n IApiResponse,\n PatchUserProfileInput,\n UserProfileResponse,\n} from '@ipetsadmin/contracts';\n\nimport type { HttpClient } from '../http-client';\n\nconst USERS_BASE = '/api/v1/users' as const;\n\n/**\n * GET /api/v1/users/me/profile — requires `Authorization: Bearer <accessToken>`.\n */\nexport async function getUserProfile(\n http: HttpClient,\n accessToken: string,\n): Promise<IApiResponse<UserProfileResponse>> {\n const { data } = await http.get<IApiResponse<UserProfileResponse>>(`${USERS_BASE}/me/profile`, {\n headers: { Authorization: `Bearer ${accessToken}` },\n });\n return data;\n}\n\n/**\n * PATCH /api/v1/users/me/profile — requires `Authorization: Bearer <accessToken>`.\n * Body must not include `avatar` (API rejects unknown keys in strict mode).\n */\nexport async function patchUserProfile(\n http: HttpClient,\n accessToken: string,\n body: PatchUserProfileInput,\n): Promise<IApiResponse<UserProfileResponse>> {\n const { data } = await http.patch<IApiResponse<UserProfileResponse>, PatchUserProfileInput>(\n `${USERS_BASE}/me/profile`,\n body,\n {\n headers: { Authorization: `Bearer ${accessToken}` },\n },\n );\n return data;\n}\n","import type { IApiResponse, HealthCheck } from '@ipetsadmin/contracts';\nimport type { HttpClient } from '../http-client';\n\n/** Same path as `/api/${v1}/health-check` on the server when `v1` is the string `'v1'`. */\nconst HEALTH_CHECK_PATH = '/api/v1/health-check' as const;\n\n/**\n * GET /api/v1/health-check — server liveness.\n *\n * Returns the full JSON the server sends (`IApiResponse<HealthCheck>`).\n *\n * **Why not `data.data` here?** Adapters like Axios wrap the HTTP body in a property also\n * called `data`. That outer `data` is the entire `res.json(...)` object. The inner\n * `IApiResponse.data` is the `HealthCheck` payload — use `.data` on the **returned** value,\n * e.g. `(await fetchHealthCheck(http)).data`.\n */\nexport async function fetchHealthCheck(http: HttpClient): Promise<IApiResponse<HealthCheck>> {\n const { data: body } = await http.get<IApiResponse<HealthCheck>>(HEALTH_CHECK_PATH);\n\n return body;\n}\n","import {\n getGoogleOAuthStart,\n getMe,\n patchVerifyEmail,\n postGoogleOAuthCallback,\n postLogin,\n postLogout,\n postRefresh,\n postRegister,\n} from './endpoints/auth';\nimport { getUserProfile, patchUserProfile } from './endpoints/user';\nimport { fetchHealthCheck } from './endpoints/health-check';\nimport type { HttpClient } from './http-client';\n\nexport interface CreateApiClientOptions {\n /**\n * Preconfigured HTTP client (e.g. Axios instance with `baseURL` set).\n * Paths in this library are relative to that base (e.g. `/api/v1/...`).\n * Both `get` and `post` are required for auth flows.\n */\n readonly http: HttpClient;\n}\n\nexport interface ApiClient {\n readonly healthCheck: () => ReturnType<typeof fetchHealthCheck>;\n readonly auth: {\n readonly register: (\n body: Parameters<typeof postRegister>[1],\n ) => ReturnType<typeof postRegister>;\n readonly login: (body: Parameters<typeof postLogin>[1]) => ReturnType<typeof postLogin>;\n readonly getGoogleOAuthStart: (redirectUri: string) => ReturnType<typeof getGoogleOAuthStart>;\n readonly postGoogleOAuthCallback: (\n body: Parameters<typeof postGoogleOAuthCallback>[1],\n ) => ReturnType<typeof postGoogleOAuthCallback>;\n readonly refresh: (body: Parameters<typeof postRefresh>[1]) => ReturnType<typeof postRefresh>;\n readonly logout: (body: Parameters<typeof postLogout>[1]) => ReturnType<typeof postLogout>;\n readonly verifyEmail: (\n body: Parameters<typeof patchVerifyEmail>[1],\n ) => ReturnType<typeof patchVerifyEmail>;\n readonly me: (accessToken: string) => ReturnType<typeof getMe>;\n };\n readonly users: {\n readonly getProfile: (accessToken: string) => ReturnType<typeof getUserProfile>;\n readonly patchProfile: (\n accessToken: string,\n body: Parameters<typeof patchUserProfile>[2],\n ) => ReturnType<typeof patchUserProfile>;\n };\n}\n\n/**\n * Creates a typed API client backed by the provided HTTP implementation.\n */\nexport function createApiClient(options: CreateApiClientOptions): ApiClient {\n const { http } = options;\n\n return {\n healthCheck: () => fetchHealthCheck(http),\n auth: {\n register: (body) => postRegister(http, body),\n login: (body) => postLogin(http, body),\n getGoogleOAuthStart: (redirectUri) => getGoogleOAuthStart(http, redirectUri),\n postGoogleOAuthCallback: (body) => postGoogleOAuthCallback(http, body),\n refresh: (body) => postRefresh(http, body),\n logout: (body) => postLogout(http, body),\n verifyEmail: (body) => patchVerifyEmail(http, body),\n me: (accessToken) => getMe(http, accessToken),\n },\n users: {\n getProfile: (accessToken) => getUserProfile(http, accessToken),\n patchProfile: (accessToken, body) => patchUserProfile(http, accessToken, body),\n },\n };\n}\n"]}
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@ipetsadmin/api-client",
3
- "version": "1.1.0",
3
+ "version": "1.1.2",
4
4
  "description": "Client used to interact with Truffa project API",
5
5
  "main": "./dist/index.js",
6
6
  "module": "./dist/index.mjs",
@@ -38,7 +38,7 @@
38
38
  "author": "",
39
39
  "license": "MIT",
40
40
  "devDependencies": {
41
- "@ipetsadmin/contracts": "1.1.2",
41
+ "@ipetsadmin/contracts": "1.1.9",
42
42
  "@eslint/js": "^10.0.1",
43
43
  "@types/express": "^5.0.5",
44
44
  "@types/node": "^24.10.0",
@@ -52,7 +52,7 @@
52
52
  "typescript-eslint": "^8.58.0"
53
53
  },
54
54
  "peerDependencies": {
55
- "@ipetsadmin/contracts": ">=1.1.1"
55
+ "@ipetsadmin/contracts": ">=1.1.9"
56
56
  },
57
57
  "publishConfig": {
58
58
  "access": "public"