@hywax/cms 3.0.0 → 3.0.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.
@@ -1,13 +1,4 @@
1
- export type HttpStatusKey
2
- = ('badRequest' | 'unauthorized' | 'forbidden' | 'notFound' | 'alreadyExists' | 'notAllowed' | 'internalServerError' | 'dbNotDefined' | 'dbConnectionRefused' | 'dbInsertFailed' | 'badGateway' | 'serviceUnavailable')
3
- & string
4
-
5
- export interface HttpStatus {
6
- code: number
7
- message: string
8
- }
9
-
10
- export const httpStatuses: Record<HttpStatusKey, HttpStatus> = {
1
+ export const httpStatuses = {
11
2
  "badRequest": {
12
3
  "code": 400,
13
4
  "message": "Неверный запрос"
package/dist/module.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@hywax/cms",
3
- "version": "3.0.0",
3
+ "version": "3.0.1",
4
4
  "configKey": "cms",
5
5
  "builder": {
6
6
  "@nuxt/module-builder": "1.0.2",
package/dist/module.mjs CHANGED
@@ -7,7 +7,7 @@ import { pascalCase, kebabCase } from 'scule';
7
7
  import { globSync } from 'tinyglobby';
8
8
 
9
9
  const name = "@hywax/cms";
10
- const version = "3.0.0";
10
+ const version = "3.0.1";
11
11
 
12
12
  function createContext(options, nuxt) {
13
13
  const { resolve } = createResolver(import.meta.url);
@@ -721,16 +721,7 @@ export {}
721
721
  filename: "cms/http-statuses.ts",
722
722
  write: true,
723
723
  getContents: () => {
724
- return `export type HttpStatusKey
725
- = (${Object.keys(options.httpStatuses).map((key) => `'${key}'`).join(" | ")})
726
- & string
727
-
728
- export interface HttpStatus {
729
- code: number
730
- message: string
731
- }
732
-
733
- export const httpStatuses: Record<HttpStatusKey, HttpStatus> = ${JSON.stringify(options.httpStatuses, null, 2)}
724
+ return `export const httpStatuses = ${JSON.stringify(options.httpStatuses, null, 2)}
734
725
  `;
735
726
  }
736
727
  });
@@ -1,15 +1,24 @@
1
- import type { HttpStatusKey } from '#cms/http-statuses';
2
1
  import type { EventHandler, EventHandlerRequest, EventHandlerResponse, H3Event } from 'h3';
3
2
  import type { CachedEventHandlerOptions } from 'nitropack/types';
4
- import type { HttpErrorOptions } from '../errors';
3
+ import { httpStatuses } from '#cms/http-statuses';
5
4
  import { H3Error } from 'h3';
6
- import { HttpError } from '../errors';
5
+ export type HttpStatusKey = keyof typeof httpStatuses;
6
+ export interface HttpStatus {
7
+ code: number;
8
+ message: string;
9
+ }
7
10
  type HttpStatusesCodesMap = Record<string, HttpStatusKey>;
11
+ export type HttpErrorOptions = Partial<Pick<H3Error, 'cause' | 'fatal' | 'data'>>;
8
12
  interface DefineHttpHandlerOptions<Response extends EventHandlerResponse> {
9
13
  httpCodesMap?: HttpStatusesCodesMap;
10
14
  cache?: CachedEventHandlerOptions<Response>;
11
15
  access?: 'admin' | 'employee' | 'user';
12
16
  }
17
+ export declare class HttpError extends Error {
18
+ readonly httpStatusKey: HttpStatusKey;
19
+ readonly options?: HttpErrorOptions | undefined;
20
+ constructor(httpStatusKey: HttpStatusKey, options?: HttpErrorOptions | undefined);
21
+ }
13
22
  /**
14
23
  * Разрешает и форматирует ошибку для HTTP ответов сервера.
15
24
  * Логирует ошибку и возвращает отформатированную H3Error с кодом статуса и сообщением.
@@ -6,13 +6,19 @@ import { cachedEventHandler } from "nitropack/runtime";
6
6
  import { camelCase } from "scule";
7
7
  import { z } from "zod";
8
8
  import { logger } from "../../utils/logger.js";
9
- import { HttpError } from "../errors/index.js";
9
+ export class HttpError extends Error {
10
+ constructor(httpStatusKey, options) {
11
+ super("Http Error");
12
+ this.httpStatusKey = httpStatusKey;
13
+ this.options = options;
14
+ }
15
+ }
10
16
  const defaultHttpCodes = {
11
17
  default: "internalServerError",
12
18
  zod: "badRequest",
13
19
  db: "internalServerError"
14
20
  };
15
- const excludedLoggedStatuses = ["unauthorized"];
21
+ const excludedLoggedStatuses = [];
16
22
  function extractHttpStatusKey(error, httpCodesMap = {}) {
17
23
  const codesMap = defu(httpCodesMap, defaultHttpCodes);
18
24
  if (error instanceof HttpError) {
@@ -1,7 +1,8 @@
1
- import { TimeoutError } from '../errors/TimeoutError';
2
1
  interface TryWithTimeoutOptions {
3
2
  timeout?: number;
4
3
  timeoutMessage?: string;
5
4
  }
5
+ export declare class TimeoutError extends Error {
6
+ }
6
7
  export declare function tryWithTimeout<T>(promise: Promise<T>, options: TryWithTimeoutOptions): Promise<T | TimeoutError>;
7
8
  export {};
@@ -1,4 +1,5 @@
1
- import { TimeoutError } from "../errors/TimeoutError.js";
1
+ export class TimeoutError extends Error {
2
+ }
2
3
  export function tryWithTimeout(promise, options) {
3
4
  return Promise.race([
4
5
  promise,
package/package.json CHANGED
@@ -1,7 +1,7 @@
1
1
  {
2
2
  "name": "@hywax/cms",
3
3
  "type": "module",
4
- "version": "3.0.0",
4
+ "version": "3.0.1",
5
5
  "description": "Hywax CMS. ⚠️ This package is intended for internal use only.",
6
6
  "imports": {
7
7
  "#build/cms/*": "./.nuxt/cms/*.ts",
@@ -1,8 +0,0 @@
1
- import type { HttpStatusKey } from '#cms/http-statuses';
2
- import type { H3Error } from 'h3';
3
- export type HttpErrorOptions = Partial<Pick<H3Error, 'cause' | 'fatal' | 'data'>>;
4
- export declare class HttpError extends Error {
5
- readonly httpStatusKey: HttpStatusKey;
6
- readonly options?: HttpErrorOptions | undefined;
7
- constructor(httpStatusKey: HttpStatusKey, options?: HttpErrorOptions | undefined);
8
- }
@@ -1,7 +0,0 @@
1
- export class HttpError extends Error {
2
- constructor(httpStatusKey, options) {
3
- super("Http Error");
4
- this.httpStatusKey = httpStatusKey;
5
- this.options = options;
6
- }
7
- }
@@ -1,2 +0,0 @@
1
- export declare class TimeoutError extends Error {
2
- }
@@ -1,2 +0,0 @@
1
- export class TimeoutError extends Error {
2
- }
@@ -1,2 +0,0 @@
1
- export * from './HttpError';
2
- export * from './TimeoutError';
@@ -1,2 +0,0 @@
1
- export * from "./HttpError.js";
2
- export * from "./TimeoutError.js";