@ipetsadmin/api-client 1.1.1 → 1.1.2
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/CHANGELOG.md +14 -0
- package/README.md +52 -28
- package/dist/index.d.mts +9 -2
- package/dist/index.d.ts +9 -2
- package/dist/index.js +25 -0
- package/dist/index.js.map +1 -1
- package/dist/index.mjs +24 -1
- package/dist/index.mjs.map +1 -1
- package/package.json +3 -3
package/CHANGELOG.md
CHANGED
|
@@ -19,6 +19,20 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0
|
|
|
19
19
|
|
|
20
20
|
### Security
|
|
21
21
|
|
|
22
|
+
## [1.1.2] - 2026-04-25
|
|
23
|
+
|
|
24
|
+
### Added
|
|
25
|
+
|
|
26
|
+
- **User profile** ([`src/endpoints/user.ts`](./src/endpoints/user.ts)):
|
|
27
|
+
- **`getUserProfile`** — `GET /api/v1/users/me/profile` — `IApiResponse<UserProfileResponse>`; requires **Bearer** `accessToken` (same pattern as **`getMe`**).
|
|
28
|
+
- **`patchUserProfile`** — `PATCH /api/v1/users/me/profile` — body **`PatchUserProfileInput`** (no **`avatar`**); **Bearer** `accessToken`.
|
|
29
|
+
- **`createApiClient`** exposes a **`users`** namespace: **`getProfile(accessToken)`** and **`patchProfile(accessToken, body)`** (delegates to the helpers above) — see [`src/create-api-client.ts`](./src/create-api-client.ts).
|
|
30
|
+
- Re-exports **`UserProfileResponse`** and **`PatchUserProfileInput`** from `@ipetsadmin/contracts` (barrel [`src/index.ts`](./src/index.ts)).
|
|
31
|
+
|
|
32
|
+
### Changed
|
|
33
|
+
|
|
34
|
+
- **Peer dependency** on **`@ipetsadmin/contracts`** is now **≥ 1.1.9** (types for profile DTOs). Dev dependency aligned for local development.
|
|
35
|
+
|
|
22
36
|
## [1.1.1] - 2026-04-25
|
|
23
37
|
|
|
24
38
|
### Added
|
package/README.md
CHANGED
|
@@ -5,7 +5,7 @@ Typed HTTP client for the Truffa API. Consumed by web and mobile apps. **No bake
|
|
|
5
5
|
## Requirements
|
|
6
6
|
|
|
7
7
|
- **Node.js** ≥ 18.18
|
|
8
|
-
- **Peer dependency:** `@ipetsadmin/contracts` **≥ 1.1.
|
|
8
|
+
- **Peer dependency:** `@ipetsadmin/contracts` **≥ 1.1.9** (auth and user types: `VerifyEmailRequest`, `UserProfileResponse`, `PatchUserProfileInput`, `IApiResponse`, etc.). Use a contracts version that includes any DTO you call.
|
|
9
9
|
|
|
10
10
|
## Installation
|
|
11
11
|
|
|
@@ -17,40 +17,43 @@ npm install @ipetsadmin/api-client @ipetsadmin/contracts
|
|
|
17
17
|
|
|
18
18
|
## What ships today
|
|
19
19
|
|
|
20
|
-
| Export | Description
|
|
21
|
-
| -------------------------------------- |
|
|
22
|
-
| `createApiClient(options)` | Factory returning **`healthCheck
|
|
23
|
-
| `ApiClient` / `CreateApiClientOptions` | Typed client and `{ http: HttpClient }` options
|
|
24
|
-
| `HttpClient` | **`get`**, **`post`**, and **`patch`** (minimal surface compatible with Axios)
|
|
25
|
-
| `HttpGet` / `HttpPost` / `HttpPatch` | Method signatures
|
|
26
|
-
| Named helpers | Same calls as
|
|
20
|
+
| Export | Description |
|
|
21
|
+
| -------------------------------------- | ---------------------------------------------------------------------------------------------------------------------------------------------------------------- |
|
|
22
|
+
| `createApiClient(options)` | Factory returning **`healthCheck`**, **`auth`**, and **`users`** (profile) namespaces |
|
|
23
|
+
| `ApiClient` / `CreateApiClientOptions` | Typed client and `{ http: HttpClient }` options |
|
|
24
|
+
| `HttpClient` | **`get`**, **`post`**, and **`patch`** (minimal surface compatible with Axios) |
|
|
25
|
+
| `HttpGet` / `HttpPost` / `HttpPatch` | Method signatures |
|
|
26
|
+
| Named helpers | Same calls as the factory — see [`auth.ts`](./src/endpoints/auth.ts), [`health-check.ts`](./src/endpoints/health-check.ts), [`user.ts`](./src/endpoints/user.ts) |
|
|
27
27
|
|
|
28
28
|
### Parity with `@ipetsadmin/api-main`
|
|
29
29
|
|
|
30
|
-
The API
|
|
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** |
|
|
32
|
+
| Area | Server routes this client implements |
|
|
33
|
+
| ---------- | ------------------------------------------------------------------------------ |
|
|
34
|
+
| **Health** | `GET /api/v1/health-check` |
|
|
35
|
+
| **Auth** | Routes under `/api/v1/auth/…` |
|
|
36
|
+
| **Users** | `GET` / `PATCH` `/api/v1/users/me/profile` (`client.users.…` or named helpers) |
|
|
36
37
|
|
|
37
38
|
`api-main` also serves **OpenAPI** (`/api-docs`, `/api-docs.json`) when enabled; that is not wrapped here.
|
|
38
39
|
|
|
39
40
|
### Endpoints
|
|
40
41
|
|
|
41
|
-
| HTTP | Path | `createApiClient` | Named helper
|
|
42
|
-
| ------- | ------------------------------------------------- | ---------------------------------------------- |
|
|
43
|
-
| `GET` | `/api/v1/health-check` | `client.healthCheck()` | `fetchHealthCheck(http)`
|
|
44
|
-
| `POST` | `/api/v1/auth/register` | `client.auth.register(body)` | `postRegister(http, body)`
|
|
45
|
-
| `POST` | `/api/v1/auth/login` | `client.auth.login(body)` | `postLogin(http, body)`
|
|
46
|
-
| `GET` | `/api/v1/auth/oauth/google/start?redirectUri=...` | `client.auth.getGoogleOAuthStart(redirectUri)` | `getGoogleOAuthStart(http, redirectUri)`
|
|
47
|
-
| `POST` | `/api/v1/auth/oauth/google/callback` | `client.auth.postGoogleOAuthCallback(body)` | `postGoogleOAuthCallback(http, body)`
|
|
48
|
-
| `POST` | `/api/v1/auth/refresh` | `client.auth.refresh(body)` | `postRefresh(http, body)`
|
|
49
|
-
| `POST` | `/api/v1/auth/logout` | `client.auth.logout(body)` | `postLogout(http, body)`
|
|
50
|
-
| `PATCH` | `/api/v1/auth/verify-email` | `client.auth.verifyEmail(body)` | `patchVerifyEmail(http, body)`
|
|
51
|
-
| `GET` | `/api/v1/auth/me` | `client.auth.me(accessToken)` | `getMe(http, accessToken)`
|
|
52
|
-
|
|
53
|
-
|
|
42
|
+
| HTTP | Path | `createApiClient` | Named helper |
|
|
43
|
+
| ------- | ------------------------------------------------- | ---------------------------------------------- | ------------------------------------------- |
|
|
44
|
+
| `GET` | `/api/v1/health-check` | `client.healthCheck()` | `fetchHealthCheck(http)` |
|
|
45
|
+
| `POST` | `/api/v1/auth/register` | `client.auth.register(body)` | `postRegister(http, body)` |
|
|
46
|
+
| `POST` | `/api/v1/auth/login` | `client.auth.login(body)` | `postLogin(http, body)` |
|
|
47
|
+
| `GET` | `/api/v1/auth/oauth/google/start?redirectUri=...` | `client.auth.getGoogleOAuthStart(redirectUri)` | `getGoogleOAuthStart(http, redirectUri)` |
|
|
48
|
+
| `POST` | `/api/v1/auth/oauth/google/callback` | `client.auth.postGoogleOAuthCallback(body)` | `postGoogleOAuthCallback(http, body)` |
|
|
49
|
+
| `POST` | `/api/v1/auth/refresh` | `client.auth.refresh(body)` | `postRefresh(http, body)` |
|
|
50
|
+
| `POST` | `/api/v1/auth/logout` | `client.auth.logout(body)` | `postLogout(http, body)` |
|
|
51
|
+
| `PATCH` | `/api/v1/auth/verify-email` | `client.auth.verifyEmail(body)` | `patchVerifyEmail(http, body)` |
|
|
52
|
+
| `GET` | `/api/v1/auth/me` | `client.auth.me(accessToken)` | `getMe(http, accessToken)` |
|
|
53
|
+
| `GET` | `/api/v1/users/me/profile` | `client.users.getProfile(accessToken)` | `getUserProfile(http, accessToken)` |
|
|
54
|
+
| `PATCH` | `/api/v1/users/me/profile` | `client.users.patchProfile(accessToken, body)` | `patchUserProfile(http, accessToken, body)` |
|
|
55
|
+
|
|
56
|
+
Responses use **`IApiResponse<T>`** from contracts (`success`, `data`, etc.). Auth session payloads are **`AuthSessionResponse`** (`TokenPair` + `user`). **`logout`** returns **204** with no JSON body. **`verifyEmail`** success envelope matches the server (typically `data` may be empty). **User profile** responses use **`IApiResponse<UserProfileResponse>`**; **PATCH** must not send **`avatar`** (API rejects it).
|
|
54
57
|
|
|
55
58
|
### Usage example (Axios)
|
|
56
59
|
|
|
@@ -85,6 +88,22 @@ For **`IApiResponse<AuthSessionResponse>`**, the **envelope** is the JSON body;
|
|
|
85
88
|
|
|
86
89
|
Call **`api.auth.verifyEmail({ token })`** (or **`patchVerifyEmail`**) with the one-time token from the verification link your backend emails. Shapes: **`VerifyEmailRequest`** from `@ipetsadmin/contracts`.
|
|
87
90
|
|
|
91
|
+
### User profile (authenticated)
|
|
92
|
+
|
|
93
|
+
After you have an **access** JWT (e.g. from login or register), read or update the persisted profile (**not** the same shape as lightweight **`/auth/me`** — includes **`role`**, **`isActive`**, full **`profile`** object):
|
|
94
|
+
|
|
95
|
+
```typescript
|
|
96
|
+
// Via the client (same `api` as other sections):
|
|
97
|
+
const prof = await api.users.getProfile(accessToken);
|
|
98
|
+
// prof — IApiResponse<UserProfileResponse>
|
|
99
|
+
|
|
100
|
+
await api.users.patchProfile(accessToken, { firstName: 'Alex', lastName: 'Kim' });
|
|
101
|
+
```
|
|
102
|
+
|
|
103
|
+
Or use the named helpers with your **`http`** instance: **`getUserProfile(http, accessToken)`**, **`patchUserProfile(http, accessToken, body)`**.
|
|
104
|
+
|
|
105
|
+
Types: **`UserProfileResponse`**, **`PatchUserProfileInput`** (re-exported from this package, defined in `@ipetsadmin/contracts`).
|
|
106
|
+
|
|
88
107
|
### Why a factory?
|
|
89
108
|
|
|
90
109
|
`createApiClient({ http })` keeps env and transport out of this package, supports multiple backends in one app, and makes tests easy with a mock `http` object.
|
|
@@ -95,8 +114,8 @@ Call **`api.auth.verifyEmail({ token })`** (or **`patchVerifyEmail`**) with the
|
|
|
95
114
|
|
|
96
115
|
1. **`HttpClient`** — abstraction over **`get` / `post` / `patch`** (`{ data: T }` response shape, Axios-compatible).
|
|
97
116
|
2. **`src/endpoints/*.ts`** — thin functions: `(http, …args) => Promise<…>`.
|
|
98
|
-
3. **`createApiClient`** — wires `http` into those endpoints
|
|
99
|
-
4. **`@ipetsadmin/contracts`** — DTOs (`RegisterRequest`, `AuthSessionResponse`, `VerifyEmailRequest`, …).
|
|
117
|
+
3. **`createApiClient`** — wires `http` into those endpoints under **`healthCheck`**, **`auth`**, and **`users`**.
|
|
118
|
+
4. **`@ipetsadmin/contracts`** — DTOs (`RegisterRequest`, `AuthSessionResponse`, `VerifyEmailRequest`, `UserProfileResponse`, `PatchUserProfileInput`, …).
|
|
100
119
|
|
|
101
120
|
### Extending further
|
|
102
121
|
|
|
@@ -121,6 +140,11 @@ const http: HttpClient = {
|
|
|
121
140
|
const api = createApiClient({ http });
|
|
122
141
|
await api.healthCheck();
|
|
123
142
|
expect(http.get).toHaveBeenCalledWith('/api/v1/health-check', undefined);
|
|
143
|
+
|
|
144
|
+
await api.users.getProfile('token');
|
|
145
|
+
expect(http.get).toHaveBeenCalledWith('/api/v1/users/me/profile', {
|
|
146
|
+
headers: { Authorization: 'Bearer token' },
|
|
147
|
+
});
|
|
124
148
|
```
|
|
125
149
|
|
|
126
150
|
---
|
package/dist/index.d.mts
CHANGED
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import { RegisterRequest, IApiResponse, AuthSessionResponse, LoginRequest, OAuthGoogleStartResponse, OAuthGoogleCallbackRequest, RefreshRequest, LogoutRequest, VerifyEmailRequest, AuthUserResponse, HealthCheck } from '@ipetsadmin/contracts';
|
|
1
|
+
import { RegisterRequest, IApiResponse, AuthSessionResponse, LoginRequest, OAuthGoogleStartResponse, OAuthGoogleCallbackRequest, RefreshRequest, LogoutRequest, VerifyEmailRequest, AuthUserResponse, UserProfileResponse, PatchUserProfileInput, HealthCheck } from '@ipetsadmin/contracts';
|
|
2
2
|
|
|
3
3
|
type HttpGet = <TResponse>(url: string, config?: unknown) => Promise<{
|
|
4
4
|
data: TResponse;
|
|
@@ -24,6 +24,9 @@ declare function postLogout(http: HttpClient, body: LogoutRequest): Promise<void
|
|
|
24
24
|
declare function getMe(http: HttpClient, accessToken: string): Promise<IApiResponse<AuthUserResponse>>;
|
|
25
25
|
declare function patchVerifyEmail(http: HttpClient, body: VerifyEmailRequest): Promise<IApiResponse<void>>;
|
|
26
26
|
|
|
27
|
+
declare function getUserProfile(http: HttpClient, accessToken: string): Promise<IApiResponse<UserProfileResponse>>;
|
|
28
|
+
declare function patchUserProfile(http: HttpClient, accessToken: string, body: PatchUserProfileInput): Promise<IApiResponse<UserProfileResponse>>;
|
|
29
|
+
|
|
27
30
|
declare function fetchHealthCheck(http: HttpClient): Promise<IApiResponse<HealthCheck>>;
|
|
28
31
|
|
|
29
32
|
interface CreateApiClientOptions {
|
|
@@ -41,7 +44,11 @@ interface ApiClient {
|
|
|
41
44
|
readonly verifyEmail: (body: Parameters<typeof patchVerifyEmail>[1]) => ReturnType<typeof patchVerifyEmail>;
|
|
42
45
|
readonly me: (accessToken: string) => ReturnType<typeof getMe>;
|
|
43
46
|
};
|
|
47
|
+
readonly users: {
|
|
48
|
+
readonly getProfile: (accessToken: string) => ReturnType<typeof getUserProfile>;
|
|
49
|
+
readonly patchProfile: (accessToken: string, body: Parameters<typeof patchUserProfile>[2]) => ReturnType<typeof patchUserProfile>;
|
|
50
|
+
};
|
|
44
51
|
}
|
|
45
52
|
declare function createApiClient(options: CreateApiClientOptions): ApiClient;
|
|
46
53
|
|
|
47
|
-
export { type ApiClient, type CreateApiClientOptions, type HttpClient, type HttpGet, type HttpPatch, type HttpPost, createApiClient, getGoogleOAuthStart, getMe, patchVerifyEmail, postGoogleOAuthCallback, postLogin, postLogout, postRefresh, postRegister };
|
|
54
|
+
export { type ApiClient, type CreateApiClientOptions, type HttpClient, type HttpGet, type HttpPatch, type HttpPost, createApiClient, getGoogleOAuthStart, getMe, getUserProfile, patchUserProfile, patchVerifyEmail, postGoogleOAuthCallback, postLogin, postLogout, postRefresh, postRegister };
|
package/dist/index.d.ts
CHANGED
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import { RegisterRequest, IApiResponse, AuthSessionResponse, LoginRequest, OAuthGoogleStartResponse, OAuthGoogleCallbackRequest, RefreshRequest, LogoutRequest, VerifyEmailRequest, AuthUserResponse, HealthCheck } from '@ipetsadmin/contracts';
|
|
1
|
+
import { RegisterRequest, IApiResponse, AuthSessionResponse, LoginRequest, OAuthGoogleStartResponse, OAuthGoogleCallbackRequest, RefreshRequest, LogoutRequest, VerifyEmailRequest, AuthUserResponse, UserProfileResponse, PatchUserProfileInput, HealthCheck } from '@ipetsadmin/contracts';
|
|
2
2
|
|
|
3
3
|
type HttpGet = <TResponse>(url: string, config?: unknown) => Promise<{
|
|
4
4
|
data: TResponse;
|
|
@@ -24,6 +24,9 @@ declare function postLogout(http: HttpClient, body: LogoutRequest): Promise<void
|
|
|
24
24
|
declare function getMe(http: HttpClient, accessToken: string): Promise<IApiResponse<AuthUserResponse>>;
|
|
25
25
|
declare function patchVerifyEmail(http: HttpClient, body: VerifyEmailRequest): Promise<IApiResponse<void>>;
|
|
26
26
|
|
|
27
|
+
declare function getUserProfile(http: HttpClient, accessToken: string): Promise<IApiResponse<UserProfileResponse>>;
|
|
28
|
+
declare function patchUserProfile(http: HttpClient, accessToken: string, body: PatchUserProfileInput): Promise<IApiResponse<UserProfileResponse>>;
|
|
29
|
+
|
|
27
30
|
declare function fetchHealthCheck(http: HttpClient): Promise<IApiResponse<HealthCheck>>;
|
|
28
31
|
|
|
29
32
|
interface CreateApiClientOptions {
|
|
@@ -41,7 +44,11 @@ interface ApiClient {
|
|
|
41
44
|
readonly verifyEmail: (body: Parameters<typeof patchVerifyEmail>[1]) => ReturnType<typeof patchVerifyEmail>;
|
|
42
45
|
readonly me: (accessToken: string) => ReturnType<typeof getMe>;
|
|
43
46
|
};
|
|
47
|
+
readonly users: {
|
|
48
|
+
readonly getProfile: (accessToken: string) => ReturnType<typeof getUserProfile>;
|
|
49
|
+
readonly patchProfile: (accessToken: string, body: Parameters<typeof patchUserProfile>[2]) => ReturnType<typeof patchUserProfile>;
|
|
50
|
+
};
|
|
44
51
|
}
|
|
45
52
|
declare function createApiClient(options: CreateApiClientOptions): ApiClient;
|
|
46
53
|
|
|
47
|
-
export { type ApiClient, type CreateApiClientOptions, type HttpClient, type HttpGet, type HttpPatch, type HttpPost, createApiClient, getGoogleOAuthStart, getMe, patchVerifyEmail, postGoogleOAuthCallback, postLogin, postLogout, postRefresh, postRegister };
|
|
54
|
+
export { type ApiClient, type CreateApiClientOptions, type HttpClient, type HttpGet, type HttpPatch, type HttpPost, createApiClient, getGoogleOAuthStart, getMe, getUserProfile, patchUserProfile, patchVerifyEmail, postGoogleOAuthCallback, postLogin, postLogout, postRefresh, postRegister };
|
package/dist/index.js
CHANGED
|
@@ -54,6 +54,25 @@ async function patchVerifyEmail(http, body) {
|
|
|
54
54
|
return data;
|
|
55
55
|
}
|
|
56
56
|
|
|
57
|
+
// src/endpoints/user.ts
|
|
58
|
+
var USERS_BASE = "/api/v1/users";
|
|
59
|
+
async function getUserProfile(http, accessToken) {
|
|
60
|
+
const { data } = await http.get(`${USERS_BASE}/me/profile`, {
|
|
61
|
+
headers: { Authorization: `Bearer ${accessToken}` }
|
|
62
|
+
});
|
|
63
|
+
return data;
|
|
64
|
+
}
|
|
65
|
+
async function patchUserProfile(http, accessToken, body) {
|
|
66
|
+
const { data } = await http.patch(
|
|
67
|
+
`${USERS_BASE}/me/profile`,
|
|
68
|
+
body,
|
|
69
|
+
{
|
|
70
|
+
headers: { Authorization: `Bearer ${accessToken}` }
|
|
71
|
+
}
|
|
72
|
+
);
|
|
73
|
+
return data;
|
|
74
|
+
}
|
|
75
|
+
|
|
57
76
|
// src/endpoints/health-check.ts
|
|
58
77
|
var HEALTH_CHECK_PATH = "/api/v1/health-check";
|
|
59
78
|
async function fetchHealthCheck(http) {
|
|
@@ -75,6 +94,10 @@ function createApiClient(options) {
|
|
|
75
94
|
logout: (body) => postLogout(http, body),
|
|
76
95
|
verifyEmail: (body) => patchVerifyEmail(http, body),
|
|
77
96
|
me: (accessToken) => getMe(http, accessToken)
|
|
97
|
+
},
|
|
98
|
+
users: {
|
|
99
|
+
getProfile: (accessToken) => getUserProfile(http, accessToken),
|
|
100
|
+
patchProfile: (accessToken, body) => patchUserProfile(http, accessToken, body)
|
|
78
101
|
}
|
|
79
102
|
};
|
|
80
103
|
}
|
|
@@ -82,6 +105,8 @@ function createApiClient(options) {
|
|
|
82
105
|
exports.createApiClient = createApiClient;
|
|
83
106
|
exports.getGoogleOAuthStart = getGoogleOAuthStart;
|
|
84
107
|
exports.getMe = getMe;
|
|
108
|
+
exports.getUserProfile = getUserProfile;
|
|
109
|
+
exports.patchUserProfile = patchUserProfile;
|
|
85
110
|
exports.patchVerifyEmail = patchVerifyEmail;
|
|
86
111
|
exports.postGoogleOAuthCallback = postGoogleOAuthCallback;
|
|
87
112
|
exports.postLogin = postLogin;
|
package/dist/index.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"sources":["../src/endpoints/auth.ts","../src/endpoints/health-check.ts","../src/create-api-client.ts"],"names":[],"mappings":";;;AAeA,IAAM,SAAA,GAAY,cAAA;AAKlB,eAAsB,YAAA,CACpB,MACA,IAAA,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,EA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,EAAsD;AAC3F,EAAA,MAAM,EAAE,IAAA,EAAM,IAAA,KAAS,MAAM,IAAA,CAAK,IAA+B,iBAAiB,CAAA;AAElF,EAAA,OAAO,IAAA;AACT;;;ACyBO,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;AAC9C,GACF;AACF","file":"index.js","sourcesContent":["import type {\n AuthSessionResponse,\n AuthUserResponse,\n IApiResponse,\n LoginRequest,\n LogoutRequest,\n OAuthGoogleCallbackRequest,\n OAuthGoogleStartResponse,\n RefreshRequest,\n RegisterRequest,\n VerifyEmailRequest,\n} from '@ipetsadmin/contracts';\n\nimport type { HttpClient } from '../http-client';\n\nconst AUTH_BASE = '/api/v1/auth' as const;\n\n/**\n * POST /api/v1/auth/register\n */\nexport async function postRegister(\n http: HttpClient,\n body: RegisterRequest,\n): Promise<IApiResponse<AuthSessionResponse>> {\n const { data } = await http.post<IApiResponse<AuthSessionResponse>, RegisterRequest>(\n `${AUTH_BASE}/register`,\n body,\n );\n return data;\n}\n\n/**\n * POST /api/v1/auth/login\n */\nexport async function postLogin(\n http: HttpClient,\n body: LoginRequest,\n): Promise<IApiResponse<AuthSessionResponse>> {\n const { data } = await http.post<IApiResponse<AuthSessionResponse>, LoginRequest>(\n `${AUTH_BASE}/login`,\n body,\n );\n return data;\n}\n\n/**\n * GET /api/v1/auth/oauth/google/start?redirectUri=...\n */\nexport async function getGoogleOAuthStart(\n http: HttpClient,\n redirectUri: string,\n): Promise<IApiResponse<OAuthGoogleStartResponse>> {\n const q = new URLSearchParams({ redirectUri });\n const { data } = await http.get<IApiResponse<OAuthGoogleStartResponse>>(\n `${AUTH_BASE}/oauth/google/start?${q.toString()}`,\n );\n return data;\n}\n\n/**\n * POST /api/v1/auth/oauth/google/callback\n */\nexport async function postGoogleOAuthCallback(\n http: HttpClient,\n body: OAuthGoogleCallbackRequest,\n): Promise<IApiResponse<AuthSessionResponse>> {\n const { data } = await http.post<IApiResponse<AuthSessionResponse>, OAuthGoogleCallbackRequest>(\n `${AUTH_BASE}/oauth/google/callback`,\n body,\n );\n return data;\n}\n\n/**\n * POST /api/v1/auth/refresh\n */\nexport async function postRefresh(\n http: HttpClient,\n body: RefreshRequest,\n): Promise<IApiResponse<AuthSessionResponse>> {\n const { data } = await http.post<IApiResponse<AuthSessionResponse>, RefreshRequest>(\n `${AUTH_BASE}/refresh`,\n body,\n );\n return data;\n}\n\n/**\n * POST /api/v1/auth/logout — 204 No Content (no JSON body).\n */\nexport async function postLogout(http: HttpClient, body: LogoutRequest): Promise<void> {\n await http.post<undefined, LogoutRequest>(`${AUTH_BASE}/logout`, body);\n}\n\n/**\n * GET /api/v1/auth/me — requires `Authorization: Bearer <accessToken>`.\n */\nexport async function getMe(\n http: HttpClient,\n accessToken: string,\n): Promise<IApiResponse<AuthUserResponse>> {\n const { data } = await http.get<IApiResponse<AuthUserResponse>>(`${AUTH_BASE}/me`, {\n headers: { Authorization: `Bearer ${accessToken}` },\n });\n return data;\n}\n\n/**\n * PATCH /api/v1/auth/verify-email\n */\nexport async function patchVerifyEmail(\n http: HttpClient,\n body: VerifyEmailRequest,\n): Promise<IApiResponse<void>> {\n const { data } = await http.patch<IApiResponse<void>, VerifyEmailRequest>(\n `${AUTH_BASE}/verify-email`,\n body,\n );\n return data;\n}\n","import type { IApiResponse, HealthCheck } from '@ipetsadmin/contracts';\nimport type { HttpClient } from '../http-client';\n\n/** Same path as `/api/${v1}/health-check` on the server when `v1` is the string `'v1'`. */\nconst HEALTH_CHECK_PATH = '/api/v1/health-check' as const;\n\n/**\n * GET /api/v1/health-check — server liveness.\n *\n * Returns the full JSON the server sends (`IApiResponse<HealthCheck>`).\n *\n * **Why not `data.data` here?** Adapters like Axios wrap the HTTP body in a property also\n * called `data`. That outer `data` is the entire `res.json(...)` object. The inner\n * `IApiResponse.data` is the `HealthCheck` payload — use `.data` on the **returned** value,\n * e.g. `(await fetchHealthCheck(http)).data`.\n */\nexport async function fetchHealthCheck(http: HttpClient): Promise<IApiResponse<HealthCheck>> {\n const { data: body } = await http.get<IApiResponse<HealthCheck>>(HEALTH_CHECK_PATH);\n\n return body;\n}\n","import {\n getGoogleOAuthStart,\n getMe,\n patchVerifyEmail,\n postGoogleOAuthCallback,\n postLogin,\n postLogout,\n postRefresh,\n postRegister,\n} from './endpoints/auth';\nimport { fetchHealthCheck } from './endpoints/health-check';\nimport type { HttpClient } from './http-client';\n\nexport interface CreateApiClientOptions {\n /**\n * Preconfigured HTTP client (e.g. Axios instance with `baseURL` set).\n * Paths in this library are relative to that base (e.g. `/api/v1/...`).\n * Both `get` and `post` are required for auth flows.\n */\n readonly http: HttpClient;\n}\n\nexport interface ApiClient {\n readonly healthCheck: () => ReturnType<typeof fetchHealthCheck>;\n readonly auth: {\n readonly register: (\n body: Parameters<typeof postRegister>[1],\n ) => ReturnType<typeof postRegister>;\n readonly login: (body: Parameters<typeof postLogin>[1]) => ReturnType<typeof postLogin>;\n readonly getGoogleOAuthStart: (redirectUri: string) => ReturnType<typeof getGoogleOAuthStart>;\n readonly postGoogleOAuthCallback: (\n body: Parameters<typeof postGoogleOAuthCallback>[1],\n ) => ReturnType<typeof postGoogleOAuthCallback>;\n readonly refresh: (body: Parameters<typeof postRefresh>[1]) => ReturnType<typeof postRefresh>;\n readonly logout: (body: Parameters<typeof postLogout>[1]) => ReturnType<typeof postLogout>;\n readonly verifyEmail: (\n body: Parameters<typeof patchVerifyEmail>[1],\n ) => ReturnType<typeof patchVerifyEmail>;\n readonly me: (accessToken: string) => ReturnType<typeof getMe>;\n };\n}\n\n/**\n * Creates a typed API client backed by the provided HTTP implementation.\n */\nexport function createApiClient(options: CreateApiClientOptions): ApiClient {\n const { http } = options;\n\n return {\n healthCheck: () => fetchHealthCheck(http),\n auth: {\n register: (body) => postRegister(http, body),\n login: (body) => postLogin(http, body),\n getGoogleOAuthStart: (redirectUri) => getGoogleOAuthStart(http, redirectUri),\n postGoogleOAuthCallback: (body) => postGoogleOAuthCallback(http, body),\n refresh: (body) => postRefresh(http, body),\n logout: (body) => postLogout(http, body),\n verifyEmail: (body) => patchVerifyEmail(http, body),\n me: (accessToken) => getMe(http, accessToken),\n },\n };\n}\n"]}
|
|
1
|
+
{"version":3,"sources":["../src/endpoints/auth.ts","../src/endpoints/user.ts","../src/endpoints/health-check.ts","../src/create-api-client.ts"],"names":[],"mappings":";;;AAeA,IAAM,SAAA,GAAY,cAAA;AAKlB,eAAsB,YAAA,CACpB,MACA,IAAA,EAC4C;AAC5C,EAAA,MAAM,EAAE,IAAA,EAAK,GAAI,MAAM,IAAA,CAAK,IAAA;AAAA,IAC1B,GAAG,SAAS,CAAA,SAAA,CAAA;AAAA,IACZ;AAAA,GACF;AACA,EAAA,OAAO,IAAA;AACT;AAKA,eAAsB,SAAA,CACpB,MACA,IAAA,EAC4C;AAC5C,EAAA,MAAM,EAAE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A,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.js","sourcesContent":["import type {\n AuthSessionResponse,\n AuthUserResponse,\n IApiResponse,\n LoginRequest,\n LogoutRequest,\n OAuthGoogleCallbackRequest,\n OAuthGoogleStartResponse,\n RefreshRequest,\n RegisterRequest,\n VerifyEmailRequest,\n} from '@ipetsadmin/contracts';\n\nimport type { HttpClient } from '../http-client';\n\nconst AUTH_BASE = '/api/v1/auth' as const;\n\n/**\n * POST /api/v1/auth/register\n */\nexport async function postRegister(\n http: HttpClient,\n body: RegisterRequest,\n): Promise<IApiResponse<AuthSessionResponse>> {\n const { data } = await http.post<IApiResponse<AuthSessionResponse>, RegisterRequest>(\n `${AUTH_BASE}/register`,\n body,\n );\n return data;\n}\n\n/**\n * POST /api/v1/auth/login\n */\nexport async function postLogin(\n http: HttpClient,\n body: LoginRequest,\n): Promise<IApiResponse<AuthSessionResponse>> {\n const { data } = await http.post<IApiResponse<AuthSessionResponse>, LoginRequest>(\n `${AUTH_BASE}/login`,\n body,\n );\n return data;\n}\n\n/**\n * GET /api/v1/auth/oauth/google/start?redirectUri=...\n */\nexport async function getGoogleOAuthStart(\n http: HttpClient,\n redirectUri: string,\n): Promise<IApiResponse<OAuthGoogleStartResponse>> {\n const q = new URLSearchParams({ redirectUri });\n const { data } = await http.get<IApiResponse<OAuthGoogleStartResponse>>(\n `${AUTH_BASE}/oauth/google/start?${q.toString()}`,\n );\n return data;\n}\n\n/**\n * POST /api/v1/auth/oauth/google/callback\n */\nexport async function postGoogleOAuthCallback(\n http: HttpClient,\n body: OAuthGoogleCallbackRequest,\n): Promise<IApiResponse<AuthSessionResponse>> {\n const { data } = await http.post<IApiResponse<AuthSessionResponse>, OAuthGoogleCallbackRequest>(\n `${AUTH_BASE}/oauth/google/callback`,\n body,\n );\n return data;\n}\n\n/**\n * POST /api/v1/auth/refresh\n */\nexport async function postRefresh(\n http: HttpClient,\n body: RefreshRequest,\n): Promise<IApiResponse<AuthSessionResponse>> {\n const { data } = await http.post<IApiResponse<AuthSessionResponse>, RefreshRequest>(\n `${AUTH_BASE}/refresh`,\n body,\n );\n return data;\n}\n\n/**\n * POST /api/v1/auth/logout — 204 No Content (no JSON body).\n */\nexport async function postLogout(http: HttpClient, body: LogoutRequest): Promise<void> {\n await http.post<undefined, LogoutRequest>(`${AUTH_BASE}/logout`, body);\n}\n\n/**\n * GET /api/v1/auth/me — requires `Authorization: Bearer <accessToken>`.\n */\nexport async function getMe(\n http: HttpClient,\n accessToken: string,\n): Promise<IApiResponse<AuthUserResponse>> {\n const { data } = await http.get<IApiResponse<AuthUserResponse>>(`${AUTH_BASE}/me`, {\n headers: { Authorization: `Bearer ${accessToken}` },\n });\n return data;\n}\n\n/**\n * PATCH /api/v1/auth/verify-email\n */\nexport async function patchVerifyEmail(\n http: HttpClient,\n body: VerifyEmailRequest,\n): Promise<IApiResponse<void>> {\n const { data } = await http.patch<IApiResponse<void>, VerifyEmailRequest>(\n `${AUTH_BASE}/verify-email`,\n body,\n );\n return data;\n}\n","import type {\n IApiResponse,\n PatchUserProfileInput,\n UserProfileResponse,\n} from '@ipetsadmin/contracts';\n\nimport type { HttpClient } from '../http-client';\n\nconst USERS_BASE = '/api/v1/users' as const;\n\n/**\n * GET /api/v1/users/me/profile — requires `Authorization: Bearer <accessToken>`.\n */\nexport async function getUserProfile(\n http: HttpClient,\n accessToken: string,\n): Promise<IApiResponse<UserProfileResponse>> {\n const { data } = await http.get<IApiResponse<UserProfileResponse>>(`${USERS_BASE}/me/profile`, {\n headers: { Authorization: `Bearer ${accessToken}` },\n });\n return data;\n}\n\n/**\n * PATCH /api/v1/users/me/profile — requires `Authorization: Bearer <accessToken>`.\n * Body must not include `avatar` (API rejects unknown keys in strict mode).\n */\nexport async function patchUserProfile(\n http: HttpClient,\n accessToken: string,\n body: PatchUserProfileInput,\n): Promise<IApiResponse<UserProfileResponse>> {\n const { data } = await http.patch<IApiResponse<UserProfileResponse>, PatchUserProfileInput>(\n `${USERS_BASE}/me/profile`,\n body,\n {\n headers: { Authorization: `Bearer ${accessToken}` },\n },\n );\n return data;\n}\n","import type { IApiResponse, HealthCheck } from '@ipetsadmin/contracts';\nimport type { HttpClient } from '../http-client';\n\n/** Same path as `/api/${v1}/health-check` on the server when `v1` is the string `'v1'`. */\nconst HEALTH_CHECK_PATH = '/api/v1/health-check' as const;\n\n/**\n * GET /api/v1/health-check — server liveness.\n *\n * Returns the full JSON the server sends (`IApiResponse<HealthCheck>`).\n *\n * **Why not `data.data` here?** Adapters like Axios wrap the HTTP body in a property also\n * called `data`. That outer `data` is the entire `res.json(...)` object. The inner\n * `IApiResponse.data` is the `HealthCheck` payload — use `.data` on the **returned** value,\n * e.g. `(await fetchHealthCheck(http)).data`.\n */\nexport async function fetchHealthCheck(http: HttpClient): Promise<IApiResponse<HealthCheck>> {\n const { data: body } = await http.get<IApiResponse<HealthCheck>>(HEALTH_CHECK_PATH);\n\n return body;\n}\n","import {\n getGoogleOAuthStart,\n getMe,\n patchVerifyEmail,\n postGoogleOAuthCallback,\n postLogin,\n postLogout,\n postRefresh,\n postRegister,\n} from './endpoints/auth';\nimport { getUserProfile, patchUserProfile } from './endpoints/user';\nimport { fetchHealthCheck } from './endpoints/health-check';\nimport type { HttpClient } from './http-client';\n\nexport interface CreateApiClientOptions {\n /**\n * Preconfigured HTTP client (e.g. Axios instance with `baseURL` set).\n * Paths in this library are relative to that base (e.g. `/api/v1/...`).\n * Both `get` and `post` are required for auth flows.\n */\n readonly http: HttpClient;\n}\n\nexport interface ApiClient {\n readonly healthCheck: () => ReturnType<typeof fetchHealthCheck>;\n readonly auth: {\n readonly register: (\n body: Parameters<typeof postRegister>[1],\n ) => ReturnType<typeof postRegister>;\n readonly login: (body: Parameters<typeof postLogin>[1]) => ReturnType<typeof postLogin>;\n readonly getGoogleOAuthStart: (redirectUri: string) => ReturnType<typeof getGoogleOAuthStart>;\n readonly postGoogleOAuthCallback: (\n body: Parameters<typeof postGoogleOAuthCallback>[1],\n ) => ReturnType<typeof postGoogleOAuthCallback>;\n readonly refresh: (body: Parameters<typeof postRefresh>[1]) => ReturnType<typeof postRefresh>;\n readonly logout: (body: Parameters<typeof postLogout>[1]) => ReturnType<typeof postLogout>;\n readonly verifyEmail: (\n body: Parameters<typeof patchVerifyEmail>[1],\n ) => ReturnType<typeof patchVerifyEmail>;\n readonly me: (accessToken: string) => ReturnType<typeof getMe>;\n };\n readonly users: {\n readonly getProfile: (accessToken: string) => ReturnType<typeof getUserProfile>;\n readonly patchProfile: (\n accessToken: string,\n body: Parameters<typeof patchUserProfile>[2],\n ) => ReturnType<typeof patchUserProfile>;\n };\n}\n\n/**\n * Creates a typed API client backed by the provided HTTP implementation.\n */\nexport function createApiClient(options: CreateApiClientOptions): ApiClient {\n const { http } = options;\n\n return {\n healthCheck: () => fetchHealthCheck(http),\n auth: {\n register: (body) => postRegister(http, body),\n login: (body) => postLogin(http, body),\n getGoogleOAuthStart: (redirectUri) => getGoogleOAuthStart(http, redirectUri),\n postGoogleOAuthCallback: (body) => postGoogleOAuthCallback(http, body),\n refresh: (body) => postRefresh(http, body),\n logout: (body) => postLogout(http, body),\n verifyEmail: (body) => patchVerifyEmail(http, body),\n me: (accessToken) => getMe(http, accessToken),\n },\n users: {\n getProfile: (accessToken) => getUserProfile(http, accessToken),\n patchProfile: (accessToken, body) => patchUserProfile(http, accessToken, body),\n },\n };\n}\n"]}
|
package/dist/index.mjs
CHANGED
|
@@ -52,6 +52,25 @@ async function patchVerifyEmail(http, body) {
|
|
|
52
52
|
return data;
|
|
53
53
|
}
|
|
54
54
|
|
|
55
|
+
// src/endpoints/user.ts
|
|
56
|
+
var USERS_BASE = "/api/v1/users";
|
|
57
|
+
async function getUserProfile(http, accessToken) {
|
|
58
|
+
const { data } = await http.get(`${USERS_BASE}/me/profile`, {
|
|
59
|
+
headers: { Authorization: `Bearer ${accessToken}` }
|
|
60
|
+
});
|
|
61
|
+
return data;
|
|
62
|
+
}
|
|
63
|
+
async function patchUserProfile(http, accessToken, body) {
|
|
64
|
+
const { data } = await http.patch(
|
|
65
|
+
`${USERS_BASE}/me/profile`,
|
|
66
|
+
body,
|
|
67
|
+
{
|
|
68
|
+
headers: { Authorization: `Bearer ${accessToken}` }
|
|
69
|
+
}
|
|
70
|
+
);
|
|
71
|
+
return data;
|
|
72
|
+
}
|
|
73
|
+
|
|
55
74
|
// src/endpoints/health-check.ts
|
|
56
75
|
var HEALTH_CHECK_PATH = "/api/v1/health-check";
|
|
57
76
|
async function fetchHealthCheck(http) {
|
|
@@ -73,10 +92,14 @@ function createApiClient(options) {
|
|
|
73
92
|
logout: (body) => postLogout(http, body),
|
|
74
93
|
verifyEmail: (body) => patchVerifyEmail(http, body),
|
|
75
94
|
me: (accessToken) => getMe(http, accessToken)
|
|
95
|
+
},
|
|
96
|
+
users: {
|
|
97
|
+
getProfile: (accessToken) => getUserProfile(http, accessToken),
|
|
98
|
+
patchProfile: (accessToken, body) => patchUserProfile(http, accessToken, body)
|
|
76
99
|
}
|
|
77
100
|
};
|
|
78
101
|
}
|
|
79
102
|
|
|
80
|
-
export { createApiClient, getGoogleOAuthStart, getMe, patchVerifyEmail, postGoogleOAuthCallback, postLogin, postLogout, postRefresh, postRegister };
|
|
103
|
+
export { createApiClient, getGoogleOAuthStart, getMe, getUserProfile, patchUserProfile, patchVerifyEmail, postGoogleOAuthCallback, postLogin, postLogout, postRefresh, postRegister };
|
|
81
104
|
//# sourceMappingURL=index.mjs.map
|
|
82
105
|
//# sourceMappingURL=index.mjs.map
|
package/dist/index.mjs.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"sources":["../src/endpoints/auth.ts","../src/endpoints/health-check.ts","../src/create-api-client.ts"],"names":[],"mappings":";AAeA,IAAM,SAAA,GAAY,cAAA;AAKlB,eAAsB,YAAA,CACpB,MACA,IAAA,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,C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AA,CAAK,IAA+B,iBAAiB,CAAA;AAElF,EAAA,OAAO,IAAA;AACT;;;ACyBO,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;AAC9C,GACF;AACF","file":"index.mjs","sourcesContent":["import type {\n AuthSessionResponse,\n AuthUserResponse,\n IApiResponse,\n LoginRequest,\n LogoutRequest,\n OAuthGoogleCallbackRequest,\n OAuthGoogleStartResponse,\n RefreshRequest,\n RegisterRequest,\n VerifyEmailRequest,\n} from '@ipetsadmin/contracts';\n\nimport type { HttpClient } from '../http-client';\n\nconst AUTH_BASE = '/api/v1/auth' as const;\n\n/**\n * POST /api/v1/auth/register\n */\nexport async function postRegister(\n http: HttpClient,\n body: RegisterRequest,\n): Promise<IApiResponse<AuthSessionResponse>> {\n const { data } = await http.post<IApiResponse<AuthSessionResponse>, RegisterRequest>(\n `${AUTH_BASE}/register`,\n body,\n );\n return data;\n}\n\n/**\n * POST /api/v1/auth/login\n */\nexport async function postLogin(\n http: HttpClient,\n body: LoginRequest,\n): Promise<IApiResponse<AuthSessionResponse>> {\n const { data } = await http.post<IApiResponse<AuthSessionResponse>, LoginRequest>(\n `${AUTH_BASE}/login`,\n body,\n );\n return data;\n}\n\n/**\n * GET /api/v1/auth/oauth/google/start?redirectUri=...\n */\nexport async function getGoogleOAuthStart(\n http: HttpClient,\n redirectUri: string,\n): Promise<IApiResponse<OAuthGoogleStartResponse>> {\n const q = new URLSearchParams({ redirectUri });\n const { data } = await http.get<IApiResponse<OAuthGoogleStartResponse>>(\n `${AUTH_BASE}/oauth/google/start?${q.toString()}`,\n );\n return data;\n}\n\n/**\n * POST /api/v1/auth/oauth/google/callback\n */\nexport async function postGoogleOAuthCallback(\n http: HttpClient,\n body: OAuthGoogleCallbackRequest,\n): Promise<IApiResponse<AuthSessionResponse>> {\n const { data } = await http.post<IApiResponse<AuthSessionResponse>, OAuthGoogleCallbackRequest>(\n `${AUTH_BASE}/oauth/google/callback`,\n body,\n );\n return data;\n}\n\n/**\n * POST /api/v1/auth/refresh\n */\nexport async function postRefresh(\n http: HttpClient,\n body: RefreshRequest,\n): Promise<IApiResponse<AuthSessionResponse>> {\n const { data } = await http.post<IApiResponse<AuthSessionResponse>, RefreshRequest>(\n `${AUTH_BASE}/refresh`,\n body,\n );\n return data;\n}\n\n/**\n * POST /api/v1/auth/logout — 204 No Content (no JSON body).\n */\nexport async function postLogout(http: HttpClient, body: LogoutRequest): Promise<void> {\n await http.post<undefined, LogoutRequest>(`${AUTH_BASE}/logout`, body);\n}\n\n/**\n * GET /api/v1/auth/me — requires `Authorization: Bearer <accessToken>`.\n */\nexport async function getMe(\n http: HttpClient,\n accessToken: string,\n): Promise<IApiResponse<AuthUserResponse>> {\n const { data } = await http.get<IApiResponse<AuthUserResponse>>(`${AUTH_BASE}/me`, {\n headers: { Authorization: `Bearer ${accessToken}` },\n });\n return data;\n}\n\n/**\n * PATCH /api/v1/auth/verify-email\n */\nexport async function patchVerifyEmail(\n http: HttpClient,\n body: VerifyEmailRequest,\n): Promise<IApiResponse<void>> {\n const { data } = await http.patch<IApiResponse<void>, VerifyEmailRequest>(\n `${AUTH_BASE}/verify-email`,\n body,\n );\n return data;\n}\n","import type { IApiResponse, HealthCheck } from '@ipetsadmin/contracts';\nimport type { HttpClient } from '../http-client';\n\n/** Same path as `/api/${v1}/health-check` on the server when `v1` is the string `'v1'`. */\nconst HEALTH_CHECK_PATH = '/api/v1/health-check' as const;\n\n/**\n * GET /api/v1/health-check — server liveness.\n *\n * Returns the full JSON the server sends (`IApiResponse<HealthCheck>`).\n *\n * **Why not `data.data` here?** Adapters like Axios wrap the HTTP body in a property also\n * called `data`. That outer `data` is the entire `res.json(...)` object. The inner\n * `IApiResponse.data` is the `HealthCheck` payload — use `.data` on the **returned** value,\n * e.g. `(await fetchHealthCheck(http)).data`.\n */\nexport async function fetchHealthCheck(http: HttpClient): Promise<IApiResponse<HealthCheck>> {\n const { data: body } = await http.get<IApiResponse<HealthCheck>>(HEALTH_CHECK_PATH);\n\n return body;\n}\n","import {\n getGoogleOAuthStart,\n getMe,\n patchVerifyEmail,\n postGoogleOAuthCallback,\n postLogin,\n postLogout,\n postRefresh,\n postRegister,\n} from './endpoints/auth';\nimport { fetchHealthCheck } from './endpoints/health-check';\nimport type { HttpClient } from './http-client';\n\nexport interface CreateApiClientOptions {\n /**\n * Preconfigured HTTP client (e.g. Axios instance with `baseURL` set).\n * Paths in this library are relative to that base (e.g. `/api/v1/...`).\n * Both `get` and `post` are required for auth flows.\n */\n readonly http: HttpClient;\n}\n\nexport interface ApiClient {\n readonly healthCheck: () => ReturnType<typeof fetchHealthCheck>;\n readonly auth: {\n readonly register: (\n body: Parameters<typeof postRegister>[1],\n ) => ReturnType<typeof postRegister>;\n readonly login: (body: Parameters<typeof postLogin>[1]) => ReturnType<typeof postLogin>;\n readonly getGoogleOAuthStart: (redirectUri: string) => ReturnType<typeof getGoogleOAuthStart>;\n readonly postGoogleOAuthCallback: (\n body: Parameters<typeof postGoogleOAuthCallback>[1],\n ) => ReturnType<typeof postGoogleOAuthCallback>;\n readonly refresh: (body: Parameters<typeof postRefresh>[1]) => ReturnType<typeof postRefresh>;\n readonly logout: (body: Parameters<typeof postLogout>[1]) => ReturnType<typeof postLogout>;\n readonly verifyEmail: (\n body: Parameters<typeof patchVerifyEmail>[1],\n ) => ReturnType<typeof patchVerifyEmail>;\n readonly me: (accessToken: string) => ReturnType<typeof getMe>;\n };\n}\n\n/**\n * Creates a typed API client backed by the provided HTTP implementation.\n */\nexport function createApiClient(options: CreateApiClientOptions): ApiClient {\n const { http } = options;\n\n return {\n healthCheck: () => fetchHealthCheck(http),\n auth: {\n register: (body) => postRegister(http, body),\n login: (body) => postLogin(http, body),\n getGoogleOAuthStart: (redirectUri) => getGoogleOAuthStart(http, redirectUri),\n postGoogleOAuthCallback: (body) => postGoogleOAuthCallback(http, body),\n refresh: (body) => postRefresh(http, body),\n logout: (body) => postLogout(http, body),\n verifyEmail: (body) => patchVerifyEmail(http, body),\n me: (accessToken) => getMe(http, accessToken),\n },\n };\n}\n"]}
|
|
1
|
+
{"version":3,"sources":["../src/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,SAA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3C,KAAA,EAAO,CAAC,IAAA,KAAS,SAAA,CAAU,MAAM,IAAI,CAAA;AAAA,MACrC,mBAAA,EAAqB,CAAC,WAAA,KAAgB,mBAAA,CAAoB,MAAM,WAAW,CAAA;AAAA,MAC3E,uBAAA,EAAyB,CAAC,IAAA,KAAS,uBAAA,CAAwB,MAAM,IAAI,CAAA;AAAA,MACrE,OAAA,EAAS,CAAC,IAAA,KAAS,WAAA,CAAY,MAAM,IAAI,CAAA;AAAA,MACzC,MAAA,EAAQ,CAAC,IAAA,KAAS,UAAA,CAAW,MAAM,IAAI,CAAA;AAAA,MACvC,WAAA,EAAa,CAAC,IAAA,KAAS,gBAAA,CAAiB,MAAM,IAAI,CAAA;AAAA,MAClD,EAAA,EAAI,CAAC,WAAA,KAAgB,KAAA,CAAM,MAAM,WAAW;AAAA,KAC9C;AAAA,IACA,KAAA,EAAO;AAAA,MACL,UAAA,EAAY,CAAC,WAAA,KAAgB,cAAA,CAAe,MAAM,WAAW,CAAA;AAAA,MAC7D,cAAc,CAAC,WAAA,EAAa,SAAS,gBAAA,CAAiB,IAAA,EAAM,aAAa,IAAI;AAAA;AAC/E,GACF;AACF","file":"index.mjs","sourcesContent":["import type {\n AuthSessionResponse,\n AuthUserResponse,\n IApiResponse,\n LoginRequest,\n LogoutRequest,\n OAuthGoogleCallbackRequest,\n OAuthGoogleStartResponse,\n RefreshRequest,\n RegisterRequest,\n VerifyEmailRequest,\n} from '@ipetsadmin/contracts';\n\nimport type { HttpClient } from '../http-client';\n\nconst AUTH_BASE = '/api/v1/auth' as const;\n\n/**\n * POST /api/v1/auth/register\n */\nexport async function postRegister(\n http: HttpClient,\n body: RegisterRequest,\n): Promise<IApiResponse<AuthSessionResponse>> {\n const { data } = await http.post<IApiResponse<AuthSessionResponse>, RegisterRequest>(\n `${AUTH_BASE}/register`,\n body,\n );\n return data;\n}\n\n/**\n * POST /api/v1/auth/login\n */\nexport async function postLogin(\n http: HttpClient,\n body: LoginRequest,\n): Promise<IApiResponse<AuthSessionResponse>> {\n const { data } = await http.post<IApiResponse<AuthSessionResponse>, LoginRequest>(\n `${AUTH_BASE}/login`,\n body,\n );\n return data;\n}\n\n/**\n * GET /api/v1/auth/oauth/google/start?redirectUri=...\n */\nexport async function getGoogleOAuthStart(\n http: HttpClient,\n redirectUri: string,\n): Promise<IApiResponse<OAuthGoogleStartResponse>> {\n const q = new URLSearchParams({ redirectUri });\n const { data } = await http.get<IApiResponse<OAuthGoogleStartResponse>>(\n `${AUTH_BASE}/oauth/google/start?${q.toString()}`,\n );\n return data;\n}\n\n/**\n * POST /api/v1/auth/oauth/google/callback\n */\nexport async function postGoogleOAuthCallback(\n http: HttpClient,\n body: OAuthGoogleCallbackRequest,\n): Promise<IApiResponse<AuthSessionResponse>> {\n const { data } = await http.post<IApiResponse<AuthSessionResponse>, OAuthGoogleCallbackRequest>(\n `${AUTH_BASE}/oauth/google/callback`,\n body,\n );\n return data;\n}\n\n/**\n * POST /api/v1/auth/refresh\n */\nexport async function postRefresh(\n http: HttpClient,\n body: RefreshRequest,\n): Promise<IApiResponse<AuthSessionResponse>> {\n const { data } = await http.post<IApiResponse<AuthSessionResponse>, RefreshRequest>(\n `${AUTH_BASE}/refresh`,\n body,\n );\n return data;\n}\n\n/**\n * POST /api/v1/auth/logout — 204 No Content (no JSON body).\n */\nexport async function postLogout(http: HttpClient, body: LogoutRequest): Promise<void> {\n await http.post<undefined, LogoutRequest>(`${AUTH_BASE}/logout`, body);\n}\n\n/**\n * GET /api/v1/auth/me — requires `Authorization: Bearer <accessToken>`.\n */\nexport async function getMe(\n http: HttpClient,\n accessToken: string,\n): Promise<IApiResponse<AuthUserResponse>> {\n const { data } = await http.get<IApiResponse<AuthUserResponse>>(`${AUTH_BASE}/me`, {\n headers: { Authorization: `Bearer ${accessToken}` },\n });\n return data;\n}\n\n/**\n * PATCH /api/v1/auth/verify-email\n */\nexport async function patchVerifyEmail(\n http: HttpClient,\n body: VerifyEmailRequest,\n): Promise<IApiResponse<void>> {\n const { data } = await http.patch<IApiResponse<void>, VerifyEmailRequest>(\n `${AUTH_BASE}/verify-email`,\n body,\n );\n return data;\n}\n","import type {\n IApiResponse,\n PatchUserProfileInput,\n UserProfileResponse,\n} from '@ipetsadmin/contracts';\n\nimport type { HttpClient } from '../http-client';\n\nconst USERS_BASE = '/api/v1/users' as const;\n\n/**\n * GET /api/v1/users/me/profile — requires `Authorization: Bearer <accessToken>`.\n */\nexport async function getUserProfile(\n http: HttpClient,\n accessToken: string,\n): Promise<IApiResponse<UserProfileResponse>> {\n const { data } = await http.get<IApiResponse<UserProfileResponse>>(`${USERS_BASE}/me/profile`, {\n headers: { Authorization: `Bearer ${accessToken}` },\n });\n return data;\n}\n\n/**\n * PATCH /api/v1/users/me/profile — requires `Authorization: Bearer <accessToken>`.\n * Body must not include `avatar` (API rejects unknown keys in strict mode).\n */\nexport async function patchUserProfile(\n http: HttpClient,\n accessToken: string,\n body: PatchUserProfileInput,\n): Promise<IApiResponse<UserProfileResponse>> {\n const { data } = await http.patch<IApiResponse<UserProfileResponse>, PatchUserProfileInput>(\n `${USERS_BASE}/me/profile`,\n body,\n {\n headers: { Authorization: `Bearer ${accessToken}` },\n },\n );\n return data;\n}\n","import type { IApiResponse, HealthCheck } from '@ipetsadmin/contracts';\nimport type { HttpClient } from '../http-client';\n\n/** Same path as `/api/${v1}/health-check` on the server when `v1` is the string `'v1'`. */\nconst HEALTH_CHECK_PATH = '/api/v1/health-check' as const;\n\n/**\n * GET /api/v1/health-check — server liveness.\n *\n * Returns the full JSON the server sends (`IApiResponse<HealthCheck>`).\n *\n * **Why not `data.data` here?** Adapters like Axios wrap the HTTP body in a property also\n * called `data`. That outer `data` is the entire `res.json(...)` object. The inner\n * `IApiResponse.data` is the `HealthCheck` payload — use `.data` on the **returned** value,\n * e.g. `(await fetchHealthCheck(http)).data`.\n */\nexport async function fetchHealthCheck(http: HttpClient): Promise<IApiResponse<HealthCheck>> {\n const { data: body } = await http.get<IApiResponse<HealthCheck>>(HEALTH_CHECK_PATH);\n\n return body;\n}\n","import {\n getGoogleOAuthStart,\n getMe,\n patchVerifyEmail,\n postGoogleOAuthCallback,\n postLogin,\n postLogout,\n postRefresh,\n postRegister,\n} from './endpoints/auth';\nimport { getUserProfile, patchUserProfile } from './endpoints/user';\nimport { fetchHealthCheck } from './endpoints/health-check';\nimport type { HttpClient } from './http-client';\n\nexport interface CreateApiClientOptions {\n /**\n * Preconfigured HTTP client (e.g. Axios instance with `baseURL` set).\n * Paths in this library are relative to that base (e.g. `/api/v1/...`).\n * Both `get` and `post` are required for auth flows.\n */\n readonly http: HttpClient;\n}\n\nexport interface ApiClient {\n readonly healthCheck: () => ReturnType<typeof fetchHealthCheck>;\n readonly auth: {\n readonly register: (\n body: Parameters<typeof postRegister>[1],\n ) => ReturnType<typeof postRegister>;\n readonly login: (body: Parameters<typeof postLogin>[1]) => ReturnType<typeof postLogin>;\n readonly getGoogleOAuthStart: (redirectUri: string) => ReturnType<typeof getGoogleOAuthStart>;\n readonly postGoogleOAuthCallback: (\n body: Parameters<typeof postGoogleOAuthCallback>[1],\n ) => ReturnType<typeof postGoogleOAuthCallback>;\n readonly refresh: (body: Parameters<typeof postRefresh>[1]) => ReturnType<typeof postRefresh>;\n readonly logout: (body: Parameters<typeof postLogout>[1]) => ReturnType<typeof postLogout>;\n readonly verifyEmail: (\n body: Parameters<typeof patchVerifyEmail>[1],\n ) => ReturnType<typeof patchVerifyEmail>;\n readonly me: (accessToken: string) => ReturnType<typeof getMe>;\n };\n readonly users: {\n readonly getProfile: (accessToken: string) => ReturnType<typeof getUserProfile>;\n readonly patchProfile: (\n accessToken: string,\n body: Parameters<typeof patchUserProfile>[2],\n ) => ReturnType<typeof patchUserProfile>;\n };\n}\n\n/**\n * Creates a typed API client backed by the provided HTTP implementation.\n */\nexport function createApiClient(options: CreateApiClientOptions): ApiClient {\n const { http } = options;\n\n return {\n healthCheck: () => fetchHealthCheck(http),\n auth: {\n register: (body) => postRegister(http, body),\n login: (body) => postLogin(http, body),\n getGoogleOAuthStart: (redirectUri) => getGoogleOAuthStart(http, redirectUri),\n postGoogleOAuthCallback: (body) => postGoogleOAuthCallback(http, body),\n refresh: (body) => postRefresh(http, body),\n logout: (body) => postLogout(http, body),\n verifyEmail: (body) => patchVerifyEmail(http, body),\n me: (accessToken) => getMe(http, accessToken),\n },\n users: {\n getProfile: (accessToken) => getUserProfile(http, accessToken),\n patchProfile: (accessToken, body) => patchUserProfile(http, accessToken, body),\n },\n };\n}\n"]}
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@ipetsadmin/api-client",
|
|
3
|
-
"version": "1.1.
|
|
3
|
+
"version": "1.1.2",
|
|
4
4
|
"description": "Client used to interact with Truffa project API",
|
|
5
5
|
"main": "./dist/index.js",
|
|
6
6
|
"module": "./dist/index.mjs",
|
|
@@ -38,7 +38,7 @@
|
|
|
38
38
|
"author": "",
|
|
39
39
|
"license": "MIT",
|
|
40
40
|
"devDependencies": {
|
|
41
|
-
"@ipetsadmin/contracts": "1.1.
|
|
41
|
+
"@ipetsadmin/contracts": "1.1.9",
|
|
42
42
|
"@eslint/js": "^10.0.1",
|
|
43
43
|
"@types/express": "^5.0.5",
|
|
44
44
|
"@types/node": "^24.10.0",
|
|
@@ -52,7 +52,7 @@
|
|
|
52
52
|
"typescript-eslint": "^8.58.0"
|
|
53
53
|
},
|
|
54
54
|
"peerDependencies": {
|
|
55
|
-
"@ipetsadmin/contracts": ">=1.1.
|
|
55
|
+
"@ipetsadmin/contracts": ">=1.1.9"
|
|
56
56
|
},
|
|
57
57
|
"publishConfig": {
|
|
58
58
|
"access": "public"
|