@arkyn/server 3.0.3 → 3.0.5
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/README.md +20 -20
- package/dist/http/badResponses/badGateway.d.ts +1 -1
- package/dist/http/badResponses/badRequest.d.ts +1 -1
- package/dist/http/badResponses/conflict.d.ts +1 -1
- package/dist/http/badResponses/forbidden.d.ts +1 -1
- package/dist/http/badResponses/notFound.d.ts +1 -1
- package/dist/http/badResponses/notImplemented.d.ts +1 -1
- package/dist/http/badResponses/serverError.d.ts +1 -1
- package/dist/http/badResponses/unauthorized.d.ts +1 -1
- package/dist/http/badResponses/unprocessableEntity.d.ts +1 -1
- package/dist/http/successResponses/created.d.ts +1 -1
- package/dist/http/successResponses/found.d.ts +1 -1
- package/dist/http/successResponses/noContent.d.ts +1 -1
- package/dist/http/successResponses/success.d.ts +1 -1
- package/dist/http/successResponses/updated.d.ts +1 -1
- package/dist/index.js.map +1 -1
- package/dist/modules/http/badResponses/badGateway.js.map +1 -1
- package/dist/modules/http/badResponses/badRequest.js.map +1 -1
- package/dist/modules/http/badResponses/conflict.js.map +1 -1
- package/dist/modules/http/badResponses/forbidden.js.map +1 -1
- package/dist/modules/http/badResponses/notFound.js.map +1 -1
- package/dist/modules/http/badResponses/notImplemented.js.map +1 -1
- package/dist/modules/http/badResponses/serverError.js.map +1 -1
- package/dist/modules/http/badResponses/unauthorized.js.map +1 -1
- package/dist/modules/http/badResponses/unprocessableEntity.js.map +1 -1
- package/dist/modules/http/successResponses/created.js.map +1 -1
- package/dist/modules/http/successResponses/found.js.map +1 -1
- package/dist/modules/http/successResponses/noContent.js.map +1 -1
- package/dist/modules/http/successResponses/success.js.map +1 -1
- package/dist/modules/http/successResponses/updated.js.map +1 -1
- package/dist/modules/services/debugService.js.map +1 -1
- package/dist/modules/utilities/formAsyncParse.js.map +1 -1
- package/dist/modules/utilities/schemaValidator.js.map +1 -1
- package/dist/services/debugService.d.ts +1 -1
- package/dist/utilities/formAsyncParse.d.ts +1 -1
- package/dist/utilities/schemaValidator.d.ts +4 -4
- package/package.json +1 -1
package/README.md
CHANGED
|
@@ -8,7 +8,7 @@ Comprehensive server-side utilities for building robust backend applications, fe
|
|
|
8
8
|
|
|
9
9
|
## 🎯 What it solves
|
|
10
10
|
|
|
11
|
-
Backend code
|
|
11
|
+
Backend code, Remix/React Router loaders and actions, or any fetch-based server, tends to reinvent the same plumbing on every project: consistent success/error response shapes, centralized error handling, request body/form parsing, schema validation, and validation of Brazilian documents (CPF/CNPJ/CEP/RG) plus generic fields (email/password/phone/date). `@arkyn/server` packages all of that into small, well-typed primitives so route handlers stay focused on business logic instead of response boilerplate.
|
|
12
12
|
|
|
13
13
|
## ✨ Features
|
|
14
14
|
|
|
@@ -24,12 +24,12 @@ Backend code — Remix/React Router loaders and actions, or any fetch-based serv
|
|
|
24
24
|
|
|
25
25
|
- **Node.js** `>=18.0.0` or **Bun** `>=1.0.0`
|
|
26
26
|
- Peer dependencies (install alongside `@arkyn/server`):
|
|
27
|
-
- `zod >=4.4.3
|
|
28
|
-
- `libphonenumber-js >=1.13.7
|
|
27
|
+
- `zod >=4.4.3`, required by `SchemaValidator`, `formParse`, and `formAsyncParse`.
|
|
28
|
+
- `libphonenumber-js >=1.13.7`, required by `validatePhone`.
|
|
29
29
|
|
|
30
30
|
## 📦 Installation
|
|
31
31
|
|
|
32
|
-
> **ESM only.** This package ships as native ES modules with no CommonJS build
|
|
32
|
+
> **ESM only.** This package ships as native ES modules with no CommonJS build, use `import`, not `require()`.
|
|
33
33
|
|
|
34
34
|
```bash
|
|
35
35
|
npm install @arkyn/server zod libphonenumber-js
|
|
@@ -58,11 +58,11 @@ export async function action({ request }: ActionFunctionArgs) {
|
|
|
58
58
|
|
|
59
59
|
### HTTP Responses
|
|
60
60
|
|
|
61
|
-
Every response class extends a base with `.toResponse()` (returns a `Response` with a `Content-Type: application/json` header) and `.toJson()` (built on `Response.json()`). Both produce an equivalent JSON body
|
|
61
|
+
Every response class extends a base with `.toResponse()` (returns a `Response` with a `Content-Type: application/json` header) and `.toJson()` (built on `Response.json()`). Both produce an equivalent JSON body, pick whichever reads better at the call site. `NoContent` only exposes `.toResponse()`, since it always returns a `null` body.
|
|
62
62
|
|
|
63
63
|
#### BadGateway
|
|
64
64
|
|
|
65
|
-
HTTP 502
|
|
65
|
+
HTTP 502, the upstream server returned an invalid or unexpected response.
|
|
66
66
|
|
|
67
67
|
```typescript
|
|
68
68
|
throw new BadGateway("Payment gateway unavailable");
|
|
@@ -70,7 +70,7 @@ throw new BadGateway("Payment gateway unavailable");
|
|
|
70
70
|
|
|
71
71
|
#### BadRequest
|
|
72
72
|
|
|
73
|
-
HTTP 400
|
|
73
|
+
HTTP 400, the request is malformed or contains invalid data.
|
|
74
74
|
|
|
75
75
|
```typescript
|
|
76
76
|
throw new BadRequest("Invalid request body");
|
|
@@ -78,7 +78,7 @@ throw new BadRequest("Invalid request body");
|
|
|
78
78
|
|
|
79
79
|
#### Conflict
|
|
80
80
|
|
|
81
|
-
HTTP 409
|
|
81
|
+
HTTP 409, the request conflicts with the current state of the server (e.g. duplicate record).
|
|
82
82
|
|
|
83
83
|
```typescript
|
|
84
84
|
throw new Conflict("Email already in use");
|
|
@@ -86,7 +86,7 @@ throw new Conflict("Email already in use");
|
|
|
86
86
|
|
|
87
87
|
#### Forbidden
|
|
88
88
|
|
|
89
|
-
HTTP 403
|
|
89
|
+
HTTP 403, authenticated but not authorized to access this resource.
|
|
90
90
|
|
|
91
91
|
```typescript
|
|
92
92
|
throw new Forbidden("You don't have permission to delete this resource");
|
|
@@ -94,7 +94,7 @@ throw new Forbidden("You don't have permission to delete this resource");
|
|
|
94
94
|
|
|
95
95
|
#### NotFound
|
|
96
96
|
|
|
97
|
-
HTTP 404
|
|
97
|
+
HTTP 404, the requested resource does not exist.
|
|
98
98
|
|
|
99
99
|
```typescript
|
|
100
100
|
throw new NotFound("Product not found");
|
|
@@ -102,7 +102,7 @@ throw new NotFound("Product not found");
|
|
|
102
102
|
|
|
103
103
|
#### NotImplemented
|
|
104
104
|
|
|
105
|
-
HTTP 501
|
|
105
|
+
HTTP 501, the server does not support the functionality required to fulfill the request.
|
|
106
106
|
|
|
107
107
|
```typescript
|
|
108
108
|
throw new NotImplemented("Webhook delivery is not yet implemented");
|
|
@@ -110,7 +110,7 @@ throw new NotImplemented("Webhook delivery is not yet implemented");
|
|
|
110
110
|
|
|
111
111
|
#### ServerError
|
|
112
112
|
|
|
113
|
-
HTTP 500
|
|
113
|
+
HTTP 500, an unexpected condition prevented the server from fulfilling the request.
|
|
114
114
|
|
|
115
115
|
```typescript
|
|
116
116
|
throw new ServerError("Failed to connect to the database");
|
|
@@ -118,7 +118,7 @@ throw new ServerError("Failed to connect to the database");
|
|
|
118
118
|
|
|
119
119
|
#### Unauthorized
|
|
120
120
|
|
|
121
|
-
HTTP 401
|
|
121
|
+
HTTP 401, the request lacks valid authentication credentials.
|
|
122
122
|
|
|
123
123
|
```typescript
|
|
124
124
|
throw new Unauthorized("Invalid or expired token");
|
|
@@ -126,7 +126,7 @@ throw new Unauthorized("Invalid or expired token");
|
|
|
126
126
|
|
|
127
127
|
#### UnprocessableEntity
|
|
128
128
|
|
|
129
|
-
HTTP 422
|
|
129
|
+
HTTP 422, the request is well-formed but contains semantic validation errors. Typically used for form field validation failures.
|
|
130
130
|
|
|
131
131
|
```typescript
|
|
132
132
|
throw new UnprocessableEntity({
|
|
@@ -138,7 +138,7 @@ throw new UnprocessableEntity({
|
|
|
138
138
|
|
|
139
139
|
#### Created
|
|
140
140
|
|
|
141
|
-
HTTP 201
|
|
141
|
+
HTTP 201, the request succeeded and a new resource was created.
|
|
142
142
|
|
|
143
143
|
```typescript
|
|
144
144
|
return new Created("User created successfully", { id: user.id }).toJson();
|
|
@@ -146,7 +146,7 @@ return new Created("User created successfully", { id: user.id }).toJson();
|
|
|
146
146
|
|
|
147
147
|
#### Found
|
|
148
148
|
|
|
149
|
-
HTTP 302
|
|
149
|
+
HTTP 302, the resource was located and the response includes it in the body.
|
|
150
150
|
|
|
151
151
|
```typescript
|
|
152
152
|
return new Found("Products retrieved", { products }).toJson();
|
|
@@ -154,7 +154,7 @@ return new Found("Products retrieved", { products }).toJson();
|
|
|
154
154
|
|
|
155
155
|
#### NoContent
|
|
156
156
|
|
|
157
|
-
HTTP 204
|
|
157
|
+
HTTP 204, the request succeeded but there is no content to return. Typically used for delete or update operations where a body is not needed.
|
|
158
158
|
|
|
159
159
|
```typescript
|
|
160
160
|
return new NoContent("Record deleted").toResponse();
|
|
@@ -162,7 +162,7 @@ return new NoContent("Record deleted").toResponse();
|
|
|
162
162
|
|
|
163
163
|
#### Success
|
|
164
164
|
|
|
165
|
-
HTTP 200
|
|
165
|
+
HTTP 200, the request succeeded and the response body contains the result.
|
|
166
166
|
|
|
167
167
|
```typescript
|
|
168
168
|
return new Success("Order fetched", { order }).toJson();
|
|
@@ -170,7 +170,7 @@ return new Success("Order fetched", { order }).toJson();
|
|
|
170
170
|
|
|
171
171
|
#### Updated
|
|
172
172
|
|
|
173
|
-
HTTP 200
|
|
173
|
+
HTTP 200, the request succeeded and the resource was updated. Semantically equivalent to `Success` but signals an update operation to consumers.
|
|
174
174
|
|
|
175
175
|
```typescript
|
|
176
176
|
return new Updated("Profile updated", { user }).toJson();
|
|
@@ -268,7 +268,7 @@ flushDebugLogs({
|
|
|
268
268
|
|
|
269
269
|
#### formAsyncParse
|
|
270
270
|
|
|
271
|
-
Async variant of `formParse
|
|
271
|
+
Async variant of `formParse`, uses `safeParseAsync` to support Zod schemas with async refinements. Returns `{ success: true, data }` on success or `{ success: false, fieldErrors, fields }` on failure.
|
|
272
272
|
|
|
273
273
|
```typescript
|
|
274
274
|
const schema = z.object({ email: z.string().email() });
|
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
import { BadResponse } from "./_badResponse";
|
|
2
2
|
/**
|
|
3
|
-
* HTTP 502 Bad Gateway
|
|
3
|
+
* HTTP 502 Bad Gateway, the upstream server returned an invalid or unexpected response.
|
|
4
4
|
*
|
|
5
5
|
* Throw inside a server action/loader and catch with `errorHandler`, or call `.toJson()` directly.
|
|
6
6
|
*
|
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
import { BadResponse } from "./_badResponse";
|
|
2
2
|
/**
|
|
3
|
-
* HTTP 409 Conflict
|
|
3
|
+
* HTTP 409 Conflict, the request conflicts with the current state of the server (e.g. duplicate record).
|
|
4
4
|
*
|
|
5
5
|
* @example
|
|
6
6
|
* ```typescript
|
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
import { BadResponse } from "./_badResponse";
|
|
2
2
|
/**
|
|
3
|
-
* HTTP 501 Not Implemented
|
|
3
|
+
* HTTP 501 Not Implemented, the server does not support the functionality required to fulfill the request.
|
|
4
4
|
*
|
|
5
5
|
* @example
|
|
6
6
|
* ```typescript
|
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
import { BadResponse } from "./_badResponse";
|
|
2
2
|
/**
|
|
3
|
-
* HTTP 500 Internal Server Error
|
|
3
|
+
* HTTP 500 Internal Server Error, an unexpected condition prevented the server from fulfilling the request.
|
|
4
4
|
*
|
|
5
5
|
* @example
|
|
6
6
|
* ```typescript
|
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
import { BadResponse } from "./_badResponse";
|
|
2
2
|
/**
|
|
3
|
-
* HTTP 422 Unprocessable Entity
|
|
3
|
+
* HTTP 422 Unprocessable Entity, the request is well-formed but contains semantic validation errors.
|
|
4
4
|
* Typically used for form field validation failures.
|
|
5
5
|
*
|
|
6
6
|
* @example
|
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
import { SuccessResponse } from "./_successResponse";
|
|
2
2
|
/**
|
|
3
|
-
* HTTP 302 Found
|
|
3
|
+
* HTTP 302 Found, the resource was located and the response includes it in the body.
|
|
4
4
|
*
|
|
5
5
|
* @example
|
|
6
6
|
* ```typescript
|
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
import { SuccessResponse } from "./_successResponse";
|
|
2
2
|
/**
|
|
3
|
-
* HTTP 204 No Content
|
|
3
|
+
* HTTP 204 No Content, the request succeeded but there is no content to return.
|
|
4
4
|
* Typically used for delete or update operations where a body is not needed.
|
|
5
5
|
*
|
|
6
6
|
* @example
|
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
import { SuccessResponse } from "./_successResponse";
|
|
2
2
|
/**
|
|
3
|
-
* HTTP 200 OK
|
|
3
|
+
* HTTP 200 OK, the request succeeded and the resource was updated.
|
|
4
4
|
* Semantically equivalent to `Success` but signals an update operation to consumers.
|
|
5
5
|
*
|
|
6
6
|
* @example
|