@kulkan/kulterra-api-client 1.1.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 +41 -0
- package/LICENSE +21 -0
- package/README.md +129 -0
- package/dist/index.d.mts +41 -0
- package/dist/index.d.ts +41 -0
- package/dist/index.js +83 -0
- package/dist/index.js.map +1 -0
- package/dist/index.mjs +74 -0
- package/dist/index.mjs.map +1 -0
- package/package.json +71 -0
package/CHANGELOG.md
ADDED
|
@@ -0,0 +1,41 @@
|
|
|
1
|
+
# Changelog
|
|
2
|
+
|
|
3
|
+
All notable changes to this project are documented in this file.
|
|
4
|
+
|
|
5
|
+
The format is based on [Keep a Changelog](https://keepachangelog.com/en/1.1.0/),
|
|
6
|
+
and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0.html).
|
|
7
|
+
|
|
8
|
+
## [Unreleased]
|
|
9
|
+
|
|
10
|
+
### Added
|
|
11
|
+
|
|
12
|
+
### Changed
|
|
13
|
+
|
|
14
|
+
### Deprecated
|
|
15
|
+
|
|
16
|
+
### Removed
|
|
17
|
+
|
|
18
|
+
### Fixed
|
|
19
|
+
|
|
20
|
+
### Security
|
|
21
|
+
|
|
22
|
+
## [1.1.0] - 2026-04-04
|
|
23
|
+
|
|
24
|
+
### Added
|
|
25
|
+
|
|
26
|
+
- **`HttpClient.post`** and **`HttpPost`** type for JSON bodies (Axios-compatible).
|
|
27
|
+
- **Auth endpoints** (`src/endpoints/auth.ts`): `postRegister`, `postLogin`, `getGoogleOAuthStart`, `postGoogleOAuthCallback`, `postRefresh`, `postLogout`, `getMe`.
|
|
28
|
+
- **`createApiClient`** exposes **`auth`** namespace delegating to the auth endpoints.
|
|
29
|
+
- **Peer dependency** on `@kulkan/kulterra-contracts` **≥ 1.1.1** (align with service ports and Auth0 helper types on the API).
|
|
30
|
+
- README updated with endpoint table and OAuth flow notes.
|
|
31
|
+
|
|
32
|
+
### Changed
|
|
33
|
+
|
|
34
|
+
- **`createApiClient`** now requires an `http` implementation that provides both **`get`** and **`post`** (breaking for consumers that only implemented `get`).
|
|
35
|
+
|
|
36
|
+
## [1.0.0] - 2026-04-02
|
|
37
|
+
|
|
38
|
+
### Added
|
|
39
|
+
|
|
40
|
+
- Initial public release of `@kulkan/kulterra-api-client`.
|
|
41
|
+
- MIT license, README, and npm publish tooling (validate, build, Husky, lint-staged).
|
package/LICENSE
ADDED
|
@@ -0,0 +1,21 @@
|
|
|
1
|
+
MIT License
|
|
2
|
+
|
|
3
|
+
Copyright (c) 2026 ipetsadmin
|
|
4
|
+
|
|
5
|
+
Permission is hereby granted, free of charge, to any person obtaining a copy
|
|
6
|
+
of this software and associated documentation files (the "Software"), to deal
|
|
7
|
+
in the Software without restriction, including without limitation the rights
|
|
8
|
+
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
|
9
|
+
copies of the Software, and to permit persons to whom the Software is
|
|
10
|
+
furnished to do so, subject to the following conditions:
|
|
11
|
+
|
|
12
|
+
The above copyright notice and this permission notice shall be included in all
|
|
13
|
+
copies or substantial portions of the Software.
|
|
14
|
+
|
|
15
|
+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
|
16
|
+
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
|
17
|
+
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
|
18
|
+
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
|
19
|
+
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
|
20
|
+
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
|
|
21
|
+
SOFTWARE.
|
package/README.md
ADDED
|
@@ -0,0 +1,129 @@
|
|
|
1
|
+
# `@kulkan/kulterra-api-client`
|
|
2
|
+
|
|
3
|
+
Typed HTTP client for the Truffa API. Consumed by web and mobile apps. **No baked-in base URL:** pass a preconfigured HTTP layer (typically an [Axios](https://axios-http.com/) instance with `baseURL` set). Request and response shapes come from [`@kulkan/kulterra-contracts`](https://www.npmjs.com/package/@kulkan/contracts).
|
|
4
|
+
|
|
5
|
+
## Requirements
|
|
6
|
+
|
|
7
|
+
- **Node.js** ≥ 18.18
|
|
8
|
+
- **Peer dependency:** `@kulkan/kulterra-contracts` **≥ 1.1.0** (auth types and shared envelopes)
|
|
9
|
+
|
|
10
|
+
## Installation
|
|
11
|
+
|
|
12
|
+
```bash
|
|
13
|
+
pnpm add @kulkan/kulterra-api-client @kulkan/kulterra-contracts
|
|
14
|
+
# or
|
|
15
|
+
npm install @kulkan/kulterra-api-client @kulkan/kulterra-contracts
|
|
16
|
+
```
|
|
17
|
+
|
|
18
|
+
## What ships today
|
|
19
|
+
|
|
20
|
+
| Export | Description |
|
|
21
|
+
| -------------------------------------- | ------------------------------------------------------------------------------------------------------------------------------------------------- |
|
|
22
|
+
| `createApiClient(options)` | Factory returning `healthCheck` + **`auth`** namespace |
|
|
23
|
+
| `ApiClient` / `CreateApiClientOptions` | Typed client and `{ http: HttpClient }` options |
|
|
24
|
+
| `HttpClient` | **`get`** and **`post`** (minimal surface compatible with Axios) |
|
|
25
|
+
| `HttpGet` / `HttpPost` | Method signatures |
|
|
26
|
+
| Named auth helpers | `postRegister`, `postLogin`, `getGoogleOAuthStart`, `postGoogleOAuthCallback`, `postRefresh`, `postLogout`, `getMe` (see `src/endpoints/auth.ts`) |
|
|
27
|
+
|
|
28
|
+
### Endpoints implemented
|
|
29
|
+
|
|
30
|
+
| HTTP | Path | Client |
|
|
31
|
+
| ------ | ------------------------------------------------- | ------------------------------------------------------------------------------------------ |
|
|
32
|
+
| `GET` | `/api/v1/health-check` | `client.healthCheck()` |
|
|
33
|
+
| `POST` | `/api/v1/auth/register` | `client.auth.register(body)` or `postRegister(http, body)` |
|
|
34
|
+
| `POST` | `/api/v1/auth/login` | `client.auth.login(body)` or `postLogin(http, body)` |
|
|
35
|
+
| `GET` | `/api/v1/auth/oauth/google/start?redirectUri=...` | `client.auth.getGoogleOAuthStart(redirectUri)` or `getGoogleOAuthStart(http, redirectUri)` |
|
|
36
|
+
| `POST` | `/api/v1/auth/oauth/google/callback` | `client.auth.postGoogleOAuthCallback(body)` or `postGoogleOAuthCallback(http, body)` |
|
|
37
|
+
| `POST` | `/api/v1/auth/refresh` | `client.auth.refresh(body)` or `postRefresh(http, body)` |
|
|
38
|
+
| `POST` | `/api/v1/auth/logout` | `client.auth.logout(body)` or `postLogout(http, body)` |
|
|
39
|
+
| `GET` | `/api/v1/auth/me` | `client.auth.me(accessToken)` or `getMe(http, accessToken)` |
|
|
40
|
+
|
|
41
|
+
Responses follow **`IApiResponse<T>`** from contracts (`success`, `data`, etc.). Auth session payloads are **`AuthSessionResponse`** (`TokenPair` + `user`). **`logout`** returns **204** with no JSON body.
|
|
42
|
+
|
|
43
|
+
### Usage example (Axios)
|
|
44
|
+
|
|
45
|
+
Paths are **relative to `baseURL`** (e.g. `https://api.example.com`).
|
|
46
|
+
|
|
47
|
+
```typescript
|
|
48
|
+
import axios from 'axios';
|
|
49
|
+
import { createApiClient } from '@kulkan/kulterra-api-client';
|
|
50
|
+
|
|
51
|
+
const http = axios.create({
|
|
52
|
+
baseURL: process.env.API_BASE_URL,
|
|
53
|
+
timeout: 30_000,
|
|
54
|
+
headers: { 'Content-Type': 'application/json' },
|
|
55
|
+
});
|
|
56
|
+
|
|
57
|
+
const api = createApiClient({ http });
|
|
58
|
+
|
|
59
|
+
const health = await api.healthCheck();
|
|
60
|
+
const session = await api.auth.login({ email: 'user@example.com', password: '********' });
|
|
61
|
+
// session.data — IApiResponse<AuthSessionResponse>; use session.data?.data for the inner payload when using Axios default response shape
|
|
62
|
+
```
|
|
63
|
+
|
|
64
|
+
Axios returns `{ data: body }` where `body` is the full JSON from the server. For `IApiResponse<AuthSessionResponse>`, the **envelope** is in `response.data`; the **`AuthSessionResponse`** is typically `response.data.data` (depending on your typings).
|
|
65
|
+
|
|
66
|
+
### OAuth (mobile / web)
|
|
67
|
+
|
|
68
|
+
1. Call **`getGoogleOAuthStart`** with the same **`redirectUri`** you registered in Auth0 and in the API’s `OAUTH_ALLOWED_REDIRECT_URIS`.
|
|
69
|
+
2. Open **`authorizationUrl`** in a browser / `ASWebAuthenticationSession`.
|
|
70
|
+
3. After redirect, **`POST`** the **`code`**, **`state`**, and **`redirectUri`** to **`postGoogleOAuthCallback`**.
|
|
71
|
+
|
|
72
|
+
### Why a factory?
|
|
73
|
+
|
|
74
|
+
`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.
|
|
75
|
+
|
|
76
|
+
---
|
|
77
|
+
|
|
78
|
+
## Architecture
|
|
79
|
+
|
|
80
|
+
1. **`HttpClient`** — abstraction over GET/POST (`{ data: T }` shape, Axios-compatible).
|
|
81
|
+
2. **`src/endpoints/*.ts`** — thin functions: `(http, …args) => Promise<…>`.
|
|
82
|
+
3. **`createApiClient`** — wires `http` into endpoints.
|
|
83
|
+
4. **`@kulkan/kulterra-contracts`** — DTOs (`RegisterRequest`, `AuthSessionResponse`, …).
|
|
84
|
+
|
|
85
|
+
### Extending further
|
|
86
|
+
|
|
87
|
+
If you add PATCH/PUT/DELETE, extend **`HttpClient`** in `src/http-client.ts` and add endpoint modules. For request config (query params, headers), align types with your adapter (Axios uses a second `config` argument on `get`/`post`).
|
|
88
|
+
|
|
89
|
+
---
|
|
90
|
+
|
|
91
|
+
## Testing
|
|
92
|
+
|
|
93
|
+
Inject a fake **`HttpClient`** with **`get`** and **`post`** mocks and assert URLs and payloads.
|
|
94
|
+
|
|
95
|
+
```typescript
|
|
96
|
+
import type { HttpClient } from '@kulkan/kulterra-api-client';
|
|
97
|
+
import { createApiClient } from '@kulkan/kulterra-api-client';
|
|
98
|
+
|
|
99
|
+
const http: HttpClient = {
|
|
100
|
+
get: jest.fn().mockResolvedValue({ data: { success: true, data: {} } }),
|
|
101
|
+
post: jest.fn().mockResolvedValue({ data: { success: true, data: {} } }),
|
|
102
|
+
};
|
|
103
|
+
|
|
104
|
+
const api = createApiClient({ http });
|
|
105
|
+
await api.healthCheck();
|
|
106
|
+
expect(http.get).toHaveBeenCalledWith('/api/v1/health-check', undefined);
|
|
107
|
+
```
|
|
108
|
+
|
|
109
|
+
---
|
|
110
|
+
|
|
111
|
+
## Development (this repository)
|
|
112
|
+
|
|
113
|
+
| Script | Purpose |
|
|
114
|
+
| ------------------------- | ------------------------------------ |
|
|
115
|
+
| `pnpm run build` | `tsup` → `dist/` (CJS, ESM, `.d.ts`) |
|
|
116
|
+
| `pnpm run typecheck` | `tsc --noEmit` |
|
|
117
|
+
| `pnpm run lint` | ESLint |
|
|
118
|
+
| `pnpm run validate` | typecheck + lint + Prettier check |
|
|
119
|
+
| `pnpm run prepublishOnly` | validate + build before publish |
|
|
120
|
+
|
|
121
|
+
---
|
|
122
|
+
|
|
123
|
+
## Changelog
|
|
124
|
+
|
|
125
|
+
See [CHANGELOG.md](./CHANGELOG.md).
|
|
126
|
+
|
|
127
|
+
## License
|
|
128
|
+
|
|
129
|
+
MIT — see [LICENSE](./LICENSE).
|
package/dist/index.d.mts
ADDED
|
@@ -0,0 +1,41 @@
|
|
|
1
|
+
import { RegisterRequest, IApiResponse, AuthSessionResponse, LoginRequest, OAuthGoogleStartResponse, OAuthGoogleCallbackRequest, RefreshRequest, LogoutRequest, AuthUserResponse, HealthCheck } from '@kulkan/kulterra-contracts';
|
|
2
|
+
|
|
3
|
+
type HttpGet = <TResponse>(url: string, config?: unknown) => Promise<{
|
|
4
|
+
data: TResponse;
|
|
5
|
+
}>;
|
|
6
|
+
type HttpPost = <TResponse, TBody = unknown>(url: string, body?: TBody, config?: unknown) => Promise<{
|
|
7
|
+
data: TResponse;
|
|
8
|
+
}>;
|
|
9
|
+
interface HttpClient {
|
|
10
|
+
readonly get: HttpGet;
|
|
11
|
+
readonly post: HttpPost;
|
|
12
|
+
}
|
|
13
|
+
|
|
14
|
+
declare function postRegister(http: HttpClient, body: RegisterRequest): Promise<IApiResponse<AuthSessionResponse>>;
|
|
15
|
+
declare function postLogin(http: HttpClient, body: LoginRequest): Promise<IApiResponse<AuthSessionResponse>>;
|
|
16
|
+
declare function getGoogleOAuthStart(http: HttpClient, redirectUri: string): Promise<IApiResponse<OAuthGoogleStartResponse>>;
|
|
17
|
+
declare function postGoogleOAuthCallback(http: HttpClient, body: OAuthGoogleCallbackRequest): Promise<IApiResponse<AuthSessionResponse>>;
|
|
18
|
+
declare function postRefresh(http: HttpClient, body: RefreshRequest): Promise<IApiResponse<AuthSessionResponse>>;
|
|
19
|
+
declare function postLogout(http: HttpClient, body: LogoutRequest): Promise<void>;
|
|
20
|
+
declare function getMe(http: HttpClient, accessToken: string): Promise<IApiResponse<AuthUserResponse>>;
|
|
21
|
+
|
|
22
|
+
declare function fetchHealthCheck(http: HttpClient): Promise<IApiResponse<HealthCheck>>;
|
|
23
|
+
|
|
24
|
+
interface CreateApiClientOptions {
|
|
25
|
+
readonly http: HttpClient;
|
|
26
|
+
}
|
|
27
|
+
interface ApiClient {
|
|
28
|
+
readonly healthCheck: () => ReturnType<typeof fetchHealthCheck>;
|
|
29
|
+
readonly auth: {
|
|
30
|
+
readonly register: (body: Parameters<typeof postRegister>[1]) => ReturnType<typeof postRegister>;
|
|
31
|
+
readonly login: (body: Parameters<typeof postLogin>[1]) => ReturnType<typeof postLogin>;
|
|
32
|
+
readonly getGoogleOAuthStart: (redirectUri: string) => ReturnType<typeof getGoogleOAuthStart>;
|
|
33
|
+
readonly postGoogleOAuthCallback: (body: Parameters<typeof postGoogleOAuthCallback>[1]) => ReturnType<typeof postGoogleOAuthCallback>;
|
|
34
|
+
readonly refresh: (body: Parameters<typeof postRefresh>[1]) => ReturnType<typeof postRefresh>;
|
|
35
|
+
readonly logout: (body: Parameters<typeof postLogout>[1]) => ReturnType<typeof postLogout>;
|
|
36
|
+
readonly me: (accessToken: string) => ReturnType<typeof getMe>;
|
|
37
|
+
};
|
|
38
|
+
}
|
|
39
|
+
declare function createApiClient(options: CreateApiClientOptions): ApiClient;
|
|
40
|
+
|
|
41
|
+
export { type ApiClient, type CreateApiClientOptions, type HttpClient, type HttpGet, type HttpPost, createApiClient, getGoogleOAuthStart, getMe, postGoogleOAuthCallback, postLogin, postLogout, postRefresh, postRegister };
|
package/dist/index.d.ts
ADDED
|
@@ -0,0 +1,41 @@
|
|
|
1
|
+
import { RegisterRequest, IApiResponse, AuthSessionResponse, LoginRequest, OAuthGoogleStartResponse, OAuthGoogleCallbackRequest, RefreshRequest, LogoutRequest, AuthUserResponse, HealthCheck } from '@kulkan/kulterra-contracts';
|
|
2
|
+
|
|
3
|
+
type HttpGet = <TResponse>(url: string, config?: unknown) => Promise<{
|
|
4
|
+
data: TResponse;
|
|
5
|
+
}>;
|
|
6
|
+
type HttpPost = <TResponse, TBody = unknown>(url: string, body?: TBody, config?: unknown) => Promise<{
|
|
7
|
+
data: TResponse;
|
|
8
|
+
}>;
|
|
9
|
+
interface HttpClient {
|
|
10
|
+
readonly get: HttpGet;
|
|
11
|
+
readonly post: HttpPost;
|
|
12
|
+
}
|
|
13
|
+
|
|
14
|
+
declare function postRegister(http: HttpClient, body: RegisterRequest): Promise<IApiResponse<AuthSessionResponse>>;
|
|
15
|
+
declare function postLogin(http: HttpClient, body: LoginRequest): Promise<IApiResponse<AuthSessionResponse>>;
|
|
16
|
+
declare function getGoogleOAuthStart(http: HttpClient, redirectUri: string): Promise<IApiResponse<OAuthGoogleStartResponse>>;
|
|
17
|
+
declare function postGoogleOAuthCallback(http: HttpClient, body: OAuthGoogleCallbackRequest): Promise<IApiResponse<AuthSessionResponse>>;
|
|
18
|
+
declare function postRefresh(http: HttpClient, body: RefreshRequest): Promise<IApiResponse<AuthSessionResponse>>;
|
|
19
|
+
declare function postLogout(http: HttpClient, body: LogoutRequest): Promise<void>;
|
|
20
|
+
declare function getMe(http: HttpClient, accessToken: string): Promise<IApiResponse<AuthUserResponse>>;
|
|
21
|
+
|
|
22
|
+
declare function fetchHealthCheck(http: HttpClient): Promise<IApiResponse<HealthCheck>>;
|
|
23
|
+
|
|
24
|
+
interface CreateApiClientOptions {
|
|
25
|
+
readonly http: HttpClient;
|
|
26
|
+
}
|
|
27
|
+
interface ApiClient {
|
|
28
|
+
readonly healthCheck: () => ReturnType<typeof fetchHealthCheck>;
|
|
29
|
+
readonly auth: {
|
|
30
|
+
readonly register: (body: Parameters<typeof postRegister>[1]) => ReturnType<typeof postRegister>;
|
|
31
|
+
readonly login: (body: Parameters<typeof postLogin>[1]) => ReturnType<typeof postLogin>;
|
|
32
|
+
readonly getGoogleOAuthStart: (redirectUri: string) => ReturnType<typeof getGoogleOAuthStart>;
|
|
33
|
+
readonly postGoogleOAuthCallback: (body: Parameters<typeof postGoogleOAuthCallback>[1]) => ReturnType<typeof postGoogleOAuthCallback>;
|
|
34
|
+
readonly refresh: (body: Parameters<typeof postRefresh>[1]) => ReturnType<typeof postRefresh>;
|
|
35
|
+
readonly logout: (body: Parameters<typeof postLogout>[1]) => ReturnType<typeof postLogout>;
|
|
36
|
+
readonly me: (accessToken: string) => ReturnType<typeof getMe>;
|
|
37
|
+
};
|
|
38
|
+
}
|
|
39
|
+
declare function createApiClient(options: CreateApiClientOptions): ApiClient;
|
|
40
|
+
|
|
41
|
+
export { type ApiClient, type CreateApiClientOptions, type HttpClient, type HttpGet, type HttpPost, createApiClient, getGoogleOAuthStart, getMe, postGoogleOAuthCallback, postLogin, postLogout, postRefresh, postRegister };
|
package/dist/index.js
ADDED
|
@@ -0,0 +1,83 @@
|
|
|
1
|
+
'use strict';
|
|
2
|
+
|
|
3
|
+
// src/endpoints/auth.ts
|
|
4
|
+
var AUTH_BASE = "/api/v1/auth";
|
|
5
|
+
async function postRegister(http, body) {
|
|
6
|
+
const { data } = await http.post(
|
|
7
|
+
`${AUTH_BASE}/register`,
|
|
8
|
+
body
|
|
9
|
+
);
|
|
10
|
+
return data;
|
|
11
|
+
}
|
|
12
|
+
async function postLogin(http, body) {
|
|
13
|
+
const { data } = await http.post(
|
|
14
|
+
`${AUTH_BASE}/login`,
|
|
15
|
+
body
|
|
16
|
+
);
|
|
17
|
+
return data;
|
|
18
|
+
}
|
|
19
|
+
async function getGoogleOAuthStart(http, redirectUri) {
|
|
20
|
+
const q = new URLSearchParams({ redirectUri });
|
|
21
|
+
const { data } = await http.get(
|
|
22
|
+
`${AUTH_BASE}/oauth/google/start?${q.toString()}`
|
|
23
|
+
);
|
|
24
|
+
return data;
|
|
25
|
+
}
|
|
26
|
+
async function postGoogleOAuthCallback(http, body) {
|
|
27
|
+
const { data } = await http.post(
|
|
28
|
+
`${AUTH_BASE}/oauth/google/callback`,
|
|
29
|
+
body
|
|
30
|
+
);
|
|
31
|
+
return data;
|
|
32
|
+
}
|
|
33
|
+
async function postRefresh(http, body) {
|
|
34
|
+
const { data } = await http.post(
|
|
35
|
+
`${AUTH_BASE}/refresh`,
|
|
36
|
+
body
|
|
37
|
+
);
|
|
38
|
+
return data;
|
|
39
|
+
}
|
|
40
|
+
async function postLogout(http, body) {
|
|
41
|
+
await http.post(`${AUTH_BASE}/logout`, body);
|
|
42
|
+
}
|
|
43
|
+
async function getMe(http, accessToken) {
|
|
44
|
+
const { data } = await http.get(`${AUTH_BASE}/me`, {
|
|
45
|
+
headers: { Authorization: `Bearer ${accessToken}` }
|
|
46
|
+
});
|
|
47
|
+
return data;
|
|
48
|
+
}
|
|
49
|
+
|
|
50
|
+
// src/endpoints/health-check.ts
|
|
51
|
+
var HEALTH_CHECK_PATH = "/api/v1/health-check";
|
|
52
|
+
async function fetchHealthCheck(http) {
|
|
53
|
+
const { data: body } = await http.get(HEALTH_CHECK_PATH);
|
|
54
|
+
return body;
|
|
55
|
+
}
|
|
56
|
+
|
|
57
|
+
// src/create-api-client.ts
|
|
58
|
+
function createApiClient(options) {
|
|
59
|
+
const { http } = options;
|
|
60
|
+
return {
|
|
61
|
+
healthCheck: () => fetchHealthCheck(http),
|
|
62
|
+
auth: {
|
|
63
|
+
register: (body) => postRegister(http, body),
|
|
64
|
+
login: (body) => postLogin(http, body),
|
|
65
|
+
getGoogleOAuthStart: (redirectUri) => getGoogleOAuthStart(http, redirectUri),
|
|
66
|
+
postGoogleOAuthCallback: (body) => postGoogleOAuthCallback(http, body),
|
|
67
|
+
refresh: (body) => postRefresh(http, body),
|
|
68
|
+
logout: (body) => postLogout(http, body),
|
|
69
|
+
me: (accessToken) => getMe(http, accessToken)
|
|
70
|
+
}
|
|
71
|
+
};
|
|
72
|
+
}
|
|
73
|
+
|
|
74
|
+
exports.createApiClient = createApiClient;
|
|
75
|
+
exports.getGoogleOAuthStart = getGoogleOAuthStart;
|
|
76
|
+
exports.getMe = getMe;
|
|
77
|
+
exports.postGoogleOAuthCallback = postGoogleOAuthCallback;
|
|
78
|
+
exports.postLogin = postLogin;
|
|
79
|
+
exports.postLogout = postLogout;
|
|
80
|
+
exports.postRefresh = postRefresh;
|
|
81
|
+
exports.postRegister = postRegister;
|
|
82
|
+
//# sourceMappingURL=index.js.map
|
|
83
|
+
//# sourceMappingURL=index.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"sources":["../src/endpoints/auth.ts","../src/endpoints/health-check.ts","../src/create-api-client.ts"],"names":[],"mappings":";;;AAcA,IAAM,SAAA,GAAY,cAAA;AAKlB,eAAsB,YAAA,CACpB,MACA,IAAA,EAC4C;AAC5C,EAAA,MAAM,EAAE,IAAA,EAAK,GAAI,MAAM,IAAA,CAAK,IAAA;AAAA,IAC1B,GAAG,SAAS,CAAA,SAAA,CAAA;AAAA,IACZ;AAAA,GACF;AACA,EAAA,OAAO,IAAA;AACT;AAKA,eAAsB,SAAA,CACpB,MACA,IAAA,EAC4C;AAC5C,EAAA,MAAM,EAAE,IAAA,EAAK,GAAI,MAAM,IAAA,CAAK,IAAA;AAAA,IAC1B,GAAG,SAAS,CAAA,MAAA,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sD;AAC3F,EAAA,MAAM,EAAE,IAAA,EAAM,IAAA,KAAS,MAAM,IAAA,CAAK,IAA+B,iBAAiB,CAAA;AAElF,EAAA,OAAO,IAAA;AACT;;;ACqBO,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,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} from '@kulkan/kulterra-contracts';\n\nimport type { HttpClient } from '../http-client';\n\nconst AUTH_BASE = '/api/v1/auth' as const;\n\n/**\n * POST /api/v1/auth/register\n */\nexport async function postRegister(\n http: HttpClient,\n body: RegisterRequest,\n): Promise<IApiResponse<AuthSessionResponse>> {\n const { data } = await http.post<IApiResponse<AuthSessionResponse>, RegisterRequest>(\n `${AUTH_BASE}/register`,\n body,\n );\n return data;\n}\n\n/**\n * POST /api/v1/auth/login\n */\nexport async function postLogin(\n http: HttpClient,\n body: LoginRequest,\n): Promise<IApiResponse<AuthSessionResponse>> {\n const { data } = await http.post<IApiResponse<AuthSessionResponse>, LoginRequest>(\n `${AUTH_BASE}/login`,\n body,\n );\n return data;\n}\n\n/**\n * GET /api/v1/auth/oauth/google/start?redirectUri=...\n */\nexport async function getGoogleOAuthStart(\n http: HttpClient,\n redirectUri: string,\n): Promise<IApiResponse<OAuthGoogleStartResponse>> {\n const q = new URLSearchParams({ redirectUri });\n const { data } = await http.get<IApiResponse<OAuthGoogleStartResponse>>(\n `${AUTH_BASE}/oauth/google/start?${q.toString()}`,\n );\n return data;\n}\n\n/**\n * POST /api/v1/auth/oauth/google/callback\n */\nexport async function postGoogleOAuthCallback(\n http: HttpClient,\n body: OAuthGoogleCallbackRequest,\n): Promise<IApiResponse<AuthSessionResponse>> {\n const { data } = await http.post<IApiResponse<AuthSessionResponse>, OAuthGoogleCallbackRequest>(\n `${AUTH_BASE}/oauth/google/callback`,\n body,\n );\n return data;\n}\n\n/**\n * POST /api/v1/auth/refresh\n */\nexport async function postRefresh(\n http: HttpClient,\n body: RefreshRequest,\n): Promise<IApiResponse<AuthSessionResponse>> {\n const { data } = await http.post<IApiResponse<AuthSessionResponse>, RefreshRequest>(\n `${AUTH_BASE}/refresh`,\n body,\n );\n return data;\n}\n\n/**\n * POST /api/v1/auth/logout — 204 No Content (no JSON body).\n */\nexport async function postLogout(http: HttpClient, body: LogoutRequest): Promise<void> {\n await http.post<undefined, LogoutRequest>(`${AUTH_BASE}/logout`, body);\n}\n\n/**\n * GET /api/v1/auth/me — requires `Authorization: Bearer <accessToken>`.\n */\nexport async function getMe(\n http: HttpClient,\n accessToken: string,\n): Promise<IApiResponse<AuthUserResponse>> {\n const { data } = await http.get<IApiResponse<AuthUserResponse>>(`${AUTH_BASE}/me`, {\n headers: { Authorization: `Bearer ${accessToken}` },\n });\n return data;\n}\n","import type { IApiResponse, HealthCheck } from '@kulkan/kulterra-contracts';\nimport type { HttpClient } from '../http-client';\n\n/** Same path as `/api/${v1}/health-check` on the server when `v1` is the string `'v1'`. */\nconst HEALTH_CHECK_PATH = '/api/v1/health-check' as const;\n\n/**\n * GET /api/v1/health-check — server liveness.\n *\n * Returns the full JSON the server sends (`IApiResponse<HealthCheck>`).\n *\n * **Why not `data.data` here?** Adapters like Axios wrap the HTTP body in a property also\n * called `data`. That outer `data` is the entire `res.json(...)` object. The inner\n * `IApiResponse.data` is the `HealthCheck` payload — use `.data` on the **returned** value,\n * e.g. `(await fetchHealthCheck(http)).data`.\n */\nexport async function fetchHealthCheck(http: HttpClient): Promise<IApiResponse<HealthCheck>> {\n const { data: body } = await http.get<IApiResponse<HealthCheck>>(HEALTH_CHECK_PATH);\n\n return body;\n}\n","import {\n getGoogleOAuthStart,\n getMe,\n postGoogleOAuthCallback,\n postLogin,\n postLogout,\n postRefresh,\n postRegister,\n} from './endpoints/auth';\nimport { fetchHealthCheck } from './endpoints/health-check';\nimport type { HttpClient } from './http-client';\n\nexport interface CreateApiClientOptions {\n /**\n * Preconfigured HTTP client (e.g. Axios instance with `baseURL` set).\n * Paths in this library are relative to that base (e.g. `/api/v1/...`).\n * Both `get` and `post` are required for auth flows.\n */\n readonly http: HttpClient;\n}\n\nexport interface ApiClient {\n readonly healthCheck: () => ReturnType<typeof fetchHealthCheck>;\n readonly auth: {\n readonly register: (\n body: Parameters<typeof postRegister>[1],\n ) => ReturnType<typeof postRegister>;\n readonly login: (body: Parameters<typeof postLogin>[1]) => ReturnType<typeof postLogin>;\n readonly getGoogleOAuthStart: (redirectUri: string) => ReturnType<typeof getGoogleOAuthStart>;\n readonly postGoogleOAuthCallback: (\n body: Parameters<typeof postGoogleOAuthCallback>[1],\n ) => ReturnType<typeof postGoogleOAuthCallback>;\n readonly refresh: (body: Parameters<typeof postRefresh>[1]) => ReturnType<typeof postRefresh>;\n readonly logout: (body: Parameters<typeof postLogout>[1]) => ReturnType<typeof postLogout>;\n readonly me: (accessToken: string) => ReturnType<typeof getMe>;\n };\n}\n\n/**\n * Creates a typed API client backed by the provided HTTP implementation.\n */\nexport function createApiClient(options: CreateApiClientOptions): ApiClient {\n const { http } = options;\n\n return {\n healthCheck: () => fetchHealthCheck(http),\n auth: {\n register: (body) => postRegister(http, body),\n login: (body) => postLogin(http, body),\n getGoogleOAuthStart: (redirectUri) => getGoogleOAuthStart(http, redirectUri),\n postGoogleOAuthCallback: (body) => postGoogleOAuthCallback(http, body),\n refresh: (body) => postRefresh(http, body),\n logout: (body) => postLogout(http, body),\n me: (accessToken) => getMe(http, accessToken),\n },\n };\n}\n"]}
|
package/dist/index.mjs
ADDED
|
@@ -0,0 +1,74 @@
|
|
|
1
|
+
// src/endpoints/auth.ts
|
|
2
|
+
var AUTH_BASE = "/api/v1/auth";
|
|
3
|
+
async function postRegister(http, body) {
|
|
4
|
+
const { data } = await http.post(
|
|
5
|
+
`${AUTH_BASE}/register`,
|
|
6
|
+
body
|
|
7
|
+
);
|
|
8
|
+
return data;
|
|
9
|
+
}
|
|
10
|
+
async function postLogin(http, body) {
|
|
11
|
+
const { data } = await http.post(
|
|
12
|
+
`${AUTH_BASE}/login`,
|
|
13
|
+
body
|
|
14
|
+
);
|
|
15
|
+
return data;
|
|
16
|
+
}
|
|
17
|
+
async function getGoogleOAuthStart(http, redirectUri) {
|
|
18
|
+
const q = new URLSearchParams({ redirectUri });
|
|
19
|
+
const { data } = await http.get(
|
|
20
|
+
`${AUTH_BASE}/oauth/google/start?${q.toString()}`
|
|
21
|
+
);
|
|
22
|
+
return data;
|
|
23
|
+
}
|
|
24
|
+
async function postGoogleOAuthCallback(http, body) {
|
|
25
|
+
const { data } = await http.post(
|
|
26
|
+
`${AUTH_BASE}/oauth/google/callback`,
|
|
27
|
+
body
|
|
28
|
+
);
|
|
29
|
+
return data;
|
|
30
|
+
}
|
|
31
|
+
async function postRefresh(http, body) {
|
|
32
|
+
const { data } = await http.post(
|
|
33
|
+
`${AUTH_BASE}/refresh`,
|
|
34
|
+
body
|
|
35
|
+
);
|
|
36
|
+
return data;
|
|
37
|
+
}
|
|
38
|
+
async function postLogout(http, body) {
|
|
39
|
+
await http.post(`${AUTH_BASE}/logout`, body);
|
|
40
|
+
}
|
|
41
|
+
async function getMe(http, accessToken) {
|
|
42
|
+
const { data } = await http.get(`${AUTH_BASE}/me`, {
|
|
43
|
+
headers: { Authorization: `Bearer ${accessToken}` }
|
|
44
|
+
});
|
|
45
|
+
return data;
|
|
46
|
+
}
|
|
47
|
+
|
|
48
|
+
// src/endpoints/health-check.ts
|
|
49
|
+
var HEALTH_CHECK_PATH = "/api/v1/health-check";
|
|
50
|
+
async function fetchHealthCheck(http) {
|
|
51
|
+
const { data: body } = await http.get(HEALTH_CHECK_PATH);
|
|
52
|
+
return body;
|
|
53
|
+
}
|
|
54
|
+
|
|
55
|
+
// src/create-api-client.ts
|
|
56
|
+
function createApiClient(options) {
|
|
57
|
+
const { http } = options;
|
|
58
|
+
return {
|
|
59
|
+
healthCheck: () => fetchHealthCheck(http),
|
|
60
|
+
auth: {
|
|
61
|
+
register: (body) => postRegister(http, body),
|
|
62
|
+
login: (body) => postLogin(http, body),
|
|
63
|
+
getGoogleOAuthStart: (redirectUri) => getGoogleOAuthStart(http, redirectUri),
|
|
64
|
+
postGoogleOAuthCallback: (body) => postGoogleOAuthCallback(http, body),
|
|
65
|
+
refresh: (body) => postRefresh(http, body),
|
|
66
|
+
logout: (body) => postLogout(http, body),
|
|
67
|
+
me: (accessToken) => getMe(http, accessToken)
|
|
68
|
+
}
|
|
69
|
+
};
|
|
70
|
+
}
|
|
71
|
+
|
|
72
|
+
export { createApiClient, getGoogleOAuthStart, getMe, postGoogleOAuthCallback, postLogin, postLogout, postRefresh, postRegister };
|
|
73
|
+
//# sourceMappingURL=index.mjs.map
|
|
74
|
+
//# sourceMappingURL=index.mjs.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"sources":["../src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AgB,KAAA,CAAM,MAAM,WAAW;AAAA;AAC9C,GACF;AACF","file":"index.mjs","sourcesContent":["import type {\n AuthSessionResponse,\n AuthUserResponse,\n IApiResponse,\n LoginRequest,\n LogoutRequest,\n OAuthGoogleCallbackRequest,\n OAuthGoogleStartResponse,\n RefreshRequest,\n RegisterRequest,\n} from '@kulkan/kulterra-contracts';\n\nimport type { HttpClient } from '../http-client';\n\nconst AUTH_BASE = '/api/v1/auth' as const;\n\n/**\n * POST /api/v1/auth/register\n */\nexport async function postRegister(\n http: HttpClient,\n body: RegisterRequest,\n): Promise<IApiResponse<AuthSessionResponse>> {\n const { data } = await http.post<IApiResponse<AuthSessionResponse>, RegisterRequest>(\n `${AUTH_BASE}/register`,\n body,\n );\n return data;\n}\n\n/**\n * POST /api/v1/auth/login\n */\nexport async function postLogin(\n http: HttpClient,\n body: LoginRequest,\n): Promise<IApiResponse<AuthSessionResponse>> {\n const { data } = await http.post<IApiResponse<AuthSessionResponse>, LoginRequest>(\n `${AUTH_BASE}/login`,\n body,\n );\n return data;\n}\n\n/**\n * GET /api/v1/auth/oauth/google/start?redirectUri=...\n */\nexport async function getGoogleOAuthStart(\n http: HttpClient,\n redirectUri: string,\n): Promise<IApiResponse<OAuthGoogleStartResponse>> {\n const q = new URLSearchParams({ redirectUri });\n const { data } = await http.get<IApiResponse<OAuthGoogleStartResponse>>(\n `${AUTH_BASE}/oauth/google/start?${q.toString()}`,\n );\n return data;\n}\n\n/**\n * POST /api/v1/auth/oauth/google/callback\n */\nexport async function postGoogleOAuthCallback(\n http: HttpClient,\n body: OAuthGoogleCallbackRequest,\n): Promise<IApiResponse<AuthSessionResponse>> {\n const { data } = await http.post<IApiResponse<AuthSessionResponse>, OAuthGoogleCallbackRequest>(\n `${AUTH_BASE}/oauth/google/callback`,\n body,\n );\n return data;\n}\n\n/**\n * POST /api/v1/auth/refresh\n */\nexport async function postRefresh(\n http: HttpClient,\n body: RefreshRequest,\n): Promise<IApiResponse<AuthSessionResponse>> {\n const { data } = await http.post<IApiResponse<AuthSessionResponse>, RefreshRequest>(\n `${AUTH_BASE}/refresh`,\n body,\n );\n return data;\n}\n\n/**\n * POST /api/v1/auth/logout — 204 No Content (no JSON body).\n */\nexport async function postLogout(http: HttpClient, body: LogoutRequest): Promise<void> {\n await http.post<undefined, LogoutRequest>(`${AUTH_BASE}/logout`, body);\n}\n\n/**\n * GET /api/v1/auth/me — requires `Authorization: Bearer <accessToken>`.\n */\nexport async function getMe(\n http: HttpClient,\n accessToken: string,\n): Promise<IApiResponse<AuthUserResponse>> {\n const { data } = await http.get<IApiResponse<AuthUserResponse>>(`${AUTH_BASE}/me`, {\n headers: { Authorization: `Bearer ${accessToken}` },\n });\n return data;\n}\n","import type { IApiResponse, HealthCheck } from '@kulkan/kulterra-contracts';\nimport type { HttpClient } from '../http-client';\n\n/** Same path as `/api/${v1}/health-check` on the server when `v1` is the string `'v1'`. */\nconst HEALTH_CHECK_PATH = '/api/v1/health-check' as const;\n\n/**\n * GET /api/v1/health-check — server liveness.\n *\n * Returns the full JSON the server sends (`IApiResponse<HealthCheck>`).\n *\n * **Why not `data.data` here?** Adapters like Axios wrap the HTTP body in a property also\n * called `data`. That outer `data` is the entire `res.json(...)` object. The inner\n * `IApiResponse.data` is the `HealthCheck` payload — use `.data` on the **returned** value,\n * e.g. `(await fetchHealthCheck(http)).data`.\n */\nexport async function fetchHealthCheck(http: HttpClient): Promise<IApiResponse<HealthCheck>> {\n const { data: body } = await http.get<IApiResponse<HealthCheck>>(HEALTH_CHECK_PATH);\n\n return body;\n}\n","import {\n getGoogleOAuthStart,\n getMe,\n postGoogleOAuthCallback,\n postLogin,\n postLogout,\n postRefresh,\n postRegister,\n} from './endpoints/auth';\nimport { fetchHealthCheck } from './endpoints/health-check';\nimport type { HttpClient } from './http-client';\n\nexport interface CreateApiClientOptions {\n /**\n * Preconfigured HTTP client (e.g. Axios instance with `baseURL` set).\n * Paths in this library are relative to that base (e.g. `/api/v1/...`).\n * Both `get` and `post` are required for auth flows.\n */\n readonly http: HttpClient;\n}\n\nexport interface ApiClient {\n readonly healthCheck: () => ReturnType<typeof fetchHealthCheck>;\n readonly auth: {\n readonly register: (\n body: Parameters<typeof postRegister>[1],\n ) => ReturnType<typeof postRegister>;\n readonly login: (body: Parameters<typeof postLogin>[1]) => ReturnType<typeof postLogin>;\n readonly getGoogleOAuthStart: (redirectUri: string) => ReturnType<typeof getGoogleOAuthStart>;\n readonly postGoogleOAuthCallback: (\n body: Parameters<typeof postGoogleOAuthCallback>[1],\n ) => ReturnType<typeof postGoogleOAuthCallback>;\n readonly refresh: (body: Parameters<typeof postRefresh>[1]) => ReturnType<typeof postRefresh>;\n readonly logout: (body: Parameters<typeof postLogout>[1]) => ReturnType<typeof postLogout>;\n readonly me: (accessToken: string) => ReturnType<typeof getMe>;\n };\n}\n\n/**\n * Creates a typed API client backed by the provided HTTP implementation.\n */\nexport function createApiClient(options: CreateApiClientOptions): ApiClient {\n const { http } = options;\n\n return {\n healthCheck: () => fetchHealthCheck(http),\n auth: {\n register: (body) => postRegister(http, body),\n login: (body) => postLogin(http, body),\n getGoogleOAuthStart: (redirectUri) => getGoogleOAuthStart(http, redirectUri),\n postGoogleOAuthCallback: (body) => postGoogleOAuthCallback(http, body),\n refresh: (body) => postRefresh(http, body),\n logout: (body) => postLogout(http, body),\n me: (accessToken) => getMe(http, accessToken),\n },\n };\n}\n"]}
|
package/package.json
ADDED
|
@@ -0,0 +1,71 @@
|
|
|
1
|
+
{
|
|
2
|
+
"name": "@kulkan/kulterra-api-client",
|
|
3
|
+
"version": "1.1.1",
|
|
4
|
+
"description": "Client used to interact with KulTerra project API",
|
|
5
|
+
"main": "./dist/index.js",
|
|
6
|
+
"module": "./dist/index.mjs",
|
|
7
|
+
"types": "./dist/index.d.ts",
|
|
8
|
+
"exports": {
|
|
9
|
+
".": {
|
|
10
|
+
"types": "./dist/index.d.ts",
|
|
11
|
+
"import": "./dist/index.mjs",
|
|
12
|
+
"require": "./dist/index.js",
|
|
13
|
+
"default": "./dist/index.mjs"
|
|
14
|
+
}
|
|
15
|
+
},
|
|
16
|
+
"files": [
|
|
17
|
+
"dist",
|
|
18
|
+
"README.md",
|
|
19
|
+
"LICENSE",
|
|
20
|
+
"CHANGELOG.md"
|
|
21
|
+
],
|
|
22
|
+
"lint-staged": {
|
|
23
|
+
"src/**/*.{ts,tsx}": [
|
|
24
|
+
"eslint --fix --max-warnings 0",
|
|
25
|
+
"prettier --write"
|
|
26
|
+
],
|
|
27
|
+
"tsup.config.ts": "prettier --write",
|
|
28
|
+
"*.{json,md}": "prettier --write"
|
|
29
|
+
},
|
|
30
|
+
"engines": {
|
|
31
|
+
"node": ">=18.18.0"
|
|
32
|
+
},
|
|
33
|
+
"keywords": [
|
|
34
|
+
"types",
|
|
35
|
+
"typescript",
|
|
36
|
+
"shared"
|
|
37
|
+
],
|
|
38
|
+
"author": "",
|
|
39
|
+
"license": "MIT",
|
|
40
|
+
"devDependencies": {
|
|
41
|
+
"@kulkan/kulterra-contracts": "1.1.5",
|
|
42
|
+
"@eslint/js": "^10.0.1",
|
|
43
|
+
"@types/express": "^5.0.5",
|
|
44
|
+
"@types/node": "^24.10.0",
|
|
45
|
+
"eslint": "^10.1.0",
|
|
46
|
+
"eslint-config-prettier": "^10.1.8",
|
|
47
|
+
"husky": "^9.1.7",
|
|
48
|
+
"lint-staged": "^16.4.0",
|
|
49
|
+
"prettier": "^3.8.1",
|
|
50
|
+
"tsup": "^8.5.1",
|
|
51
|
+
"typescript": "^5.9.3",
|
|
52
|
+
"typescript-eslint": "^8.58.0"
|
|
53
|
+
},
|
|
54
|
+
"peerDependencies": {
|
|
55
|
+
"@kulkan/kulterra-contracts": ">=1.1.5"
|
|
56
|
+
},
|
|
57
|
+
"publishConfig": {
|
|
58
|
+
"access": "public"
|
|
59
|
+
},
|
|
60
|
+
"scripts": {
|
|
61
|
+
"build": "tsup",
|
|
62
|
+
"clean": "rm -rf dist",
|
|
63
|
+
"typecheck": "tsc --noEmit",
|
|
64
|
+
"lint": "eslint . --cache --cache-location .eslintcache",
|
|
65
|
+
"lint:fix": "eslint . --fix --cache --cache-location .eslintcache",
|
|
66
|
+
"format": "prettier --write .",
|
|
67
|
+
"format:check": "prettier --check .",
|
|
68
|
+
"validate": "pnpm run typecheck && pnpm run lint && pnpm run format:check",
|
|
69
|
+
"publish:npm": "pnpm publish --access public --no-git-checks"
|
|
70
|
+
}
|
|
71
|
+
}
|