apeframework 0.0.0-dev.3 → 0.0.0-dev.5

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.
Files changed (225) hide show
  1. package/README.md +0 -14
  2. package/api/Api.d.ts +28 -0
  3. package/api/Api.js +72 -0
  4. package/api/Api.ts +104 -0
  5. package/api/Endpoint.d.ts +12 -0
  6. package/api/Endpoint.ts +16 -0
  7. package/api/ErrorHandler.d.ts +3 -0
  8. package/api/ErrorHandler.ts +11 -0
  9. package/api/Handler.d.ts +3 -0
  10. package/api/Handler.ts +10 -0
  11. package/api/Method.d.ts +8 -0
  12. package/api/Method.js +11 -0
  13. package/api/Method.ts +11 -0
  14. package/api/Schema.d.ts +9 -0
  15. package/api/Schema.ts +13 -0
  16. package/cipher/Cipher.js +2 -2
  17. package/cipher/Cipher.ts +2 -2
  18. package/cipher/errors/{CipherDecryptError.d.ts → DecryptError.d.ts} +2 -2
  19. package/cipher/errors/{CipherDecryptError.js → DecryptError.js} +3 -3
  20. package/cipher/errors/{CipherDecryptError.ts → DecryptError.ts} +2 -2
  21. package/cipher/errors/SecretLengthError.d.ts +5 -0
  22. package/{jwt/errors/JwtSecretLengthError.js → cipher/errors/SecretLengthError.js} +3 -3
  23. package/{jwt/errors/JwtSecretLengthError.ts → cipher/errors/SecretLengthError.ts} +2 -2
  24. package/cipher/validateSecretLength.js +2 -2
  25. package/cipher/validateSecretLength.ts +2 -2
  26. package/cli/utils/print.d.ts +2 -0
  27. package/cli/utils/{write.js → print.js} +3 -3
  28. package/cli/utils/print.ts +7 -0
  29. package/cli/utils/printLn.d.ts +2 -0
  30. package/cli/utils/{writeLn.js → printLn.js} +3 -3
  31. package/cli/utils/{writeLn.ts → printLn.ts} +2 -2
  32. package/{env/errors/EnvFileReadError.d.ts → config/errors/FileReadError.d.ts} +2 -2
  33. package/{tls/errors/TlsFileReadError.js → config/errors/FileReadError.js} +3 -3
  34. package/{env/errors/EnvFileReadError.ts → config/errors/FileReadError.ts} +2 -2
  35. package/config/errors/PropertyNameError.d.ts +5 -0
  36. package/config/errors/{ConfigPropertyNameError.js → PropertyNameError.js} +3 -3
  37. package/config/errors/{ConfigPropertyNameError.ts → PropertyNameError.ts} +2 -2
  38. package/config/errors/PropertyParseError.d.ts +5 -0
  39. package/config/errors/PropertyParseError.js +10 -0
  40. package/config/errors/PropertyParseError.ts +11 -0
  41. package/config/parseProperty.js +2 -2
  42. package/config/parseProperty.ts +2 -2
  43. package/config/readFile.js +4 -4
  44. package/config/readFile.ts +4 -4
  45. package/config/validatePropertyName.js +2 -2
  46. package/config/validatePropertyName.ts +2 -2
  47. package/{tls/errors/TlsFileReadError.d.ts → env/errors/FileReadError.d.ts} +2 -2
  48. package/env/errors/{EnvFileReadError.js → FileReadError.js} +3 -3
  49. package/{tls/errors/TlsFileReadError.ts → env/errors/FileReadError.ts} +2 -2
  50. package/env/readFile.js +3 -3
  51. package/env/readFile.ts +3 -3
  52. package/jwt/Jwt.d.ts +0 -6
  53. package/jwt/Jwt.js +8 -34
  54. package/jwt/Jwt.ts +8 -51
  55. package/jwt/Payload.d.ts +7 -3
  56. package/jwt/Payload.ts +7 -3
  57. package/jwt/errors/SecretLengthError.d.ts +5 -0
  58. package/{cipher/errors/CipherSecretLengthError.js → jwt/errors/SecretLengthError.js} +3 -3
  59. package/{cipher/errors/CipherSecretLengthError.ts → jwt/errors/SecretLengthError.ts} +2 -2
  60. package/jwt/validateSecretLength.js +2 -2
  61. package/jwt/validateSecretLength.ts +2 -2
  62. package/logger/Level.d.ts +7 -6
  63. package/logger/Level.js +7 -6
  64. package/logger/Level.ts +7 -6
  65. package/logger/Logger.d.ts +9 -9
  66. package/logger/Logger.js +4 -0
  67. package/logger/Logger.ts +15 -9
  68. package/logger/Severity.d.ts +6 -7
  69. package/logger/Severity.js +6 -7
  70. package/logger/Severity.ts +6 -7
  71. package/logger/adapters/file/FileLogger.d.ts +5 -5
  72. package/logger/adapters/file/FileLogger.js +17 -17
  73. package/logger/adapters/file/FileLogger.ts +19 -19
  74. package/logger/adapters/noop/NoopLogger.d.ts +2 -2
  75. package/logger/adapters/noop/NoopLogger.js +2 -1
  76. package/logger/adapters/noop/NoopLogger.ts +2 -2
  77. package/logger/adapters/stdio/StdioLogger.d.ts +5 -5
  78. package/logger/adapters/stdio/StdioLogger.js +19 -17
  79. package/logger/adapters/stdio/StdioLogger.ts +21 -19
  80. package/mailer/Event.d.ts +4 -4
  81. package/mailer/Event.ts +4 -4
  82. package/mailer/{EventLocation.d.ts → Location.d.ts} +2 -2
  83. package/mailer/Location.js +2 -0
  84. package/mailer/{EventLocation.ts → Location.ts} +2 -2
  85. package/mailer/Mailer.d.ts +5 -4
  86. package/mailer/Mailer.js +48 -0
  87. package/mailer/Mailer.ts +63 -4
  88. package/mailer/Method.d.ts +5 -0
  89. package/mailer/Method.js +8 -0
  90. package/mailer/{EventMethod.ts → Method.ts} +2 -2
  91. package/mailer/adapters/noop/NoopMailer.d.ts +3 -3
  92. package/mailer/adapters/noop/NoopMailer.js +3 -2
  93. package/mailer/adapters/noop/NoopMailer.ts +3 -3
  94. package/mailer/adapters/smtp/SmtpMailer.d.ts +3 -3
  95. package/mailer/adapters/smtp/SmtpMailer.js +4 -2
  96. package/mailer/adapters/smtp/SmtpMailer.ts +5 -3
  97. package/mailer/errors/AddressEmailError.d.ts +5 -0
  98. package/mailer/errors/{MailerAddressEmailError.js → AddressEmailError.js} +3 -3
  99. package/mailer/errors/{MailerAddressEmailError.ts → AddressEmailError.ts} +2 -2
  100. package/mailer/errors/EventAttachmentUrlError.d.ts +5 -0
  101. package/mailer/errors/{MailerEventAttachmentUrlError.js → EventAttachmentUrlError.js} +3 -3
  102. package/mailer/errors/{MailerEventAttachmentUrlError.ts → EventAttachmentUrlError.ts} +2 -2
  103. package/mailer/errors/{MailerEventGeolocationError.d.ts → EventGeolocationError.d.ts} +2 -2
  104. package/mailer/errors/{MailerEventGeolocationError.js → EventGeolocationError.js} +3 -3
  105. package/mailer/errors/{MailerEventGeolocationError.ts → EventGeolocationError.ts} +2 -2
  106. package/mailer/errors/EventUrlError.d.ts +5 -0
  107. package/mailer/errors/{MailerEventUrlError.js → EventUrlError.js} +3 -3
  108. package/mailer/errors/{MailerEventUrlError.ts → EventUrlError.ts} +2 -2
  109. package/mailer/errors/{MailerListUrlError.d.ts → ListUrlError.d.ts} +2 -2
  110. package/mailer/errors/{MailerListUrlError.js → ListUrlError.js} +3 -3
  111. package/mailer/errors/{MailerListUrlError.ts → ListUrlError.ts} +2 -2
  112. package/mailer/validateAddressEmail.js +2 -2
  113. package/mailer/validateAddressEmail.ts +2 -2
  114. package/mailer/validateEventAttachmentUrl.js +2 -2
  115. package/mailer/validateEventAttachmentUrl.ts +2 -2
  116. package/mailer/validateEventGeolocation.js +2 -2
  117. package/mailer/validateEventGeolocation.ts +2 -2
  118. package/mailer/validateEventUrl.js +2 -2
  119. package/mailer/validateEventUrl.ts +2 -2
  120. package/mailer/validateListUrl.js +2 -2
  121. package/mailer/validateListUrl.ts +2 -2
  122. package/package.json +1 -5
  123. package/parser/errors/{ParserInputError.d.ts → ParseError.d.ts} +2 -2
  124. package/parser/errors/ParseError.js +10 -0
  125. package/parser/errors/ParseError.ts +11 -0
  126. package/parser/factories/unit/createUnitParser.js +3 -3
  127. package/parser/factories/unit/createUnitParser.ts +3 -3
  128. package/parser/parseBoolean.js +2 -2
  129. package/parser/parseBoolean.ts +2 -2
  130. package/parser/parseInteger.js +3 -3
  131. package/parser/parseInteger.ts +3 -3
  132. package/parser/parseNumber.js +3 -3
  133. package/parser/parseNumber.ts +3 -3
  134. package/parser/parseString.js +2 -2
  135. package/parser/parseString.ts +2 -2
  136. package/pwd/errors/{PwdHashRoundsError.d.ts → HashRoundsError.d.ts} +2 -2
  137. package/pwd/errors/{PwdHashRoundsError.js → HashRoundsError.js} +3 -3
  138. package/pwd/errors/{PwdHashRoundsError.ts → HashRoundsError.ts} +2 -2
  139. package/pwd/validateHashRounds.js +2 -2
  140. package/pwd/validateHashRounds.ts +2 -2
  141. package/{config/errors/ConfigFileReadError.d.ts → tls/errors/FileReadError.d.ts} +2 -2
  142. package/{config/errors/ConfigFileReadError.js → tls/errors/FileReadError.js} +3 -3
  143. package/{config/errors/ConfigFileReadError.ts → tls/errors/FileReadError.ts} +2 -2
  144. package/tls/readFile.js +3 -3
  145. package/tls/readFile.ts +3 -3
  146. package/cipher/errors/CipherSecretLengthError.d.ts +0 -5
  147. package/cli/utils/write.d.ts +0 -2
  148. package/cli/utils/write.ts +0 -7
  149. package/cli/utils/writeLn.d.ts +0 -2
  150. package/config/errors/ConfigParseError.d.ts +0 -5
  151. package/config/errors/ConfigParseError.js +0 -10
  152. package/config/errors/ConfigParseError.ts +0 -11
  153. package/config/errors/ConfigPropertyNameError.d.ts +0 -5
  154. package/db/ColumnBuilder.d.ts +0 -13
  155. package/db/ColumnBuilder.js +0 -42
  156. package/db/ColumnBuilder.ts +0 -61
  157. package/db/Database.d.ts +0 -19
  158. package/db/Database.js +0 -49
  159. package/db/Database.ts +0 -74
  160. package/db/Driver.d.ts +0 -30
  161. package/db/Driver.ts +0 -33
  162. package/db/NullConstraint.d.ts +0 -2
  163. package/db/NullConstraint.ts +0 -5
  164. package/db/ReferentialAction.d.ts +0 -2
  165. package/db/ReferentialAction.ts +0 -5
  166. package/db/TableBuilder.d.ts +0 -49
  167. package/db/TableBuilder.js +0 -234
  168. package/db/TableBuilder.ts +0 -367
  169. package/db/adapters/mysql/createMysqlDatabase.d.ts +0 -12
  170. package/db/adapters/mysql/createMysqlDatabase.js +0 -32
  171. package/db/adapters/mysql/createMysqlDatabase.ts +0 -39
  172. package/db/adapters/mysql/driver.d.ts +0 -3
  173. package/db/adapters/mysql/driver.js +0 -43
  174. package/db/adapters/mysql/driver.ts +0 -45
  175. package/db/adapters/mysql/typeCast.d.ts +0 -2
  176. package/db/adapters/mysql/typeCast.js +0 -17
  177. package/db/adapters/mysql/typeCast.ts +0 -18
  178. package/db/adapters/postgres/driver.d.ts +0 -3
  179. package/db/adapters/postgres/driver.js +0 -43
  180. package/db/adapters/postgres/driver.ts +0 -45
  181. package/db/adapters/sqlite/driver.d.ts +0 -3
  182. package/db/adapters/sqlite/driver.js +0 -43
  183. package/db/adapters/sqlite/driver.ts +0 -45
  184. package/db/errors/DbColumnLengthError.d.ts +0 -5
  185. package/db/errors/DbColumnLengthError.js +0 -10
  186. package/db/errors/DbColumnLengthError.ts +0 -11
  187. package/db/errors/DbColumnMaxLengthError.d.ts +0 -5
  188. package/db/errors/DbColumnMaxLengthError.js +0 -10
  189. package/db/errors/DbColumnMaxLengthError.ts +0 -11
  190. package/db/errors/DbColumnPrecisionError.d.ts +0 -5
  191. package/db/errors/DbColumnPrecisionError.js +0 -10
  192. package/db/errors/DbColumnPrecisionError.ts +0 -11
  193. package/db/errors/DbColumnScaleError.d.ts +0 -5
  194. package/db/errors/DbColumnScaleError.js +0 -10
  195. package/db/errors/DbColumnScaleError.ts +0 -11
  196. package/db/getConstraintName.d.ts +0 -2
  197. package/db/getConstraintName.js +0 -15
  198. package/db/getConstraintName.ts +0 -18
  199. package/db/getReferentialActionSql.d.ts +0 -3
  200. package/db/getReferentialActionSql.js +0 -12
  201. package/db/getReferentialActionSql.ts +0 -17
  202. package/db/setNullConstraint.d.ts +0 -4
  203. package/db/setNullConstraint.js +0 -9
  204. package/db/setNullConstraint.ts +0 -15
  205. package/db/validateColumnLength.d.ts +0 -2
  206. package/db/validateColumnLength.js +0 -10
  207. package/db/validateColumnLength.ts +0 -11
  208. package/db/validateColumnMaxLength.d.ts +0 -2
  209. package/db/validateColumnMaxLength.js +0 -10
  210. package/db/validateColumnMaxLength.ts +0 -11
  211. package/db/validateColumnPrecision.d.ts +0 -2
  212. package/db/validateColumnPrecision.js +0 -14
  213. package/db/validateColumnPrecision.ts +0 -15
  214. package/jwt/errors/JwtSecretLengthError.d.ts +0 -5
  215. package/mailer/EventMethod.d.ts +0 -5
  216. package/mailer/EventMethod.js +0 -8
  217. package/mailer/errors/MailerAddressEmailError.d.ts +0 -5
  218. package/mailer/errors/MailerEventAttachmentUrlError.d.ts +0 -5
  219. package/mailer/errors/MailerEventUrlError.d.ts +0 -5
  220. package/parser/errors/ParserInputError.js +0 -10
  221. package/parser/errors/ParserInputError.ts +0 -11
  222. /package/{db/Driver.js → api/Endpoint.js} +0 -0
  223. /package/{db/NullConstraint.js → api/ErrorHandler.js} +0 -0
  224. /package/{db/ReferentialAction.js → api/Handler.js} +0 -0
  225. /package/{mailer/EventLocation.js → api/Schema.js} +0 -0
