Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
40 commits
Select commit Hold shift + click to select a range
bbd8f10
[F9-5] 로그인 토큰의 사용자 번호를 숫자로 맞춤
claude Dec 2, 2026
60654d3
[F9-5] 요청 경계가 다시 쓰는 사용자 번호도 숫자로 맞춤
claude Dec 2, 2026
867839c
[F9-5] 요청 경계가 다시 쓰는 사용자 번호도 숫자로 맞춤
claude Dec 2, 2026
540a9fc
[F9-5] G03 기준선 숫자 낮춤 (legacy-boundary.ts 가 작아짐)
claude Dec 2, 2026
2693157
[F10-0] F10 정의 초안: 리드를 현행 업무 수준으로
claude Dec 2, 2026
935022d
[F10-0] F10 정의 결정 기록
claude Dec 2, 2026
8171720
[F10-0] F10 상세 설계 초안
claude Dec 2, 2026
120ba4c
[F10-0] F10 상세 설계 결정 기록
claude Dec 2, 2026
006a8ee
[F10-1] 필드 입력 형식과 숫자 범위 검사
claude Dec 2, 2026
9a1c6ca
[F10-1] 화면의 형식 검사를 엔진-UI 안 사본으로 옮김
claude Dec 2, 2026
0f8b3ac
[F10-2] 연결 선택(시도→시군구)과 행정구역 코드표
claude Dec 2, 2026
cb72d79
[F10-9] 리드 모바일 디자인을 F10 설계에 더함
claude Dec 2, 2026
90d5248
[F10-3] 글자 칸을 선택형으로 바꾸기, 담당자 사용자 고르기
claude Dec 2, 2026
f83fac3
[F10-5] 화면 나누기, 여러 건 담당자 변경, 중복 안내
claude Dec 2, 2026
cfa0e82
[F10-5] 담당자 변경 권한 선언과 화면 모델 access 테스트 맞춤
claude Dec 2, 2026
7ccf905
[F10-4] 진행 단계 막대와 단계별 핵심 항목
claude Dec 2, 2026
a79cf3f
[REQ-3] 거래처·연락처·기회·활동 필드와 코드 묶음을 세일즈포스 현행 화면에 맞춤 (A 설정)
claude Dec 2, 2026
7de5b61
[REQ-3] 코드 문구를 code.json 으로 옮기고, 새 관련 목록(활동·하위 거래처)에 맞춰 테스트 기대값 고침
claude Dec 2, 2026
4e6f1c7
Merge remote-tracking branch 'origin/main' into claude/project-thread…
claude Dec 2, 2026
af057c0
[F10-9] 엔진 화면의 좁은 화면 모양을 기존 리드 모바일 디자인으로
claude Dec 2, 2026
da18de5
[F10-6] 리드 필드·선택지·규칙·화면을 현행 매뉴얼에 맞춤
claude Dec 2, 2026
4f67b6c
[REQ-4] 엔진 레코드 삭제: API, 참조 막기, 상세 화면 삭제 버튼 (C 엔진 새 능력)
claude Dec 2, 2026
3411330
Merge branch 'claude/project-thread-5d5bok' of https://github.com/dio…
claude Dec 2, 2026
335deb4
[F10-7] 관리자 화면 전환: 편집기만 보이는 메뉴, 이 화면 편집, 업무 화면으로 돌아가기
claude Dec 2, 2026
a7af511
[REQ-4] 영업 담당(lead_sales) 권한에 거래처·연락처·기회·활동·리드 삭제를 줌 (행 권한 안의 자기 레코드)
claude Dec 2, 2026
fa41124
[REQ-4] 영업 담당 삭제 권한 넓힘을 guard-raises.json 에 선언하고, D08 테스트 예시를 삭제 권한이 …
claude Dec 2, 2026
ad2d684
[F10-8] F10 실제 DB 확인 스크립트와 합성 쌍둥이
claude Dec 2, 2026
afa6c41
[REQ-4] 엔진 보안 테스트를 영업 담당 삭제 권한에 맞춤 (위조 토큰 시험은 권한 없는 GUEST 로)
claude Dec 2, 2026
de996a2
[F10-8] F10 단계 보고
claude Dec 2, 2026
fbdb35a
[REQ-4] 병합된 #56 의 예외 선언(영업 담당 삭제 권한)을 guard-raises.json 에서 지움
claude Dec 2, 2026
9c5b2fa
Merge branch 'claude/project-thread-5d5bok' of https://github.com/dio…
claude Dec 2, 2026
37f1c41
[REQ-4] 병합된 #56 의 예외 선언(영업 담당 삭제 권한)을 guard-raises.json 에서 지움
claude Dec 2, 2026
ee5a27e
[F10-8] main 병합: 레코드 삭제(REQ-4)와 F10 합치기
claude Dec 2, 2026
90dc594
[F10-8] main 병합: REQ-4 예외 선언 지우기(#58)
claude Dec 2, 2026
8a9c342
[REQ-5] 거래처·활동 입력·상세 화면에 필드 배치(탭·구역, 화면 조각 파일), 이메일·웹 주소·우편번호·전화 형식
claude Dec 2, 2026
ad8aa4c
Merge remote-tracking branch 'origin/main' into claude/project-thread…
claude Dec 2, 2026
be37038
[REQ-5] 병합된 #57 의 F10-5 예외 선언을 지우고, 메타데이터 단계 올리기 테스트의 본문 한도를 300KB→60…
claude Dec 2, 2026
76b4f37
Merge branch 'claude/project-thread-5d5bok' of https://github.com/dio…
claude Dec 2, 2026
4c6c5e0
[REQ-6] 계산 필드(formula): 설정 계약, C11 검사, 엔진 계산, 저장 시 계산, 테스트
claude Dec 2, 2026
3d4a5ba
Merge branch 'claude/req6-formula' into claude/project-thread-5d5bok
claude Dec 2, 2026
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
12 changes: 8 additions & 4 deletions backend/src/database/crm-obj-store.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
// The record store of metadata objects (F2-4): runs the statements of crm-obj-sql.ts and turns rows back into values.
// The engine API decides what may be written; this layer only reads and writes inside the company and access condition.
import type { AccessPredicate, RecordValue } from '@dio-crm/engine';
import { formulaValues } from '@dio-crm/engine';
import type { FieldDef } from '@dio-crm/contracts/metadata';
import { MetaQuery, MetaTransactional } from './crm-meta-version-store';
import { PublishedCheck, assertStillPublished } from './crm-meta-published';
Expand All @@ -12,6 +13,9 @@ import { ListQuery, Page, RecordScope, Statement, countStatement, deleteStatemen

export interface StoredRecord { id: string; values: Record<string, RecordValue> }
const run = (query: MetaQuery, s: Statement) => query(s.text, s.params);
/** REQ-6: the written values with every calculated field worked out over the whole record after the write. */
const withFormulas = (object: ObjectShape, before: Record<string, RecordValue> | undefined, values: Record<string, RecordValue>) =>
({ ...values, ...formulaValues(object.fields, { ...(before ?? {}), ...values }) });

function valueOf(field: FieldDef, raw: unknown): RecordValue {
if (raw === null || raw === undefined) return null;
Expand Down Expand Up @@ -57,7 +61,7 @@ export function recordTx(query: MetaQuery, at: Date): RecordTx {
return row ? recordOf(object, row) : undefined;
},
async insert(object, scope, values) {
const id = Number((await run(query, insertStatement(object, scope, values, at))).recordset[0].id);
const id = Number((await run(query, insertStatement(object, scope, withFormulas(object, undefined, values), at))).recordset[0].id);
const created = await reread(object, scope, id);
await writeChanges(query, object, scope, id, undefined, created.values, at);
return created;
Expand All @@ -73,7 +77,7 @@ export function recordTx(query: MetaQuery, at: Date): RecordTx {
},
async update(object, scope, before, values) {
const id = Number(before.id);
await run(query, updateStatement(object, scope, id, values, at));
await run(query, updateStatement(object, scope, id, withFormulas(object, before.values, values), at));
const updated = await reread(object, scope, id);
await writeChanges(query, object, scope, id, before.values, updated.values, at);
return updated;
Expand Down Expand Up @@ -118,7 +122,7 @@ export class SqlObjectRecords {
insert(object: ObjectShape, scope: RecordScope, values: Record<string, RecordValue>, at: Date, check?: PublishedCheck): Promise<StoredRecord> {
return this.db.transaction(async query => {
if (check) await assertStillPublished(query, check, 'shared');
const id = Number((await run(query, insertStatement(object, scope, values, at))).recordset[0].id);
const id = Number((await run(query, insertStatement(object, scope, withFormulas(object, undefined, values), at))).recordset[0].id);
const [row] = (await run(query, getStatement(object, scope, { kind: 'all' }, id, false))).recordset;
const created = recordOf(object, row);
await writeChanges(query, object, scope, id, undefined, created.values, at);
Expand All @@ -138,7 +142,7 @@ export class SqlObjectRecords {
const [row] = (await run(query, getStatement(object, scope, predicate, id, true))).recordset;
if (!row) return undefined;
const before = recordOf(object, row);
await run(query, updateStatement(object, scope, id, decide(before), at));
await run(query, updateStatement(object, scope, id, withFormulas(object, before.values, decide(before)), at));
const [after] = (await run(query, getStatement(object, scope, { kind: 'all' }, id, false))).recordset;
const updated = recordOf(object, after);
await writeChanges(query, object, scope, id, before.values, updated.values, at);
Expand Down
37 changes: 37 additions & 0 deletions backend/src/modules/engine-api/engine-formula.spec.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,37 @@
// Calculated fields (REQ-6) through the API on the SQLite fake: stored on create and update, recomputed from the whole
// record when only an input changes, and refused when a client tries to write one.
import { caller, editJson, engineFixture, readMetadata } from '../../../test/support/engine-fixture';
import { EngineApiError } from './engine-records';

const u1 = caller('u1');
const FIELDS = 'metadata/objects/opportunity/fields.json';
/** The opportunity with two number inputs and two formulas over them (one reads the other). */
const withFormulas = () => editJson(readMetadata(), FIELDS, doc => {
const f = (key: string, type: string, formula?: unknown) => ({ aliases: [], key, labelKey: 'opportunity.field.amount', required: false, system: false, type, ...(formula ? { formula } : {}) });
doc.fields.push(
f('discount', 'decimal'),
f('net_amount', 'decimal', { op: 'sub', args: [{ field: 'amount' }, { field: 'discount' }] }),
f('discount_rate', 'decimal', { op: 'round', scale: 1, arg: { op: 'mul', args: [{ op: 'div', args: [{ field: 'discount' }, { field: 'amount' }] }, { value: 100 }] } }),
);
});

describe('engine API: calculated fields (REQ-6)', () => {
it('stores the formulas on create and recomputes them when one input changes', async () => {
const { api } = await engineFixture(withFormulas());
const acc = await api.create(u1, 'account', { name: 'A' });
const opp = await api.create(u1, 'opportunity', { name: 'O', account: acc.id, stage: 'DISCOVERY', amount: 1000, discount: 150 });
expect(opp.values).toMatchObject({ net_amount: 850, discount_rate: 15 });
const after = await api.update(u1, 'opportunity', opp.id, { discount: 250 });
expect(after.values).toMatchObject({ amount: 1000, net_amount: 750, discount_rate: 25 });
const cleared = await api.update(u1, 'opportunity', opp.id, { amount: null });
expect(cleared.values).toMatchObject({ net_amount: null, discount_rate: null });
});

it('refuses a client value for a calculated field', async () => {
const { api } = await engineFixture(withFormulas());
const acc = await api.create(u1, 'account', { name: 'A' });
const e = await api.create(u1, 'opportunity', { name: 'O', account: acc.id, stage: 'DISCOVERY', net_amount: 5 }).then(() => undefined, err => err);
expect(e).toBeInstanceOf(EngineApiError);
expect(e.errors).toEqual([{ code: 'READ_ONLY_FIELD', field: 'net_amount' }]);
});
});
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,7 @@ beforeAll(async () => {
.overrideProvider(MetadataAdminService).useValue({ admin }).compile();
app = moduleRef.createNestApplication();
// As main.ts: the staging route takes the whole metadata folder in one body.
configureMetadataBody(app, 300 * 1024);
configureMetadataBody(app, 600 * 1024);
await app.listen(0);
base = await app.getUrl();
jwt = moduleRef.get(JwtService);
Expand All @@ -46,7 +46,7 @@ describe('metadata versions are admin work', () => {
it('takes the whole repository metadata in one body, and refuses a body over the staging limit with 413', async () => {
expect(Buffer.byteLength(JSON.stringify({ files: readMetadata({ security: true }) }))).toBeGreaterThan(100 * 1024);
expect((await call('POST', V, token('admin', ADMIN), { files: readMetadata({ security: true }) })).status).toBe(201);
const huge = [{ path: 'metadata/terms/en-US/x.json', content: 'x'.repeat(310 * 1024) }];
const huge = [{ path: 'metadata/terms/en-US/x.json', content: 'x'.repeat(610 * 1024) }];
expect(await call('POST', V, token('admin', ADMIN), { files: huge })).toMatchObject({ status: 413, body: { error: 'PAYLOAD_TOO_LARGE' } });
});

Expand Down
3 changes: 3 additions & 0 deletions docs/framework/metamodel.md
Original file line number Diff line number Diff line change
Expand Up @@ -100,6 +100,8 @@ F10-1: 글자 필드에는 입력 형식 `format`(email, phone, url, bizno, zip,

F10-2: 코드 묶음은 위 묶음 `parentGroup` 을 가질 수 있다. 그러면 모든 값에 위 묶음의 코드 `parent` 가 있어야 하고, 위아래 연결이 돌면 안 된다. 선택형 필드의 `dependsOn` 은 같은 개체의 다른 선택형 필드이고, 그 필드의 코드 묶음이 이 필드 코드 묶음의 `parentGroup` 이어야 한다. 어기면 C10_PARENT 다. 엔진은 저장할 때 아래 값의 `parent` 가 위 값과 다르면 PARENT_MISMATCH 로 거절한다. 한 파일에 들어가지 않는 코드 묶음은 `codes/<묶음>/01.json, 02.json …` 으로 나눈다(각 파일은 값 일부를 가진 같은 묶음).

REQ-6: 숫자 필드(integer, decimal)는 `formula` 를 가질 수 있다. 식은 `{ "field": "<같은 개체의 숫자 필드>" }`, `{ "value": 숫자 }`, `{ "op": "add|sub|mul|div", "args": [식, 식, …] }`, `{ "op": "round", "arg": 식, "scale": 자리수 }` 로 짠다. 엔진은 저장할 때마다 기록 전체로 값을 계산해 함께 저장하고, 누구도 직접 쓸 수 없다(READ_ONLY_FIELD). 빈 값을 읽거나 0 으로 나누면 결과는 빈 값이다. 숫자 필드가 아니거나, 필수이거나, 읽는 필드가 같은 개체의 살아 있는 숫자 필드가 아니거나, 계산 필드끼리 돌고 돌면 C11_FORMULA 다. 다른 개체의 합계(롤업)는 아직 없다.

F10-4: 업무 흐름(workflow.json)의 `stateDetails` 는 상태마다 상세 화면 단계 막대 아래 보일 핵심 항목 `keyFields`(필드, 최대 8개)와 안내 문구 `guideKey`(용어 키, 선택)를 둔다. 상태가 `states` 에 없거나 두 번 나오거나, 필드가 개체에 없거나 두 번 나오면 W10_STATE_DETAIL 이다. 핵심 항목은 쓰이는 필드로 세어 숨길 수 없다.

F10-5: 한 파일에 들어가지 않는 화면은 `objects/<개체>/screens/<화면>/01.json, 02.json …` 으로 나눈다. 각 파일은 같은 화면의 화면 설정 전체 꼴이고, 읽을 때 번호 순서로 탭·구역·필드 배치를 이어 붙인다. 쓰는 쪽(화면 편집기, 필드 편집기, `filesFromBundle`)은 첫 파일에 탭과 구역을, 그 뒤에 필드 배치를 넣고, 한 파일에 들어가면 나누지 않는다. 한 파일과 조각 폴더를 함께 두거나 번호가 비면 F02 다.
Expand Down Expand Up @@ -139,6 +141,7 @@ F10-5: 한 파일에 들어가지 않는 화면은 `objects/<개체>/screens/<
| `B04_APPROVAL_PRIORITY_TIE` | error | `validateBundle` | 동작 "{action}" 에 붙은 결재 정책 "{policy}" 와 "{other}" 의 우선순위가 같습니다. 어느 것이 이길지 정해지도록 priority 를 다르게 적으세요. |
| `B05_APPROVAL_FIRST_STEP` | error | `validateBundle` | 결재선 "{route}" 의 첫 단계 결재자는 requester(기안자 조직의 조직장)여야 하고, 둘째 단계부터는 next 여야 합니다. |
| `C10_PARENT` | error | `validateBundle` | 연결 선택 "{name}" 이(가) 맞지 않습니다: {detail}. |
| `C11_FORMULA` | error | `validateBundle` | 계산 필드 "{name}" 의 식이 맞지 않습니다: {detail}. |
| `D01_REMOVED_WITHOUT_DEPRECATION` | error | `diffBundles` | {kind} "{key}" 이(가) 폐기 예정 표시 없이 사라졌습니다. |
| `D02_RENAMED_WITHOUT_ALIAS` | error | `diffBundles` | {kind} "{key}" 의 이름이 "{to}" 로 바뀐 것 같지만 옛 이름(alias)이 없습니다. |
| `D03_TYPE_CHANGED` | error | `diffBundles` | 필드 "{key}" 의 형식이 {from} 에서 {to} 로 바뀌었습니다. 허용된 넓힘이 아닙니다. |
Expand Down
39 changes: 1 addition & 38 deletions guard-raises.json
Original file line number Diff line number Diff line change
@@ -1,42 +1,5 @@
{
"schemaVersion": 1,
"note": "예외 선언. 기준선을 올리거나, legacy 목록에 파일을 넣거나, 테스트를 지우거나 줄이는 변경은 여기에 정확히 선언해야 보호 검사(--protect)를 통과한다. 선언은 PR 요약 맨 위에 나오고 사람이 확인한다. 병합된 뒤에는 지운다. 쓰는 법: docs/framework/ci-gates.md",
"raises": [
{
"rule": "P6",
"file": "metadata/security/profiles.json",
"from": null,
"to": {
"kind": "grant-widened",
"role": "BRANCH_MANAGER",
"gained": "lead.owner.change:run"
},
"reason": "F10 상세 설계 결정 3(dio 승인, 2026-12-02 04:28Z): 여러 건 담당자 변경 권한 lead.owner.change 를 관리자 묶음(lead_manager)에만 준다. 행 권한은 넓히지 않는다.",
"changeId": "F10-5"
},
{
"rule": "P6",
"file": "metadata/security/profiles.json",
"from": null,
"to": {
"kind": "grant-widened",
"role": "CRM_ADMIN",
"gained": "lead.owner.change:run"
},
"reason": "F10 상세 설계 결정 3(dio 승인, 2026-12-02 04:28Z): 여러 건 담당자 변경 권한 lead.owner.change 를 관리자 묶음(lead_manager)에만 준다. 행 권한은 넓히지 않는다.",
"changeId": "F10-5"
},
{
"rule": "P6",
"file": "metadata/security/profiles.json",
"from": null,
"to": {
"kind": "grant-widened",
"role": "HQ_MANAGER",
"gained": "lead.owner.change:run"
},
"reason": "F10 상세 설계 결정 3(dio 승인, 2026-12-02 04:28Z): 여러 건 담당자 변경 권한 lead.owner.change 를 관리자 묶음(lead_manager)에만 준다. 행 권한은 넓히지 않는다.",
"changeId": "F10-5"
}
]
"raises": []
}
1 change: 1 addition & 0 deletions metadata/objects/account/fields/01.json
Original file line number Diff line number Diff line change
Expand Up @@ -120,6 +120,7 @@
},
{
"aliases": [],
"format": "url",
"key": "website",
"labelKey": "account.field.website",
"maxLength": 255,
Expand Down
2 changes: 2 additions & 0 deletions metadata/objects/account/fields/02.json
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@
"fields": [
{
"aliases": [],
"format": "email",
"key": "tax_email",
"labelKey": "account.field.tax_email",
"maxLength": 255,
Expand All @@ -20,6 +21,7 @@
},
{
"aliases": [],
"format": "zip",
"key": "postal_code",
"labelKey": "account.field.postal_code",
"maxLength": 100,
Expand Down
91 changes: 0 additions & 91 deletions metadata/objects/account/screens/create.json

This file was deleted.

Loading
Loading