@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
|
@@ -1,282 +0,0 @@
|
|
|
1
|
-
import {
|
|
2
|
-
DriverRegistry,
|
|
3
|
-
DefaultDriverRegistry,
|
|
4
|
-
DEFAULT_DRIVER_ID
|
|
5
|
-
} from "../src/services/driver-registry";
|
|
6
|
-
import { DataDriver } from "@rebasepro/types";
|
|
7
|
-
|
|
8
|
-
/**
|
|
9
|
-
* Mock DataDriver for testing
|
|
10
|
-
*/
|
|
11
|
-
function createMockDataDriverDelegate(key: string): DataDriver {
|
|
12
|
-
return {
|
|
13
|
-
key,
|
|
14
|
-
initialised: true,
|
|
15
|
-
fetchCollection: jest.fn().mockResolvedValue([]),
|
|
16
|
-
fetchEntity: jest.fn().mockResolvedValue(undefined),
|
|
17
|
-
saveEntity: jest.fn().mockResolvedValue({ id: "test-id",
|
|
18
|
-
path: "test",
|
|
19
|
-
values: {} }),
|
|
20
|
-
deleteEntity: jest.fn().mockResolvedValue(undefined),
|
|
21
|
-
checkUniqueField: jest.fn().mockResolvedValue(true)
|
|
22
|
-
};
|
|
23
|
-
}
|
|
24
|
-
|
|
25
|
-
describe("DriverRegistry", () => {
|
|
26
|
-
describe("DEFAULT_DRIVER_ID", () => {
|
|
27
|
-
it("should be '(default)'", () => {
|
|
28
|
-
expect(DEFAULT_DRIVER_ID).toBe("(default)");
|
|
29
|
-
});
|
|
30
|
-
});
|
|
31
|
-
|
|
32
|
-
describe("DefaultDriverRegistry", () => {
|
|
33
|
-
describe("constructor and basic operations", () => {
|
|
34
|
-
it("should create an empty registry", () => {
|
|
35
|
-
const registry = new DefaultDriverRegistry();
|
|
36
|
-
expect(registry.size()).toBe(0);
|
|
37
|
-
expect(registry.list()).toEqual([]);
|
|
38
|
-
});
|
|
39
|
-
|
|
40
|
-
it("should register a driver", () => {
|
|
41
|
-
const registry = new DefaultDriverRegistry();
|
|
42
|
-
const mockDelegate = createMockDataDriverDelegate("postgres");
|
|
43
|
-
|
|
44
|
-
registry.register("test-db", mockDelegate);
|
|
45
|
-
|
|
46
|
-
expect(registry.has("test-db")).toBe(true);
|
|
47
|
-
expect(registry.size()).toBe(1);
|
|
48
|
-
expect(registry.list()).toContain("test-db");
|
|
49
|
-
});
|
|
50
|
-
|
|
51
|
-
it("should get a registered driver", () => {
|
|
52
|
-
const registry = new DefaultDriverRegistry();
|
|
53
|
-
const mockDelegate = createMockDataDriverDelegate("postgres");
|
|
54
|
-
|
|
55
|
-
registry.register("my-db", mockDelegate);
|
|
56
|
-
|
|
57
|
-
const retrieved = registry.get("my-db");
|
|
58
|
-
expect(retrieved).toBe(mockDelegate);
|
|
59
|
-
});
|
|
60
|
-
|
|
61
|
-
it("should return undefined for non-existent driver", () => {
|
|
62
|
-
const registry = new DefaultDriverRegistry();
|
|
63
|
-
expect(registry.get("non-existent")).toBeUndefined();
|
|
64
|
-
});
|
|
65
|
-
});
|
|
66
|
-
|
|
67
|
-
describe("default driver handling", () => {
|
|
68
|
-
it("should get default driver with get(undefined)", () => {
|
|
69
|
-
const registry = new DefaultDriverRegistry();
|
|
70
|
-
const mockDelegate = createMockDataDriverDelegate("postgres");
|
|
71
|
-
|
|
72
|
-
registry.register(DEFAULT_DRIVER_ID, mockDelegate);
|
|
73
|
-
|
|
74
|
-
expect(registry.get(undefined)).toBe(mockDelegate);
|
|
75
|
-
expect(registry.get(null)).toBe(mockDelegate);
|
|
76
|
-
});
|
|
77
|
-
|
|
78
|
-
it("should get default driver with getDefault()", () => {
|
|
79
|
-
const registry = new DefaultDriverRegistry();
|
|
80
|
-
const mockDelegate = createMockDataDriverDelegate("postgres");
|
|
81
|
-
|
|
82
|
-
registry.register(DEFAULT_DRIVER_ID, mockDelegate);
|
|
83
|
-
|
|
84
|
-
expect(registry.getDefault()).toBe(mockDelegate);
|
|
85
|
-
});
|
|
86
|
-
|
|
87
|
-
it("should throw error when no default driver exists", () => {
|
|
88
|
-
const registry = new DefaultDriverRegistry();
|
|
89
|
-
|
|
90
|
-
expect(() => registry.getDefault()).toThrow(
|
|
91
|
-
"[DriverRegistry] No default driver registered."
|
|
92
|
-
);
|
|
93
|
-
});
|
|
94
|
-
});
|
|
95
|
-
|
|
96
|
-
describe("getOrDefault", () => {
|
|
97
|
-
let registry: DefaultDriverRegistry;
|
|
98
|
-
let defaultDelegate: DataDriver;
|
|
99
|
-
let analyticsDelegate: DataDriver;
|
|
100
|
-
|
|
101
|
-
beforeEach(() => {
|
|
102
|
-
registry = new DefaultDriverRegistry();
|
|
103
|
-
defaultDelegate = createMockDataDriverDelegate("default-postgres");
|
|
104
|
-
analyticsDelegate = createMockDataDriverDelegate("analytics-postgres");
|
|
105
|
-
|
|
106
|
-
registry.register(DEFAULT_DRIVER_ID, defaultDelegate);
|
|
107
|
-
registry.register("analytics", analyticsDelegate);
|
|
108
|
-
});
|
|
109
|
-
|
|
110
|
-
it("should return specific driver when found", () => {
|
|
111
|
-
expect(registry.getOrDefault("analytics")).toBe(analyticsDelegate);
|
|
112
|
-
});
|
|
113
|
-
|
|
114
|
-
it("should return default when id is undefined", () => {
|
|
115
|
-
expect(registry.getOrDefault(undefined)).toBe(defaultDelegate);
|
|
116
|
-
});
|
|
117
|
-
|
|
118
|
-
it("should return default when id is null", () => {
|
|
119
|
-
expect(registry.getOrDefault(null)).toBe(defaultDelegate);
|
|
120
|
-
});
|
|
121
|
-
|
|
122
|
-
it("should fallback to default when id not found", () => {
|
|
123
|
-
// This should log a warning and return the default
|
|
124
|
-
const consoleSpy = jest.spyOn(console, "warn").mockImplementation();
|
|
125
|
-
|
|
126
|
-
expect(registry.getOrDefault("non-existent")).toBe(defaultDelegate);
|
|
127
|
-
expect(consoleSpy).toHaveBeenCalledWith(
|
|
128
|
-
expect.stringContaining('Driver "non-existent" not found')
|
|
129
|
-
);
|
|
130
|
-
|
|
131
|
-
consoleSpy.mockRestore();
|
|
132
|
-
});
|
|
133
|
-
|
|
134
|
-
it("should throw when fallback fails (no default)", () => {
|
|
135
|
-
const emptyRegistry = new DefaultDriverRegistry();
|
|
136
|
-
|
|
137
|
-
expect(() => emptyRegistry.getOrDefault("anything")).toThrow();
|
|
138
|
-
});
|
|
139
|
-
});
|
|
140
|
-
|
|
141
|
-
describe("overwriting drivers", () => {
|
|
142
|
-
it("should overwrite existing driver with same id", () => {
|
|
143
|
-
const registry = new DefaultDriverRegistry();
|
|
144
|
-
const original = createMockDataDriverDelegate("original");
|
|
145
|
-
const replacement = createMockDataDriverDelegate("replacement");
|
|
146
|
-
|
|
147
|
-
const consoleSpy = jest.spyOn(console, "warn").mockImplementation();
|
|
148
|
-
|
|
149
|
-
registry.register("my-db", original);
|
|
150
|
-
registry.register("my-db", replacement);
|
|
151
|
-
|
|
152
|
-
expect(registry.get("my-db")).toBe(replacement);
|
|
153
|
-
expect(consoleSpy).toHaveBeenCalledWith(
|
|
154
|
-
expect.stringContaining('Overwriting driver with id "my-db"')
|
|
155
|
-
);
|
|
156
|
-
|
|
157
|
-
consoleSpy.mockRestore();
|
|
158
|
-
});
|
|
159
|
-
});
|
|
160
|
-
|
|
161
|
-
describe("list and size", () => {
|
|
162
|
-
it("should list all registered drivers", () => {
|
|
163
|
-
const registry = new DefaultDriverRegistry();
|
|
164
|
-
|
|
165
|
-
registry.register("db-1", createMockDataDriverDelegate("pg1"));
|
|
166
|
-
registry.register("db-2", createMockDataDriverDelegate("pg2"));
|
|
167
|
-
registry.register(DEFAULT_DRIVER_ID, createMockDataDriverDelegate("default"));
|
|
168
|
-
|
|
169
|
-
const list = registry.list();
|
|
170
|
-
expect(list).toHaveLength(3);
|
|
171
|
-
expect(list).toContain("db-1");
|
|
172
|
-
expect(list).toContain("db-2");
|
|
173
|
-
expect(list).toContain(DEFAULT_DRIVER_ID);
|
|
174
|
-
});
|
|
175
|
-
|
|
176
|
-
it("should return correct size", () => {
|
|
177
|
-
const registry = new DefaultDriverRegistry();
|
|
178
|
-
|
|
179
|
-
expect(registry.size()).toBe(0);
|
|
180
|
-
|
|
181
|
-
registry.register("db-1", createMockDataDriverDelegate("pg1"));
|
|
182
|
-
expect(registry.size()).toBe(1);
|
|
183
|
-
|
|
184
|
-
registry.register("db-2", createMockDataDriverDelegate("pg2"));
|
|
185
|
-
expect(registry.size()).toBe(2);
|
|
186
|
-
});
|
|
187
|
-
});
|
|
188
|
-
});
|
|
189
|
-
|
|
190
|
-
describe("DefaultDriverRegistry.create() factory", () => {
|
|
191
|
-
describe("with single DataDriver", () => {
|
|
192
|
-
it('should register single delegate as "(default)"', () => {
|
|
193
|
-
const mockDelegate = createMockDataDriverDelegate("postgres");
|
|
194
|
-
|
|
195
|
-
const registry = DefaultDriverRegistry.create(mockDelegate);
|
|
196
|
-
|
|
197
|
-
expect(registry.has(DEFAULT_DRIVER_ID)).toBe(true);
|
|
198
|
-
expect(registry.getDefault()).toBe(mockDelegate);
|
|
199
|
-
expect(registry.size()).toBe(1);
|
|
200
|
-
});
|
|
201
|
-
});
|
|
202
|
-
|
|
203
|
-
describe("with map of DataDriverDelegates", () => {
|
|
204
|
-
it("should register all delegates from map", () => {
|
|
205
|
-
const defaultDelegate = createMockDataDriverDelegate("default-pg");
|
|
206
|
-
const analyticsDelegate = createMockDataDriverDelegate("analytics-pg");
|
|
207
|
-
|
|
208
|
-
const registry = DefaultDriverRegistry.create({
|
|
209
|
-
[DEFAULT_DRIVER_ID]: defaultDelegate,
|
|
210
|
-
"analytics": analyticsDelegate
|
|
211
|
-
});
|
|
212
|
-
|
|
213
|
-
expect(registry.size()).toBe(2);
|
|
214
|
-
expect(registry.getDefault()).toBe(defaultDelegate);
|
|
215
|
-
expect(registry.get("analytics")).toBe(analyticsDelegate);
|
|
216
|
-
});
|
|
217
|
-
|
|
218
|
-
it("should use first entry as default if no explicit default provided", () => {
|
|
219
|
-
const db1 = createMockDataDriverDelegate("db1");
|
|
220
|
-
const db2 = createMockDataDriverDelegate("db2");
|
|
221
|
-
|
|
222
|
-
const consoleSpy = jest.spyOn(console, "warn").mockImplementation();
|
|
223
|
-
|
|
224
|
-
const registry = DefaultDriverRegistry.create({
|
|
225
|
-
"primary": db1,
|
|
226
|
-
"secondary": db2
|
|
227
|
-
});
|
|
228
|
-
|
|
229
|
-
// Should have registered both + created default pointing to first
|
|
230
|
-
expect(registry.size()).toBe(3); // primary, secondary, (default)
|
|
231
|
-
expect(registry.has(DEFAULT_DRIVER_ID)).toBe(true);
|
|
232
|
-
expect(consoleSpy).toHaveBeenCalledWith(
|
|
233
|
-
expect.stringContaining('No "(default)" driver provided')
|
|
234
|
-
);
|
|
235
|
-
|
|
236
|
-
consoleSpy.mockRestore();
|
|
237
|
-
});
|
|
238
|
-
|
|
239
|
-
it("should handle empty map gracefully", () => {
|
|
240
|
-
const registry = DefaultDriverRegistry.create({});
|
|
241
|
-
|
|
242
|
-
expect(registry.size()).toBe(0);
|
|
243
|
-
expect(() => registry.getDefault()).toThrow();
|
|
244
|
-
});
|
|
245
|
-
});
|
|
246
|
-
});
|
|
247
|
-
|
|
248
|
-
describe("type detection (isDataDriverDelegate)", () => {
|
|
249
|
-
it("should correctly identify a DataDriver", () => {
|
|
250
|
-
const mockDelegate = createMockDataDriverDelegate("postgres");
|
|
251
|
-
|
|
252
|
-
// The factory should recognize it as a single delegate
|
|
253
|
-
const registry = DefaultDriverRegistry.create(mockDelegate);
|
|
254
|
-
expect(registry.size()).toBe(1);
|
|
255
|
-
expect(registry.has(DEFAULT_DRIVER_ID)).toBe(true);
|
|
256
|
-
});
|
|
257
|
-
|
|
258
|
-
it("should correctly identify a map of DataDriverDelegates", () => {
|
|
259
|
-
const delegates = {
|
|
260
|
-
[DEFAULT_DRIVER_ID]: createMockDataDriverDelegate("pg1"),
|
|
261
|
-
"other": createMockDataDriverDelegate("pg2")
|
|
262
|
-
};
|
|
263
|
-
|
|
264
|
-
// The factory should recognize it as a map
|
|
265
|
-
const registry = DefaultDriverRegistry.create(delegates);
|
|
266
|
-
expect(registry.size()).toBe(2);
|
|
267
|
-
});
|
|
268
|
-
|
|
269
|
-
it("should not mistakenly identify a map as a single delegate", () => {
|
|
270
|
-
// A map doesn't have the required DataDriver methods
|
|
271
|
-
const map = {
|
|
272
|
-
key: "not-a-delegate", // This looks like the key property but...
|
|
273
|
-
db1: createMockDataDriverDelegate("pg1")
|
|
274
|
-
};
|
|
275
|
-
|
|
276
|
-
// This should be treated as a map (and show a warning because 'key' isn't a valid delegate)
|
|
277
|
-
const registry = DefaultDriverRegistry.create(map as any);
|
|
278
|
-
// 'key' entry will be ignored since it's not a valid delegate
|
|
279
|
-
expect(registry.has("db1")).toBe(true);
|
|
280
|
-
});
|
|
281
|
-
});
|
|
282
|
-
});
|
|
@@ -1,174 +0,0 @@
|
|
|
1
|
-
import {
|
|
2
|
-
getPasswordResetTemplate,
|
|
3
|
-
getEmailVerificationTemplate,
|
|
4
|
-
getUserInvitationTemplate,
|
|
5
|
-
getWelcomeEmailTemplate
|
|
6
|
-
} from "../src/email/templates";
|
|
7
|
-
|
|
8
|
-
describe("getPasswordResetTemplate", () => {
|
|
9
|
-
const user = { email: "john@example.com",
|
|
10
|
-
displayName: "John Doe" };
|
|
11
|
-
const resetUrl = "https://example.com/reset?token=abc123";
|
|
12
|
-
|
|
13
|
-
it("returns subject, html, and text", () => {
|
|
14
|
-
const result = getPasswordResetTemplate(resetUrl, user);
|
|
15
|
-
expect(result.subject).toBeTruthy();
|
|
16
|
-
expect(result.html).toBeTruthy();
|
|
17
|
-
expect(result.text).toBeTruthy();
|
|
18
|
-
});
|
|
19
|
-
|
|
20
|
-
it("subject includes default app name", () => {
|
|
21
|
-
const result = getPasswordResetTemplate(resetUrl, user);
|
|
22
|
-
expect(result.subject).toContain("Rebase");
|
|
23
|
-
});
|
|
24
|
-
|
|
25
|
-
it("subject includes custom app name", () => {
|
|
26
|
-
const result = getPasswordResetTemplate(resetUrl, user, "MyApp");
|
|
27
|
-
expect(result.subject).toContain("MyApp");
|
|
28
|
-
});
|
|
29
|
-
|
|
30
|
-
it("html contains the reset URL", () => {
|
|
31
|
-
const result = getPasswordResetTemplate(resetUrl, user);
|
|
32
|
-
expect(result.html).toContain(resetUrl);
|
|
33
|
-
});
|
|
34
|
-
|
|
35
|
-
it("text contains the reset URL", () => {
|
|
36
|
-
const result = getPasswordResetTemplate(resetUrl, user);
|
|
37
|
-
expect(result.text).toContain(resetUrl);
|
|
38
|
-
});
|
|
39
|
-
|
|
40
|
-
it("uses displayName for greeting", () => {
|
|
41
|
-
const result = getPasswordResetTemplate(resetUrl, user);
|
|
42
|
-
expect(result.html).toContain("John Doe");
|
|
43
|
-
expect(result.text).toContain("John Doe");
|
|
44
|
-
});
|
|
45
|
-
|
|
46
|
-
it("falls back to email prefix when displayName is null", () => {
|
|
47
|
-
const userNoName = { email: "jane@example.com",
|
|
48
|
-
displayName: null };
|
|
49
|
-
const result = getPasswordResetTemplate(resetUrl, userNoName);
|
|
50
|
-
expect(result.html).toContain("jane");
|
|
51
|
-
expect(result.text).toContain("jane");
|
|
52
|
-
});
|
|
53
|
-
|
|
54
|
-
it("html contains DOCTYPE and body tags", () => {
|
|
55
|
-
const result = getPasswordResetTemplate(resetUrl, user);
|
|
56
|
-
expect(result.html).toContain("<!DOCTYPE html>");
|
|
57
|
-
expect(result.html).toContain("<body");
|
|
58
|
-
expect(result.html).toContain("</body>");
|
|
59
|
-
});
|
|
60
|
-
});
|
|
61
|
-
|
|
62
|
-
describe("getEmailVerificationTemplate", () => {
|
|
63
|
-
const user = { email: "alice@example.com",
|
|
64
|
-
displayName: "Alice" };
|
|
65
|
-
const verifyUrl = "https://example.com/verify?token=xyz789";
|
|
66
|
-
|
|
67
|
-
it("returns subject, html, and text", () => {
|
|
68
|
-
const result = getEmailVerificationTemplate(verifyUrl, user);
|
|
69
|
-
expect(result.subject).toBeTruthy();
|
|
70
|
-
expect(result.html).toBeTruthy();
|
|
71
|
-
expect(result.text).toBeTruthy();
|
|
72
|
-
});
|
|
73
|
-
|
|
74
|
-
it("subject mentions email verification", () => {
|
|
75
|
-
const result = getEmailVerificationTemplate(verifyUrl, user);
|
|
76
|
-
expect(result.subject.toLowerCase()).toContain("verify");
|
|
77
|
-
});
|
|
78
|
-
|
|
79
|
-
it("html contains the verification URL", () => {
|
|
80
|
-
const result = getEmailVerificationTemplate(verifyUrl, user);
|
|
81
|
-
expect(result.html).toContain(verifyUrl);
|
|
82
|
-
});
|
|
83
|
-
|
|
84
|
-
it("text contains the verification URL", () => {
|
|
85
|
-
const result = getEmailVerificationTemplate(verifyUrl, user);
|
|
86
|
-
expect(result.text).toContain(verifyUrl);
|
|
87
|
-
});
|
|
88
|
-
|
|
89
|
-
it("uses displayName when available", () => {
|
|
90
|
-
const result = getEmailVerificationTemplate(verifyUrl, user);
|
|
91
|
-
expect(result.html).toContain("Alice");
|
|
92
|
-
});
|
|
93
|
-
|
|
94
|
-
it("uses custom app name", () => {
|
|
95
|
-
const result = getEmailVerificationTemplate(verifyUrl, user, "CustomApp");
|
|
96
|
-
expect(result.subject).toContain("CustomApp");
|
|
97
|
-
expect(result.html).toContain("CustomApp");
|
|
98
|
-
});
|
|
99
|
-
});
|
|
100
|
-
|
|
101
|
-
describe("getUserInvitationTemplate", () => {
|
|
102
|
-
const user = { email: "bob@example.com",
|
|
103
|
-
displayName: "Bob" };
|
|
104
|
-
const setPasswordUrl = "https://example.com/set-password?token=def456";
|
|
105
|
-
|
|
106
|
-
it("returns subject, html, and text", () => {
|
|
107
|
-
const result = getUserInvitationTemplate(setPasswordUrl, user);
|
|
108
|
-
expect(result.subject).toBeTruthy();
|
|
109
|
-
expect(result.html).toBeTruthy();
|
|
110
|
-
expect(result.text).toBeTruthy();
|
|
111
|
-
});
|
|
112
|
-
|
|
113
|
-
it("subject mentions invitation", () => {
|
|
114
|
-
const result = getUserInvitationTemplate(setPasswordUrl, user);
|
|
115
|
-
expect(result.subject.toLowerCase()).toContain("invited");
|
|
116
|
-
});
|
|
117
|
-
|
|
118
|
-
it("html contains the set password URL", () => {
|
|
119
|
-
const result = getUserInvitationTemplate(setPasswordUrl, user);
|
|
120
|
-
expect(result.html).toContain(setPasswordUrl);
|
|
121
|
-
});
|
|
122
|
-
|
|
123
|
-
it("text contains the set password URL", () => {
|
|
124
|
-
const result = getUserInvitationTemplate(setPasswordUrl, user);
|
|
125
|
-
expect(result.text).toContain(setPasswordUrl);
|
|
126
|
-
});
|
|
127
|
-
|
|
128
|
-
it("falls back to email prefix when no displayName", () => {
|
|
129
|
-
const userNoName = { email: "charlie@example.com" };
|
|
130
|
-
const result = getUserInvitationTemplate(setPasswordUrl, userNoName);
|
|
131
|
-
expect(result.html).toContain("charlie");
|
|
132
|
-
});
|
|
133
|
-
});
|
|
134
|
-
|
|
135
|
-
describe("getWelcomeEmailTemplate", () => {
|
|
136
|
-
const user = { email: "dave@example.com",
|
|
137
|
-
displayName: "Dave" };
|
|
138
|
-
|
|
139
|
-
it("returns subject, html, and text", () => {
|
|
140
|
-
const result = getWelcomeEmailTemplate(user);
|
|
141
|
-
expect(result.subject).toBeTruthy();
|
|
142
|
-
expect(result.html).toBeTruthy();
|
|
143
|
-
expect(result.text).toBeTruthy();
|
|
144
|
-
});
|
|
145
|
-
|
|
146
|
-
it("includes the app name in subject", () => {
|
|
147
|
-
const result = getWelcomeEmailTemplate(user, "SuperApp");
|
|
148
|
-
expect(result.subject).toContain("SuperApp");
|
|
149
|
-
});
|
|
150
|
-
|
|
151
|
-
it("uses displayName for greeting", () => {
|
|
152
|
-
const result = getWelcomeEmailTemplate(user);
|
|
153
|
-
expect(result.html).toContain("Dave");
|
|
154
|
-
});
|
|
155
|
-
|
|
156
|
-
it("includes login URL when provided", () => {
|
|
157
|
-
const loginUrl = "https://example.com/login";
|
|
158
|
-
const result = getWelcomeEmailTemplate(user, "Rebase", loginUrl);
|
|
159
|
-
expect(result.html).toContain(loginUrl);
|
|
160
|
-
expect(result.text).toContain(loginUrl);
|
|
161
|
-
});
|
|
162
|
-
|
|
163
|
-
it("handles missing login URL gracefully", () => {
|
|
164
|
-
const result = getWelcomeEmailTemplate(user);
|
|
165
|
-
expect(result.html).toBeTruthy();
|
|
166
|
-
expect(result.text).toBeTruthy();
|
|
167
|
-
});
|
|
168
|
-
|
|
169
|
-
it("html contains proper structure", () => {
|
|
170
|
-
const result = getWelcomeEmailTemplate(user);
|
|
171
|
-
expect(result.html).toContain("<!DOCTYPE html>");
|
|
172
|
-
expect(result.html).toContain("<body");
|
|
173
|
-
});
|
|
174
|
-
});
|
package/test/env.test.ts
DELETED
|
@@ -1,128 +0,0 @@
|
|
|
1
|
-
import { loadEnv } from "../src/env";
|
|
2
|
-
import { z } from "zod";
|
|
3
|
-
|
|
4
|
-
describe("env configuration and localhost validation", () => {
|
|
5
|
-
const originalEnv = { ...process.env };
|
|
6
|
-
|
|
7
|
-
beforeEach(() => {
|
|
8
|
-
// Clear process.env to ensure fresh test runs
|
|
9
|
-
process.env = {};
|
|
10
|
-
// Add basic fallback requirements to prevent bootstrap crashes
|
|
11
|
-
process.env.DATABASE_URL = "postgresql://localhost:5432/rebase";
|
|
12
|
-
process.env.JWT_SECRET = "super-secret-jwt-key-must-be-long-long-long";
|
|
13
|
-
});
|
|
14
|
-
|
|
15
|
-
afterEach(() => {
|
|
16
|
-
process.env = { ...originalEnv };
|
|
17
|
-
});
|
|
18
|
-
|
|
19
|
-
it("should parse default env variables in development mode", () => {
|
|
20
|
-
expect(() => loadEnv()).not.toThrow();
|
|
21
|
-
const env = loadEnv();
|
|
22
|
-
expect(env.DATABASE_URL).toBe("postgresql://localhost:5432/rebase");
|
|
23
|
-
});
|
|
24
|
-
|
|
25
|
-
it("should fail validation in production if DATABASE_URL contains localhost", () => {
|
|
26
|
-
process.env.NODE_ENV = "production";
|
|
27
|
-
process.env.DATABASE_URL = "postgresql://localhost:5432/rebase";
|
|
28
|
-
process.env.JWT_SECRET = "12345678901234567890123456789012";
|
|
29
|
-
process.env.FRONTEND_URL = "https://my-app.com";
|
|
30
|
-
|
|
31
|
-
expect(() => loadEnv()).toThrow(/postgresql:\/\/localhost:5432\/rebase/);
|
|
32
|
-
});
|
|
33
|
-
|
|
34
|
-
it("should fail validation in production if DATABASE_URL contains 127.0.0.1", () => {
|
|
35
|
-
process.env.NODE_ENV = "production";
|
|
36
|
-
process.env.DATABASE_URL = "postgresql://127.0.0.1:5432/rebase";
|
|
37
|
-
process.env.JWT_SECRET = "12345678901234567890123456789012";
|
|
38
|
-
process.env.FRONTEND_URL = "https://my-app.com";
|
|
39
|
-
|
|
40
|
-
expect(() => loadEnv()).toThrow(/postgresql:\/\/127\.0\.0\.1:5432\/rebase/);
|
|
41
|
-
});
|
|
42
|
-
|
|
43
|
-
it("should fail validation in production if DATABASE_URL contains an IPv6 loopback [::1]", () => {
|
|
44
|
-
process.env.NODE_ENV = "production";
|
|
45
|
-
process.env.DATABASE_URL = "postgresql://[::1]:5432/rebase";
|
|
46
|
-
process.env.JWT_SECRET = "12345678901234567890123456789012";
|
|
47
|
-
process.env.FRONTEND_URL = "https://my-app.com";
|
|
48
|
-
|
|
49
|
-
expect(() => loadEnv()).toThrow(/postgresql:\/\/\[::1\]:5432\/rebase/);
|
|
50
|
-
});
|
|
51
|
-
|
|
52
|
-
it("should fail validation in production if DATABASE_URL contains a loopback in the 127.x.x.x range", () => {
|
|
53
|
-
process.env.NODE_ENV = "production";
|
|
54
|
-
process.env.DATABASE_URL = "postgresql://127.0.0.2:5432/rebase";
|
|
55
|
-
process.env.JWT_SECRET = "12345678901234567890123456789012";
|
|
56
|
-
process.env.FRONTEND_URL = "https://my-app.com";
|
|
57
|
-
|
|
58
|
-
expect(() => loadEnv()).toThrow(/postgresql:\/\/127\.0\.0\.2:5432\/rebase/);
|
|
59
|
-
});
|
|
60
|
-
|
|
61
|
-
it("should succeed validation in production with a non-localhost DATABASE_URL", () => {
|
|
62
|
-
process.env.NODE_ENV = "production";
|
|
63
|
-
process.env.DATABASE_URL = "postgresql://db.my-app.com:5432/rebase";
|
|
64
|
-
process.env.JWT_SECRET = "12345678901234567890123456789012";
|
|
65
|
-
process.env.FRONTEND_URL = "https://my-app.com";
|
|
66
|
-
|
|
67
|
-
expect(() => loadEnv()).not.toThrow();
|
|
68
|
-
const env = loadEnv();
|
|
69
|
-
expect(env.DATABASE_URL).toBe("postgresql://db.my-app.com:5432/rebase");
|
|
70
|
-
});
|
|
71
|
-
|
|
72
|
-
it("should allow localhost URLs in production if ALLOW_LOCALHOST_IN_PRODUCTION is set to true", () => {
|
|
73
|
-
process.env.NODE_ENV = "production";
|
|
74
|
-
process.env.DATABASE_URL = "postgresql://localhost:5432/rebase";
|
|
75
|
-
process.env.JWT_SECRET = "12345678901234567890123456789012";
|
|
76
|
-
process.env.FRONTEND_URL = "https://my-app.com";
|
|
77
|
-
process.env.ALLOW_LOCALHOST_IN_PRODUCTION = "true";
|
|
78
|
-
|
|
79
|
-
expect(() => loadEnv()).not.toThrow();
|
|
80
|
-
const env = loadEnv();
|
|
81
|
-
expect(env.DATABASE_URL).toBe("postgresql://localhost:5432/rebase");
|
|
82
|
-
});
|
|
83
|
-
|
|
84
|
-
it("should not block localhost URLs in CORS_ORIGINS in production mode", () => {
|
|
85
|
-
process.env.NODE_ENV = "production";
|
|
86
|
-
process.env.DATABASE_URL = "postgresql://db.my-app.com:5432/rebase";
|
|
87
|
-
process.env.JWT_SECRET = "12345678901234567890123456789012";
|
|
88
|
-
process.env.FRONTEND_URL = "https://my-app.com";
|
|
89
|
-
process.env.CORS_ORIGINS = "http://localhost:3000,https://my-app.com";
|
|
90
|
-
|
|
91
|
-
expect(() => loadEnv()).not.toThrow();
|
|
92
|
-
const env = loadEnv();
|
|
93
|
-
expect(env.CORS_ORIGINS).toBe("http://localhost:3000,https://my-app.com");
|
|
94
|
-
});
|
|
95
|
-
|
|
96
|
-
it("should validate and block localhost in extended variables", () => {
|
|
97
|
-
process.env.NODE_ENV = "production";
|
|
98
|
-
process.env.DATABASE_URL = "postgresql://db.my-app.com:5432/rebase";
|
|
99
|
-
process.env.JWT_SECRET = "12345678901234567890123456789012";
|
|
100
|
-
process.env.FRONTEND_URL = "https://my-app.com";
|
|
101
|
-
// Extended URL points to localhost
|
|
102
|
-
process.env.EXTERNAL_SERVICE_URL = "https://localhost:8080/api";
|
|
103
|
-
|
|
104
|
-
const extension = {
|
|
105
|
-
extend: z.object({
|
|
106
|
-
EXTERNAL_SERVICE_URL: z.string().url()
|
|
107
|
-
})
|
|
108
|
-
};
|
|
109
|
-
|
|
110
|
-
expect(() => loadEnv(extension)).toThrow(/https:\/\/localhost:8080\/api/);
|
|
111
|
-
});
|
|
112
|
-
|
|
113
|
-
it("should validate and block plain host string matching localhost", () => {
|
|
114
|
-
process.env.NODE_ENV = "production";
|
|
115
|
-
process.env.DATABASE_URL = "postgresql://db.my-app.com:5432/rebase";
|
|
116
|
-
process.env.JWT_SECRET = "12345678901234567890123456789012";
|
|
117
|
-
process.env.FRONTEND_URL = "https://my-app.com";
|
|
118
|
-
process.env.DB_HOST = "localhost";
|
|
119
|
-
|
|
120
|
-
const extension = {
|
|
121
|
-
extend: z.object({
|
|
122
|
-
DB_HOST: z.string()
|
|
123
|
-
})
|
|
124
|
-
};
|
|
125
|
-
|
|
126
|
-
expect(() => loadEnv(extension)).toThrow(/localhost/);
|
|
127
|
-
});
|
|
128
|
-
});
|