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
package/src/ui/api.ts
CHANGED
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import { execFileSync
|
|
1
|
+
import { execFileSync } from "child_process";
|
|
2
2
|
import fs from "fs";
|
|
3
3
|
import path from "path";
|
|
4
4
|
|
|
@@ -14,17 +14,12 @@ import { SD } from "../dict/sd";
|
|
|
14
14
|
import { sonamuDictionary } from "../dict/sonamu-dictionary";
|
|
15
15
|
import { type Entity } from "../entity/entity";
|
|
16
16
|
import { EntityManager } from "../entity/entity-manager";
|
|
17
|
-
import {
|
|
18
|
-
BadRequestException,
|
|
19
|
-
isSoException,
|
|
20
|
-
ServiceUnavailableException,
|
|
21
|
-
} from "../exceptions/so-exceptions";
|
|
22
|
-
import { TemplateManager } from "../template/template-manager";
|
|
17
|
+
import { BadRequestException } from "../exceptions/so-exceptions";
|
|
23
18
|
import { DataExplorer, type DataExplorerOptions } from "../testing/data-explorer";
|
|
24
19
|
import { FixtureGenerator, type FixtureGenerationSpec } from "../testing/fixture-generator";
|
|
25
20
|
import { FixtureManager } from "../testing/fixture-manager";
|
|
26
21
|
import { type DuplicateCheckOptions } from "../testing/fixture-manager";
|
|
27
|
-
import { BUILT_IN_TYPE_IDS
|
|
22
|
+
import { BUILT_IN_TYPE_IDS } from "../types/types";
|
|
28
23
|
import {
|
|
29
24
|
type Cone,
|
|
30
25
|
type EntityIndex,
|
|
@@ -33,10 +28,14 @@ import {
|
|
|
33
28
|
type FixtureRecord,
|
|
34
29
|
type FixtureSearchOptions,
|
|
35
30
|
type FlattenSubsetRow,
|
|
36
|
-
type PathAndCode,
|
|
37
31
|
} from "../types/types";
|
|
38
32
|
import { isObjectValue } from "../utils/runtime-value";
|
|
39
|
-
import {
|
|
33
|
+
import {
|
|
34
|
+
canServeSonamuUIToken,
|
|
35
|
+
getSonamuUIToken,
|
|
36
|
+
requireSonamuUIToken,
|
|
37
|
+
SONAMU_UI_TOKEN_PLACEHOLDER,
|
|
38
|
+
} from "./access-guard";
|
|
40
39
|
import { setAiApi } from "./ai-api";
|
|
41
40
|
import { forwardAsyncErrors } from "./async-route";
|
|
42
41
|
import { type CddAddRuleRequest } from "./cdd-service";
|
|
@@ -51,11 +50,10 @@ import {
|
|
|
51
50
|
readRule,
|
|
52
51
|
} from "./cdd-service";
|
|
53
52
|
import { registerMigrationsApi } from "./migrations-api";
|
|
54
|
-
|
|
55
|
-
|
|
56
|
-
|
|
57
|
-
|
|
58
|
-
}
|
|
53
|
+
import { registerOpenVscodeApi } from "./open-vscode-api";
|
|
54
|
+
import { registerScaffoldingApi } from "./scaffolding-api";
|
|
55
|
+
import { assertUIDBPreset } from "./ui-db-presets";
|
|
56
|
+
import { requireSameOriginUIRequest } from "./ui-request-guard";
|
|
59
57
|
|
|
60
58
|
async function waitForHMRCompleted<T>(fn: () => Promise<T>): Promise<T> {
|
|
61
59
|
const waitPromise = new Promise<void>((resolve) => {
|
|
@@ -87,6 +85,19 @@ function flattenSubsetRows(subsetRows: EntitySubsetRow[]): FlattenSubsetRow[] {
|
|
|
87
85
|
export async function sonamuUIApiPlugin(fastify: FastifyInstance) {
|
|
88
86
|
fastify.register(
|
|
89
87
|
async (server) => {
|
|
88
|
+
// 이 범위에 등록되는 모든 API 라우트(이후 추가되는 라우트 포함)에 접근 토큰 검사를 붙입니다.
|
|
89
|
+
// 원본 URL이 아니라 매칭된 라우트 패턴으로 판정하므로 퍼센트 인코딩 등으로 우회할 수 없습니다.
|
|
90
|
+
server.addHook("onRoute", (routeOptions) => {
|
|
91
|
+
if (!routeOptions.url.startsWith(`${routeOptions.prefix}/api/`)) {
|
|
92
|
+
return;
|
|
93
|
+
}
|
|
94
|
+
const existing = routeOptions.onRequest;
|
|
95
|
+
routeOptions.onRequest = [
|
|
96
|
+
requireSonamuUIToken,
|
|
97
|
+
...(existing === undefined ? [] : Array.isArray(existing) ? existing : [existing]),
|
|
98
|
+
];
|
|
99
|
+
});
|
|
100
|
+
|
|
90
101
|
await setAiApi(server);
|
|
91
102
|
await registerMigrationsApi(server);
|
|
92
103
|
|
|
@@ -94,64 +105,27 @@ export async function sonamuUIApiPlugin(fastify: FastifyInstance) {
|
|
|
94
105
|
return Sonamu.config;
|
|
95
106
|
});
|
|
96
107
|
|
|
97
|
-
server
|
|
98
|
-
Querystring: {
|
|
99
|
-
entityId?: string;
|
|
100
|
-
preset?: "types" | "entity.json" | "generated";
|
|
101
|
-
absPath?: string;
|
|
102
|
-
};
|
|
103
|
-
}>("/api/tools/openVscode", (request) =>
|
|
104
|
-
forwardAsyncErrors(async () => {
|
|
105
|
-
const { entityId, preset, absPath } = request.query;
|
|
106
|
-
|
|
107
|
-
const targetPath = (() => {
|
|
108
|
-
if (entityId && preset) {
|
|
109
|
-
const entity = EntityManager.get(entityId);
|
|
110
|
-
const { names } = entity;
|
|
111
|
-
|
|
112
|
-
const { apiRootPath } = Sonamu;
|
|
113
|
-
const filename = (() => {
|
|
114
|
-
switch (preset) {
|
|
115
|
-
case "types":
|
|
116
|
-
return `${names.fs}.types.ts`;
|
|
117
|
-
case "entity.json":
|
|
118
|
-
return `${names.fs}.entity.json`;
|
|
119
|
-
case "generated":
|
|
120
|
-
return `${names.fs}.generated.ts`;
|
|
121
|
-
}
|
|
122
|
-
return undefined;
|
|
123
|
-
})();
|
|
124
|
-
return `${apiRootPath}/src/application/${entity.names.parentFs}/${filename}`;
|
|
125
|
-
} else {
|
|
126
|
-
if (!absPath) {
|
|
127
|
-
throw new BadRequestException(SD("sonamu.error.presetOrAbsPathRequired"));
|
|
128
|
-
}
|
|
129
|
-
return absPath;
|
|
130
|
-
}
|
|
131
|
-
})();
|
|
132
|
-
execSync(`code ${targetPath}`);
|
|
133
|
-
}),
|
|
134
|
-
);
|
|
108
|
+
await registerOpenVscodeApi(server);
|
|
135
109
|
|
|
136
|
-
server.
|
|
137
|
-
|
|
110
|
+
server.post<{
|
|
111
|
+
Body: {
|
|
138
112
|
editor: "vscode" | "cursor" | "zed";
|
|
139
113
|
absPath: string;
|
|
140
114
|
};
|
|
141
|
-
}>("/api/tools/openEditor", (request) =>
|
|
115
|
+
}>("/api/tools/openEditor", { onRequest: requireSameOriginUIRequest }, (request) =>
|
|
142
116
|
forwardAsyncErrors(async () => {
|
|
143
117
|
const commands = {
|
|
144
118
|
vscode: "code",
|
|
145
119
|
cursor: "cursor",
|
|
146
120
|
zed: "zed",
|
|
147
121
|
} as const;
|
|
148
|
-
const command = commands[request.
|
|
122
|
+
const command = commands[request.body.editor];
|
|
149
123
|
if (command === undefined) {
|
|
150
124
|
throw new BadRequestException(SD("error.badRequest"));
|
|
151
125
|
}
|
|
152
126
|
|
|
153
127
|
// 셸을 거치지 않아 파일 경로가 명령으로 해석되지 않도록 합니다.
|
|
154
|
-
execFileSync(command, [request.
|
|
128
|
+
execFileSync(command, [request.body.absPath]);
|
|
155
129
|
}),
|
|
156
130
|
);
|
|
157
131
|
|
|
@@ -503,7 +477,7 @@ export async function sonamuUIApiPlugin(fastify: FastifyInstance) {
|
|
|
503
477
|
const { entityId, at, newProp } = request.body;
|
|
504
478
|
|
|
505
479
|
const entity = EntityManager.get(entityId);
|
|
506
|
-
entity.modifyProp(newProp, at);
|
|
480
|
+
await entity.modifyProp(newProp, at);
|
|
507
481
|
|
|
508
482
|
return true;
|
|
509
483
|
});
|
|
@@ -521,7 +495,7 @@ export async function sonamuUIApiPlugin(fastify: FastifyInstance) {
|
|
|
521
495
|
const { entityId, at } = request.body;
|
|
522
496
|
|
|
523
497
|
const entity = EntityManager.get(entityId);
|
|
524
|
-
entity.delProp(at);
|
|
498
|
+
await entity.delProp(at);
|
|
525
499
|
return true;
|
|
526
500
|
});
|
|
527
501
|
}),
|
|
@@ -539,7 +513,7 @@ export async function sonamuUIApiPlugin(fastify: FastifyInstance) {
|
|
|
539
513
|
const { entityId, at, to } = request.body;
|
|
540
514
|
|
|
541
515
|
const entity = EntityManager.get(entityId);
|
|
542
|
-
entity.moveProp(at, to);
|
|
516
|
+
await entity.moveProp(at, to);
|
|
543
517
|
|
|
544
518
|
return true;
|
|
545
519
|
});
|
|
@@ -794,130 +768,7 @@ export async function sonamuUIApiPlugin(fastify: FastifyInstance) {
|
|
|
794
768
|
}),
|
|
795
769
|
);
|
|
796
770
|
|
|
797
|
-
server
|
|
798
|
-
Body: {
|
|
799
|
-
entityIds: string[];
|
|
800
|
-
templateKeys: string[];
|
|
801
|
-
};
|
|
802
|
-
}>("/api/scaffolding/getStatus", (request) =>
|
|
803
|
-
forwardAsyncErrors(async () => {
|
|
804
|
-
const { entityIds, templateKeys: _templateKeys } = request.body;
|
|
805
|
-
if ((entityIds ?? []).length === 0) {
|
|
806
|
-
throw new BadRequestException(SD("sonamu.error.entityIdsRequired"));
|
|
807
|
-
} else if ((_templateKeys ?? []).length === 0) {
|
|
808
|
-
throw new BadRequestException(SD("sonamu.error.templateKeysRequired"));
|
|
809
|
-
}
|
|
810
|
-
|
|
811
|
-
// sorting
|
|
812
|
-
entityIds.sort((a, b) => (a < b ? -1 : a > b ? 1 : 0));
|
|
813
|
-
const templateKeys = TemplateKey.options.filter((tk) => _templateKeys.includes(tk));
|
|
814
|
-
|
|
815
|
-
const combinations = entityIds.flatMap((entityId) => {
|
|
816
|
-
return templateKeys.map((templateKey) => [entityId, templateKey]);
|
|
817
|
-
});
|
|
818
|
-
|
|
819
|
-
const statuses = await Promise.all(
|
|
820
|
-
combinations.map(async ([entityId, templateKey]) => {
|
|
821
|
-
const { subPath, fullPath, isExists } = await Sonamu.syncer.checkExistsGenCode(
|
|
822
|
-
entityId,
|
|
823
|
-
/* SAFETY: UI 도구의 Zod 입력 스키마가 이 값의 타입을 보장한다. */ templateKey as TemplateKey,
|
|
824
|
-
);
|
|
825
|
-
return {
|
|
826
|
-
entityId,
|
|
827
|
-
templateKey,
|
|
828
|
-
subPath,
|
|
829
|
-
fullPath,
|
|
830
|
-
isExists,
|
|
831
|
-
};
|
|
832
|
-
}),
|
|
833
|
-
);
|
|
834
|
-
return { statuses };
|
|
835
|
-
}),
|
|
836
|
-
);
|
|
837
|
-
|
|
838
|
-
server.post<{
|
|
839
|
-
Body: {
|
|
840
|
-
options: {
|
|
841
|
-
entityId: string;
|
|
842
|
-
templateKey: string;
|
|
843
|
-
enumId?: string;
|
|
844
|
-
overwrite?: boolean;
|
|
845
|
-
}[];
|
|
846
|
-
};
|
|
847
|
-
}>("/api/scaffolding/generate", (request) =>
|
|
848
|
-
forwardAsyncErrors(async () => {
|
|
849
|
-
const { options } = request.body;
|
|
850
|
-
if (options.length === 0) {
|
|
851
|
-
throw new BadRequestException(SD("sonamu.error.optionsRequired"));
|
|
852
|
-
}
|
|
853
|
-
|
|
854
|
-
// 1. 모든 템플릿에서 필요한 dict 키를 수집
|
|
855
|
-
const keys = options.flatMap(({ templateKey }) => {
|
|
856
|
-
const template = TemplateManager.get(templateKey);
|
|
857
|
-
return template.getRequiredDictKeys() ?? [];
|
|
858
|
-
});
|
|
859
|
-
|
|
860
|
-
// 2. target별로 ensureDictKeys 호출 (순차 처리)
|
|
861
|
-
await sonamuDictionary.ensureDictKeys([...new Set(keys)]);
|
|
862
|
-
|
|
863
|
-
// 3. 템플릿 생성 (병렬 처리)
|
|
864
|
-
const result = await Promise.all(
|
|
865
|
-
options.map(async ({ entityId, templateKey, enumId, overwrite }) => {
|
|
866
|
-
try {
|
|
867
|
-
return await Sonamu.syncer.generateTemplate(
|
|
868
|
-
/* SAFETY: UI 도구의 Zod 입력 스키마가 이 값의 타입을 보장한다. */ templateKey as TemplateKey,
|
|
869
|
-
/* SAFETY: UI 도구의 Zod 입력 스키마가 Entity 템플릿 옵션을 보장한다. */ {
|
|
870
|
-
entityId,
|
|
871
|
-
enumId,
|
|
872
|
-
} as EntityTemplateInput,
|
|
873
|
-
{
|
|
874
|
-
overwrite,
|
|
875
|
-
},
|
|
876
|
-
);
|
|
877
|
-
} catch (e) {
|
|
878
|
-
if (isSoException(e) && e.statusCode === 541) {
|
|
879
|
-
return null;
|
|
880
|
-
} else {
|
|
881
|
-
console.error(e);
|
|
882
|
-
throw e;
|
|
883
|
-
}
|
|
884
|
-
}
|
|
885
|
-
}),
|
|
886
|
-
);
|
|
887
|
-
|
|
888
|
-
if (result.filter(nonNullable).length === 0) {
|
|
889
|
-
throw new ServiceUnavailableException(SD("sonamu.error.allFilesGenerated"));
|
|
890
|
-
}
|
|
891
|
-
return result;
|
|
892
|
-
}),
|
|
893
|
-
);
|
|
894
|
-
|
|
895
|
-
server.post<{
|
|
896
|
-
Body: {
|
|
897
|
-
option: {
|
|
898
|
-
entityId: string;
|
|
899
|
-
templateKey: string;
|
|
900
|
-
enumId?: string;
|
|
901
|
-
};
|
|
902
|
-
};
|
|
903
|
-
}>("/api/scaffolding/preview", (request): Promise<{ pathAndCodes: PathAndCode[] }> =>
|
|
904
|
-
forwardAsyncErrors(async () => {
|
|
905
|
-
const { option } = request.body;
|
|
906
|
-
|
|
907
|
-
try {
|
|
908
|
-
const { templateKey, ...templateOptions } = option;
|
|
909
|
-
const pathAndCodes = await Sonamu.syncer.renderTemplate(
|
|
910
|
-
/* SAFETY: UI 도구의 Zod 입력 스키마가 이 값의 타입을 보장한다. */ templateKey as TemplateKey,
|
|
911
|
-
templateOptions,
|
|
912
|
-
);
|
|
913
|
-
|
|
914
|
-
return { pathAndCodes };
|
|
915
|
-
} catch (e) {
|
|
916
|
-
console.error(e);
|
|
917
|
-
throw e;
|
|
918
|
-
}
|
|
919
|
-
}),
|
|
920
|
-
);
|
|
771
|
+
await registerScaffoldingApi(server);
|
|
921
772
|
|
|
922
773
|
server.post("/api/fixture", (request) =>
|
|
923
774
|
forwardAsyncErrors(async () => {
|
|
@@ -928,6 +779,9 @@ export async function sonamuUIApiPlugin(fastify: FastifyInstance) {
|
|
|
928
779
|
search: FixtureSearchOptions;
|
|
929
780
|
duplicateCheck?: DuplicateCheckOptions;
|
|
930
781
|
};
|
|
782
|
+
// 운영 계열 DB를 브라우저 요청으로 조회하거나 비교하지 않도록 프리셋을 제한합니다.
|
|
783
|
+
assertUIDBPreset(sourceDB, Sonamu.dbConfig, "sourceDB");
|
|
784
|
+
assertUIDBPreset(targetDB, Sonamu.dbConfig, "targetDB");
|
|
931
785
|
|
|
932
786
|
return FixtureManager.getFixtures(sourceDB, targetDB, search, duplicateCheck);
|
|
933
787
|
}),
|
|
@@ -940,6 +794,7 @@ export async function sonamuUIApiPlugin(fastify: FastifyInstance) {
|
|
|
940
794
|
db: keyof SonamuDBConfig;
|
|
941
795
|
fixtures: FixtureRecord[];
|
|
942
796
|
};
|
|
797
|
+
assertUIDBPreset(db, Sonamu.dbConfig, "db");
|
|
943
798
|
|
|
944
799
|
return FixtureManager.insertFixtures(db, fixtures);
|
|
945
800
|
}),
|
|
@@ -1369,19 +1224,25 @@ export async function sonamuUIApiPlugin(fastify: FastifyInstance) {
|
|
|
1369
1224
|
}),
|
|
1370
1225
|
);
|
|
1371
1226
|
|
|
1372
|
-
server.post<{ Body: { filePath: string } }>(
|
|
1373
|
-
|
|
1374
|
-
|
|
1375
|
-
|
|
1376
|
-
|
|
1227
|
+
server.post<{ Body: { filePath: string } }>(
|
|
1228
|
+
"/api/cdd/editContent",
|
|
1229
|
+
{ onRequest: requireSameOriginUIRequest },
|
|
1230
|
+
(request) =>
|
|
1231
|
+
forwardAsyncErrors(async () => {
|
|
1232
|
+
const { filePath } = request.body;
|
|
1233
|
+
return editContent(filePath);
|
|
1234
|
+
}),
|
|
1377
1235
|
);
|
|
1378
1236
|
|
|
1379
|
-
server.post<{ Body: { filePath: string } }>(
|
|
1380
|
-
|
|
1381
|
-
|
|
1382
|
-
|
|
1383
|
-
|
|
1384
|
-
|
|
1237
|
+
server.post<{ Body: { filePath: string } }>(
|
|
1238
|
+
"/api/cdd/openSource",
|
|
1239
|
+
{ onRequest: requireSameOriginUIRequest },
|
|
1240
|
+
(request) =>
|
|
1241
|
+
forwardAsyncErrors(async () => {
|
|
1242
|
+
const { filePath } = request.body;
|
|
1243
|
+
openSourceFile(filePath);
|
|
1244
|
+
return { success: true };
|
|
1245
|
+
}),
|
|
1385
1246
|
);
|
|
1386
1247
|
|
|
1387
1248
|
// CDD Rules API
|
|
@@ -1416,15 +1277,21 @@ export async function sonamuUIApiPlugin(fastify: FastifyInstance) {
|
|
|
1416
1277
|
prefix: "/",
|
|
1417
1278
|
decorateReply: false,
|
|
1418
1279
|
wildcard: false,
|
|
1280
|
+
// index.html은 접근 토큰을 넣어야 하므로 아래 SPA fallback에서만 내려줍니다.
|
|
1281
|
+
index: false,
|
|
1419
1282
|
});
|
|
1420
1283
|
|
|
1421
1284
|
// SPA fallback - 정적 파일이 없는 모든 경로는 index.html로
|
|
1422
|
-
server.get("*", async (
|
|
1285
|
+
server.get("*", async (request, reply) => {
|
|
1286
|
+
if (!canServeSonamuUIToken(request)) {
|
|
1287
|
+
return reply.code(403).send({ message: SD("error.forbidden"), issues: [] });
|
|
1288
|
+
}
|
|
1423
1289
|
reply.headers({ "Content-type": "text/html" }).send(
|
|
1424
1290
|
fs
|
|
1425
1291
|
.readFileSync(path.resolve(uiDistPath, "index.html"))
|
|
1426
1292
|
.toString()
|
|
1427
|
-
.replace("{{projectName}}", Sonamu.config.projectName ?? "UnknownSonamuProject")
|
|
1293
|
+
.replace("{{projectName}}", Sonamu.config.projectName ?? "UnknownSonamuProject")
|
|
1294
|
+
.replace(SONAMU_UI_TOKEN_PLACEHOLDER, getSonamuUIToken()),
|
|
1428
1295
|
);
|
|
1429
1296
|
});
|
|
1430
1297
|
},
|
|
@@ -0,0 +1,109 @@
|
|
|
1
|
+
import { isIP } from "node:net";
|
|
2
|
+
|
|
3
|
+
import { type FastifyInstance, type FastifyReply, type FastifyRequest } from "fastify";
|
|
4
|
+
|
|
5
|
+
import { type SonamuServerOptions } from "../api/config";
|
|
6
|
+
import { SD } from "../dict/sd";
|
|
7
|
+
|
|
8
|
+
/** Host 헤더에서 호스트 이름과 포트만 받아들입니다. userinfo·경로·공백이 섞인 값은 거부합니다. */
|
|
9
|
+
const HOST_HEADER_PATTERN =
|
|
10
|
+
/^(?:\[(?<ipv6>[0-9a-f:.]+)\]|(?<name>[^\s:@/?#[\]\\]+))(?::\d{1,5})?$/i;
|
|
11
|
+
|
|
12
|
+
/**
|
|
13
|
+
* 개발 서버의 Sonamu UI·dev 라우트가 받아들일 Host 헤더인지 판정합니다.
|
|
14
|
+
*
|
|
15
|
+
* DNS rebinding은 공격자가 소유한 도메인 이름을 개발자 PC 주소로 바꿔치기하므로
|
|
16
|
+
* 브라우저가 보내는 Host에는 공격자 도메인이 남습니다. 따라서 공격자가 이름을 소유할 수 없는
|
|
17
|
+
* localhost, *.localhost, IP 리터럴과 설정에 적힌 호스트만 허용합니다.
|
|
18
|
+
*
|
|
19
|
+
* @param hostHeader 요청의 Host 헤더 값
|
|
20
|
+
* @param configuredHostnames server.listen.host, server.baseUrl처럼 앱이 직접 설정한 호스트 이름
|
|
21
|
+
*/
|
|
22
|
+
export function isAllowedDevHost(
|
|
23
|
+
hostHeader: string | undefined,
|
|
24
|
+
configuredHostnames: readonly string[] = [],
|
|
25
|
+
): boolean {
|
|
26
|
+
if (hostHeader === undefined) {
|
|
27
|
+
return false;
|
|
28
|
+
}
|
|
29
|
+
const groups = HOST_HEADER_PATTERN.exec(hostHeader.trim())?.groups;
|
|
30
|
+
if (groups === undefined) {
|
|
31
|
+
return false;
|
|
32
|
+
}
|
|
33
|
+
|
|
34
|
+
const ipv6 = groups.ipv6;
|
|
35
|
+
if (ipv6 !== undefined) {
|
|
36
|
+
return isIP(ipv6) === 6;
|
|
37
|
+
}
|
|
38
|
+
|
|
39
|
+
const hostname = groups.name?.toLowerCase();
|
|
40
|
+
if (hostname === undefined) {
|
|
41
|
+
return false;
|
|
42
|
+
}
|
|
43
|
+
// IP 리터럴은 DNS를 거치지 않아 rebinding 대상이 될 수 없습니다(Vite allowedHosts 기본 규칙과 같음).
|
|
44
|
+
if (isIP(hostname) !== 0) {
|
|
45
|
+
return true;
|
|
46
|
+
}
|
|
47
|
+
if (hostname === "localhost" || hostname.endsWith(".localhost")) {
|
|
48
|
+
return true;
|
|
49
|
+
}
|
|
50
|
+
return configuredHostnames.some((configured) => configured.toLowerCase() === hostname);
|
|
51
|
+
}
|
|
52
|
+
|
|
53
|
+
/**
|
|
54
|
+
* 서버 설정에서 개발자가 직접 지정한 호스트 이름(listen.host, baseUrl의 호스트)을 모읍니다.
|
|
55
|
+
*/
|
|
56
|
+
export function getConfiguredDevHostnames(
|
|
57
|
+
serverOptions: Pick<SonamuServerOptions, "baseUrl" | "listen">,
|
|
58
|
+
): string[] {
|
|
59
|
+
const hostnames: string[] = [];
|
|
60
|
+
const listenHost = serverOptions.listen?.host;
|
|
61
|
+
if (listenHost !== undefined && listenHost !== "") {
|
|
62
|
+
hostnames.push(listenHost);
|
|
63
|
+
}
|
|
64
|
+
if (serverOptions.baseUrl !== undefined) {
|
|
65
|
+
try {
|
|
66
|
+
hostnames.push(new URL(serverOptions.baseUrl).hostname.replace(/^\[(.*)\]$/, "$1"));
|
|
67
|
+
} catch {
|
|
68
|
+
// URL이 아닌 baseUrl은 허용 호스트에 더하지 않습니다.
|
|
69
|
+
}
|
|
70
|
+
}
|
|
71
|
+
return hostnames;
|
|
72
|
+
}
|
|
73
|
+
|
|
74
|
+
function isUnderPrefix(routeUrl: string, prefix: string): boolean {
|
|
75
|
+
// prefix를 둔 플러그인의 "*" 라우트는 "/sonamu-ui*"로 합쳐지므로 "*" 경계도 같은 라우트 묶음으로 봅니다.
|
|
76
|
+
return (
|
|
77
|
+
routeUrl === prefix || routeUrl.startsWith(`${prefix}/`) || routeUrl.startsWith(`${prefix}*`)
|
|
78
|
+
);
|
|
79
|
+
}
|
|
80
|
+
|
|
81
|
+
/**
|
|
82
|
+
* 허용되지 않은 Host로 들어온 Sonamu UI·dev 라우트 요청을 403으로 거부하는 onRequest 훅을 등록합니다.
|
|
83
|
+
*
|
|
84
|
+
* 매칭된 라우트 경로(routeOptions.url)가 protectedPrefixes 아래일 때만 검사하므로
|
|
85
|
+
* 앱 API와 404 응답에는 영향을 주지 않습니다. 보호할 라우트를 등록하기 전에 호출해야 합니다.
|
|
86
|
+
*/
|
|
87
|
+
export function registerDevHostGuard(
|
|
88
|
+
server: FastifyInstance,
|
|
89
|
+
options: { configuredHostnames: readonly string[]; protectedPrefixes: readonly string[] },
|
|
90
|
+
): void {
|
|
91
|
+
const prefixes = options.protectedPrefixes
|
|
92
|
+
.map((prefix) => prefix.replace(/\/+$/, ""))
|
|
93
|
+
.filter((prefix) => prefix !== "");
|
|
94
|
+
|
|
95
|
+
server.addHook(
|
|
96
|
+
"onRequest",
|
|
97
|
+
async (request: FastifyRequest, reply: FastifyReply): Promise<FastifyReply | undefined> => {
|
|
98
|
+
const routeUrl = request.routeOptions.url;
|
|
99
|
+
if (routeUrl === undefined || !prefixes.some((prefix) => isUnderPrefix(routeUrl, prefix))) {
|
|
100
|
+
return undefined;
|
|
101
|
+
}
|
|
102
|
+
if (isAllowedDevHost(request.headers.host, options.configuredHostnames)) {
|
|
103
|
+
return undefined;
|
|
104
|
+
}
|
|
105
|
+
// async 훅에서 응답을 끝낼 때는 reply를 반환해야 핸들러로 넘어가지 않습니다.
|
|
106
|
+
return reply.code(403).send({ message: SD("error.forbidden"), issues: [] });
|
|
107
|
+
},
|
|
108
|
+
);
|
|
109
|
+
}
|