@technomoron/api-server-base 2.0.0-beta.21 → 2.0.0-beta.23

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 (177) hide show
  1. package/dist/cjs/common/types.cjs +10 -0
  2. package/dist/cjs/common/types.d.ts +137 -0
  3. package/dist/cjs/{api-module.cjs → server/src/api-module.cjs} +8 -0
  4. package/dist/{esm → cjs/server/src}/api-module.d.ts +15 -0
  5. package/dist/cjs/{api-server-base.cjs → server/src/api-server-base.cjs} +669 -627
  6. package/dist/{esm → cjs/server/src}/api-server-base.d.ts +105 -78
  7. package/dist/cjs/{auth-api/auth-module.js → server/src/auth-api/auth-module.cjs} +96 -76
  8. package/dist/cjs/{auth-api → server/src/auth-api}/auth-module.d.ts +1 -1
  9. package/dist/cjs/{auth-api/compat-auth-storage.js → server/src/auth-api/compat-auth-storage.cjs} +4 -4
  10. package/dist/cjs/{auth-api/mem-auth-store.js → server/src/auth-api/mem-auth-store.cjs} +7 -7
  11. package/dist/cjs/{auth-api/module.js → server/src/auth-api/module.cjs} +1 -1
  12. package/dist/cjs/server/src/auth-api/schemas.cjs +171 -0
  13. package/dist/cjs/server/src/auth-api/schemas.d.ts +21 -0
  14. package/dist/cjs/{auth-api/sql-auth-store.js → server/src/auth-api/sql-auth-store.cjs} +8 -8
  15. package/dist/cjs/{auth-api/user-id.js → server/src/auth-api/user-id.cjs} +12 -3
  16. package/dist/{esm → cjs/server/src}/auth-cookie-options.d.ts +5 -3
  17. package/dist/cjs/server/src/base/client-info.cjs +285 -0
  18. package/dist/cjs/server/src/base/client-info.d.ts +27 -0
  19. package/dist/cjs/server/src/base/error-utils.cjs +50 -0
  20. package/dist/cjs/server/src/base/error-utils.d.ts +16 -0
  21. package/dist/cjs/server/src/base/request-utils.cjs +27 -0
  22. package/dist/cjs/server/src/base/request-utils.d.ts +8 -0
  23. package/dist/cjs/{index.cjs → server/src/index.cjs} +24 -15
  24. package/dist/{esm → cjs/server/src}/index.d.ts +7 -0
  25. package/dist/cjs/server/src/limiter/auth-rate-limiter.cjs +35 -0
  26. package/dist/cjs/server/src/limiter/auth-rate-limiter.d.ts +12 -0
  27. package/dist/cjs/server/src/limiter/fixed-window.cjs +41 -0
  28. package/dist/cjs/server/src/limiter/fixed-window.d.ts +11 -0
  29. package/dist/cjs/{oauth/base.js → server/src/oauth/base.cjs} +1 -0
  30. package/dist/cjs/{oauth → server/src/oauth}/base.d.ts +8 -1
  31. package/dist/cjs/{oauth/memory.js → server/src/oauth/memory.cjs} +7 -4
  32. package/dist/{esm → cjs/server/src}/oauth/memory.d.ts +1 -1
  33. package/dist/cjs/{oauth/models.js → server/src/oauth/models.cjs} +2 -2
  34. package/dist/cjs/{oauth/sequelize.js → server/src/oauth/sequelize.cjs} +11 -7
  35. package/dist/{esm → cjs/server/src}/oauth/sequelize.d.ts +1 -1
  36. package/dist/cjs/{passkey/base.js → server/src/passkey/base.cjs} +1 -0
  37. package/dist/{esm → cjs/server/src}/passkey/base.d.ts +11 -0
  38. package/dist/cjs/{passkey/memory.js → server/src/passkey/memory.cjs} +2 -2
  39. package/dist/cjs/{passkey/models.js → server/src/passkey/models.cjs} +1 -1
  40. package/dist/cjs/{passkey/sequelize.js → server/src/passkey/sequelize.cjs} +3 -3
  41. package/dist/cjs/{passkey/service.js → server/src/passkey/service.cjs} +17 -3
  42. package/dist/{esm → cjs/server/src}/passkey/service.d.ts +1 -1
  43. package/dist/cjs/{sequelize-utils.js → server/src/sequelize-utils.cjs} +4 -5
  44. package/dist/cjs/{token/base.js → server/src/token/base.cjs} +4 -0
  45. package/dist/{esm → cjs/server/src}/token/base.d.ts +7 -0
  46. package/dist/cjs/{token/memory.js → server/src/token/memory.cjs} +15 -20
  47. package/dist/cjs/{token/sequelize.js → server/src/token/sequelize.cjs} +25 -11
  48. package/dist/cjs/server/src/upload/memory.cjs +92 -0
  49. package/dist/cjs/server/src/upload/memory.d.ts +17 -0
  50. package/dist/cjs/server/src/upload/tus-module.cjs +270 -0
  51. package/dist/cjs/server/src/upload/tus-module.d.ts +38 -0
  52. package/dist/cjs/server/src/upload/types.d.ts +8 -0
  53. package/dist/cjs/{user/base.js → server/src/user/base.cjs} +1 -0
  54. package/dist/cjs/{user → server/src/user}/base.d.ts +9 -0
  55. package/dist/cjs/{user/memory.js → server/src/user/memory.cjs} +29 -7
  56. package/dist/cjs/{user/sequelize.js → server/src/user/sequelize.cjs} +33 -8
  57. package/dist/cjs/server/src/user/types.cjs +2 -0
  58. package/dist/esm/common/types.d.ts +137 -0
  59. package/dist/esm/common/types.js +9 -0
  60. package/dist/{cjs → esm/server/src}/api-module.d.ts +15 -0
  61. package/dist/esm/{api-module.js → server/src/api-module.js} +8 -0
  62. package/dist/{cjs → esm/server/src}/api-server-base.d.ts +105 -78
  63. package/dist/esm/{api-server-base.js → server/src/api-server-base.js} +658 -616
  64. package/dist/esm/{auth-api → server/src/auth-api}/auth-module.d.ts +1 -1
  65. package/dist/esm/{auth-api → server/src/auth-api}/auth-module.js +92 -72
  66. package/dist/esm/{auth-api → server/src/auth-api}/compat-auth-storage.js +3 -3
  67. package/dist/esm/server/src/auth-api/schemas.d.ts +21 -0
  68. package/dist/esm/server/src/auth-api/schemas.js +168 -0
  69. package/dist/esm/{auth-api → server/src/auth-api}/user-id.js +12 -3
  70. package/dist/{cjs → esm/server/src}/auth-cookie-options.d.ts +5 -3
  71. package/dist/esm/server/src/base/client-info.d.ts +27 -0
  72. package/dist/esm/server/src/base/client-info.js +282 -0
  73. package/dist/esm/server/src/base/error-utils.d.ts +16 -0
  74. package/dist/esm/server/src/base/error-utils.js +44 -0
  75. package/dist/esm/server/src/base/request-utils.d.ts +8 -0
  76. package/dist/esm/server/src/base/request-utils.js +23 -0
  77. package/dist/{cjs → esm/server/src}/index.d.ts +7 -0
  78. package/dist/esm/{index.js → server/src/index.js} +4 -0
  79. package/dist/esm/server/src/limiter/auth-rate-limiter.d.ts +12 -0
  80. package/dist/esm/server/src/limiter/auth-rate-limiter.js +32 -0
  81. package/dist/esm/server/src/limiter/fixed-window.d.ts +11 -0
  82. package/dist/esm/server/src/limiter/fixed-window.js +37 -0
  83. package/dist/esm/{oauth → server/src/oauth}/base.d.ts +8 -1
  84. package/dist/esm/server/src/oauth/base.js +3 -0
  85. package/dist/{cjs → esm/server/src}/oauth/memory.d.ts +1 -1
  86. package/dist/esm/{oauth → server/src/oauth}/memory.js +5 -2
  87. package/dist/{cjs → esm/server/src}/oauth/sequelize.d.ts +1 -1
  88. package/dist/esm/{oauth → server/src/oauth}/sequelize.js +6 -2
  89. package/dist/{cjs → esm/server/src}/passkey/base.d.ts +11 -0
  90. package/dist/esm/server/src/passkey/base.js +3 -0
  91. package/dist/{cjs → esm/server/src}/passkey/service.d.ts +1 -1
  92. package/dist/esm/{passkey → server/src/passkey}/service.js +17 -3
  93. package/dist/esm/{sequelize-utils.js → server/src/sequelize-utils.js} +4 -5
  94. package/dist/{cjs → esm/server/src}/token/base.d.ts +7 -0
  95. package/dist/esm/{token → server/src/token}/base.js +4 -0
  96. package/dist/esm/{token → server/src/token}/memory.js +14 -19
  97. package/dist/esm/{token → server/src/token}/sequelize.js +22 -8
  98. package/dist/esm/server/src/upload/memory.d.ts +17 -0
  99. package/dist/esm/server/src/upload/memory.js +86 -0
  100. package/dist/esm/server/src/upload/tus-module.d.ts +38 -0
  101. package/dist/esm/server/src/upload/tus-module.js +266 -0
  102. package/dist/esm/server/src/upload/types.d.ts +8 -0
  103. package/dist/esm/{user → server/src/user}/base.d.ts +9 -0
  104. package/dist/esm/{user → server/src/user}/base.js +1 -0
  105. package/dist/esm/{user → server/src/user}/memory.js +27 -5
  106. package/dist/esm/{user → server/src/user}/sequelize.js +30 -5
  107. package/dist/esm/server/src/user/types.js +1 -0
  108. package/docs/swagger/openapi.json +411 -125
  109. package/package.json +129 -134
  110. package/README.txt +0 -213
  111. package/dist/esm/oauth/base.js +0 -2
  112. package/dist/esm/passkey/base.js +0 -2
  113. /package/dist/cjs/{auth-api → server/src/auth-api}/compat-auth-storage.d.ts +0 -0
  114. /package/dist/cjs/{auth-api → server/src/auth-api}/mem-auth-store.d.ts +0 -0
  115. /package/dist/cjs/{auth-api → server/src/auth-api}/module.d.ts +0 -0
  116. /package/dist/cjs/{auth-api → server/src/auth-api}/sql-auth-store.d.ts +0 -0
  117. /package/dist/cjs/{auth-api/storage.js → server/src/auth-api/storage.cjs} +0 -0
  118. /package/dist/cjs/{auth-api → server/src/auth-api}/storage.d.ts +0 -0
  119. /package/dist/cjs/{auth-api/types.js → server/src/auth-api/types.cjs} +0 -0
  120. /package/dist/cjs/{auth-api → server/src/auth-api}/types.d.ts +0 -0
  121. /package/dist/cjs/{auth-api → server/src/auth-api}/user-id.d.ts +0 -0
  122. /package/dist/cjs/{auth-cookie-options.js → server/src/auth-cookie-options.cjs} +0 -0
  123. /package/dist/cjs/{oauth → server/src/oauth}/models.d.ts +0 -0
  124. /package/dist/cjs/{oauth/types.js → server/src/oauth/types.cjs} +0 -0
  125. /package/dist/cjs/{oauth → server/src/oauth}/types.d.ts +0 -0
  126. /package/dist/cjs/{passkey/config.js → server/src/passkey/config.cjs} +0 -0
  127. /package/dist/cjs/{passkey → server/src/passkey}/config.d.ts +0 -0
  128. /package/dist/cjs/{passkey → server/src/passkey}/memory.d.ts +0 -0
  129. /package/dist/cjs/{passkey → server/src/passkey}/models.d.ts +0 -0
  130. /package/dist/cjs/{passkey → server/src/passkey}/sequelize.d.ts +0 -0
  131. /package/dist/cjs/{passkey/types.js → server/src/passkey/types.cjs} +0 -0
  132. /package/dist/cjs/{passkey → server/src/passkey}/types.d.ts +0 -0
  133. /package/dist/cjs/{sequelize-utils.d.ts → server/src/sequelize-utils.d.ts} +0 -0
  134. /package/dist/cjs/{token → server/src/token}/memory.d.ts +0 -0
  135. /package/dist/cjs/{token → server/src/token}/sequelize.d.ts +0 -0
  136. /package/dist/cjs/{token/types.js → server/src/token/types.cjs} +0 -0
  137. /package/dist/cjs/{token → server/src/token}/types.d.ts +0 -0
  138. /package/dist/cjs/{user/types.js → server/src/upload/types.cjs} +0 -0
  139. /package/dist/cjs/{user → server/src/user}/memory.d.ts +0 -0
  140. /package/dist/cjs/{user → server/src/user}/sequelize.d.ts +0 -0
  141. /package/dist/cjs/{user → server/src/user}/types.d.ts +0 -0
  142. /package/dist/esm/{auth-api → server/src/auth-api}/compat-auth-storage.d.ts +0 -0
  143. /package/dist/esm/{auth-api → server/src/auth-api}/mem-auth-store.d.ts +0 -0
  144. /package/dist/esm/{auth-api → server/src/auth-api}/mem-auth-store.js +0 -0
  145. /package/dist/esm/{auth-api → server/src/auth-api}/module.d.ts +0 -0
  146. /package/dist/esm/{auth-api → server/src/auth-api}/module.js +0 -0
  147. /package/dist/esm/{auth-api → server/src/auth-api}/sql-auth-store.d.ts +0 -0
  148. /package/dist/esm/{auth-api → server/src/auth-api}/sql-auth-store.js +0 -0
  149. /package/dist/esm/{auth-api → server/src/auth-api}/storage.d.ts +0 -0
  150. /package/dist/esm/{auth-api → server/src/auth-api}/storage.js +0 -0
  151. /package/dist/esm/{auth-api → server/src/auth-api}/types.d.ts +0 -0
  152. /package/dist/esm/{auth-api → server/src/auth-api}/types.js +0 -0
  153. /package/dist/esm/{auth-api → server/src/auth-api}/user-id.d.ts +0 -0
  154. /package/dist/esm/{auth-cookie-options.js → server/src/auth-cookie-options.js} +0 -0
  155. /package/dist/esm/{oauth → server/src/oauth}/models.d.ts +0 -0
  156. /package/dist/esm/{oauth → server/src/oauth}/models.js +0 -0
  157. /package/dist/esm/{oauth → server/src/oauth}/types.d.ts +0 -0
  158. /package/dist/esm/{oauth → server/src/oauth}/types.js +0 -0
  159. /package/dist/esm/{passkey → server/src/passkey}/config.d.ts +0 -0
  160. /package/dist/esm/{passkey → server/src/passkey}/config.js +0 -0
  161. /package/dist/esm/{passkey → server/src/passkey}/memory.d.ts +0 -0
  162. /package/dist/esm/{passkey → server/src/passkey}/memory.js +0 -0
  163. /package/dist/esm/{passkey → server/src/passkey}/models.d.ts +0 -0
  164. /package/dist/esm/{passkey → server/src/passkey}/models.js +0 -0
  165. /package/dist/esm/{passkey → server/src/passkey}/sequelize.d.ts +0 -0
  166. /package/dist/esm/{passkey → server/src/passkey}/sequelize.js +0 -0
  167. /package/dist/esm/{passkey → server/src/passkey}/types.d.ts +0 -0
  168. /package/dist/esm/{passkey → server/src/passkey}/types.js +0 -0
  169. /package/dist/esm/{sequelize-utils.d.ts → server/src/sequelize-utils.d.ts} +0 -0
  170. /package/dist/esm/{token → server/src/token}/memory.d.ts +0 -0
  171. /package/dist/esm/{token → server/src/token}/sequelize.d.ts +0 -0
  172. /package/dist/esm/{token → server/src/token}/types.d.ts +0 -0
  173. /package/dist/esm/{token → server/src/token}/types.js +0 -0
  174. /package/dist/esm/{user → server/src/upload}/types.js +0 -0
  175. /package/dist/esm/{user → server/src/user}/memory.d.ts +0 -0
  176. /package/dist/esm/{user → server/src/user}/sequelize.d.ts +0 -0
  177. /package/dist/esm/{user → server/src/user}/types.d.ts +0 -0
