@ipetsadmin/api-client 1.1.1 → 1.2.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/CHANGELOG.md CHANGED
@@ -19,6 +19,20 @@ 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
+
22
36
  ## [1.1.1] - 2026-04-25
23
37
 
24
38
  ### 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.1** (auth types, `VerifyEmailRequest`, and `IApiResponse` envelopes). Use a contracts version that includes any DTO you call (e.g. `VerifyEmailRequest` for **`verifyEmail`**).
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,40 +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`** and **`auth`** namespace |
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 `client.*` — see [`src/endpoints/auth.ts`](./src/endpoints/auth.ts) and [`src/endpoints/health-check.ts`](./src/endpoints/health-check.ts) |
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
27
 
28
28
  ### Parity with `@ipetsadmin/api-main`
29
29
 
30
- The API currently mounts **one public JSON surface** used by this client (see `api-main` `server.ts` / `routes/auth.routes.ts`):
30
+ The API surfaces below are covered by this client (see `api-main` `server.ts` and route modules under `routes/`):
31
31
 
32
- | Area | Server routes this client implements |
33
- | ---------- | ------------------------------------ |
34
- | **Health** | `GET /api/v1/health-check` |
35
- | **Auth** | All routes under `/api/v1/auth/…` |
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) |
36
37
 
37
38
  `api-main` also serves **OpenAPI** (`/api-docs`, `/api-docs.json`) when enabled; that is not wrapped here.
38
39
 
39
40
  ### Endpoints
40
41
 
41
- | HTTP | Path | `createApiClient` | Named helper |
42
- | ------- | ------------------------------------------------- | ---------------------------------------------- | ---------------------------------------- |
43
- | `GET` | `/api/v1/health-check` | `client.healthCheck()` | `fetchHealthCheck(http)` |
44
- | `POST` | `/api/v1/auth/register` | `client.auth.register(body)` | `postRegister(http, body)` |
45
- | `POST` | `/api/v1/auth/login` | `client.auth.login(body)` | `postLogin(http, body)` |
46
- | `GET` | `/api/v1/auth/oauth/google/start?redirectUri=...` | `client.auth.getGoogleOAuthStart(redirectUri)` | `getGoogleOAuthStart(http, redirectUri)` |
47
- | `POST` | `/api/v1/auth/oauth/google/callback` | `client.auth.postGoogleOAuthCallback(body)` | `postGoogleOAuthCallback(http, body)` |
48
- | `POST` | `/api/v1/auth/refresh` | `client.auth.refresh(body)` | `postRefresh(http, body)` |
49
- | `POST` | `/api/v1/auth/logout` | `client.auth.logout(body)` | `postLogout(http, body)` |
50
- | `PATCH` | `/api/v1/auth/verify-email` | `client.auth.verifyEmail(body)` | `patchVerifyEmail(http, body)` |
51
- | `GET` | `/api/v1/auth/me` | `client.auth.me(accessToken)` | `getMe(http, accessToken)` |
52
-
53
- 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).
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).
54
57
 
55
58
  ### Usage example (Axios)
56
59
 
@@ -85,6 +88,22 @@ For **`IApiResponse<AuthSessionResponse>`**, the **envelope** is the JSON body;
85
88
 
86
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`.
87
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`).
106
+
88
107
  ### Why a factory?
89
108
 
90
109
  `createApiClient({ http })` keeps env and transport out of this package, supports multiple backends in one app, and makes tests easy with a mock `http` object.
@@ -95,8 +114,8 @@ Call **`api.auth.verifyEmail({ token })`** (or **`patchVerifyEmail`**) with the
95
114
 
96
115
  1. **`HttpClient`** — abstraction over **`get` / `post` / `patch`** (`{ data: T }` response shape, Axios-compatible).
97
116
  2. **`src/endpoints/*.ts`** — thin functions: `(http, …args) => Promise<…>`.
98
- 3. **`createApiClient`** — wires `http` into those endpoints.
99
- 4. **`@ipetsadmin/contracts`** — DTOs (`RegisterRequest`, `AuthSessionResponse`, `VerifyEmailRequest`, …).
117
+ 3. **`createApiClient`** — wires `http` into those endpoints under **`healthCheck`**, **`auth`**, and **`users`**.
118
+ 4. **`@ipetsadmin/contracts`** — DTOs (`RegisterRequest`, `AuthSessionResponse`, `VerifyEmailRequest`, `UserProfileResponse`, `PatchUserProfileInput`, …).
100
119
 
101
120
  ### Extending further
102
121
 
@@ -121,6 +140,11 @@ const http: HttpClient = {
121
140
  const api = createApiClient({ http });
122
141
  await api.healthCheck();
123
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
+ });
124
148
  ```
125
149
 
126
150
  ---
package/dist/index.d.mts CHANGED
@@ -1,4 +1,4 @@
1
- import { RegisterRequest, IApiResponse, AuthSessionResponse, LoginRequest, OAuthGoogleStartResponse, OAuthGoogleCallbackRequest, RefreshRequest, LogoutRequest, VerifyEmailRequest, AuthUserResponse, HealthCheck } from '@ipetsadmin/contracts';
1
+ import { RegisterRequest, IApiResponse, AuthSessionResponse, LoginRequest, OAuthGoogleStartResponse, OAuthGoogleCallbackRequest, RefreshRequest, LogoutRequest, VerifyEmailRequest, AuthUserResponse, UserProfileResponse, PatchUserProfileInput, CreatePetInput, IPet, HealthCheck } from '@ipetsadmin/contracts';
2
2
 
3
3
  type HttpGet = <TResponse>(url: string, config?: unknown) => Promise<{
4
4
  data: TResponse;
@@ -24,6 +24,11 @@ declare function postLogout(http: HttpClient, body: LogoutRequest): Promise<void
24
24
  declare function getMe(http: HttpClient, accessToken: string): Promise<IApiResponse<AuthUserResponse>>;
25
25
  declare function patchVerifyEmail(http: HttpClient, body: VerifyEmailRequest): Promise<IApiResponse<void>>;
26
26
 
27
+ declare function getUserProfile(http: HttpClient, accessToken: string): Promise<IApiResponse<UserProfileResponse>>;
28
+ declare function getUserPets(http: HttpClient, accessToken: string, userId: string): Promise<IApiResponse<IPet[]>>;
29
+ declare function createUserPet(http: HttpClient, accessToken: string, userId: string, body: CreatePetInput): Promise<IApiResponse<IPet>>;
30
+ declare function patchUserProfile(http: HttpClient, accessToken: string, body: PatchUserProfileInput): Promise<IApiResponse<UserProfileResponse>>;
31
+
27
32
  declare function fetchHealthCheck(http: HttpClient): Promise<IApiResponse<HealthCheck>>;
28
33
 
29
34
  interface CreateApiClientOptions {
@@ -41,7 +46,11 @@ interface ApiClient {
41
46
  readonly verifyEmail: (body: Parameters<typeof patchVerifyEmail>[1]) => ReturnType<typeof patchVerifyEmail>;
42
47
  readonly me: (accessToken: string) => ReturnType<typeof getMe>;
43
48
  };
49
+ readonly users: {
50
+ readonly getProfile: (accessToken: string) => ReturnType<typeof getUserProfile>;
51
+ readonly patchProfile: (accessToken: string, body: Parameters<typeof patchUserProfile>[2]) => ReturnType<typeof patchUserProfile>;
52
+ };
44
53
  }
45
54
  declare function createApiClient(options: CreateApiClientOptions): ApiClient;
46
55
 
47
- export { type ApiClient, type CreateApiClientOptions, type HttpClient, type HttpGet, type HttpPatch, type HttpPost, createApiClient, getGoogleOAuthStart, getMe, patchVerifyEmail, postGoogleOAuthCallback, postLogin, postLogout, postRefresh, postRegister };
56
+ export { type ApiClient, type CreateApiClientOptions, type HttpClient, type HttpGet, type HttpPatch, type HttpPost, createApiClient, createUserPet, getGoogleOAuthStart, getMe, getUserPets, 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, VerifyEmailRequest, AuthUserResponse, HealthCheck } from '@ipetsadmin/contracts';
1
+ import { RegisterRequest, IApiResponse, AuthSessionResponse, LoginRequest, OAuthGoogleStartResponse, OAuthGoogleCallbackRequest, RefreshRequest, LogoutRequest, VerifyEmailRequest, AuthUserResponse, UserProfileResponse, PatchUserProfileInput, CreatePetInput, IPet, HealthCheck } from '@ipetsadmin/contracts';
2
2
 
3
3
  type HttpGet = <TResponse>(url: string, config?: unknown) => Promise<{
4
4
  data: TResponse;
@@ -24,6 +24,11 @@ declare function postLogout(http: HttpClient, body: LogoutRequest): Promise<void
24
24
  declare function getMe(http: HttpClient, accessToken: string): Promise<IApiResponse<AuthUserResponse>>;
25
25
  declare function patchVerifyEmail(http: HttpClient, body: VerifyEmailRequest): Promise<IApiResponse<void>>;
26
26
 
27
+ declare function getUserProfile(http: HttpClient, accessToken: string): Promise<IApiResponse<UserProfileResponse>>;
28
+ declare function getUserPets(http: HttpClient, accessToken: string, userId: string): Promise<IApiResponse<IPet[]>>;
29
+ declare function createUserPet(http: HttpClient, accessToken: string, userId: string, body: CreatePetInput): Promise<IApiResponse<IPet>>;
30
+ declare function patchUserProfile(http: HttpClient, accessToken: string, body: PatchUserProfileInput): Promise<IApiResponse<UserProfileResponse>>;
31
+
27
32
  declare function fetchHealthCheck(http: HttpClient): Promise<IApiResponse<HealthCheck>>;
28
33
 
29
34
  interface CreateApiClientOptions {
@@ -41,7 +46,11 @@ interface ApiClient {
41
46
  readonly verifyEmail: (body: Parameters<typeof patchVerifyEmail>[1]) => ReturnType<typeof patchVerifyEmail>;
42
47
  readonly me: (accessToken: string) => ReturnType<typeof getMe>;
43
48
  };
49
+ readonly users: {
50
+ readonly getProfile: (accessToken: string) => ReturnType<typeof getUserProfile>;
51
+ readonly patchProfile: (accessToken: string, body: Parameters<typeof patchUserProfile>[2]) => ReturnType<typeof patchUserProfile>;
52
+ };
44
53
  }
45
54
  declare function createApiClient(options: CreateApiClientOptions): ApiClient;
46
55
 
47
- export { type ApiClient, type CreateApiClientOptions, type HttpClient, type HttpGet, type HttpPatch, type HttpPost, createApiClient, getGoogleOAuthStart, getMe, patchVerifyEmail, postGoogleOAuthCallback, postLogin, postLogout, postRefresh, postRegister };
56
+ export { type ApiClient, type CreateApiClientOptions, type HttpClient, type HttpGet, type HttpPatch, type HttpPost, createApiClient, createUserPet, getGoogleOAuthStart, getMe, getUserPets, getUserProfile, patchUserProfile, patchVerifyEmail, postGoogleOAuthCallback, postLogin, postLogout, postRefresh, postRegister };
package/dist/index.js CHANGED
@@ -54,6 +54,41 @@ async function patchVerifyEmail(http, body) {
54
54
  return data;
55
55
  }
56
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 getUserPets(http, accessToken, userId) {
66
+ const { data } = await http.get(`${USERS_BASE}/${userId}/pets`, {
67
+ headers: { Authorization: `Bearer ${accessToken}` }
68
+ });
69
+ return data;
70
+ }
71
+ async function createUserPet(http, accessToken, userId, body) {
72
+ const { data } = await http.post(
73
+ `${USERS_BASE}/${userId}/pets`,
74
+ body,
75
+ {
76
+ headers: { Authorization: `Bearer ${accessToken}` }
77
+ }
78
+ );
79
+ return data;
80
+ }
81
+ async function patchUserProfile(http, accessToken, body) {
82
+ const { data } = await http.patch(
83
+ `${USERS_BASE}/me/profile`,
84
+ body,
85
+ {
86
+ headers: { Authorization: `Bearer ${accessToken}` }
87
+ }
88
+ );
89
+ return data;
90
+ }
91
+
57
92
  // src/endpoints/health-check.ts
58
93
  var HEALTH_CHECK_PATH = "/api/v1/health-check";
59
94
  async function fetchHealthCheck(http) {
@@ -75,13 +110,21 @@ function createApiClient(options) {
75
110
  logout: (body) => postLogout(http, body),
76
111
  verifyEmail: (body) => patchVerifyEmail(http, body),
77
112
  me: (accessToken) => getMe(http, accessToken)
113
+ },
114
+ users: {
115
+ getProfile: (accessToken) => getUserProfile(http, accessToken),
116
+ patchProfile: (accessToken, body) => patchUserProfile(http, accessToken, body)
78
117
  }
79
118
  };
80
119
  }
81
120
 
82
121
  exports.createApiClient = createApiClient;
122
+ exports.createUserPet = createUserPet;
83
123
  exports.getGoogleOAuthStart = getGoogleOAuthStart;
84
124
  exports.getMe = getMe;
125
+ exports.getUserPets = getUserPets;
126
+ exports.getUserProfile = getUserProfile;
127
+ exports.patchUserProfile = patchUserProfile;
85
128
  exports.patchVerifyEmail = patchVerifyEmail;
86
129
  exports.postGoogleOAuthCallback = postGoogleOAuthCallback;
87
130
  exports.postLogin = postLogin;
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":";;;AAeA,IAAM,SAAA,GAAY,cAAA;AAKlB,eAAsB,YAAA,CACpB,MACA,IAAA,EAC4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AS,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;AAC9C,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 { 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 { 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}\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 };\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,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,IAAA;AACT;AAKA,eAAsB,WAAA,CACpB,MACA,IAAA,EAC4C;AAC5C,EAAA,MAAM,EAAE,IAAA,EAAK,GAAI,MA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AAI,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.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 IPet,\n PatchUserProfileInput,\n UserProfileResponse,\n CreatePetInput,\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 * GET /api/v1/users/:userId/pets — requires `Authorization: Bearer <accessToken>`.\n */\nexport async function getUserPets(\n http: HttpClient,\n accessToken: string,\n userId: string,\n): Promise<IApiResponse<IPet[]>> {\n const { data } = await http.get<IApiResponse<IPet[]>>(`${USERS_BASE}/${userId}/pets`, {\n headers: { Authorization: `Bearer ${accessToken}` },\n });\n return data;\n}\n\n/**\n * POST /api/v1/users/:userId/pets — requires `Authorization: Bearer <accessToken>`.\n */\nexport async function createUserPet(\n http: HttpClient,\n accessToken: string,\n userId: string,\n body: CreatePetInput,\n): Promise<IApiResponse<IPet>> {\n const { data } = await http.post<IApiResponse<IPet>, CreatePetInput>(\n `${USERS_BASE}/${userId}/pets`,\n body,\n {\n headers: { Authorization: `Bearer ${accessToken}` },\n },\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
@@ -52,6 +52,41 @@ async function patchVerifyEmail(http, body) {
52
52
  return data;
53
53
  }
54
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 getUserPets(http, accessToken, userId) {
64
+ const { data } = await http.get(`${USERS_BASE}/${userId}/pets`, {
65
+ headers: { Authorization: `Bearer ${accessToken}` }
66
+ });
67
+ return data;
68
+ }
69
+ async function createUserPet(http, accessToken, userId, body) {
70
+ const { data } = await http.post(
71
+ `${USERS_BASE}/${userId}/pets`,
72
+ body,
73
+ {
74
+ headers: { Authorization: `Bearer ${accessToken}` }
75
+ }
76
+ );
77
+ return data;
78
+ }
79
+ async function patchUserProfile(http, accessToken, body) {
80
+ const { data } = await http.patch(
81
+ `${USERS_BASE}/me/profile`,
82
+ body,
83
+ {
84
+ headers: { Authorization: `Bearer ${accessToken}` }
85
+ }
86
+ );
87
+ return data;
88
+ }
89
+
55
90
  // src/endpoints/health-check.ts
56
91
  var HEALTH_CHECK_PATH = "/api/v1/health-check";
57
92
  async function fetchHealthCheck(http) {
@@ -73,10 +108,14 @@ function createApiClient(options) {
73
108
  logout: (body) => postLogout(http, body),
74
109
  verifyEmail: (body) => patchVerifyEmail(http, body),
75
110
  me: (accessToken) => getMe(http, accessToken)
111
+ },
112
+ users: {
113
+ getProfile: (accessToken) => getUserProfile(http, accessToken),
114
+ patchProfile: (accessToken, body) => patchUserProfile(http, accessToken, body)
76
115
  }
77
116
  };
78
117
  }
79
118
 
80
- export { createApiClient, getGoogleOAuthStart, getMe, patchVerifyEmail, postGoogleOAuthCallback, postLogin, postLogout, postRefresh, postRegister };
119
+ export { createApiClient, createUserPet, getGoogleOAuthStart, getMe, getUserPets, getUserProfile, patchUserProfile, patchVerifyEmail, postGoogleOAuthCallback, postLogin, postLogout, postRefresh, postRegister };
81
120
  //# sourceMappingURL=index.mjs.map
82
121
  //# 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":";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;AA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AAI,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 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 { 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 { 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}\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 };\n}\n"]}
1
+ {"version":3,"sources":["../src/end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B,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 IPet,\n PatchUserProfileInput,\n UserProfileResponse,\n CreatePetInput,\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 * GET /api/v1/users/:userId/pets — requires `Authorization: Bearer <accessToken>`.\n */\nexport async function getUserPets(\n http: HttpClient,\n accessToken: string,\n userId: string,\n): Promise<IApiResponse<IPet[]>> {\n const { data } = await http.get<IApiResponse<IPet[]>>(`${USERS_BASE}/${userId}/pets`, {\n headers: { Authorization: `Bearer ${accessToken}` },\n });\n return data;\n}\n\n/**\n * POST /api/v1/users/:userId/pets — requires `Authorization: Bearer <accessToken>`.\n */\nexport async function createUserPet(\n http: HttpClient,\n accessToken: string,\n userId: string,\n body: CreatePetInput,\n): Promise<IApiResponse<IPet>> {\n const { data } = await http.post<IApiResponse<IPet>, CreatePetInput>(\n `${USERS_BASE}/${userId}/pets`,\n body,\n {\n headers: { Authorization: `Bearer ${accessToken}` },\n },\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.1",
3
+ "version": "1.2.0",
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.7",
41
+ "@ipetsadmin/contracts": "1.2.1",
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.2.1"
56
56
  },
57
57
  "publishConfig": {
58
58
  "access": "public"