@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,144 +0,0 @@
|
|
|
1
|
-
import {
|
|
2
|
-
httpMethodToOperation,
|
|
3
|
-
isOperationAllowed,
|
|
4
|
-
ApiKeyOperation
|
|
5
|
-
} from "../src/auth/api-keys/api-key-permission-guard";
|
|
6
|
-
import type { ApiKeyPermission } from "../src/auth/api-keys/api-key-types";
|
|
7
|
-
|
|
8
|
-
describe("httpMethodToOperation", () => {
|
|
9
|
-
it("maps GET to read", () => {
|
|
10
|
-
expect(httpMethodToOperation("GET")).toBe("read");
|
|
11
|
-
});
|
|
12
|
-
|
|
13
|
-
it("maps HEAD to read", () => {
|
|
14
|
-
expect(httpMethodToOperation("HEAD")).toBe("read");
|
|
15
|
-
});
|
|
16
|
-
|
|
17
|
-
it("maps OPTIONS to read", () => {
|
|
18
|
-
expect(httpMethodToOperation("OPTIONS")).toBe("read");
|
|
19
|
-
});
|
|
20
|
-
|
|
21
|
-
it("maps POST to write", () => {
|
|
22
|
-
expect(httpMethodToOperation("POST")).toBe("write");
|
|
23
|
-
});
|
|
24
|
-
|
|
25
|
-
it("maps PUT to write", () => {
|
|
26
|
-
expect(httpMethodToOperation("PUT")).toBe("write");
|
|
27
|
-
});
|
|
28
|
-
|
|
29
|
-
it("maps PATCH to write", () => {
|
|
30
|
-
expect(httpMethodToOperation("PATCH")).toBe("write");
|
|
31
|
-
});
|
|
32
|
-
|
|
33
|
-
it("maps DELETE to delete", () => {
|
|
34
|
-
expect(httpMethodToOperation("DELETE")).toBe("delete");
|
|
35
|
-
});
|
|
36
|
-
|
|
37
|
-
it("is case-insensitive", () => {
|
|
38
|
-
expect(httpMethodToOperation("get")).toBe("read");
|
|
39
|
-
expect(httpMethodToOperation("post")).toBe("write");
|
|
40
|
-
expect(httpMethodToOperation("delete")).toBe("delete");
|
|
41
|
-
expect(httpMethodToOperation("Patch")).toBe("write");
|
|
42
|
-
});
|
|
43
|
-
|
|
44
|
-
it("defaults unknown methods to read", () => {
|
|
45
|
-
expect(httpMethodToOperation("CONNECT")).toBe("read");
|
|
46
|
-
expect(httpMethodToOperation("TRACE")).toBe("read");
|
|
47
|
-
expect(httpMethodToOperation("UNKNOWN")).toBe("read");
|
|
48
|
-
});
|
|
49
|
-
});
|
|
50
|
-
|
|
51
|
-
describe("isOperationAllowed", () => {
|
|
52
|
-
it("allows operation with exact collection match", () => {
|
|
53
|
-
const permissions: ApiKeyPermission[] = [
|
|
54
|
-
{ collection: "users",
|
|
55
|
-
operations: ["read", "write"] }
|
|
56
|
-
];
|
|
57
|
-
expect(isOperationAllowed(permissions, "users", "read")).toBe(true);
|
|
58
|
-
expect(isOperationAllowed(permissions, "users", "write")).toBe(true);
|
|
59
|
-
});
|
|
60
|
-
|
|
61
|
-
it("denies operation not in the operations list", () => {
|
|
62
|
-
const permissions: ApiKeyPermission[] = [
|
|
63
|
-
{ collection: "users",
|
|
64
|
-
operations: ["read"] }
|
|
65
|
-
];
|
|
66
|
-
expect(isOperationAllowed(permissions, "users", "write")).toBe(false);
|
|
67
|
-
expect(isOperationAllowed(permissions, "users", "delete")).toBe(false);
|
|
68
|
-
});
|
|
69
|
-
|
|
70
|
-
it("denies operation for non-matching collection", () => {
|
|
71
|
-
const permissions: ApiKeyPermission[] = [
|
|
72
|
-
{ collection: "users",
|
|
73
|
-
operations: ["read", "write", "delete"] }
|
|
74
|
-
];
|
|
75
|
-
expect(isOperationAllowed(permissions, "posts", "read")).toBe(false);
|
|
76
|
-
});
|
|
77
|
-
|
|
78
|
-
it("allows wildcard collection '*' to match any collection", () => {
|
|
79
|
-
const permissions: ApiKeyPermission[] = [
|
|
80
|
-
{ collection: "*",
|
|
81
|
-
operations: ["read"] }
|
|
82
|
-
];
|
|
83
|
-
expect(isOperationAllowed(permissions, "users", "read")).toBe(true);
|
|
84
|
-
expect(isOperationAllowed(permissions, "posts", "read")).toBe(true);
|
|
85
|
-
expect(isOperationAllowed(permissions, "anything", "read")).toBe(true);
|
|
86
|
-
});
|
|
87
|
-
|
|
88
|
-
it("wildcard collection still checks operations", () => {
|
|
89
|
-
const permissions: ApiKeyPermission[] = [
|
|
90
|
-
{ collection: "*",
|
|
91
|
-
operations: ["read"] }
|
|
92
|
-
];
|
|
93
|
-
expect(isOperationAllowed(permissions, "users", "write")).toBe(false);
|
|
94
|
-
expect(isOperationAllowed(permissions, "users", "delete")).toBe(false);
|
|
95
|
-
});
|
|
96
|
-
|
|
97
|
-
it("returns false for empty permissions array", () => {
|
|
98
|
-
expect(isOperationAllowed([], "users", "read")).toBe(false);
|
|
99
|
-
});
|
|
100
|
-
|
|
101
|
-
it("checks all permission entries and grants if any match", () => {
|
|
102
|
-
const permissions: ApiKeyPermission[] = [
|
|
103
|
-
{ collection: "users",
|
|
104
|
-
operations: ["read"] },
|
|
105
|
-
{ collection: "posts",
|
|
106
|
-
operations: ["write"] },
|
|
107
|
-
{ collection: "comments",
|
|
108
|
-
operations: ["read", "write", "delete"] }
|
|
109
|
-
];
|
|
110
|
-
expect(isOperationAllowed(permissions, "users", "read")).toBe(true);
|
|
111
|
-
expect(isOperationAllowed(permissions, "posts", "write")).toBe(true);
|
|
112
|
-
expect(isOperationAllowed(permissions, "comments", "delete")).toBe(true);
|
|
113
|
-
expect(isOperationAllowed(permissions, "users", "write")).toBe(false);
|
|
114
|
-
expect(isOperationAllowed(permissions, "posts", "read")).toBe(false);
|
|
115
|
-
});
|
|
116
|
-
|
|
117
|
-
it("handles overlapping permissions correctly", () => {
|
|
118
|
-
const permissions: ApiKeyPermission[] = [
|
|
119
|
-
{ collection: "users",
|
|
120
|
-
operations: ["read"] },
|
|
121
|
-
{ collection: "users",
|
|
122
|
-
operations: ["write"] }
|
|
123
|
-
];
|
|
124
|
-
expect(isOperationAllowed(permissions, "users", "read")).toBe(true);
|
|
125
|
-
expect(isOperationAllowed(permissions, "users", "write")).toBe(true);
|
|
126
|
-
expect(isOperationAllowed(permissions, "users", "delete")).toBe(false);
|
|
127
|
-
});
|
|
128
|
-
|
|
129
|
-
it("handles mixed wildcard and specific permissions", () => {
|
|
130
|
-
const permissions: ApiKeyPermission[] = [
|
|
131
|
-
{ collection: "*",
|
|
132
|
-
operations: ["read"] },
|
|
133
|
-
{ collection: "users",
|
|
134
|
-
operations: ["write", "delete"] }
|
|
135
|
-
];
|
|
136
|
-
// Wildcard read for everything
|
|
137
|
-
expect(isOperationAllowed(permissions, "posts", "read")).toBe(true);
|
|
138
|
-
// Specific write/delete for users
|
|
139
|
-
expect(isOperationAllowed(permissions, "users", "write")).toBe(true);
|
|
140
|
-
expect(isOperationAllowed(permissions, "users", "delete")).toBe(true);
|
|
141
|
-
// No write for non-users
|
|
142
|
-
expect(isOperationAllowed(permissions, "posts", "write")).toBe(false);
|
|
143
|
-
});
|
|
144
|
-
});
|
|
@@ -1,89 +0,0 @@
|
|
|
1
|
-
import { AstSchemaEditor } from "../src/api/ast-schema-editor";
|
|
2
|
-
import * as fs from "fs";
|
|
3
|
-
import * as path from "path";
|
|
4
|
-
import * as os from "os";
|
|
5
|
-
|
|
6
|
-
describe("AstSchemaEditor", () => {
|
|
7
|
-
let testDir: string;
|
|
8
|
-
let editor: AstSchemaEditor;
|
|
9
|
-
|
|
10
|
-
beforeEach(() => {
|
|
11
|
-
testDir = fs.mkdtempSync(path.join(os.tmpdir(), "ast-schema-editor-test-"));
|
|
12
|
-
editor = new AstSchemaEditor(testDir);
|
|
13
|
-
});
|
|
14
|
-
|
|
15
|
-
afterEach(() => {
|
|
16
|
-
fs.rmSync(testDir, { recursive: true,
|
|
17
|
-
force: true });
|
|
18
|
-
});
|
|
19
|
-
|
|
20
|
-
it("should merge properties while preserving existing functions when saving a collection", async () => {
|
|
21
|
-
// Setup initial file
|
|
22
|
-
const fileContent = `import { EntityCollection } from "@rebasepro/types";
|
|
23
|
-
|
|
24
|
-
const productsCollection: EntityCollection = {
|
|
25
|
-
name: "Products",
|
|
26
|
-
slug: "products",
|
|
27
|
-
properties: {
|
|
28
|
-
id: { type: "string" },
|
|
29
|
-
name: { type: "string" },
|
|
30
|
-
category: {
|
|
31
|
-
type: "reference",
|
|
32
|
-
target: () => categoriesCollection
|
|
33
|
-
}
|
|
34
|
-
}
|
|
35
|
-
};
|
|
36
|
-
|
|
37
|
-
export default productsCollection;
|
|
38
|
-
`;
|
|
39
|
-
fs.writeFileSync(path.join(testDir, "products.ts"), fileContent);
|
|
40
|
-
|
|
41
|
-
// We want to update the collection data, simulating what the frontend sends
|
|
42
|
-
const updatedData = {
|
|
43
|
-
name: "Updated Products",
|
|
44
|
-
slug: "products",
|
|
45
|
-
properties: {
|
|
46
|
-
id: { type: "string" },
|
|
47
|
-
name: { type: "string",
|
|
48
|
-
description: "Product name" },
|
|
49
|
-
category: {
|
|
50
|
-
type: "reference"
|
|
51
|
-
// Notice target is dropped since the frontend REST payload wouldn't have it serialized
|
|
52
|
-
}
|
|
53
|
-
}
|
|
54
|
-
};
|
|
55
|
-
|
|
56
|
-
await editor.saveCollection("products", updatedData);
|
|
57
|
-
|
|
58
|
-
const newContent = fs.readFileSync(path.join(testDir, "products.ts"), "utf-8");
|
|
59
|
-
expect(newContent).toContain('name: "Updated Products"');
|
|
60
|
-
expect(newContent).toContain("target: () => categoriesCollection");
|
|
61
|
-
expect(newContent).toContain('description: "Product name"');
|
|
62
|
-
});
|
|
63
|
-
|
|
64
|
-
it("should safely escape string values containing quotes and prevent code injection", async () => {
|
|
65
|
-
// Setup initial file
|
|
66
|
-
const fileContent = `import { EntityCollection } from "@rebasepro/types";
|
|
67
|
-
const productsCollection: EntityCollection = {
|
|
68
|
-
name: "Products",
|
|
69
|
-
slug: "products",
|
|
70
|
-
properties: {}
|
|
71
|
-
};
|
|
72
|
-
export default productsCollection;
|
|
73
|
-
`;
|
|
74
|
-
fs.writeFileSync(path.join(testDir, "products.ts"), fileContent);
|
|
75
|
-
|
|
76
|
-
// Payload attempting breakout
|
|
77
|
-
const maliciousData = {
|
|
78
|
-
name: 'Products", description: "Injected description", breakout: "true',
|
|
79
|
-
slug: "products",
|
|
80
|
-
properties: {}
|
|
81
|
-
};
|
|
82
|
-
|
|
83
|
-
await editor.saveCollection("products", maliciousData);
|
|
84
|
-
|
|
85
|
-
const newContent = fs.readFileSync(path.join(testDir, "products.ts"), "utf-8");
|
|
86
|
-
// Verify that the quote was safely escaped and did not break out to create a new property
|
|
87
|
-
expect(newContent).toContain('name: "Products\\", description: \\"Injected description\\", breakout: \\"true"');
|
|
88
|
-
});
|
|
89
|
-
});
|