sonamu 0.13.10 → 0.14.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/dist/api/caster.d.ts.map +1 -1
- package/dist/api/caster.js +2 -1
- package/dist/api/code-converters.d.ts +5 -1
- package/dist/api/code-converters.d.ts.map +1 -1
- package/dist/api/code-converters.js +24 -7
- package/dist/api/config.d.ts +7 -0
- package/dist/api/config.d.ts.map +1 -1
- package/dist/api/config.js +1 -1
- package/dist/api/decorators.d.ts +1 -0
- package/dist/api/decorators.d.ts.map +1 -1
- package/dist/api/decorators.js +1 -1
- package/dist/api/guards.d.ts +37 -0
- package/dist/api/guards.d.ts.map +1 -0
- package/dist/api/guards.js +96 -0
- package/dist/api/sonamu.d.ts +14 -1
- package/dist/api/sonamu.d.ts.map +1 -1
- package/dist/api/sonamu.js +121 -25
- package/dist/api/websocket-helpers.d.ts +6 -1
- package/dist/api/websocket-helpers.d.ts.map +1 -1
- package/dist/api/websocket-helpers.js +7 -4
- package/dist/auth/auth-entity-policy.d.ts +32 -0
- package/dist/auth/auth-entity-policy.d.ts.map +1 -0
- package/dist/auth/auth-entity-policy.js +44 -0
- package/dist/auth/auth-secret.d.ts +24 -0
- package/dist/auth/auth-secret.d.ts.map +1 -0
- package/dist/auth/auth-secret.js +46 -0
- package/dist/auth/base-url.d.ts +39 -0
- package/dist/auth/base-url.d.ts.map +1 -0
- package/dist/auth/base-url.js +84 -0
- package/dist/auth/better-auth-entities.js +20 -7
- package/dist/auth/better-auth-options.d.ts +15 -0
- package/dist/auth/better-auth-options.d.ts.map +1 -0
- package/dist/auth/better-auth-options.js +38 -0
- package/dist/auth/better-auth-request.d.ts +8 -1
- package/dist/auth/better-auth-request.d.ts.map +1 -1
- package/dist/auth/better-auth-request.js +26 -3
- package/dist/auth/plugins/entity-definitions/admin.d.ts.map +1 -1
- package/dist/auth/plugins/entity-definitions/admin.js +6 -1
- package/dist/auth/plugins/entity-definitions/anonymous.d.ts.map +1 -1
- package/dist/auth/plugins/entity-definitions/anonymous.js +2 -1
- package/dist/auth/plugins/entity-definitions/api-key.d.ts.map +1 -1
- package/dist/auth/plugins/entity-definitions/api-key.js +18 -2
- package/dist/auth/plugins/entity-definitions/audit-log.d.ts.map +1 -1
- package/dist/auth/plugins/entity-definitions/audit-log.js +27 -1
- package/dist/auth/plugins/entity-definitions/jwt.d.ts.map +1 -1
- package/dist/auth/plugins/entity-definitions/jwt.js +4 -2
- package/dist/auth/plugins/entity-definitions/organization.d.ts.map +1 -1
- package/dist/auth/plugins/entity-definitions/organization.js +15 -1
- package/dist/auth/plugins/entity-definitions/passkey.d.ts.map +1 -1
- package/dist/auth/plugins/entity-definitions/passkey.js +9 -1
- package/dist/auth/plugins/entity-definitions/phone-number.d.ts.map +1 -1
- package/dist/auth/plugins/entity-definitions/phone-number.js +2 -1
- package/dist/auth/plugins/entity-definitions/sso.d.ts.map +1 -1
- package/dist/auth/plugins/entity-definitions/sso.js +7 -3
- package/dist/auth/plugins/entity-definitions/two-factor.d.ts.map +1 -1
- package/dist/auth/plugins/entity-definitions/two-factor.js +8 -3
- package/dist/auth/verify-email-guard.d.ts +37 -0
- package/dist/auth/verify-email-guard.d.ts.map +1 -0
- package/dist/auth/verify-email-guard.js +48 -0
- package/dist/bin/build-config.d.ts.map +1 -1
- package/dist/bin/build-config.js +6 -2
- package/dist/bin/typecheck-web.js +1 -1
- package/dist/cache/decorator.d.ts +12 -0
- package/dist/cache/decorator.d.ts.map +1 -1
- package/dist/cache/decorator.js +86 -19
- package/dist/cache/index.d.ts +1 -1
- package/dist/cache/index.d.ts.map +1 -1
- package/dist/cache/index.js +3 -3
- package/dist/cache/types.d.ts +16 -0
- package/dist/cache/types.d.ts.map +1 -1
- package/dist/cli/plugin-loader.d.ts +17 -0
- package/dist/cli/plugin-loader.d.ts.map +1 -0
- package/dist/cli/plugin-loader.js +178 -0
- package/dist/cli/plugin.d.ts +65 -0
- package/dist/cli/plugin.d.ts.map +1 -0
- package/dist/cli/plugin.js +7 -0
- package/dist/code-formatting/oxfmt.js +1 -1
- package/dist/code-formatting/oxlint.js +1 -1
- package/dist/database/db.d.ts +35 -10
- package/dist/database/db.d.ts.map +1 -1
- package/dist/database/db.js +37 -4
- package/dist/database/puri.d.ts +8 -0
- package/dist/database/puri.d.ts.map +1 -1
- package/dist/database/puri.js +108 -171
- package/dist/database/puri.types.d.ts +2 -0
- package/dist/database/puri.types.d.ts.map +1 -1
- package/dist/database/puri.types.js +1 -1
- package/dist/database/sql-expression-brand.d.ts +10 -0
- package/dist/database/sql-expression-brand.d.ts.map +1 -0
- package/dist/database/sql-expression-brand.js +10 -0
- package/dist/dict/en.d.ts +1 -0
- package/dist/dict/en.d.ts.map +1 -1
- package/dist/dict/en.js +2 -1
- package/dist/dict/ko.d.ts +1 -0
- package/dist/dict/ko.d.ts.map +1 -1
- package/dist/dict/ko.js +2 -1
- package/dist/dict/sonamu-dictionary.d.ts +23 -1
- package/dist/dict/sonamu-dictionary.d.ts.map +1 -1
- package/dist/dict/sonamu-dictionary.js +187 -32
- package/dist/entity/entity-codegen-safety.d.ts +105 -0
- package/dist/entity/entity-codegen-safety.d.ts.map +1 -0
- package/dist/entity/entity-codegen-safety.js +70 -0
- package/dist/entity/entity-manager.d.ts +32 -0
- package/dist/entity/entity-manager.d.ts.map +1 -1
- package/dist/entity/entity-manager.js +21 -2
- package/dist/entity/entity.d.ts +5 -2
- package/dist/entity/entity.d.ts.map +1 -1
- package/dist/entity/entity.js +19 -8
- package/dist/env.d.ts +19 -0
- package/dist/env.d.ts.map +1 -1
- package/dist/env.js +31 -3
- package/dist/filter/utils.d.ts +2 -2
- package/dist/filter/utils.d.ts.map +1 -1
- package/dist/filter/utils.js +16 -11
- package/dist/index.d.ts +4 -3
- package/dist/index.d.ts.map +1 -1
- package/dist/index.js +7 -6
- package/dist/logger/configure.d.ts.map +1 -1
- package/dist/logger/configure.js +10 -3
- package/dist/migration/code-generation.d.ts.map +1 -1
- package/dist/migration/code-generation.js +177 -96
- package/dist/migration/migrator.d.ts +16 -0
- package/dist/migration/migrator.d.ts.map +1 -1
- package/dist/migration/migrator.js +28 -3
- package/dist/migration/slack-confirm.d.ts +6 -2
- package/dist/migration/slack-confirm.d.ts.map +1 -1
- package/dist/migration/slack-confirm.js +11 -9
- package/dist/ssr/errors.d.ts +13 -0
- package/dist/ssr/errors.d.ts.map +1 -0
- package/dist/ssr/errors.js +12 -0
- package/dist/ssr/index.d.ts +1 -0
- package/dist/ssr/index.d.ts.map +1 -1
- package/dist/ssr/index.js +5 -2
- package/dist/ssr/renderer.d.ts +6 -0
- package/dist/ssr/renderer.d.ts.map +1 -1
- package/dist/ssr/renderer.js +10 -1
- package/dist/storage/base-file.d.ts +6 -2
- package/dist/storage/base-file.d.ts.map +1 -1
- package/dist/storage/base-file.js +10 -5
- package/dist/storage/buffered-file.d.ts +1 -0
- package/dist/storage/buffered-file.d.ts.map +1 -1
- package/dist/storage/buffered-file.js +5 -2
- package/dist/storage/index.d.ts +1 -0
- package/dist/storage/index.d.ts.map +1 -1
- package/dist/storage/index.js +4 -2
- package/dist/storage/upload-safety.d.ts +47 -0
- package/dist/storage/upload-safety.d.ts.map +1 -0
- package/dist/storage/upload-safety.js +112 -0
- package/dist/stream/ws.d.ts +6 -0
- package/dist/stream/ws.d.ts.map +1 -1
- package/dist/stream/ws.js +52 -6
- package/dist/syncer/api-parser.js +6 -1
- package/dist/syncer/code-generator.d.ts +2 -0
- package/dist/syncer/code-generator.d.ts.map +1 -1
- package/dist/syncer/code-generator.js +21 -7
- package/dist/template/implementations/entity.template.d.ts.map +1 -1
- package/dist/template/implementations/entity.template.js +40 -35
- package/dist/template/implementations/generated.template.d.ts +10 -0
- package/dist/template/implementations/generated.template.d.ts.map +1 -1
- package/dist/template/implementations/generated.template.js +46 -7
- package/dist/template/implementations/generated_http.template.d.ts.map +1 -1
- package/dist/template/implementations/generated_http.template.js +3 -1
- package/dist/template/implementations/init_types.template.d.ts.map +1 -1
- package/dist/template/implementations/init_types.template.js +3 -8
- package/dist/template/implementations/model.template.d.ts.map +1 -1
- package/dist/template/implementations/model.template.js +9 -2
- package/dist/template/implementations/sd.template.d.ts +0 -1
- package/dist/template/implementations/sd.template.d.ts.map +1 -1
- package/dist/template/implementations/sd.template.js +2 -5
- package/dist/template/implementations/view_form.template.d.ts.map +1 -1
- package/dist/template/implementations/view_form.template.js +8 -6
- package/dist/template/implementations/view_list.template.d.ts.map +1 -1
- package/dist/template/implementations/view_list.template.js +8 -4
- package/dist/testing/dev-test-routes.d.ts.map +1 -1
- package/dist/testing/dev-test-routes.js +7 -4
- package/dist/tooling/__tests__/helpers/sonamu-test-root.js +1 -1
- package/dist/tooling/cdd-service.js +1 -1
- package/dist/tooling/index.d.ts +1 -0
- package/dist/tooling/index.d.ts.map +1 -1
- package/dist/tooling/index.js +3 -1
- package/dist/tsdown.api.config.js +1 -1
- package/dist/types/types.d.ts +81 -1
- package/dist/types/types.d.ts.map +1 -1
- package/dist/types/types.js +2 -1
- package/dist/ui/__tests__/ui-test-helpers.d.ts +10 -0
- package/dist/ui/__tests__/ui-test-helpers.d.ts.map +1 -0
- package/dist/ui/__tests__/ui-test-helpers.js +75 -0
- package/dist/ui/access-guard.d.ts +42 -0
- package/dist/ui/access-guard.d.ts.map +1 -0
- package/dist/ui/access-guard.js +94 -0
- package/dist/ui/api.d.ts.map +1 -1
- package/dist/ui/api.js +40 -95
- package/dist/ui/dev-host-guard.d.ts +28 -0
- package/dist/ui/dev-host-guard.d.ts.map +1 -0
- package/dist/ui/dev-host-guard.js +67 -0
- package/dist/ui/migrations-api.d.ts.map +1 -1
- package/dist/ui/migrations-api.js +72 -16
- package/dist/ui/open-vscode-api.d.ts +4 -0
- package/dist/ui/open-vscode-api.d.ts.map +1 -0
- package/dist/ui/open-vscode-api.js +65 -0
- package/dist/ui/scaffolding-api.d.ts +18 -0
- package/dist/ui/scaffolding-api.d.ts.map +1 -0
- package/dist/ui/scaffolding-api.js +111 -0
- package/dist/ui/ui-db-presets.d.ts +19 -0
- package/dist/ui/ui-db-presets.d.ts.map +1 -0
- package/dist/ui/ui-db-presets.js +34 -0
- package/dist/ui/ui-request-guard.d.ts +11 -0
- package/dist/ui/ui-request-guard.d.ts.map +1 -0
- package/dist/ui/ui-request-guard.js +38 -0
- package/dist/ui-web/assets/{index-QDMyy31K.js → index-BPqP-tug.js} +39 -39
- package/dist/ui-web/index.html +2 -1
- package/package.json +1 -1
- package/src/__tests__/env.test.ts +121 -2
- package/src/api/__tests__/code-converters.union.test.ts +97 -0
- package/src/api/__tests__/guards.test.ts +233 -0
- package/src/api/__tests__/sonamu.auth-secret.test.ts +77 -0
- package/src/api/__tests__/sonamu.dev-host-guard.test.ts +130 -0
- package/src/api/__tests__/sonamu.guards.test.ts +327 -0
- package/src/api/__tests__/sonamu.upload-limits.test.ts +156 -0
- package/src/api/__tests__/websocket-helpers.test.ts +101 -0
- package/src/api/caster.ts +7 -0
- package/src/api/code-converters.ts +44 -12
- package/src/api/config.ts +8 -0
- package/src/api/decorators.ts +1 -0
- package/src/api/guards.ts +130 -0
- package/src/api/sonamu.ts +195 -39
- package/src/api/websocket-helpers.ts +11 -6
- package/src/auth/__tests__/auth-entity-policy.test.ts +59 -0
- package/src/auth/__tests__/auth-secret.test.ts +133 -0
- package/src/auth/__tests__/base-url-host-poisoning.test.ts +193 -0
- package/src/auth/__tests__/base-url.test.ts +117 -0
- package/src/auth/__tests__/better-auth-options.test.ts +194 -0
- package/src/auth/__tests__/better-auth-request.test.ts +45 -0
- package/src/auth/__tests__/verify-email-guard.test.ts +228 -0
- package/src/auth/auth-entity-policy.ts +48 -0
- package/src/auth/auth-secret.ts +77 -0
- package/src/auth/base-url.ts +109 -0
- package/src/auth/better-auth-entities.ts +30 -30
- package/src/auth/better-auth-options.ts +39 -0
- package/src/auth/better-auth-request.ts +28 -1
- package/src/auth/plugins/entity-definitions/admin.ts +5 -0
- package/src/auth/plugins/entity-definitions/anonymous.ts +9 -1
- package/src/auth/plugins/entity-definitions/api-key.ts +53 -16
- package/src/auth/plugins/entity-definitions/audit-log.ts +122 -21
- package/src/auth/plugins/entity-definitions/jwt.ts +5 -4
- package/src/auth/plugins/entity-definitions/organization.ts +26 -6
- package/src/auth/plugins/entity-definitions/passkey.ts +8 -7
- package/src/auth/plugins/entity-definitions/phone-number.ts +1 -0
- package/src/auth/plugins/entity-definitions/sso.ts +20 -15
- package/src/auth/plugins/entity-definitions/two-factor.ts +21 -5
- package/src/auth/verify-email-guard.ts +82 -0
- package/src/bin/__tests__/build-web-command.test.ts +24 -0
- package/src/bin/build-config.ts +5 -0
- package/src/cache/decorator.ts +116 -21
- package/src/cache/index.ts +6 -1
- package/src/cache/types.ts +18 -0
- package/src/cli/plugin-loader.ts +238 -0
- package/src/cli/plugin.ts +82 -0
- package/src/database/__tests__/db.test.ts +64 -1
- package/src/database/__tests__/puri.test.ts +56 -0
- package/src/database/db.ts +56 -6
- package/src/database/puri.ts +135 -125
- package/src/database/puri.types.test-d.ts +12 -0
- package/src/database/puri.types.ts +3 -0
- package/src/database/sql-expression-brand.ts +9 -0
- package/src/dict/__tests__/sonamu-dictionary.test.ts +217 -0
- package/src/dict/en.ts +2 -0
- package/src/dict/ko.ts +2 -0
- package/src/dict/sonamu-dictionary.ts +298 -38
- package/src/entity/__tests__/entity-codegen-safety.test.ts +326 -0
- package/src/entity/entity-codegen-safety.ts +126 -0
- package/src/entity/entity-manager.ts +29 -1
- package/src/entity/entity.ts +26 -12
- package/src/env.ts +52 -1
- package/src/filter/utils.ts +19 -7
- package/src/index.ts +4 -3
- package/src/logger/__tests__/configure.test.ts +51 -1
- package/src/logger/configure.ts +14 -1
- package/src/migration/__tests__/code-generation.escape.test.ts +322 -0
- package/src/migration/__tests__/migrator.test.ts +76 -1
- package/src/migration/code-generation.ts +247 -117
- package/src/migration/migrator.ts +45 -4
- package/src/migration/slack-confirm.ts +19 -5
- package/src/ssr/__tests__/preload-guard.test.ts +274 -0
- package/src/ssr/errors.ts +11 -0
- package/src/ssr/index.ts +1 -0
- package/src/ssr/renderer.ts +12 -0
- package/src/storage/__tests__/upload-safety.test.ts +179 -0
- package/src/storage/base-file.ts +8 -4
- package/src/storage/buffered-file.ts +3 -1
- package/src/storage/index.ts +9 -0
- package/src/storage/upload-safety.ts +155 -0
- package/src/stream/__tests__/ws.test.ts +97 -0
- package/src/stream/ws.ts +67 -5
- package/src/syncer/__tests__/api-parser.readonly.test.ts +55 -0
- package/src/syncer/__tests__/code-generator-path-containment.test.ts +105 -0
- package/src/syncer/api-parser.ts +12 -0
- package/src/syncer/code-generator.ts +34 -6
- package/src/template/__tests__/generated.template.search-text.test.ts +5 -1
- package/src/template/__tests__/model.template.auth-entity.test.ts +42 -0
- package/src/template/__tests__/save-params.template.test.ts +219 -0
- package/src/template/implementations/entity.template.ts +53 -48
- package/src/template/implementations/generated.template.ts +87 -12
- package/src/template/implementations/generated_http.template.ts +5 -0
- package/src/template/implementations/init_types.template.ts +4 -22
- package/src/template/implementations/model.template.ts +15 -1
- package/src/template/implementations/sd.template.ts +4 -5
- package/src/template/implementations/view_form.template.ts +13 -5
- package/src/template/implementations/view_list.template.ts +12 -3
- package/src/testing/__tests__/dev-test-routes.test.ts +99 -0
- package/src/testing/dev-test-routes.ts +7 -3
- package/src/tooling/__tests__/cli-plugins.contract.test.ts +273 -0
- package/src/tooling/index.ts +1 -0
- package/src/types/types.ts +22 -1
- package/src/ui/__tests__/access-guard.test.ts +217 -0
- package/src/ui/__tests__/dev-host-guard.test.ts +161 -0
- package/src/ui/__tests__/fixture-api.test.ts +92 -0
- package/src/ui/__tests__/migrations-api.test.ts +352 -0
- package/src/ui/__tests__/open-vscode.test.ts +151 -0
- package/src/ui/__tests__/scaffolding-api.test.ts +232 -0
- package/src/ui/__tests__/ui-process-routes.test.ts +166 -0
- package/src/ui/__tests__/ui-test-helpers.ts +71 -0
- package/src/ui/access-guard.ts +115 -0
- package/src/ui/api.ts +65 -198
- package/src/ui/dev-host-guard.ts +109 -0
- package/src/ui/migrations-api.ts +130 -24
- package/src/ui/open-vscode-api.ts +82 -0
- package/src/ui/scaffolding-api.ts +177 -0
- package/src/ui/ui-db-presets.ts +41 -0
- package/src/ui/ui-request-guard.ts +53 -0
|
@@ -0,0 +1,101 @@
|
|
|
1
|
+
import fastify, { type FastifyInstance } from "fastify";
|
|
2
|
+
import { afterEach, describe, expect, it } from "vitest";
|
|
3
|
+
|
|
4
|
+
import {
|
|
5
|
+
DEFAULT_WEBSOCKET_MAX_PAYLOAD_BYTES,
|
|
6
|
+
resolveWebSocketPluginOptions,
|
|
7
|
+
} from "../websocket-helpers";
|
|
8
|
+
|
|
9
|
+
type CloseResult = { code: number; reason: string } | "message";
|
|
10
|
+
|
|
11
|
+
// 프레임 하나를 보내고 서버가 연결을 닫는지(코드) 또는 echo로 응답하는지 기다린다
|
|
12
|
+
function sendFrameAndAwaitOutcome(url: string, payload: string): Promise<CloseResult> {
|
|
13
|
+
return new Promise((resolve, reject) => {
|
|
14
|
+
const client = new WebSocket(url);
|
|
15
|
+
client.addEventListener("open", () => {
|
|
16
|
+
client.send(payload);
|
|
17
|
+
});
|
|
18
|
+
client.addEventListener("message", () => {
|
|
19
|
+
resolve("message");
|
|
20
|
+
client.close();
|
|
21
|
+
});
|
|
22
|
+
client.addEventListener("close", (event) => {
|
|
23
|
+
resolve({ code: event.code, reason: event.reason });
|
|
24
|
+
});
|
|
25
|
+
client.addEventListener("error", () => {
|
|
26
|
+
// close 이벤트가 뒤따르므로 여기서는 결과를 정하지 않는다
|
|
27
|
+
});
|
|
28
|
+
setTimeout(() => reject(new Error("websocket outcome timeout")), 5000);
|
|
29
|
+
});
|
|
30
|
+
}
|
|
31
|
+
|
|
32
|
+
describe("resolveWebSocketPluginOptions", () => {
|
|
33
|
+
it("plugins.ws: true이면 maxPayload 기본값 64KiB를 넣는다", () => {
|
|
34
|
+
expect(DEFAULT_WEBSOCKET_MAX_PAYLOAD_BYTES).toBe(64 * 1024);
|
|
35
|
+
expect(resolveWebSocketPluginOptions({ rawPluginOption: true })).toEqual({
|
|
36
|
+
options: { maxPayload: 64 * 1024 },
|
|
37
|
+
});
|
|
38
|
+
});
|
|
39
|
+
|
|
40
|
+
it("maxPayload를 지정하지 않은 객체 설정에도 기본값을 넣고 다른 옵션은 유지한다", () => {
|
|
41
|
+
expect(
|
|
42
|
+
resolveWebSocketPluginOptions({
|
|
43
|
+
rawPluginOption: { options: { perMessageDeflate: false } },
|
|
44
|
+
}),
|
|
45
|
+
).toEqual({
|
|
46
|
+
options: { perMessageDeflate: false, maxPayload: 64 * 1024 },
|
|
47
|
+
});
|
|
48
|
+
});
|
|
49
|
+
|
|
50
|
+
it("사용자가 지정한 maxPayload는 그대로 둔다", () => {
|
|
51
|
+
expect(
|
|
52
|
+
resolveWebSocketPluginOptions({
|
|
53
|
+
rawPluginOption: { options: { maxPayload: 1024 * 1024 } },
|
|
54
|
+
}),
|
|
55
|
+
).toEqual({
|
|
56
|
+
options: { maxPayload: 1024 * 1024 },
|
|
57
|
+
});
|
|
58
|
+
});
|
|
59
|
+
});
|
|
60
|
+
|
|
61
|
+
describe("WebSocket 프레임 상한 (실제 @fastify/websocket 서버)", () => {
|
|
62
|
+
let server: FastifyInstance | null = null;
|
|
63
|
+
|
|
64
|
+
afterEach(async () => {
|
|
65
|
+
await server?.close();
|
|
66
|
+
server = null;
|
|
67
|
+
});
|
|
68
|
+
|
|
69
|
+
async function startEchoServer(): Promise<string> {
|
|
70
|
+
server = fastify();
|
|
71
|
+
const websocketPlugin = (await import("@fastify/websocket")).default;
|
|
72
|
+
const options = resolveWebSocketPluginOptions({ rawPluginOption: true });
|
|
73
|
+
await server.register(websocketPlugin, options);
|
|
74
|
+
server.register(async (instance) => {
|
|
75
|
+
instance.get("/echo", { websocket: true }, (socket) => {
|
|
76
|
+
socket.on("message", (data) => {
|
|
77
|
+
// ws의 RawData는 Buffer | ArrayBuffer | Buffer[]이므로 형태별로 바이트 길이를 구한다
|
|
78
|
+
const byteLength = Array.isArray(data)
|
|
79
|
+
? data.reduce((sum, chunk) => sum + chunk.length, 0)
|
|
80
|
+
: data.byteLength;
|
|
81
|
+
socket.send(String(byteLength));
|
|
82
|
+
});
|
|
83
|
+
});
|
|
84
|
+
});
|
|
85
|
+
// listen()이 돌려주는 실제 주소(http://127.0.0.1:<port>)를 URL로 파싱해 OS가 배정한 포트를 얻는다
|
|
86
|
+
const { port } = new URL(await server.listen({ port: 0, host: "127.0.0.1" }));
|
|
87
|
+
return `ws://127.0.0.1:${port}/echo`;
|
|
88
|
+
}
|
|
89
|
+
|
|
90
|
+
it("기본 설정에서 64KiB를 넘는 프레임은 1009로 닫는다", async () => {
|
|
91
|
+
const url = await startEchoServer();
|
|
92
|
+
const outcome = await sendFrameAndAwaitOutcome(url, "x".repeat(64 * 1024 + 1));
|
|
93
|
+
expect(outcome).toMatchObject({ code: 1009 });
|
|
94
|
+
});
|
|
95
|
+
|
|
96
|
+
it("기본 설정에서 64KiB 이하 프레임은 그대로 받는다", async () => {
|
|
97
|
+
const url = await startEchoServer();
|
|
98
|
+
const outcome = await sendFrameAndAwaitOutcome(url, "x".repeat(64 * 1024));
|
|
99
|
+
expect(outcome).toBe("message");
|
|
100
|
+
});
|
|
101
|
+
});
|
package/src/api/caster.ts
CHANGED
|
@@ -49,6 +49,13 @@ export function caster(zodType: $ZodType, raw: any): any {
|
|
|
49
49
|
} else if (zodType instanceof z.ZodBoolean && (raw === "true" || raw === "false")) {
|
|
50
50
|
// boolean
|
|
51
51
|
return raw === "true";
|
|
52
|
+
} else if (
|
|
53
|
+
zodType instanceof z.ZodLiteral &&
|
|
54
|
+
(raw === "true" || raw === "false") &&
|
|
55
|
+
zodType.values.has(raw === "true")
|
|
56
|
+
) {
|
|
57
|
+
// true/false 리터럴: GET 쿼리 문자열도 boolean과 같은 규칙으로 변환한다.
|
|
58
|
+
return raw === "true";
|
|
52
59
|
} else if (raw !== null && Array.isArray(raw) && zodType instanceof z.ZodArray) {
|
|
53
60
|
// array
|
|
54
61
|
// oxlint-disable-next-line @typescript-eslint/no-explicit-any -- 캐스팅에는 any가 필요함.
|
|
@@ -118,6 +118,8 @@ export function unwrapPromiseOnce(paramType: ApiParamType) {
|
|
|
118
118
|
* ApiParamType을 Zod 타입 인스턴스로 변환합니다.
|
|
119
119
|
* string, number, array, union 등 모든 ApiParamType을 처리하며,
|
|
120
120
|
* 순환참조가 발생하는 경우 z.unknown()으로 fallback합니다.
|
|
121
|
+
* null/undefined/void/true/false 키워드는 각각 정확한 검증기로 변환하고,
|
|
122
|
+
* any/unknown으로 선언한 경우에만 의도적으로 z.unknown()을 반환합니다.
|
|
121
123
|
*/
|
|
122
124
|
export function getZodTypeFromApiParamType<Input>(
|
|
123
125
|
input: Input,
|
|
@@ -133,6 +135,19 @@ export function getZodTypeFromApiParamType<Input>(
|
|
|
133
135
|
return z.number();
|
|
134
136
|
case "boolean":
|
|
135
137
|
return z.boolean();
|
|
138
|
+
case "null":
|
|
139
|
+
return z.null();
|
|
140
|
+
case "undefined":
|
|
141
|
+
case "void":
|
|
142
|
+
// JSON으로는 undefined 값을 보낼 수 없으므로 키 누락만 허용하고 다른 값은 모두 거부한다.
|
|
143
|
+
return z.undefined().optional();
|
|
144
|
+
case "true":
|
|
145
|
+
return z.literal(true);
|
|
146
|
+
case "false":
|
|
147
|
+
return z.literal(false);
|
|
148
|
+
case "any":
|
|
149
|
+
case "unknown":
|
|
150
|
+
return z.unknown();
|
|
136
151
|
default: {
|
|
137
152
|
const advType =
|
|
138
153
|
/* SAFETY: API 데코레이터와 Zod 검증기 등록 계약이 이 값의 타입을 보장한다. */ paramType as {
|
|
@@ -149,7 +164,8 @@ export function getZodTypeFromApiParamType<Input>(
|
|
|
149
164
|
t: string;
|
|
150
165
|
props: ApiParam[];
|
|
151
166
|
};
|
|
152
|
-
|
|
167
|
+
// 인라인 객체 멤버의 명명 타입도 최상위 파라미터와 같은 references로 해석해야 검증이 생략되지 않는다.
|
|
168
|
+
return getZodObjectFromApiParams(objType.props, references);
|
|
153
169
|
}
|
|
154
170
|
case "array": {
|
|
155
171
|
const arrType =
|
|
@@ -231,18 +247,32 @@ export function getZodTypeFromApiParamType<Input>(
|
|
|
231
247
|
t: string;
|
|
232
248
|
types: ApiParamType[];
|
|
233
249
|
};
|
|
234
|
-
// nullable
|
|
235
|
-
|
|
236
|
-
|
|
237
|
-
|
|
238
|
-
|
|
239
|
-
|
|
250
|
+
// null/undefined 멤버는 따로 떼어 나머지 union에 nullable/optional로 붙인다.
|
|
251
|
+
// 멤버 수와 무관하게 남은 멤버만으로 검증기를 만들어야 리터럴 union이 그대로 지켜진다.
|
|
252
|
+
const hasNull = unionType.types.some((type) => type === "null");
|
|
253
|
+
const hasUndefined = unionType.types.some(
|
|
254
|
+
(type) => type === "undefined" || type === "void",
|
|
255
|
+
);
|
|
256
|
+
const memberTypes = unionType.types.filter(
|
|
257
|
+
(type) => type !== "null" && type !== "undefined" && type !== "void",
|
|
258
|
+
);
|
|
259
|
+
if (memberTypes.length === 0) {
|
|
260
|
+
if (!hasNull) {
|
|
261
|
+
return z.undefined().optional();
|
|
240
262
|
}
|
|
263
|
+
return hasUndefined ? z.null().optional() : z.null();
|
|
241
264
|
}
|
|
242
|
-
|
|
243
|
-
|
|
244
|
-
|
|
245
|
-
|
|
265
|
+
let zodType: z.ZodType =
|
|
266
|
+
memberTypes.length === 1
|
|
267
|
+
? getZodTypeFromApiParamType(memberTypes[0], references)
|
|
268
|
+
: z.union(memberTypes.map((type) => getZodTypeFromApiParamType(type, references)));
|
|
269
|
+
if (hasNull) {
|
|
270
|
+
zodType = zodType.nullable();
|
|
271
|
+
}
|
|
272
|
+
if (hasUndefined) {
|
|
273
|
+
zodType = zodType.optional();
|
|
274
|
+
}
|
|
275
|
+
return zodType;
|
|
246
276
|
}
|
|
247
277
|
case "intersection": {
|
|
248
278
|
const intersectionType =
|
|
@@ -278,12 +308,14 @@ export function getZodTypeFromApiParamType<Input>(
|
|
|
278
308
|
/**
|
|
279
309
|
* ApiParam 배열을 ZodObject로 변환합니다.
|
|
280
310
|
* 각 파라미터의 optional 여부를 반영하여 Zod 스키마를 생성합니다.
|
|
311
|
+
* references는 필수입니다. 빠뜨리면 모든 명명 타입이 z.unknown()이 되어 검증 없이 통과하므로
|
|
312
|
+
* 기본값을 두지 않고 호출부에서 컴파일 오류가 나게 합니다.
|
|
281
313
|
*/
|
|
282
314
|
export function getZodObjectFromApiParams(
|
|
283
315
|
apiParams: ApiParam[],
|
|
284
316
|
references: {
|
|
285
317
|
[id: string]: z.ZodType;
|
|
286
|
-
}
|
|
318
|
+
},
|
|
287
319
|
): z.ZodObject {
|
|
288
320
|
return z.object(
|
|
289
321
|
Object.fromEntries(
|
package/src/api/config.ts
CHANGED
|
@@ -16,6 +16,7 @@ import { type SsePluginOptions } from "fastify-sse-v2/lib/types";
|
|
|
16
16
|
import { type Knex } from "knex";
|
|
17
17
|
|
|
18
18
|
import { type CacheConfig } from "../cache/types";
|
|
19
|
+
import { type SonamuCliPlugin } from "../cli/plugin";
|
|
19
20
|
import { type SonamuDBConfig } from "../database/db";
|
|
20
21
|
import { applyCurrentSnapshotToProcessEnv } from "../env";
|
|
21
22
|
import { type SonamuLoggingOptions } from "../logger/configure";
|
|
@@ -172,6 +173,11 @@ export type SonamuConfig<TSinkId extends string = string, TFilterId extends stri
|
|
|
172
173
|
*/
|
|
173
174
|
externalEditor?: "Visual Studio Code" | "Zed" | "Cursor";
|
|
174
175
|
|
|
176
|
+
/** Commands added to the `sonamu` CLI. A plugin's top-level command must not shadow a built-in one. */
|
|
177
|
+
cli?: {
|
|
178
|
+
plugins?: readonly SonamuCliPlugin[];
|
|
179
|
+
};
|
|
180
|
+
|
|
175
181
|
/**
|
|
176
182
|
* Slack 승인 설정 (Production 마이그레이션용)
|
|
177
183
|
*
|
|
@@ -217,6 +223,7 @@ export type SonamuServerOptions = {
|
|
|
217
223
|
qs?: boolean | QsPluginOptions;
|
|
218
224
|
sse?: boolean | SsePluginOptions;
|
|
219
225
|
static?: boolean | FastifyStaticOptions;
|
|
226
|
+
/** WebSocket 플러그인 (@fastify/websocket). options.maxPayload를 생략하면 프레임 1개당 64KiB로 제한합니다. */
|
|
220
227
|
ws?: boolean | WebsocketPluginOptions;
|
|
221
228
|
|
|
222
229
|
custom?: (server: FastifyInstance) => void;
|
|
@@ -226,6 +233,7 @@ export type SonamuServerOptions = {
|
|
|
226
233
|
* better-auth 인증 설정
|
|
227
234
|
* Sonamu 확장으로 additionalFields에 sonamuType 속성 추가 가능
|
|
228
235
|
* BetterAuth의 DBFieldAttribute를 확장할 수 없어서 우선 user만 적용
|
|
236
|
+
* user.additionalFields에서 input을 생략하면 false로 취급하므로 가입·수정 요청 바디로 받을 필드만 input: true로 지정
|
|
229
237
|
*/
|
|
230
238
|
auth?: BetterAuthOptions & {
|
|
231
239
|
user?: {
|
package/src/api/decorators.ts
CHANGED
|
@@ -90,6 +90,7 @@ type StreamUploadOptions = {
|
|
|
90
90
|
export type UploadDecoratorOptions = {
|
|
91
91
|
guards?: GuardKey[];
|
|
92
92
|
description?: string;
|
|
93
|
+
/** 지정한 항목만 server.plugins.multipart.limits를 덮어쓰고, 생략하거나 undefined인 항목은 전역 한도를 따릅니다. */
|
|
93
94
|
limits?: FastifyMultipartBaseOptions["limits"];
|
|
94
95
|
} & (BufferUploadOptions | StreamUploadOptions);
|
|
95
96
|
|
|
@@ -0,0 +1,130 @@
|
|
|
1
|
+
import chalk from "chalk";
|
|
2
|
+
|
|
3
|
+
import { SD } from "../dict/sd";
|
|
4
|
+
import { UnauthorizedException } from "../exceptions/so-exceptions";
|
|
5
|
+
import { type ExtendedApi, type GuardKey } from "./decorators";
|
|
6
|
+
|
|
7
|
+
// 서버 상태를 바꾸지 않는 HTTP 메서드. 이 외의 메서드는 상태 변경 API로 본다.
|
|
8
|
+
const SAFE_HTTP_METHODS = new Set(["GET", "HEAD", "OPTIONS"]);
|
|
9
|
+
|
|
10
|
+
/**
|
|
11
|
+
* guards를 지정하지 않은 상태 변경(POST/PUT/PATCH/DELETE 등) API 목록을 반환합니다.
|
|
12
|
+
*
|
|
13
|
+
* - `guards`가 `undefined`인 API만 대상입니다. `guards: []`는 공개 API를 명시적으로 표시한 것으로 보고 제외합니다.
|
|
14
|
+
* - WebSocket API는 GET 업그레이드로 연결되므로 제외합니다.
|
|
15
|
+
*/
|
|
16
|
+
export function findUnguardedMutationApis(apis: readonly ExtendedApi[]): ExtendedApi[] {
|
|
17
|
+
return apis.filter((api) => {
|
|
18
|
+
if (api.websocketOptions) {
|
|
19
|
+
return false;
|
|
20
|
+
}
|
|
21
|
+
const method = (api.options.httpMethod ?? "GET").toUpperCase();
|
|
22
|
+
if (SAFE_HTTP_METHODS.has(method)) {
|
|
23
|
+
return false;
|
|
24
|
+
}
|
|
25
|
+
return api.options.guards === undefined;
|
|
26
|
+
});
|
|
27
|
+
}
|
|
28
|
+
|
|
29
|
+
/**
|
|
30
|
+
* guards 없는 상태 변경 API가 있으면 부팅 시 경고를 출력합니다.
|
|
31
|
+
* guards 미지정은 인증 없이 누구나 호출할 수 있다는 뜻이므로, 의도한 공개 API라면 `guards: []`로 명시하게 안내합니다.
|
|
32
|
+
*
|
|
33
|
+
* @returns 경고 대상 API 목록
|
|
34
|
+
*/
|
|
35
|
+
export function warnUnguardedMutationApis(
|
|
36
|
+
apis: readonly ExtendedApi[],
|
|
37
|
+
log: (message: string) => void = console.warn,
|
|
38
|
+
): ExtendedApi[] {
|
|
39
|
+
const unguarded = findUnguardedMutationApis(apis);
|
|
40
|
+
if (unguarded.length === 0) {
|
|
41
|
+
return unguarded;
|
|
42
|
+
}
|
|
43
|
+
|
|
44
|
+
const lines = unguarded.map(
|
|
45
|
+
(api) =>
|
|
46
|
+
` ${(api.options.httpMethod ?? "GET").toUpperCase()} ${api.path} (${api.modelName}.${api.methodName})`,
|
|
47
|
+
);
|
|
48
|
+
log(
|
|
49
|
+
chalk.yellow(
|
|
50
|
+
[
|
|
51
|
+
`⚠ ${unguarded.length} state-changing API(s) have no guards and are callable without authentication:`,
|
|
52
|
+
...lines,
|
|
53
|
+
` Add guards (e.g. guards: ["user"]) or mark intentionally public APIs with guards: [].`,
|
|
54
|
+
].join("\n"),
|
|
55
|
+
),
|
|
56
|
+
);
|
|
57
|
+
return unguarded;
|
|
58
|
+
}
|
|
59
|
+
|
|
60
|
+
/**
|
|
61
|
+
* `guardKeys`에 없는 가드 키를 사용하는 API와 그 키 목록을 반환합니다.
|
|
62
|
+
*/
|
|
63
|
+
export function findApisWithUnhandledGuardKeys(
|
|
64
|
+
apis: readonly ExtendedApi[],
|
|
65
|
+
guardKeys: readonly GuardKey[],
|
|
66
|
+
): { api: ExtendedApi; keys: GuardKey[] }[] {
|
|
67
|
+
const handled = new Set<GuardKey>(guardKeys);
|
|
68
|
+
return apis.flatMap((api) => {
|
|
69
|
+
const keys = (api.options.guards ?? []).filter((guard) => !handled.has(guard));
|
|
70
|
+
return keys.length > 0 ? [{ api, keys }] : [];
|
|
71
|
+
});
|
|
72
|
+
}
|
|
73
|
+
|
|
74
|
+
/**
|
|
75
|
+
* 부팅 시 `guardKeys` 설정을 검사합니다.
|
|
76
|
+
*
|
|
77
|
+
* - `guardKeys`를 설정했으면, 목록에 없는 가드 키를 쓰는 API가 있을 때 부팅을 중단합니다.
|
|
78
|
+
* 그대로 두면 해당 API는 런타임에 항상 거부되므로 설정 실수를 부팅 시점에 드러냅니다.
|
|
79
|
+
* - `guardKeys`를 설정하지 않았으면 기존 동작(모든 키를 guardHandler에 위임)을 유지하고,
|
|
80
|
+
* 가드를 쓰는 API가 있을 때만 처리되지 않은 키가 통과될 수 있다고 경고합니다.
|
|
81
|
+
*/
|
|
82
|
+
export function checkGuardKeys(
|
|
83
|
+
apis: readonly ExtendedApi[],
|
|
84
|
+
guardKeys: readonly GuardKey[] | undefined,
|
|
85
|
+
log: (message: string) => void = console.warn,
|
|
86
|
+
): void {
|
|
87
|
+
if (guardKeys === undefined) {
|
|
88
|
+
const usesGuards = apis.some((api) => (api.options.guards ?? []).length > 0);
|
|
89
|
+
if (usesGuards) {
|
|
90
|
+
log(
|
|
91
|
+
chalk.yellow(
|
|
92
|
+
[
|
|
93
|
+
"⚠ server.apiConfig.guardKeys is not configured: every guard key is passed to guardHandler,",
|
|
94
|
+
" and a key the guardHandler does not check is allowed.",
|
|
95
|
+
' Declare the keys your guardHandler implements (e.g. guardKeys: ["user", "admin"]) to deny any other key.',
|
|
96
|
+
].join("\n"),
|
|
97
|
+
),
|
|
98
|
+
);
|
|
99
|
+
}
|
|
100
|
+
return;
|
|
101
|
+
}
|
|
102
|
+
|
|
103
|
+
const unhandled = findApisWithUnhandledGuardKeys(apis, guardKeys);
|
|
104
|
+
if (unhandled.length === 0) {
|
|
105
|
+
return;
|
|
106
|
+
}
|
|
107
|
+
const lines = unhandled.map(
|
|
108
|
+
({ api, keys }) => ` ${api.path} (${api.modelName}.${api.methodName}): ${keys.join(", ")}`,
|
|
109
|
+
);
|
|
110
|
+
throw new Error(
|
|
111
|
+
[
|
|
112
|
+
`${unhandled.length} API(s) use guard keys that are not in server.apiConfig.guardKeys [${guardKeys.join(", ")}]:`,
|
|
113
|
+
...lines,
|
|
114
|
+
" Implement these keys in guardHandler and add them to guardKeys, or remove them from the APIs.",
|
|
115
|
+
].join("\n"),
|
|
116
|
+
);
|
|
117
|
+
}
|
|
118
|
+
|
|
119
|
+
/**
|
|
120
|
+
* `guardKeys`가 설정된 경우, 목록에 없는 가드 키 요청을 guardHandler 호출 없이 거부합니다.
|
|
121
|
+
* `guardKeys`가 없으면 기존 동작을 유지하기 위해 아무것도 하지 않습니다.
|
|
122
|
+
*/
|
|
123
|
+
export function assertGuardKeyHandled(
|
|
124
|
+
guard: GuardKey,
|
|
125
|
+
guardKeys: readonly GuardKey[] | undefined,
|
|
126
|
+
): void {
|
|
127
|
+
if (guardKeys !== undefined && !guardKeys.includes(guard)) {
|
|
128
|
+
throw new UnauthorizedException(SD("error.forbidden"));
|
|
129
|
+
}
|
|
130
|
+
}
|