@validors/sdk 0.1.7 → 0.1.8

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.
Files changed (2) hide show
  1. package/README.md +20 -28
  2. package/package.json +1 -1
package/README.md CHANGED
@@ -123,28 +123,27 @@ All options are passed as a `ValidorsOptions` object to any of the middleware fa
123
123
  ```ts
124
124
  import * as validors from '@validors/sdk';
125
125
 
126
- export const { route } = validors.nextjs({
126
+ export const { monitor } = validors.nextjs({
127
127
  apiKey: process.env.VALIDORS_API_KEY!,
128
128
  });
129
129
  ```
130
130
 
131
- **Step 2** — add one line per route file:
131
+ **Step 2** — wrap each exported handler:
132
132
 
133
133
  ```ts
134
134
  // app/api/users/route.ts
135
135
  import { NextResponse } from 'next/server';
136
- import { route } from '@/lib/validors';
137
-
138
- export const { GET, POST } = route('/api/users', {
139
- GET: async (req) => {
140
- const users = await getUsers();
141
- return NextResponse.json({ users });
142
- },
143
- POST: async (req) => {
144
- const body = await req.json();
145
- const user = await createUser(body);
146
- return NextResponse.json({ user }, { status: 201 });
147
- },
136
+ import { monitor } from '@/lib/validors';
137
+
138
+ export const GET = monitor('/api/users', async (req) => {
139
+ const users = await getUsers();
140
+ return NextResponse.json({ users });
141
+ });
142
+
143
+ export const POST = monitor('/api/users', async (req) => {
144
+ const body = await req.json();
145
+ const user = await createUser(body);
146
+ return NextResponse.json({ user }, { status: 201 });
148
147
  });
149
148
  ```
150
149
 
@@ -153,20 +152,13 @@ export const { GET, POST } = route('/api/users', {
153
152
  ```ts
154
153
  // app/api/users/[id]/route.ts
155
154
  import { NextResponse } from 'next/server';
156
- import { route } from '@/lib/validors';
157
-
158
- export const { GET, DELETE } = route('/api/users/[id]', {
159
- GET: async (req, context) => {
160
- const { id } = await (context as { params: Promise<{ id: string }> }).params;
161
- const user = await getUserById(id);
162
- if (!user) return NextResponse.json({ error: 'Not found' }, { status: 404 });
163
- return NextResponse.json({ user });
164
- },
165
- DELETE: async (req, context) => {
166
- const { id } = await (context as { params: Promise<{ id: string }> }).params;
167
- await deleteUser(id);
168
- return NextResponse.json({ success: true });
169
- },
155
+ import { monitor } from '@/lib/validors';
156
+
157
+ export const GET = monitor('/api/users/[id]', async (req, context) => {
158
+ const { id } = await (context as { params: Promise<{ id: string }> }).params;
159
+ const user = await getUserById(id);
160
+ if (!user) return NextResponse.json({ error: 'Not found' }, { status: 404 });
161
+ return NextResponse.json({ user });
170
162
  });
171
163
  ```
172
164
 
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@validors/sdk",
3
- "version": "0.1.7",
3
+ "version": "0.1.8",
4
4
  "description": "Backend API monitoring SDK for Validors",
5
5
  "main": "dist/index.js",
6
6
  "types": "dist/index.d.ts",