@nara-web/core 0.1.0

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.
@@ -0,0 +1,37 @@
1
+ export declare class HttpError extends Error {
2
+ readonly statusCode: number;
3
+ readonly code: string;
4
+ constructor(message: string, statusCode?: number, code?: string);
5
+ toJSON(): Record<string, unknown>;
6
+ }
7
+ export declare class ValidationError extends HttpError {
8
+ readonly errors: Record<string, string[]>;
9
+ constructor(message?: string, errors?: Record<string, string[]>);
10
+ toJSON(): Record<string, unknown>;
11
+ }
12
+ export declare class AuthError extends HttpError {
13
+ constructor(message?: string);
14
+ }
15
+ export declare class NotFoundError extends HttpError {
16
+ constructor(message?: string);
17
+ }
18
+ export declare class ForbiddenError extends HttpError {
19
+ constructor(message?: string);
20
+ }
21
+ export declare class BadRequestError extends HttpError {
22
+ constructor(message?: string);
23
+ }
24
+ export declare class ConflictError extends HttpError {
25
+ constructor(message?: string);
26
+ }
27
+ export declare class TooManyRequestsError extends HttpError {
28
+ readonly retryAfter?: number;
29
+ constructor(message?: string, retryAfter?: number);
30
+ toJSON(): Record<string, unknown>;
31
+ }
32
+ export declare class InternalError extends HttpError {
33
+ constructor(message?: string);
34
+ }
35
+ export declare function isHttpError(error: unknown): error is HttpError;
36
+ export declare function isValidationError(error: unknown): error is ValidationError;
37
+ //# sourceMappingURL=errors.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"errors.d.ts","sourceRoot":"","sources":["../src/errors.ts"],"names":[],"mappings":"AAgBA,qBAAa,SAAU,SAAQ,KAAK;IAClC,SAAgB,UAAU,EAAE,MAAM,CAAC;IACnC,SAAgB,IAAI,EAAE,MAAM,CAAC;gBAEjB,OAAO,EAAE,MAAM,EAAE,UAAU,GAAE,MAAY,EAAE,IAAI,GAAE,MAAqB;IAWlF,MAAM,IAAI,MAAM,CAAC,MAAM,EAAE,OAAO,CAAC;CAQlC;AAcD,qBAAa,eAAgB,SAAQ,SAAS;IAC5C,SAAgB,MAAM,EAAE,MAAM,CAAC,MAAM,EAAE,MAAM,EAAE,CAAC,CAAC;gBAErC,OAAO,GAAE,MAA4B,EAAE,MAAM,GAAE,MAAM,CAAC,MAAM,EAAE,MAAM,EAAE,CAAM;IAMxF,MAAM,IAAI,MAAM,CAAC,MAAM,EAAE,OAAO,CAAC;CAMlC;AAWD,qBAAa,SAAU,SAAQ,SAAS;gBAC1B,OAAO,GAAE,MAAuB;CAI7C;AAWD,qBAAa,aAAc,SAAQ,SAAS;gBAC9B,OAAO,GAAE,MAAoB;CAI1C;AAWD,qBAAa,cAAe,SAAQ,SAAS;gBAC/B,OAAO,GAAE,MAAoB;CAI1C;AAWD,qBAAa,eAAgB,SAAQ,SAAS;gBAChC,OAAO,GAAE,MAAsB;CAI5C;AAWD,qBAAa,aAAc,SAAQ,SAAS;gBAC9B,OAAO,GAAE,MAAmB;CAIzC;AAUD,qBAAa,oBAAqB,SAAQ,SAAS;IACjD,SAAgB,UAAU,CAAC,EAAE,MAAM,CAAC;gBAExB,OAAO,GAAE,MAA4B,EAAE,UAAU,CAAC,EAAE,MAAM;IAMtE,MAAM,IAAI,MAAM,CAAC,MAAM,EAAE,OAAO,CAAC;CAMlC;AAUD,qBAAa,aAAc,SAAQ,SAAS;gBAC9B,OAAO,GAAE,MAAgC;CAItD;AAKD,wBAAgB,WAAW,CAAC,KAAK,EAAE,OAAO,GAAG,KAAK,IAAI,SAAS,CAE9D;AAKD,wBAAgB,iBAAiB,CAAC,KAAK,EAAE,OAAO,GAAG,KAAK,IAAI,eAAe,CAE1E"}
package/dist/errors.js ADDED
@@ -0,0 +1,100 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.InternalError = exports.TooManyRequestsError = exports.ConflictError = exports.BadRequestError = exports.ForbiddenError = exports.NotFoundError = exports.AuthError = exports.ValidationError = exports.HttpError = void 0;
4
+ exports.isHttpError = isHttpError;
5
+ exports.isValidationError = isValidationError;
6
+ class HttpError extends Error {
7
+ constructor(message, statusCode = 500, code = 'HTTP_ERROR') {
8
+ super(message);
9
+ this.name = 'HttpError';
10
+ this.statusCode = statusCode;
11
+ this.code = code;
12
+ Error.captureStackTrace(this, this.constructor);
13
+ }
14
+ toJSON() {
15
+ return {
16
+ name: this.name,
17
+ message: this.message,
18
+ statusCode: this.statusCode,
19
+ code: this.code,
20
+ };
21
+ }
22
+ }
23
+ exports.HttpError = HttpError;
24
+ class ValidationError extends HttpError {
25
+ constructor(message = 'Validation failed', errors = {}) {
26
+ super(message, 422, 'VALIDATION_ERROR');
27
+ this.name = 'ValidationError';
28
+ this.errors = errors;
29
+ }
30
+ toJSON() {
31
+ return {
32
+ ...super.toJSON(),
33
+ errors: this.errors,
34
+ };
35
+ }
36
+ }
37
+ exports.ValidationError = ValidationError;
38
+ class AuthError extends HttpError {
39
+ constructor(message = 'Unauthorized') {
40
+ super(message, 401, 'AUTH_ERROR');
41
+ this.name = 'AuthError';
42
+ }
43
+ }
44
+ exports.AuthError = AuthError;
45
+ class NotFoundError extends HttpError {
46
+ constructor(message = 'Not Found') {
47
+ super(message, 404, 'NOT_FOUND');
48
+ this.name = 'NotFoundError';
49
+ }
50
+ }
51
+ exports.NotFoundError = NotFoundError;
52
+ class ForbiddenError extends HttpError {
53
+ constructor(message = 'Forbidden') {
54
+ super(message, 403, 'FORBIDDEN');
55
+ this.name = 'ForbiddenError';
56
+ }
57
+ }
58
+ exports.ForbiddenError = ForbiddenError;
59
+ class BadRequestError extends HttpError {
60
+ constructor(message = 'Bad Request') {
61
+ super(message, 400, 'BAD_REQUEST');
62
+ this.name = 'BadRequestError';
63
+ }
64
+ }
65
+ exports.BadRequestError = BadRequestError;
66
+ class ConflictError extends HttpError {
67
+ constructor(message = 'Conflict') {
68
+ super(message, 409, 'CONFLICT');
69
+ this.name = 'ConflictError';
70
+ }
71
+ }
72
+ exports.ConflictError = ConflictError;
73
+ class TooManyRequestsError extends HttpError {
74
+ constructor(message = 'Too Many Requests', retryAfter) {
75
+ super(message, 429, 'TOO_MANY_REQUESTS');
76
+ this.name = 'TooManyRequestsError';
77
+ this.retryAfter = retryAfter;
78
+ }
79
+ toJSON() {
80
+ return {
81
+ ...super.toJSON(),
82
+ ...(this.retryAfter && { retryAfter: this.retryAfter }),
83
+ };
84
+ }
85
+ }
86
+ exports.TooManyRequestsError = TooManyRequestsError;
87
+ class InternalError extends HttpError {
88
+ constructor(message = 'Internal Server Error') {
89
+ super(message, 500, 'INTERNAL_ERROR');
90
+ this.name = 'InternalError';
91
+ }
92
+ }
93
+ exports.InternalError = InternalError;
94
+ function isHttpError(error) {
95
+ return error instanceof HttpError;
96
+ }
97
+ function isValidationError(error) {
98
+ return error instanceof ValidationError;
99
+ }
100
+ //# sourceMappingURL=errors.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"errors.js","sourceRoot":"","sources":["../src/errors.ts"],"names":[],"mappings":";;;AAiMA,kCAEC;AAKD,8CAEC;AA1LD,MAAa,SAAU,SAAQ,KAAK;IAIlC,YAAY,OAAe,EAAE,aAAqB,GAAG,EAAE,OAAe,YAAY;QAChF,KAAK,CAAC,OAAO,CAAC,CAAC;QACf,IAAI,CAAC,IAAI,GAAG,WAAW,CAAC;QACxB,IAAI,CAAC,UAAU,GAAG,UAAU,CAAC;QAC7B,IAAI,CAAC,IAAI,GAAG,IAAI,CAAC;QACjB,KAAK,CAAC,iBAAiB,CAAC,IAAI,EAAE,IAAI,CAAC,WAAW,CAAC,CAAC;IAClD,CAAC;IAKD,MAAM;QACJ,OAAO;YACL,IAAI,EAAE,IAAI,CAAC,IAAI;YACf,OAAO,EAAE,IAAI,CAAC,OAAO;YACrB,UAAU,EAAE,IAAI,CAAC,UAAU;YAC3B,IAAI,EAAE,IAAI,CAAC,IAAI;SAChB,CAAC;IACJ,CAAC;CACF;AAvBD,8BAuBC;AAcD,MAAa,eAAgB,SAAQ,SAAS;IAG5C,YAAY,UAAkB,mBAAmB,EAAE,SAAmC,EAAE;QACtF,KAAK,CA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sCAKC;AAUD,MAAa,oBAAqB,SAAQ,SAAS;IAGjD,YAAY,UAAkB,mBAAmB,EAAE,UAAmB;QACpE,KAAK,CAAC,OAAO,EAAE,GAAG,EAAE,mBAAmB,CAAC,CAAC;QACzC,IAAI,CAAC,IAAI,GAAG,sBAAsB,CAAC;QACnC,IAAI,CAAC,UAAU,GAAG,UAAU,CAAC;IAC/B,CAAC;IAED,MAAM;QACJ,OAAO;YACL,GAAG,KAAK,CAAC,MAAM,EAAE;YACjB,GAAG,CAAC,IAAI,CAAC,UAAU,IAAI,EAAE,UAAU,EAAE,IAAI,CAAC,UAAU,EAAE,CAAC;SACxD,CAAC;IACJ,CAAC;CACF;AAfD,oDAeC;AAUD,MAAa,aAAc,SAAQ,SAAS;IAC1C,YAAY,UAAkB,uBAAuB;QACnD,KAAK,CAAC,OAAO,EAAE,GAAG,EAAE,gBAAgB,CAAC,CAAC;QACtC,IAAI,CAAC,IAAI,GAAG,eAAe,CAAC;IAC9B,CAAC;CACF;AALD,sCAKC;AAKD,SAAgB,WAAW,CAAC,KAAc;IACxC,OAAO,KAAK,YAAY,SAAS,CAAC;AACpC,CAAC;AAKD,SAAgB,iBAAiB,CAAC,KAAc;IAC9C,OAAO,KAAK,YAAY,eAAe,CAAC;AAC1C,CAAC"}
@@ -0,0 +1,3 @@
1
+ export * from './types';
2
+ export * from './adapters/types';
3
+ //# sourceMappingURL=index.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AAAA,cAAc,SAAS,CAAC;AACxB,cAAc,kBAAkB,CAAC"}
package/dist/index.js ADDED
@@ -0,0 +1,19 @@
1
+ "use strict";
2
+ var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) {
3
+ if (k2 === undefined) k2 = k;
4
+ var desc = Object.getOwnPropertyDescriptor(m, k);
5
+ if (!desc || ("get" in desc ? !m.__esModule : desc.writable || desc.configurable)) {
6
+ desc = { enumerable: true, get: function() { return m[k]; } };
7
+ }
8
+ Object.defineProperty(o, k2, desc);
9
+ }) : (function(o, m, k, k2) {
10
+ if (k2 === undefined) k2 = k;
11
+ o[k2] = m[k];
12
+ }));
13
+ var __exportStar = (this && this.__exportStar) || function(m, exports) {
14
+ for (var p in m) if (p !== "default" && !Object.prototype.hasOwnProperty.call(exports, p)) __createBinding(exports, m, p);
15
+ };
16
+ Object.defineProperty(exports, "__esModule", { value: true });
17
+ __exportStar(require("./types"), exports);
18
+ __exportStar(require("./adapters/types"), exports);
19
+ //# sourceMappingURL=index.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"index.js","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":";;;;;;;;;;;;;;;;AAAA,0CAAwB;AACxB,mDAAiC"}
@@ -0,0 +1,29 @@
1
+ import type { NaraResponse } from './types';
2
+ import { PaginatedMeta } from '@services/Paginator';
3
+ export type PaginationMeta = PaginatedMeta;
4
+ export type { PaginatedMeta };
5
+ export type ResponseMeta = PaginationMeta | Record<string, unknown>;
6
+ export interface ApiSuccessResponse<T = unknown> {
7
+ success: true;
8
+ message: string;
9
+ data?: T;
10
+ meta?: ResponseMeta;
11
+ }
12
+ export interface ApiErrorResponse {
13
+ success: false;
14
+ message: string;
15
+ code?: string;
16
+ errors?: Record<string, string[]>;
17
+ }
18
+ export type ApiResponse<T = unknown> = ApiSuccessResponse<T> | ApiErrorResponse;
19
+ export declare function jsonSuccess<T = unknown>(res: NaraResponse, message: string, data?: T, meta?: ResponseMeta, statusCode?: number): NaraResponse;
20
+ export declare function jsonError(res: NaraResponse, message: string, statusCode?: number, code?: string, errors?: Record<string, string[]>): NaraResponse;
21
+ export declare function jsonPaginated<T = unknown>(res: NaraResponse, message: string, data: T[], meta: PaginatedMeta): NaraResponse;
22
+ export declare function jsonCreated<T = unknown>(res: NaraResponse, message: string, data?: T): NaraResponse;
23
+ export declare function jsonNoContent(res: NaraResponse): NaraResponse;
24
+ export declare function jsonUnauthorized(res: NaraResponse, message?: string): NaraResponse;
25
+ export declare function jsonForbidden(res: NaraResponse, message?: string): NaraResponse;
26
+ export declare function jsonNotFound(res: NaraResponse, message?: string): NaraResponse;
27
+ export declare function jsonValidationError(res: NaraResponse, message?: string, errors?: Record<string, string[]>): NaraResponse;
28
+ export declare function jsonServerError(res: NaraResponse, message?: string): NaraResponse;
29
+ //# sourceMappingURL=response.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"response.d.ts","sourceRoot":"","sources":["../src/response.ts"],"names":[],"mappings":"AAqBA,OAAO,KAAK,EAAE,YAAY,EAAE,MAAM,SAAS,CAAC;AAE5C,OAAO,EAAE,aAAa,EAAE,MAAM,qBAAqB,CAAC;AAMpD,MAAM,MAAM,cAAc,GAAG,aAAa,CAAC;AAC3C,YAAY,EAAE,aAAa,EAAE,CAAC;AAK9B,MAAM,MAAM,YAAY,GAAG,cAAc,GAAG,MAAM,CAAC,MAAM,EAAE,OAAO,CAAC,CAAC;AAKpE,MAAM,WAAW,kBAAkB,CAAC,CAAC,GAAG,OAAO;IAC7C,OAAO,EAAE,IAAI,CAAC;IACd,OAAO,EAAE,MAAM,CAAC;IAChB,IAAI,CAAC,EAAE,CAAC,CAAC;IACT,IAAI,CAAC,EAAE,YAAY,CAAC;CACrB;AAKD,MAAM,WAAW,gBAAgB;IAC/B,OAAO,EAAE,KAAK,CAAC;IACf,OAAO,EAAE,MAAM,CAAC;IAChB,IAAI,CAAC,EAAE,MAAM,CAAC;IACd,MAAM,CAAC,EAAE,MAAM,CAAC,MAAM,EAAE,MAAM,EAAE,CAAC,CAAC;CACnC;AAKD,MAAM,MAAM,WAAW,CAAC,CAAC,GAAG,OAAO,IAAI,kBAAkB,CAAC,CAAC,CAAC,GAAG,gBAAgB,CAAC;AAyBhF,wBAAgB,WAAW,CAAC,CAAC,GAAG,OAAO,EACrC,GAAG,EAAE,YAAY,EACjB,OAAO,EAAE,MAAM,EACf,IAAI,CAAC,EAAE,CAAC,EACR,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ports.jsonSuccess = jsonSuccess;
4
+ exports.jsonError = jsonError;
5
+ exports.jsonPaginated = jsonPaginated;
6
+ exports.jsonCreated = jsonCreated;
7
+ exports.jsonNoContent = jsonNoContent;
8
+ exports.jsonUnauthorized = jsonUnauthorized;
9
+ exports.jsonForbidden = jsonForbidden;
10
+ exports.jsonNotFound = jsonNotFound;
11
+ exports.jsonValidationError = jsonValidationError;
12
+ exports.jsonServerError = jsonServerError;
13
+ function jsonSuccess(res, message, data, meta, statusCode = 200) {
14
+ const response = {
15
+ success: true,
16
+ message,
17
+ };
18
+ if (data !== undefined) {
19
+ response.data = data;
20
+ }
21
+ if (meta !== undefined) {
22
+ response.meta = meta;
23
+ }
24
+ res.status(statusCode).json(response);
25
+ return res;
26
+ }
27
+ function jsonError(res, message, statusCode = 400, code, errors) {
28
+ const response = {
29
+ success: false,
30
+ message,
31
+ };
32
+ if (code !== undefined) {
33
+ response.code = code;
34
+ }
35
+ if (errors !== undefined) {
36
+ response.errors = errors;
37
+ }
38
+ res.status(statusCode).json(response);
39
+ return res;
40
+ }
41
+ function jsonPaginated(res, message, data, meta) {
42
+ const paginationMeta = {
43
+ ...meta,
44
+ totalPages: meta.totalPages ?? Math.ceil(meta.total / meta.limit),
45
+ };
46
+ return jsonSuccess(res, message, data, paginationMeta);
47
+ }
48
+ function jsonCreated(res, message, data) {
49
+ return jsonSuccess(res, message, data, undefined, 201);
50
+ }
51
+ function jsonNoContent(res) {
52
+ res.status(204).send('');
53
+ return res;
54
+ }
55
+ function jsonUnauthorized(res, message = 'Unauthorized') {
56
+ return jsonError(res, message, 401, 'UNAUTHORIZED');
57
+ }
58
+ function jsonForbidden(res, message = 'Forbidden') {
59
+ return jsonError(res, message, 403, 'FORBIDDEN');
60
+ }
61
+ function jsonNotFound(res, message = 'Not Found') {
62
+ return jsonError(res, message, 404, 'NOT_FOUND');
63
+ }
64
+ function jsonValidationError(res, message = 'Validation failed', errors) {
65
+ return jsonError(res, message, 422, 'VALIDATION_ERROR', errors);
66
+ }
67
+ function jsonServerError(res, message = 'Internal Server Error') {
68
+ return jsonError(res, message, 500, 'INTERNAL_ERROR');
69
+ }
70
+ //# sourceMappingURL=response.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"response.js","sourceRoot":"","sources":["../src/response.ts"],"names":[],"mappings":";;AAqFA,kCAsBC;AAyBD,8BAsBC;AAwBD,sCAaC;AAUD,kCAMC;AAYD,sCAGC;AAQD,4CAKC;AAQD,sCAKC;AAQD,oCAKC;AAWD,kDAMC;AAQD,0CAKC;AA9MD,SAAgB,WAAW,CACzB,GAAiB,EACjB,OAAe,EACf,IAAQ,EACR,IAAmB,EACnB,aAAqB,GAAG;IAExB,MAAM,QAAQ,GAA0B;QACtC,OAAO,EAAE,IAAI;QACb,OAAO;KACR,CAAC;IAEF,IAAI,IAAI,KAAK,SAAS,EAAE,CAAC;QACvB,QAAQ,CAAC,IAAI,GAAG,IAAI,CAAC;IACvB,CAAC;IAED,IAAI,IAAI,KAAK,SAAS,EAAE,CAAC;QACvB,QAAQ,CAAC,IAAI,GAAG,IAAI,CAAC;IACvB,CAAC;IAED,GAAG,CAAC,MAAM,CAAC,UAAU,CAAC,CAAC,IAAI,CAAC,QAAQ,CAAC,CAAC;IACtC,OAAO,GAAG,CAAC;AACb,CAAC;AAyBD,SAAgB,SAAS,CACvB,GAAiB,EACjB,OAAe,EACf,aAAqB,GAAG,EACxB,IAAa,EACb,MAAiC;IAEjC,MAAM,QAAQ,GAAqB;QACjC,OAAO,EAAE,KAAK;QACd,OAAO;KACR,CAAC;IAEF,IAAI,IAAI,KAAK,SAAS,EAAE,CAAC;QACvB,QAAQ,CAAC,IAAI,GAAG,IAAI,CAAC;IACvB,CAAC;IAED,IAAI,MAAM,KAAK,SAAS,EAAE,CAAC;QACzB,QAAQ,CAAC,MAAM,GAAG,MAAM,CAAC;IAC3B,CAAC;IAED,GAAG,CAAC,MAAM,CAAC,UAAU,CAAC,CAAC,IAAI,CAAC,QAAQ,CAAC,C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G,EAAE,kBAAkB,EAAE,MAAM,CAAC,CAAC;AAClE,CAAC;AAQD,SAAgB,eAAe,CAC7B,GAAiB,EACjB,UAAkB,uBAAuB;IAEzC,OAAO,SAAS,CAAC,GAAG,EAAE,OAAO,EAAE,GAAG,EAAE,gBAAgB,CAAC,CAAC;AACxD,CAAC"}
@@ -0,0 +1,27 @@
1
+ import type { Request as HyperRequest, Response as HyperResponse, MiddlewareNext } from "hyper-express";
2
+ export interface User {
3
+ id: string;
4
+ name: string | null;
5
+ email: string;
6
+ phone: string | null;
7
+ avatar: string | null;
8
+ is_admin: boolean;
9
+ is_verified: boolean;
10
+ created_at?: number;
11
+ updated_at?: number;
12
+ }
13
+ export interface NaraRequest extends HyperRequest {
14
+ user?: User;
15
+ share?: Record<string, unknown>;
16
+ }
17
+ export interface NaraResponse extends HyperResponse {
18
+ view(template: string, data?: Record<string, unknown>): Promise<unknown>;
19
+ inertia?(component: string, props?: Record<string, unknown>, viewProps?: Record<string, unknown>): Promise<unknown>;
20
+ flash(key: string, value: unknown): NaraResponse;
21
+ }
22
+ export interface NaraResponseWithInertia extends NaraResponse {
23
+ inertia(component: string, props?: Record<string, unknown>, viewProps?: Record<string, unknown>): Promise<unknown>;
24
+ }
25
+ export type NaraMiddleware = (req: NaraRequest, res: NaraResponse, next: MiddlewareNext) => unknown | Promise<unknown>;
26
+ export type NaraHandler = (req: NaraRequest, res: NaraResponse) => unknown | Promise<unknown>;
27
+ //# sourceMappingURL=types.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"types.d.ts","sourceRoot":"","sources":["../src/types.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,OAAO,IAAI,YAAY,EAAE,QAAQ,IAAI,aAAa,EAAE,cAAc,EAAE,MAAM,eAAe,CAAC;AAKxG,MAAM,WAAW,IAAI;IACnB,EAAE,EAAE,MAAM,CAAC;IACX,IAAI,EAAE,MAAM,GAAG,IAAI,CAAC;IACpB,KAAK,EAAE,MAAM,CAAC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M,WAAW,GAAG,CACxB,GAAG,EAAE,WAAW,EAChB,GAAG,EAAE,YAAY,KACd,OAAO,GAAG,OAAO,CAAC,OAAO,CAAC,CAAC"}
package/dist/types.js ADDED
@@ -0,0 +1,3 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ //# sourceMappingURL=types.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"types.js","sourceRoot":"","sources":["../src/types.ts"],"names":[],"mappings":""}
package/package.json ADDED
@@ -0,0 +1,24 @@
1
+ {
2
+ "name": "@nara-web/core",
3
+ "version": "0.1.0",
4
+ "description": "NARA Framework Core - HyperExpress-based Node.js framework",
5
+ "main": "dist/index.js",
6
+ "types": "dist/index.d.ts",
7
+ "exports": {
8
+ ".": "./dist/index.js"
9
+ },
10
+ "scripts": {
11
+ "build": "tsc",
12
+ "dev": "tsc --watch"
13
+ },
14
+ "dependencies": {
15
+ "hyper-express": "^6.17.3",
16
+ "knex": "^3.1.0",
17
+ "bcrypt": "^5.1.1",
18
+ "jsonwebtoken": "^9.0.2",
19
+ "dotenv": "^16.4.7",
20
+ "zod": "^3.24.1"
21
+ },
22
+ "peerDependencies": {},
23
+ "license": "MIT"
24
+ }
@@ -0,0 +1,31 @@
1
+ import type { MiddlewareNext } from "hyper-express";
2
+ import type { NaraRequest, NaraResponse } from "../types";
3
+
4
+ /**
5
+ * Handler type for adapter middleware
6
+ */
7
+ export type AdapterMiddlewareHandler = (
8
+ req: NaraRequest,
9
+ res: NaraResponse,
10
+ next: MiddlewareNext
11
+ ) => unknown | Promise<unknown>;
12
+
13
+ /**
14
+ * Frontend Adapter Interface
15
+ */
16
+ export interface FrontendAdapter {
17
+ /**
18
+ * Unique name for the adapter
19
+ */
20
+ name: string;
21
+
22
+ /**
23
+ * Factory that returns the adapter's global middleware
24
+ */
25
+ middleware: () => AdapterMiddlewareHandler;
26
+
27
+ /**
28
+ * Method called during app initialization to extend the NaraResponse prototype or instance
29
+ */
30
+ extendResponse: (res: NaraResponse) => void;
31
+ }
package/src/index.ts ADDED
@@ -0,0 +1,2 @@
1
+ export * from './types';
2
+ export * from './adapters/types';
package/src/types.ts ADDED
@@ -0,0 +1,65 @@
1
+ import type { Request as HyperRequest, Response as HyperResponse, MiddlewareNext } from "hyper-express";
2
+
3
+ /**
4
+ * User interface for authenticated requests
5
+ */
6
+ export interface User {
7
+ id: string;
8
+ name: string | null;
9
+ email: string;
10
+ phone: string | null;
11
+ avatar: string | null;
12
+ is_admin: boolean;
13
+ is_verified: boolean;
14
+ created_at?: number;
15
+ updated_at?: number;
16
+ }
17
+
18
+ /**
19
+ * Extended Request interface with user and shared data
20
+ */
21
+ export interface NaraRequest extends HyperRequest {
22
+ user?: User;
23
+ share?: Record<string, unknown>;
24
+ }
25
+
26
+ /**
27
+ * Extended Response interface with Nara-specific methods
28
+ */
29
+ export interface NaraResponse extends HyperResponse {
30
+ view(template: string, data?: Record<string, unknown>): Promise<unknown>;
31
+ inertia?(
32
+ component: string,
33
+ props?: Record<string, unknown>,
34
+ viewProps?: Record<string, unknown>
35
+ ): Promise<unknown>;
36
+ flash(key: string, value: unknown): NaraResponse;
37
+ }
38
+
39
+ /**
40
+ * NaraResponse with Inertia support explicitly enabled
41
+ */
42
+ export interface NaraResponseWithInertia extends NaraResponse {
43
+ inertia(
44
+ component: string,
45
+ props?: Record<string, unknown>,
46
+ viewProps?: Record<string, unknown>
47
+ ): Promise<unknown>;
48
+ }
49
+
50
+ /**
51
+ * Middleware function type
52
+ */
53
+ export type NaraMiddleware = (
54
+ req: NaraRequest,
55
+ res: NaraResponse,
56
+ next: MiddlewareNext
57
+ ) => unknown | Promise<unknown>;
58
+
59
+ /**
60
+ * Route handler function type
61
+ */
62
+ export type NaraHandler = (
63
+ req: NaraRequest,
64
+ res: NaraResponse
65
+ ) => unknown | Promise<unknown>;
package/tsconfig.json ADDED
@@ -0,0 +1,11 @@
1
+ {
2
+ "extends": "../../tsconfig.json",
3
+ "compilerOptions": {
4
+ "outDir": "./dist",
5
+ "rootDir": "./src",
6
+ "composite": true,
7
+ "declaration": true,
8
+ "declarationMap": true
9
+ },
10
+ "include": ["src/**/*"]
11
+ }