@newhomestar/sdk 0.6.5 → 0.6.7
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/dist/next.d.ts +105 -0
- package/dist/next.js +67 -0
- package/package.json +5 -1
package/dist/next.d.ts
ADDED
|
@@ -0,0 +1,105 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* @newhomestar/sdk/next
|
|
3
|
+
*
|
|
4
|
+
* Utilities for building Nova service endpoints in Next.js App Router.
|
|
5
|
+
* Each route file exports a `nova` constant using `novaEndpoint()`.
|
|
6
|
+
*
|
|
7
|
+
* `nova services push` scans all route files for this export and
|
|
8
|
+
* auto-registers the endpoint in the platform DB (app_service_endpoints).
|
|
9
|
+
*
|
|
10
|
+
* @example
|
|
11
|
+
* ```ts
|
|
12
|
+
* // src/app/api/hris/employees/route.ts
|
|
13
|
+
* import { novaEndpoint } from '@newhomestar/sdk/next';
|
|
14
|
+
* import { z } from 'zod';
|
|
15
|
+
*
|
|
16
|
+
* export const nova = novaEndpoint({
|
|
17
|
+
* method: 'GET',
|
|
18
|
+
* path: '/hris/employees',
|
|
19
|
+
* category: 'employees',
|
|
20
|
+
* input: z.object({ page_size: z.coerce.number().default(25) }),
|
|
21
|
+
* output: z.object({ results: z.array(z.any()), next: z.string().nullable() }),
|
|
22
|
+
* });
|
|
23
|
+
*
|
|
24
|
+
* export async function GET(req: Request) {
|
|
25
|
+
* const input = nova.parseQuery(req);
|
|
26
|
+
* return nova.respond({ results: [], next: null });
|
|
27
|
+
* }
|
|
28
|
+
* ```
|
|
29
|
+
*/
|
|
30
|
+
import type { ZodTypeAny } from 'zod';
|
|
31
|
+
export type ParamIn = 'path' | 'query' | 'body' | 'header';
|
|
32
|
+
export type ParamUiType = 'text' | 'textarea' | 'number' | 'integer' | 'boolean' | 'date' | 'datetime' | 'select' | 'multiselect' | 'password' | 'email' | 'url' | 'uuid' | 'json' | 'hidden';
|
|
33
|
+
export interface ParamMeta {
|
|
34
|
+
in: ParamIn;
|
|
35
|
+
uiType?: ParamUiType;
|
|
36
|
+
label?: string;
|
|
37
|
+
description?: string;
|
|
38
|
+
placeholder?: string;
|
|
39
|
+
required?: boolean;
|
|
40
|
+
defaultValue?: unknown;
|
|
41
|
+
options?: Array<{
|
|
42
|
+
label: string;
|
|
43
|
+
value: string | number | boolean;
|
|
44
|
+
}>;
|
|
45
|
+
min?: number;
|
|
46
|
+
max?: number;
|
|
47
|
+
step?: number;
|
|
48
|
+
pattern?: string;
|
|
49
|
+
order?: number;
|
|
50
|
+
group?: string;
|
|
51
|
+
}
|
|
52
|
+
export interface NovaEndpointDef<I extends ZodTypeAny = ZodTypeAny, O extends ZodTypeAny = ZodTypeAny> {
|
|
53
|
+
/** HTTP method */
|
|
54
|
+
method: 'GET' | 'POST' | 'PUT' | 'PATCH' | 'DELETE';
|
|
55
|
+
/** REST path template. Use :param for path params. e.g. "/hris/employees/:id" */
|
|
56
|
+
path: string;
|
|
57
|
+
/** Human-readable description shown in Odyssey UI endpoint tester */
|
|
58
|
+
description?: string;
|
|
59
|
+
/** Endpoint group for Odyssey UI organization */
|
|
60
|
+
category?: string;
|
|
61
|
+
/** Reference to a service schema slug for the response */
|
|
62
|
+
responseSchema?: string;
|
|
63
|
+
/** Zod schema for query/path params — converted to JSON Schema on push */
|
|
64
|
+
input: I;
|
|
65
|
+
/** Zod schema for the response body — converted to JSON Schema on push */
|
|
66
|
+
output: O;
|
|
67
|
+
/** Per-field parameter metadata */
|
|
68
|
+
params?: Record<string, ParamMeta>;
|
|
69
|
+
/** Whether this endpoint requires a valid JWT (default: true) */
|
|
70
|
+
requiresAuth?: boolean;
|
|
71
|
+
/** Whether this endpoint returns sensitive data (SSN, DOB, etc.) */
|
|
72
|
+
sensitiveFields?: boolean;
|
|
73
|
+
}
|
|
74
|
+
export type NovaEndpoint<I extends ZodTypeAny = ZodTypeAny, O extends ZodTypeAny = ZodTypeAny> = NovaEndpointDef<I, O> & {
|
|
75
|
+
/**
|
|
76
|
+
* Parse and validate URL query string params against the input schema.
|
|
77
|
+
* Uses z.coerce for string→number/boolean conversion automatically.
|
|
78
|
+
*/
|
|
79
|
+
parseQuery(req: Request): ReturnType<I['parse']>;
|
|
80
|
+
/**
|
|
81
|
+
* Parse and validate JSON request body against the input schema.
|
|
82
|
+
*/
|
|
83
|
+
parseBody(req: Request): Promise<ReturnType<I['parse']>>;
|
|
84
|
+
/**
|
|
85
|
+
* Validate output data and serialize to a Response.
|
|
86
|
+
*/
|
|
87
|
+
respond(data: ReturnType<O['parse']>, status?: number): Response;
|
|
88
|
+
};
|
|
89
|
+
/**
|
|
90
|
+
* novaEndpoint() — define a Nova service endpoint co-located with its route.
|
|
91
|
+
*
|
|
92
|
+
* Export the result as `nova` and `nova services push` will auto-discover
|
|
93
|
+
* and register this endpoint in the platform DB.
|
|
94
|
+
*
|
|
95
|
+
* @example
|
|
96
|
+
* ```ts
|
|
97
|
+
* export const nova = novaEndpoint({
|
|
98
|
+
* method: 'GET',
|
|
99
|
+
* path: '/hris/employees',
|
|
100
|
+
* input: z.object({ page_size: z.coerce.number().default(25) }),
|
|
101
|
+
* output: z.object({ results: z.array(EmployeeZod), next: z.string().nullable() }),
|
|
102
|
+
* });
|
|
103
|
+
* ```
|
|
104
|
+
*/
|
|
105
|
+
export declare function novaEndpoint<I extends ZodTypeAny, O extends ZodTypeAny>(cfg: NovaEndpointDef<I, O>): NovaEndpoint<I, O>;
|
package/dist/next.js
ADDED
|
@@ -0,0 +1,67 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* @newhomestar/sdk/next
|
|
3
|
+
*
|
|
4
|
+
* Utilities for building Nova service endpoints in Next.js App Router.
|
|
5
|
+
* Each route file exports a `nova` constant using `novaEndpoint()`.
|
|
6
|
+
*
|
|
7
|
+
* `nova services push` scans all route files for this export and
|
|
8
|
+
* auto-registers the endpoint in the platform DB (app_service_endpoints).
|
|
9
|
+
*
|
|
10
|
+
* @example
|
|
11
|
+
* ```ts
|
|
12
|
+
* // src/app/api/hris/employees/route.ts
|
|
13
|
+
* import { novaEndpoint } from '@newhomestar/sdk/next';
|
|
14
|
+
* import { z } from 'zod';
|
|
15
|
+
*
|
|
16
|
+
* export const nova = novaEndpoint({
|
|
17
|
+
* method: 'GET',
|
|
18
|
+
* path: '/hris/employees',
|
|
19
|
+
* category: 'employees',
|
|
20
|
+
* input: z.object({ page_size: z.coerce.number().default(25) }),
|
|
21
|
+
* output: z.object({ results: z.array(z.any()), next: z.string().nullable() }),
|
|
22
|
+
* });
|
|
23
|
+
*
|
|
24
|
+
* export async function GET(req: Request) {
|
|
25
|
+
* const input = nova.parseQuery(req);
|
|
26
|
+
* return nova.respond({ results: [], next: null });
|
|
27
|
+
* }
|
|
28
|
+
* ```
|
|
29
|
+
*/
|
|
30
|
+
// ─── Factory function ─────────────────────────────────────────────────────────
|
|
31
|
+
/**
|
|
32
|
+
* novaEndpoint() — define a Nova service endpoint co-located with its route.
|
|
33
|
+
*
|
|
34
|
+
* Export the result as `nova` and `nova services push` will auto-discover
|
|
35
|
+
* and register this endpoint in the platform DB.
|
|
36
|
+
*
|
|
37
|
+
* @example
|
|
38
|
+
* ```ts
|
|
39
|
+
* export const nova = novaEndpoint({
|
|
40
|
+
* method: 'GET',
|
|
41
|
+
* path: '/hris/employees',
|
|
42
|
+
* input: z.object({ page_size: z.coerce.number().default(25) }),
|
|
43
|
+
* output: z.object({ results: z.array(EmployeeZod), next: z.string().nullable() }),
|
|
44
|
+
* });
|
|
45
|
+
* ```
|
|
46
|
+
*/
|
|
47
|
+
export function novaEndpoint(cfg) {
|
|
48
|
+
return {
|
|
49
|
+
...cfg,
|
|
50
|
+
parseQuery(req) {
|
|
51
|
+
const url = new URL(req.url);
|
|
52
|
+
const raw = {};
|
|
53
|
+
url.searchParams.forEach((value, key) => {
|
|
54
|
+
raw[key] = value;
|
|
55
|
+
});
|
|
56
|
+
return cfg.input.parse(raw);
|
|
57
|
+
},
|
|
58
|
+
async parseBody(req) {
|
|
59
|
+
const body = await req.json();
|
|
60
|
+
return cfg.input.parse(body);
|
|
61
|
+
},
|
|
62
|
+
respond(data, status = 200) {
|
|
63
|
+
const validated = cfg.output.parse(data);
|
|
64
|
+
return Response.json(validated, { status });
|
|
65
|
+
},
|
|
66
|
+
};
|
|
67
|
+
}
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@newhomestar/sdk",
|
|
3
|
-
"version": "0.6.
|
|
3
|
+
"version": "0.6.7",
|
|
4
4
|
"description": "Type-safe SDK for building Nova pipelines (workers & functions)",
|
|
5
5
|
"homepage": "https://github.com/newhomestar/nova-node-sdk#readme",
|
|
6
6
|
"bugs": {
|
|
@@ -19,6 +19,10 @@
|
|
|
19
19
|
".": {
|
|
20
20
|
"import": "./dist/index.js",
|
|
21
21
|
"types": "./dist/index.d.ts"
|
|
22
|
+
},
|
|
23
|
+
"./next": {
|
|
24
|
+
"import": "./dist/next.js",
|
|
25
|
+
"types": "./dist/next.d.ts"
|
|
22
26
|
}
|
|
23
27
|
},
|
|
24
28
|
"files": [
|