very-express 0.9.0 → 0.10.1

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (131) hide show
  1. package/.tmp/als-proof.mjs +15 -0
  2. package/.tmp/als-proof2.mjs +9 -0
  3. package/.tmp/gen/out/.env +41 -0
  4. package/.tmp/gen/out/.vex/meta.json +387 -0
  5. package/.tmp/gen/out/Dockerfile +20 -0
  6. package/.tmp/gen/out/README.md +39 -0
  7. package/.tmp/gen/out/package.json +51 -0
  8. package/.tmp/gen/out/public/css/style.css +8 -0
  9. package/.tmp/gen/out/public/js/deleteaccount.js +80 -0
  10. package/.tmp/gen/out/public/js/login.js +59 -0
  11. package/.tmp/gen/out/public/js/logincallback.js +19 -0
  12. package/.tmp/gen/out/public/js/mytokens.js +11 -0
  13. package/.tmp/gen/out/public/js/refreshtokens.js +23 -0
  14. package/.tmp/gen/out/scripts/build.js +39 -0
  15. package/.tmp/gen/out/scripts/oacg-fix.js +83 -0
  16. package/.tmp/gen/out/tsconfig.json +30 -0
  17. package/.tmp/gen/out/tsoa.json +32 -0
  18. package/.tmp/gen/schemas/Project.json +50 -0
  19. package/.tmp/gen/schemas/Session.json +49 -0
  20. package/.tmp/gen/schemas/User.json +81 -0
  21. package/.tmp/gen/schemas/UserAuthProfiles.json +54 -0
  22. package/.tmp/gen/schemas/UserRole.json +40 -0
  23. package/.tmp/gen/schemas/UserTenant.json +39 -0
  24. package/.tmp/gen/vex.config.json +39 -0
  25. package/.tmp/gen0/out/.env +41 -0
  26. package/.tmp/gen0/out/.vex/meta.json +323 -0
  27. package/.tmp/gen0/out/Dockerfile +20 -0
  28. package/.tmp/gen0/out/README.md +39 -0
  29. package/.tmp/gen0/out/package.json +51 -0
  30. package/.tmp/gen0/out/public/css/style.css +8 -0
  31. package/.tmp/gen0/out/public/js/deleteaccount.js +80 -0
  32. package/.tmp/gen0/out/public/js/login.js +59 -0
  33. package/.tmp/gen0/out/public/js/logincallback.js +19 -0
  34. package/.tmp/gen0/out/public/js/mytokens.js +11 -0
  35. package/.tmp/gen0/out/public/js/refreshtokens.js +23 -0
  36. package/.tmp/gen0/out/scripts/build.js +39 -0
  37. package/.tmp/gen0/out/scripts/oacg-fix.js +83 -0
  38. package/.tmp/gen0/out/tsconfig.json +30 -0
  39. package/.tmp/gen0/out/tsoa.json +32 -0
  40. package/.tmp/gen0/schemas/Session.json +49 -0
  41. package/.tmp/gen0/schemas/User.json +81 -0
  42. package/.tmp/gen0/schemas/UserAuthProfiles.json +54 -0
  43. package/.tmp/gen0/schemas/UserRole.json +38 -0
  44. package/.tmp/gen0/vex.config.json +32 -0
  45. package/.tmp/gend/out/.env +41 -0
  46. package/.tmp/gend/out/.vex/meta.json +317 -0
  47. package/.tmp/gend/out/Dockerfile +20 -0
  48. package/.tmp/gend/out/README.md +39 -0
  49. package/.tmp/gend/out/package.json +51 -0
  50. package/.tmp/gend/out/public/css/style.css +8 -0
  51. package/.tmp/gend/out/public/js/deleteaccount.js +80 -0
  52. package/.tmp/gend/out/public/js/login.js +59 -0
  53. package/.tmp/gend/out/public/js/logincallback.js +19 -0
  54. package/.tmp/gend/out/public/js/mytokens.js +11 -0
  55. package/.tmp/gend/out/public/js/refreshtokens.js +23 -0
  56. package/.tmp/gend/out/scripts/build.js +39 -0
  57. package/.tmp/gend/out/scripts/oacg-fix.js +83 -0
  58. package/.tmp/gend/out/tsconfig.json +30 -0
  59. package/.tmp/gend/out/tsoa.json +32 -0
  60. package/.tmp/gend/schemas/Session.json +49 -0
  61. package/.tmp/gend/schemas/User.json +81 -0
  62. package/.tmp/gend/schemas/UserAuthProfiles.json +54 -0
  63. package/.tmp/gend/schemas/UserContact.json +40 -0
  64. package/.tmp/gend/schemas/UserNote.json +27 -0
  65. package/.tmp/gend/vex.config.json +33 -0
  66. package/.tmp/genh/out/.env +41 -0
  67. package/.tmp/genh/out/.vex/meta.json +323 -0
  68. package/.tmp/genh/out/Dockerfile +20 -0
  69. package/.tmp/genh/out/README.md +39 -0
  70. package/.tmp/genh/out/package.json +51 -0
  71. package/.tmp/genh/out/public/css/style.css +8 -0
  72. package/.tmp/genh/out/public/js/deleteaccount.js +80 -0
  73. package/.tmp/genh/out/public/js/login.js +59 -0
  74. package/.tmp/genh/out/public/js/logincallback.js +19 -0
  75. package/.tmp/genh/out/public/js/mytokens.js +11 -0
  76. package/.tmp/genh/out/public/js/refreshtokens.js +23 -0
  77. package/.tmp/genh/out/scripts/build.js +39 -0
  78. package/.tmp/genh/out/scripts/oacg-fix.js +83 -0
  79. package/.tmp/genh/out/tsconfig.json +30 -0
  80. package/.tmp/genh/out/tsoa.json +32 -0
  81. package/.tmp/genh/schemas/Project.json +41 -0
  82. package/.tmp/genh/schemas/Session.json +49 -0
  83. package/.tmp/genh/schemas/User.json +81 -0
  84. package/.tmp/genh/schemas/UserAuthProfiles.json +54 -0
  85. package/.tmp/genh/schemas/UserTenant.json +39 -0
  86. package/.tmp/genh/vex.config.json +34 -0
  87. package/.tmp/gens/out/.env +41 -0
  88. package/.tmp/gens/out/.vex/meta.json +335 -0
  89. package/.tmp/gens/out/Dockerfile +20 -0
  90. package/.tmp/gens/out/README.md +39 -0
  91. package/.tmp/gens/out/package.json +51 -0
  92. package/.tmp/gens/out/public/css/style.css +8 -0
  93. package/.tmp/gens/out/public/js/deleteaccount.js +80 -0
  94. package/.tmp/gens/out/public/js/login.js +59 -0
  95. package/.tmp/gens/out/public/js/logincallback.js +19 -0
  96. package/.tmp/gens/out/public/js/mytokens.js +11 -0
  97. package/.tmp/gens/out/public/js/refreshtokens.js +23 -0
  98. package/.tmp/gens/out/scripts/build.js +39 -0
  99. package/.tmp/gens/out/scripts/oacg-fix.js +83 -0
  100. package/.tmp/gens/out/tsconfig.json +30 -0
  101. package/.tmp/gens/out/tsoa.json +32 -0
  102. package/.tmp/gens/schemas/Session.json +49 -0
  103. package/.tmp/gens/schemas/User.json +81 -0
  104. package/.tmp/gens/schemas/UserAuthProfiles.json +54 -0
  105. package/.tmp/gens/schemas/UserRole.json +38 -0
  106. package/.tmp/gens/vex.config.json +32 -0
  107. package/.tmp/npmtest/package.json +1 -0
  108. package/.tmp/ro-test +0 -0
  109. package/AGENTS.md +4 -3
  110. package/README.md +1 -0
  111. package/dist/index.js +955 -653
  112. package/dist/templates/_middlewares/Authentication.ts +1 -1
  113. package/dist/templates/_middlewares/UserContext.ts +30 -4
  114. package/dist/templates/_services/MongooseRepositoryAdapter.ts +94 -4
  115. package/dist/templates/_services/TypeOrmRepositoryAdapter.ts +92 -17
  116. package/dist/templates/_services/VexDbConnector.ts +36 -1
  117. package/dist/templates/_services/auth/JWTService.ts +13 -2
  118. package/dist/templates/_tenant/TenantScopeContext.ts +56 -0
  119. package/dist/templates/_types/auth.ts +7 -1
  120. package/dist/templates/_types/vex/VexRepository.ts +9 -2
  121. package/dist/templates/tenantJsonSchema/UserTenant.json +33 -0
  122. package/docs/architecture/databaseTargets.md +37 -8
  123. package/docs/architecture/generatorPipeline.md +2 -1
  124. package/docs/features/accountDeletion.md +61 -9
  125. package/docs/features/dataIsolation.md +58 -31
  126. package/docs/features/tenantIsolation.md +147 -0
  127. package/docs/releaseNote/v0-10-0.md +147 -0
  128. package/docs/releaseNote/v0-10-1.md +84 -0
  129. package/docs/vexJsonSchema.md +22 -0
  130. package/package.json +1 -1
  131. package/vitest.config.ts +3 -0
