dsh-postapi 0.0.0-stage → 0.0.1
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/LICENSE +201 -0
- package/README.md +139 -2
- package/cordis.patch.yml +3 -0
- package/dist/client.js +5651 -0
- package/docs/DETAIL.md +27 -0
- package/docs/apifox-design-spec.md +101 -0
- package/docs/apifox-research/analysis.md +254 -0
- package/docs/apifox-ui-delivery.md +150 -0
- package/docs/apifox-visual-parity-spec.md +353 -0
- package/docs/feature-matrix.md +112 -0
- package/docs/flow-reference/sequence-reference.html +163 -0
- package/docs/interface-contract-v2.md +175 -0
- package/docs/interface-contract.md +105 -0
- package/docs/nav-layout-v2-spec.md +107 -0
- package/docs/preview.svg +9 -0
- package/docs/probe-client.legacy.js +31 -0
- package/docs/rootcause-sidebar-vanish.md +95 -0
- package/docs/rootcause.md +86 -0
- package/docs/sidebar-notes.md +153 -0
- package/docs/ui-audit.md +197 -0
- package/docs/ui-notes.md +98 -0
- package/docs/v2-delivery.md +99 -0
- package/icon.svg +4 -0
- package/index.js +5 -0
- package/locale/en.json +7 -0
- package/locale/zh.json +7 -0
- package/package.json +73 -4
- package/src/client/index.js +132 -0
- package/src/client/jsx-shim.js +9 -0
- package/src/client/pages/__tests__/heights.test.js +135 -0
- package/src/client/pages/components/AssertTable.jsx +122 -0
- package/src/client/pages/components/BodyEditor.jsx +91 -0
- package/src/client/pages/components/EmptyState.jsx +52 -0
- package/src/client/pages/components/FolderTree.jsx +109 -0
- package/src/client/pages/components/JsonEditor.jsx +45 -0
- package/src/client/pages/components/ParamTable.jsx +226 -0
- package/src/client/pages/components/ResponsePanel.jsx +278 -0
- package/src/client/pages/components/ScriptPanel.jsx +99 -0
- package/src/client/pages/components/StatusPill.jsx +35 -0
- package/src/client/pages/components/__tests__/apifox-ui.test.js +291 -0
- package/src/client/pages/components/__tests__/pages-a.test.js +392 -0
- package/src/client/pages/components/__tests__/tree.test.js +379 -0
- package/src/client/pages/components/headerPresets.js +63 -0
- package/src/client/pages/debug.jsx +576 -0
- package/src/client/pages/design-tokens.css +2604 -0
- package/src/client/pages/doc.jsx +552 -0
- package/src/client/pages/env.jsx +378 -0
- package/src/client/pages/flow.jsx +349 -0
- package/src/client/pages/history.jsx +238 -0
- package/src/client/pages/import.jsx +396 -0
- package/src/client/pages/mock.jsx +316 -0
- package/src/client/pages/overview.jsx +348 -0
- package/src/client/pages/schema.jsx +317 -0
- package/src/client/pages/search.jsx +216 -0
- package/src/client/pages/sequence.jsx +344 -0
- package/src/client/pages/settings.jsx +205 -0
- package/src/client/pages/test.jsx +470 -0
- package/src/client/pages/theme.js +27 -0
- package/src/client/pages-entry.js +20 -0
- package/src/client/shell/ApiTitle.js +19 -0
- package/src/client/shell/Body.js +492 -0
- package/src/client/shell/definition.js +57 -0
- package/src/client/shell/locales.js +185 -0
- package/src/client/shell/menu.js +174 -0
- package/src/client/shell/registry.js +530 -0
- package/src/host/bridge.js +407 -0
- package/src/host/codegen.js +356 -0
- package/src/host/import-export.js +1044 -0
- package/src/host/index.js +102 -0
- package/src/host/mock-server.js +303 -0
- package/src/host/request.js +336 -0
- package/src/host/script-sandbox.js +272 -0
- package/src/host/storage.js +803 -0
- package/src/host/test-runner.js +126 -0
- package/src/host/variables.js +108 -0
|
@@ -0,0 +1,803 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* 存储服务 v2:契约 §2(schema v2 / 原子写 / 串行队列 / 损坏隔离 / .trash 备份)
|
|
3
|
+
* 与 §3 postapi.storage face。纯工厂 createStorageService(basePath) 便于测试注入临时目录。
|
|
4
|
+
* v2 相对 v1:index.json 带 version;project.json 带 schemaVersion 与 schemas/environments/
|
|
5
|
+
* globals/mocks/testCases/testScenarios/settings 等实体;endpoint 补全 protocol/responses/
|
|
6
|
+
* preProcessors/postProcessors/mock/tags/status;新增 14 个 face 方法。
|
|
7
|
+
* 既有 9 个方法签名与四条机制(原子写 / 串行队列 / 损坏隔离 / .trash)保持不变。
|
|
8
|
+
*/
|
|
9
|
+
import { promises as fs } from 'node:fs'
|
|
10
|
+
import os from 'node:os'
|
|
11
|
+
import path from 'node:path'
|
|
12
|
+
import { randomBytes } from 'node:crypto'
|
|
13
|
+
|
|
14
|
+
/**
|
|
15
|
+
* 默认数据根目录(可移植):POSTAPI_DATA_DIR 环境变量优先,否则落在用户主目录下的
|
|
16
|
+
* `.dsh/postapi`。不写死任何盘符——插件要能被任意用户装上就用,宿主侧可再用
|
|
17
|
+
* config.basePath / config.storage.basePath 覆盖到指定目录。
|
|
18
|
+
*/
|
|
19
|
+
export const DEFAULT_BASE_PATH = (() => {
|
|
20
|
+
const fromEnv = (process.env.POSTAPI_DATA_DIR || '').trim()
|
|
21
|
+
return fromEnv !== '' ? fromEnv : path.join(os.homedir(), '.dsh', 'postapi')
|
|
22
|
+
})()
|
|
23
|
+
export const SCHEMA_VERSION = 2
|
|
24
|
+
|
|
25
|
+
/** 契约 §2.2 settings 默认值。 */
|
|
26
|
+
export const DEFAULT_SETTINGS = {
|
|
27
|
+
mockPort: 4010,
|
|
28
|
+
proxyUrl: '',
|
|
29
|
+
requestTimeoutMs: 30000,
|
|
30
|
+
historyLimit: 200,
|
|
31
|
+
}
|
|
32
|
+
|
|
33
|
+
const DEFAULT_HISTORY_LIMIT = DEFAULT_SETTINGS.historyLimit
|
|
34
|
+
|
|
35
|
+
function nowIso() {
|
|
36
|
+
return new Date().toISOString()
|
|
37
|
+
}
|
|
38
|
+
|
|
39
|
+
/** 契约 §2.2 id 规则:前缀 + Date.now().toString(36) + 2 位随机。 */
|
|
40
|
+
export function makeId(prefix) {
|
|
41
|
+
return `${prefix}${Date.now().toString(36)}${randomBytes(1).toString('hex')}`
|
|
42
|
+
}
|
|
43
|
+
|
|
44
|
+
/** 同格式内避开已有 id(同毫秒高并发时随机位碰撞则重取)。 */
|
|
45
|
+
function uniqueId(prefix, existing) {
|
|
46
|
+
let id = makeId(prefix)
|
|
47
|
+
while (existing.has(id)) id = makeId(prefix)
|
|
48
|
+
return id
|
|
49
|
+
}
|
|
50
|
+
|
|
51
|
+
/** 契约 §2.2 endpoint 默认结构(v2 全字段;createdAt/updatedAt 由写路径显式赋)。 */
|
|
52
|
+
export const ENDPOINT_DEFAULTS = {
|
|
53
|
+
name: '',
|
|
54
|
+
folderId: null,
|
|
55
|
+
order: 0,
|
|
56
|
+
protocol: 'http',
|
|
57
|
+
method: 'GET',
|
|
58
|
+
url: '',
|
|
59
|
+
params: [],
|
|
60
|
+
pathParams: [],
|
|
61
|
+
headers: [],
|
|
62
|
+
cookies: [],
|
|
63
|
+
body: { type: 'none', content: '', schema: null, examples: [] },
|
|
64
|
+
auth: { type: 'none', token: '', username: '', password: '', key: '', value: '', addTo: 'header' },
|
|
65
|
+
responses: [],
|
|
66
|
+
preProcessors: [],
|
|
67
|
+
postProcessors: [],
|
|
68
|
+
mock: { enabled: false, delayMs: 0, rules: [] },
|
|
69
|
+
description: '',
|
|
70
|
+
tags: [],
|
|
71
|
+
status: 'developing',
|
|
72
|
+
}
|
|
73
|
+
|
|
74
|
+
/** 契约 §2.2 response 默认结构。 */
|
|
75
|
+
const RESPONSE_DEFAULTS = {
|
|
76
|
+
name: '',
|
|
77
|
+
code: 200,
|
|
78
|
+
contentType: 'application/json',
|
|
79
|
+
body: '',
|
|
80
|
+
schema: null,
|
|
81
|
+
headers: [],
|
|
82
|
+
enabled: true,
|
|
83
|
+
isDefault: false,
|
|
84
|
+
}
|
|
85
|
+
|
|
86
|
+
/** 契约 §2.2 schema 默认结构。 */
|
|
87
|
+
const SCHEMA_DEFAULTS = {
|
|
88
|
+
name: '',
|
|
89
|
+
folderId: null,
|
|
90
|
+
jsonSchema: {},
|
|
91
|
+
description: '',
|
|
92
|
+
}
|
|
93
|
+
|
|
94
|
+
/** 契约 §2.2 environment 默认结构。 */
|
|
95
|
+
const ENV_DEFAULTS = {
|
|
96
|
+
name: '',
|
|
97
|
+
baseUrl: '',
|
|
98
|
+
isDefault: false,
|
|
99
|
+
variables: [],
|
|
100
|
+
}
|
|
101
|
+
|
|
102
|
+
function emptyProject(id, name) {
|
|
103
|
+
const ts = nowIso()
|
|
104
|
+
return {
|
|
105
|
+
id,
|
|
106
|
+
name,
|
|
107
|
+
description: '',
|
|
108
|
+
createdAt: ts,
|
|
109
|
+
updatedAt: ts,
|
|
110
|
+
schemaVersion: SCHEMA_VERSION,
|
|
111
|
+
folders: [],
|
|
112
|
+
endpoints: [],
|
|
113
|
+
schemas: [],
|
|
114
|
+
environments: [],
|
|
115
|
+
globals: { variables: [] },
|
|
116
|
+
mocks: [],
|
|
117
|
+
testCases: [],
|
|
118
|
+
testScenarios: [],
|
|
119
|
+
flow: { name: '', steps: [] },
|
|
120
|
+
settings: { ...DEFAULT_SETTINGS },
|
|
121
|
+
}
|
|
122
|
+
}
|
|
123
|
+
|
|
124
|
+
/** 浅补默认字段;无缺失时返回原引用,避免无意义重写。 */
|
|
125
|
+
function withDefaults(item, defaults) {
|
|
126
|
+
if (!item || typeof item !== 'object') return { item: { ...defaults }, changed: true }
|
|
127
|
+
let changed = false
|
|
128
|
+
const out = { ...item }
|
|
129
|
+
for (const [k, v] of Object.entries(defaults)) {
|
|
130
|
+
if (out[k] === undefined) {
|
|
131
|
+
out[k] = v
|
|
132
|
+
changed = true
|
|
133
|
+
}
|
|
134
|
+
}
|
|
135
|
+
return { item: changed ? out : item, changed }
|
|
136
|
+
}
|
|
137
|
+
|
|
138
|
+
/** endpoint 归一:顶层 + body/auth/mock 三个嵌套对象都补默认(v1 数据缺这些字段)。 */
|
|
139
|
+
function normalizeEndpoint(ep) {
|
|
140
|
+
const base = withDefaults(ep, ENDPOINT_DEFAULTS)
|
|
141
|
+
const out = { ...base.item }
|
|
142
|
+
let changed = base.changed
|
|
143
|
+
for (const key of ['body', 'auth', 'mock']) {
|
|
144
|
+
const nested = withDefaults(out[key], ENDPOINT_DEFAULTS[key])
|
|
145
|
+
if (nested.changed) {
|
|
146
|
+
out[key] = nested.item
|
|
147
|
+
changed = true
|
|
148
|
+
}
|
|
149
|
+
}
|
|
150
|
+
return { item: changed ? out : ep, changed }
|
|
151
|
+
}
|
|
152
|
+
|
|
153
|
+
/** project 归一:v1 project.json(无 schemaVersion / settings / schemas 等)升级到 v2 结构。 */
|
|
154
|
+
function normalizeProject(raw) {
|
|
155
|
+
let changed = false
|
|
156
|
+
const project = { ...raw }
|
|
157
|
+
if (project.schemaVersion !== SCHEMA_VERSION) {
|
|
158
|
+
project.schemaVersion = SCHEMA_VERSION
|
|
159
|
+
changed = true
|
|
160
|
+
}
|
|
161
|
+
const blanks = {
|
|
162
|
+
description: '',
|
|
163
|
+
folders: [],
|
|
164
|
+
endpoints: [],
|
|
165
|
+
schemas: [],
|
|
166
|
+
environments: [],
|
|
167
|
+
globals: { variables: [] },
|
|
168
|
+
mocks: [],
|
|
169
|
+
testCases: [],
|
|
170
|
+
testScenarios: [],
|
|
171
|
+
flow: { name: '', steps: [] },
|
|
172
|
+
}
|
|
173
|
+
for (const [k, v] of Object.entries(blanks)) {
|
|
174
|
+
if (project[k] === undefined || project[k] === null) {
|
|
175
|
+
project[k] = v
|
|
176
|
+
changed = true
|
|
177
|
+
}
|
|
178
|
+
}
|
|
179
|
+
const settings = { ...DEFAULT_SETTINGS, ...(project.settings || {}) }
|
|
180
|
+
if (JSON.stringify(settings) !== JSON.stringify(project.settings)) {
|
|
181
|
+
project.settings = settings
|
|
182
|
+
changed = true
|
|
183
|
+
}
|
|
184
|
+
const endpoints = project.endpoints.map((ep) => normalizeEndpoint(ep))
|
|
185
|
+
if (endpoints.some((r) => r.changed)) {
|
|
186
|
+
project.endpoints = endpoints.map((r) => r.item)
|
|
187
|
+
changed = true
|
|
188
|
+
}
|
|
189
|
+
return { project: changed ? project : raw, changed }
|
|
190
|
+
}
|
|
191
|
+
|
|
192
|
+
function upsertById(list, item) {
|
|
193
|
+
const i = list.findIndex((x) => x.id === item.id)
|
|
194
|
+
if (i >= 0) list[i] = item
|
|
195
|
+
else list.push(item)
|
|
196
|
+
}
|
|
197
|
+
|
|
198
|
+
/** 返回给调用方的副本:search 结果不暴露内部引用。 */
|
|
199
|
+
function clone(v) {
|
|
200
|
+
return JSON.parse(JSON.stringify(v))
|
|
201
|
+
}
|
|
202
|
+
|
|
203
|
+
function asVariables(globals) {
|
|
204
|
+
if (Array.isArray(globals)) return { variables: globals }
|
|
205
|
+
if (globals && typeof globals === 'object') return { variables: [], ...globals }
|
|
206
|
+
return { variables: [] }
|
|
207
|
+
}
|
|
208
|
+
|
|
209
|
+
export function createStorageService(basePath = DEFAULT_BASE_PATH) {
|
|
210
|
+
// 进程内 promise 串行队列:所有写操作排队执行,并发写不互相覆盖(契约 §2)。
|
|
211
|
+
let tail = Promise.resolve()
|
|
212
|
+
const enqueue = (job) => {
|
|
213
|
+
const run = tail.then(job, job)
|
|
214
|
+
tail = run.then(() => {}, () => {})
|
|
215
|
+
return run
|
|
216
|
+
}
|
|
217
|
+
|
|
218
|
+
const indexFile = () => path.join(basePath, 'index.json')
|
|
219
|
+
const projectFile = (id) => path.join(basePath, id, 'project.json')
|
|
220
|
+
const historyFile = (id) => path.join(basePath, id, 'history.json')
|
|
221
|
+
|
|
222
|
+
/** 原子写:tmp 文件 + fs.rename(契约 §2)。 */
|
|
223
|
+
async function atomicWrite(file, data) {
|
|
224
|
+
await fs.mkdir(path.dirname(file), { recursive: true })
|
|
225
|
+
const tmp = `${file}.tmp`
|
|
226
|
+
await fs.writeFile(tmp, data)
|
|
227
|
+
await fs.rename(tmp, file)
|
|
228
|
+
}
|
|
229
|
+
|
|
230
|
+
async function readJson(file) {
|
|
231
|
+
return JSON.parse(await fs.readFile(file, 'utf8'))
|
|
232
|
+
}
|
|
233
|
+
|
|
234
|
+
/**
|
|
235
|
+
* 读 index.json:ENOENT → 空库(version 2);v1(无 version)自动补 version:2 并标记 upgraded,
|
|
236
|
+
* 由调用方决定是否落盘升级(listProjects 入队写回)。
|
|
237
|
+
*/
|
|
238
|
+
async function readIndexState() {
|
|
239
|
+
try {
|
|
240
|
+
const index = await readJson(indexFile())
|
|
241
|
+
let upgraded = false
|
|
242
|
+
if (index.version !== SCHEMA_VERSION) {
|
|
243
|
+
index.version = SCHEMA_VERSION
|
|
244
|
+
upgraded = true
|
|
245
|
+
}
|
|
246
|
+
if (!Array.isArray(index.projects)) {
|
|
247
|
+
index.projects = []
|
|
248
|
+
upgraded = true
|
|
249
|
+
}
|
|
250
|
+
return { index, upgraded }
|
|
251
|
+
} catch (err) {
|
|
252
|
+
if (err.code === 'ENOENT') return { index: { version: SCHEMA_VERSION, projects: [] }, upgraded: false }
|
|
253
|
+
throw err
|
|
254
|
+
}
|
|
255
|
+
}
|
|
256
|
+
|
|
257
|
+
async function readIndex() {
|
|
258
|
+
return (await readIndexState()).index
|
|
259
|
+
}
|
|
260
|
+
|
|
261
|
+
const writeIndex = (index) => atomicWrite(indexFile(), JSON.stringify(index, null, 2))
|
|
262
|
+
|
|
263
|
+
/**
|
|
264
|
+
* 读取 project.json 并归一为 v2。损坏(解析失败)→ 原文件改名 .corrupt-<ts> 后返回待重建的空结构;
|
|
265
|
+
* ENOENT → null。不在本函数内落盘,由调用方决定写路径(队列内直写 / getProject 入队)。
|
|
266
|
+
*/
|
|
267
|
+
async function loadProjectData(id) {
|
|
268
|
+
const file = projectFile(id)
|
|
269
|
+
try {
|
|
270
|
+
const raw = await readJson(file)
|
|
271
|
+
const { project, changed } = normalizeProject(raw)
|
|
272
|
+
return { data: project, upgrade: changed }
|
|
273
|
+
} catch (err) {
|
|
274
|
+
if (err.code === 'ENOENT') return null
|
|
275
|
+
const corruptName = `${file}.corrupt-${Date.now()}`
|
|
276
|
+
await fs.rename(file, corruptName).catch(() => {})
|
|
277
|
+
// name 尽量从 index.json 找回,减少损坏重建的信息损失
|
|
278
|
+
let name = ''
|
|
279
|
+
try {
|
|
280
|
+
const index = await readIndex()
|
|
281
|
+
name = (index.projects.find((p) => p.id === id) || {}).name || ''
|
|
282
|
+
} catch {
|
|
283
|
+
// 找回失败不阻塞重建
|
|
284
|
+
}
|
|
285
|
+
return { data: emptyProject(id, name), rebuild: true }
|
|
286
|
+
}
|
|
287
|
+
}
|
|
288
|
+
|
|
289
|
+
const saveProject = (project) =>
|
|
290
|
+
atomicWrite(projectFile(project.id), JSON.stringify(project, null, 2))
|
|
291
|
+
|
|
292
|
+
/** 队列内取项目:损坏时直接重建落盘,v1 结构时升级落盘。 */
|
|
293
|
+
async function loadProjectForWrite(id) {
|
|
294
|
+
const loaded = await loadProjectData(id)
|
|
295
|
+
if (!loaded) throw new Error(`project not found: ${id}`)
|
|
296
|
+
if (loaded.rebuild || loaded.upgrade) await saveProject(loaded.data)
|
|
297
|
+
return loaded.data
|
|
298
|
+
}
|
|
299
|
+
|
|
300
|
+
/** 读 history.json:ENOENT → 空历史;损坏 → 隔离 .corrupt-<ts> 后返回空历史。 */
|
|
301
|
+
async function readHistory(id) {
|
|
302
|
+
const file = historyFile(id)
|
|
303
|
+
try {
|
|
304
|
+
const data = await readJson(file)
|
|
305
|
+
return { entries: Array.isArray(data.entries) ? data.entries : [] }
|
|
306
|
+
} catch (err) {
|
|
307
|
+
if (err.code === 'ENOENT') return { entries: [] }
|
|
308
|
+
await fs.rename(file, `${file}.corrupt-${Date.now()}`).catch(() => {})
|
|
309
|
+
return { entries: [] }
|
|
310
|
+
}
|
|
311
|
+
}
|
|
312
|
+
|
|
313
|
+
return {
|
|
314
|
+
async listProjects() {
|
|
315
|
+
const { index, upgraded } = await readIndexState()
|
|
316
|
+
// v1 index.json 读入后升级落盘(契约 §2.1:自动补 version: 2 并保留 projects)
|
|
317
|
+
if (upgraded) await enqueue(() => writeIndex(index))
|
|
318
|
+
return index.projects
|
|
319
|
+
},
|
|
320
|
+
|
|
321
|
+
async createProject(name) {
|
|
322
|
+
return enqueue(async () => {
|
|
323
|
+
const project = emptyProject(uniqueId('proj_', new Set()), name)
|
|
324
|
+
await saveProject(project)
|
|
325
|
+
const index = await readIndex()
|
|
326
|
+
index.projects.push({ id: project.id, name: project.name, updatedAt: project.updatedAt })
|
|
327
|
+
await writeIndex(index)
|
|
328
|
+
return project
|
|
329
|
+
})
|
|
330
|
+
},
|
|
331
|
+
|
|
332
|
+
async renameProject(id, name) {
|
|
333
|
+
return enqueue(async () => {
|
|
334
|
+
const project = await loadProjectForWrite(id)
|
|
335
|
+
project.name = name
|
|
336
|
+
project.updatedAt = nowIso()
|
|
337
|
+
await saveProject(project)
|
|
338
|
+
const index = await readIndex()
|
|
339
|
+
const entry = index.projects.find((p) => p.id === id)
|
|
340
|
+
if (entry) {
|
|
341
|
+
entry.name = name
|
|
342
|
+
entry.updatedAt = project.updatedAt
|
|
343
|
+
}
|
|
344
|
+
await writeIndex(index)
|
|
345
|
+
return project
|
|
346
|
+
})
|
|
347
|
+
},
|
|
348
|
+
|
|
349
|
+
async deleteProject(id) {
|
|
350
|
+
return enqueue(async () => {
|
|
351
|
+
const dir = path.join(basePath, id)
|
|
352
|
+
// 契约 §2:整目录先复制到 .trash/<projectId>-<ts>/ 再删除
|
|
353
|
+
const trashDir = path.join(basePath, '.trash', `${id}-${Date.now()}`)
|
|
354
|
+
await fs.mkdir(path.dirname(trashDir), { recursive: true })
|
|
355
|
+
await fs.cp(dir, trashDir, { recursive: true, force: true })
|
|
356
|
+
await fs.rm(dir, { recursive: true, force: true })
|
|
357
|
+
const index = await readIndex()
|
|
358
|
+
index.projects = index.projects.filter((p) => p.id !== id)
|
|
359
|
+
await writeIndex(index)
|
|
360
|
+
return { id }
|
|
361
|
+
})
|
|
362
|
+
},
|
|
363
|
+
|
|
364
|
+
async getProject(id) {
|
|
365
|
+
const loaded = await loadProjectData(id)
|
|
366
|
+
if (!loaded) throw new Error(`project not found: ${id}`)
|
|
367
|
+
// 损坏重建 / v1→v2 升级都落盘(读路径不入队直写,避免与写路径竞争)
|
|
368
|
+
if (loaded.rebuild || loaded.upgrade) await enqueue(() => saveProject(loaded.data))
|
|
369
|
+
return loaded.data
|
|
370
|
+
},
|
|
371
|
+
|
|
372
|
+
async saveEndpoint(projectId, endpoint) {
|
|
373
|
+
return enqueue(async () => {
|
|
374
|
+
const project = await loadProjectForWrite(projectId)
|
|
375
|
+
const ts = nowIso()
|
|
376
|
+
if (endpoint && endpoint.id != null) {
|
|
377
|
+
// 有 id 覆盖:保留 createdAt,更新 updatedAt(契约 §2)
|
|
378
|
+
const prev = project.endpoints.find((e) => e.id === endpoint.id)
|
|
379
|
+
const saved = {
|
|
380
|
+
...withEndpointDefaults(endpoint, prev),
|
|
381
|
+
createdAt: prev ? prev.createdAt : ts,
|
|
382
|
+
updatedAt: ts,
|
|
383
|
+
}
|
|
384
|
+
upsertById(project.endpoints, saved)
|
|
385
|
+
project.updatedAt = ts
|
|
386
|
+
await saveProject(project)
|
|
387
|
+
return saved
|
|
388
|
+
}
|
|
389
|
+
const saved = {
|
|
390
|
+
...withEndpointDefaults(endpoint, null),
|
|
391
|
+
id: uniqueId('ep_', new Set(project.endpoints.map((e) => e.id))),
|
|
392
|
+
order: endpoint && endpoint.order != null ? Number(endpoint.order) : project.endpoints.length,
|
|
393
|
+
createdAt: ts,
|
|
394
|
+
updatedAt: ts,
|
|
395
|
+
}
|
|
396
|
+
project.endpoints.push(saved)
|
|
397
|
+
project.updatedAt = ts
|
|
398
|
+
await saveProject(project)
|
|
399
|
+
return saved
|
|
400
|
+
})
|
|
401
|
+
},
|
|
402
|
+
|
|
403
|
+
async deleteEndpoint(projectId, endpointId) {
|
|
404
|
+
return enqueue(async () => {
|
|
405
|
+
const project = await loadProjectForWrite(projectId)
|
|
406
|
+
project.endpoints = project.endpoints.filter((e) => e.id !== endpointId)
|
|
407
|
+
project.updatedAt = nowIso()
|
|
408
|
+
await saveProject(project)
|
|
409
|
+
return { id: endpointId }
|
|
410
|
+
})
|
|
411
|
+
},
|
|
412
|
+
|
|
413
|
+
async saveFolder(projectId, folder) {
|
|
414
|
+
return enqueue(async () => {
|
|
415
|
+
const project = await loadProjectForWrite(projectId)
|
|
416
|
+
const saved = folder && folder.id != null
|
|
417
|
+
? { name: '', parentId: null, order: 0, ...folder }
|
|
418
|
+
: {
|
|
419
|
+
name: '',
|
|
420
|
+
parentId: null,
|
|
421
|
+
...folder,
|
|
422
|
+
id: uniqueId('fld_', new Set(project.folders.map((f) => f.id))),
|
|
423
|
+
order: folder && folder.order != null ? Number(folder.order) : project.folders.length,
|
|
424
|
+
}
|
|
425
|
+
upsertById(project.folders, saved)
|
|
426
|
+
project.updatedAt = nowIso()
|
|
427
|
+
await saveProject(project)
|
|
428
|
+
return saved
|
|
429
|
+
})
|
|
430
|
+
},
|
|
431
|
+
|
|
432
|
+
async deleteFolder(projectId, folderId) {
|
|
433
|
+
return enqueue(async () => {
|
|
434
|
+
const project = await loadProjectForWrite(projectId)
|
|
435
|
+
project.folders = project.folders.filter((f) => f.id !== folderId)
|
|
436
|
+
// 契约 §2:子项 folderId/parentId 置 null,不级联删
|
|
437
|
+
for (const ep of project.endpoints) if (ep.folderId === folderId) ep.folderId = null
|
|
438
|
+
for (const f of project.folders) if (f.parentId === folderId) f.parentId = null
|
|
439
|
+
for (const s of project.schemas) if (s.folderId === folderId) s.folderId = null
|
|
440
|
+
project.updatedAt = nowIso()
|
|
441
|
+
await saveProject(project)
|
|
442
|
+
return { id: folderId }
|
|
443
|
+
})
|
|
444
|
+
},
|
|
445
|
+
|
|
446
|
+
/** 契约 §3:目录/接口移动与排序(endpoint 的 parentId 落在 folderId 上)。 */
|
|
447
|
+
async moveNode(projectId, move) {
|
|
448
|
+
return enqueue(async () => {
|
|
449
|
+
const project = await loadProjectForWrite(projectId)
|
|
450
|
+
const m = move && typeof move === 'object' ? move : {}
|
|
451
|
+
const id = m.id == null ? '' : String(m.id)
|
|
452
|
+
if (id === '') throw new Error('moveNode: id is required')
|
|
453
|
+
const parentId = m.parentId == null || m.parentId === '' ? null : String(m.parentId)
|
|
454
|
+
// 目标不存在时幂等返回归一结果(契约未定义错误语义,桥侧通用透传不应因此 500)
|
|
455
|
+
if (m.kind === 'endpoint') {
|
|
456
|
+
const ep = project.endpoints.find((e) => e.id === id)
|
|
457
|
+
if (!ep) return { kind: 'endpoint', id, parentId, order: m.order != null ? Number(m.order) : 0 }
|
|
458
|
+
ep.folderId = parentId
|
|
459
|
+
if (m.order != null) ep.order = Number(m.order)
|
|
460
|
+
project.updatedAt = nowIso()
|
|
461
|
+
await saveProject(project)
|
|
462
|
+
return ep
|
|
463
|
+
}
|
|
464
|
+
if (m.kind !== 'folder') throw new Error(`moveNode: unknown kind ${m.kind}`)
|
|
465
|
+
const folder = project.folders.find((f) => f.id === id)
|
|
466
|
+
if (!folder) return { kind: 'folder', id, parentId, order: m.order != null ? Number(m.order) : 0 }
|
|
467
|
+
folder.parentId = parentId
|
|
468
|
+
if (m.order != null) folder.order = Number(m.order)
|
|
469
|
+
project.updatedAt = nowIso()
|
|
470
|
+
await saveProject(project)
|
|
471
|
+
return folder
|
|
472
|
+
})
|
|
473
|
+
},
|
|
474
|
+
|
|
475
|
+
/**
|
|
476
|
+
* 导入 bundle 原子落盘:{ folders, endpoints, schemas } 一次 enqueue、一次 saveProject。
|
|
477
|
+
* id 冲突(已有同 id)重分配并在 idMap 记旧→新;folder 的 parentId / endpoint 与 schema 的
|
|
478
|
+
* folderId 按 idMap 改写,避免挂到旧 id 上。folders 按数组先序写入(父必在子前)。
|
|
479
|
+
*/
|
|
480
|
+
async importBundle(projectId, bundle) {
|
|
481
|
+
return enqueue(async () => {
|
|
482
|
+
const project = await loadProjectForWrite(projectId)
|
|
483
|
+
const b = bundle && typeof bundle === 'object' ? bundle : {}
|
|
484
|
+
const ts = nowIso()
|
|
485
|
+
const idMap = {}
|
|
486
|
+
const taken = {
|
|
487
|
+
fld_: new Set(project.folders.map((f) => f.id)),
|
|
488
|
+
ep_: new Set(project.endpoints.map((e) => e.id)),
|
|
489
|
+
sch_: new Set(project.schemas.map((s) => s.id)),
|
|
490
|
+
}
|
|
491
|
+
/** 取 id:未占用则原样保留,否则分配新 id 并记映射。 */
|
|
492
|
+
const takeId = (raw, prefix) => {
|
|
493
|
+
const old = raw && raw.id != null ? String(raw.id) : ''
|
|
494
|
+
if (old !== '' && !taken[prefix].has(old)) {
|
|
495
|
+
taken[prefix].add(old)
|
|
496
|
+
return old
|
|
497
|
+
}
|
|
498
|
+
const next = uniqueId(prefix, taken[prefix])
|
|
499
|
+
taken[prefix].add(next)
|
|
500
|
+
if (old !== '') idMap[old] = next
|
|
501
|
+
return next
|
|
502
|
+
}
|
|
503
|
+
/** 父引用改写:命中 idMap 用新 id,未在 bundle 内的既有 id 保持原值。 */
|
|
504
|
+
const remap = (v) => {
|
|
505
|
+
if (v == null || v === '') return null
|
|
506
|
+
const key = String(v)
|
|
507
|
+
return idMap[key] !== undefined ? idMap[key] : key
|
|
508
|
+
}
|
|
509
|
+
const rows = (v) => (Array.isArray(v) ? v : [])
|
|
510
|
+
|
|
511
|
+
// 两遍处理:先给全部目录分配 id(建全 idMap),再 remap parentId,
|
|
512
|
+
// 这样即使 bundle.folders 不是先序,子目录也能正确指向父目录的新 id。
|
|
513
|
+
const folderRows = rows(b.folders).map((raw) => {
|
|
514
|
+
const f = raw && typeof raw === 'object' ? raw : {}
|
|
515
|
+
return { ...f, oldId: f.id == null ? '' : String(f.id), id: takeId(f, 'fld_') }
|
|
516
|
+
})
|
|
517
|
+
// 落盘顺序按父子深度稳定排序:bundle 乱序时 project.json 里仍是父在子前
|
|
518
|
+
const byOldId = new Map()
|
|
519
|
+
for (const f of folderRows) if (f.oldId !== '') byOldId.set(f.oldId, f)
|
|
520
|
+
const depthOf = (f) => {
|
|
521
|
+
let d = 0
|
|
522
|
+
let cur = f
|
|
523
|
+
const guard = new Set([f.oldId])
|
|
524
|
+
while (cur && cur.parentId && byOldId.has(cur.parentId) && !guard.has(cur.parentId)) {
|
|
525
|
+
guard.add(cur.parentId)
|
|
526
|
+
cur = byOldId.get(cur.parentId)
|
|
527
|
+
d += 1
|
|
528
|
+
}
|
|
529
|
+
return d
|
|
530
|
+
}
|
|
531
|
+
const ordered = folderRows
|
|
532
|
+
.map((f, i) => ({ f, i, d: depthOf(f) }))
|
|
533
|
+
.sort((x, y) => (x.d - y.d) || (x.i - y.i))
|
|
534
|
+
.map((x) => x.f)
|
|
535
|
+
const folders = ordered.map(({ oldId, ...f }) => ({
|
|
536
|
+
name: '',
|
|
537
|
+
order: 0,
|
|
538
|
+
...f,
|
|
539
|
+
parentId: remap(f.parentId),
|
|
540
|
+
createdAt: f.createdAt || ts,
|
|
541
|
+
updatedAt: ts,
|
|
542
|
+
}))
|
|
543
|
+
const endpoints = rows(b.endpoints).map((raw) => {
|
|
544
|
+
const ep = raw && typeof raw === 'object' ? raw : {}
|
|
545
|
+
return {
|
|
546
|
+
...withEndpointDefaults(ep, null),
|
|
547
|
+
id: takeId(ep, 'ep_'),
|
|
548
|
+
folderId: remap(ep.folderId),
|
|
549
|
+
createdAt: ts,
|
|
550
|
+
updatedAt: ts,
|
|
551
|
+
}
|
|
552
|
+
})
|
|
553
|
+
const schemas = rows(b.schemas).map((raw) => {
|
|
554
|
+
const s = raw && typeof raw === 'object' ? raw : {}
|
|
555
|
+
return {
|
|
556
|
+
...SCHEMA_DEFAULTS,
|
|
557
|
+
...s,
|
|
558
|
+
id: takeId(s, 'sch_'),
|
|
559
|
+
folderId: remap(s.folderId),
|
|
560
|
+
createdAt: s.createdAt || ts,
|
|
561
|
+
updatedAt: ts,
|
|
562
|
+
}
|
|
563
|
+
})
|
|
564
|
+
|
|
565
|
+
project.folders.push(...folders)
|
|
566
|
+
project.endpoints.push(...endpoints)
|
|
567
|
+
project.schemas.push(...schemas)
|
|
568
|
+
project.updatedAt = ts
|
|
569
|
+
await saveProject(project)
|
|
570
|
+
return { folders: folders.length, endpoints: endpoints.length, schemas: schemas.length, idMap }
|
|
571
|
+
})
|
|
572
|
+
},
|
|
573
|
+
|
|
574
|
+
async saveSchema(projectId, schema) {
|
|
575
|
+
return enqueue(async () => {
|
|
576
|
+
const project = await loadProjectForWrite(projectId)
|
|
577
|
+
const ts = nowIso()
|
|
578
|
+
const prev = schema && schema.id != null
|
|
579
|
+
? project.schemas.find((s) => s.id === schema.id)
|
|
580
|
+
: undefined
|
|
581
|
+
const saved = {
|
|
582
|
+
...SCHEMA_DEFAULTS,
|
|
583
|
+
...(prev || {}),
|
|
584
|
+
...(schema || {}),
|
|
585
|
+
id: schema && schema.id != null
|
|
586
|
+
? schema.id
|
|
587
|
+
: uniqueId('sch_', new Set(project.schemas.map((s) => s.id))),
|
|
588
|
+
createdAt: prev ? prev.createdAt : ts,
|
|
589
|
+
updatedAt: ts,
|
|
590
|
+
}
|
|
591
|
+
upsertById(project.schemas, saved)
|
|
592
|
+
project.updatedAt = ts
|
|
593
|
+
await saveProject(project)
|
|
594
|
+
return saved
|
|
595
|
+
})
|
|
596
|
+
},
|
|
597
|
+
|
|
598
|
+
async deleteSchema(projectId, schemaId) {
|
|
599
|
+
return enqueue(async () => {
|
|
600
|
+
const project = await loadProjectForWrite(projectId)
|
|
601
|
+
project.schemas = project.schemas.filter((s) => s.id !== schemaId)
|
|
602
|
+
project.updatedAt = nowIso()
|
|
603
|
+
await saveProject(project)
|
|
604
|
+
return { id: schemaId }
|
|
605
|
+
})
|
|
606
|
+
},
|
|
607
|
+
|
|
608
|
+
async saveEnvironment(projectId, env) {
|
|
609
|
+
return enqueue(async () => {
|
|
610
|
+
const project = await loadProjectForWrite(projectId)
|
|
611
|
+
const prev = env && env.id != null
|
|
612
|
+
? project.environments.find((e) => e.id === env.id)
|
|
613
|
+
: undefined
|
|
614
|
+
const saved = {
|
|
615
|
+
...ENV_DEFAULTS,
|
|
616
|
+
...(prev || {}),
|
|
617
|
+
...(env || {}),
|
|
618
|
+
variables: Array.isArray((env && env.variables))
|
|
619
|
+
? env.variables
|
|
620
|
+
: (prev && Array.isArray(prev.variables) ? prev.variables : []),
|
|
621
|
+
id: env && env.id != null
|
|
622
|
+
? env.id
|
|
623
|
+
: uniqueId('env_', new Set(project.environments.map((e) => e.id))),
|
|
624
|
+
}
|
|
625
|
+
upsertById(project.environments, saved)
|
|
626
|
+
project.updatedAt = nowIso()
|
|
627
|
+
await saveProject(project)
|
|
628
|
+
return saved
|
|
629
|
+
})
|
|
630
|
+
},
|
|
631
|
+
|
|
632
|
+
async deleteEnvironment(projectId, envId) {
|
|
633
|
+
return enqueue(async () => {
|
|
634
|
+
const project = await loadProjectForWrite(projectId)
|
|
635
|
+
project.environments = project.environments.filter((e) => e.id !== envId)
|
|
636
|
+
project.updatedAt = nowIso()
|
|
637
|
+
await saveProject(project)
|
|
638
|
+
return { id: envId }
|
|
639
|
+
})
|
|
640
|
+
},
|
|
641
|
+
|
|
642
|
+
async saveGlobals(projectId, globals) {
|
|
643
|
+
return enqueue(async () => {
|
|
644
|
+
const project = await loadProjectForWrite(projectId)
|
|
645
|
+
project.globals = asVariables(globals)
|
|
646
|
+
project.updatedAt = nowIso()
|
|
647
|
+
await saveProject(project)
|
|
648
|
+
return project.globals
|
|
649
|
+
})
|
|
650
|
+
},
|
|
651
|
+
|
|
652
|
+
async saveProjectSettings(projectId, settings) {
|
|
653
|
+
return enqueue(async () => {
|
|
654
|
+
const project = await loadProjectForWrite(projectId)
|
|
655
|
+
// 局部合并:只覆盖传入键,其余沿用(契约 §3 saveProjectSettings 语义)
|
|
656
|
+
project.settings = {
|
|
657
|
+
...DEFAULT_SETTINGS,
|
|
658
|
+
...(project.settings || {}),
|
|
659
|
+
...(settings && typeof settings === 'object' ? settings : {}),
|
|
660
|
+
}
|
|
661
|
+
project.updatedAt = nowIso()
|
|
662
|
+
await saveProject(project)
|
|
663
|
+
return project.settings
|
|
664
|
+
})
|
|
665
|
+
},
|
|
666
|
+
|
|
667
|
+
async saveFlow(projectId, flow) {
|
|
668
|
+
return enqueue(async () => {
|
|
669
|
+
const project = await loadProjectForWrite(projectId)
|
|
670
|
+
project.flow = {
|
|
671
|
+
name: '',
|
|
672
|
+
steps: [],
|
|
673
|
+
...(flow && typeof flow === 'object' ? flow : {}),
|
|
674
|
+
}
|
|
675
|
+
project.updatedAt = nowIso()
|
|
676
|
+
await saveProject(project)
|
|
677
|
+
return project.flow
|
|
678
|
+
})
|
|
679
|
+
},
|
|
680
|
+
|
|
681
|
+
async saveResponse(projectId, endpointId, response) {
|
|
682
|
+
return enqueue(async () => {
|
|
683
|
+
const project = await loadProjectForWrite(projectId)
|
|
684
|
+
const ep = project.endpoints.find((e) => e.id === endpointId)
|
|
685
|
+
// endpoint 不存在时幂等回构造结果、不落盘(桥侧通用透传不应 500,契约未定义错误语义)
|
|
686
|
+
if (!ep) {
|
|
687
|
+
return {
|
|
688
|
+
...RESPONSE_DEFAULTS,
|
|
689
|
+
...(response || {}),
|
|
690
|
+
id: response && response.id != null ? response.id : uniqueId('res_', new Set()),
|
|
691
|
+
}
|
|
692
|
+
}
|
|
693
|
+
if (!Array.isArray(ep.responses)) ep.responses = []
|
|
694
|
+
const prev = response && response.id != null
|
|
695
|
+
? ep.responses.find((r) => r.id === response.id)
|
|
696
|
+
: undefined
|
|
697
|
+
const saved = {
|
|
698
|
+
...RESPONSE_DEFAULTS,
|
|
699
|
+
...(prev || {}),
|
|
700
|
+
...(response || {}),
|
|
701
|
+
id: response && response.id != null
|
|
702
|
+
? response.id
|
|
703
|
+
: uniqueId('res_', new Set(ep.responses.map((r) => r.id))),
|
|
704
|
+
}
|
|
705
|
+
// 首个响应自动成为默认响应(契约 §2.2 isDefault)
|
|
706
|
+
if (!prev && ep.responses.length === 0 && response && response.isDefault === undefined) {
|
|
707
|
+
saved.isDefault = true
|
|
708
|
+
}
|
|
709
|
+
upsertById(ep.responses, saved)
|
|
710
|
+
project.updatedAt = nowIso()
|
|
711
|
+
await saveProject(project)
|
|
712
|
+
return saved
|
|
713
|
+
})
|
|
714
|
+
},
|
|
715
|
+
|
|
716
|
+
async deleteResponse(projectId, endpointId, responseId) {
|
|
717
|
+
return enqueue(async () => {
|
|
718
|
+
const project = await loadProjectForWrite(projectId)
|
|
719
|
+
const ep = project.endpoints.find((e) => e.id === endpointId)
|
|
720
|
+
// 同上:缺失 endpoint 幂等返回,不抛错
|
|
721
|
+
if (!ep) return { id: responseId }
|
|
722
|
+
ep.responses = (ep.responses || []).filter((r) => r.id !== responseId)
|
|
723
|
+
project.updatedAt = nowIso()
|
|
724
|
+
await saveProject(project)
|
|
725
|
+
return { id: responseId }
|
|
726
|
+
})
|
|
727
|
+
},
|
|
728
|
+
|
|
729
|
+
async getHistory(projectId) {
|
|
730
|
+
if (!projectId) throw new Error('getHistory: projectId is required')
|
|
731
|
+
return readHistory(projectId)
|
|
732
|
+
},
|
|
733
|
+
|
|
734
|
+
async appendHistory(projectId, entry) {
|
|
735
|
+
return enqueue(async () => {
|
|
736
|
+
if (!projectId) throw new Error('appendHistory: projectId is required')
|
|
737
|
+
const project = await loadProjectForWrite(projectId)
|
|
738
|
+
const history = await readHistory(projectId)
|
|
739
|
+
const limit = Number((project.settings && project.settings.historyLimit) || DEFAULT_HISTORY_LIMIT)
|
|
740
|
+
const e = entry && typeof entry === 'object' ? entry : {}
|
|
741
|
+
const saved = {
|
|
742
|
+
id: e.id != null
|
|
743
|
+
? String(e.id)
|
|
744
|
+
: uniqueId('his_', new Set(history.entries.map((x) => x.id))),
|
|
745
|
+
at: e.at != null ? String(e.at) : nowIso(),
|
|
746
|
+
method: e.method != null ? String(e.method).toUpperCase() : 'GET',
|
|
747
|
+
url: e.url != null ? String(e.url) : '',
|
|
748
|
+
status: e.status != null ? Number(e.status) : 0,
|
|
749
|
+
timeMs: e.timeMs != null ? Number(e.timeMs) : 0,
|
|
750
|
+
bodySize: e.bodySize != null ? Number(e.bodySize) : 0,
|
|
751
|
+
request: e.request && typeof e.request === 'object' ? e.request : {},
|
|
752
|
+
response: e.response && typeof e.response === 'object' ? e.response : {},
|
|
753
|
+
}
|
|
754
|
+
history.entries.push(saved)
|
|
755
|
+
// 契约 §2.3:按 settings.historyLimit 保留最新 N 条(数组尾部为最新)
|
|
756
|
+
const kept = limit > 0 ? history.entries.slice(-limit) : []
|
|
757
|
+
await atomicWrite(historyFile(projectId), JSON.stringify({ entries: kept }, null, 2))
|
|
758
|
+
return saved
|
|
759
|
+
})
|
|
760
|
+
},
|
|
761
|
+
|
|
762
|
+
async clearHistory(projectId) {
|
|
763
|
+
return enqueue(async () => {
|
|
764
|
+
if (!projectId) throw new Error('clearHistory: projectId is required')
|
|
765
|
+
const history = await readHistory(projectId)
|
|
766
|
+
const cleared = history.entries.length
|
|
767
|
+
await atomicWrite(historyFile(projectId), JSON.stringify({ entries: [] }, null, 2))
|
|
768
|
+
return { cleared }
|
|
769
|
+
})
|
|
770
|
+
},
|
|
771
|
+
|
|
772
|
+
/** 契约 §3:名称/url/description 命中,大小写不敏感;空关键字返回空集(不返回全部)。 */
|
|
773
|
+
async search(projectId, keyword) {
|
|
774
|
+
if (!projectId) throw new Error('search: projectId is required')
|
|
775
|
+
const kw = typeof keyword === 'string' ? keyword.trim().toLowerCase() : ''
|
|
776
|
+
if (kw === '') return { endpoints: [], schemas: [], folders: [] }
|
|
777
|
+
const loaded = await loadProjectData(projectId)
|
|
778
|
+
if (!loaded) throw new Error(`project not found: ${projectId}`)
|
|
779
|
+
const project = loaded.data
|
|
780
|
+
const hit = (...fields) =>
|
|
781
|
+
fields.some((f) => typeof f === 'string' && f.toLowerCase().includes(kw))
|
|
782
|
+
return {
|
|
783
|
+
endpoints: clone(project.endpoints.filter((ep) => hit(ep.name, ep.url, ep.description))),
|
|
784
|
+
schemas: clone(project.schemas.filter((s) => hit(s.name, s.description))),
|
|
785
|
+
folders: clone(project.folders.filter((f) => hit(f.name))),
|
|
786
|
+
}
|
|
787
|
+
},
|
|
788
|
+
}
|
|
789
|
+
}
|
|
790
|
+
|
|
791
|
+
/** endpoint 补默认:ENDPOINT_DEFAULTS ← 旧值 ← 新值,body/auth/mock 三层各自合并。 */
|
|
792
|
+
function withEndpointDefaults(patch, prev) {
|
|
793
|
+
const p = patch && typeof patch === 'object' ? patch : {}
|
|
794
|
+
const b = prev && typeof prev === 'object' ? prev : {}
|
|
795
|
+
return {
|
|
796
|
+
...ENDPOINT_DEFAULTS,
|
|
797
|
+
...b,
|
|
798
|
+
...p,
|
|
799
|
+
body: { ...ENDPOINT_DEFAULTS.body, ...(b.body || {}), ...(p.body || {}) },
|
|
800
|
+
auth: { ...ENDPOINT_DEFAULTS.auth, ...(b.auth || {}), ...(p.auth || {}) },
|
|
801
|
+
mock: { ...ENDPOINT_DEFAULTS.mock, ...(b.mock || {}), ...(p.mock || {}) },
|
|
802
|
+
}
|
|
803
|
+
}
|