@ipetsadmin/api-client 1.2.0 → 1.3.1
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 +24 -0
- package/README.md +65 -36
- package/dist/index.d.mts +31 -4
- package/dist/index.d.ts +31 -4
- package/dist/index.js +86 -1
- package/dist/index.js.map +1 -1
- package/dist/index.mjs +79 -2
- package/dist/index.mjs.map +1 -1
- package/package.json +3 -3
package/CHANGELOG.md
CHANGED
|
@@ -19,6 +19,30 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0
|
|
|
19
19
|
|
|
20
20
|
### Security
|
|
21
21
|
|
|
22
|
+
## [1.3.0] - 2026-05-15
|
|
23
|
+
|
|
24
|
+
### Added
|
|
25
|
+
|
|
26
|
+
- **`HttpPut`** and **`HttpClient.put`** for JSON bodies (required for pet updates; Axios-compatible).
|
|
27
|
+
- **Pets / treatments** ([`src/endpoints/pet.ts`](./src/endpoints/pet.ts)), mounted under `/api/v1/pets/...`:
|
|
28
|
+
- **`getPetDetails`** — `GET /api/v1/pets/:petId` — `IApiResponse<PetResponse>`.
|
|
29
|
+
- **`putPetDetails`** — `PUT /api/v1/pets/:petId` — body **`PutPetDetailsBody`** (partial; no `ownerId` / timestamps).
|
|
30
|
+
- **`getPetTreatments`** — `GET /api/v1/pets/:petId/treatments`.
|
|
31
|
+
- **`createPetTreatment`** — `POST /api/v1/pets/:petId/treatments` — body **`PostPetTreatmentRequestBody`** (no `petId` in body; `status` optional).
|
|
32
|
+
- **`getPetTreatment`** — `GET /api/v1/pets/:petId/treatments/:treatmentId`.
|
|
33
|
+
- **`createApiClient`** **`pets`** namespace: **`getById`**, **`update`**, **`getTreatments`**, **`createTreatment`**, **`getTreatment`** (Bearer `accessToken`).
|
|
34
|
+
- **`createApiClient`** **`users`** namespace: **`getPets`**, **`createPet`** (were only named exports before).
|
|
35
|
+
- Type aliases **`PostUserPetRequestBody`**, **`PutPetDetailsBody`**, **`PostPetTreatmentRequestBody`**; re-exports from [`src/index.ts`](./src/index.ts).
|
|
36
|
+
|
|
37
|
+
### Changed
|
|
38
|
+
|
|
39
|
+
- **Peer dependency** on **`@ipetsadmin/contracts`** is now **≥ 1.3.0** (pet/treatment DTOs such as **`TreatmentResponse`**, **`CreateTreatmentInput`**). Dev dependency **1.3.0**.
|
|
40
|
+
- **`createUserPet`** / **`getUserPets`** now use **`PetResponse`** in **`IApiResponse`** typings; create body is **`PostUserPetRequestBody`** (**`Omit<CreatePetInput, 'ownerId' \| 'createdAt' \| 'updatedAt'>`**) instead of full **`CreatePetInput`** (matches **`POST /users/:userId/pets`** body).
|
|
41
|
+
|
|
42
|
+
### Breaking
|
|
43
|
+
|
|
44
|
+
- Custom **`HttpClient`** implementations must implement **`put`** (in addition to **`get`**, **`post`**, **`patch`**).
|
|
45
|
+
|
|
22
46
|
## [1.1.2] - 2026-04-25
|
|
23
47
|
|
|
24
48
|
### 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.
|
|
8
|
+
- **Peer dependency:** `@ipetsadmin/contracts` **≥ 1.3.0** (auth, profile, pets, treatments: `PetResponse`, `CreateTreatmentInput`, `TreatmentResponse`, `IApiResponse`, etc.). Use a contracts version that includes every DTO you call.
|
|
9
9
|
|
|
10
10
|
## Installation
|
|
11
11
|
|
|
@@ -17,44 +17,54 @@ npm install @ipetsadmin/api-client @ipetsadmin/contracts
|
|
|
17
17
|
|
|
18
18
|
## What ships today
|
|
19
19
|
|
|
20
|
-
| Export
|
|
21
|
-
|
|
|
22
|
-
| `createApiClient(options)`
|
|
23
|
-
| `ApiClient` / `CreateApiClientOptions`
|
|
24
|
-
| `HttpClient`
|
|
25
|
-
| `HttpGet` / `HttpPost` / `HttpPatch`
|
|
26
|
-
| Named helpers
|
|
20
|
+
| Export | Description |
|
|
21
|
+
| ------------------------------------------------ | ---------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------- |
|
|
22
|
+
| `createApiClient(options)` | Factory returning **`healthCheck`**, **`auth`**, **`users`**, and **`pets`** namespaces |
|
|
23
|
+
| `ApiClient` / `CreateApiClientOptions` | Typed client and `{ http: HttpClient }` options |
|
|
24
|
+
| `HttpClient` | **`get`**, **`post`**, **`patch`**, and **`put`** (minimal surface compatible with Axios) |
|
|
25
|
+
| `HttpGet` / `HttpPost` / `HttpPatch` / `HttpPut` | 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), [`pet.ts`](./src/endpoints/pet.ts) |
|
|
27
27
|
|
|
28
28
|
### Parity with `@ipetsadmin/api-main`
|
|
29
29
|
|
|
30
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** | Routes under `/api/v1/auth/…`
|
|
36
|
-
| **Users** | `GET` / `PATCH` `/api/v1/users/me/profile
|
|
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`; `GET` / `POST` `/api/v1/users/{userId}/pets` |
|
|
37
|
+
| **Pets** | `GET` / `PUT` `/api/v1/pets/{petId}`; `GET` / `POST` `/api/v1/pets/{petId}/treatments`; `GET` `/api/v1/pets/{petId}/treatments/{treatmentId}` |
|
|
37
38
|
|
|
38
39
|
`api-main` also serves **OpenAPI** (`/api-docs`, `/api-docs.json`) when enabled; that is not wrapped here.
|
|
39
40
|
|
|
40
41
|
### Endpoints
|
|
41
42
|
|
|
42
|
-
| HTTP | Path | `createApiClient`
|
|
43
|
-
| ------- | ------------------------------------------------- |
|
|
44
|
-
| `GET` | `/api/v1/health-check` | `client.healthCheck()`
|
|
45
|
-
| `POST` | `/api/v1/auth/register` | `client.auth.register(body)`
|
|
46
|
-
| `POST` | `/api/v1/auth/login` | `client.auth.login(body)`
|
|
47
|
-
| `GET` | `/api/v1/auth/oauth/google/start?redirectUri=...` | `client.auth.getGoogleOAuthStart(redirectUri)`
|
|
48
|
-
| `POST` | `/api/v1/auth/oauth/google/callback` | `client.auth.postGoogleOAuthCallback(body)`
|
|
49
|
-
| `POST` | `/api/v1/auth/refresh` | `client.auth.refresh(body)`
|
|
50
|
-
| `POST` | `/api/v1/auth/logout` | `client.auth.logout(body)`
|
|
51
|
-
| `PATCH` | `/api/v1/auth/verify-email` | `client.auth.verifyEmail(body)`
|
|
52
|
-
| `GET` | `/api/v1/auth/me` | `client.auth.me(accessToken)`
|
|
53
|
-
| `GET` | `/api/v1/users/me/profile` | `client.users.getProfile(accessToken)`
|
|
54
|
-
| `PATCH` | `/api/v1/users/me/profile` | `client.users.patchProfile(accessToken, body)`
|
|
43
|
+
| HTTP | Path | `createApiClient` | Named helper |
|
|
44
|
+
| ------- | ------------------------------------------------- | ----------------------------------------------------------- | -------------------------------------------------------- |
|
|
45
|
+
| `GET` | `/api/v1/health-check` | `client.healthCheck()` | `fetchHealthCheck(http)` |
|
|
46
|
+
| `POST` | `/api/v1/auth/register` | `client.auth.register(body)` | `postRegister(http, body)` |
|
|
47
|
+
| `POST` | `/api/v1/auth/login` | `client.auth.login(body)` | `postLogin(http, body)` |
|
|
48
|
+
| `GET` | `/api/v1/auth/oauth/google/start?redirectUri=...` | `client.auth.getGoogleOAuthStart(redirectUri)` | `getGoogleOAuthStart(http, redirectUri)` |
|
|
49
|
+
| `POST` | `/api/v1/auth/oauth/google/callback` | `client.auth.postGoogleOAuthCallback(body)` | `postGoogleOAuthCallback(http, body)` |
|
|
50
|
+
| `POST` | `/api/v1/auth/refresh` | `client.auth.refresh(body)` | `postRefresh(http, body)` |
|
|
51
|
+
| `POST` | `/api/v1/auth/logout` | `client.auth.logout(body)` | `postLogout(http, body)` |
|
|
52
|
+
| `PATCH` | `/api/v1/auth/verify-email` | `client.auth.verifyEmail(body)` | `patchVerifyEmail(http, body)` |
|
|
53
|
+
| `GET` | `/api/v1/auth/me` | `client.auth.me(accessToken)` | `getMe(http, accessToken)` |
|
|
54
|
+
| `GET` | `/api/v1/users/me/profile` | `client.users.getProfile(accessToken)` | `getUserProfile(http, accessToken)` |
|
|
55
|
+
| `PATCH` | `/api/v1/users/me/profile` | `client.users.patchProfile(accessToken, body)` | `patchUserProfile(http, accessToken, body)` |
|
|
56
|
+
| `GET` | `/api/v1/users/{userId}/pets` | `client.users.getPets(accessToken, userId)` | `getUserPets(http, accessToken, userId)` |
|
|
57
|
+
| `POST` | `/api/v1/users/{userId}/pets` | `client.users.createPet(accessToken, userId, body)` | `createUserPet(http, accessToken, userId, body)` |
|
|
58
|
+
| `GET` | `/api/v1/pets/{petId}` | `client.pets.getById(accessToken, petId)` | `getPetDetails(http, accessToken, petId)` |
|
|
59
|
+
| `PUT` | `/api/v1/pets/{petId}` | `client.pets.update(accessToken, petId, body)` | `putPetDetails(http, accessToken, petId, body)` |
|
|
60
|
+
| `GET` | `/api/v1/pets/{petId}/treatments` | `client.pets.getTreatments(accessToken, petId)` | `getPetTreatments(http, accessToken, petId)` |
|
|
61
|
+
| `POST` | `/api/v1/pets/{petId}/treatments` | `client.pets.createTreatment(accessToken, petId, body)` | `createPetTreatment(http, accessToken, petId, body)` |
|
|
62
|
+
| `GET` | `/api/v1/pets/{petId}/treatments/{treatmentId}` | `client.pets.getTreatment(accessToken, petId, treatmentId)` | `getPetTreatment(http, accessToken, petId, treatmentId)` |
|
|
55
63
|
|
|
56
64
|
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).
|
|
57
65
|
|
|
66
|
+
**Pets:** **`IApiResponse<PetResponse>`** for single-pet calls; **`PetResponse`** is the same shape as **`IPet`**. **Create pet under a user** uses **`PostUserPetRequestBody`** (no `ownerId` / `createdAt` / `updatedAt` in JSON — the API fills those). **Treatments** use **`TreatmentResponse`**; **create** body is **`PostPetTreatmentRequestBody`** (no `petId`; optional **`status`**). **PUT pet** uses **`PutPetDetailsBody`** (partial fields only).
|
|
67
|
+
|
|
58
68
|
### Usage example (Axios)
|
|
59
69
|
|
|
60
70
|
Paths are **relative to `baseURL`** (e.g. `https://api.example.com`).
|
|
@@ -93,16 +103,34 @@ Call **`api.auth.verifyEmail({ token })`** (or **`patchVerifyEmail`**) with the
|
|
|
93
103
|
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
104
|
|
|
95
105
|
```typescript
|
|
96
|
-
// Via the client (same `api` as other sections):
|
|
97
106
|
const prof = await api.users.getProfile(accessToken);
|
|
98
|
-
// prof — IApiResponse<UserProfileResponse>
|
|
99
|
-
|
|
100
107
|
await api.users.patchProfile(accessToken, { firstName: 'Alex', lastName: 'Kim' });
|
|
101
108
|
```
|
|
102
109
|
|
|
103
|
-
|
|
110
|
+
### Pets and treatments (authenticated)
|
|
111
|
+
|
|
112
|
+
```typescript
|
|
113
|
+
import { TreatmentType } from '@ipetsadmin/contracts';
|
|
114
|
+
|
|
115
|
+
const pets = await api.users.getPets(accessToken, userId);
|
|
116
|
+
|
|
117
|
+
const pet = await api.pets.getById(accessToken, petId);
|
|
118
|
+
await api.pets.update(accessToken, petId, { description: 'Updated notes' });
|
|
119
|
+
|
|
120
|
+
const list = await api.pets.getTreatments(accessToken, petId);
|
|
121
|
+
const created = await api.pets.createTreatment(accessToken, petId, {
|
|
122
|
+
ownerId: userId,
|
|
123
|
+
medicationName: 'Example',
|
|
124
|
+
dosage: '1 tablet',
|
|
125
|
+
frequencyHours: 12,
|
|
126
|
+
durationDays: 7,
|
|
127
|
+
totalDoses: 14,
|
|
128
|
+
treatmentType: TreatmentType.MEDICATION,
|
|
129
|
+
});
|
|
130
|
+
const one = await api.pets.getTreatment(accessToken, petId, created.data!.id);
|
|
131
|
+
```
|
|
104
132
|
|
|
105
|
-
|
|
133
|
+
Or use the named helpers from **`./endpoints/pet`** / **`./endpoints/user`**.
|
|
106
134
|
|
|
107
135
|
### Why a factory?
|
|
108
136
|
|
|
@@ -112,20 +140,20 @@ Types: **`UserProfileResponse`**, **`PatchUserProfileInput`** (re-exported from
|
|
|
112
140
|
|
|
113
141
|
## Architecture
|
|
114
142
|
|
|
115
|
-
1. **`HttpClient`** — abstraction over **`get` / `post` / `patch`** (`{ data: T }` response shape, Axios-compatible).
|
|
143
|
+
1. **`HttpClient`** — abstraction over **`get` / `post` / `patch` / `put`** (`{ data: T }` response shape, Axios-compatible).
|
|
116
144
|
2. **`src/endpoints/*.ts`** — thin functions: `(http, …args) => Promise<…>`.
|
|
117
|
-
3. **`createApiClient`** — wires `http` into those endpoints under **`healthCheck`**, **`auth`**, and **`
|
|
118
|
-
4. **`@ipetsadmin/contracts`** — DTOs (`RegisterRequest`, `AuthSessionResponse`, `
|
|
145
|
+
3. **`createApiClient`** — wires `http` into those endpoints under **`healthCheck`**, **`auth`**, **`users`**, and **`pets`**.
|
|
146
|
+
4. **`@ipetsadmin/contracts`** — DTOs (`RegisterRequest`, `AuthSessionResponse`, `PetResponse`, `CreateTreatmentInput`, …).
|
|
119
147
|
|
|
120
148
|
### Extending further
|
|
121
149
|
|
|
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 **`
|
|
150
|
+
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`**, **`patch`**, and **`put`**; **`getMe`** and pet routes set `Authorization: Bearer` for the access token argument).
|
|
123
151
|
|
|
124
152
|
---
|
|
125
153
|
|
|
126
154
|
## Testing
|
|
127
155
|
|
|
128
|
-
Inject a fake **`HttpClient`** with **`get`**, **`post`**, and **`
|
|
156
|
+
Inject a fake **`HttpClient`** with **`get`**, **`post`**, **`patch`**, and **`put`** mocks and assert URLs and payloads.
|
|
129
157
|
|
|
130
158
|
```typescript
|
|
131
159
|
import type { HttpClient } from '@ipetsadmin/api-client';
|
|
@@ -135,6 +163,7 @@ const http: HttpClient = {
|
|
|
135
163
|
get: jest.fn().mockResolvedValue({ data: { success: true, data: {} } }),
|
|
136
164
|
post: jest.fn().mockResolvedValue({ data: { success: true, data: {} } }),
|
|
137
165
|
patch: jest.fn().mockResolvedValue({ data: { success: true } }),
|
|
166
|
+
put: jest.fn().mockResolvedValue({ data: { success: true, data: {} } }),
|
|
138
167
|
};
|
|
139
168
|
|
|
140
169
|
const api = createApiClient({ http });
|
package/dist/index.d.mts
CHANGED
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import { RegisterRequest, IApiResponse, AuthSessionResponse, LoginRequest, OAuthGoogleStartResponse, OAuthGoogleCallbackRequest, RefreshRequest, LogoutRequest, VerifyEmailRequest, AuthUserResponse,
|
|
1
|
+
import { RegisterRequest, IApiResponse, AuthSessionResponse, LoginRequest, OAuthGoogleStartResponse, OAuthGoogleCallbackRequest, RefreshRequest, LogoutRequest, VerifyEmailRequest, AuthUserResponse, PetResponse, CreatePetInput, TreatmentResponse, CreateTreatmentInput, DoseResponse, CreateDoseInput, UserProfileResponse, PatchUserProfileInput, HealthCheck } from '@ipetsadmin/contracts';
|
|
2
2
|
|
|
3
3
|
type HttpGet = <TResponse>(url: string, config?: unknown) => Promise<{
|
|
4
4
|
data: TResponse;
|
|
@@ -9,10 +9,14 @@ type HttpPost = <TResponse, TBody = unknown>(url: string, body?: TBody, config?:
|
|
|
9
9
|
type HttpPatch = <TResponse, TBody = unknown>(url: string, body?: TBody, config?: unknown) => Promise<{
|
|
10
10
|
data: TResponse;
|
|
11
11
|
}>;
|
|
12
|
+
type HttpPut = <TResponse, TBody = unknown>(url: string, body?: TBody, config?: unknown) => Promise<{
|
|
13
|
+
data: TResponse;
|
|
14
|
+
}>;
|
|
12
15
|
interface HttpClient {
|
|
13
16
|
readonly get: HttpGet;
|
|
14
17
|
readonly post: HttpPost;
|
|
15
18
|
readonly patch: HttpPatch;
|
|
19
|
+
readonly put: HttpPut;
|
|
16
20
|
}
|
|
17
21
|
|
|
18
22
|
declare function postRegister(http: HttpClient, body: RegisterRequest): Promise<IApiResponse<AuthSessionResponse>>;
|
|
@@ -24,9 +28,21 @@ declare function postLogout(http: HttpClient, body: LogoutRequest): Promise<void
|
|
|
24
28
|
declare function getMe(http: HttpClient, accessToken: string): Promise<IApiResponse<AuthUserResponse>>;
|
|
25
29
|
declare function patchVerifyEmail(http: HttpClient, body: VerifyEmailRequest): Promise<IApiResponse<void>>;
|
|
26
30
|
|
|
31
|
+
type PutPetDetailsBody = Partial<Omit<CreatePetInput, 'ownerId' | 'createdAt' | 'updatedAt'>>;
|
|
32
|
+
type PostPetTreatmentRequestBody = Omit<CreateTreatmentInput, 'petId'> & Partial<Pick<CreateTreatmentInput, 'status'>>;
|
|
33
|
+
type PostPetTreatmentDoseBody = Omit<CreateDoseInput, 'treatmentId' | 'petId' | 'ownerId'> & Partial<Pick<CreateDoseInput, 'status'>>;
|
|
34
|
+
declare function getPetDetails(http: HttpClient, accessToken: string, petId: string): Promise<IApiResponse<PetResponse>>;
|
|
35
|
+
declare function putPetDetails(http: HttpClient, accessToken: string, petId: string, body: PutPetDetailsBody): Promise<IApiResponse<PetResponse>>;
|
|
36
|
+
declare function getPetTreatments(http: HttpClient, accessToken: string, petId: string): Promise<IApiResponse<TreatmentResponse[]>>;
|
|
37
|
+
declare function createPetTreatment(http: HttpClient, accessToken: string, petId: string, body: PostPetTreatmentRequestBody): Promise<IApiResponse<TreatmentResponse>>;
|
|
38
|
+
declare function getPetTreatment(http: HttpClient, accessToken: string, petId: string, treatmentId: string): Promise<IApiResponse<TreatmentResponse>>;
|
|
39
|
+
declare function getPetTreatmentDoses(http: HttpClient, accessToken: string, petId: string, treatmentId: string): Promise<IApiResponse<DoseResponse[]>>;
|
|
40
|
+
declare function createPetTreatmentDose(http: HttpClient, accessToken: string, petId: string, treatmentId: string, body: PostPetTreatmentDoseBody): Promise<IApiResponse<DoseResponse>>;
|
|
41
|
+
|
|
42
|
+
type PostUserPetRequestBody = Omit<CreatePetInput, 'ownerId' | 'createdAt' | 'updatedAt'>;
|
|
27
43
|
declare function getUserProfile(http: HttpClient, accessToken: string): Promise<IApiResponse<UserProfileResponse>>;
|
|
28
|
-
declare function getUserPets(http: HttpClient, accessToken: string, userId: string): Promise<IApiResponse<
|
|
29
|
-
declare function createUserPet(http: HttpClient, accessToken: string, userId: string, body:
|
|
44
|
+
declare function getUserPets(http: HttpClient, accessToken: string, userId: string): Promise<IApiResponse<PetResponse[]>>;
|
|
45
|
+
declare function createUserPet(http: HttpClient, accessToken: string, userId: string, body: PostUserPetRequestBody): Promise<IApiResponse<PetResponse>>;
|
|
30
46
|
declare function patchUserProfile(http: HttpClient, accessToken: string, body: PatchUserProfileInput): Promise<IApiResponse<UserProfileResponse>>;
|
|
31
47
|
|
|
32
48
|
declare function fetchHealthCheck(http: HttpClient): Promise<IApiResponse<HealthCheck>>;
|
|
@@ -49,8 +65,19 @@ interface ApiClient {
|
|
|
49
65
|
readonly users: {
|
|
50
66
|
readonly getProfile: (accessToken: string) => ReturnType<typeof getUserProfile>;
|
|
51
67
|
readonly patchProfile: (accessToken: string, body: Parameters<typeof patchUserProfile>[2]) => ReturnType<typeof patchUserProfile>;
|
|
68
|
+
readonly getPets: (accessToken: string, userId: string) => ReturnType<typeof getUserPets>;
|
|
69
|
+
readonly createPet: (accessToken: string, userId: string, body: Parameters<typeof createUserPet>[3]) => ReturnType<typeof createUserPet>;
|
|
70
|
+
};
|
|
71
|
+
readonly pets: {
|
|
72
|
+
readonly getById: (accessToken: string, petId: string) => ReturnType<typeof getPetDetails>;
|
|
73
|
+
readonly update: (accessToken: string, petId: string, body: Parameters<typeof putPetDetails>[3]) => ReturnType<typeof putPetDetails>;
|
|
74
|
+
readonly getTreatments: (accessToken: string, petId: string) => ReturnType<typeof getPetTreatments>;
|
|
75
|
+
readonly createTreatment: (accessToken: string, petId: string, body: Parameters<typeof createPetTreatment>[3]) => ReturnType<typeof createPetTreatment>;
|
|
76
|
+
readonly getTreatment: (accessToken: string, petId: string, treatmentId: string) => ReturnType<typeof getPetTreatment>;
|
|
77
|
+
readonly getTreatmentDoses: (accessToken: string, petId: string, treatmentId: string) => ReturnType<typeof getPetTreatmentDoses>;
|
|
78
|
+
readonly createTreatmentDose: (accessToken: string, petId: string, treatmentId: string, body: Parameters<typeof createPetTreatmentDose>[4]) => ReturnType<typeof createPetTreatmentDose>;
|
|
52
79
|
};
|
|
53
80
|
}
|
|
54
81
|
declare function createApiClient(options: CreateApiClientOptions): ApiClient;
|
|
55
82
|
|
|
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 };
|
|
83
|
+
export { type ApiClient, type CreateApiClientOptions, type HttpClient, type HttpGet, type HttpPatch, type HttpPost, type HttpPut, type PostPetTreatmentDoseBody, type PostPetTreatmentRequestBody, type PostUserPetRequestBody, type PutPetDetailsBody, createApiClient, createPetTreatment, createPetTreatmentDose, createUserPet, fetchHealthCheck, getGoogleOAuthStart, getMe, getPetDetails, getPetTreatment, getPetTreatmentDoses, getPetTreatments, getUserPets, getUserProfile, patchUserProfile, patchVerifyEmail, postGoogleOAuthCallback, postLogin, postLogout, postRefresh, postRegister, putPetDetails };
|
package/dist/index.d.ts
CHANGED
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import { RegisterRequest, IApiResponse, AuthSessionResponse, LoginRequest, OAuthGoogleStartResponse, OAuthGoogleCallbackRequest, RefreshRequest, LogoutRequest, VerifyEmailRequest, AuthUserResponse,
|
|
1
|
+
import { RegisterRequest, IApiResponse, AuthSessionResponse, LoginRequest, OAuthGoogleStartResponse, OAuthGoogleCallbackRequest, RefreshRequest, LogoutRequest, VerifyEmailRequest, AuthUserResponse, PetResponse, CreatePetInput, TreatmentResponse, CreateTreatmentInput, DoseResponse, CreateDoseInput, UserProfileResponse, PatchUserProfileInput, HealthCheck } from '@ipetsadmin/contracts';
|
|
2
2
|
|
|
3
3
|
type HttpGet = <TResponse>(url: string, config?: unknown) => Promise<{
|
|
4
4
|
data: TResponse;
|
|
@@ -9,10 +9,14 @@ type HttpPost = <TResponse, TBody = unknown>(url: string, body?: TBody, config?:
|
|
|
9
9
|
type HttpPatch = <TResponse, TBody = unknown>(url: string, body?: TBody, config?: unknown) => Promise<{
|
|
10
10
|
data: TResponse;
|
|
11
11
|
}>;
|
|
12
|
+
type HttpPut = <TResponse, TBody = unknown>(url: string, body?: TBody, config?: unknown) => Promise<{
|
|
13
|
+
data: TResponse;
|
|
14
|
+
}>;
|
|
12
15
|
interface HttpClient {
|
|
13
16
|
readonly get: HttpGet;
|
|
14
17
|
readonly post: HttpPost;
|
|
15
18
|
readonly patch: HttpPatch;
|
|
19
|
+
readonly put: HttpPut;
|
|
16
20
|
}
|
|
17
21
|
|
|
18
22
|
declare function postRegister(http: HttpClient, body: RegisterRequest): Promise<IApiResponse<AuthSessionResponse>>;
|
|
@@ -24,9 +28,21 @@ declare function postLogout(http: HttpClient, body: LogoutRequest): Promise<void
|
|
|
24
28
|
declare function getMe(http: HttpClient, accessToken: string): Promise<IApiResponse<AuthUserResponse>>;
|
|
25
29
|
declare function patchVerifyEmail(http: HttpClient, body: VerifyEmailRequest): Promise<IApiResponse<void>>;
|
|
26
30
|
|
|
31
|
+
type PutPetDetailsBody = Partial<Omit<CreatePetInput, 'ownerId' | 'createdAt' | 'updatedAt'>>;
|
|
32
|
+
type PostPetTreatmentRequestBody = Omit<CreateTreatmentInput, 'petId'> & Partial<Pick<CreateTreatmentInput, 'status'>>;
|
|
33
|
+
type PostPetTreatmentDoseBody = Omit<CreateDoseInput, 'treatmentId' | 'petId' | 'ownerId'> & Partial<Pick<CreateDoseInput, 'status'>>;
|
|
34
|
+
declare function getPetDetails(http: HttpClient, accessToken: string, petId: string): Promise<IApiResponse<PetResponse>>;
|
|
35
|
+
declare function putPetDetails(http: HttpClient, accessToken: string, petId: string, body: PutPetDetailsBody): Promise<IApiResponse<PetResponse>>;
|
|
36
|
+
declare function getPetTreatments(http: HttpClient, accessToken: string, petId: string): Promise<IApiResponse<TreatmentResponse[]>>;
|
|
37
|
+
declare function createPetTreatment(http: HttpClient, accessToken: string, petId: string, body: PostPetTreatmentRequestBody): Promise<IApiResponse<TreatmentResponse>>;
|
|
38
|
+
declare function getPetTreatment(http: HttpClient, accessToken: string, petId: string, treatmentId: string): Promise<IApiResponse<TreatmentResponse>>;
|
|
39
|
+
declare function getPetTreatmentDoses(http: HttpClient, accessToken: string, petId: string, treatmentId: string): Promise<IApiResponse<DoseResponse[]>>;
|
|
40
|
+
declare function createPetTreatmentDose(http: HttpClient, accessToken: string, petId: string, treatmentId: string, body: PostPetTreatmentDoseBody): Promise<IApiResponse<DoseResponse>>;
|
|
41
|
+
|
|
42
|
+
type PostUserPetRequestBody = Omit<CreatePetInput, 'ownerId' | 'createdAt' | 'updatedAt'>;
|
|
27
43
|
declare function getUserProfile(http: HttpClient, accessToken: string): Promise<IApiResponse<UserProfileResponse>>;
|
|
28
|
-
declare function getUserPets(http: HttpClient, accessToken: string, userId: string): Promise<IApiResponse<
|
|
29
|
-
declare function createUserPet(http: HttpClient, accessToken: string, userId: string, body:
|
|
44
|
+
declare function getUserPets(http: HttpClient, accessToken: string, userId: string): Promise<IApiResponse<PetResponse[]>>;
|
|
45
|
+
declare function createUserPet(http: HttpClient, accessToken: string, userId: string, body: PostUserPetRequestBody): Promise<IApiResponse<PetResponse>>;
|
|
30
46
|
declare function patchUserProfile(http: HttpClient, accessToken: string, body: PatchUserProfileInput): Promise<IApiResponse<UserProfileResponse>>;
|
|
31
47
|
|
|
32
48
|
declare function fetchHealthCheck(http: HttpClient): Promise<IApiResponse<HealthCheck>>;
|
|
@@ -49,8 +65,19 @@ interface ApiClient {
|
|
|
49
65
|
readonly users: {
|
|
50
66
|
readonly getProfile: (accessToken: string) => ReturnType<typeof getUserProfile>;
|
|
51
67
|
readonly patchProfile: (accessToken: string, body: Parameters<typeof patchUserProfile>[2]) => ReturnType<typeof patchUserProfile>;
|
|
68
|
+
readonly getPets: (accessToken: string, userId: string) => ReturnType<typeof getUserPets>;
|
|
69
|
+
readonly createPet: (accessToken: string, userId: string, body: Parameters<typeof createUserPet>[3]) => ReturnType<typeof createUserPet>;
|
|
70
|
+
};
|
|
71
|
+
readonly pets: {
|
|
72
|
+
readonly getById: (accessToken: string, petId: string) => ReturnType<typeof getPetDetails>;
|
|
73
|
+
readonly update: (accessToken: string, petId: string, body: Parameters<typeof putPetDetails>[3]) => ReturnType<typeof putPetDetails>;
|
|
74
|
+
readonly getTreatments: (accessToken: string, petId: string) => ReturnType<typeof getPetTreatments>;
|
|
75
|
+
readonly createTreatment: (accessToken: string, petId: string, body: Parameters<typeof createPetTreatment>[3]) => ReturnType<typeof createPetTreatment>;
|
|
76
|
+
readonly getTreatment: (accessToken: string, petId: string, treatmentId: string) => ReturnType<typeof getPetTreatment>;
|
|
77
|
+
readonly getTreatmentDoses: (accessToken: string, petId: string, treatmentId: string) => ReturnType<typeof getPetTreatmentDoses>;
|
|
78
|
+
readonly createTreatmentDose: (accessToken: string, petId: string, treatmentId: string, body: Parameters<typeof createPetTreatmentDose>[4]) => ReturnType<typeof createPetTreatmentDose>;
|
|
52
79
|
};
|
|
53
80
|
}
|
|
54
81
|
declare function createApiClient(options: CreateApiClientOptions): ApiClient;
|
|
55
82
|
|
|
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 };
|
|
83
|
+
export { type ApiClient, type CreateApiClientOptions, type HttpClient, type HttpGet, type HttpPatch, type HttpPost, type HttpPut, type PostPetTreatmentDoseBody, type PostPetTreatmentRequestBody, type PostUserPetRequestBody, type PutPetDetailsBody, createApiClient, createPetTreatment, createPetTreatmentDose, createUserPet, fetchHealthCheck, getGoogleOAuthStart, getMe, getPetDetails, getPetTreatment, getPetTreatmentDoses, getPetTreatments, getUserPets, getUserProfile, patchUserProfile, patchVerifyEmail, postGoogleOAuthCallback, postLogin, postLogout, postRefresh, postRegister, putPetDetails };
|
package/dist/index.js
CHANGED
|
@@ -54,6 +54,72 @@ async function patchVerifyEmail(http, body) {
|
|
|
54
54
|
return data;
|
|
55
55
|
}
|
|
56
56
|
|
|
57
|
+
// src/endpoints/pet.ts
|
|
58
|
+
var PETS_BASE = "/api/v1/pets";
|
|
59
|
+
async function getPetDetails(http, accessToken, petId) {
|
|
60
|
+
const { data } = await http.get(`${PETS_BASE}/${petId}`, {
|
|
61
|
+
headers: { Authorization: `Bearer ${accessToken}` }
|
|
62
|
+
});
|
|
63
|
+
return data;
|
|
64
|
+
}
|
|
65
|
+
async function putPetDetails(http, accessToken, petId, body) {
|
|
66
|
+
const { data } = await http.put(
|
|
67
|
+
`${PETS_BASE}/${petId}`,
|
|
68
|
+
body,
|
|
69
|
+
{
|
|
70
|
+
headers: { Authorization: `Bearer ${accessToken}` }
|
|
71
|
+
}
|
|
72
|
+
);
|
|
73
|
+
return data;
|
|
74
|
+
}
|
|
75
|
+
async function getPetTreatments(http, accessToken, petId) {
|
|
76
|
+
const { data } = await http.get(
|
|
77
|
+
`${PETS_BASE}/${petId}/treatments`,
|
|
78
|
+
{
|
|
79
|
+
headers: { Authorization: `Bearer ${accessToken}` }
|
|
80
|
+
}
|
|
81
|
+
);
|
|
82
|
+
return data;
|
|
83
|
+
}
|
|
84
|
+
async function createPetTreatment(http, accessToken, petId, body) {
|
|
85
|
+
const { data } = await http.post(
|
|
86
|
+
`${PETS_BASE}/${petId}/treatments`,
|
|
87
|
+
body,
|
|
88
|
+
{
|
|
89
|
+
headers: { Authorization: `Bearer ${accessToken}` }
|
|
90
|
+
}
|
|
91
|
+
);
|
|
92
|
+
return data;
|
|
93
|
+
}
|
|
94
|
+
async function getPetTreatment(http, accessToken, petId, treatmentId) {
|
|
95
|
+
const { data } = await http.get(
|
|
96
|
+
`${PETS_BASE}/${petId}/treatments/${treatmentId}`,
|
|
97
|
+
{
|
|
98
|
+
headers: { Authorization: `Bearer ${accessToken}` }
|
|
99
|
+
}
|
|
100
|
+
);
|
|
101
|
+
return data;
|
|
102
|
+
}
|
|
103
|
+
async function getPetTreatmentDoses(http, accessToken, petId, treatmentId) {
|
|
104
|
+
const { data } = await http.get(
|
|
105
|
+
`${PETS_BASE}/${petId}/treatments/${treatmentId}/doses`,
|
|
106
|
+
{
|
|
107
|
+
headers: { Authorization: `Bearer ${accessToken}` }
|
|
108
|
+
}
|
|
109
|
+
);
|
|
110
|
+
return data;
|
|
111
|
+
}
|
|
112
|
+
async function createPetTreatmentDose(http, accessToken, petId, treatmentId, body) {
|
|
113
|
+
const { data } = await http.post(
|
|
114
|
+
`${PETS_BASE}/${petId}/treatments/${treatmentId}/doses`,
|
|
115
|
+
body,
|
|
116
|
+
{
|
|
117
|
+
headers: { Authorization: `Bearer ${accessToken}` }
|
|
118
|
+
}
|
|
119
|
+
);
|
|
120
|
+
return data;
|
|
121
|
+
}
|
|
122
|
+
|
|
57
123
|
// src/endpoints/user.ts
|
|
58
124
|
var USERS_BASE = "/api/v1/users";
|
|
59
125
|
async function getUserProfile(http, accessToken) {
|
|
@@ -113,15 +179,33 @@ function createApiClient(options) {
|
|
|
113
179
|
},
|
|
114
180
|
users: {
|
|
115
181
|
getProfile: (accessToken) => getUserProfile(http, accessToken),
|
|
116
|
-
patchProfile: (accessToken, body) => patchUserProfile(http, accessToken, body)
|
|
182
|
+
patchProfile: (accessToken, body) => patchUserProfile(http, accessToken, body),
|
|
183
|
+
getPets: (accessToken, userId) => getUserPets(http, accessToken, userId),
|
|
184
|
+
createPet: (accessToken, userId, body) => createUserPet(http, accessToken, userId, body)
|
|
185
|
+
},
|
|
186
|
+
pets: {
|
|
187
|
+
getById: (accessToken, petId) => getPetDetails(http, accessToken, petId),
|
|
188
|
+
update: (accessToken, petId, body) => putPetDetails(http, accessToken, petId, body),
|
|
189
|
+
getTreatments: (accessToken, petId) => getPetTreatments(http, accessToken, petId),
|
|
190
|
+
createTreatment: (accessToken, petId, body) => createPetTreatment(http, accessToken, petId, body),
|
|
191
|
+
getTreatment: (accessToken, petId, treatmentId) => getPetTreatment(http, accessToken, petId, treatmentId),
|
|
192
|
+
getTreatmentDoses: (accessToken, petId, treatmentId) => getPetTreatmentDoses(http, accessToken, petId, treatmentId),
|
|
193
|
+
createTreatmentDose: (accessToken, petId, treatmentId, body) => createPetTreatmentDose(http, accessToken, petId, treatmentId, body)
|
|
117
194
|
}
|
|
118
195
|
};
|
|
119
196
|
}
|
|
120
197
|
|
|
121
198
|
exports.createApiClient = createApiClient;
|
|
199
|
+
exports.createPetTreatment = createPetTreatment;
|
|
200
|
+
exports.createPetTreatmentDose = createPetTreatmentDose;
|
|
122
201
|
exports.createUserPet = createUserPet;
|
|
202
|
+
exports.fetchHealthCheck = fetchHealthCheck;
|
|
123
203
|
exports.getGoogleOAuthStart = getGoogleOAuthStart;
|
|
124
204
|
exports.getMe = getMe;
|
|
205
|
+
exports.getPetDetails = getPetDetails;
|
|
206
|
+
exports.getPetTreatment = getPetTreatment;
|
|
207
|
+
exports.getPetTreatmentDoses = getPetTreatmentDoses;
|
|
208
|
+
exports.getPetTreatments = getPetTreatments;
|
|
125
209
|
exports.getUserPets = getUserPets;
|
|
126
210
|
exports.getUserProfile = getUserProfile;
|
|
127
211
|
exports.patchUserProfile = patchUserProfile;
|
|
@@ -131,5 +215,6 @@ exports.postLogin = postLogin;
|
|
|
131
215
|
exports.postLogout = postLogout;
|
|
132
216
|
exports.postRefresh = postRefresh;
|
|
133
217
|
exports.postRegister = postRegister;
|
|
218
|
+
exports.putPetDetails = putPetDetails;
|
|
134
219
|
//# sourceMappingURL=index.js.map
|
|
135
220
|
//# sourceMappingURL=index.js.map
|
package/dist/index.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
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,MAA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essionResponse,\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"]}
|
|
1
|
+
{"version":3,"sources":["../src/endpoints/auth.ts","../src/endpoints/pet.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,MAA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AA,CAAiB,IAAA,EAAM,aAAa,KAAK,CAAA;AAAA,MAChF,eAAA,EAAiB,CAAC,WAAA,EAAa,KAAA,EAAO,SACpC,kBAAA,CAAmB,IAAA,EAAM,WAAA,EAAa,KAAA,EAAO,IAAI,CAAA;AAAA,MACnD,YAAA,EAAc,CAAC,WAAA,EAAa,KAAA,EAAO,gBACjC,eAAA,CAAgB,IAAA,EAAM,WAAA,EAAa,KAAA,EAAO,WAAW,CAAA;AAAA,MACvD,iBAAA,EAAmB,CAAC,WAAA,EAAa,KAAA,EAAO,gBACtC,oBAAA,CAAqB,IAAA,EAAM,WAAA,EAAa,KAAA,EAAO,WAAW,CAAA;AAAA,MAC5D,mBAAA,EAAqB,CAAC,WAAA,EAAa,KAAA,EAAO,WAAA,EAAa,IAAA,KACrD,sBAAA,CAAuB,IAAA,EAAM,WAAA,EAAa,KAAA,EAAO,WAAA,EAAa,IAAI;AAAA;AACtE,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 CreateDoseInput,\n CreatePetInput,\n CreateTreatmentInput,\n DoseResponse,\n IApiResponse,\n PetResponse,\n TreatmentResponse,\n} from '@ipetsadmin/contracts';\n\nimport type { HttpClient } from '../http-client';\n\nconst PETS_BASE = '/api/v1/pets' as const;\n\n/** Body for PUT /api/v1/pets/:petId (partial update; excludes server-owned fields). */\nexport type PutPetDetailsBody = Partial<\n Omit<CreatePetInput, 'ownerId' | 'createdAt' | 'updatedAt'>\n>;\n\n/**\n * Same fields as creating a treatment without `petId` (provided in the URL). `status` may be omitted\n * (defaults on the server).\n */\nexport type PostPetTreatmentRequestBody = Omit<CreateTreatmentInput, 'petId'> &\n Partial<Pick<CreateTreatmentInput, 'status'>>;\n\n/**\n * POST .../treatments/:treatmentId/doses — `treatmentId`, `petId`, and `ownerId` are not sent in JSON.\n */\nexport type PostPetTreatmentDoseBody = Omit<CreateDoseInput, 'treatmentId' | 'petId' | 'ownerId'> &\n Partial<Pick<CreateDoseInput, 'status'>>;\n\n/**\n * GET /api/v1/pets/:petId — Bearer access token required.\n */\nexport async function getPetDetails(\n http: HttpClient,\n accessToken: string,\n petId: string,\n): Promise<IApiResponse<PetResponse>> {\n const { data } = await http.get<IApiResponse<PetResponse>>(`${PETS_BASE}/${petId}`, {\n headers: { Authorization: `Bearer ${accessToken}` },\n });\n return data;\n}\n\n/**\n * PUT /api/v1/pets/:petId — partial update; owner must match JWT user.\n */\nexport async function putPetDetails(\n http: HttpClient,\n accessToken: string,\n petId: string,\n body: PutPetDetailsBody,\n): Promise<IApiResponse<PetResponse>> {\n const { data } = await http.put<IApiResponse<PetResponse>, PutPetDetailsBody>(\n `${PETS_BASE}/${petId}`,\n body,\n {\n headers: { Authorization: `Bearer ${accessToken}` },\n },\n );\n return data;\n}\n\n/**\n * GET /api/v1/pets/:petId/treatments\n */\nexport async function getPetTreatments(\n http: HttpClient,\n accessToken: string,\n petId: string,\n): Promise<IApiResponse<TreatmentResponse[]>> {\n const { data } = await http.get<IApiResponse<TreatmentResponse[]>>(\n `${PETS_BASE}/${petId}/treatments`,\n {\n headers: { Authorization: `Bearer ${accessToken}` },\n },\n );\n return data;\n}\n\n/**\n * POST /api/v1/pets/:petId/treatments — 201 Created (`IApiResponse<TreatmentResponse>` body).\n */\nexport async function createPetTreatment(\n http: HttpClient,\n accessToken: string,\n petId: string,\n body: PostPetTreatmentRequestBody,\n): Promise<IApiResponse<TreatmentResponse>> {\n const { data } = await http.post<IApiResponse<TreatmentResponse>, PostPetTreatmentRequestBody>(\n `${PETS_BASE}/${petId}/treatments`,\n body,\n {\n headers: { Authorization: `Bearer ${accessToken}` },\n },\n );\n return data;\n}\n\n/**\n * GET /api/v1/pets/:petId/treatments/:treatmentId\n */\nexport async function getPetTreatment(\n http: HttpClient,\n accessToken: string,\n petId: string,\n treatmentId: string,\n): Promise<IApiResponse<TreatmentResponse>> {\n const { data } = await http.get<IApiResponse<TreatmentResponse>>(\n `${PETS_BASE}/${petId}/treatments/${treatmentId}`,\n {\n headers: { Authorization: `Bearer ${accessToken}` },\n },\n );\n return data;\n}\n\n/**\n * GET /api/v1/pets/:petId/treatments/:treatmentId/doses\n */\nexport async function getPetTreatmentDoses(\n http: HttpClient,\n accessToken: string,\n petId: string,\n treatmentId: string,\n): Promise<IApiResponse<DoseResponse[]>> {\n const { data } = await http.get<IApiResponse<DoseResponse[]>>(\n `${PETS_BASE}/${petId}/treatments/${treatmentId}/doses`,\n {\n headers: { Authorization: `Bearer ${accessToken}` },\n },\n );\n return data;\n}\n\n/**\n * POST /api/v1/pets/:petId/treatments/:treatmentId/doses — 201 Created.\n */\nexport async function createPetTreatmentDose(\n http: HttpClient,\n accessToken: string,\n petId: string,\n treatmentId: string,\n body: PostPetTreatmentDoseBody,\n): Promise<IApiResponse<DoseResponse>> {\n const { data } = await http.post<IApiResponse<DoseResponse>, PostPetTreatmentDoseBody>(\n `${PETS_BASE}/${petId}/treatments/${treatmentId}/doses`,\n body,\n {\n headers: { Authorization: `Bearer ${accessToken}` },\n },\n );\n return data;\n}\n","import type {\n CreatePetInput,\n IApiResponse,\n PatchUserProfileInput,\n PetResponse,\n UserProfileResponse,\n} from '@ipetsadmin/contracts';\n\nimport type { HttpClient } from '../http-client';\n\nconst USERS_BASE = '/api/v1/users' as const;\n\n/** Body for POST /users/:userId/pets (`ownerId` / timestamps come from the server). */\nexport type PostUserPetRequestBody = Omit<CreatePetInput, 'ownerId' | 'createdAt' | 'updatedAt'>;\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<PetResponse[]>> {\n const { data } = await http.get<IApiResponse<PetResponse[]>>(`${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: PostUserPetRequestBody,\n): Promise<IApiResponse<PetResponse>> {\n const { data } = await http.post<IApiResponse<PetResponse>, PostUserPetRequestBody>(\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 {\n createPetTreatment,\n createPetTreatmentDose,\n getPetDetails,\n getPetTreatment,\n getPetTreatmentDoses,\n getPetTreatments,\n putPetDetails,\n} from './endpoints/pet';\nimport { createUserPet, getUserPets, 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 * `get`, `post`, `patch`, and `put` are required for all implemented routes.\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 readonly getPets: (accessToken: string, userId: string) => ReturnType<typeof getUserPets>;\n readonly createPet: (\n accessToken: string,\n userId: string,\n body: Parameters<typeof createUserPet>[3],\n ) => ReturnType<typeof createUserPet>;\n };\n readonly pets: {\n readonly getById: (accessToken: string, petId: string) => ReturnType<typeof getPetDetails>;\n readonly update: (\n accessToken: string,\n petId: string,\n body: Parameters<typeof putPetDetails>[3],\n ) => ReturnType<typeof putPetDetails>;\n readonly getTreatments: (\n accessToken: string,\n petId: string,\n ) => ReturnType<typeof getPetTreatments>;\n readonly createTreatment: (\n accessToken: string,\n petId: string,\n body: Parameters<typeof createPetTreatment>[3],\n ) => ReturnType<typeof createPetTreatment>;\n readonly getTreatment: (\n accessToken: string,\n petId: string,\n treatmentId: string,\n ) => ReturnType<typeof getPetTreatment>;\n readonly getTreatmentDoses: (\n accessToken: string,\n petId: string,\n treatmentId: string,\n ) => ReturnType<typeof getPetTreatmentDoses>;\n readonly createTreatmentDose: (\n accessToken: string,\n petId: string,\n treatmentId: string,\n body: Parameters<typeof createPetTreatmentDose>[4],\n ) => ReturnType<typeof createPetTreatmentDose>;\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 getPets: (accessToken, userId) => getUserPets(http, accessToken, userId),\n createPet: (accessToken, userId, body) => createUserPet(http, accessToken, userId, body),\n },\n pets: {\n getById: (accessToken, petId) => getPetDetails(http, accessToken, petId),\n update: (accessToken, petId, body) => putPetDetails(http, accessToken, petId, body),\n getTreatments: (accessToken, petId) => getPetTreatments(http, accessToken, petId),\n createTreatment: (accessToken, petId, body) =>\n createPetTreatment(http, accessToken, petId, body),\n getTreatment: (accessToken, petId, treatmentId) =>\n getPetTreatment(http, accessToken, petId, treatmentId),\n getTreatmentDoses: (accessToken, petId, treatmentId) =>\n getPetTreatmentDoses(http, accessToken, petId, treatmentId),\n createTreatmentDose: (accessToken, petId, treatmentId, body) =>\n createPetTreatmentDose(http, accessToken, petId, treatmentId, body),\n },\n };\n}\n"]}
|
package/dist/index.mjs
CHANGED
|
@@ -52,6 +52,72 @@ async function patchVerifyEmail(http, body) {
|
|
|
52
52
|
return data;
|
|
53
53
|
}
|
|
54
54
|
|
|
55
|
+
// src/endpoints/pet.ts
|
|
56
|
+
var PETS_BASE = "/api/v1/pets";
|
|
57
|
+
async function getPetDetails(http, accessToken, petId) {
|
|
58
|
+
const { data } = await http.get(`${PETS_BASE}/${petId}`, {
|
|
59
|
+
headers: { Authorization: `Bearer ${accessToken}` }
|
|
60
|
+
});
|
|
61
|
+
return data;
|
|
62
|
+
}
|
|
63
|
+
async function putPetDetails(http, accessToken, petId, body) {
|
|
64
|
+
const { data } = await http.put(
|
|
65
|
+
`${PETS_BASE}/${petId}`,
|
|
66
|
+
body,
|
|
67
|
+
{
|
|
68
|
+
headers: { Authorization: `Bearer ${accessToken}` }
|
|
69
|
+
}
|
|
70
|
+
);
|
|
71
|
+
return data;
|
|
72
|
+
}
|
|
73
|
+
async function getPetTreatments(http, accessToken, petId) {
|
|
74
|
+
const { data } = await http.get(
|
|
75
|
+
`${PETS_BASE}/${petId}/treatments`,
|
|
76
|
+
{
|
|
77
|
+
headers: { Authorization: `Bearer ${accessToken}` }
|
|
78
|
+
}
|
|
79
|
+
);
|
|
80
|
+
return data;
|
|
81
|
+
}
|
|
82
|
+
async function createPetTreatment(http, accessToken, petId, body) {
|
|
83
|
+
const { data } = await http.post(
|
|
84
|
+
`${PETS_BASE}/${petId}/treatments`,
|
|
85
|
+
body,
|
|
86
|
+
{
|
|
87
|
+
headers: { Authorization: `Bearer ${accessToken}` }
|
|
88
|
+
}
|
|
89
|
+
);
|
|
90
|
+
return data;
|
|
91
|
+
}
|
|
92
|
+
async function getPetTreatment(http, accessToken, petId, treatmentId) {
|
|
93
|
+
const { data } = await http.get(
|
|
94
|
+
`${PETS_BASE}/${petId}/treatments/${treatmentId}`,
|
|
95
|
+
{
|
|
96
|
+
headers: { Authorization: `Bearer ${accessToken}` }
|
|
97
|
+
}
|
|
98
|
+
);
|
|
99
|
+
return data;
|
|
100
|
+
}
|
|
101
|
+
async function getPetTreatmentDoses(http, accessToken, petId, treatmentId) {
|
|
102
|
+
const { data } = await http.get(
|
|
103
|
+
`${PETS_BASE}/${petId}/treatments/${treatmentId}/doses`,
|
|
104
|
+
{
|
|
105
|
+
headers: { Authorization: `Bearer ${accessToken}` }
|
|
106
|
+
}
|
|
107
|
+
);
|
|
108
|
+
return data;
|
|
109
|
+
}
|
|
110
|
+
async function createPetTreatmentDose(http, accessToken, petId, treatmentId, body) {
|
|
111
|
+
const { data } = await http.post(
|
|
112
|
+
`${PETS_BASE}/${petId}/treatments/${treatmentId}/doses`,
|
|
113
|
+
body,
|
|
114
|
+
{
|
|
115
|
+
headers: { Authorization: `Bearer ${accessToken}` }
|
|
116
|
+
}
|
|
117
|
+
);
|
|
118
|
+
return data;
|
|
119
|
+
}
|
|
120
|
+
|
|
55
121
|
// src/endpoints/user.ts
|
|
56
122
|
var USERS_BASE = "/api/v1/users";
|
|
57
123
|
async function getUserProfile(http, accessToken) {
|
|
@@ -111,11 +177,22 @@ function createApiClient(options) {
|
|
|
111
177
|
},
|
|
112
178
|
users: {
|
|
113
179
|
getProfile: (accessToken) => getUserProfile(http, accessToken),
|
|
114
|
-
patchProfile: (accessToken, body) => patchUserProfile(http, accessToken, body)
|
|
180
|
+
patchProfile: (accessToken, body) => patchUserProfile(http, accessToken, body),
|
|
181
|
+
getPets: (accessToken, userId) => getUserPets(http, accessToken, userId),
|
|
182
|
+
createPet: (accessToken, userId, body) => createUserPet(http, accessToken, userId, body)
|
|
183
|
+
},
|
|
184
|
+
pets: {
|
|
185
|
+
getById: (accessToken, petId) => getPetDetails(http, accessToken, petId),
|
|
186
|
+
update: (accessToken, petId, body) => putPetDetails(http, accessToken, petId, body),
|
|
187
|
+
getTreatments: (accessToken, petId) => getPetTreatments(http, accessToken, petId),
|
|
188
|
+
createTreatment: (accessToken, petId, body) => createPetTreatment(http, accessToken, petId, body),
|
|
189
|
+
getTreatment: (accessToken, petId, treatmentId) => getPetTreatment(http, accessToken, petId, treatmentId),
|
|
190
|
+
getTreatmentDoses: (accessToken, petId, treatmentId) => getPetTreatmentDoses(http, accessToken, petId, treatmentId),
|
|
191
|
+
createTreatmentDose: (accessToken, petId, treatmentId, body) => createPetTreatmentDose(http, accessToken, petId, treatmentId, body)
|
|
115
192
|
}
|
|
116
193
|
};
|
|
117
194
|
}
|
|
118
195
|
|
|
119
|
-
export { createApiClient, createUserPet, getGoogleOAuthStart, getMe, getUserPets, getUserProfile, patchUserProfile, patchVerifyEmail, postGoogleOAuthCallback, postLogin, postLogout, postRefresh, postRegister };
|
|
196
|
+
export { createApiClient, createPetTreatment, createPetTreatmentDose, createUserPet, fetchHealthCheck, getGoogleOAuthStart, getMe, getPetDetails, getPetTreatment, getPetTreatmentDoses, getPetTreatments, getUserPets, getUserProfile, patchUserProfile, patchVerifyEmail, postGoogleOAuthCallback, postLogin, postLogout, postRefresh, postRegister, putPetDetails };
|
|
120
197
|
//# sourceMappingURL=index.mjs.map
|
|
121
198
|
//# sourceMappingURL=index.mjs.map
|
package/dist/index.mjs.map
CHANGED
|
@@ -1 +1 @@
|
|
|
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,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AM,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 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"]}
|
|
1
|
+
{"version":3,"sources":["../src/endpoints/auth.ts","../src/endpoints/pet.ts","../src/endpoints/user.ts","../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AI,CAAA;AAAA,MACnD,YAAA,EAAc,CAAC,WAAA,EAAa,KAAA,EAAO,gBACjC,eAAA,CAAgB,IAAA,EAAM,WAAA,EAAa,KAAA,EAAO,WAAW,CAAA;AAAA,MACvD,iBAAA,EAAmB,CAAC,WAAA,EAAa,KAAA,EAAO,gBACtC,oBAAA,CAAqB,IAAA,EAAM,WAAA,EAAa,KAAA,EAAO,WAAW,CAAA;AAAA,MAC5D,mBAAA,EAAqB,CAAC,WAAA,EAAa,KAAA,EAAO,WAAA,EAAa,IAAA,KACrD,sBAAA,CAAuB,IAAA,EAAM,WAAA,EAAa,KAAA,EAAO,WAAA,EAAa,IAAI;AAAA;AACtE,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 CreateDoseInput,\n CreatePetInput,\n CreateTreatmentInput,\n DoseResponse,\n IApiResponse,\n PetResponse,\n TreatmentResponse,\n} from '@ipetsadmin/contracts';\n\nimport type { HttpClient } from '../http-client';\n\nconst PETS_BASE = '/api/v1/pets' as const;\n\n/** Body for PUT /api/v1/pets/:petId (partial update; excludes server-owned fields). */\nexport type PutPetDetailsBody = Partial<\n Omit<CreatePetInput, 'ownerId' | 'createdAt' | 'updatedAt'>\n>;\n\n/**\n * Same fields as creating a treatment without `petId` (provided in the URL). `status` may be omitted\n * (defaults on the server).\n */\nexport type PostPetTreatmentRequestBody = Omit<CreateTreatmentInput, 'petId'> &\n Partial<Pick<CreateTreatmentInput, 'status'>>;\n\n/**\n * POST .../treatments/:treatmentId/doses — `treatmentId`, `petId`, and `ownerId` are not sent in JSON.\n */\nexport type PostPetTreatmentDoseBody = Omit<CreateDoseInput, 'treatmentId' | 'petId' | 'ownerId'> &\n Partial<Pick<CreateDoseInput, 'status'>>;\n\n/**\n * GET /api/v1/pets/:petId — Bearer access token required.\n */\nexport async function getPetDetails(\n http: HttpClient,\n accessToken: string,\n petId: string,\n): Promise<IApiResponse<PetResponse>> {\n const { data } = await http.get<IApiResponse<PetResponse>>(`${PETS_BASE}/${petId}`, {\n headers: { Authorization: `Bearer ${accessToken}` },\n });\n return data;\n}\n\n/**\n * PUT /api/v1/pets/:petId — partial update; owner must match JWT user.\n */\nexport async function putPetDetails(\n http: HttpClient,\n accessToken: string,\n petId: string,\n body: PutPetDetailsBody,\n): Promise<IApiResponse<PetResponse>> {\n const { data } = await http.put<IApiResponse<PetResponse>, PutPetDetailsBody>(\n `${PETS_BASE}/${petId}`,\n body,\n {\n headers: { Authorization: `Bearer ${accessToken}` },\n },\n );\n return data;\n}\n\n/**\n * GET /api/v1/pets/:petId/treatments\n */\nexport async function getPetTreatments(\n http: HttpClient,\n accessToken: string,\n petId: string,\n): Promise<IApiResponse<TreatmentResponse[]>> {\n const { data } = await http.get<IApiResponse<TreatmentResponse[]>>(\n `${PETS_BASE}/${petId}/treatments`,\n {\n headers: { Authorization: `Bearer ${accessToken}` },\n },\n );\n return data;\n}\n\n/**\n * POST /api/v1/pets/:petId/treatments — 201 Created (`IApiResponse<TreatmentResponse>` body).\n */\nexport async function createPetTreatment(\n http: HttpClient,\n accessToken: string,\n petId: string,\n body: PostPetTreatmentRequestBody,\n): Promise<IApiResponse<TreatmentResponse>> {\n const { data } = await http.post<IApiResponse<TreatmentResponse>, PostPetTreatmentRequestBody>(\n `${PETS_BASE}/${petId}/treatments`,\n body,\n {\n headers: { Authorization: `Bearer ${accessToken}` },\n },\n );\n return data;\n}\n\n/**\n * GET /api/v1/pets/:petId/treatments/:treatmentId\n */\nexport async function getPetTreatment(\n http: HttpClient,\n accessToken: string,\n petId: string,\n treatmentId: string,\n): Promise<IApiResponse<TreatmentResponse>> {\n const { data } = await http.get<IApiResponse<TreatmentResponse>>(\n `${PETS_BASE}/${petId}/treatments/${treatmentId}`,\n {\n headers: { Authorization: `Bearer ${accessToken}` },\n },\n );\n return data;\n}\n\n/**\n * GET /api/v1/pets/:petId/treatments/:treatmentId/doses\n */\nexport async function getPetTreatmentDoses(\n http: HttpClient,\n accessToken: string,\n petId: string,\n treatmentId: string,\n): Promise<IApiResponse<DoseResponse[]>> {\n const { data } = await http.get<IApiResponse<DoseResponse[]>>(\n `${PETS_BASE}/${petId}/treatments/${treatmentId}/doses`,\n {\n headers: { Authorization: `Bearer ${accessToken}` },\n },\n );\n return data;\n}\n\n/**\n * POST /api/v1/pets/:petId/treatments/:treatmentId/doses — 201 Created.\n */\nexport async function createPetTreatmentDose(\n http: HttpClient,\n accessToken: string,\n petId: string,\n treatmentId: string,\n body: PostPetTreatmentDoseBody,\n): Promise<IApiResponse<DoseResponse>> {\n const { data } = await http.post<IApiResponse<DoseResponse>, PostPetTreatmentDoseBody>(\n `${PETS_BASE}/${petId}/treatments/${treatmentId}/doses`,\n body,\n {\n headers: { Authorization: `Bearer ${accessToken}` },\n },\n );\n return data;\n}\n","import type {\n CreatePetInput,\n IApiResponse,\n PatchUserProfileInput,\n PetResponse,\n UserProfileResponse,\n} from '@ipetsadmin/contracts';\n\nimport type { HttpClient } from '../http-client';\n\nconst USERS_BASE = '/api/v1/users' as const;\n\n/** Body for POST /users/:userId/pets (`ownerId` / timestamps come from the server). */\nexport type PostUserPetRequestBody = Omit<CreatePetInput, 'ownerId' | 'createdAt' | 'updatedAt'>;\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<PetResponse[]>> {\n const { data } = await http.get<IApiResponse<PetResponse[]>>(`${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: PostUserPetRequestBody,\n): Promise<IApiResponse<PetResponse>> {\n const { data } = await http.post<IApiResponse<PetResponse>, PostUserPetRequestBody>(\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 {\n createPetTreatment,\n createPetTreatmentDose,\n getPetDetails,\n getPetTreatment,\n getPetTreatmentDoses,\n getPetTreatments,\n putPetDetails,\n} from './endpoints/pet';\nimport { createUserPet, getUserPets, 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 * `get`, `post`, `patch`, and `put` are required for all implemented routes.\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 readonly getPets: (accessToken: string, userId: string) => ReturnType<typeof getUserPets>;\n readonly createPet: (\n accessToken: string,\n userId: string,\n body: Parameters<typeof createUserPet>[3],\n ) => ReturnType<typeof createUserPet>;\n };\n readonly pets: {\n readonly getById: (accessToken: string, petId: string) => ReturnType<typeof getPetDetails>;\n readonly update: (\n accessToken: string,\n petId: string,\n body: Parameters<typeof putPetDetails>[3],\n ) => ReturnType<typeof putPetDetails>;\n readonly getTreatments: (\n accessToken: string,\n petId: string,\n ) => ReturnType<typeof getPetTreatments>;\n readonly createTreatment: (\n accessToken: string,\n petId: string,\n body: Parameters<typeof createPetTreatment>[3],\n ) => ReturnType<typeof createPetTreatment>;\n readonly getTreatment: (\n accessToken: string,\n petId: string,\n treatmentId: string,\n ) => ReturnType<typeof getPetTreatment>;\n readonly getTreatmentDoses: (\n accessToken: string,\n petId: string,\n treatmentId: string,\n ) => ReturnType<typeof getPetTreatmentDoses>;\n readonly createTreatmentDose: (\n accessToken: string,\n petId: string,\n treatmentId: string,\n body: Parameters<typeof createPetTreatmentDose>[4],\n ) => ReturnType<typeof createPetTreatmentDose>;\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 getPets: (accessToken, userId) => getUserPets(http, accessToken, userId),\n createPet: (accessToken, userId, body) => createUserPet(http, accessToken, userId, body),\n },\n pets: {\n getById: (accessToken, petId) => getPetDetails(http, accessToken, petId),\n update: (accessToken, petId, body) => putPetDetails(http, accessToken, petId, body),\n getTreatments: (accessToken, petId) => getPetTreatments(http, accessToken, petId),\n createTreatment: (accessToken, petId, body) =>\n createPetTreatment(http, accessToken, petId, body),\n getTreatment: (accessToken, petId, treatmentId) =>\n getPetTreatment(http, accessToken, petId, treatmentId),\n getTreatmentDoses: (accessToken, petId, treatmentId) =>\n getPetTreatmentDoses(http, accessToken, petId, treatmentId),\n createTreatmentDose: (accessToken, petId, treatmentId, body) =>\n createPetTreatmentDose(http, accessToken, petId, treatmentId, body),\n },\n };\n}\n"]}
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@ipetsadmin/api-client",
|
|
3
|
-
"version": "1.
|
|
3
|
+
"version": "1.3.1",
|
|
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.
|
|
41
|
+
"@ipetsadmin/contracts": "1.3.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.
|
|
55
|
+
"@ipetsadmin/contracts": ">=1.3.1"
|
|
56
56
|
},
|
|
57
57
|
"publishConfig": {
|
|
58
58
|
"access": "public"
|