@@ -1,7 +1,7 @@
1
1
  "use strict";
2
2
  Object.defineProperty(exports, "__esModule", { value: true });
3
3
  exports.parseProperty = void 0;
4
- const ConfigParseError_1 = require("./errors/ConfigParseError");
4
+ const PropertyParseError_1 = require("./errors/PropertyParseError");
5
5
  const parseProperty = (name, parser, defaultValue, fileValue, envValue, argsValue) => {
6
6
  const sources = [
7
7
  {
@@ -31,7 +31,7 @@ const parseProperty = (name, parser, defaultValue, fileValue, envValue, argsValu
31
31
  return parser(source.value);
32
32
  }
33
33
  catch (error) {
34
- throw new ConfigParseError_1.ConfigParseError(name, source.name, error.message);
34
+ throw new PropertyParseError_1.PropertyParseError(name, source.name, error.message);
35
35
  }
36
36
  };
37
37
  exports.parseProperty = parseProperty;
@@ -1,4 +1,4 @@
1
- import { ConfigParseError } from './errors/ConfigParseError'
1
+ import { PropertyParseError } from './errors/PropertyParseError'
2
2
  import type { Parser } from '../parser/Parser'
3
3
 
4
4
  const parseProperty = <Type>(
@@ -38,7 +38,7 @@ const parseProperty = <Type>(
38
38
  try {
39
39
  return parser(source.value)
40
40
  } catch (error) {
41
- throw new ConfigParseError(name, source.name, (error as Error).message)
41
+ throw new PropertyParseError(name, source.name, (error as Error).message)
42
42
  }
43
43
  }
44
44
 
@@ -5,7 +5,7 @@ var __importDefault = (this && this.__importDefault) || function (mod) {
5
5
  Object.defineProperty(exports, "__esModule", { value: true });
6
6
  exports.readFile = void 0;
7
7
  const fs_extra_1 = __importDefault(require("fs-extra"));
8
- const ConfigFileReadError_1 = require("./errors/ConfigFileReadError");
8
+ const FileReadError_1 = require("./errors/FileReadError");
9
9
  const readFile = (path, required = false) => {
10
10
  let json = {};
11
11
  let fileExists;
@@ -16,15 +16,15 @@ const readFile = (path, required = false) => {
16
16
  }
17
17
  }
18
18
  catch (error) {
19
- throw new ConfigFileReadError_1.ConfigFileReadError(path, error.message);
19
+ throw new FileReadError_1.FileReadError(path, error.message);
20
20
  }
21
21
  if (required && !fileExists) {
22
- throw new ConfigFileReadError_1.ConfigFileReadError(path, 'missing file');
22
+ throw new FileReadError_1.FileReadError(path, 'missing file');
23
23
  }
24
24
  if (typeof json !== 'object'
25
25
  || Array.isArray(json)
26
26
  || json === null) {
27
- throw new ConfigFileReadError_1.ConfigFileReadError(path, 'invalid content');
27
+ throw new FileReadError_1.FileReadError(path, 'invalid content');
28
28
  }
29
29
  return json;
30
30
  };
@@ -1,5 +1,5 @@
1
1
  import fs from 'fs-extra'
2
- import { ConfigFileReadError } from './errors/ConfigFileReadError'
2
+ import { FileReadError } from './errors/FileReadError'
3
3
 
4
4
  const readFile = (path: string, required = false): Record<string, any> => {
5
5
  let json: any = {}
@@ -11,11 +11,11 @@ const readFile = (path: string, required = false): Record<string, any> => {
11
11
  json = fs.readJsonSync(path)
12
12
  }
13
13
  } catch (error) {
14
- throw new ConfigFileReadError(path, (error as Error).message)
14
+ throw new FileReadError(path, (error as Error).message)
15
15
  }
16
16
 
17
17
  if (required && !fileExists) {
18
- throw new ConfigFileReadError(path, 'missing file')
18
+ throw new FileReadError(path, 'missing file')
19
19
  }
20
20
 
21
21
  if (
@@ -23,7 +23,7 @@ const readFile = (path: string, required = false): Record<string, any> => {
23
23
  || Array.isArray(json)
24
24
  || json === null
25
25
  ) {
26
- throw new ConfigFileReadError(path, 'invalid content')
26
+ throw new FileReadError(path, 'invalid content')
27
27
  }
28
28
 
29
29
  return json as Record<string, any>
@@ -1,11 +1,11 @@
1
1
  "use strict";
2
2
  Object.defineProperty(exports, "__esModule", { value: true });
3
3
  exports.validatePropertyName = void 0;
4
- const ConfigPropertyNameError_1 = require("./errors/ConfigPropertyNameError");
4
+ const PropertyNameError_1 = require("./errors/PropertyNameError");
5
5
  const propertyNameRegex = /^[a-z](?:[0-9A-Za-z])*$/u;
6
6
  const validatePropertyName = (name) => {
7
7
  if (!propertyNameRegex.test(name)) {
8
- throw new ConfigPropertyNameError_1.ConfigPropertyNameError(name);
8
+ throw new PropertyNameError_1.PropertyNameError(name);
9
9
  }
10
10
  };
11
11
  exports.validatePropertyName = validatePropertyName;
@@ -1,10 +1,10 @@
1
- import { ConfigPropertyNameError } from './errors/ConfigPropertyNameError'
1
+ import { PropertyNameError } from './errors/PropertyNameError'
2
2
 
3
3
  const propertyNameRegex = /^[a-z](?:[0-9A-Za-z])*$/u
4
4
 
5
5
  const validatePropertyName = (name: string): void => {
6
6
  if (!propertyNameRegex.test(name)) {
7
- throw new ConfigPropertyNameError(name)
7
+ throw new PropertyNameError(name)
8
8
  }
9
9
  }
10
10
 
@@ -1,5 +1,5 @@
1
1
  import { BaseError } from '../../error/BaseError';
2
- declare class TlsFileReadError extends BaseError {
2
+ declare class FileReadError extends BaseError {
3
3
  constructor(path: string, message: string);
4
4
  }
5
- export { TlsFileReadError, };
5
+ export { FileReadError, };
@@ -1,10 +1,10 @@
1
1
  "use strict";
2
2
  Object.defineProperty(exports, "__esModule", { value: true });
3
- exports.EnvFileReadError = void 0;
3
+ exports.FileReadError = void 0;
4
4
  const BaseError_1 = require("../../error/BaseError");
5
- class EnvFileReadError extends BaseError_1.BaseError {
5
+ class FileReadError extends BaseError_1.BaseError {
6
6
  constructor(path, message) {
7
7
  super(`failed reading file "${path}": ${message}`);
8
8
  }
9
9
  }
10
- exports.EnvFileReadError = EnvFileReadError;
10
+ exports.FileReadError = FileReadError;
@@ -1,11 +1,11 @@
1
1
  import { BaseError } from '../../error/BaseError'
2
2
 
3
- class TlsFileReadError extends BaseError {
3
+ class FileReadError extends BaseError {
4
4
  public constructor(path: string, message: string) {
5
5
  super(`failed reading file "${path}": ${message}`)
6
6
  }
7
7
  }
8
8
 
9
9
  export {
10
- TlsFileReadError,
10
+ FileReadError,
11
11
  }
package/env/readFile.js CHANGED
@@ -6,7 +6,7 @@ Object.defineProperty(exports, "__esModule", { value: true });
6
6
  exports.readFile = void 0;
7
7
  const dotenv_1 = __importDefault(require("dotenv"));
8
8
  const fs_extra_1 = __importDefault(require("fs-extra"));
9
- const EnvFileReadError_1 = require("./errors/EnvFileReadError");
9
+ const FileReadError_1 = require("./errors/FileReadError");
10
10
  const readFile = (path, required = false) => {
11
11
  try {
12
12
  if (fs_extra_1.default.existsSync(path)) {
@@ -14,10 +14,10 @@ const readFile = (path, required = false) => {
14
14
  }
15
15
  }
16
16
  catch (error) {
17
- throw new EnvFileReadError_1.EnvFileReadError(path, error.message);
17
+ throw new FileReadError_1.FileReadError(path, error.message);
18
18
  }
19
19
  if (required) {
20
- throw new EnvFileReadError_1.EnvFileReadError(path, 'missing file');
20
+ throw new FileReadError_1.FileReadError(path, 'missing file');
21
21
  }
22
22
  return {};
23
23
  };
package/env/readFile.ts CHANGED
@@ -1,6 +1,6 @@
1
1
  import dotenv from 'dotenv'
2
2
  import fs from 'fs-extra'
3
- import { EnvFileReadError } from './errors/EnvFileReadError'
3
+ import { FileReadError } from './errors/FileReadError'
4
4
  import type { Env } from './Env'
5
5
 
6
6
  const readFile = (path: string, required = false): Env => {
@@ -9,11 +9,11 @@ const readFile = (path: string, required = false): Env => {
9
9
  return dotenv.parse(fs.readFileSync(path))
10
10
  }
11
11
  } catch (error) {
12
- throw new EnvFileReadError(path, (error as Error).message)
12
+ throw new FileReadError(path, (error as Error).message)
13
13
  }
14
14
 
15
15
  if (required) {
16
- throw new EnvFileReadError(path, 'missing file')
16
+ throw new FileReadError(path, 'missing file')
17
17
  }
18
18
 
19
19
  return {}
package/jwt/Jwt.d.ts CHANGED
@@ -3,15 +3,9 @@ import type { Payload } from './Payload';
3
3
  declare class Jwt {
4
4
  private readonly algorithm;
5
5
  private readonly secret;
6
- private readonly issuer;
7
- private readonly audience;
8
- private readonly expiration;
9
6
  constructor(params: {
10
7
  algorithm: Algorithm;
11
8
  secret: string;
12
- issuer: string;
13
- audience: string;
14
- expiration?: number;
15
9
  });
16
10
  createToken(payload: Payload): Promise<string>;
17
11
  verifyToken<Type extends Payload>(token: string, timestamp: number): Promise<Type | undefined>;
package/jwt/Jwt.js CHANGED
@@ -6,52 +6,26 @@ const validateSecretLength_1 = require("./validateSecretLength");
6
6
  class Jwt {
7
7
  algorithm;
8
8
  secret;
9
- issuer;
10
- audience;
11
- expiration;
12
9
  constructor(params) {
13
10
  (0, validateSecretLength_1.validateSecretLength)(params.algorithm, params.secret);
14
11
  this.algorithm = params.algorithm;
15
12
  this.secret = new TextEncoder().encode(params.secret);
16
- this.issuer = params.issuer;
17
- this.audience = params.audience;
18
- this.expiration = params.expiration;
19
13
  }
20
14
  async createToken(payload) {
21
- const jwt = new jose_1.SignJWT(Object.fromEntries(Object.entries(payload).filter(([key]) => {
22
- return !['subject', 'issuedAt', 'id'].includes(key);
23
- })));
24
- jwt
25
- .setProtectedHeader({ typ: 'JWT', alg: this.algorithm })
26
- .setIssuer(this.issuer)
27
- .setAudience(this.audience)
28
- .setSubject(payload.subject)
29
- .setIssuedAt(payload.issuedAt);
30
- if (this.expiration) {
31
- jwt.setExpirationTime(payload.issuedAt + this.expiration);
32
- }
33
- if (payload.id) {
34
- jwt.setJti(payload.id);
35
- }
36
- return jwt.sign(this.secret);
15
+ return new jose_1.SignJWT(payload)
16
+ .setProtectedHeader({
17
+ typ: 'JWT',
18
+ alg: this.algorithm,
19
+ })
20
+ .sign(this.secret);
37
21
  }
38
22
  async verifyToken(token, timestamp) {
39
23
  try {
40
- const { payload: jwt } = await (0, jose_1.jwtVerify)(token, this.secret, {
24
+ const { payload } = await (0, jose_1.jwtVerify)(token, this.secret, {
41
25
  typ: 'JWT',
42
- algorithms: [this.algorithm],
43
- audience: this.audience,
44
26
  currentDate: new Date(timestamp * 1000),
45
27
  });
46
- const payload = Object.fromEntries(Object.entries(jwt).filter(([key]) => {
47
- return !['iss', 'aud', 'sub', 'iat', 'exp', 'jti'].includes(key);
48
- }));
49
- return {
50
- subject: jwt.sub,
51
- issuedAt: jwt.iat,
52
- ...jwt.jti ? { id: jwt.jti } : {},
53
- ...payload,
54
- };
28
+ return payload;
55
29
  }
56
30
  catch (error) {
57
31
  return undefined;
package/jwt/Jwt.ts CHANGED
@@ -8,53 +8,23 @@ class Jwt {
8
8
 
9
9
  private readonly secret: Uint8Array
10
10
 
11
- private readonly issuer: string
12
-
13
- private readonly audience: string
14
-
15
- private readonly expiration: number | undefined
16
-
17
11
  public constructor(params: {
18
12
  algorithm: Algorithm,
19
13
  secret: string,
20
- issuer: string,
21
- audience: string,
22
- expiration?: number,
23
14
  }) {
24
15
  validateSecretLength(params.algorithm, params.secret)
25
16
 
26
17
  this.algorithm = params.algorithm
27
18
  this.secret = new TextEncoder().encode(params.secret)
28
- this.issuer = params.issuer
29
- this.audience = params.audience
30
- this.expiration = params.expiration
31
19
  }
32
20
 
33
21
  public async createToken(payload: Payload): Promise<string> {
34
- const jwt = new SignJWT(
35
- Object.fromEntries(
36
- Object.entries(payload).filter(([key]) => {
37
- return !['subject', 'issuedAt', 'id'].includes(key)
38
- }),
39
- ),
40
- )
41
-
42
- jwt
43
- .setProtectedHeader({ typ: 'JWT', alg: this.algorithm })
44
- .setIssuer(this.issuer)
45
- .setAudience(this.audience)
46
- .setSubject(payload.subject)
47
- .setIssuedAt(payload.issuedAt)
48
-
49
- if (this.expiration) {
50
- jwt.setExpirationTime(payload.issuedAt + this.expiration)
51
- }
52
-
53
- if (payload.id) {
54
- jwt.setJti(payload.id)
55
- }
56
-
57
- return jwt.sign(this.secret)
22
+ return new SignJWT(payload)
23
+ .setProtectedHeader({
24
+ typ: 'JWT',
25
+ alg: this.algorithm,
26
+ })
27
+ .sign(this.secret)
58
28
  }
59
29
 
60
30
  public async verifyToken<Type extends Payload>(
@@ -62,25 +32,12 @@ class Jwt {
62
32
  timestamp: number,
63
33
  ): Promise<Type | undefined> {
64
34
  try {
65
- const { payload: jwt } = await jwtVerify(token, this.secret, {
35
+ const { payload } = await jwtVerify(token, this.secret, {
66
36
  typ: 'JWT',
67
- algorithms: [this.algorithm],
68
- audience: this.audience,
69
37
  currentDate: new Date(timestamp * 1000),
70
38
  })
71
39
 
72
- const payload = Object.fromEntries(
73
- Object.entries(jwt).filter(([key]) => {
74
- return !['iss', 'aud', 'sub', 'iat', 'exp', 'jti'].includes(key)
75
- }),
76
- )
77
-
78
- return {
79
- subject: jwt.sub,
80
- issuedAt: jwt.iat,
81
- ...jwt.jti ? { id: jwt.jti } : {},
82
- ...payload,
83
- } as Type
40
+ return payload as Type
84
41
  } catch (error) {
85
42
  return undefined
86
43
  }
package/jwt/Payload.d.ts CHANGED
@@ -1,7 +1,11 @@
1
1
  interface Payload {
2
2
  [key: string]: unknown;
3
- subject: string;
4
- issuedAt: number;
5
- id?: string;
3
+ iss?: string;
4
+ aud?: string[];
5
+ sub?: string;
6
+ jti?: string;
7
+ iat?: number;
8
+ exp?: number;
9
+ nbf?: number;
6
10
  }
7
11
  export { type Payload, };
package/jwt/Payload.ts CHANGED
@@ -1,8 +1,12 @@
1
1
  interface Payload {
2
2
  [key: string]: unknown,
3
- subject: string,
4
- issuedAt: number,
5
- id?: string,
3
+ iss?: string,
4
+ aud?: string[],
5
+ sub?: string,
6
+ jti?: string,
7
+ iat?: number,
8
+ exp?: number,
9
+ nbf?: number,
6
10
  }
7
11
 
8
12
  export {
@@ -0,0 +1,5 @@
1
+ import { BaseError } from '../../error/BaseError';
2
+ declare class SecretLengthError extends BaseError {
3
+ constructor();
4
+ }
5
+ export { SecretLengthError, };
@@ -1,10 +1,10 @@
1
1
  "use strict";
2
2
  Object.defineProperty(exports, "__esModule", { value: true });
3
- exports.CipherSecretLengthError = void 0;
3
+ exports.SecretLengthError = void 0;
4
4
  const BaseError_1 = require("../../error/BaseError");
5
- class CipherSecretLengthError extends BaseError_1.BaseError {
5
+ class SecretLengthError extends BaseError_1.BaseError {
6
6
  constructor() {
7
7
  super('invalid secret length');
8
8
  }
9
9
  }
10
- exports.CipherSecretLengthError = CipherSecretLengthError;
10
+ exports.SecretLengthError = SecretLengthError;
@@ -1,11 +1,11 @@
1
1
  import { BaseError } from '../../error/BaseError'
2
2
 
3
- class CipherSecretLengthError extends BaseError {
3
+ class SecretLengthError extends BaseError {
4
4
  public constructor() {
5
5
  super('invalid secret length')
6
6
  }
7
7
  }
8
8
 
9
9
  export {
10
- CipherSecretLengthError,
10
+ SecretLengthError,
11
11
  }
@@ -2,7 +2,7 @@
2
2
  Object.defineProperty(exports, "__esModule", { value: true });
3
3
  exports.validateSecretLength = void 0;
4
4
  const Algorithm_1 = require("./Algorithm");
5
- const JwtSecretLengthError_1 = require("./errors/JwtSecretLengthError");
5
+ const SecretLengthError_1 = require("./errors/SecretLengthError");
6
6
  const minSecretLength = {
7
7
  [Algorithm_1.Algorithm.HS256]: 32,
8
8
  [Algorithm_1.Algorithm.HS384]: 48,
@@ -10,7 +10,7 @@ const minSecretLength = {
10
10
  };
11
11
  const validateSecretLength = (algorithm, secret) => {
12
12
  if (Buffer.from(secret).length < minSecretLength[algorithm]) {
13
- throw new JwtSecretLengthError_1.JwtSecretLengthError();
13
+ throw new SecretLengthError_1.SecretLengthError();
14
14
  }
15
15
  };
16
16
  exports.validateSecretLength = validateSecretLength;
@@ -1,5 +1,5 @@
1
1
  import { Algorithm } from './Algorithm'
2
- import { JwtSecretLengthError } from './errors/JwtSecretLengthError'
2
+ import { SecretLengthError } from './errors/SecretLengthError'
3
3
 
4
4
  const minSecretLength = {
5
5
  [Algorithm.HS256]: 32,
@@ -9,7 +9,7 @@ const minSecretLength = {
9
9
 
10
10
  const validateSecretLength = (algorithm: Algorithm, secret: string): void => {
11
11
  if (Buffer.from(secret).length < minSecretLength[algorithm]) {
12
- throw new JwtSecretLengthError()
12
+ throw new SecretLengthError()
13
13
  }
14
14
  }
15
15
 
package/logger/Level.d.ts CHANGED
@@ -1,9 +1,10 @@
1
1
  declare enum Level {
2
- TRACE = 10,
3
- DEBUG = 20,
4
- INFO = 30,
5
- WARN = 40,
6
- ERROR = 50,
7
- FATAL = 60
2
+ TRACE = "trace",
3
+ DEBUG = "debug",
4
+ INFO = "info",
5
+ WARN = "warn",
6
+ ERROR = "error",
7
+ FATAL = "fatal",
8
+ OFF = "off"
8
9
  }
9
10
  export { Level, };
package/logger/Level.js CHANGED
@@ -3,10 +3,11 @@ Object.defineProperty(exports, "__esModule", { value: true });
3
3
  exports.Level = void 0;
4
4
  var Level;
5
5
  (function (Level) {
6
- Level[Level["TRACE"] = 10] = "TRACE";
7
- Level[Level["DEBUG"] = 20] = "DEBUG";
8
- Level[Level["INFO"] = 30] = "INFO";
9
- Level[Level["WARN"] = 40] = "WARN";
10
- Level[Level["ERROR"] = 50] = "ERROR";
11
- Level[Level["FATAL"] = 60] = "FATAL";
6
+ Level["TRACE"] = "trace";
7
+ Level["DEBUG"] = "debug";
8
+ Level["INFO"] = "info";
9
+ Level["WARN"] = "warn";
10
+ Level["ERROR"] = "error";
11
+ Level["FATAL"] = "fatal";
12
+ Level["OFF"] = "off";
12
13
  })(Level || (exports.Level = Level = {}));
package/logger/Level.ts CHANGED
@@ -1,10 +1,11 @@
1
1
  enum Level {
2
- TRACE = 10,
3
- DEBUG = 20,
4
- INFO = 30,
5
- WARN = 40,
6
- ERROR = 50,
7
- FATAL = 60,
2
+ TRACE = 'trace',
3
+ DEBUG = 'debug',
4
+ INFO = 'info',
5
+ WARN = 'warn',
6
+ ERROR = 'error',
7
+ FATAL = 'fatal',
8
+ OFF = 'off',
8
9
  }
9
10
 
10
11
  export {
@@ -1,10 +1,10 @@
1
- interface Logger {
2
- trace: (message: string, data?: unknown) => void;
3
- debug: (message: string, data?: unknown) => void;
4
- info: (message: string, data?: unknown) => void;
5
- warn: (message: string, data?: unknown) => void;
6
- error: (message: string, data?: unknown) => void;
7
- fatal: (message: string, data?: unknown) => void;
8
- close: () => Promise<void>;
1
+ declare abstract class Logger {
2
+ abstract trace(message: string, data?: unknown): void;
3
+ abstract debug(message: string, data?: unknown): void;
4
+ abstract info(message: string, data?: unknown): void;
5
+ abstract warn(message: string, data?: unknown): void;
6
+ abstract error(message: string, data?: unknown): void;
7
+ abstract fatal(message: string, data?: unknown): void;
8
+ abstract close(): Promise<void>;
9
9
  }
10
- export { type Logger, };
10
+ export { Logger, };
package/logger/Logger.js CHANGED
@@ -1,2 +1,6 @@
1
1
  "use strict";
2
2
  Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.Logger = void 0;
4
+ class Logger {
5
+ }
6
+ exports.Logger = Logger;
package/logger/Logger.ts CHANGED
@@ -1,13 +1,19 @@
1
- interface Logger {
2
- trace: (message: string, data?: unknown) => void,
3
- debug: (message: string, data?: unknown) => void,
4
- info: (message: string, data?: unknown) => void,
5
- warn: (message: string, data?: unknown) => void,
6
- error: (message: string, data?: unknown) => void,
7
- fatal: (message: string, data?: unknown) => void,
8
- close: () => Promise<void>,
1
+ abstract class Logger {
2
+ public abstract trace(message: string, data?: unknown): void
3
+
4
+ public abstract debug(message: string, data?: unknown): void
5
+
6
+ public abstract info(message: string, data?: unknown): void
7
+
8
+ public abstract warn(message: string, data?: unknown): void
9
+
10
+ public abstract error(message: string, data?: unknown): void
11
+
12
+ public abstract fatal(message: string, data?: unknown): void
13
+
14
+ public abstract close(): Promise<void>
9
15
  }
10
16
 
11
17
  export {
12
- type Logger,
18
+ Logger,
13
19
  }
@@ -1,10 +1,9 @@
1
1
  declare enum Severity {
2
- TRACE = "trace",
3
- DEBUG = "debug",
4
- INFO = "info",
5
- WARN = "warn",
6
- ERROR = "error",
7
- FATAL = "fatal",
8
- OFF = "off"
2
+ TRACE = 10,
3
+ DEBUG = 20,
4
+ INFO = 30,
5
+ WARN = 40,
6
+ ERROR = 50,
7
+ FATAL = 60
9
8
  }
10
9
  export { Severity, };
@@ -3,11 +3,10 @@ Object.defineProperty(exports, "__esModule", { value: true });
3
3
  exports.Severity = void 0;
4
4
  var Severity;
5
5
  (function (Severity) {
6
- Severity["TRACE"] = "trace";
7
- Severity["DEBUG"] = "debug";
8
- Severity["INFO"] = "info";
9
- Severity["WARN"] = "warn";
10
- Severity["ERROR"] = "error";
11
- Severity["FATAL"] = "fatal";
12
- Severity["OFF"] = "off";
6
+ Severity[Severity["TRACE"] = 10] = "TRACE";
7
+ Severity[Severity["DEBUG"] = 20] = "DEBUG";
8
+ Severity[Severity["INFO"] = 30] = "INFO";
9
+ Severity[Severity["WARN"] = 40] = "WARN";
10
+ Severity[Severity["ERROR"] = 50] = "ERROR";
11
+ Severity[Severity["FATAL"] = 60] = "FATAL";
13
12
  })(Severity || (exports.Severity = Severity = {}));
@@ -1,11 +1,10 @@
1
1
  enum Severity {
2
- TRACE = 'trace',
3
- DEBUG = 'debug',
4
- INFO = 'info',
5
- WARN = 'warn',
6
- ERROR = 'error',
7
- FATAL = 'fatal',
8
- OFF = 'off',
2
+ TRACE = 10,
3
+ DEBUG = 20,
4
+ INFO = 30,
5
+ WARN = 40,
6
+ ERROR = 50,
7
+ FATAL = 60,
9
8
  }
10
9
 
11
10
  export {