apeframework 0.0.0-dev.20 → 0.0.0-dev.21
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/LICENSE +1 -1
- package/cipher/Algorithm.js +2 -4
- package/cipher/Cipher.js +9 -15
- package/cipher/errors/DecryptError.js +3 -6
- package/cipher/errors/SecretLengthError.js +3 -6
- package/cipher/validateSecretLength.js +7 -10
- package/cli/Args.js +1 -2
- package/cli/Command.js +1 -2
- package/cli/getArgs.js +3 -6
- package/cli/parseArgs.js +3 -9
- package/cli/utils/exit.js +1 -4
- package/cli/utils/formatList.js +3 -6
- package/cli/utils/formatTable.js +3 -6
- package/cli/utils/formatText.js +3 -6
- package/cli/utils/print.js +1 -4
- package/cli/utils/printLn.js +3 -6
- package/config/Config.js +1 -2
- package/config/Properties.js +1 -2
- package/config/errors/FileReadError.js +3 -6
- package/config/errors/PropertyNameError.js +3 -6
- package/config/errors/PropertyParseError.js +3 -6
- package/config/getConfig.js +8 -11
- package/config/getPropertyEnvVar.js +1 -4
- package/config/parseProperty.js +3 -6
- package/config/readFile.js +8 -14
- package/config/validatePropertyName.js +3 -6
- package/env/Env.js +1 -2
- package/env/errors/FileReadError.js +3 -6
- package/env/getEnv.js +3 -6
- package/env/readFile.js +8 -14
- package/error/BaseError.js +1 -4
- package/jwt/Algorithm.js +2 -4
- package/jwt/Jwt.js +6 -9
- package/jwt/Payload.js +1 -2
- package/jwt/errors/SecretLengthError.js +3 -6
- package/jwt/validateSecretLength.js +7 -10
- package/logger/Level.js +2 -4
- package/logger/Logger.js +1 -4
- package/logger/Severity.js +2 -4
- package/logger/adapters/file/FileLogger.js +11 -17
- package/logger/adapters/file/errors/FileInitError.js +3 -6
- package/logger/adapters/file/initFile.js +6 -12
- package/logger/adapters/noop/NoopLogger.js +3 -6
- package/logger/adapters/stdio/StdioLogger.js +11 -17
- package/mailer/Address.js +1 -2
- package/mailer/Attachment.js +1 -2
- package/mailer/Event.js +1 -2
- package/mailer/List.js +1 -2
- package/mailer/Location.js +1 -2
- package/mailer/Mail.js +1 -2
- package/mailer/Mailer.js +16 -19
- package/mailer/Method.js +2 -4
- package/mailer/adapters/noop/NoopMailer.js +5 -8
- package/mailer/adapters/smtp/SmtpMailer.js +19 -25
- package/mailer/adapters/smtp/getAddress.js +1 -4
- package/mailer/adapters/smtp/getAddresses.js +3 -6
- package/mailer/adapters/smtp/getAttachments.js +1 -4
- package/mailer/errors/AddressEmailError.js +3 -6
- package/mailer/errors/EventAttachmentUrlError.js +3 -6
- package/mailer/errors/EventGeolocationError.js +3 -6
- package/mailer/errors/EventUrlError.js +3 -6
- package/mailer/errors/ListUrlError.js +3 -6
- package/mailer/getIcalendar.js +3 -6
- package/mailer/validateAddressEmail.js +5 -8
- package/mailer/validateEventAttachmentUrl.js +5 -8
- package/mailer/validateEventGeolocation.js +5 -8
- package/mailer/validateEventUrl.js +5 -8
- package/mailer/validateListUrl.js +5 -8
- package/package.json +2 -4
- package/parser/Parser.js +1 -2
- package/parser/errors/ParseError.js +3 -6
- package/parser/factories/enum/createEnumParser.js +3 -6
- package/parser/factories/unit/Unit.js +1 -2
- package/parser/factories/unit/createUnitParser.js +8 -11
- package/parser/parseBoolean.js +3 -6
- package/parser/parseBytes.js +3 -6
- package/parser/parseInteger.js +6 -9
- package/parser/parseMilliseconds.js +3 -6
- package/parser/parseNumber.js +4 -7
- package/parser/parseString.js +3 -6
- package/pwd/Pwd.js +6 -12
- package/pwd/errors/HashRoundsError.js +3 -6
- package/pwd/validateHashRounds.js +3 -6
- package/server/ErrorHandler.js +1 -2
- package/server/Format.js +1 -2
- package/server/Handler.js +1 -2
- package/server/Method.js +2 -4
- package/server/OpenApiFormat.js +2 -4
- package/server/Route.js +1 -2
- package/server/Schema.js +1 -2
- package/server/Server.js +15 -21
- package/server/getAjv.js +5 -11
- package/tls/Tls.js +1 -2
- package/tls/errors/FileReadError.js +3 -6
- package/tls/getTls.js +5 -8
- package/tls/readFile.js +7 -13
- package/utils/getRandomHexString.js +3 -6
- package/utils/getTimestamp.js +1 -4
- package/utils/isValidEmail.js +1 -4
- package/utils/isValidGeolocation.js +1 -4
- package/utils/isValidHexString.js +1 -4
- package/utils/isValidIsoDate.js +1 -4
- package/utils/isValidJwtToken.js +1 -4
- package/utils/isValidUrl.js +1 -4
- package/utils/isValidUuid.js +1 -4
- package/utils/wait.js +1 -4
- package/cipher/Algorithm.ts +0 -9
- package/cipher/Cipher.ts +0 -46
- package/cipher/errors/DecryptError.ts +0 -11
- package/cipher/errors/SecretLengthError.ts +0 -11
- package/cipher/validateSecretLength.ts +0 -18
- package/cli/Args.ts +0 -8
- package/cli/Command.ts +0 -7
- package/cli/getArgs.ts +0 -10
- package/cli/parseArgs.ts +0 -34
- package/cli/utils/exit.ts +0 -7
- package/cli/utils/formatList.ts +0 -11
- package/cli/utils/formatTable.ts +0 -25
- package/cli/utils/formatText.ts +0 -9
- package/cli/utils/print.ts +0 -7
- package/cli/utils/printLn.ts +0 -9
- package/config/Config.ts +0 -5
- package/config/Properties.ts +0 -12
- package/config/errors/FileReadError.ts +0 -11
- package/config/errors/PropertyNameError.ts +0 -11
- package/config/errors/PropertyParseError.ts +0 -11
- package/config/getConfig.ts +0 -47
- package/config/getPropertyEnvVar.ts +0 -15
- package/config/parseProperty.ts +0 -47
- package/config/readFile.ts +0 -34
- package/config/validatePropertyName.ts +0 -13
- package/env/Env.ts +0 -5
- package/env/errors/FileReadError.ts +0 -11
- package/env/getEnv.ts +0 -24
- package/env/readFile.ts +0 -24
- package/error/BaseError.ts +0 -12
- package/jwt/Algorithm.ts +0 -9
- package/jwt/Jwt.ts +0 -49
- package/jwt/Payload.ts +0 -14
- package/jwt/errors/SecretLengthError.ts +0 -11
- package/jwt/validateSecretLength.ts +0 -18
- package/logger/Level.ts +0 -13
- package/logger/Logger.ts +0 -19
- package/logger/Severity.ts +0 -12
- package/logger/adapters/file/FileLogger.ts +0 -87
- package/logger/adapters/file/errors/FileInitError.ts +0 -11
- package/logger/adapters/file/initFile.ts +0 -18
- package/logger/adapters/noop/NoopLogger.ts +0 -21
- package/logger/adapters/stdio/StdioLogger.ts +0 -89
- package/mailer/Address.ts +0 -8
- package/mailer/Attachment.ts +0 -11
- package/mailer/Event.ts +0 -20
- package/mailer/List.ts +0 -10
- package/mailer/Location.ts +0 -12
- package/mailer/Mail.ts +0 -23
- package/mailer/Mailer.ts +0 -69
- package/mailer/Method.ts +0 -8
- package/mailer/adapters/noop/NoopMailer.ts +0 -15
- package/mailer/adapters/smtp/SmtpMailer.ts +0 -74
- package/mailer/adapters/smtp/getAddress.ts +0 -15
- package/mailer/adapters/smtp/getAddresses.ts +0 -17
- package/mailer/adapters/smtp/getAttachments.ts +0 -20
- package/mailer/errors/AddressEmailError.ts +0 -11
- package/mailer/errors/EventAttachmentUrlError.ts +0 -11
- package/mailer/errors/EventGeolocationError.ts +0 -11
- package/mailer/errors/EventUrlError.ts +0 -11
- package/mailer/errors/ListUrlError.ts +0 -11
- package/mailer/getIcalendar.ts +0 -39
- package/mailer/validateAddressEmail.ts +0 -12
- package/mailer/validateEventAttachmentUrl.ts +0 -12
- package/mailer/validateEventGeolocation.ts +0 -15
- package/mailer/validateEventUrl.ts +0 -12
- package/mailer/validateListUrl.ts +0 -12
- package/parser/Parser.ts +0 -5
- package/parser/errors/ParseError.ts +0 -11
- package/parser/factories/enum/createEnumParser.ts +0 -21
- package/parser/factories/unit/Unit.ts +0 -8
- package/parser/factories/unit/createUnitParser.ts +0 -50
- package/parser/parseBoolean.ts +0 -33
- package/parser/parseBytes.ts +0 -55
- package/parser/parseInteger.ts +0 -23
- package/parser/parseMilliseconds.ts +0 -31
- package/parser/parseNumber.ts +0 -22
- package/parser/parseString.ts +0 -16
- package/pwd/Pwd.ts +0 -31
- package/pwd/errors/HashRoundsError.ts +0 -11
- package/pwd/validateHashRounds.ts +0 -11
- package/server/ErrorHandler.ts +0 -11
- package/server/Format.ts +0 -15
- package/server/Handler.ts +0 -10
- package/server/Method.ts +0 -11
- package/server/OpenApiFormat.ts +0 -8
- package/server/Route.ts +0 -16
- package/server/Schema.ts +0 -13
- package/server/Server.ts +0 -134
- package/server/getAjv.ts +0 -26
- package/tls/Tls.ts +0 -10
- package/tls/errors/FileReadError.ts +0 -11
- package/tls/getTls.ts +0 -24
- package/tls/readFile.ts +0 -18
- package/utils/getRandomHexString.ts +0 -9
- package/utils/getTimestamp.ts +0 -7
- package/utils/isValidEmail.ts +0 -9
- package/utils/isValidGeolocation.ts +0 -10
- package/utils/isValidHexString.ts +0 -9
- package/utils/isValidIsoDate.ts +0 -9
- package/utils/isValidJwtToken.ts +0 -9
- package/utils/isValidUrl.ts +0 -21
- package/utils/isValidUuid.ts +0 -10
- package/utils/wait.ts +0 -9
|
@@ -1,13 +1,10 @@
|
|
|
1
|
-
|
|
2
|
-
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
-
exports.createEnumParser = void 0;
|
|
4
|
-
const ParseError_1 = require("../../errors/ParseError");
|
|
1
|
+
import { ParseError } from '../../errors/ParseError';
|
|
5
2
|
const createEnumParser = (params) => {
|
|
6
3
|
return (input) => {
|
|
7
4
|
if (!Object.values(params.enum).includes(input)) {
|
|
8
|
-
throw new
|
|
5
|
+
throw new ParseError(params.type);
|
|
9
6
|
}
|
|
10
7
|
return input;
|
|
11
8
|
};
|
|
12
9
|
};
|
|
13
|
-
|
|
10
|
+
export { createEnumParser, };
|
|
@@ -1,2 +1 @@
|
|
|
1
|
-
|
|
2
|
-
Object.defineProperty(exports, "__esModule", { value: true });
|
|
1
|
+
export {};
|
|
@@ -1,17 +1,14 @@
|
|
|
1
|
-
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
const ParseError_1 = require("../../errors/ParseError");
|
|
5
|
-
const parseNumber_1 = require("../../parseNumber");
|
|
6
|
-
const parseString_1 = require("../../parseString");
|
|
1
|
+
import { ParseError } from '../../errors/ParseError';
|
|
2
|
+
import { parseNumber } from '../../parseNumber';
|
|
3
|
+
import { parseString } from '../../parseString';
|
|
7
4
|
const createUnitParser = (params) => {
|
|
8
5
|
return (input) => {
|
|
9
6
|
let string;
|
|
10
7
|
try {
|
|
11
|
-
string =
|
|
8
|
+
string = parseString(input);
|
|
12
9
|
}
|
|
13
10
|
catch (error) {
|
|
14
|
-
throw new
|
|
11
|
+
throw new ParseError(params.type);
|
|
15
12
|
}
|
|
16
13
|
const units = [];
|
|
17
14
|
params.units.forEach((u) => {
|
|
@@ -25,12 +22,12 @@ const createUnitParser = (params) => {
|
|
|
25
22
|
});
|
|
26
23
|
let number;
|
|
27
24
|
try {
|
|
28
|
-
number =
|
|
25
|
+
number = parseNumber(string.substring(0, string.length - (unit?.symbol.length ?? 0)));
|
|
29
26
|
}
|
|
30
27
|
catch (error) {
|
|
31
|
-
throw new
|
|
28
|
+
throw new ParseError(params.type);
|
|
32
29
|
}
|
|
33
30
|
return number * (unit?.value ?? 1);
|
|
34
31
|
};
|
|
35
32
|
};
|
|
36
|
-
|
|
33
|
+
export { createUnitParser, };
|
package/parser/parseBoolean.js
CHANGED
|
@@ -1,7 +1,4 @@
|
|
|
1
|
-
|
|
2
|
-
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
-
exports.parseBoolean = void 0;
|
|
4
|
-
const ParseError_1 = require("./errors/ParseError");
|
|
1
|
+
import { ParseError } from './errors/ParseError';
|
|
5
2
|
const parseBoolean = (input) => {
|
|
6
3
|
if ([
|
|
7
4
|
true,
|
|
@@ -26,6 +23,6 @@ const parseBoolean = (input) => {
|
|
|
26
23
|
].includes(input)) {
|
|
27
24
|
return false;
|
|
28
25
|
}
|
|
29
|
-
throw new
|
|
26
|
+
throw new ParseError('boolean');
|
|
30
27
|
};
|
|
31
|
-
|
|
28
|
+
export { parseBoolean, };
|
package/parser/parseBytes.js
CHANGED
|
@@ -1,8 +1,5 @@
|
|
|
1
|
-
|
|
2
|
-
|
|
3
|
-
exports.parseBytes = void 0;
|
|
4
|
-
const createUnitParser_1 = require("./factories/unit/createUnitParser");
|
|
5
|
-
const parseBytes = (0, createUnitParser_1.createUnitParser)({
|
|
1
|
+
import { createUnitParser } from './factories/unit/createUnitParser';
|
|
2
|
+
const parseBytes = createUnitParser({
|
|
6
3
|
type: 'bytes',
|
|
7
4
|
units: [
|
|
8
5
|
{
|
|
@@ -51,4 +48,4 @@ const parseBytes = (0, createUnitParser_1.createUnitParser)({
|
|
|
51
48
|
},
|
|
52
49
|
],
|
|
53
50
|
});
|
|
54
|
-
|
|
51
|
+
export { parseBytes, };
|
package/parser/parseInteger.js
CHANGED
|
@@ -1,19 +1,16 @@
|
|
|
1
|
-
|
|
2
|
-
|
|
3
|
-
exports.parseInteger = void 0;
|
|
4
|
-
const ParseError_1 = require("./errors/ParseError");
|
|
5
|
-
const parseNumber_1 = require("./parseNumber");
|
|
1
|
+
import { ParseError } from './errors/ParseError';
|
|
2
|
+
import { parseNumber } from './parseNumber';
|
|
6
3
|
const parseInteger = (input) => {
|
|
7
4
|
let number;
|
|
8
5
|
try {
|
|
9
|
-
number =
|
|
6
|
+
number = parseNumber(input);
|
|
10
7
|
}
|
|
11
8
|
catch (error) {
|
|
12
|
-
throw new
|
|
9
|
+
throw new ParseError('integer');
|
|
13
10
|
}
|
|
14
11
|
if (!Number.isSafeInteger(number)) {
|
|
15
|
-
throw new
|
|
12
|
+
throw new ParseError('integer');
|
|
16
13
|
}
|
|
17
14
|
return number;
|
|
18
15
|
};
|
|
19
|
-
|
|
16
|
+
export { parseInteger, };
|
|
@@ -1,8 +1,5 @@
|
|
|
1
|
-
|
|
2
|
-
|
|
3
|
-
exports.parseMilliseconds = void 0;
|
|
4
|
-
const createUnitParser_1 = require("./factories/unit/createUnitParser");
|
|
5
|
-
const parseMilliseconds = (0, createUnitParser_1.createUnitParser)({
|
|
1
|
+
import { createUnitParser } from './factories/unit/createUnitParser';
|
|
2
|
+
const parseMilliseconds = createUnitParser({
|
|
6
3
|
type: 'milliseconds',
|
|
7
4
|
units: [
|
|
8
5
|
{
|
|
@@ -27,4 +24,4 @@ const parseMilliseconds = (0, createUnitParser_1.createUnitParser)({
|
|
|
27
24
|
},
|
|
28
25
|
],
|
|
29
26
|
});
|
|
30
|
-
|
|
27
|
+
export { parseMilliseconds, };
|
package/parser/parseNumber.js
CHANGED
|
@@ -1,18 +1,15 @@
|
|
|
1
|
-
|
|
2
|
-
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
-
exports.parseNumber = void 0;
|
|
4
|
-
const ParseError_1 = require("./errors/ParseError");
|
|
1
|
+
import { ParseError } from './errors/ParseError';
|
|
5
2
|
const parseNumber = (input) => {
|
|
6
3
|
if ([undefined, null].includes(input)) {
|
|
7
4
|
return 0;
|
|
8
5
|
}
|
|
9
6
|
else if (['object', 'function', 'symbol'].includes(typeof input)) {
|
|
10
|
-
throw new
|
|
7
|
+
throw new ParseError('number');
|
|
11
8
|
}
|
|
12
9
|
const number = Number(input);
|
|
13
10
|
if (!Number.isFinite(number)) {
|
|
14
|
-
throw new
|
|
11
|
+
throw new ParseError('number');
|
|
15
12
|
}
|
|
16
13
|
return number;
|
|
17
14
|
};
|
|
18
|
-
|
|
15
|
+
export { parseNumber, };
|
package/parser/parseString.js
CHANGED
|
@@ -1,14 +1,11 @@
|
|
|
1
|
-
|
|
2
|
-
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
-
exports.parseString = void 0;
|
|
4
|
-
const ParseError_1 = require("./errors/ParseError");
|
|
1
|
+
import { ParseError } from './errors/ParseError';
|
|
5
2
|
const parseString = (input) => {
|
|
6
3
|
if ([undefined, null].includes(input)) {
|
|
7
4
|
return '';
|
|
8
5
|
}
|
|
9
6
|
else if (['object', 'function', 'symbol'].includes(typeof input)) {
|
|
10
|
-
throw new
|
|
7
|
+
throw new ParseError('string');
|
|
11
8
|
}
|
|
12
9
|
return String(input);
|
|
13
10
|
};
|
|
14
|
-
|
|
11
|
+
export { parseString, };
|
package/pwd/Pwd.js
CHANGED
|
@@ -1,22 +1,16 @@
|
|
|
1
|
-
|
|
2
|
-
|
|
3
|
-
return (mod && mod.__esModule) ? mod : { "default": mod };
|
|
4
|
-
};
|
|
5
|
-
Object.defineProperty(exports, "__esModule", { value: true });
|
|
6
|
-
exports.Pwd = void 0;
|
|
7
|
-
const bcryptjs_1 = __importDefault(require("bcryptjs"));
|
|
8
|
-
const validateHashRounds_1 = require("./validateHashRounds");
|
|
1
|
+
import bcrypt from 'bcryptjs';
|
|
2
|
+
import { validateHashRounds } from './validateHashRounds';
|
|
9
3
|
class Pwd {
|
|
10
4
|
hashRounds;
|
|
11
5
|
constructor(params) {
|
|
12
|
-
|
|
6
|
+
validateHashRounds(params.hashRounds);
|
|
13
7
|
this.hashRounds = params.hashRounds;
|
|
14
8
|
}
|
|
15
9
|
async hashPassword(password) {
|
|
16
|
-
return
|
|
10
|
+
return bcrypt.hashSync(password, this.hashRounds);
|
|
17
11
|
}
|
|
18
12
|
async verifyPassword(password, hash) {
|
|
19
|
-
return
|
|
13
|
+
return bcrypt.compareSync(password, hash);
|
|
20
14
|
}
|
|
21
15
|
}
|
|
22
|
-
|
|
16
|
+
export { Pwd, };
|
|
@@ -1,10 +1,7 @@
|
|
|
1
|
-
|
|
2
|
-
|
|
3
|
-
exports.HashRoundsError = void 0;
|
|
4
|
-
const BaseError_1 = require("../../error/BaseError");
|
|
5
|
-
class HashRoundsError extends BaseError_1.BaseError {
|
|
1
|
+
import { BaseError } from '../../error/BaseError';
|
|
2
|
+
class HashRoundsError extends BaseError {
|
|
6
3
|
constructor(hashRounds) {
|
|
7
4
|
super(`invalid hash rounds "${hashRounds}"`);
|
|
8
5
|
}
|
|
9
6
|
}
|
|
10
|
-
|
|
7
|
+
export { HashRoundsError, };
|
|
@@ -1,10 +1,7 @@
|
|
|
1
|
-
|
|
2
|
-
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
-
exports.validateHashRounds = void 0;
|
|
4
|
-
const HashRoundsError_1 = require("./errors/HashRoundsError");
|
|
1
|
+
import { HashRoundsError } from './errors/HashRoundsError';
|
|
5
2
|
const validateHashRounds = (hashRounds) => {
|
|
6
3
|
if (hashRounds < 1) {
|
|
7
|
-
throw new
|
|
4
|
+
throw new HashRoundsError(hashRounds);
|
|
8
5
|
}
|
|
9
6
|
};
|
|
10
|
-
|
|
7
|
+
export { validateHashRounds, };
|
package/server/ErrorHandler.js
CHANGED
|
@@ -1,2 +1 @@
|
|
|
1
|
-
|
|
2
|
-
Object.defineProperty(exports, "__esModule", { value: true });
|
|
1
|
+
export {};
|
package/server/Format.js
CHANGED
|
@@ -1,2 +1 @@
|
|
|
1
|
-
|
|
2
|
-
Object.defineProperty(exports, "__esModule", { value: true });
|
|
1
|
+
export {};
|
package/server/Handler.js
CHANGED
|
@@ -1,2 +1 @@
|
|
|
1
|
-
|
|
2
|
-
Object.defineProperty(exports, "__esModule", { value: true });
|
|
1
|
+
export {};
|
package/server/Method.js
CHANGED
|
@@ -1,6 +1,3 @@
|
|
|
1
|
-
"use strict";
|
|
2
|
-
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
-
exports.Method = void 0;
|
|
4
1
|
var Method;
|
|
5
2
|
(function (Method) {
|
|
6
3
|
Method["DELETE"] = "DELETE";
|
|
@@ -8,4 +5,5 @@ var Method;
|
|
|
8
5
|
Method["PATCH"] = "PATCH";
|
|
9
6
|
Method["POST"] = "POST";
|
|
10
7
|
Method["PUT"] = "PUT";
|
|
11
|
-
})(Method || (
|
|
8
|
+
})(Method || (Method = {}));
|
|
9
|
+
export { Method, };
|
package/server/OpenApiFormat.js
CHANGED
|
@@ -1,8 +1,6 @@
|
|
|
1
|
-
"use strict";
|
|
2
|
-
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
-
exports.OpenApiFormat = void 0;
|
|
4
1
|
var OpenApiFormat;
|
|
5
2
|
(function (OpenApiFormat) {
|
|
6
3
|
OpenApiFormat["JSON"] = "json";
|
|
7
4
|
OpenApiFormat["YAML"] = "yaml";
|
|
8
|
-
})(OpenApiFormat || (
|
|
5
|
+
})(OpenApiFormat || (OpenApiFormat = {}));
|
|
6
|
+
export { OpenApiFormat, };
|
package/server/Route.js
CHANGED
|
@@ -1,2 +1 @@
|
|
|
1
|
-
|
|
2
|
-
Object.defineProperty(exports, "__esModule", { value: true });
|
|
1
|
+
export {};
|
package/server/Schema.js
CHANGED
|
@@ -1,2 +1 @@
|
|
|
1
|
-
|
|
2
|
-
Object.defineProperty(exports, "__esModule", { value: true });
|
|
1
|
+
export {};
|
package/server/Server.js
CHANGED
|
@@ -1,16 +1,10 @@
|
|
|
1
|
-
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
const cors_1 = __importDefault(require("@fastify/cors"));
|
|
9
|
-
const response_validation_1 = __importDefault(require("@fastify/response-validation"));
|
|
10
|
-
const swagger_1 = __importDefault(require("@fastify/swagger"));
|
|
11
|
-
const fastify_1 = __importDefault(require("fastify"));
|
|
12
|
-
const OpenApiFormat_1 = require("./OpenApiFormat");
|
|
13
|
-
const getAjv_1 = require("./getAjv");
|
|
1
|
+
import compress from '@fastify/compress';
|
|
2
|
+
import cors from '@fastify/cors';
|
|
3
|
+
import responseValidation from '@fastify/response-validation';
|
|
4
|
+
import swagger from '@fastify/swagger';
|
|
5
|
+
import fastify from 'fastify';
|
|
6
|
+
import { OpenApiFormat } from './OpenApiFormat';
|
|
7
|
+
import { getAjv } from './getAjv';
|
|
14
8
|
class Server {
|
|
15
9
|
server;
|
|
16
10
|
host;
|
|
@@ -18,11 +12,11 @@ class Server {
|
|
|
18
12
|
constructor(params) {
|
|
19
13
|
this.host = params.host;
|
|
20
14
|
this.port = params.port;
|
|
21
|
-
this.server = (
|
|
15
|
+
this.server = fastify();
|
|
22
16
|
this.server.setValidatorCompiler(({ schema }) => {
|
|
23
|
-
return
|
|
17
|
+
return getAjv(params.formats).compile(schema);
|
|
24
18
|
});
|
|
25
|
-
this.server.register(
|
|
19
|
+
this.server.register(swagger, {
|
|
26
20
|
openapi: {
|
|
27
21
|
openapi: '3.1.0',
|
|
28
22
|
info: {
|
|
@@ -32,16 +26,16 @@ class Server {
|
|
|
32
26
|
},
|
|
33
27
|
});
|
|
34
28
|
if (params.responseValidation) {
|
|
35
|
-
this.server.register(
|
|
29
|
+
this.server.register(responseValidation);
|
|
36
30
|
}
|
|
37
31
|
if (params.compression?.enabled) {
|
|
38
|
-
this.server.register(
|
|
32
|
+
this.server.register(compress, {
|
|
39
33
|
global: true,
|
|
40
34
|
threshold: params.compression.threshold ?? 1024,
|
|
41
35
|
});
|
|
42
36
|
}
|
|
43
37
|
if (params.cors?.enabled) {
|
|
44
|
-
this.server.register(
|
|
38
|
+
this.server.register(cors, {
|
|
45
39
|
origin: params.cors.origins,
|
|
46
40
|
});
|
|
47
41
|
}
|
|
@@ -85,8 +79,8 @@ class Server {
|
|
|
85
79
|
}
|
|
86
80
|
openapi(format) {
|
|
87
81
|
return this.server.swagger({
|
|
88
|
-
yaml: format ===
|
|
82
|
+
yaml: format === OpenApiFormat.YAML,
|
|
89
83
|
});
|
|
90
84
|
}
|
|
91
85
|
}
|
|
92
|
-
|
|
86
|
+
export { Server, };
|
package/server/getAjv.js
CHANGED
|
@@ -1,18 +1,12 @@
|
|
|
1
|
-
|
|
2
|
-
|
|
3
|
-
return (mod && mod.__esModule) ? mod : { "default": mod };
|
|
4
|
-
};
|
|
5
|
-
Object.defineProperty(exports, "__esModule", { value: true });
|
|
6
|
-
exports.getAjv = void 0;
|
|
7
|
-
const ajv_1 = require("ajv");
|
|
8
|
-
const fast_uri_1 = __importDefault(require("fast-uri"));
|
|
1
|
+
import { Ajv } from 'ajv';
|
|
2
|
+
import fastUri from 'fast-uri';
|
|
9
3
|
const getAjv = (formats) => {
|
|
10
|
-
const ajv = new
|
|
4
|
+
const ajv = new Ajv({
|
|
11
5
|
addUsedSchema: false,
|
|
12
6
|
allErrors: false,
|
|
13
7
|
coerceTypes: 'array',
|
|
14
8
|
removeAdditional: true,
|
|
15
|
-
uriResolver:
|
|
9
|
+
uriResolver: fastUri,
|
|
16
10
|
useDefaults: true,
|
|
17
11
|
});
|
|
18
12
|
if (formats) {
|
|
@@ -22,4 +16,4 @@ const getAjv = (formats) => {
|
|
|
22
16
|
}
|
|
23
17
|
return ajv;
|
|
24
18
|
};
|
|
25
|
-
|
|
19
|
+
export { getAjv, };
|
package/tls/Tls.js
CHANGED
|
@@ -1,2 +1 @@
|
|
|
1
|
-
|
|
2
|
-
Object.defineProperty(exports, "__esModule", { value: true });
|
|
1
|
+
export {};
|
|
@@ -1,10 +1,7 @@
|
|
|
1
|
-
|
|
2
|
-
|
|
3
|
-
exports.FileReadError = void 0;
|
|
4
|
-
const BaseError_1 = require("../../error/BaseError");
|
|
5
|
-
class FileReadError extends BaseError_1.BaseError {
|
|
1
|
+
import { BaseError } from '../../error/BaseError';
|
|
2
|
+
class FileReadError extends BaseError {
|
|
6
3
|
constructor(path, message) {
|
|
7
4
|
super(`failed reading file "${path}": ${message}`);
|
|
8
5
|
}
|
|
9
6
|
}
|
|
10
|
-
|
|
7
|
+
export { FileReadError, };
|
package/tls/getTls.js
CHANGED
|
@@ -1,17 +1,14 @@
|
|
|
1
|
-
|
|
2
|
-
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
-
exports.getTls = void 0;
|
|
4
|
-
const readFile_1 = require("./readFile");
|
|
1
|
+
import { readFile } from './readFile';
|
|
5
2
|
const getTls = (tls) => {
|
|
6
3
|
return tls
|
|
7
4
|
? {
|
|
8
|
-
...tls.key ? { key:
|
|
9
|
-
...tls.cert ? { cert:
|
|
10
|
-
...tls.ca ? { ca:
|
|
5
|
+
...tls.key ? { key: readFile(tls.key) } : {},
|
|
6
|
+
...tls.cert ? { cert: readFile(tls.cert) } : {},
|
|
7
|
+
...tls.ca ? { ca: readFile(tls.ca) } : {},
|
|
11
8
|
...tls.verify === undefined
|
|
12
9
|
? {}
|
|
13
10
|
: { rejectUnauthorized: tls.verify },
|
|
14
11
|
}
|
|
15
12
|
: undefined;
|
|
16
13
|
};
|
|
17
|
-
|
|
14
|
+
export { getTls, };
|
package/tls/readFile.js
CHANGED
|
@@ -1,20 +1,14 @@
|
|
|
1
|
-
|
|
2
|
-
|
|
3
|
-
return (mod && mod.__esModule) ? mod : { "default": mod };
|
|
4
|
-
};
|
|
5
|
-
Object.defineProperty(exports, "__esModule", { value: true });
|
|
6
|
-
exports.readFile = void 0;
|
|
7
|
-
const fs_extra_1 = __importDefault(require("fs-extra"));
|
|
8
|
-
const FileReadError_1 = require("./errors/FileReadError");
|
|
1
|
+
import fs from 'fs-extra';
|
|
2
|
+
import { FileReadError } from './errors/FileReadError';
|
|
9
3
|
const readFile = (path) => {
|
|
10
4
|
try {
|
|
11
|
-
if (
|
|
12
|
-
return
|
|
5
|
+
if (fs.existsSync(path)) {
|
|
6
|
+
return fs.readFileSync(path).toString();
|
|
13
7
|
}
|
|
14
8
|
}
|
|
15
9
|
catch (error) {
|
|
16
|
-
throw new
|
|
10
|
+
throw new FileReadError(path, error.message);
|
|
17
11
|
}
|
|
18
|
-
throw new
|
|
12
|
+
throw new FileReadError(path, 'missing file');
|
|
19
13
|
};
|
|
20
|
-
|
|
14
|
+
export { readFile, };
|
|
@@ -1,8 +1,5 @@
|
|
|
1
|
-
|
|
2
|
-
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
-
exports.getRandomHexString = void 0;
|
|
4
|
-
const crypto_1 = require("crypto");
|
|
1
|
+
import { randomBytes } from 'crypto';
|
|
5
2
|
const getRandomHexString = (length) => {
|
|
6
|
-
return
|
|
3
|
+
return randomBytes(length / 2 + 1).toString('hex').substring(0, length);
|
|
7
4
|
};
|
|
8
|
-
|
|
5
|
+
export { getRandomHexString, };
|
package/utils/getTimestamp.js
CHANGED
package/utils/isValidEmail.js
CHANGED
|
@@ -1,8 +1,5 @@
|
|
|
1
|
-
"use strict";
|
|
2
|
-
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
-
exports.isValidEmail = void 0;
|
|
4
1
|
const emailRegex = /^[^@\s]+@[^@\s]+\.[^@\s]+$/u;
|
|
5
2
|
const isValidEmail = (email) => {
|
|
6
3
|
return emailRegex.test(email);
|
|
7
4
|
};
|
|
8
|
-
|
|
5
|
+
export { isValidEmail, };
|
|
@@ -1,10 +1,7 @@
|
|
|
1
|
-
"use strict";
|
|
2
|
-
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
-
exports.isValidGeolocation = void 0;
|
|
4
1
|
const isValidGeolocation = (latitude, longitude) => {
|
|
5
2
|
return latitude >= -90
|
|
6
3
|
&& latitude <= 90
|
|
7
4
|
&& longitude >= -180
|
|
8
5
|
&& longitude <= 180;
|
|
9
6
|
};
|
|
10
|
-
|
|
7
|
+
export { isValidGeolocation, };
|
|
@@ -1,8 +1,5 @@
|
|
|
1
|
-
"use strict";
|
|
2
|
-
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
-
exports.isValidHexString = void 0;
|
|
4
1
|
const hexStringRegex = /^[0-9a-f]*$/u;
|
|
5
2
|
const isValidHexString = (string) => {
|
|
6
3
|
return hexStringRegex.test(string);
|
|
7
4
|
};
|
|
8
|
-
|
|
5
|
+
export { isValidHexString, };
|
package/utils/isValidIsoDate.js
CHANGED
|
@@ -1,8 +1,5 @@
|
|
|
1
|
-
"use strict";
|
|
2
|
-
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
-
exports.isValidIsoDate = void 0;
|
|
4
1
|
const isValidIsoDate = (date) => {
|
|
5
2
|
const d = new Date(date);
|
|
6
3
|
return !isNaN(d.getTime()) && date === d.toISOString();
|
|
7
4
|
};
|
|
8
|
-
|
|
5
|
+
export { isValidIsoDate, };
|
package/utils/isValidJwtToken.js
CHANGED
|
@@ -1,8 +1,5 @@
|
|
|
1
|
-
"use strict";
|
|
2
|
-
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
-
exports.isValidJwtToken = void 0;
|
|
4
1
|
const jwtTokenRegex = /^[0-9A-Za-z-_]+\.[0-9A-Za-z-_]+\.[0-9A-Za-z-_]+$/u;
|
|
5
2
|
const isValidJwtToken = (token) => {
|
|
6
3
|
return jwtTokenRegex.test(token);
|
|
7
4
|
};
|
|
8
|
-
|
|
5
|
+
export { isValidJwtToken, };
|
package/utils/isValidUrl.js
CHANGED
|
@@ -1,6 +1,3 @@
|
|
|
1
|
-
"use strict";
|
|
2
|
-
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
-
exports.isValidUrl = void 0;
|
|
4
1
|
const isValidUrl = (url) => {
|
|
5
2
|
try {
|
|
6
3
|
const parsed = new URL(url);
|
|
@@ -16,4 +13,4 @@ const isValidUrl = (url) => {
|
|
|
16
13
|
return false;
|
|
17
14
|
}
|
|
18
15
|
};
|
|
19
|
-
|
|
16
|
+
export { isValidUrl, };
|
package/utils/isValidUuid.js
CHANGED
|
@@ -1,8 +1,5 @@
|
|
|
1
|
-
"use strict";
|
|
2
|
-
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
-
exports.isValidUuid = void 0;
|
|
4
1
|
const uuidRegex = /^[0-9a-f]{8}-[0-9a-f]{4}-[0-9a-f]{4}-[0-9a-f]{4}-[0-9a-f]{12}$/u;
|
|
5
2
|
const isValidUuid = (uuid) => {
|
|
6
3
|
return uuidRegex.test(uuid);
|
|
7
4
|
};
|
|
8
|
-
|
|
5
|
+
export { isValidUuid, };
|
package/utils/wait.js
CHANGED
|
@@ -1,9 +1,6 @@
|
|
|
1
|
-
"use strict";
|
|
2
|
-
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
-
exports.wait = void 0;
|
|
4
1
|
const wait = async (milliseconds) => {
|
|
5
2
|
return new Promise((resolve) => {
|
|
6
3
|
setTimeout(resolve, milliseconds);
|
|
7
4
|
});
|
|
8
5
|
};
|
|
9
|
-
|
|
6
|
+
export { wait, };
|
package/cipher/Algorithm.ts
DELETED
package/cipher/Cipher.ts
DELETED
|
@@ -1,46 +0,0 @@
|
|
|
1
|
-
import crypto from 'crypto'
|
|
2
|
-
import { DecryptError } from './errors/DecryptError'
|
|
3
|
-
import { validateSecretLength } from './validateSecretLength'
|
|
4
|
-
import type { Algorithm } from './Algorithm'
|
|
5
|
-
|
|
6
|
-
class Cipher {
|
|
7
|
-
private readonly algorithm: Algorithm
|
|
8
|
-
|
|
9
|
-
private readonly secret: Buffer
|
|
10
|
-
|
|
11
|
-
public constructor(params: {
|
|
12
|
-
algorithm: Algorithm,
|
|
13
|
-
secret: string,
|
|
14
|
-
}) {
|
|
15
|
-
validateSecretLength(params.algorithm, params.secret)
|
|
16
|
-
|
|
17
|
-
this.algorithm = params.algorithm
|
|
18
|
-
this.secret = Buffer.from(params.secret, 'utf8')
|
|
19
|
-
}
|
|
20
|
-
|
|
21
|
-
public encrypt(string: string): string {
|
|
22
|
-
const iv = crypto.randomBytes(16)
|
|
23
|
-
const cipher = crypto.createCipheriv(this.algorithm, this.secret, iv)
|
|
24
|
-
|
|
25
|
-
return iv.toString('hex')
|
|
26
|
-
+ cipher.update(string, 'utf8', 'hex')
|
|
27
|
-
+ cipher.final('hex')
|
|
28
|
-
}
|
|
29
|
-
|
|
30
|
-
public decrypt(string: string): string {
|
|
31
|
-
const buffer = Buffer.from(string, 'hex')
|
|
32
|
-
const iv = buffer.subarray(0, 16)
|
|
33
|
-
const decipher = crypto.createDecipheriv(this.algorithm, this.secret, iv)
|
|
34
|
-
|
|
35
|
-
try {
|
|
36
|
-
return decipher.update(buffer.subarray(16), undefined, 'utf8')
|
|
37
|
-
+ decipher.final('utf8')
|
|
38
|
-
} catch (error) {
|
|
39
|
-
throw new DecryptError((error as Error).message)
|
|
40
|
-
}
|
|
41
|
-
}
|
|
42
|
-
}
|
|
43
|
-
|
|
44
|
-
export {
|
|
45
|
-
Cipher,
|
|
46
|
-
}
|