@eliceio/cdk-cli 0.0.0-stage → 0.1.0-alpha.2
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 +526 -2
- package/es/bin/index.d.ts +2 -0
- package/es/bin/index.js +10 -0
- package/es/cli.d.ts +5 -0
- package/es/cli.js +209 -0
- package/es/commands/build/index.d.ts +30 -0
- package/es/commands/build/index.js +163 -0
- package/es/commands/check/index.d.ts +9 -0
- package/es/commands/check/index.js +31 -0
- package/es/commands/create/index.d.ts +8 -0
- package/es/commands/create/index.js +22 -0
- package/es/commands/create/scaffold.d.ts +24 -0
- package/es/commands/create/scaffold.js +82 -0
- package/es/commands/dev/index.d.ts +6 -0
- package/es/commands/dev/index.js +40 -0
- package/es/commands/doctor/index.d.ts +34 -0
- package/es/commands/doctor/index.js +311 -0
- package/es/commands/guide/index.d.ts +29 -0
- package/es/commands/guide/index.js +120 -0
- package/es/commands/skill/index.d.ts +48 -0
- package/es/commands/skill/index.js +173 -0
- package/es/core/collect.d.ts +21 -0
- package/es/core/collect.js +89 -0
- package/es/core/config.d.ts +55 -0
- package/es/core/config.js +109 -0
- package/es/core/manifest.d.ts +15 -0
- package/es/core/manifest.js +43 -0
- package/es/core/minify.d.ts +18 -0
- package/es/core/minify.js +93 -0
- package/es/core/prepare.d.ts +12 -0
- package/es/core/prepare.js +86 -0
- package/es/core/protocol.d.ts +2 -0
- package/es/core/protocol.js +4 -0
- package/es/core/sandbox.d.ts +17 -0
- package/es/core/sandbox.js +182 -0
- package/es/core/zip.d.ts +4 -0
- package/es/core/zip.js +17 -0
- package/es/dev/grading.d.ts +15 -0
- package/es/dev/grading.js +37 -0
- package/es/dev/host-page.d.ts +7 -0
- package/es/dev/host-page.js +240 -0
- package/es/dev/inject.d.ts +8 -0
- package/es/dev/inject.js +38 -0
- package/es/dev/mock-api.d.ts +65 -0
- package/es/dev/mock-api.js +269 -0
- package/es/dev/server.d.ts +25 -0
- package/es/dev/server.js +309 -0
- package/es/engines/static/index.d.ts +3 -0
- package/es/engines/static/index.js +11 -0
- package/es/engines/types.d.ts +12 -0
- package/es/engines/vite/index.d.ts +2 -0
- package/es/engines/vite/index.js +4 -0
- package/es/index.d.ts +2 -0
- package/es/index.js +2 -0
- package/es/rules/check.d.ts +2 -0
- package/es/rules/check.js +282 -0
- package/es/rules/index.d.ts +8 -0
- package/es/rules/index.js +7 -0
- package/es/rules/manifest.d.ts +39 -0
- package/es/rules/manifest.js +168 -0
- package/es/rules/node.d.ts +11 -0
- package/es/rules/node.js +87 -0
- package/es/rules/path.d.ts +7 -0
- package/es/rules/path.js +35 -0
- package/es/rules/refs.d.ts +19 -0
- package/es/rules/refs.js +111 -0
- package/es/rules/skip.d.ts +12 -0
- package/es/rules/skip.js +55 -0
- package/es/rules/spec.d.ts +3 -0
- package/es/rules/spec.js +6 -0
- package/es/rules/types.d.ts +140 -0
- package/es/rules/unused.d.ts +7 -0
- package/es/rules/unused.js +21 -0
- package/es/rules/zip.d.ts +13 -0
- package/es/rules/zip.js +45 -0
- package/es/rules.json.js +3 -0
- package/es/types.d.ts +4 -0
- package/es/version.d.ts +2 -0
- package/es/version.js +7 -0
- package/guides/content-development.md +207 -0
- package/package.json +50 -3
- package/rules.json +608 -0
- package/skills/_shared/always.md +7 -0
- package/skills/elice-content-check/SKILL.md +22 -0
- package/skills/elice-content-create/SKILL.md +21 -0
- package/skills/elice-content-migrate/SKILL.md +21 -0
- package/templates/_shared/lib/cdk-mock.d.ts +94 -0
- package/templates/_shared/lib/cdk-mock.js +429 -0
- package/templates/_shared/lib/cdk.js +3 -0
- package/templates/_shared/lib/elice-content.css +262 -0
- package/templates/_shared/lib/elice-content.d.ts +123 -0
- package/templates/_shared/lib/elice-content.js +534 -0
- package/templates/_shared/lib/elice-tokens.css +446 -0
- package/templates/blank/README.md +64 -0
- package/templates/blank/commentary.txt +2 -0
- package/templates/blank/content.json +4 -0
- package/templates/blank/edit.html +15 -0
- package/templates/blank/elice.config.json +12 -0
- package/templates/blank/gitignore +3 -0
- package/templates/blank/index.html +15 -0
- package/templates/blank/instructor.html +15 -0
- package/templates/blank/screens/edit.js +21 -0
- package/templates/blank/screens/instructor.js +9 -0
- package/templates/blank/screens/learn.js +19 -0
- package/templates/blank/styles.css +1 -0
- package/templates/quiz/README.md +108 -0
- package/templates/quiz/commentary.txt +2 -0
- package/templates/quiz/content.json +81 -0
- package/templates/quiz/core/behaviors.d.ts +59 -0
- package/templates/quiz/core/behaviors.js +310 -0
- package/templates/quiz/core/dom.d.ts +13 -0
- package/templates/quiz/core/dom.js +83 -0
- package/templates/quiz/core/editor.d.ts +48 -0
- package/templates/quiz/core/editor.js +206 -0
- package/templates/quiz/core/markdown.d.ts +2 -0
- package/templates/quiz/core/markdown.js +84 -0
- package/templates/quiz/core/model.d.ts +20 -0
- package/templates/quiz/core/model.js +203 -0
- package/templates/quiz/edit.html +17 -0
- package/templates/quiz/elice.config.json +14 -0
- package/templates/quiz/gitignore +3 -0
- package/templates/quiz/grading.json +13 -0
- package/templates/quiz/index.html +17 -0
- package/templates/quiz/instructor.html +17 -0
- package/templates/quiz/screens/edit.js +139 -0
- package/templates/quiz/screens/instructor.js +27 -0
- package/templates/quiz/screens/learn.js +55 -0
- package/templates/quiz/styles.css +570 -0
- package/templates/quiz/ui/templates/choice.js +22 -0
- package/templates/quiz/ui/templates/edit.d.ts +13 -0
- package/templates/quiz/ui/templates/edit.js +183 -0
- package/templates/quiz/ui/templates/group.js +68 -0
- package/templates/quiz/ui/templates/index.d.ts +5 -0
- package/templates/quiz/ui/templates/index.js +17 -0
- package/templates/quiz/ui/templates/order.js +35 -0
- package/templates/quiz/ui/templates/page.js +29 -0
- package/templates/quiz/ui/templates/question.js +28 -0
- package/templates/quiz/ui/templates/text.js +16 -0
- package/templates/quiz/ui/texts.d.ts +3 -0
- package/templates/quiz/ui/texts.js +127 -0
- package/templates/quiz/ui/theme.css +50 -0
|
@@ -0,0 +1,182 @@
|
|
|
1
|
+
import { build } from 'esbuild';
|
|
2
|
+
import 'fflate';
|
|
3
|
+
import { resolveRef } from '../rules/path.js';
|
|
4
|
+
import { classifyRef } from '../rules/refs.js';
|
|
5
|
+
import { rules } from '../rules/spec.js';
|
|
6
|
+
|
|
7
|
+
/**
|
|
8
|
+
* LXP는 자료를 origin이 `null`인 sandbox iframe(`allow-scripts`)에서 열고, 자료 파일 서버는
|
|
9
|
+
* `Access-Control-Allow-Origin`을 주지 않는다. 그래서 CORS 모드로 받는 요청이 모두 막힌다:
|
|
10
|
+
* `<script type="module" src>` · 그 안의 `import` · `import()` · `fetch('content.json')`.
|
|
11
|
+
* (일반 `<script src>` · `<link rel="stylesheet">` · `<img>`는 CORS를 쓰지 않아 그대로 된다.)
|
|
12
|
+
*
|
|
13
|
+
* build는 zip에 넣기 전에 HTML마다:
|
|
14
|
+
* - `<script type="module" src="상대경로">`를 esbuild로 하나로 묶어 `<script type="module">` 본문으로 넣는다
|
|
15
|
+
* (zip 안 파일만 묶음. `import.meta.url`은 원래 파일 주소로 바꿔 상대경로 계산이 그대로 맞게).
|
|
16
|
+
* - zip 안 JSON(metadata.json 제외)을 페이지에 넣고 `fetch`가 그 주소를 받으면 넣어 둔 내용을 돌려준다.
|
|
17
|
+
* 원본 JS · JSON 파일은 zip에 그대로 둔다 (`ecdk dev` · 다른 참조용).
|
|
18
|
+
*/
|
|
19
|
+
const encoder = new TextEncoder();
|
|
20
|
+
const decoder = new TextDecoder();
|
|
21
|
+
const MODULE_SCRIPT = /<script\b([^>]*)>\s*<\/script\s*>/gi;
|
|
22
|
+
/** build가 묶어 넣은 모듈 스크립트 표시 (검사가 본문을 건너뜀) */
|
|
23
|
+
const BUNDLE_ATTR = 'data-ecdk-bundle';
|
|
24
|
+
function attr(attrs, name) {
|
|
25
|
+
const m = new RegExp(`\\b${name}\\s*=\\s*(?:"([^"]*)"|'([^']*)'|([^\\s>]+))`, 'i').exec(attrs);
|
|
26
|
+
return m ? m[1] ?? m[2] ?? m[3] : undefined;
|
|
27
|
+
}
|
|
28
|
+
/** HTML 안에 넣어도 태그가 끝나지 않게 */
|
|
29
|
+
const escapeInline = code => code.replace(/<\/(script)/gi, '<\\/$1');
|
|
30
|
+
/** zip 안 파일만 읽는 esbuild 플러그인. zip 밖(외부 주소 · 패키지 이름)은 오류 */
|
|
31
|
+
/** 페이지 폴더에서 zip 최상위로 올라가는 ../ (하위 폴더 페이지는 깊이만큼) */
|
|
32
|
+
const upFrom = page => '../'.repeat(page.split('/').length - 1);
|
|
33
|
+
function zipFiles(byPath, page) {
|
|
34
|
+
return {
|
|
35
|
+
name: 'ecdk-zip',
|
|
36
|
+
setup(b) {
|
|
37
|
+
b.onResolve({
|
|
38
|
+
filter: /.*/
|
|
39
|
+
}, args => {
|
|
40
|
+
// 진입 파일은 zip 경로로 넘긴다. 실행 폴더에 같은 이름의 파일이 있으면 esbuild가 앞에 ./를 붙여 넘기므로 뗀다
|
|
41
|
+
if (args.kind === 'entry-point') {
|
|
42
|
+
const path = args.path.replace(/^\.\//, '');
|
|
43
|
+
if (!byPath.has(path)) return {
|
|
44
|
+
errors: [{
|
|
45
|
+
text: `파일이 없습니다: ${args.path}`
|
|
46
|
+
}]
|
|
47
|
+
};
|
|
48
|
+
return {
|
|
49
|
+
path,
|
|
50
|
+
namespace: 'zip'
|
|
51
|
+
};
|
|
52
|
+
}
|
|
53
|
+
if (classifyRef(args.path) !== 'local') return {
|
|
54
|
+
errors: [{
|
|
55
|
+
text: `zip 안 파일만 묶을 수 있습니다: ${args.path}`
|
|
56
|
+
}]
|
|
57
|
+
};
|
|
58
|
+
const path = resolveRef(args.importer, args.path.replace(/[?#].*$/, ''));
|
|
59
|
+
if (path === null || !byPath.has(path)) return {
|
|
60
|
+
errors: [{
|
|
61
|
+
text: `파일이 없습니다: ${args.path} (${args.importer}에서)`
|
|
62
|
+
}]
|
|
63
|
+
};
|
|
64
|
+
return {
|
|
65
|
+
path,
|
|
66
|
+
namespace: 'zip'
|
|
67
|
+
};
|
|
68
|
+
});
|
|
69
|
+
b.onLoad({
|
|
70
|
+
filter: /.*/,
|
|
71
|
+
namespace: 'zip'
|
|
72
|
+
}, args => {
|
|
73
|
+
const file = byPath.get(args.path);
|
|
74
|
+
// 빈 내용으로 묶으면 build는 통과하고 LXP에서 화면이 뜨지 않으므로, 찾지 못하면 오류로 알린다
|
|
75
|
+
if (!file) return {
|
|
76
|
+
errors: [{
|
|
77
|
+
text: `파일이 없습니다: ${args.path}`
|
|
78
|
+
}]
|
|
79
|
+
};
|
|
80
|
+
const text = decoder.decode(file.data);
|
|
81
|
+
// 묶으면 import.meta.url이 페이지 주소가 된다. 원래 파일 주소로 두어 new URL('./x', import.meta.url)이 그대로 맞게.
|
|
82
|
+
// 하위 폴더 페이지는 깊이만큼 올라가고, <base href>와 상관없도록 페이지 주소(location.href) 기준으로
|
|
83
|
+
const contents = text.replaceAll('import.meta.url', `new URL(${JSON.stringify(upFrom(page) + args.path)}, location.href).href`);
|
|
84
|
+
return {
|
|
85
|
+
contents,
|
|
86
|
+
loader: /\.json$/i.test(args.path) ? 'json' : 'js'
|
|
87
|
+
};
|
|
88
|
+
});
|
|
89
|
+
}
|
|
90
|
+
};
|
|
91
|
+
}
|
|
92
|
+
async function bundle(entry, page, byPath, opts) {
|
|
93
|
+
const r = await build({
|
|
94
|
+
entryPoints: [entry],
|
|
95
|
+
...(opts.workingDir ? {
|
|
96
|
+
absWorkingDir: opts.workingDir
|
|
97
|
+
} : {}),
|
|
98
|
+
// minify를 켜면 실제로 실행되는 묶음 코드를 줄인다 (원본 JS는 이제 실행되지 않음)
|
|
99
|
+
minify: opts.minify === true,
|
|
100
|
+
bundle: true,
|
|
101
|
+
format: 'esm',
|
|
102
|
+
target: 'es2022',
|
|
103
|
+
write: false,
|
|
104
|
+
logLevel: 'silent',
|
|
105
|
+
plugins: [zipFiles(byPath, page)]
|
|
106
|
+
}).catch(e => {
|
|
107
|
+
throw new Error(`${entry}를 묶지 못했습니다: ${e.errors?.[0]?.text ?? e.message ?? 'esbuild 오류'}. LXP에서는 모듈 스크립트를 따로 받을 수 없어 build가 HTML 안에 묶어 넣습니다.`);
|
|
108
|
+
});
|
|
109
|
+
return r.outputFiles[0]?.text ?? '';
|
|
110
|
+
}
|
|
111
|
+
/** zip 안 JSON을 넣어 두고, 그 주소를 fetch하면 넣어 둔 내용을 돌려준다 */
|
|
112
|
+
function jsonPrelude(files, page) {
|
|
113
|
+
// zip 최상위 기준 경로 앞에 페이지 깊이만큼 ../를 붙여, 실행할 때 페이지 주소(location.href)로 풀어 비교한다.
|
|
114
|
+
// fetch 인자는 브라우저처럼 document.baseURI로 푼다
|
|
115
|
+
const up = upFrom(page);
|
|
116
|
+
const data = {};
|
|
117
|
+
for (const f of files) {
|
|
118
|
+
if (!/\.json$/i.test(f.path) || f.path === rules.manifest.file) continue;
|
|
119
|
+
try {
|
|
120
|
+
data[up + f.path] = JSON.parse(decoder.decode(f.data));
|
|
121
|
+
} catch {
|
|
122
|
+
// 형식이 틀린 JSON은 넣지 않는다 (검사가 알려 줌)
|
|
123
|
+
}
|
|
124
|
+
}
|
|
125
|
+
if (Object.keys(data).length === 0) return '';
|
|
126
|
+
const json = escapeInline(JSON.stringify(data));
|
|
127
|
+
return `<script>(()=>{const d=${json},b=document.baseURI,m=new Map(Object.entries(d).map(([k,v])=>[new URL(k,location.href).href,v])),f=window.fetch.bind(window);window.fetch=(i,o)=>{try{const u=new URL(typeof i==='string'||i instanceof URL?i:i.url,b).href.replace(/[?#].*$/,'');if(m.has(u)&&(!o||!o.method||o.method.toUpperCase()==='GET'))return Promise.resolve(new Response(JSON.stringify(m.get(u)),{headers:{'Content-Type':'application/json'}}))}catch{}return f(i,o)}})();</script>`;
|
|
128
|
+
}
|
|
129
|
+
/** HTML의 모듈 스크립트(src)를 묶어 본문으로 넣는다. 바뀐 파일만 새로 만들어 돌려준다 */
|
|
130
|
+
async function inlineModuleScripts(files, /** esbuild 작업 폴더 (기본: 실행 폴더). 테스트에서 프로젝트 폴더 안 실행을 흉내 낼 때 */
|
|
131
|
+
opts = {}) {
|
|
132
|
+
const byPath = new Map(files.map(f => [f.path, f]));
|
|
133
|
+
const pages = [];
|
|
134
|
+
const out = [];
|
|
135
|
+
for (const f of files) {
|
|
136
|
+
if (!/\.html?$/i.test(f.path)) {
|
|
137
|
+
out.push(f);
|
|
138
|
+
continue;
|
|
139
|
+
}
|
|
140
|
+
const html = decoder.decode(f.data);
|
|
141
|
+
// 주석 안의 스크립트(<!-- <script type="module" src="old.js"> -->)는 실행되지 않으므로 묶지 않는다
|
|
142
|
+
const comments = [...html.matchAll(/<!--[\s\S]*?-->/g)].map(c => [c.index, c.index + c[0].length]);
|
|
143
|
+
const inComment = at => comments.some(([from, to]) => at > from && at < to);
|
|
144
|
+
const scripts = [...html.matchAll(MODULE_SCRIPT)].filter(m => {
|
|
145
|
+
if (inComment(m.index)) return false;
|
|
146
|
+
const a = m[1] ?? '';
|
|
147
|
+
const src = attr(a, 'src');
|
|
148
|
+
return attr(a, 'type')?.toLowerCase() === 'module' && src && classifyRef(src) === 'local';
|
|
149
|
+
});
|
|
150
|
+
if (scripts.length === 0) {
|
|
151
|
+
out.push(f);
|
|
152
|
+
continue;
|
|
153
|
+
}
|
|
154
|
+
let next = '';
|
|
155
|
+
let last = 0;
|
|
156
|
+
for (const [i, m] of scripts.entries()) {
|
|
157
|
+
const src = attr(m[1] ?? '', 'src') ?? '';
|
|
158
|
+
const entry = resolveRef(f.path, src.replace(/[?#].*$/, ''));
|
|
159
|
+
if (entry === null || !byPath.has(entry)) throw new Error(`${f.path}의 모듈 스크립트 파일이 없습니다: ${src}`);
|
|
160
|
+
const code = await bundle(entry, f.path, byPath, opts);
|
|
161
|
+
next += html.slice(last, m.index);
|
|
162
|
+
if (i === 0) next += jsonPrelude(files, f.path);
|
|
163
|
+
// data-ecdk-bundle: 원본(ecdk-ignore 주석 포함)을 이미 검사했으니 zip 검사에서 이 본문은 다시 보지 않는다
|
|
164
|
+
next += `<script type="module" ${BUNDLE_ATTR}="${entry}">\n${escapeInline(code)}</script>`;
|
|
165
|
+
last = (m.index ?? 0) + m[0].length;
|
|
166
|
+
}
|
|
167
|
+
next += html.slice(last);
|
|
168
|
+
pages.push(f.path);
|
|
169
|
+
out.push({
|
|
170
|
+
...f,
|
|
171
|
+
data: encoder.encode(next)
|
|
172
|
+
});
|
|
173
|
+
}
|
|
174
|
+
return {
|
|
175
|
+
files: out,
|
|
176
|
+
report: {
|
|
177
|
+
pages
|
|
178
|
+
}
|
|
179
|
+
};
|
|
180
|
+
}
|
|
181
|
+
|
|
182
|
+
export { BUNDLE_ATTR, inlineModuleScripts };
|
package/es/core/zip.d.ts
ADDED
package/es/core/zip.js
ADDED
|
@@ -0,0 +1,17 @@
|
|
|
1
|
+
import { zipSync } from 'fflate';
|
|
2
|
+
|
|
3
|
+
/** 파일 시각을 고정하고 이름순으로 넣어 같은 입력이면 같은 zip이 나온다. 이름은 UTF-8 플래그와 함께 저장된다. */
|
|
4
|
+
const FIXED_MTIME = new Date(1980, 0, 1);
|
|
5
|
+
function createZip(files) {
|
|
6
|
+
const entries = {};
|
|
7
|
+
for (const f of [...files].sort((a, b) => a.path < b.path ? -1 : 1)) {
|
|
8
|
+
entries[f.path] = [f.data, {
|
|
9
|
+
mtime: FIXED_MTIME
|
|
10
|
+
}];
|
|
11
|
+
}
|
|
12
|
+
return zipSync(entries, {
|
|
13
|
+
level: 9
|
|
14
|
+
});
|
|
15
|
+
}
|
|
16
|
+
|
|
17
|
+
export { createZip };
|
|
@@ -0,0 +1,15 @@
|
|
|
1
|
+
import type { GradingConfig } from '../core/config.js';
|
|
2
|
+
/** 제출 응답 `{ is_correct, score }` (서버 설계 v25). 채점하지 않는 유형은 둘 다 null */
|
|
3
|
+
export interface GradeResult {
|
|
4
|
+
isCorrect: boolean | null;
|
|
5
|
+
score: number | null;
|
|
6
|
+
}
|
|
7
|
+
/** dev가 rubric(AI) 채점을 흉내 낼 때 돌려주는 점수. 서버는 요청 안에서 채점한다 */
|
|
8
|
+
export declare const RUBRIC_DEV_SCORE = 80;
|
|
9
|
+
/**
|
|
10
|
+
* elice-material `grading` 흉내 (서버 설계 v25). 채점은 모두 요청 안에서 끝난다 (rubric 포함).
|
|
11
|
+
* 템플릿 mock(`lib/cdk-mock.js`의 gradeLocally)과 같은 판정이고,
|
|
12
|
+
* pattern exact는 서버처럼 답 전체를 한 번에 비교한다 (부분 점수 없음).
|
|
13
|
+
* manual · none 등 자동 채점이 아닌 유형은 `{ isCorrect: null, score: null }`.
|
|
14
|
+
*/
|
|
15
|
+
export declare function grade(grading: GradingConfig | undefined, answer: unknown): GradeResult;
|
|
@@ -0,0 +1,37 @@
|
|
|
1
|
+
/** dev가 rubric(AI) 채점을 흉내 낼 때 돌려주는 점수. 서버는 요청 안에서 채점한다 */
|
|
2
|
+
const RUBRIC_DEV_SCORE = 80;
|
|
3
|
+
const normalize = v => typeof v === 'string' ? v.trim().toLowerCase() : Array.isArray(v) ? v.map(normalize).sort() : v && typeof v === 'object' ? Object.fromEntries(Object.keys(v).sort().map(k => [k, normalize(v[k])])) : v;
|
|
4
|
+
/**
|
|
5
|
+
* elice-material `grading` 흉내 (서버 설계 v25). 채점은 모두 요청 안에서 끝난다 (rubric 포함).
|
|
6
|
+
* 템플릿 mock(`lib/cdk-mock.js`의 gradeLocally)과 같은 판정이고,
|
|
7
|
+
* pattern exact는 서버처럼 답 전체를 한 번에 비교한다 (부분 점수 없음).
|
|
8
|
+
* manual · none 등 자동 채점이 아닌 유형은 `{ isCorrect: null, score: null }`.
|
|
9
|
+
*/
|
|
10
|
+
function grade(grading, answer) {
|
|
11
|
+
const type = grading?.type ?? 'on_submit';
|
|
12
|
+
if (type === 'on_access') return {
|
|
13
|
+
isCorrect: null,
|
|
14
|
+
score: null
|
|
15
|
+
};
|
|
16
|
+
if (type === 'on_submit') return {
|
|
17
|
+
isCorrect: true,
|
|
18
|
+
score: 100
|
|
19
|
+
};
|
|
20
|
+
if (type === 'pattern') {
|
|
21
|
+
const ok = grading?.match === 'regex' ? new RegExp(String(grading.answer_key)).test(String(answer)) : JSON.stringify(normalize(answer)) === JSON.stringify(normalize(grading?.answer_key));
|
|
22
|
+
return {
|
|
23
|
+
isCorrect: ok,
|
|
24
|
+
score: ok ? 100 : 0
|
|
25
|
+
};
|
|
26
|
+
}
|
|
27
|
+
if (type === 'rubric') return {
|
|
28
|
+
isCorrect: true,
|
|
29
|
+
score: RUBRIC_DEV_SCORE
|
|
30
|
+
};
|
|
31
|
+
return {
|
|
32
|
+
isCorrect: null,
|
|
33
|
+
score: null
|
|
34
|
+
};
|
|
35
|
+
}
|
|
36
|
+
|
|
37
|
+
export { RUBRIC_DEV_SCORE, grade };
|
|
@@ -0,0 +1,240 @@
|
|
|
1
|
+
import { DEV_MATERIAL_ID } from './mock-api.js';
|
|
2
|
+
|
|
3
|
+
/**
|
|
4
|
+
* LXP 학습 · 편집 페이지 흉내. 보기를 바꾸고 콘텐츠를 sandbox iframe으로 띄우며,
|
|
5
|
+
* @eliceio/cdk가 보내는 postMessage(settings-change · navigate-*)를 받아 처리한다
|
|
6
|
+
*/
|
|
7
|
+
function hostPage(opts) {
|
|
8
|
+
return `<!doctype html>
|
|
9
|
+
<html lang="ko">
|
|
10
|
+
<head>
|
|
11
|
+
<meta charset="utf-8">
|
|
12
|
+
<meta name="viewport" content="width=device-width, initial-scale=1">
|
|
13
|
+
<title>ecdk dev · ${opts.title.replace(/</g, '<')}</title>
|
|
14
|
+
<style>
|
|
15
|
+
:root { color-scheme: light; font-family: system-ui, -apple-system, 'Apple SD Gothic Neo', sans-serif; --line: #d8dce5; --accent: #6a3df0; }
|
|
16
|
+
* { box-sizing: border-box; }
|
|
17
|
+
body { margin: 0; height: 100vh; display: grid; grid-template-rows: auto auto auto 1fr; background: #f5f6f9; color: #1b2230; }
|
|
18
|
+
header { display: flex; flex-wrap: wrap; gap: 8px; align-items: center; padding: 8px 12px; background: #fff; border-bottom: 1px solid var(--line); font-size: 13px; }
|
|
19
|
+
header b { margin-right: 8px; }
|
|
20
|
+
.group { display: flex; gap: 4px; align-items: center; }
|
|
21
|
+
.sep { width: 1px; height: 20px; background: var(--line); margin: 0 4px; }
|
|
22
|
+
button { font: inherit; padding: 4px 10px; border: 1px solid var(--line); border-radius: 6px; background: #fff; cursor: pointer; }
|
|
23
|
+
button[aria-pressed="true"] { border-color: var(--accent); color: #fff; background: var(--accent); }
|
|
24
|
+
button:disabled { cursor: default; opacity: 0.5; }
|
|
25
|
+
#check { padding: 6px 12px; font-size: 12px; background: #fff; border-bottom: 1px solid var(--line); white-space: pre-wrap; font-family: ui-monospace, Menlo, monospace; }
|
|
26
|
+
#check.fail { background: #fdecea; color: #b3261e; }
|
|
27
|
+
#messages { margin: 0; padding: 4px 12px; font-size: 12px; background: #fafbfc; border-bottom: 1px solid var(--line); font-family: ui-monospace, Menlo, monospace; white-space: pre-wrap; min-height: 1.6em; }
|
|
28
|
+
main { display: flex; justify-content: center; padding: 12px; min-height: 0; }
|
|
29
|
+
iframe { width: 100%; max-width: var(--w, 100%); height: 100%; border: 1px solid var(--line); border-radius: 8px; background: #fff; }
|
|
30
|
+
.muted { color: #5b6577; }
|
|
31
|
+
label { display: inline-flex; gap: 4px; align-items: center; }
|
|
32
|
+
details#sdk-tools { position: relative; }
|
|
33
|
+
details#sdk-tools summary { display: inline-block; cursor: pointer; padding: 4px 10px; border: 1px solid var(--line); border-radius: 6px; list-style: none; user-select: none; }
|
|
34
|
+
details#sdk-tools summary::-webkit-details-marker { display: none; }
|
|
35
|
+
details#sdk-tools summary::before { content: '▸ '; }
|
|
36
|
+
details#sdk-tools[open] summary::before { content: '▾ '; }
|
|
37
|
+
details#sdk-tools[open] summary { border-color: var(--accent); color: var(--accent); }
|
|
38
|
+
.tools { position: absolute; top: calc(100% + 6px); left: 0; z-index: 10; display: grid; gap: 8px; width: max-content; max-width: calc(100vw - 32px); padding: 10px 12px; background: #fff; border: 1px solid var(--line); border-radius: 8px; box-shadow: 0 6px 20px rgba(27, 34, 48, 0.12); }
|
|
39
|
+
.tool { display: flex; flex-wrap: wrap; gap: 6px; align-items: center; }
|
|
40
|
+
.tool code { font-size: 12px; color: #5b6577; }
|
|
41
|
+
.tool b { margin: 0; }
|
|
42
|
+
[hidden] { display: none !important; }
|
|
43
|
+
</style>
|
|
44
|
+
</head>
|
|
45
|
+
<body>
|
|
46
|
+
<header>
|
|
47
|
+
<b>ecdk dev</b>
|
|
48
|
+
<div class="group" id="scenarios" role="group" aria-label="보기"></div>
|
|
49
|
+
<span class="sep"></span>
|
|
50
|
+
<div class="group" role="group" aria-label="화면 폭">
|
|
51
|
+
<button data-w="100%" aria-pressed="true">데스크톱</button><button data-w="720px">태블릿</button><button data-w="360px">모바일</button>
|
|
52
|
+
</div>
|
|
53
|
+
<span class="sep"></span>
|
|
54
|
+
<button id="save" hidden disabled title="편집 화면이 saveSettings()로 넘긴 설정을 자료에 저장합니다">저장</button>
|
|
55
|
+
<button id="reset" title="제출 기록 · 점수 · 완료, 편집 화면에서 저장한 내용을 지우고 처음 들어온 상태로 다시 엽니다">처음 상태로</button>
|
|
56
|
+
<span class="sep"></span>
|
|
57
|
+
<details id="sdk-tools">
|
|
58
|
+
<summary title="@eliceio/cdk가 LXP에서 받는 값을 바꿔 봅니다">SDK 기능</summary>
|
|
59
|
+
<div class="tools">
|
|
60
|
+
<div class="tool" role="group" aria-label="차시 이동" title="sdk.navigation.getHasPrevious() · getHasNext()가 받는 값. 끄면 첫 차시 · 마지막 차시처럼 동작합니다. previous() · next()는 dev에서 이동하지 않고 아래에 기록만 남깁니다">
|
|
61
|
+
<b>차시 이동</b> <code>sdk.navigation</code>
|
|
62
|
+
<label><input type="checkbox" id="has-prev" checked>이전 차시 있음</label>
|
|
63
|
+
<label><input type="checkbox" id="has-next" checked>다음 차시 있음</label>
|
|
64
|
+
</div>
|
|
65
|
+
<div class="tool" role="group" aria-label="저장 전 미리보기" title="LXP 편집 페이지의 미리보기처럼 토큰 없이 학생 화면을 엽니다. settings가 비어 content.json 기본 내용으로 뜨고, 제출은 기록되지 않습니다(늘 100점)">
|
|
66
|
+
<b>저장 전 미리보기</b> <code>#preview=1</code>
|
|
67
|
+
<button type="button" id="open-preview">열기</button>
|
|
68
|
+
</div>
|
|
69
|
+
</div>
|
|
70
|
+
</details>
|
|
71
|
+
<span class="muted" id="hint"></span>
|
|
72
|
+
</header>
|
|
73
|
+
<div id="check">검사 중…</div>
|
|
74
|
+
<pre id="messages" aria-live="polite"></pre>
|
|
75
|
+
<main><iframe id="content" sandbox="allow-scripts" title="콘텐츠"></iframe></main>
|
|
76
|
+
<script type="module">
|
|
77
|
+
const MATERIAL_ID = ${JSON.stringify(DEV_MATERIAL_ID)};
|
|
78
|
+
const SDK_SOURCE = 'eliceio-content-sdk';
|
|
79
|
+
// [보기, 이름, 화면, 주소 조각]. token은 흉내 서버가 발급, edit는 운영처럼 토큰 없음.
|
|
80
|
+
const SCENARIOS = [
|
|
81
|
+
['student', '학생', 'learn', 'token'],
|
|
82
|
+
['tutor', '튜터링', 'learn', 'token'],
|
|
83
|
+
['instructor', '교육자 화면', 'instructor', 'token'],
|
|
84
|
+
['edit', '내용 편집', 'edit', 'edit=1'],
|
|
85
|
+
];
|
|
86
|
+
// 토큰 없는 미리보기(#preview=1)는 settings가 비고 늘 100점이라 학생 보기와 구분이 안 돼 보기 버튼에서 빼고,
|
|
87
|
+
// SDK 기능 안의 도구로만 연다 (SDK · 키트는 이 상태를 따로 다룸: isDraftPreview, "기록되지 않음" 안내)
|
|
88
|
+
const PREVIEW = ['preview', '저장 전 미리보기', 'learn', 'preview=1'];
|
|
89
|
+
const scenarioOf = (name) => (name === PREVIEW[0] ? PREVIEW : SCENARIOS.find((s) => s[0] === name));
|
|
90
|
+
const frame = document.getElementById('content');
|
|
91
|
+
const previewEl = document.getElementById('open-preview');
|
|
92
|
+
const scenariosEl = document.getElementById('scenarios');
|
|
93
|
+
const saveEl = document.getElementById('save');
|
|
94
|
+
const messagesEl = document.getElementById('messages');
|
|
95
|
+
let state = { kind: 'material', entries: {}, contentBase: '' };
|
|
96
|
+
// 저장소가 막힌 브라우저에서도 화면이 떠야 하므로 sessionStorage는 모두 try로 감싼다
|
|
97
|
+
let current = 'student';
|
|
98
|
+
try { current = sessionStorage.getItem('ecdk-scenario') || 'student'; } catch {}
|
|
99
|
+
let pendingSettings = null;
|
|
100
|
+
|
|
101
|
+
function note(line) {
|
|
102
|
+
const lines = (messagesEl.textContent ? messagesEl.textContent.split('\\n') : []).slice(-4);
|
|
103
|
+
lines.push(new Date().toLocaleTimeString() + ' ' + line);
|
|
104
|
+
messagesEl.textContent = lines.join('\\n');
|
|
105
|
+
}
|
|
106
|
+
|
|
107
|
+
// 교육자 화면은 instructor 진입 파일이 없으면 학생 화면을 연다 (@eliceio/cdk resolveScreen과 같음)
|
|
108
|
+
const entryOf = (screen) => state.entries[screen] || (screen === 'instructor' ? state.entries.learn : undefined);
|
|
109
|
+
|
|
110
|
+
async function open(scenario) {
|
|
111
|
+
current = scenario;
|
|
112
|
+
try { sessionStorage.setItem('ecdk-scenario', scenario); } catch {}
|
|
113
|
+
for (const b of scenariosEl.children) b.setAttribute('aria-pressed', String(b.dataset.scenario === scenario));
|
|
114
|
+
previewEl.setAttribute('aria-pressed', String(scenario === PREVIEW[0]));
|
|
115
|
+
const [, label, screen, fragment] = scenarioOf(scenario);
|
|
116
|
+
const entry = entryOf(screen);
|
|
117
|
+
pendingSettings = null;
|
|
118
|
+
saveEl.hidden = scenario !== 'edit';
|
|
119
|
+
saveEl.disabled = true;
|
|
120
|
+
// 같은 파일이면 해시만 바뀌어 다시 로드되지 않으므로 매번 쿼리를 바꾼다
|
|
121
|
+
const url = state.contentBase + entry + '?ecdk=' + Date.now();
|
|
122
|
+
if (fragment === 'token') {
|
|
123
|
+
const { token } = await (await fetch('/__ecdk/token?scenario=' + scenario)).json();
|
|
124
|
+
frame.src = url + '#token=' + token;
|
|
125
|
+
} else {
|
|
126
|
+
frame.src = url + '#' + fragment;
|
|
127
|
+
}
|
|
128
|
+
document.getElementById('hint').textContent =
|
|
129
|
+
(state.kind === 'description' ? '문제 설명 · ' : '') + entry + ' · ' + (scenario === PREVIEW[0] ? label : scenario);
|
|
130
|
+
}
|
|
131
|
+
|
|
132
|
+
// 화면(learn · instructor · edit)은 검사기가 kindModes로 이미 걸러 state.entries에 켠 것만 온다.
|
|
133
|
+
// 문제 설명에는 학생 보기만 둔다: 다른 보기가 있는지는 서버 · LXP와 아직 정하지 않았다 (progress G81)
|
|
134
|
+
const available = (s) => entryOf(s[2]) && (state.kind !== 'description' || s[0] === 'student');
|
|
135
|
+
function renderScenarios() {
|
|
136
|
+
scenariosEl.replaceChildren(...SCENARIOS.filter(available).map(([scenario, label]) => {
|
|
137
|
+
const b = document.createElement('button');
|
|
138
|
+
b.textContent = label; b.dataset.scenario = scenario;
|
|
139
|
+
b.onclick = () => open(scenario);
|
|
140
|
+
return b;
|
|
141
|
+
}));
|
|
142
|
+
const keep = current === PREVIEW[0] ? available(PREVIEW) : SCENARIOS.some((s) => s[0] === current && available(s));
|
|
143
|
+
if (!keep) current = 'student';
|
|
144
|
+
}
|
|
145
|
+
|
|
146
|
+
function renderCheck(c) {
|
|
147
|
+
const el = document.getElementById('check');
|
|
148
|
+
el.className = c.ok ? '' : 'fail';
|
|
149
|
+
el.textContent = c.summary;
|
|
150
|
+
}
|
|
151
|
+
|
|
152
|
+
// @eliceio/cdk → 학습 · 편집 페이지. 보낸 창이 이 iframe이고 source가 SDK인 것만 받는다
|
|
153
|
+
window.addEventListener('message', (event) => {
|
|
154
|
+
if (event.source !== frame.contentWindow) return;
|
|
155
|
+
const data = event.data;
|
|
156
|
+
if (!data || typeof data !== 'object' || data.source !== SDK_SOURCE) return;
|
|
157
|
+
const payload = data.payload || {};
|
|
158
|
+
switch (data.type) {
|
|
159
|
+
case 'settings-change':
|
|
160
|
+
if (current !== 'edit' || !payload.settings || typeof payload.settings !== 'object') return;
|
|
161
|
+
pendingSettings = payload.settings;
|
|
162
|
+
saveEl.disabled = false;
|
|
163
|
+
note('settings-change: ' + JSON.stringify(pendingSettings) + ' (저장을 누르면 자료에 저장)');
|
|
164
|
+
return;
|
|
165
|
+
case 'navigate-prev':
|
|
166
|
+
note('navigate-prev: 이전 차시로 이동 (dev는 이동하지 않음)');
|
|
167
|
+
return;
|
|
168
|
+
case 'navigate-next':
|
|
169
|
+
note('navigate-next: 다음 차시로 이동 (dev는 이동하지 않음)');
|
|
170
|
+
return;
|
|
171
|
+
case 'navigate':
|
|
172
|
+
note('navigate: 차시 ' + payload.lecturePageId + '로 이동 (dev는 이동하지 않음)');
|
|
173
|
+
return;
|
|
174
|
+
case 'navigate-state-sync': {
|
|
175
|
+
const reply = {
|
|
176
|
+
source: SDK_SOURCE,
|
|
177
|
+
type: 'navigate-state',
|
|
178
|
+
materialId: data.materialId,
|
|
179
|
+
requestId: data.requestId,
|
|
180
|
+
payload: {
|
|
181
|
+
hasPreviousLecturePage: document.getElementById('has-prev').checked,
|
|
182
|
+
hasNextLecturePage: document.getElementById('has-next').checked,
|
|
183
|
+
},
|
|
184
|
+
};
|
|
185
|
+
// sandbox iframe의 출처는 null이라 '*'로만 보낼 수 있다
|
|
186
|
+
event.source.postMessage(reply, '*');
|
|
187
|
+
note('navigate-state-sync → ' + JSON.stringify(reply.payload));
|
|
188
|
+
return;
|
|
189
|
+
}
|
|
190
|
+
default:
|
|
191
|
+
note('알 수 없는 메시지: ' + data.type);
|
|
192
|
+
}
|
|
193
|
+
});
|
|
194
|
+
|
|
195
|
+
// 편집 페이지의 자료 저장: 마지막으로 받은 settings를 edit 토큰으로 PATCH
|
|
196
|
+
saveEl.onclick = async () => {
|
|
197
|
+
if (!pendingSettings) return;
|
|
198
|
+
const { token } = await (await fetch('/__ecdk/token?scenario=edit')).json();
|
|
199
|
+
const res = await fetch('/api/materials/' + MATERIAL_ID, {
|
|
200
|
+
method: 'PATCH',
|
|
201
|
+
headers: { Authorization: 'Bearer ' + token, 'Content-Type': 'application/json' },
|
|
202
|
+
body: JSON.stringify({ settings: pendingSettings }),
|
|
203
|
+
});
|
|
204
|
+
note(res.ok ? '저장했습니다. 다른 보기에서 material.settings로 받습니다' : '저장 실패 (' + res.status + ')');
|
|
205
|
+
if (res.ok) saveEl.disabled = true;
|
|
206
|
+
};
|
|
207
|
+
|
|
208
|
+
for (const b of document.querySelectorAll('[data-w]')) b.onclick = () => {
|
|
209
|
+
for (const x of document.querySelectorAll('[data-w]')) x.setAttribute('aria-pressed', String(x === b));
|
|
210
|
+
frame.style.setProperty('--w', b.dataset.w);
|
|
211
|
+
};
|
|
212
|
+
// SDK 기능 펼침 상태는 이 탭에서만 기억한다
|
|
213
|
+
const toolsEl = document.getElementById('sdk-tools');
|
|
214
|
+
try { toolsEl.open = sessionStorage.getItem('ecdk-sdk-tools') === '1'; } catch {}
|
|
215
|
+
toolsEl.ontoggle = () => { try { sessionStorage.setItem('ecdk-sdk-tools', toolsEl.open ? '1' : '0'); } catch {} };
|
|
216
|
+
// 드롭다운은 콘텐츠 위에 뜨므로 바깥 클릭 · 콘텐츠(iframe)로 포커스 이동 · Esc로 닫는다
|
|
217
|
+
document.addEventListener('click', (e) => { if (toolsEl.open && !toolsEl.contains(e.target)) toolsEl.open = false; });
|
|
218
|
+
window.addEventListener('blur', () => { if (toolsEl.open && document.activeElement === frame) toolsEl.open = false; });
|
|
219
|
+
document.addEventListener('keydown', (e) => {
|
|
220
|
+
if (e.key !== 'Escape' || !toolsEl.open) return;
|
|
221
|
+
toolsEl.open = false;
|
|
222
|
+
toolsEl.querySelector('summary').focus();
|
|
223
|
+
});
|
|
224
|
+
previewEl.onclick = () => { toolsEl.open = false; open(PREVIEW[0]); };
|
|
225
|
+
document.getElementById('reset').onclick = async () => { await fetch('/__ecdk/reset', { method: 'POST' }); open(current); };
|
|
226
|
+
|
|
227
|
+
state = await (await fetch('/__ecdk/state')).json();
|
|
228
|
+
renderScenarios(); renderCheck(state.check); open(current);
|
|
229
|
+
|
|
230
|
+
const events = new EventSource('/__ecdk/events');
|
|
231
|
+
events.addEventListener('reload', async (e) => {
|
|
232
|
+
state = JSON.parse(e.data);
|
|
233
|
+
renderScenarios(); renderCheck(state.check); open(current);
|
|
234
|
+
});
|
|
235
|
+
</script>
|
|
236
|
+
</body>
|
|
237
|
+
</html>`;
|
|
238
|
+
}
|
|
239
|
+
|
|
240
|
+
export { hostPage };
|
|
@@ -0,0 +1,8 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* dev에서만 콘텐츠 HTML의 <head> 맨 앞에 넣는 스크립트 (zip에는 들어가지 않음).
|
|
3
|
+
* - 키트가 흉내 서버를 쓰도록 API 주소를, 콘텐츠 주소를 직접 열어 mock으로 돌 때 쓸 로컬 채점 설정 주소를 알려 줌 (window.__ECDK_DEV__)
|
|
4
|
+
* - 콘솔 오류 · 처리 안 된 예외 · 불러오지 못한 파일을 터미널로 보냄
|
|
5
|
+
*/
|
|
6
|
+
export declare function devScript(hostOrigin: string): string;
|
|
7
|
+
/** <head> 바로 뒤(없으면 맨 앞)에 넣는다. 다른 스크립트보다 먼저 돌아야 오류를 놓치지 않는다 */
|
|
8
|
+
export declare function injectDevScript(html: string, hostOrigin: string): string;
|
package/es/dev/inject.js
ADDED
|
@@ -0,0 +1,38 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* dev에서만 콘텐츠 HTML의 <head> 맨 앞에 넣는 스크립트 (zip에는 들어가지 않음).
|
|
3
|
+
* - 키트가 흉내 서버를 쓰도록 API 주소를, 콘텐츠 주소를 직접 열어 mock으로 돌 때 쓸 로컬 채점 설정 주소를 알려 줌 (window.__ECDK_DEV__)
|
|
4
|
+
* - 콘솔 오류 · 처리 안 된 예외 · 불러오지 못한 파일을 터미널로 보냄
|
|
5
|
+
*/
|
|
6
|
+
function devScript(hostOrigin) {
|
|
7
|
+
const api = `${hostOrigin}/api`;
|
|
8
|
+
const log = `${hostOrigin}/__ecdk/log`;
|
|
9
|
+
const grading = `${hostOrigin}/__ecdk/grading`;
|
|
10
|
+
return `<script>
|
|
11
|
+
(() => {
|
|
12
|
+
window.__ECDK_DEV__ = { api: ${JSON.stringify(api)}, grading: ${JSON.stringify(grading)} };
|
|
13
|
+
const send = (level, message) => {
|
|
14
|
+
try { fetch(${JSON.stringify(log)}, { method: 'POST', body: JSON.stringify({ level, message: String(message), page: location.pathname.split('/').pop() }) }); } catch (e) {}
|
|
15
|
+
};
|
|
16
|
+
for (const level of ['error', 'warn']) {
|
|
17
|
+
const orig = console[level];
|
|
18
|
+
console[level] = (...args) => { send(level, args.map((a) => (a instanceof Error ? a.stack || a.message : typeof a === 'string' ? a : JSON.stringify(a))).join(' ')); orig.apply(console, args); };
|
|
19
|
+
}
|
|
20
|
+
addEventListener('error', (e) => {
|
|
21
|
+
const t = e.target;
|
|
22
|
+
if (t && t !== window && (t.src || t.href)) send('error', '불러오지 못함: ' + (t.src || t.href));
|
|
23
|
+
else send('error', (e.error && e.error.stack) || e.message);
|
|
24
|
+
}, true);
|
|
25
|
+
addEventListener('unhandledrejection', (e) => send('error', 'Promise 오류: ' + ((e.reason && e.reason.stack) || e.reason)));
|
|
26
|
+
})();
|
|
27
|
+
</script>`;
|
|
28
|
+
}
|
|
29
|
+
/** <head> 바로 뒤(없으면 맨 앞)에 넣는다. 다른 스크립트보다 먼저 돌아야 오류를 놓치지 않는다 */
|
|
30
|
+
function injectDevScript(html, hostOrigin) {
|
|
31
|
+
const script = devScript(hostOrigin);
|
|
32
|
+
const m = html.match(/<head\b[^>]*>/i);
|
|
33
|
+
if (!m || m.index === undefined) return script + html;
|
|
34
|
+
const at = m.index + m[0].length;
|
|
35
|
+
return html.slice(0, at) + script + html.slice(at);
|
|
36
|
+
}
|
|
37
|
+
|
|
38
|
+
export { devScript, injectDevScript };
|
|
@@ -0,0 +1,65 @@
|
|
|
1
|
+
import type { IncomingMessage, ServerResponse } from 'node:http';
|
|
2
|
+
import type { GradingConfig } from '../core/config.js';
|
|
3
|
+
/**
|
|
4
|
+
* elice-material API 흉내 (서버 설계 v25, @eliceio/cdk 1.x가 부르는 것만).
|
|
5
|
+
* 응답은 elib 형식 `{ data, meta }`, 필드는 snake_case. 오류는 `{ data: null, meta: { error } }`.
|
|
6
|
+
*/
|
|
7
|
+
export declare const DEV_MATERIAL_ID = "00000000-0000-4000-8000-0000000000e1";
|
|
8
|
+
export declare const STUDENT: {
|
|
9
|
+
account_id: number;
|
|
10
|
+
anonymous_id: string;
|
|
11
|
+
fullname: string;
|
|
12
|
+
};
|
|
13
|
+
export declare const MANAGER: {
|
|
14
|
+
account_id: number;
|
|
15
|
+
anonymous_id: string;
|
|
16
|
+
fullname: string;
|
|
17
|
+
};
|
|
18
|
+
export type MaterialScope = 'learn' | 'edit';
|
|
19
|
+
export type MaterialViewer = 'student' | 'instructor' | 'tutor';
|
|
20
|
+
/**
|
|
21
|
+
* dev 호스트 화면의 보기 (dev 전용). 토큰은 scope + viewer로 바뀐다.
|
|
22
|
+
* - student · instructor · tutor: `#token=…` (scope learn)
|
|
23
|
+
* - edit: 토큰 없이 `#edit=1`. edit 토큰은 호스트의 "저장" 버튼이 PATCH할 때만 쓴다
|
|
24
|
+
*/
|
|
25
|
+
export type DevScenario = 'student' | 'instructor' | 'tutor' | 'edit';
|
|
26
|
+
/** 토큰을 발급하는 보기 */
|
|
27
|
+
export type TokenScenario = DevScenario;
|
|
28
|
+
export declare const TOKEN_SCENARIOS: Readonly<Record<DevScenario, {
|
|
29
|
+
scope: MaterialScope;
|
|
30
|
+
viewer: MaterialViewer;
|
|
31
|
+
}>>;
|
|
32
|
+
export declare const isTokenScenario: (v: unknown) => v is TokenScenario;
|
|
33
|
+
export declare function issueToken(scenario: TokenScenario, ttlSeconds?: number): string;
|
|
34
|
+
interface Submission {
|
|
35
|
+
id: string;
|
|
36
|
+
material_version_id: string;
|
|
37
|
+
account_id: number;
|
|
38
|
+
created_at: string;
|
|
39
|
+
answer: unknown;
|
|
40
|
+
is_correct: boolean | null;
|
|
41
|
+
score: number | null;
|
|
42
|
+
}
|
|
43
|
+
interface Result {
|
|
44
|
+
score: number | null;
|
|
45
|
+
submit_count: number;
|
|
46
|
+
completed_at: string | null;
|
|
47
|
+
}
|
|
48
|
+
export interface MockState {
|
|
49
|
+
settings: Record<string, unknown>;
|
|
50
|
+
submissions: Submission[];
|
|
51
|
+
/** 계정별 결과. 자료당 하나이고 버전이 바뀌어도 지우지 않는다 */
|
|
52
|
+
results: Map<number, Result>;
|
|
53
|
+
/** 계정별 최근 1분 제출 시각 (rate limit) */
|
|
54
|
+
recent: Map<number, number[]>;
|
|
55
|
+
}
|
|
56
|
+
export declare const createState: () => MockState;
|
|
57
|
+
export interface MockApiOptions {
|
|
58
|
+
state: MockState;
|
|
59
|
+
getGrading: () => GradingConfig | undefined;
|
|
60
|
+
getEntries: () => Record<string, string>;
|
|
61
|
+
onEvent?: (message: string) => void;
|
|
62
|
+
}
|
|
63
|
+
/** `/api` 아래 요청을 처리한다 */
|
|
64
|
+
export declare function handleMockApi(req: IncomingMessage, res: ServerResponse, path: string, opts: MockApiOptions): Promise<void>;
|
|
65
|
+
export {};
|