enonic-wizardry
Advanced tools
Comparing version 0.0.3 to 0.0.4
@@ -1,3 +0,7 @@ | ||
import { Response } from "enonic-fp/lib/common"; | ||
import { Error, ErrorKey, Response } from "enonic-fp/lib/common"; | ||
export declare const defaultStatusNumbers: { | ||
[key in ErrorKey]: number; | ||
}; | ||
export declare function status(status: number, body?: string | object): Response; | ||
export declare function errorResponse(i18nPrefix: string): (err: Error) => Response; | ||
export declare const ok: (body: any) => Response; | ||
@@ -4,0 +8,0 @@ export declare const created: (body: any) => Response; |
@@ -0,1 +1,13 @@ | ||
import { localize } from "enonic-fp/lib/i18n"; | ||
import { getOrElse } from 'fp-ts/lib/Option'; | ||
export var defaultStatusNumbers = { | ||
"BadRequestError": 400, | ||
"UnauthorizedError": 401, | ||
"ForbiddenError": 403, | ||
"NotFoundError": 404, | ||
"MethodNotAllowedError": 405, | ||
"InternalServerError": 500, | ||
"BadGatewayError": 502, | ||
"PublishError": 500, | ||
}; | ||
function contentType(body) { | ||
@@ -13,2 +25,11 @@ return (typeof body === "string") | ||
} | ||
export function errorResponse(i18nPrefix) { | ||
return function (err) { | ||
var i18nKey = i18nPrefix + "." + err.errorKey; | ||
return status(defaultStatusNumbers[err.errorKey], { | ||
message: getOrElse(function () { return i18nKey; })(localize({ key: i18nKey })), | ||
debug: String(err) | ||
}); | ||
}; | ||
} | ||
export var ok = function (body) { return status(200, body); }; | ||
@@ -15,0 +36,0 @@ export var created = function (body) { return status(201, body); }; |
@@ -1,3 +0,7 @@ | ||
import { Response } from "enonic-fp/lib/common"; | ||
import { Error, ErrorKey, Response } from "enonic-fp/lib/common"; | ||
export declare const defaultStatusNumbers: { | ||
[key in ErrorKey]: number; | ||
}; | ||
export declare function status(status: number, body?: string | object): Response; | ||
export declare function errorResponse(i18nPrefix: string): (err: Error) => Response; | ||
export declare const ok: (body: any) => Response; | ||
@@ -4,0 +8,0 @@ export declare const created: (body: any) => Response; |
"use strict"; | ||
Object.defineProperty(exports, "__esModule", { value: true }); | ||
var i18n_1 = require("enonic-fp/lib/i18n"); | ||
var Option_1 = require("fp-ts/lib/Option"); | ||
exports.defaultStatusNumbers = { | ||
"BadRequestError": 400, | ||
"UnauthorizedError": 401, | ||
"ForbiddenError": 403, | ||
"NotFoundError": 404, | ||
"MethodNotAllowedError": 405, | ||
"InternalServerError": 500, | ||
"BadGatewayError": 502, | ||
"PublishError": 500, | ||
}; | ||
function contentType(body) { | ||
@@ -16,2 +28,12 @@ return (typeof body === "string") | ||
exports.status = status; | ||
function errorResponse(i18nPrefix) { | ||
return function (err) { | ||
var i18nKey = i18nPrefix + "." + err.errorKey; | ||
return status(exports.defaultStatusNumbers[err.errorKey], { | ||
message: Option_1.getOrElse(function () { return i18nKey; })(i18n_1.localize({ key: i18nKey })), | ||
debug: String(err) | ||
}); | ||
}; | ||
} | ||
exports.errorResponse = errorResponse; | ||
exports.ok = function (body) { return status(200, body); }; | ||
@@ -18,0 +40,0 @@ exports.created = function (body) { return status(201, body); }; |
{ | ||
"name": "enonic-wizardry", | ||
"version": "0.0.3", | ||
"version": "0.0.4", | ||
"description": "Functional utility library for Enonic XP", | ||
@@ -27,3 +27,3 @@ "main": "lib/index.js", | ||
"dependencies": { | ||
"enonic-fp": "^0.0.8", | ||
"enonic-fp": "^0.0.9", | ||
"fp-ts": "^2.0.5" | ||
@@ -30,0 +30,0 @@ }, |
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
18582
391
+ Addedenonic-fp@0.0.9(transitive)
- Removedenonic-fp@0.0.8(transitive)
Updatedenonic-fp@^0.0.9