package/package.json CHANGED
@@ -1,135 +1,130 @@
1
1
  {
2
- "name": "@technomoron/api-server-base",
3
- "version": "2.0.0-beta.21",
4
- "description": "Api Server Skeleton / Base Class",
5
- "type": "module",
6
- "main": "./dist/cjs/index.cjs",
7
- "module": "./dist/esm/index.js",
8
- "types": "./dist/esm/index.d.ts",
9
- "exports": {
10
- ".": {
11
- "types": "./dist/esm/index.d.ts",
12
- "import": "./dist/esm/index.js",
13
- "require": "./dist/cjs/index.cjs"
14
- },
15
- "./auth-api/sql-auth-store": {
16
- "types": "./dist/esm/auth-api/sql-auth-store.d.ts",
17
- "import": "./dist/esm/auth-api/sql-auth-store.js",
18
- "require": "./dist/cjs/auth-api/sql-auth-store.js"
19
- },
20
- "./oauth/sequelize": {
21
- "types": "./dist/esm/oauth/sequelize.d.ts",
22
- "import": "./dist/esm/oauth/sequelize.js",
23
- "require": "./dist/cjs/oauth/sequelize.js"
24
- },
25
- "./passkey/sequelize": {
26
- "types": "./dist/esm/passkey/sequelize.d.ts",
27
- "import": "./dist/esm/passkey/sequelize.js",
28
- "require": "./dist/cjs/passkey/sequelize.js"
29
- },
30
- "./token/sequelize": {
31
- "types": "./dist/esm/token/sequelize.d.ts",
32
- "import": "./dist/esm/token/sequelize.js",
33
- "require": "./dist/cjs/token/sequelize.js"
34
- },
35
- "./user/sequelize": {
36
- "types": "./dist/esm/user/sequelize.d.ts",
37
- "import": "./dist/esm/user/sequelize.js",
38
- "require": "./dist/cjs/user/sequelize.js"
39
- }
40
- },
41
- "repository": {
42
- "type": "git",
43
- "url": "git+https://github.com/technomoron/api-server-base.git"
44
- },
45
- "author": "Bjørn Erik Jacobsen",
46
- "license": "MIT",
47
- "copyright": "Copyright (c) 2025 Bjørn Erik Jacobsen",
48
- "bugs": {
49
- "url": "https://github.com/technomoron/api-server-base/issues"
50
- },
51
- "homepage": "https://github.com/technomoron/api-server-base#readme",
52
- "scripts": {
53
- "scrub": "rm -rf ./node_modules/ pnpm-lock.yaml ./dist/",
54
- "build:cjs": "tsc --project tsconfig/tsconfig.cjs.json && node scripts/prepare-cjs.cjs",
55
- "build:esm": "tsc --project tsconfig/tsconfig.esm.json",
56
- "build": "run-s build:cjs build:esm",
57
- "test": "vitest run",
58
- "test:unit": "vitest run tests/unit",
59
- "test:functional": "vitest run tests/functional",
60
- "test:watch": "vitest --watch",
61
- "prepublishOnly": "run-s build:cjs build:esm",
62
- "lint": "eslint --no-error-on-unmatched-pattern --ext .js,.cjs,.mjs,.ts,.mts,.tsx,.vue,.json ./",
63
- "lintfix": "eslint --fix --no-error-on-unmatched-pattern --ext .js,.cjs,.mjs,.ts,.mts,.tsx,.vue,.json ./",
64
- "format": "run-s lintfix pretty",
65
- "cleanbuild": "rm -rf ./dist/ && run-s format build",
66
- "pretty": "prettier --write \"**/*.{js,jsx,cjs,mjs,ts,tsx,mts,vue,json,md}\"",
67
- "lintconfig": "node lintconfig.cjs"
68
- },
69
- "dependencies": {
70
- "@simplewebauthn/server": "^13.2.2",
71
- "@types/express": "^5.0.6",
72
- "bcryptjs": "^3.0.3",
73
- "cookie-parser": "^1.4.7",
74
- "cors": "^2.8.6",
75
- "express": "^5.2.1",
76
- "jsonwebtoken": "^9.0.3",
77
- "multer": "^2.0.2"
78
- },
79
- "devDependencies": {
80
- "@types/cookie-parser": "^1.4.10",
81
- "@types/cors": "^2.8.19",
82
- "@types/express-serve-static-core": "^5.1.1",
83
- "@types/jsonwebtoken": "^9.0.10",
84
- "@types/multer": "^2.0.0",
85
- "@types/supertest": "^6.0.3",
86
- "@typescript-eslint/eslint-plugin": "^8.54.0",
87
- "@typescript-eslint/parser": "^8.54.0",
88
- "@vitest/coverage-v8": "4.0.18",
89
- "eslint": "^9.39.2",
90
- "eslint-config-prettier": "^10.1.8",
91
- "eslint-plugin-import": "^2.32.0",
92
- "jsonc-eslint-parser": "^2.4.2",
93
- "mysql2": "^3.16.3",
94
- "pg": "^8.18.0",
95
- "prettier": "^3.8.1",
96
- "sequelize": "^6.37.7",
97
- "sqlite3": "^5.1.7",
98
- "supertest": "^7.2.2",
99
- "typescript": "^5.9.3",
100
- "vitest": "^4.0.18",
101
- "npm-run-all": "^4.1.5"
102
- },
103
- "peerDependencies": {
104
- "mysql2": "^3.16.0",
105
- "pg": "^8.16.3",
106
- "sequelize": "^6.37.7",
107
- "sqlite3": "^5.1.7"
108
- },
109
- "peerDependenciesMeta": {
110
- "mysql2": {
111
- "optional": true
112
- },
113
- "pg": {
114
- "optional": true
115
- },
116
- "sequelize": {
117
- "optional": true
118
- },
119
- "sqlite3": {
120
- "optional": true
121
- }
122
- },
123
- "pnpm": {
124
- "onlyBuiltDependencies": [
125
- "esbuild",
126
- "sqlite3"
127
- ]
128
- },
129
- "files": [
130
- "dist/",
131
- "docs/swagger/openapi.json",
132
- "package.json"
133
- ],
134
- "packageManager": "pnpm@10.28.2"
135
- }
2
+ "name": "@technomoron/api-server-base",
3
+ "version": "2.0.0-beta.23",
4
+ "description": "Api Server Skeleton / Base Class",
5
+ "type": "module",
6
+ "main": "./dist/cjs/index.cjs",
7
+ "module": "./dist/esm/index.js",
8
+ "types": "./dist/esm/index.d.ts",
9
+ "exports": {
10
+ ".": {
11
+ "types": "./dist/esm/index.d.ts",
12
+ "import": "./dist/esm/index.js",
13
+ "require": "./dist/cjs/index.cjs"
14
+ },
15
+ "./auth-api/sql-auth-store": {
16
+ "types": "./dist/esm/auth-api/sql-auth-store.d.ts",
17
+ "import": "./dist/esm/auth-api/sql-auth-store.js",
18
+ "require": "./dist/cjs/auth-api/sql-auth-store.cjs"
19
+ },
20
+ "./oauth/sequelize": {
21
+ "types": "./dist/esm/oauth/sequelize.d.ts",
22
+ "import": "./dist/esm/oauth/sequelize.js",
23
+ "require": "./dist/cjs/oauth/sequelize.cjs"
24
+ },
25
+ "./passkey/sequelize": {
26
+ "types": "./dist/esm/passkey/sequelize.d.ts",
27
+ "import": "./dist/esm/passkey/sequelize.js",
28
+ "require": "./dist/cjs/passkey/sequelize.cjs"
29
+ },
30
+ "./token/sequelize": {
31
+ "types": "./dist/esm/token/sequelize.d.ts",
32
+ "import": "./dist/esm/token/sequelize.js",
33
+ "require": "./dist/cjs/token/sequelize.cjs"
34
+ },
35
+ "./user/sequelize": {
36
+ "types": "./dist/esm/user/sequelize.d.ts",
37
+ "import": "./dist/esm/user/sequelize.js",
38
+ "require": "./dist/cjs/user/sequelize.cjs"
39
+ }
40
+ },
41
+ "repository": {
42
+ "type": "git",
43
+ "url": "git+https://github.com/technomoron/api-server-base.git",
44
+ "directory": "packages/server"
45
+ },
46
+ "author": "Bjørn Erik Jacobsen",
47
+ "license": "MIT",
48
+ "copyright": "Copyright (c) 2025 Bjørn Erik Jacobsen",
49
+ "bugs": {
50
+ "url": "https://github.com/technomoron/api-server-base/issues"
51
+ },
52
+ "homepage": "https://github.com/technomoron/api-server-base#readme",
53
+ "engines": {
54
+ "node": ">=18"
55
+ },
56
+ "dependencies": {
57
+ "@simplewebauthn/server": "^13.2.2",
58
+ "bcryptjs": "^3.0.3",
59
+ "jsonwebtoken": "^9.0.3",
60
+ "fastify": "^5.6.1",
61
+ "@fastify/cookie": "^11.0.2",
62
+ "@fastify/cors": "^11.1.0",
63
+ "@fastify/multipart": "^9.2.1",
64
+ "@fastify/static": "^8.3.0"
65
+ },
66
+ "devDependencies": {
67
+ "@types/jsonwebtoken": "^9.0.10",
68
+ "@types/supertest": "^6.0.3",
69
+ "@typescript-eslint/eslint-plugin": "^8.54.0",
70
+ "@typescript-eslint/parser": "^8.54.0",
71
+ "@vitest/coverage-v8": "4.0.18",
72
+ "eslint": "^9.39.2",
73
+ "eslint-config-prettier": "^10.1.8",
74
+ "eslint-plugin-import": "^2.32.0",
75
+ "jsonc-eslint-parser": "^2.4.2",
76
+ "mysql2": "^3.16.3",
77
+ "pg": "^8.18.0",
78
+ "prettier": "^3.8.1",
79
+ "sequelize": "^6.37.7",
80
+ "sqlite3": "^5.1.7",
81
+ "supertest": "^7.2.2",
82
+ "typescript": "^5.9.3",
83
+ "vitest": "^4.0.18",
84
+ "npm-run-all": "^4.1.5"
85
+ },
86
+ "peerDependencies": {
87
+ "mysql2": "^3.16.0",
88
+ "pg": "^8.16.3",
89
+ "sequelize": "^6.37.7",
90
+ "sqlite3": "^5.1.7"
91
+ },
92
+ "peerDependenciesMeta": {
93
+ "mysql2": {
94
+ "optional": true
95
+ },
96
+ "pg": {
97
+ "optional": true
98
+ },
99
+ "sequelize": {
100
+ "optional": true
101
+ },
102
+ "sqlite3": {
103
+ "optional": true
104
+ }
105
+ },
106
+ "files": [
107
+ "dist/",
108
+ "docs/swagger/openapi.json",
109
+ "package.json",
110
+ "LICENSE"
111
+ ],
112
+ "scripts": {
113
+ "scrub": "rm -rf ./node_modules/ pnpm-lock.yaml ./dist/",
114
+ "build:cjs": "tsc --project tsconfig/tsconfig.cjs.json && node scripts/prepare-cjs.cjs",
115
+ "build:esm": "tsc --project tsconfig/tsconfig.esm.json",
116
+ "build": "run-s build:cjs build:esm",
117
+ "test": "vitest run",
118
+ "test:unit": "vitest run tests/unit",
119
+ "test:functional": "vitest run tests/functional",
120
+ "test:watch": "vitest --watch",
121
+ "lint": "eslint --no-error-on-unmatched-pattern --ext .js,.cjs,.mjs,.ts,.mts,.tsx,.vue,.json ./",
122
+ "lintfix": "eslint --fix --no-error-on-unmatched-pattern --ext .js,.cjs,.mjs,.ts,.mts,.tsx,.vue,.json ./",
123
+ "format": "run-s lintfix pretty",
124
+ "cleanbuild": "rm -rf ./dist/ && run-s format build",
125
+ "pretty": "prettier --write \"**/*.{js,jsx,cjs,mjs,ts,tsx,mts,vue,json,md}\"",
126
+ "lintconfig": "node lintconfig.cjs",
127
+ "release:check": "bash ./scripts/release-check.sh",
128
+ "release": "bash ./scripts/release.sh"
129
+ }
130
+ }
package/README.txt DELETED
@@ -1,213 +0,0 @@
1
- API Server Base
2
- ================
3
-
4
- Toolkit for building authenticated Express APIs in TypeScript. ApiServer wraps Express with sensible defaults for JSON parsing, cookie handling, CORS, JWT helpers, and a predictable module system.
5
-
6
- - Easy setup of a Node Express based API server with all the basics covered.
7
- - The server can be extended and methods related to user authentication, API keys and more can be overridden in the derived class.
8
- - Create API endpoints that are either public, protected or open API calls that may or may not have an authenticated session for dual behaviour.
9
- - Standardized request handling (POST, GET, file uploads if enabled and more).
10
- - Authentication system using JWT or simple API bearer keys, fully customizable by overriding class methods (now exposes both the resolved API key and stored token row to handlers).
11
- - Unified error handling. Just throw new ApiError(...) in any API callback in order ot emit the correct API response.
12
- - Create structured, standardized API response as JSON data, containing typed return data, response codes and more.
13
-
14
- Highlights
15
- ----------
16
- Strongly typed base classes for servers (ApiServer) and feature modules (ApiModule).
17
- Consistent request lifecycle with centralized authentication, authorization hook, and tuple based handler responses.
18
- JWT, cookie, and API key support with overridable extension points.
19
- No runtime dependencies beyond the Express ecosystem; required packages install automatically.
20
- Ships ESM and CommonJS builds plus TypeScript declarations for any Node runtime.
21
-
22
- Installation
23
- ------------
24
- pnpm add @technomoron/api-server-base
25
-
26
- All runtime dependencies and `@types/*` packages are bundled with the distribution. The library exports ES modules by default. Consumers that rely on CommonJS can import via the require entry exposed in package.json.
27
-
28
- Quick Start
29
- -----------
30
- import { ApiServer, ApiModule, ApiError, BaseAuthAdapter } from '@technomoron/api-server-base';
31
-
32
- type DemoUser = { id: string; email: string; password: string };
33
-
34
- class DemoStorage extends BaseAuthAdapter<DemoUser, Omit<DemoUser, 'password'>> {
35
- private readonly users = new Map<string, DemoUser>([
36
- ['1', { id: '1', email: 'demo@example.com', password: 'secret' }]
37
- ]);
38
-
39
- async getUser(uid: unknown) {
40
- return this.users.get(String(uid)) ?? null;
41
- }
42
-
43
- getUserPasswordHash(user: DemoUser) {
44
- return user.password;
45
- }
46
-
47
- filterUser(user: DemoUser) {
48
- const { password: _password, ...safe } = user;
49
- void _password;
50
- return safe;
51
- }
52
- }
53
-
54
- class AppServer extends ApiServer {}
55
-
56
- class UserModule extends ApiModule<AppServer> {
57
- constructor() {
58
- super({ namespace: '/users' });
59
- }
60
-
61
- defineRoutes() {
62
- return [
63
- {
64
- method: 'get',
65
- path: '/',
66
- auth: { type: 'yes', req: 'any' },
67
- handler: async ({ server, tokenData }) => {
68
- const storage = server.getAuthStorage();
69
- const user = tokenData ? await storage.getUser(tokenData.uid) : null;
70
- if (!user) {
71
- throw new ApiError({ code: 404, message: 'User not found' });
72
- }
73
- return [200, storage.filterUser(user)];
74
- },
75
- },
76
- ];
77
- }
78
- }
79
-
80
- const yourStorageAdapter = new DemoStorage();
81
-
82
- const server = new AppServer({
83
- apiPort: 3101,
84
- apiHost: '127.0.0.1',
85
- accessSecret: 'replace-me'
86
- })
87
- .authStorage(yourStorageAdapter)
88
- .api(new UserModule())
89
- .finalize()
90
- .start();
91
-
92
- Need a dedicated auth module as well? Chain `.authModule(...)` in the same spot.
93
-
94
- Handlers must return a tuple: [statusCode], [statusCode, data], or [statusCode, data, message]. Throw ApiError for predictable failures.
95
-
96
- Configuration Reference
97
- -----------------------
98
- Pass a partial config object to the ApiServer constructor. Defaults cover most values so you can opt in to what you need.
99
-
100
- apiPort (number, default 3101) Port the Express app listens on.
101
- apiHost (string, default 'localhost') Bind address.
102
- apiBasePath (string, default '/api') Prefix applied to every module namespace.
103
- origins (string array, default empty array) CORS allowlist; empty allows all origins.
104
- uploadPath (string, default empty string) Enables multer.any() when provided.
105
- uploadMax (number, default 30 * 1024 * 1024) Maximum upload size in bytes.
106
- staticDirs (record, default empty object) Map of mount path => disk path for serving static files as-is (ex: { '/assets': './public' }).
107
- accessSecret (string, default empty string) Required for JWT signing and verification.
108
- refreshSecret (string, default empty string) Used for refresh tokens if you implement them.
109
- cookieDomain (string, default '') Domain applied to auth cookies.
110
- cookiePath (string, default '/') Path applied to auth cookies.
111
- cookieSameSite ('lax' | 'strict' | 'none', default 'lax') SameSite attribute applied to auth cookies.
112
- cookieSecure (boolean | 'auto', default 'auto') Secure attribute applied to auth cookies; 'auto' enables Secure only when the request is HTTPS (or forwarded as HTTPS).
113
- cookieHttpOnly (boolean, default true) HttpOnly attribute applied to auth cookies.
114
- accessCookie (string, default 'dat') Access token cookie name.
115
- refreshCookie (string, default 'drt') Refresh token cookie name.
116
- accessExpiry (number, default 60 * 15) Access token lifetime in seconds.
117
- refreshExpiry (number, default 30 * 24 * 60 * 60) Refresh token lifetime in seconds.
118
- sessionRefreshExpiry (number, default 24 * 60 * 60) Session token lifetime in seconds when clients opt out of "remember me" cookies.
119
- authApi (boolean, default false) Toggle you can use when mounting auth routes.
120
- devMode (boolean, default false) Custom hook for development only features.
121
- debug (boolean, default false) When true the server logs inbound requests via dumpRequest.
122
- hydrateGetBody (boolean, default true) Copy query parameters into `req.body` for GET requests; set false if you prefer untouched bodies.
123
- validateTokens (boolean, default false) When true, every JWT-authenticated request must match a stored token row (access token + user id) before reaching your handler. API keys remain stateless either way.
124
- refreshMaybe (boolean, default false) When true, `auth: maybe` routes will try to refresh a missing/expired access token using the refresh cookie; if refresh fails, the request stays anonymous.
125
-
126
- Tip: If you add new configuration fields in downstream projects, extend ApiServerConf and update fillConfig so defaults stay aligned.
127
-
128
- Request Lifecycle
129
- -----------------
130
- 1. Express middlewares (express.json, cookie-parser, optional multer) run before your handler.
131
- 2. ApiServer wraps the route inside handle_request, creating an ApiRequest and logging when debug is enabled.
132
- 3. authenticate enforces the ApiRoute auth type: `none`, `maybe`, `yes`, `strict`, or `apikey`. Bearer JWTs and the access cookie (`accessCookie`, default `dat`) are accepted for `yes`/`strict`, while API key tokens prefixed with `apikey-` always delegate to `getApiKey`. When `refreshSecret` is configured and your storage supports refresh lookups (`getToken({ refreshToken })` + `updateToken(...)`), `yes`/`strict` routes will automatically mint a new access token when it is missing or expired (and also recover from "Authorization token is no longer valid" by refreshing). `maybe` routes only do the same when `refreshMaybe: true`. The optional `strict` type (or server-wide `validateTokens` flag) requires the signed JWT to exist in storage; when it does, the persisted row is attached to `apiReq.authToken`. The dedicated `apikey` type simply means “an API key is required”; otherwise API keys are still accepted by `yes`/`strict` routes alongside JWTs, and `apiReq.apiKey` is populated when present.
133
- 4. authorize runs with the requested auth class (any or admin in the base implementation). Override to connect to your role system.
134
- 5. The handler executes and returns its tuple. Responses are normalized to { code, message, data } JSON.
135
- 6. Errors bubble into the wrapper. ApiError instances respect the provided status codes; other exceptions result in a 500 with text derived from guessExceptionText.
136
-
137
- Client IP Helpers
138
- -----------------
139
- Call `apiReq.getClientInfo()` when you need the entire client fingerprint captured during request hydration. It returns the raw user-agent string plus derived browser/OS/device labels along with the computed `ip` and `ipchain`.
140
-
141
- Call `apiReq.getClientIp()` to obtain the most likely client address, skipping loopback entries collected from proxy headers. Use `apiReq.getClientIpChain()` when you need the de-duplicated sequence gathered from the standard Forwarded/X-Forwarded-For/X-Real-IP headers as well as Express' `req.ip`/`req.ips` and the underlying socket. Both helpers reuse the cached payload returned by `apiReq.getClientInfo()`.
142
-
143
- Extending the Base Classes
144
- --------------------------
145
- Implement the AuthStorage contract (getUser, verifyPassword, storeToken, updateToken, etc.) to integrate with your persistence layer, then supply it via authStorage().
146
- Use your storage adapter's filterUser helper to trim sensitive data before returning responses.
147
- Provide your own authorize method to enforce role based access control using the ApiAuthClass enum.
148
- Create feature modules by extending ApiModule. Use the optional checkConfig hook to validate prerequisites before routes mount.
149
-
150
- OAuth Client Secrets
151
- --------------------
152
- If your OAuth client records use a client secret, make `getClient(clientId)` return a client with a truthy `clientSecret` (do not return the stored hash/secret itself) and implement `verifyClientSecret(client, clientSecret)` on your storage adapter. If `clientSecret` is truthy but `verifyClientSecret` is not overridden, the `/auth/v1/oauth2/token` endpoint returns 501.
153
-
154
- Sequelize Table Prefixes
155
- ------------------------
156
- Sequelize-backed stores accept `tablePrefix` to prepend to the built-in table names (`users`, `jwttokens`, `passkey_credentials`, `passkey_challenges`, `oauth_clients`, `oauth_codes`).
157
-
158
- SqlAuthStore supports both a global prefix (`tablePrefix`) and per-module overrides (`tablePrefixes.user|token|passkey|oauth`). When present, `tokenStoreOptions.tablePrefix` and `oauthStoreOptions.tablePrefix` take precedence.
159
-
160
- Example:
161
-
162
- const store = new SqlAuthStore({
163
- sequelize,
164
- tablePrefix: 'myapp_'
165
- });
166
- // Creates tables like myapp_users, myapp_jwttokens, myapp_oauth_clients, ...
167
-
168
- If you need a different base name (for example `myapp_tokens` instead of `myapp_jwttokens`), pass a custom model or model factory to the store and set the `tableName` yourself.
169
-
170
- Custom Express Endpoints
171
- ------------------------
172
- ApiModule routes run inside the tuple wrapper (always responding with a standardized JSON envelope). For endpoints that need raw Express control (streaming, webhooks, tus uploads, etc.), mount your own handlers directly.
173
-
174
- - `server.useExpress(...)` mounts middleware/routes and keeps the built-in `/api` 404 handler ordered last, so mounts under `apiBasePath` are not intercepted.
175
- - Protect endpoints by inserting `server.expressAuth({ type, req })` as middleware. It authenticates using the same JWT/cookie/API-key logic as ApiModule routes and then runs `authorize`.
176
- - On success, `expressAuth` attaches the computed ApiRequest to both `req.apiReq` and `res.locals.apiReq`.
177
- - If you want the same JSON error envelope for custom endpoints, mount `server.expressErrorHandler()` after your custom routes.
178
-
179
- Example:
180
-
181
- server
182
- .useExpress(
183
- '/api/custom/optional',
184
- server.expressAuth({ type: 'maybe', req: 'any' }),
185
- (req, res) => {
186
- const apiReq = (req as any).apiReq;
187
- res.status(200).json({ uid: apiReq.tokenData?.uid ?? null });
188
- }
189
- )
190
- .useExpress(server.expressErrorHandler());
191
-
192
- Finalize And Start
193
- ------------------
194
- Call `server.finalize()` after you have mounted all ApiModules and custom Express endpoints. After finalize (or after `start()`), calling `api()` / `useExpress()` will throw.
195
-
196
-
197
- Tooling and Scripts
198
- -------------------
199
- npm run build Build CommonJS and ESM outputs (dist/cjs, dist/esm).
200
- npm run build:cjs Compile using tsconfig/tsconfig.cjs.json.
201
- npm run build:esm Compile using tsconfig/tsconfig.esm.json.
202
- npm run lint Run ESLint with the flat config (eslint.config.mjs).
203
- npm run lintfix Lint and apply autofixes.
204
- npm run pretty Run Prettier over common source and documentation files.
205
- npm run cleanbuild Remove dist/, format, lint, and rebuild.
206
-
207
- Documentation
208
- -------------
209
- See docs/ folder.
210
-
211
- License
212
- -------
213
- MIT License (see LICENSE). Copyright 2025 Bjorn Erik Jacobsen / Technomoron
@@ -1,2 +0,0 @@
1
- export class OAuthStore {
2
- }
@@ -1,2 +0,0 @@
1
- export class PasskeyStore {
2
- }
File without changes
File without changes
File without changes
File without changes
File without changes
File without changes
File without changes