@rebasepro/server-core 0.7.0 → 0.9.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/README.md +2 -2
- package/dist/api/ast-schema-editor.d.ts +21 -0
- package/dist/api/collections_for_test/callbacks_test_collection.d.ts +2 -0
- package/dist/api/errors.d.ts +53 -0
- package/dist/api/index.d.ts +7 -0
- package/dist/api/logs-routes.d.ts +37 -0
- package/dist/api/openapi-generator.d.ts +16 -0
- package/dist/api/rest/api-generator.d.ts +68 -0
- package/{src/api/rest/index.ts → dist/api/rest/index.d.ts} +0 -1
- package/dist/api/rest/query-parser.d.ts +6 -0
- package/dist/api/schema-editor-routes.d.ts +3 -0
- package/dist/api/types.d.ts +56 -0
- package/dist/auth/adapter-middleware.d.ts +43 -0
- package/dist/auth/admin-roles-route.d.ts +18 -0
- package/dist/auth/admin-user-ops.d.ts +79 -0
- package/dist/auth/admin-users-route.d.ts +28 -0
- package/dist/auth/api-keys/api-key-middleware.d.ts +39 -0
- package/{src/auth/api-keys/api-key-permission-guard.ts → dist/auth/api-keys/api-key-permission-guard.d.ts} +2 -34
- package/dist/auth/api-keys/api-key-routes.d.ts +20 -0
- package/dist/auth/api-keys/api-key-store.d.ts +35 -0
- package/{src/auth/api-keys/api-key-types.ts → dist/auth/api-keys/api-key-types.d.ts} +0 -6
- package/{src/auth/api-keys/index.ts → dist/auth/api-keys/index.d.ts} +2 -22
- package/dist/auth/apple-oauth.d.ts +30 -0
- package/{src/auth/auth-hooks.ts → dist/auth/auth-hooks.d.ts} +15 -73
- package/dist/auth/bitbucket-oauth.d.ts +11 -0
- package/dist/auth/builtin-auth-adapter.d.ts +55 -0
- package/dist/auth/cookie-utils.d.ts +32 -0
- package/{src/auth/crypto-utils.ts → dist/auth/crypto-utils.d.ts} +1 -16
- package/dist/auth/custom-auth-adapter.d.ts +39 -0
- package/dist/auth/discord-oauth.d.ts +14 -0
- package/dist/auth/facebook-oauth.d.ts +14 -0
- package/dist/auth/github-oauth.d.ts +15 -0
- package/dist/auth/gitlab-oauth.d.ts +13 -0
- package/dist/auth/google-oauth.d.ts +47 -0
- package/{src/auth/index.ts → dist/auth/index.d.ts} +4 -22
- package/{src/auth/interfaces.ts → dist/auth/interfaces.d.ts} +20 -89
- package/dist/auth/jwt.d.ts +67 -0
- package/dist/auth/linkedin-oauth.d.ts +18 -0
- package/dist/auth/magic-link-routes.d.ts +32 -0
- package/dist/auth/mfa-crypto.d.ts +23 -0
- package/dist/auth/mfa-routes.d.ts +7 -0
- package/dist/auth/mfa.d.ts +49 -0
- package/dist/auth/microsoft-oauth.d.ts +16 -0
- package/dist/auth/middleware.d.ts +158 -0
- package/dist/auth/password.d.ts +22 -0
- package/dist/auth/rate-limiter.d.ts +50 -0
- package/dist/auth/reset-password-admin.d.ts +29 -0
- package/dist/auth/rls-scope.d.ts +31 -0
- package/dist/auth/routes.d.ts +66 -0
- package/dist/auth/session-routes.d.ts +29 -0
- package/dist/auth/slack-oauth.d.ts +12 -0
- package/dist/auth/spotify-oauth.d.ts +12 -0
- package/dist/auth/twitter-oauth.d.ts +18 -0
- package/dist/collections/BackendCollectionRegistry.d.ts +13 -0
- package/dist/collections/loader.d.ts +5 -0
- package/dist/cron/cron-loader.d.ts +18 -0
- package/dist/cron/cron-routes.d.ts +14 -0
- package/dist/cron/cron-scheduler.d.ts +106 -0
- package/dist/cron/cron-store.d.ts +32 -0
- package/dist/cron/define-cron.d.ts +28 -0
- package/{src/cron/index.ts → dist/cron/index.d.ts} +1 -0
- package/dist/db/interfaces.d.ts +18 -0
- package/dist/dynamic-import-Dvh-K5fl.js +22 -0
- package/dist/dynamic-import-Dvh-K5fl.js.map +1 -0
- package/dist/email/index.d.ts +6 -0
- package/dist/email/smtp-email-service.d.ts +30 -0
- package/dist/email/templates.d.ts +50 -0
- package/{src/email/types.ts → dist/email/types.d.ts} +40 -36
- package/dist/env.d.ts +102 -0
- package/dist/functions/define-function.d.ts +55 -0
- package/dist/functions/function-loader.d.ts +18 -0
- package/dist/functions/function-routes.d.ts +10 -0
- package/{src/functions/index.ts → dist/functions/index.d.ts} +2 -0
- package/dist/history/history-routes.d.ts +23 -0
- package/{src/history/index.ts → dist/history/index.d.ts} +0 -1
- package/dist/index.d.ts +35 -0
- package/dist/index.es.js +18184 -0
- package/dist/index.es.js.map +1 -0
- package/dist/index.umd.js +48629 -0
- package/dist/index.umd.js.map +1 -0
- package/dist/init/docs.d.ts +4 -0
- package/dist/init/health.d.ts +2 -0
- package/dist/init/middlewares.d.ts +10 -0
- package/dist/init/shutdown.d.ts +65 -0
- package/dist/init/storage.d.ts +5 -0
- package/dist/init.d.ts +344 -0
- package/dist/jwt-BwIn8xmk.js +4200 -0
- package/dist/jwt-BwIn8xmk.js.map +1 -0
- package/dist/logger-BYU66ENZ.js +94 -0
- package/dist/logger-BYU66ENZ.js.map +1 -0
- package/dist/ms-DnYXB-Wd.js +162 -0
- package/dist/ms-DnYXB-Wd.js.map +1 -0
- package/dist/openapi-generator-Z9oYWLf_.js +586 -0
- package/dist/openapi-generator-Z9oYWLf_.js.map +1 -0
- package/dist/schema-editor-routes-D3ef8zu1.js +219 -0
- package/dist/schema-editor-routes-D3ef8zu1.js.map +1 -0
- package/dist/serve-spa.d.ts +36 -0
- package/dist/services/driver-registry.d.ts +78 -0
- package/dist/services/routed-realtime-service.d.ts +43 -0
- package/dist/services/webhook-service.d.ts +29 -0
- package/dist/singleton.d.ts +51 -0
- package/dist/src-B4OLmNVa.js +437 -0
- package/dist/src-B4OLmNVa.js.map +1 -0
- package/dist/src-B5WkP1Rv.js +24778 -0
- package/dist/src-B5WkP1Rv.js.map +1 -0
- package/dist/storage/GCSStorageController.d.ts +43 -0
- package/dist/storage/LocalStorageController.d.ts +46 -0
- package/dist/storage/S3StorageController.d.ts +40 -0
- package/dist/storage/image-transform.d.ts +50 -0
- package/{src/storage/index.ts → dist/storage/index.d.ts} +6 -21
- package/dist/storage/routes.d.ts +70 -0
- package/dist/storage/storage-registry.d.ts +78 -0
- package/dist/storage/tus-handler.d.ts +53 -0
- package/{src/storage/types.ts → dist/storage/types.d.ts} +32 -38
- package/dist/types/index.d.ts +11 -0
- package/dist/utils/dev-port.d.ts +45 -0
- package/dist/utils/dynamic-import.d.ts +25 -0
- package/dist/utils/logger.d.ts +31 -0
- package/dist/utils/logging.d.ts +9 -0
- package/dist/utils/request-id.d.ts +4 -0
- package/dist/utils/request-logger.d.ts +19 -0
- package/{src/utils/sql.ts → dist/utils/sql.d.ts} +5 -16
- package/package.json +49 -22
- package/coverage/clover.xml +0 -3739
- package/coverage/coverage-final.json +0 -31
- package/coverage/lcov-report/base.css +0 -224
- package/coverage/lcov-report/block-navigation.js +0 -87
- package/coverage/lcov-report/favicon.png +0 -0
- package/coverage/lcov-report/index.html +0 -266
- package/coverage/lcov-report/prettify.css +0 -1
- package/coverage/lcov-report/prettify.js +0 -2
- package/coverage/lcov-report/sort-arrow-sprite.png +0 -0
- package/coverage/lcov-report/sorter.js +0 -210
- package/coverage/lcov-report/src/api/ast-schema-editor.ts.html +0 -952
- package/coverage/lcov-report/src/api/errors.ts.html +0 -472
- package/coverage/lcov-report/src/api/graphql/graphql-schema-generator.ts.html +0 -1069
- package/coverage/lcov-report/src/api/graphql/index.html +0 -116
- package/coverage/lcov-report/src/api/index.html +0 -176
- package/coverage/lcov-report/src/api/openapi-generator.ts.html +0 -565
- package/coverage/lcov-report/src/api/rest/api-generator.ts.html +0 -994
- package/coverage/lcov-report/src/api/rest/index.html +0 -131
- package/coverage/lcov-report/src/api/rest/query-parser.ts.html +0 -550
- package/coverage/lcov-report/src/api/schema-editor-routes.ts.html +0 -202
- package/coverage/lcov-report/src/api/server.ts.html +0 -823
- package/coverage/lcov-report/src/auth/admin-routes.ts.html +0 -973
- package/coverage/lcov-report/src/auth/index.html +0 -176
- package/coverage/lcov-report/src/auth/jwt.ts.html +0 -574
- package/coverage/lcov-report/src/auth/middleware.ts.html +0 -745
- package/coverage/lcov-report/src/auth/password.ts.html +0 -310
- package/coverage/lcov-report/src/auth/services.ts.html +0 -2074
- package/coverage/lcov-report/src/collections/index.html +0 -116
- package/coverage/lcov-report/src/collections/loader.ts.html +0 -232
- package/coverage/lcov-report/src/db/auth-schema.ts.html +0 -523
- package/coverage/lcov-report/src/db/data-transformer.ts.html +0 -1753
- package/coverage/lcov-report/src/db/entityService.ts.html +0 -700
- package/coverage/lcov-report/src/db/index.html +0 -146
- package/coverage/lcov-report/src/db/services/EntityFetchService.ts.html +0 -4048
- package/coverage/lcov-report/src/db/services/EntityPersistService.ts.html +0 -883
- package/coverage/lcov-report/src/db/services/RelationService.ts.html +0 -3121
- package/coverage/lcov-report/src/db/services/entity-helpers.ts.html +0 -442
- package/coverage/lcov-report/src/db/services/index.html +0 -176
- package/coverage/lcov-report/src/db/services/index.ts.html +0 -124
- package/coverage/lcov-report/src/generate-drizzle-schema-logic.ts.html +0 -1960
- package/coverage/lcov-report/src/index.html +0 -116
- package/coverage/lcov-report/src/services/driver-registry.ts.html +0 -631
- package/coverage/lcov-report/src/services/index.html +0 -131
- package/coverage/lcov-report/src/services/postgresDataDriver.ts.html +0 -3025
- package/coverage/lcov-report/src/storage/LocalStorageController.ts.html +0 -1189
- package/coverage/lcov-report/src/storage/S3StorageController.ts.html +0 -970
- package/coverage/lcov-report/src/storage/index.html +0 -161
- package/coverage/lcov-report/src/storage/storage-registry.ts.html +0 -646
- package/coverage/lcov-report/src/storage/types.ts.html +0 -451
- package/coverage/lcov-report/src/utils/drizzle-conditions.ts.html +0 -3082
- package/coverage/lcov-report/src/utils/index.html +0 -116
- package/coverage/lcov.info +0 -7179
- package/jest.config.cjs +0 -19
- package/src/api/ast-schema-editor.ts +0 -289
- package/src/api/collections_for_test/callbacks_test_collection.ts +0 -61
- package/src/api/errors.ts +0 -278
- package/src/api/graphql/graphql-schema-generator.ts +0 -383
- package/src/api/graphql/index.ts +0 -2
- package/src/api/index.ts +0 -11
- package/src/api/logs-routes.ts +0 -132
- package/src/api/openapi-generator.ts +0 -727
- package/src/api/rest/api-generator-count.test.ts +0 -126
- package/src/api/rest/api-generator.ts +0 -747
- package/src/api/rest/query-parser.ts +0 -300
- package/src/api/schema-editor-routes.ts +0 -41
- package/src/api/server.ts +0 -271
- package/src/api/types.ts +0 -104
- package/src/auth/adapter-middleware.ts +0 -114
- package/src/auth/admin-roles-route.ts +0 -36
- package/src/auth/admin-user-ops.ts +0 -236
- package/src/auth/admin-users-route.ts +0 -302
- package/src/auth/api-keys/api-key-middleware.ts +0 -133
- package/src/auth/api-keys/api-key-routes.ts +0 -193
- package/src/auth/api-keys/api-key-store.ts +0 -340
- package/src/auth/apple-oauth.ts +0 -122
- package/src/auth/bitbucket-oauth.ts +0 -84
- package/src/auth/builtin-auth-adapter.ts +0 -380
- package/src/auth/custom-auth-adapter.ts +0 -86
- package/src/auth/discord-oauth.ts +0 -85
- package/src/auth/facebook-oauth.ts +0 -74
- package/src/auth/github-oauth.ts +0 -112
- package/src/auth/gitlab-oauth.ts +0 -72
- package/src/auth/google-oauth.ts +0 -223
- package/src/auth/jwt.ts +0 -208
- package/src/auth/linkedin-oauth.ts +0 -83
- package/src/auth/magic-link-routes.ts +0 -167
- package/src/auth/mfa-crypto.ts +0 -91
- package/src/auth/mfa-routes.ts +0 -323
- package/src/auth/mfa.ts +0 -161
- package/src/auth/microsoft-oauth.ts +0 -90
- package/src/auth/middleware.ts +0 -369
- package/src/auth/password.ts +0 -77
- package/src/auth/rate-limiter.ts +0 -225
- package/src/auth/reset-password-admin.ts +0 -160
- package/src/auth/rls-scope.ts +0 -58
- package/src/auth/routes.ts +0 -802
- package/src/auth/session-routes.ts +0 -353
- package/src/auth/slack-oauth.ts +0 -73
- package/src/auth/spotify-oauth.ts +0 -69
- package/src/auth/twitter-oauth.ts +0 -128
- package/src/collections/BackendCollectionRegistry.ts +0 -20
- package/src/collections/loader.ts +0 -50
- package/src/cron/cron-loader.ts +0 -84
- package/src/cron/cron-routes.test.ts +0 -265
- package/src/cron/cron-routes.ts +0 -85
- package/src/cron/cron-scheduler.test.ts +0 -559
- package/src/cron/cron-scheduler.ts +0 -581
- package/src/cron/cron-store.ts +0 -166
- package/src/db/interfaces.ts +0 -60
- package/src/email/index.ts +0 -19
- package/src/email/smtp-email-service.ts +0 -123
- package/src/email/templates.ts +0 -470
- package/src/env.ts +0 -227
- package/src/functions/function-loader.ts +0 -116
- package/src/functions/function-routes.ts +0 -31
- package/src/history/history-routes.ts +0 -129
- package/src/index.ts +0 -70
- package/src/init/docs.ts +0 -47
- package/src/init/health.ts +0 -37
- package/src/init/middlewares.ts +0 -61
- package/src/init/shutdown.ts +0 -56
- package/src/init/storage.ts +0 -57
- package/src/init.ts +0 -1041
- package/src/serve-spa.ts +0 -89
- package/src/services/driver-registry.ts +0 -183
- package/src/services/routed-realtime-service.ts +0 -113
- package/src/services/webhook-service.ts +0 -155
- package/src/singleton.ts +0 -70
- package/src/storage/LocalStorageController.ts +0 -389
- package/src/storage/S3StorageController.ts +0 -300
- package/src/storage/image-transform.ts +0 -218
- package/src/storage/routes.ts +0 -368
- package/src/storage/storage-registry.ts +0 -188
- package/src/storage/tus-handler.ts +0 -315
- package/src/types/index.ts +0 -27
- package/src/utils/dev-port.ts +0 -196
- package/src/utils/logger.ts +0 -143
- package/src/utils/logging.ts +0 -40
- package/src/utils/request-id.ts +0 -40
- package/src/utils/request-logger.ts +0 -72
- package/test/api-generator.test.ts +0 -588
- package/test/api-key-permission-guard.test.ts +0 -144
- package/test/ast-schema-editor.test.ts +0 -89
- package/test/auth-middleware-hono.test.ts +0 -556
- package/test/auth-routes.test.ts +0 -1098
- package/test/backend-hooks-data.test.ts +0 -477
- package/test/custom-auth-adapter.test.ts +0 -189
- package/test/driver-registry.test.ts +0 -282
- package/test/email-templates.test.ts +0 -174
- package/test/env.test.ts +0 -128
- package/test/error-propagation.test.ts +0 -226
- package/test/errors-hono.test.ts +0 -133
- package/test/errors.test.ts +0 -155
- package/test/function-loader.test.ts +0 -127
- package/test/graphql-schema-generator.test.ts +0 -554
- package/test/jwt-security.test.ts +0 -182
- package/test/jwt.test.ts +0 -326
- package/test/mfa.test.ts +0 -197
- package/test/middleware.test.ts +0 -305
- package/test/multi-datasource-routing.test.ts +0 -113
- package/test/password.test.ts +0 -165
- package/test/query-parser.test.ts +0 -233
- package/test/rate-limiter.test.ts +0 -102
- package/test/reset-password-admin.test.ts +0 -113
- package/test/routed-realtime-service.test.ts +0 -86
- package/test/safe-compare.test.ts +0 -66
- package/test/singleton.test.ts +0 -59
- package/test/smtp-email-service.test.ts +0 -169
- package/test/storage-local.test.ts +0 -271
- package/test/storage-registry.test.ts +0 -282
- package/test/storage-routes.test.ts +0 -222
- package/test/storage-s3.test.ts +0 -304
- package/test/transform-auth-response.test.ts +0 -305
- package/test/webhook-service.test.ts +0 -260
- package/tsconfig.json +0 -54
- package/tsconfig.prod.json +0 -23
- package/vite.config.ts +0 -86
package/src/email/templates.ts
DELETED
|
@@ -1,470 +0,0 @@
|
|
|
1
|
-
/**
|
|
2
|
-
* Default email templates for authentication emails
|
|
3
|
-
*/
|
|
4
|
-
|
|
5
|
-
interface TemplateUser {
|
|
6
|
-
email: string;
|
|
7
|
-
displayName?: string | null;
|
|
8
|
-
}
|
|
9
|
-
|
|
10
|
-
/**
|
|
11
|
-
* Get a greeting name for the user
|
|
12
|
-
*/
|
|
13
|
-
function getGreeting(user: TemplateUser): string {
|
|
14
|
-
return user.displayName || user.email.split("@")[0];
|
|
15
|
-
}
|
|
16
|
-
|
|
17
|
-
/**
|
|
18
|
-
* Common email styles
|
|
19
|
-
*/
|
|
20
|
-
const styles = {
|
|
21
|
-
container: `
|
|
22
|
-
font-family: -apple-system, BlinkMacSystemFont, 'Segoe UI', Roboto, 'Helvetica Neue', Arial, sans-serif;
|
|
23
|
-
max-width: 600px;
|
|
24
|
-
margin: 0 auto;
|
|
25
|
-
padding: 40px 20px;
|
|
26
|
-
background-color: #f8fafc;
|
|
27
|
-
`,
|
|
28
|
-
card: `
|
|
29
|
-
background-color: #ffffff;
|
|
30
|
-
border-radius: 12px;
|
|
31
|
-
padding: 40px;
|
|
32
|
-
box-shadow: 0 4px 6px -1px rgba(0, 0, 0, 0.1);
|
|
33
|
-
`,
|
|
34
|
-
heading: `
|
|
35
|
-
color: #1e293b;
|
|
36
|
-
font-size: 24px;
|
|
37
|
-
font-weight: 600;
|
|
38
|
-
margin: 0 0 20px 0;
|
|
39
|
-
`,
|
|
40
|
-
paragraph: `
|
|
41
|
-
color: #475569;
|
|
42
|
-
font-size: 16px;
|
|
43
|
-
line-height: 1.6;
|
|
44
|
-
margin: 0 0 20px 0;
|
|
45
|
-
`,
|
|
46
|
-
button: `
|
|
47
|
-
display: inline-block;
|
|
48
|
-
background-color: #3b82f6;
|
|
49
|
-
color: #ffffff;
|
|
50
|
-
font-size: 16px;
|
|
51
|
-
font-weight: 600;
|
|
52
|
-
text-decoration: none;
|
|
53
|
-
padding: 14px 28px;
|
|
54
|
-
border-radius: 8px;
|
|
55
|
-
margin: 20px 0;
|
|
56
|
-
`,
|
|
57
|
-
footer: `
|
|
58
|
-
color: #94a3b8;
|
|
59
|
-
font-size: 14px;
|
|
60
|
-
margin-top: 30px;
|
|
61
|
-
padding-top: 20px;
|
|
62
|
-
border-top: 1px solid #e2e8f0;
|
|
63
|
-
`,
|
|
64
|
-
warning: `
|
|
65
|
-
color: #64748b;
|
|
66
|
-
font-size: 14px;
|
|
67
|
-
background-color: #fef3c7;
|
|
68
|
-
padding: 12px 16px;
|
|
69
|
-
border-radius: 6px;
|
|
70
|
-
margin-top: 20px;
|
|
71
|
-
`
|
|
72
|
-
};
|
|
73
|
-
|
|
74
|
-
/**
|
|
75
|
-
* Default password reset email template
|
|
76
|
-
*/
|
|
77
|
-
export function getPasswordResetTemplate(
|
|
78
|
-
resetUrl: string,
|
|
79
|
-
user: TemplateUser,
|
|
80
|
-
appName = "Rebase"
|
|
81
|
-
): { subject: string; html: string; text: string } {
|
|
82
|
-
const greeting = getGreeting(user);
|
|
83
|
-
|
|
84
|
-
const subject = `Reset your ${appName} password`;
|
|
85
|
-
|
|
86
|
-
const html = `
|
|
87
|
-
<!DOCTYPE html>
|
|
88
|
-
<html>
|
|
89
|
-
<head>
|
|
90
|
-
<meta charset="utf-8">
|
|
91
|
-
<meta name="viewport" content="width=device-width, initial-scale=1.0">
|
|
92
|
-
<title>${subject}</title>
|
|
93
|
-
</head>
|
|
94
|
-
<body style="margin: 0; padding: 0; background-color: #f8fafc;">
|
|
95
|
-
<div style="${styles.container}">
|
|
96
|
-
<div style="${styles.card}">
|
|
97
|
-
<h1 style="${styles.heading}">Reset Your Password</h1>
|
|
98
|
-
|
|
99
|
-
<p style="${styles.paragraph}">
|
|
100
|
-
Hi ${greeting},
|
|
101
|
-
</p>
|
|
102
|
-
|
|
103
|
-
<p style="${styles.paragraph}">
|
|
104
|
-
We received a request to reset your password for your ${appName} account.
|
|
105
|
-
Click the button below to create a new password:
|
|
106
|
-
</p>
|
|
107
|
-
|
|
108
|
-
<div style="text-align: center;">
|
|
109
|
-
<a href="${resetUrl}" style="${styles.button}">Reset Password</a>
|
|
110
|
-
</div>
|
|
111
|
-
|
|
112
|
-
<p style="${styles.paragraph}">
|
|
113
|
-
Or copy and paste this link into your browser:
|
|
114
|
-
</p>
|
|
115
|
-
<p style="color: #3b82f6; word-break: break-all; font-size: 14px;">
|
|
116
|
-
${resetUrl}
|
|
117
|
-
</p>
|
|
118
|
-
|
|
119
|
-
<div style="${styles.warning}">
|
|
120
|
-
⏰ This link will expire in 1 hour for security reasons.
|
|
121
|
-
</div>
|
|
122
|
-
|
|
123
|
-
<div style="${styles.footer}">
|
|
124
|
-
<p style="margin: 0;">
|
|
125
|
-
If you didn't request a password reset, you can safely ignore this email.
|
|
126
|
-
Your password will remain unchanged.
|
|
127
|
-
</p>
|
|
128
|
-
</div>
|
|
129
|
-
</div>
|
|
130
|
-
</div>
|
|
131
|
-
</body>
|
|
132
|
-
</html>
|
|
133
|
-
`.trim();
|
|
134
|
-
|
|
135
|
-
const text = `
|
|
136
|
-
Reset Your Password
|
|
137
|
-
|
|
138
|
-
Hi ${greeting},
|
|
139
|
-
|
|
140
|
-
We received a request to reset your password for your ${appName} account.
|
|
141
|
-
|
|
142
|
-
Click this link to create a new password:
|
|
143
|
-
${resetUrl}
|
|
144
|
-
|
|
145
|
-
This link will expire in 1 hour for security reasons.
|
|
146
|
-
|
|
147
|
-
If you didn't request a password reset, you can safely ignore this email.
|
|
148
|
-
Your password will remain unchanged.
|
|
149
|
-
`.trim();
|
|
150
|
-
|
|
151
|
-
return { subject,
|
|
152
|
-
html,
|
|
153
|
-
text };
|
|
154
|
-
}
|
|
155
|
-
|
|
156
|
-
/**
|
|
157
|
-
* Default email verification template
|
|
158
|
-
*/
|
|
159
|
-
export function getEmailVerificationTemplate(
|
|
160
|
-
verifyUrl: string,
|
|
161
|
-
user: TemplateUser,
|
|
162
|
-
appName = "Rebase"
|
|
163
|
-
): { subject: string; html: string; text: string } {
|
|
164
|
-
const greeting = getGreeting(user);
|
|
165
|
-
|
|
166
|
-
const subject = `Verify your ${appName} email address`;
|
|
167
|
-
|
|
168
|
-
const html = `
|
|
169
|
-
<!DOCTYPE html>
|
|
170
|
-
<html>
|
|
171
|
-
<head>
|
|
172
|
-
<meta charset="utf-8">
|
|
173
|
-
<meta name="viewport" content="width=device-width, initial-scale=1.0">
|
|
174
|
-
<title>${subject}</title>
|
|
175
|
-
</head>
|
|
176
|
-
<body style="margin: 0; padding: 0; background-color: #f8fafc;">
|
|
177
|
-
<div style="${styles.container}">
|
|
178
|
-
<div style="${styles.card}">
|
|
179
|
-
<h1 style="${styles.heading}">Verify Your Email</h1>
|
|
180
|
-
|
|
181
|
-
<p style="${styles.paragraph}">
|
|
182
|
-
Hi ${greeting},
|
|
183
|
-
</p>
|
|
184
|
-
|
|
185
|
-
<p style="${styles.paragraph}">
|
|
186
|
-
Thanks for signing up for ${appName}! Please verify your email address
|
|
187
|
-
by clicking the button below:
|
|
188
|
-
</p>
|
|
189
|
-
|
|
190
|
-
<div style="text-align: center;">
|
|
191
|
-
<a href="${verifyUrl}" style="${styles.button}">Verify Email Address</a>
|
|
192
|
-
</div>
|
|
193
|
-
|
|
194
|
-
<p style="${styles.paragraph}">
|
|
195
|
-
Or copy and paste this link into your browser:
|
|
196
|
-
</p>
|
|
197
|
-
<p style="color: #3b82f6; word-break: break-all; font-size: 14px;">
|
|
198
|
-
${verifyUrl}
|
|
199
|
-
</p>
|
|
200
|
-
|
|
201
|
-
<div style="${styles.footer}">
|
|
202
|
-
<p style="margin: 0;">
|
|
203
|
-
If you didn't create an account with ${appName}, you can safely ignore this email.
|
|
204
|
-
</p>
|
|
205
|
-
</div>
|
|
206
|
-
</div>
|
|
207
|
-
</div>
|
|
208
|
-
</body>
|
|
209
|
-
</html>
|
|
210
|
-
`.trim();
|
|
211
|
-
|
|
212
|
-
const text = `
|
|
213
|
-
Verify Your Email
|
|
214
|
-
|
|
215
|
-
Hi ${greeting},
|
|
216
|
-
|
|
217
|
-
Thanks for signing up for ${appName}! Please verify your email address by clicking this link:
|
|
218
|
-
${verifyUrl}
|
|
219
|
-
|
|
220
|
-
If you didn't create an account with ${appName}, you can safely ignore this email.
|
|
221
|
-
`.trim();
|
|
222
|
-
|
|
223
|
-
return { subject,
|
|
224
|
-
html,
|
|
225
|
-
text };
|
|
226
|
-
}
|
|
227
|
-
|
|
228
|
-
/**
|
|
229
|
-
* Default user invitation email template
|
|
230
|
-
* Sent when an admin creates a new user account
|
|
231
|
-
*/
|
|
232
|
-
export function getUserInvitationTemplate(
|
|
233
|
-
setPasswordUrl: string,
|
|
234
|
-
user: TemplateUser,
|
|
235
|
-
appName = "Rebase"
|
|
236
|
-
): { subject: string; html: string; text: string } {
|
|
237
|
-
const greeting = getGreeting(user);
|
|
238
|
-
|
|
239
|
-
const subject = `You've been invited to ${appName}`;
|
|
240
|
-
|
|
241
|
-
const html = `
|
|
242
|
-
<!DOCTYPE html>
|
|
243
|
-
<html>
|
|
244
|
-
<head>
|
|
245
|
-
<meta charset="utf-8">
|
|
246
|
-
<meta name="viewport" content="width=device-width, initial-scale=1.0">
|
|
247
|
-
<title>${subject}</title>
|
|
248
|
-
</head>
|
|
249
|
-
<body style="margin: 0; padding: 0; background-color: #f8fafc;">
|
|
250
|
-
<div style="${styles.container}">
|
|
251
|
-
<div style="${styles.card}">
|
|
252
|
-
<h1 style="${styles.heading}">Welcome to ${appName}!</h1>
|
|
253
|
-
|
|
254
|
-
<p style="${styles.paragraph}">
|
|
255
|
-
Hi ${greeting},
|
|
256
|
-
</p>
|
|
257
|
-
|
|
258
|
-
<p style="${styles.paragraph}">
|
|
259
|
-
An account has been created for you on ${appName}.
|
|
260
|
-
Click the button below to set your password and get started:
|
|
261
|
-
</p>
|
|
262
|
-
|
|
263
|
-
<div style="text-align: center;">
|
|
264
|
-
<a href="${setPasswordUrl}" style="${styles.button}">Set Your Password</a>
|
|
265
|
-
</div>
|
|
266
|
-
|
|
267
|
-
<p style="${styles.paragraph}">
|
|
268
|
-
Or copy and paste this link into your browser:
|
|
269
|
-
</p>
|
|
270
|
-
<p style="color: #3b82f6; word-break: break-all; font-size: 14px;">
|
|
271
|
-
${setPasswordUrl}
|
|
272
|
-
</p>
|
|
273
|
-
|
|
274
|
-
<div style="${styles.warning}">
|
|
275
|
-
⏰ This link will expire in 1 hour for security reasons.
|
|
276
|
-
</div>
|
|
277
|
-
|
|
278
|
-
<div style="${styles.footer}">
|
|
279
|
-
<p style="margin: 0;">
|
|
280
|
-
If you weren't expecting this invitation, you can safely ignore this email.
|
|
281
|
-
</p>
|
|
282
|
-
</div>
|
|
283
|
-
</div>
|
|
284
|
-
</div>
|
|
285
|
-
</body>
|
|
286
|
-
</html>
|
|
287
|
-
`.trim();
|
|
288
|
-
|
|
289
|
-
const text = `
|
|
290
|
-
Welcome to ${appName}!
|
|
291
|
-
|
|
292
|
-
Hi ${greeting},
|
|
293
|
-
|
|
294
|
-
An account has been created for you on ${appName}.
|
|
295
|
-
|
|
296
|
-
Click this link to set your password and get started:
|
|
297
|
-
${setPasswordUrl}
|
|
298
|
-
|
|
299
|
-
This link will expire in 1 hour for security reasons.
|
|
300
|
-
|
|
301
|
-
If you weren't expecting this invitation, you can safely ignore this email.
|
|
302
|
-
`.trim();
|
|
303
|
-
|
|
304
|
-
return { subject,
|
|
305
|
-
html,
|
|
306
|
-
text };
|
|
307
|
-
}
|
|
308
|
-
|
|
309
|
-
/**
|
|
310
|
-
* Default welcome email template
|
|
311
|
-
* Sent automatically when a new user registers
|
|
312
|
-
*/
|
|
313
|
-
export function getWelcomeEmailTemplate(
|
|
314
|
-
user: TemplateUser,
|
|
315
|
-
appName = "Rebase",
|
|
316
|
-
loginUrl?: string
|
|
317
|
-
): { subject: string; html: string; text: string } {
|
|
318
|
-
const greeting = getGreeting(user);
|
|
319
|
-
const url = loginUrl || "";
|
|
320
|
-
|
|
321
|
-
const subject = `¡Bienvenido/a a ${appName}!`;
|
|
322
|
-
|
|
323
|
-
const html = `
|
|
324
|
-
<!DOCTYPE html>
|
|
325
|
-
<html>
|
|
326
|
-
<head>
|
|
327
|
-
<meta charset="utf-8">
|
|
328
|
-
<meta name="viewport" content="width=device-width, initial-scale=1.0">
|
|
329
|
-
<title>${subject}</title>
|
|
330
|
-
</head>
|
|
331
|
-
<body style="margin: 0; padding: 0; background-color: #f8fafc;">
|
|
332
|
-
<div style="${styles.container}">
|
|
333
|
-
<div style="${styles.card}">
|
|
334
|
-
<h1 style="${styles.heading}">¡Bienvenido/a a ${appName}!</h1>
|
|
335
|
-
|
|
336
|
-
<p style="${styles.paragraph}">
|
|
337
|
-
Hola ${greeting},
|
|
338
|
-
</p>
|
|
339
|
-
|
|
340
|
-
<p style="${styles.paragraph}">
|
|
341
|
-
Tu cuenta en ${appName} ha sido creada exitosamente.
|
|
342
|
-
Estamos encantados de tenerte con nosotros.
|
|
343
|
-
</p>
|
|
344
|
-
|
|
345
|
-
<p style="${styles.paragraph}">
|
|
346
|
-
Ya puedes acceder a tu panel y empezar a explorar todas las oportunidades
|
|
347
|
-
que tenemos para ti.
|
|
348
|
-
</p>
|
|
349
|
-
|
|
350
|
-
${url ? `
|
|
351
|
-
<div style="text-align: center;">
|
|
352
|
-
<a href="${url}" style="${styles.button}">Ir a mi Panel</a>
|
|
353
|
-
</div>
|
|
354
|
-
` : ""}
|
|
355
|
-
|
|
356
|
-
<p style="${styles.paragraph}">
|
|
357
|
-
Si tienes alguna pregunta, no dudes en contactarnos respondiendo a este correo.
|
|
358
|
-
</p>
|
|
359
|
-
|
|
360
|
-
<div style="${styles.footer}">
|
|
361
|
-
<p style="margin: 0;">
|
|
362
|
-
Este correo fue enviado porque se creó una cuenta con esta dirección de email en ${appName}.
|
|
363
|
-
</p>
|
|
364
|
-
</div>
|
|
365
|
-
</div>
|
|
366
|
-
</div>
|
|
367
|
-
</body>
|
|
368
|
-
</html>
|
|
369
|
-
`.trim();
|
|
370
|
-
|
|
371
|
-
const text = `
|
|
372
|
-
¡Bienvenido/a a ${appName}!
|
|
373
|
-
|
|
374
|
-
Hola ${greeting},
|
|
375
|
-
|
|
376
|
-
Tu cuenta en ${appName} ha sido creada exitosamente. Estamos encantados de tenerte con nosotros.
|
|
377
|
-
|
|
378
|
-
Ya puedes acceder a tu panel y empezar a explorar todas las oportunidades que tenemos para ti.
|
|
379
|
-
|
|
380
|
-
${url ? `Ir a mi panel: ${url}` : ""}
|
|
381
|
-
|
|
382
|
-
Si tienes alguna pregunta, no dudes en contactarnos respondiendo a este correo.
|
|
383
|
-
`.trim();
|
|
384
|
-
|
|
385
|
-
return { subject,
|
|
386
|
-
html,
|
|
387
|
-
text };
|
|
388
|
-
}
|
|
389
|
-
|
|
390
|
-
/**
|
|
391
|
-
* Default magic link email template
|
|
392
|
-
*/
|
|
393
|
-
export function getMagicLinkTemplate(
|
|
394
|
-
magicLinkUrl: string,
|
|
395
|
-
user: TemplateUser,
|
|
396
|
-
appName = "Rebase"
|
|
397
|
-
): { subject: string; html: string; text: string } {
|
|
398
|
-
const greeting = getGreeting(user);
|
|
399
|
-
|
|
400
|
-
const subject = `Sign in to ${appName}`;
|
|
401
|
-
|
|
402
|
-
const html = `
|
|
403
|
-
<!DOCTYPE html>
|
|
404
|
-
<html>
|
|
405
|
-
<head>
|
|
406
|
-
<meta charset="utf-8">
|
|
407
|
-
<meta name="viewport" content="width=device-width, initial-scale=1.0">
|
|
408
|
-
<title>${subject}</title>
|
|
409
|
-
</head>
|
|
410
|
-
<body style="margin: 0; padding: 0; background-color: #f8fafc;">
|
|
411
|
-
<div style="${styles.container}">
|
|
412
|
-
<div style="${styles.card}">
|
|
413
|
-
<h1 style="${styles.heading}">Sign In to ${appName}</h1>
|
|
414
|
-
|
|
415
|
-
<p style="${styles.paragraph}">
|
|
416
|
-
Hi ${greeting},
|
|
417
|
-
</p>
|
|
418
|
-
|
|
419
|
-
<p style="${styles.paragraph}">
|
|
420
|
-
We received a request to sign in to your ${appName} account.
|
|
421
|
-
Click the button below to log in:
|
|
422
|
-
</p>
|
|
423
|
-
|
|
424
|
-
<div style="text-align: center;">
|
|
425
|
-
<a href="${magicLinkUrl}" style="${styles.button}">Sign In</a>
|
|
426
|
-
</div>
|
|
427
|
-
|
|
428
|
-
<p style="${styles.paragraph}">
|
|
429
|
-
Or copy and paste this link into your browser:
|
|
430
|
-
</p>
|
|
431
|
-
<p style="color: #3b82f6; word-break: break-all; font-size: 14px;">
|
|
432
|
-
${magicLinkUrl}
|
|
433
|
-
</p>
|
|
434
|
-
|
|
435
|
-
<div style="${styles.warning}">
|
|
436
|
-
⏰ This link will expire in 15 minutes for security reasons and can only be used once.
|
|
437
|
-
</div>
|
|
438
|
-
|
|
439
|
-
<div style="${styles.footer}">
|
|
440
|
-
<p style="margin: 0;">
|
|
441
|
-
If you didn't request this sign-in link, you can safely ignore this email.
|
|
442
|
-
No action is needed.
|
|
443
|
-
</p>
|
|
444
|
-
</div>
|
|
445
|
-
</div>
|
|
446
|
-
</div>
|
|
447
|
-
</body>
|
|
448
|
-
</html>
|
|
449
|
-
`.trim();
|
|
450
|
-
|
|
451
|
-
const text = `
|
|
452
|
-
Sign In to ${appName}
|
|
453
|
-
|
|
454
|
-
Hi ${greeting},
|
|
455
|
-
|
|
456
|
-
We received a request to sign in to your ${appName} account.
|
|
457
|
-
|
|
458
|
-
Click this link to log in:
|
|
459
|
-
${magicLinkUrl}
|
|
460
|
-
|
|
461
|
-
This link will expire in 15 minutes for security reasons and can only be used once.
|
|
462
|
-
|
|
463
|
-
If you didn't request this sign-in link, you can safely ignore this email.
|
|
464
|
-
No action is needed.
|
|
465
|
-
`.trim();
|
|
466
|
-
|
|
467
|
-
return { subject,
|
|
468
|
-
html,
|
|
469
|
-
text };
|
|
470
|
-
}
|
package/src/env.ts
DELETED
|
@@ -1,227 +0,0 @@
|
|
|
1
|
-
import { z } from "zod";
|
|
2
|
-
import * as crypto from "crypto";
|
|
3
|
-
import { logger } from "./utils/logger";
|
|
4
|
-
|
|
5
|
-
/**
|
|
6
|
-
* Generate a cryptographically secure random secret (hex-encoded).
|
|
7
|
-
* Used as a fallback when secrets are not explicitly configured —
|
|
8
|
-
* avoids the need for hardcoded dev secrets.
|
|
9
|
-
*/
|
|
10
|
-
function generateSecret(bytes = 48): string {
|
|
11
|
-
return crypto.randomBytes(bytes).toString("hex");
|
|
12
|
-
}
|
|
13
|
-
|
|
14
|
-
/**
|
|
15
|
-
* Zod coercion helper: transforms `"true"` → `true`, everything else → `false`.
|
|
16
|
-
*/
|
|
17
|
-
const boolString = z.enum(["true", "false", ""]).default("false").transform(v => v === "true");
|
|
18
|
-
|
|
19
|
-
/**
|
|
20
|
-
* Zod coercion helper for optional boolean strings.
|
|
21
|
-
*/
|
|
22
|
-
const optionalBoolString = z.enum(["true", "false", ""]).optional().transform(v => v === "true");
|
|
23
|
-
|
|
24
|
-
/**
|
|
25
|
-
* Helper to determine if a string is a localhost or loopback address/URL.
|
|
26
|
-
*/
|
|
27
|
-
function isLocalhostOrLoopback(value: string): boolean {
|
|
28
|
-
const trimmed = value.trim();
|
|
29
|
-
if (!trimmed) return false;
|
|
30
|
-
|
|
31
|
-
// 1. Try parsing as URL
|
|
32
|
-
try {
|
|
33
|
-
const parsed = new URL(trimmed);
|
|
34
|
-
const host = parsed.hostname.toLowerCase();
|
|
35
|
-
if (
|
|
36
|
-
host === "localhost" ||
|
|
37
|
-
host === "127.0.0.1" ||
|
|
38
|
-
host === "::1" ||
|
|
39
|
-
host.startsWith("127.")
|
|
40
|
-
) {
|
|
41
|
-
return true;
|
|
42
|
-
}
|
|
43
|
-
} catch {
|
|
44
|
-
// Not a standard URL, or custom protocol that URL class fails to parse
|
|
45
|
-
}
|
|
46
|
-
|
|
47
|
-
// 2. Custom protocol parser fallback (e.g. postgres://, mongodb://, etc.)
|
|
48
|
-
const protocolMatch = trimmed.match(/^[a-zA-Z0-9+-.]+:\/\/(?:[^@/]+@)?(?:\[([^\]]+)\]|([^:/]+))/);
|
|
49
|
-
if (protocolMatch) {
|
|
50
|
-
const host = (protocolMatch[1] || protocolMatch[2] || "").toLowerCase();
|
|
51
|
-
if (
|
|
52
|
-
host === "localhost" ||
|
|
53
|
-
host === "127.0.0.1" ||
|
|
54
|
-
host === "::1" ||
|
|
55
|
-
host.startsWith("127.")
|
|
56
|
-
) {
|
|
57
|
-
return true;
|
|
58
|
-
}
|
|
59
|
-
}
|
|
60
|
-
|
|
61
|
-
// 3. Plain hostname / host:port checker (e.g. "localhost", "127.0.0.1:5432", "[::1]:6379")
|
|
62
|
-
let plainHost = trimmed.toLowerCase();
|
|
63
|
-
if (plainHost.startsWith("[") && plainHost.includes("]")) {
|
|
64
|
-
const endBracket = plainHost.indexOf("]");
|
|
65
|
-
plainHost = plainHost.slice(1, endBracket);
|
|
66
|
-
} else {
|
|
67
|
-
const colonIndex = plainHost.lastIndexOf(":");
|
|
68
|
-
if (colonIndex !== -1 && plainHost.indexOf(":") === colonIndex) {
|
|
69
|
-
plainHost = plainHost.substring(0, colonIndex);
|
|
70
|
-
}
|
|
71
|
-
}
|
|
72
|
-
|
|
73
|
-
if (
|
|
74
|
-
plainHost === "localhost" ||
|
|
75
|
-
plainHost === "127.0.0.1" ||
|
|
76
|
-
plainHost === "::1" ||
|
|
77
|
-
plainHost.startsWith("127.")
|
|
78
|
-
) {
|
|
79
|
-
return true;
|
|
80
|
-
}
|
|
81
|
-
|
|
82
|
-
return false;
|
|
83
|
-
}
|
|
84
|
-
|
|
85
|
-
/**
|
|
86
|
-
* The full set of environment variables recognized by a Rebase backend.
|
|
87
|
-
*/
|
|
88
|
-
const rebaseEnvSchema = z.object({
|
|
89
|
-
NODE_ENV: z.enum(["development", "production", "test"]).default("development"),
|
|
90
|
-
PORT: z.string().default("3001").transform(Number),
|
|
91
|
-
DATABASE_URL: z.string().url("DATABASE_URL must be a valid URL"),
|
|
92
|
-
ADMIN_CONNECTION_STRING: z.string().url().optional(),
|
|
93
|
-
JWT_SECRET: z.string().min(32, "JWT_SECRET must be at least 32 characters long"),
|
|
94
|
-
JWT_ACCESS_EXPIRES_IN: z.string().default("1h"),
|
|
95
|
-
JWT_REFRESH_EXPIRES_IN: z.string().default("30d"),
|
|
96
|
-
GOOGLE_CLIENT_ID: z.string().optional(),
|
|
97
|
-
GOOGLE_CLIENT_SECRET: z.string().optional(),
|
|
98
|
-
REBASE_SERVICE_KEY: z.string().optional(),
|
|
99
|
-
ALLOW_REGISTRATION: boolString,
|
|
100
|
-
ALLOW_LOCALHOST_IN_PRODUCTION: optionalBoolString,
|
|
101
|
-
CORS_ORIGINS: z.string().optional(),
|
|
102
|
-
FRONTEND_URL: z.string().optional(),
|
|
103
|
-
DB_POOL_MAX: z.string().default("20").transform(Number),
|
|
104
|
-
DB_POOL_IDLE_TIMEOUT: z.string().default("30000").transform(Number),
|
|
105
|
-
DB_POOL_CONNECT_TIMEOUT: z.string().default("10000").transform(Number),
|
|
106
|
-
DATABASE_DIRECT_URL: z.string().url().optional(),
|
|
107
|
-
DATABASE_READ_URL: z.string().url().optional(),
|
|
108
|
-
FORCE_LOCAL_STORAGE: optionalBoolString,
|
|
109
|
-
STORAGE_TYPE: z.enum(["local", "s3"]).default("local"),
|
|
110
|
-
STORAGE_PATH: z.string().optional(),
|
|
111
|
-
S3_BUCKET: z.string().optional(),
|
|
112
|
-
S3_REGION: z.string().optional(),
|
|
113
|
-
S3_ACCESS_KEY_ID: z.string().optional(),
|
|
114
|
-
S3_SECRET_ACCESS_KEY: z.string().optional(),
|
|
115
|
-
S3_ENDPOINT: z.string().url().optional(),
|
|
116
|
-
S3_FORCE_PATH_STYLE: optionalBoolString
|
|
117
|
-
});
|
|
118
|
-
|
|
119
|
-
/** Inferred type of the validated environment. */
|
|
120
|
-
export type RebaseEnv = z.infer<typeof rebaseEnvSchema>;
|
|
121
|
-
|
|
122
|
-
/**
|
|
123
|
-
* Load and validate the Rebase environment configuration from `process.env`.
|
|
124
|
-
*
|
|
125
|
-
* Call this **after** your `.env` file has been loaded (via `dotenv`, `--env-file`,
|
|
126
|
-
* container injection, etc.). This function does not load `.env` files itself —
|
|
127
|
-
* that is a deployment concern, not a framework concern.
|
|
128
|
-
*
|
|
129
|
-
* Behavior:
|
|
130
|
-
* - Auto-generates ephemeral `JWT_SECRET` and `REBASE_SERVICE_KEY` in
|
|
131
|
-
* non-production mode so developers can start without manual setup.
|
|
132
|
-
* - Blocks auto-generated secrets in production.
|
|
133
|
-
* - Returns a fully typed, validated env object.
|
|
134
|
-
*
|
|
135
|
-
* Use `extend` to add your own typed env variables on top of the base Rebase schema:
|
|
136
|
-
*
|
|
137
|
-
* @example
|
|
138
|
-
* ```ts
|
|
139
|
-
* import dotenv from "dotenv";
|
|
140
|
-
* import { z } from "zod";
|
|
141
|
-
* import { loadEnv } from "@rebasepro/server-core";
|
|
142
|
-
*
|
|
143
|
-
* dotenv.config({ path: "../../.env" });
|
|
144
|
-
*
|
|
145
|
-
* // Basic — just Rebase env vars:
|
|
146
|
-
* export const env = loadEnv();
|
|
147
|
-
*
|
|
148
|
-
* // Extended — add your own typed vars:
|
|
149
|
-
* export const env = loadEnv({
|
|
150
|
-
* extend: z.object({
|
|
151
|
-
* SMTP_HOST: z.string().optional(),
|
|
152
|
-
* SMTP_PORT: z.string().default("587").transform(Number),
|
|
153
|
-
* STRIPE_SECRET_KEY: z.string(),
|
|
154
|
-
* })
|
|
155
|
-
* });
|
|
156
|
-
* // env.SMTP_HOST → string | undefined (fully typed)
|
|
157
|
-
* // env.STRIPE_SECRET_KEY → string (validated, required)
|
|
158
|
-
* ```
|
|
159
|
-
*/
|
|
160
|
-
export function loadEnv(): RebaseEnv;
|
|
161
|
-
export function loadEnv<E extends z.ZodObject<z.ZodRawShape>>(options: { extend: E }): RebaseEnv & z.infer<E>;
|
|
162
|
-
export function loadEnv(options?: { extend?: z.ZodObject<z.ZodRawShape> }): Record<string, unknown> {
|
|
163
|
-
// Auto-generate dev secrets before validation so the Zod schema sees valid values.
|
|
164
|
-
const isProduction = process.env.NODE_ENV === "production";
|
|
165
|
-
const autoGeneratedSecrets: string[] = [];
|
|
166
|
-
|
|
167
|
-
if (!isProduction) {
|
|
168
|
-
if (!process.env.JWT_SECRET) {
|
|
169
|
-
process.env.JWT_SECRET = generateSecret();
|
|
170
|
-
autoGeneratedSecrets.push("JWT_SECRET");
|
|
171
|
-
}
|
|
172
|
-
if (!process.env.REBASE_SERVICE_KEY) {
|
|
173
|
-
process.env.REBASE_SERVICE_KEY = generateSecret();
|
|
174
|
-
autoGeneratedSecrets.push("REBASE_SERVICE_KEY");
|
|
175
|
-
}
|
|
176
|
-
}
|
|
177
|
-
|
|
178
|
-
// Merge base schema with user extensions (if provided).
|
|
179
|
-
const combinedSchema = options?.extend
|
|
180
|
-
? rebaseEnvSchema.merge(options.extend)
|
|
181
|
-
: rebaseEnvSchema;
|
|
182
|
-
|
|
183
|
-
// Validate with production-specific refinements.
|
|
184
|
-
const schema = combinedSchema.superRefine((data, ctx) => {
|
|
185
|
-
const d = data as RebaseEnv & Record<string, unknown>;
|
|
186
|
-
if (d.NODE_ENV === "production" && !d.CORS_ORIGINS && !d.FRONTEND_URL) {
|
|
187
|
-
ctx.addIssue({
|
|
188
|
-
code: z.ZodIssueCode.custom,
|
|
189
|
-
message: "CORS_ORIGINS or FRONTEND_URL must be set in production to secure the API.",
|
|
190
|
-
path: ["CORS_ORIGINS"]
|
|
191
|
-
});
|
|
192
|
-
}
|
|
193
|
-
if (d.NODE_ENV === "production" && autoGeneratedSecrets.length > 0) {
|
|
194
|
-
ctx.addIssue({
|
|
195
|
-
code: z.ZodIssueCode.custom,
|
|
196
|
-
message: `${autoGeneratedSecrets.join(", ")} must be explicitly set in production. ` +
|
|
197
|
-
"Do not rely on auto-generated secrets outside development.",
|
|
198
|
-
path: [autoGeneratedSecrets[0]]
|
|
199
|
-
});
|
|
200
|
-
}
|
|
201
|
-
if (d.NODE_ENV === "production" && !d.ALLOW_LOCALHOST_IN_PRODUCTION) {
|
|
202
|
-
for (const [key, value] of Object.entries(data)) {
|
|
203
|
-
if (key === "CORS_ORIGINS") continue;
|
|
204
|
-
if (typeof value === "string" && isLocalhostOrLoopback(value)) {
|
|
205
|
-
ctx.addIssue({
|
|
206
|
-
code: z.ZodIssueCode.custom,
|
|
207
|
-
message: `Environment variable ${key} contains a local/loopback URL or host "${value}". Deployed instances must not connect to localhost.`,
|
|
208
|
-
path: [key]
|
|
209
|
-
});
|
|
210
|
-
}
|
|
211
|
-
}
|
|
212
|
-
}
|
|
213
|
-
});
|
|
214
|
-
|
|
215
|
-
const env = schema.parse(process.env);
|
|
216
|
-
|
|
217
|
-
// Warn after successful parse so the server still starts in dev.
|
|
218
|
-
if (autoGeneratedSecrets.length > 0) {
|
|
219
|
-
logger.warn(
|
|
220
|
-
`⚠️ Auto-generated secrets for: ${autoGeneratedSecrets.join(", ")}. ` +
|
|
221
|
-
"These are ephemeral — existing tokens will be invalidated on restart. " +
|
|
222
|
-
"Set them explicitly in .env for persistent sessions."
|
|
223
|
-
);
|
|
224
|
-
}
|
|
225
|
-
|
|
226
|
-
return env as Record<string, unknown>;
|
|
227
|
-
}
|