@@ -0,0 +1,317 @@
1
+ {
2
+ "lastGeneratedVersion": "0.9.0",
3
+ "files": {
4
+ "..": {
5
+ "vex.config.json": {
6
+ "lastWriteVersion": "0.9.0",
7
+ "allowOverwrite": true
8
+ },
9
+ "schemas": {
10
+ "Session.json": {
11
+ "lastWriteVersion": "0.9.0",
12
+ "allowOverwrite": true
13
+ },
14
+ "User.json": {
15
+ "lastWriteVersion": "0.9.0",
16
+ "allowOverwrite": true
17
+ },
18
+ "UserAuthProfiles.json": {
19
+ "lastWriteVersion": "0.9.0",
20
+ "allowOverwrite": true
21
+ },
22
+ "UserContact.json": {
23
+ "lastWriteVersion": "0.9.0",
24
+ "allowOverwrite": true
25
+ }
26
+ }
27
+ },
28
+ "src": {
29
+ "system": {
30
+ "_controllers": {
31
+ "_ControllerFactory.gen.ts": {
32
+ "lastWriteVersion": "0.9.0",
33
+ "allowOverwrite": true
34
+ },
35
+ "UserController.gen.ts": {
36
+ "lastWriteVersion": "0.9.0",
37
+ "allowOverwrite": true
38
+ },
39
+ "AuthController.gen.ts": {
40
+ "lastWriteVersion": "0.9.0",
41
+ "allowOverwrite": true
42
+ }
43
+ },
44
+ "_middlewares": {
45
+ "Authentication.gen.ts": {
46
+ "lastWriteVersion": "0.9.0",
47
+ "allowOverwrite": true
48
+ },
49
+ "JoinWhitelistMiddleware.gen.ts": {
50
+ "lastWriteVersion": "0.9.0",
51
+ "allowOverwrite": true
52
+ },
53
+ "UserContext.gen.ts": {
54
+ "lastWriteVersion": "0.9.0",
55
+ "allowOverwrite": true
56
+ },
57
+ "tsoaAuthentication.gen.ts": {
58
+ "lastWriteVersion": "0.9.0",
59
+ "allowOverwrite": true
60
+ },
61
+ "JoinWhitelistRegistry.gen.ts": {
62
+ "lastWriteVersion": "0.9.0",
63
+ "allowOverwrite": true
64
+ },
65
+ "DataIsolationRegistry.gen.ts": {
66
+ "lastWriteVersion": "0.9.0",
67
+ "allowOverwrite": true
68
+ },
69
+ "VexFieldRegistry.gen.ts": {
70
+ "lastWriteVersion": "0.9.0",
71
+ "allowOverwrite": true
72
+ }
73
+ },
74
+ "_routes": {
75
+ "FirebaseAuthUI.gen.ts": {
76
+ "lastWriteVersion": "0.9.0",
77
+ "allowOverwrite": true
78
+ },
79
+ "LoginUI.gen.ts": {
80
+ "lastWriteVersion": "0.9.0",
81
+ "allowOverwrite": true
82
+ },
83
+ "oauth": {
84
+ "OAuthRouteFactory.gen.ts": {
85
+ "lastWriteVersion": "0.9.0",
86
+ "allowOverwrite": true
87
+ }
88
+ },
89
+ "SwaggerRouter.gen.ts": {
90
+ "lastWriteVersion": "0.9.0",
91
+ "allowOverwrite": true
92
+ }
93
+ },
94
+ "_services": {
95
+ "MongooseRepositoryAdapter.gen.ts": {
96
+ "lastWriteVersion": "0.9.0",
97
+ "allowOverwrite": true
98
+ },
99
+ "TypeOrmRepositoryAdapter.gen.ts": {
100
+ "lastWriteVersion": "0.9.0",
101
+ "allowOverwrite": true
102
+ },
103
+ "VexDb.gen.ts": {
104
+ "lastWriteVersion": "0.9.0",
105
+ "allowOverwrite": true
106
+ },
107
+ "VexDbConnector.gen.ts": {
108
+ "lastWriteVersion": "0.9.0",
109
+ "allowOverwrite": true
110
+ },
111
+ "VexSystem.gen.ts": {
112
+ "lastWriteVersion": "0.9.0",
113
+ "allowOverwrite": true
114
+ },
115
+ "auth": {
116
+ "JWTKeyStore.gen.ts": {
117
+ "lastWriteVersion": "0.9.0",
118
+ "allowOverwrite": true
119
+ },
120
+ "JWTService.gen.ts": {
121
+ "lastWriteVersion": "0.9.0",
122
+ "allowOverwrite": true
123
+ },
124
+ "AccountStateGuard.gen.ts": {
125
+ "lastWriteVersion": "0.9.0",
126
+ "allowOverwrite": true
127
+ }
128
+ },
129
+ "oauth": {
130
+ "OAuthProfileMap.gen.ts": {
131
+ "lastWriteVersion": "0.9.0",
132
+ "allowOverwrite": true
133
+ },
134
+ "OAuthStrategyService.gen.ts": {
135
+ "lastWriteVersion": "0.9.0",
136
+ "allowOverwrite": true
137
+ }
138
+ },
139
+ "account": {
140
+ "AccountDeletionService.gen.ts": {
141
+ "lastWriteVersion": "0.9.0",
142
+ "allowOverwrite": true
143
+ }
144
+ }
145
+ },
146
+ "_types": {
147
+ "auth.gen.ts": {
148
+ "lastWriteVersion": "0.9.0",
149
+ "allowOverwrite": true
150
+ },
151
+ "vex": {
152
+ "VexRepository.gen.ts": {
153
+ "lastWriteVersion": "0.9.0",
154
+ "allowOverwrite": true
155
+ },
156
+ "VexRequest.gen.ts": {
157
+ "lastWriteVersion": "0.9.0",
158
+ "allowOverwrite": true
159
+ },
160
+ "VexResErr.gen.ts": {
161
+ "lastWriteVersion": "0.9.0",
162
+ "allowOverwrite": true
163
+ },
164
+ "VexResOk.gen.ts": {
165
+ "lastWriteVersion": "0.9.0",
166
+ "allowOverwrite": true
167
+ },
168
+ "VexResponse.gen.ts": {
169
+ "lastWriteVersion": "0.9.0",
170
+ "allowOverwrite": true
171
+ },
172
+ "index.ts": {
173
+ "lastWriteVersion": "0.9.0",
174
+ "allowOverwrite": true
175
+ }
176
+ },
177
+ "Session.gen.ts": {
178
+ "lastWriteVersion": "0.9.0",
179
+ "allowOverwrite": true
180
+ },
181
+ "User.gen.ts": {
182
+ "lastWriteVersion": "0.9.0",
183
+ "allowOverwrite": true
184
+ },
185
+ "UserAuthProfiles.gen.ts": {
186
+ "lastWriteVersion": "0.9.0",
187
+ "allowOverwrite": true
188
+ },
189
+ "UserContact.gen.ts": {
190
+ "lastWriteVersion": "0.9.0",
191
+ "allowOverwrite": true
192
+ },
193
+ "UserNote.gen.ts": {
194
+ "lastWriteVersion": "0.9.0",
195
+ "allowOverwrite": true
196
+ }
197
+ },
198
+ "_utils": {
199
+ "hash.gen.ts": {
200
+ "lastWriteVersion": "0.9.0",
201
+ "allowOverwrite": true
202
+ },
203
+ "index.ts": {
204
+ "lastWriteVersion": "0.9.0",
205
+ "allowOverwrite": true
206
+ },
207
+ "logger.gen.ts": {
208
+ "lastWriteVersion": "0.9.0",
209
+ "allowOverwrite": true
210
+ },
211
+ "processTimer.gen.ts": {
212
+ "lastWriteVersion": "0.9.0",
213
+ "allowOverwrite": true
214
+ },
215
+ "response.gen.ts": {
216
+ "lastWriteVersion": "0.9.0",
217
+ "allowOverwrite": true
218
+ },
219
+ "validator.gen.ts": {
220
+ "lastWriteVersion": "0.9.0",
221
+ "allowOverwrite": true
222
+ }
223
+ },
224
+ "_models": {
225
+ "SessionModel.gen.ts": {
226
+ "lastWriteVersion": "0.9.0",
227
+ "allowOverwrite": true
228
+ },
229
+ "UserModel.gen.ts": {
230
+ "lastWriteVersion": "0.9.0",
231
+ "allowOverwrite": true
232
+ },
233
+ "UserAuthProfilesModel.gen.ts": {
234
+ "lastWriteVersion": "0.9.0",
235
+ "allowOverwrite": true
236
+ },
237
+ "UserContactModel.gen.ts": {
238
+ "lastWriteVersion": "0.9.0",
239
+ "allowOverwrite": true
240
+ },
241
+ "UserNoteModel.gen.ts": {
242
+ "lastWriteVersion": "0.9.0",
243
+ "allowOverwrite": true
244
+ }
245
+ }
246
+ },
247
+ "server.ts": {
248
+ "lastWriteVersion": "0.9.0",
249
+ "allowOverwrite": true
250
+ }
251
+ },
252
+ "Dockerfile": {
253
+ "lastWriteVersion": "0.9.0",
254
+ "allowOverwrite": true
255
+ },
256
+ "README.md": {
257
+ "lastWriteVersion": "0.9.0",
258
+ "allowOverwrite": true
259
+ },
260
+ "public": {
261
+ "css": {
262
+ "style.css": {
263
+ "lastWriteVersion": "0.9.0",
264
+ "allowOverwrite": true
265
+ }
266
+ },
267
+ "js": {
268
+ "deleteaccount.js": {
269
+ "lastWriteVersion": "0.9.0",
270
+ "allowOverwrite": true
271
+ },
272
+ "login.js": {
273
+ "lastWriteVersion": "0.9.0",
274
+ "allowOverwrite": true
275
+ },
276
+ "logincallback.js": {
277
+ "lastWriteVersion": "0.9.0",
278
+ "allowOverwrite": true
279
+ },
280
+ "mytokens.js": {
281
+ "lastWriteVersion": "0.9.0",
282
+ "allowOverwrite": true
283
+ },
284
+ "refreshtokens.js": {
285
+ "lastWriteVersion": "0.9.0",
286
+ "allowOverwrite": true
287
+ }
288
+ }
289
+ },
290
+ "scripts": {
291
+ "build.js": {
292
+ "lastWriteVersion": "0.9.0",
293
+ "allowOverwrite": true
294
+ },
295
+ "oacg-fix.js": {
296
+ "lastWriteVersion": "0.9.0",
297
+ "allowOverwrite": true
298
+ }
299
+ },
300
+ "tsconfig.json": {
301
+ "lastWriteVersion": "0.9.0",
302
+ "allowOverwrite": true
303
+ },
304
+ "package.json": {
305
+ "lastWriteVersion": "0.9.0",
306
+ "allowOverwrite": true
307
+ },
308
+ ".env": {
309
+ "lastWriteVersion": "0.9.0",
310
+ "allowOverwrite": true
311
+ },
312
+ "tsoa.json": {
313
+ "lastWriteVersion": "0.9.0",
314
+ "allowOverwrite": true
315
+ }
316
+ }
317
+ }
@@ -0,0 +1,20 @@
1
+ # Use the official Node.js image as the base image
2
+ FROM node:14
3
+
4
+ # Set the working directory inside the container
5
+ WORKDIR /app
6
+
7
+ # Copy package.json and package-lock.json to the working directory
8
+ COPY package*.json ./
9
+
10
+ # Install dependencies
11
+ RUN npm install
12
+
13
+ # Copy only the /dist directory to the working directory
14
+ COPY dist ./dist
15
+
16
+ # Expose the port the app runs on
17
+ EXPOSE 3000
18
+
19
+ # Define the command to run the application
20
+ CMD ["npm", "start"]
@@ -0,0 +1,39 @@
1
+ # This app is generated by [VeryExpress](https://github.com/Justin26l/VeryExpress)
2
+
3
+
4
+ # Quick Start
5
+ 1. install `very-express` from npm
6
+ `npm install -g very-express` or `npm update -g very-express`
7
+
8
+ 2. check configuration file [vex.config.json](./vex.config.json) under project root directory and keep it updated (re-generate the app with very-express).
9
+ `vex`
10
+
11
+ 3. we should have a express typescript app.
12
+ ```
13
+ ├── src/
14
+ │ └── openapi
15
+ │ └── roles (role based access control settings)
16
+ │ └── system (very express generated app)
17
+ ├── package.json
18
+ ├── tsconfig.json
19
+ ├── vex.config.json
20
+ ├── .env
21
+ └── ...
22
+ ```
23
+
24
+ 4. start the generated express app.
25
+ ```
26
+ npm i
27
+ npm build
28
+ npm run start
29
+ ```
30
+
31
+ 5. start the app in docker.
32
+ ```
33
+ npm run docker-build
34
+ npm run docker-start
35
+ ```
36
+
37
+ # Resource
38
+ - [Documents](https://github.com/Justin26l/VeryExpress/blob/main/README.md)
39
+ - [VeryExpress Discord](https://discord.gg/PZGMzDp7)
@@ -0,0 +1,51 @@
1
+ {
2
+ "main": "index.js",
3
+ "scripts": {
4
+ "build": "npm run openapi && tsc -p . && node scripts/build.js",
5
+ "start": "node dist/server.js",
6
+ "dev": "nodemon --watch src --ext ts --ignore src/system/_routes/tsoa_routes.ts --ignore src/openapi/ --exec \"tsoa spec-and-routes && ts-node src/server.ts\"",
7
+ "openapi": "tsoa spec-and-routes",
8
+ "docker-build": "docker build -t very-express .",
9
+ "docker-start": "docker run -p 3000:3000 very-express"
10
+ },
11
+ "dependencies": {
12
+ "cookie": "^0.6.0",
13
+ "cookie-parser": "^1.4.6",
14
+ "dotenv": "^16.4.4",
15
+ "express": "^4.18.2",
16
+ "firebase-admin": "^14.1.0",
17
+ "helmet": "^7.1.0",
18
+ "js-yaml": "^4.1.0",
19
+ "jsonwebtoken": "^9.0.2",
20
+ "passport": "^0.7.0",
21
+ "passport-github": "^1.1.0",
22
+ "passport-google-oauth20": "^2.0.0",
23
+ "passport-jwt": "^4.0.1",
24
+ "pg": "^8.20.0",
25
+ "reflect-metadata": "^0.2.2",
26
+ "swagger-ui-express": "^5.0.0",
27
+ "tsoa": "^7.0.0-alpha.0",
28
+ "typeorm": "^0.3.20"
29
+ },
30
+ "devDependencies": {
31
+ "@types/cookie-parser": "^1.4.7",
32
+ "@types/crypto-js": "^4.1.2",
33
+ "@types/dotenv": "^8.2.0",
34
+ "@types/express": "^4.17.17",
35
+ "@types/js-yaml": "^4.0.9",
36
+ "@types/jsonwebtoken": "^9.0.7",
37
+ "@types/mongodb": "^4.0.7",
38
+ "@types/ms": "^2.1.0",
39
+ "@types/node": "^20.4.2",
40
+ "@types/passport": "^1.0.16",
41
+ "@types/passport-github": "^1.1.12",
42
+ "@types/passport-google-oauth20": "^2.0.14",
43
+ "@types/pg": "^8.11.0",
44
+ "@types/swagger-ui-express": "^4.1.6",
45
+ "@types/ws": "^8.5.5",
46
+ "nodemon": "^2.0.22",
47
+ "strip-json-comments": "^5.0.1",
48
+ "ts-node": "^10.9.1",
49
+ "typescript": "^5.1.6"
50
+ }
51
+ }
@@ -0,0 +1,8 @@
1
+
2
+ pre {
3
+ background-color: #f4f4f4;
4
+ padding: 20px;
5
+ overflow: auto;
6
+ border: 1px solid #ccc;
7
+ white-space: pre-wrap;
8
+ }
@@ -0,0 +1,80 @@
1
+ // Self-service account deletion page.
2
+ //
3
+ // Sends the access token the same way the rest of the app does — Authorization + X-Auth-Index —
4
+ // and clears the stored tokens on success, because the account is gone the moment the tombstone
5
+ // is written: keeping a token the server will now reject only produces confusing 401s.
6
+
7
+ // The page loads this script from <head>, so it must wait for the DOM: at parse time the
8
+ // button does not exist yet and getElementById would return null.
9
+ document.addEventListener("DOMContentLoaded", function () {
10
+ var button = document.getElementById("deleteAccountBtn");
11
+ var input = document.getElementById("confirmInput");
12
+ var result = document.getElementById("deleteResult");
13
+
14
+ if (!button || !input || !result) return;
15
+
16
+ function clearTokens() {
17
+ localStorage.removeItem("accessToken");
18
+ localStorage.removeItem("accessTokenIndex");
19
+ localStorage.removeItem("refreshToken");
20
+ localStorage.removeItem("refreshTokenIndex");
21
+ }
22
+
23
+ function render(data) {
24
+ result.textContent = JSON.stringify(data, null, 2);
25
+ }
26
+
27
+ button.addEventListener("click", function () {
28
+ if (input.value !== "DELETE") {
29
+ render({ error: 'Type DELETE in the box to confirm.' });
30
+ return;
31
+ }
32
+
33
+ button.disabled = true;
34
+ render({ status: "Deleting…" });
35
+
36
+ fetch("/api/auth/delete-account", {
37
+ method: "POST",
38
+ credentials: "include",
39
+ headers: {
40
+ "Content-Type": "application/json",
41
+ "Authorization": "Bearer " + (localStorage.getItem("accessToken") || ""),
42
+ "X-Auth-Index": localStorage.getItem("accessTokenIndex") || "",
43
+ },
44
+ })
45
+ .then(function (response) {
46
+ // read as text first: an error response may not be JSON (a proxy or the
47
+ // express error handler can return HTML), and response.json() would then
48
+ // reject and hide the real status behind a parse error
49
+ return response.text().then(function (text) {
50
+ var body;
51
+ try {
52
+ body = text ? JSON.parse(text) : {};
53
+ }
54
+ catch (e) {
55
+ body = { raw: text };
56
+ }
57
+
58
+ return { ok: response.ok, status: response.status, body: body };
59
+ });
60
+ })
61
+ .then(function (outcome) {
62
+ if (!outcome.ok) {
63
+ render({ status: outcome.status, error: outcome.body });
64
+ button.disabled = false;
65
+ return;
66
+ }
67
+
68
+ clearTokens();
69
+ render({
70
+ status: "Account deleted. You have been signed out.",
71
+ result: outcome.body,
72
+ });
73
+ input.value = "";
74
+ })
75
+ .catch(function (err) {
76
+ render({ error: String(err) });
77
+ button.disabled = false;
78
+ });
79
+ });
80
+ });
@@ -0,0 +1,59 @@
1
+
2
+ document.addEventListener("DOMContentLoaded", function () {
3
+ // add event listener to login button
4
+ document.querySelector("#localLoginBtn").addEventListener("click", function () {
5
+ // call /api/auth/local
6
+ fetch("/api/auth/local", {
7
+ method: "POST",
8
+ headers: {
9
+ "Content-Type": "application/json"
10
+ },
11
+ body: JSON.stringify({
12
+ email: document.querySelector("#email").value,
13
+ password: document.querySelector("#password").value
14
+ })
15
+ })
16
+ .then(async (res) => {
17
+ if (res.status === 301 || res.status === 302) {
18
+ const data = await res.json();
19
+ if (data.result?.url) {
20
+ window.location.href = data.result?.url;
21
+ }
22
+ else {
23
+ alert("Login successful, but no redirect URL provided.");
24
+ }
25
+ }
26
+ else {
27
+ const data = await res.json();
28
+ alert("Login Failed: " + data.message);
29
+ }
30
+ })
31
+ .catch((err) => {
32
+ console.error("Error during login:", err);
33
+ alert("Login Error: " + err.message);
34
+ });
35
+ });
36
+
37
+ document.querySelector("#localRegisterBtn").addEventListener("click", function () {
38
+ // call /api/auth/register
39
+ fetch("/api/auth/register", {
40
+ method: "POST",
41
+ headers: {
42
+ "Content-Type": "application/json"
43
+ },
44
+ body: JSON.stringify({
45
+ email: document.querySelector("#email").value,
46
+ password: document.querySelector("#password").value
47
+ })
48
+ })
49
+ .then(async (res) => {
50
+ if (res.status === 201) {
51
+ alert("Registration successful. You can now log in.");
52
+ }
53
+ })
54
+ .catch((err) => {
55
+ console.error("Error during registration:", err);
56
+ alert("An error occurred during registration. Please try again later.");
57
+ });
58
+ });
59
+ });
@@ -0,0 +1,19 @@
1
+
2
+ document.addEventListener("DOMContentLoaded", function() {
3
+ console.log('Exchange Tokens from /api/auth/token');
4
+ let sessionCode = new URLSearchParams(location.search).get('code');
5
+ fetch(
6
+ '/api/auth/token?code=' + sessionCode, {
7
+ method: 'POST'
8
+ }
9
+ )
10
+ .then((res) => res.text())
11
+ .then((data) => {
12
+ const jsonData = JSON.parse(data);
13
+ document.querySelector("#tokenData").innerHTML = JSON.stringify(jsonData, null, 2);
14
+ localStorage.setItem('accessToken', jsonData.result.accessToken);
15
+ localStorage.setItem('accessTokenIndex', jsonData.result.accessTokenIndex);
16
+ localStorage.setItem('refreshToken', jsonData.result.refreshToken);
17
+ localStorage.setItem('refreshTokenIndex', jsonData.result.refreshTokenIndex);
18
+ });
19
+ });
@@ -0,0 +1,11 @@
1
+ let jsonData = {};
2
+
3
+ document.addEventListener("DOMContentLoaded", function () {
4
+ jsonData = {
5
+ accessToken: localStorage.getItem("accessToken"),
6
+ accessTokenIndex: localStorage.getItem("accessTokenIndex"),
7
+ refreshToken: localStorage.getItem("refreshToken"),
8
+ refreshTokenIndex: localStorage.getItem("refreshTokenIndex"),
9
+ };
10
+ document.querySelector("#tokenData").innerHTML = JSON.stringify(jsonData, null, 2);
11
+ });
@@ -0,0 +1,23 @@
1
+ document.addEventListener("DOMContentLoaded", function () {
2
+ jsonPayload = {
3
+ refreshToken: localStorage.getItem("refreshToken"),
4
+ refreshTokenIndex: localStorage.getItem("refreshTokenIndex"),
5
+ };
6
+
7
+ fetch("/api/auth/refresh", {
8
+ method: "POST",
9
+ body: JSON.stringify(jsonPayload),
10
+ headers: {
11
+ "Content-Type": "application/json",
12
+ "Accept": "application/json",
13
+ "Authorization": "Bearer " + localStorage.getItem("accessToken"),
14
+ "X-Auth-Index": localStorage.getItem("accessTokenIndex")
15
+ }
16
+ })
17
+ .then(res => res.json())
18
+ .then((response) => {
19
+ localStorage.setItem("accessToken", response.accessToken);
20
+ localStorage.setItem("accessTokenIndex", response.accessTokenIndex);
21
+ document.querySelector("#tokenData").innerHTML = JSON.stringify(response, null, 2);
22
+ });
23
+ });
@@ -0,0 +1,39 @@
1
+ // copy openapiDir to tsconfig's outDir
2
+
3
+ const fs = require('fs');
4
+ const path = require('path');
5
+
6
+ async function loadStripJsonComments() {
7
+ const { default: stripJsonComments } = await import('strip-json-comments');
8
+ return stripJsonComments;
9
+ }
10
+
11
+ async function main() {
12
+ // Load strip-json-comments dynamically
13
+ const stripJsonComments = await loadStripJsonComments();
14
+
15
+ const openapiDir = "src/openapi";
16
+ const tsconfigPath = "tsconfig.json"
17
+
18
+ // 1. read tsconfig.json to get outDir
19
+ const tsconfigContent = fs.readFileSync(tsconfigPath, 'utf-8');
20
+ const tsconfig = JSON.parse(stripJsonComments(tsconfigContent));
21
+ const outDir = tsconfig.compilerOptions.outDir;
22
+
23
+ // 2. copy ./openapi to outDir
24
+ const outDirOpenapi = path.resolve(outDir, 'openapi');
25
+ if (!fs.existsSync(outDirOpenapi)) {
26
+ fs.mkdirSync(outDirOpenapi, { recursive: true });
27
+ }
28
+ fs.readdirSync(openapiDir).forEach((file) => {
29
+ fs.copyFileSync(path.resolve(openapiDir, file), path.resolve(outDirOpenapi, file));
30
+ });
31
+ }
32
+
33
+
34
+ // Execute the main function
35
+ main()
36
+ .catch(err => {
37
+ console.error(err);
38
+ process.exit(1);
39
+ });