@dsh-workbench/shared 1.5.2-alpha.3 → 1.5.2-alpha.5

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.
Files changed (314) hide show
  1. package/dist/components/Activity.css +69 -0
  2. package/dist/components/Activity.d.ts +56 -0
  3. package/dist/components/Activity.js +47 -0
  4. package/dist/components/ApprovalDetail.css +3 -0
  5. package/dist/components/ApprovalDetail.d.ts +42 -0
  6. package/dist/components/ApprovalDetail.js +53 -0
  7. package/dist/components/ApprovalPlan.css +39 -0
  8. package/dist/components/ApprovalPlan.d.ts +27 -0
  9. package/dist/components/ApprovalPlan.js +19 -0
  10. package/dist/components/Card.css +19 -0
  11. package/dist/components/Card.d.ts +26 -0
  12. package/dist/components/Card.js +18 -0
  13. package/dist/components/CardAnchor.d.ts +21 -0
  14. package/dist/components/CardAnchor.js +19 -0
  15. package/dist/components/CardAnchor.module.css +3 -0
  16. package/dist/components/CardBoundary.d.ts +42 -0
  17. package/dist/components/CardBoundary.js +58 -0
  18. package/dist/components/CardBoundary.module.css +5 -0
  19. package/dist/components/CardHead.css +87 -0
  20. package/dist/components/CardHead.d.ts +30 -0
  21. package/dist/components/CardHead.js +27 -0
  22. package/dist/components/ChoiceGroup.css +182 -0
  23. package/dist/components/ChoiceGroup.d.ts +54 -0
  24. package/dist/components/ChoiceGroup.js +63 -0
  25. package/dist/components/ConfirmBar.css +26 -0
  26. package/dist/components/ConfirmBar.d.ts +36 -0
  27. package/dist/components/ConfirmBar.js +26 -0
  28. package/dist/components/EmptyIllustration.d.ts +12 -0
  29. package/dist/components/EmptyIllustration.js +32 -0
  30. package/dist/components/Field.css +20 -0
  31. package/dist/components/Field.d.ts +18 -0
  32. package/dist/components/Field.js +15 -0
  33. package/dist/components/Form.css +6 -0
  34. package/dist/components/Form.d.ts +22 -0
  35. package/dist/components/Form.js +60 -0
  36. package/dist/components/FormActions.css +13 -0
  37. package/dist/components/FormActions.d.ts +29 -0
  38. package/dist/components/FormActions.js +43 -0
  39. package/dist/components/FormNodes.d.ts +107 -0
  40. package/dist/components/FormNodes.js +165 -0
  41. package/dist/components/FormRows.css +107 -0
  42. package/dist/components/FormRows.d.ts +36 -0
  43. package/dist/components/FormRows.js +26 -0
  44. package/dist/components/FormTypes.d.ts +84 -0
  45. package/dist/components/FormTypes.js +1 -0
  46. package/dist/components/Link.css +22 -0
  47. package/dist/components/Link.d.ts +22 -0
  48. package/dist/components/Link.js +17 -0
  49. package/dist/components/LongTaskRow.css +171 -0
  50. package/dist/components/LongTaskRow.d.ts +94 -0
  51. package/dist/components/LongTaskRow.js +103 -0
  52. package/dist/components/Note.css +13 -0
  53. package/dist/components/Note.d.ts +20 -0
  54. package/dist/components/Note.js +14 -0
  55. package/dist/components/ResourceStates.css +114 -0
  56. package/dist/components/ResourceStates.d.ts +44 -0
  57. package/dist/components/ResourceStates.js +41 -0
  58. package/dist/components/Rows.css +42 -0
  59. package/dist/components/Rows.d.ts +28 -0
  60. package/dist/components/Rows.js +21 -0
  61. package/dist/components/SaveBar.d.ts +24 -0
  62. package/dist/components/SaveBar.js +25 -0
  63. package/dist/components/SelectField.css +182 -0
  64. package/dist/components/SelectField.d.ts +89 -0
  65. package/dist/components/SelectField.js +260 -0
  66. package/dist/components/SelectFieldNodes.d.ts +49 -0
  67. package/dist/components/SelectFieldNodes.js +43 -0
  68. package/dist/components/SettingsSection.css +25 -0
  69. package/dist/components/SettingsSection.d.ts +20 -0
  70. package/dist/components/SettingsSection.js +17 -0
  71. package/dist/components/SetupShell.d.ts +93 -0
  72. package/dist/components/SetupShell.js +64 -0
  73. package/dist/components/SetupShell.module.css +81 -0
  74. package/dist/components/Spinner.css +5 -0
  75. package/dist/components/Spinner.d.ts +15 -0
  76. package/dist/components/Spinner.js +13 -0
  77. package/dist/components/Stack.css +6 -0
  78. package/dist/components/Stack.d.ts +14 -0
  79. package/dist/components/Stack.js +10 -0
  80. package/dist/components/StateBlock.css +38 -0
  81. package/dist/components/StateBlock.d.ts +24 -0
  82. package/dist/components/StateBlock.js +22 -0
  83. package/dist/components/TextField.css +32 -0
  84. package/dist/components/TextField.d.ts +14 -0
  85. package/dist/components/TextField.js +10 -0
  86. package/dist/components/board-module.d.ts +307 -0
  87. package/dist/components/board-module.js +1 -0
  88. package/dist/components/card-view-validate.d.ts +5 -0
  89. package/dist/components/card-view-validate.js +256 -0
  90. package/dist/components/icons.d.ts +63 -0
  91. package/dist/components/icons.js +107 -0
  92. package/dist/components/layout/icon-command.d.ts +8 -0
  93. package/dist/components/layout/icon-command.js +21 -0
  94. package/dist/contract/capture.d.ts +16 -0
  95. package/dist/contract/capture.js +1 -0
  96. package/dist/contract/diagnostics.d.ts +34 -0
  97. package/dist/contract/diagnostics.js +124 -0
  98. package/dist/contract/protocol/unit-manager.d.ts +50 -0
  99. package/dist/contract/protocol/unit-manager.js +2 -0
  100. package/dist/host/adapter-contract.d.ts +3 -0
  101. package/dist/host/adapter-contract.js +95 -0
  102. package/dist/host/adapter-set.d.ts +27 -0
  103. package/dist/host/adapter-set.js +258 -0
  104. package/dist/host/adapter-types.d.ts +87 -0
  105. package/dist/host/adapter-types.js +23 -0
  106. package/dist/host/adapters/platform.d.ts +14 -0
  107. package/dist/host/adapters/platform.js +40 -0
  108. package/dist/host/adapters.d.ts +28 -0
  109. package/dist/host/adapters.js +9 -0
  110. package/dist/host/auth-loss.d.ts +33 -0
  111. package/dist/host/auth-loss.js +107 -0
  112. package/dist/host/board-fact.d.ts +8 -0
  113. package/dist/host/board-fact.js +16 -0
  114. package/dist/host/boot-record.d.ts +11 -0
  115. package/dist/host/boot-record.js +31 -0
  116. package/dist/host/browser.d.ts +3 -0
  117. package/dist/host/browser.js +3 -0
  118. package/dist/host/bundle-manager.d.ts +4 -0
  119. package/dist/host/bundle-manager.js +338 -0
  120. package/dist/host/changelog.d.ts +28 -0
  121. package/dist/host/changelog.js +201 -0
  122. package/dist/host/cli-error.d.ts +8 -0
  123. package/dist/host/cli-error.js +70 -0
  124. package/dist/host/cli.d.ts +4 -0
  125. package/dist/host/cli.js +9 -0
  126. package/dist/host/config-sync.d.ts +40 -0
  127. package/dist/host/config-sync.js +267 -0
  128. package/dist/host/context-ref.d.ts +13 -0
  129. package/dist/host/context-ref.js +41 -0
  130. package/dist/host/data-error.d.ts +15 -0
  131. package/dist/host/data-error.js +23 -0
  132. package/dist/host/data-plan-check.d.ts +10 -0
  133. package/dist/host/data-plan-check.js +315 -0
  134. package/dist/host/data-plan.d.ts +15 -0
  135. package/dist/host/data-plan.js +283 -0
  136. package/dist/host/data-root.d.ts +5 -0
  137. package/dist/host/data-root.js +23 -0
  138. package/dist/host/diy-debug.d.ts +80 -0
  139. package/dist/host/diy-debug.js +89 -0
  140. package/dist/host/diy-preset.d.ts +26 -0
  141. package/dist/host/diy-preset.js +115 -0
  142. package/dist/host/diy-record.d.ts +135 -0
  143. package/dist/host/diy-record.js +163 -0
  144. package/dist/host/dsh-compat.d.ts +27 -0
  145. package/dist/host/dsh-compat.js +75 -0
  146. package/dist/host/dsh-plugins.d.ts +5 -0
  147. package/dist/host/dsh-plugins.js +51 -0
  148. package/dist/host/env-policy.d.ts +82 -0
  149. package/dist/host/env-policy.js +181 -0
  150. package/dist/host/extension.d.ts +7 -0
  151. package/dist/host/extension.js +40 -0
  152. package/dist/host/facts.d.ts +31 -0
  153. package/dist/host/facts.js +58 -0
  154. package/dist/host/fs-write.d.ts +96 -0
  155. package/dist/host/fs-write.js +183 -0
  156. package/dist/host/git.d.ts +5 -0
  157. package/dist/host/git.js +1 -0
  158. package/dist/host/host-actions.d.ts +2 -0
  159. package/dist/host/host-actions.js +5 -0
  160. package/dist/host/host-kit.d.ts +37 -0
  161. package/dist/host/host-kit.js +27 -0
  162. package/dist/host/http.d.ts +47 -0
  163. package/dist/host/http.js +289 -0
  164. package/dist/host/install-failure.d.ts +50 -0
  165. package/dist/host/install-failure.js +184 -0
  166. package/dist/host/installed-module.d.ts +25 -0
  167. package/dist/host/installed-module.js +289 -0
  168. package/dist/host/installed-sources.d.ts +10 -0
  169. package/dist/host/installed-sources.js +63 -0
  170. package/dist/host/lease.d.ts +70 -0
  171. package/dist/host/lease.js +264 -0
  172. package/dist/host/lib-capabilities.d.ts +22 -0
  173. package/dist/host/lib-capabilities.js +37 -0
  174. package/dist/host/lib-install.d.ts +19 -0
  175. package/dist/host/lib-install.js +40 -0
  176. package/dist/host/lib-runners.d.ts +18 -0
  177. package/dist/host/lib-runners.js +46 -0
  178. package/dist/host/local-declaration.d.ts +7 -0
  179. package/dist/host/local-declaration.js +33 -0
  180. package/dist/host/long-task.d.ts +97 -0
  181. package/dist/host/long-task.js +297 -0
  182. package/dist/host/market-index-claim.d.ts +19 -0
  183. package/dist/host/market-index-claim.js +87 -0
  184. package/dist/host/market-index-doc.d.ts +12 -0
  185. package/dist/host/market-index-doc.js +1 -0
  186. package/dist/host/market-index-parse.d.ts +28 -0
  187. package/dist/host/market-index-parse.js +413 -0
  188. package/dist/host/market-index.d.ts +13 -0
  189. package/dist/host/market-index.js +105 -0
  190. package/dist/host/module-root.d.ts +1 -0
  191. package/dist/host/module-root.js +5 -0
  192. package/dist/host/needs.d.ts +4 -0
  193. package/dist/host/needs.js +2 -0
  194. package/dist/host/npm-registry.d.ts +10 -0
  195. package/dist/host/npm-registry.js +16 -0
  196. package/dist/host/package-content.d.ts +8 -0
  197. package/dist/host/package-content.js +90 -0
  198. package/dist/host/package-kind.d.ts +13 -0
  199. package/dist/host/package-kind.js +51 -0
  200. package/dist/host/package-route.d.ts +33 -0
  201. package/dist/host/package-route.js +68 -0
  202. package/dist/host/panel-state.d.ts +120 -0
  203. package/dist/host/panel-state.js +177 -0
  204. package/dist/host/patch-blocks.d.ts +13 -0
  205. package/dist/host/patch-blocks.js +52 -0
  206. package/dist/host/patch.d.ts +4 -0
  207. package/dist/host/patch.js +7 -0
  208. package/dist/host/paths.d.ts +12 -0
  209. package/dist/host/paths.js +20 -0
  210. package/dist/host/payload.d.ts +12 -0
  211. package/dist/host/payload.js +16 -0
  212. package/dist/host/plan-results.d.ts +5 -0
  213. package/dist/host/plan-results.js +71 -0
  214. package/dist/host/plan-run.d.ts +41 -0
  215. package/dist/host/plan-run.js +87 -0
  216. package/dist/host/platform.d.ts +14 -0
  217. package/dist/host/platform.js +40 -0
  218. package/dist/host/plugin-ledger.d.ts +32 -0
  219. package/dist/host/plugin-ledger.js +106 -0
  220. package/dist/host/plugin.d.ts +3 -0
  221. package/dist/host/plugin.js +38 -0
  222. package/dist/host/port-types.d.ts +233 -0
  223. package/dist/host/port-types.js +1 -0
  224. package/dist/host/preflight.d.ts +32 -0
  225. package/dist/host/preflight.js +1 -0
  226. package/dist/host/process-alive.d.ts +6 -0
  227. package/dist/host/process-alive.js +16 -0
  228. package/dist/host/profile-bundles.d.ts +20 -0
  229. package/dist/host/profile-bundles.js +48 -0
  230. package/dist/host/profile-create.d.ts +19 -0
  231. package/dist/host/profile-create.js +124 -0
  232. package/dist/host/profile-port.d.ts +4 -0
  233. package/dist/host/profile-port.js +4 -0
  234. package/dist/host/profile-registries.d.ts +10 -0
  235. package/dist/host/profile-registries.js +149 -0
  236. package/dist/host/provision.d.ts +32 -0
  237. package/dist/host/provision.js +105 -0
  238. package/dist/host/read-json.d.ts +1 -0
  239. package/dist/host/read-json.js +11 -0
  240. package/dist/host/recipe-rules.d.ts +5 -0
  241. package/dist/host/recipe-rules.js +412 -0
  242. package/dist/host/recipe.d.ts +14 -0
  243. package/dist/host/recipe.js +332 -0
  244. package/dist/host/registry-declaration.d.ts +21 -0
  245. package/dist/host/registry-declaration.js +42 -0
  246. package/dist/host/reinstall-record.d.ts +16 -0
  247. package/dist/host/reinstall-record.js +54 -0
  248. package/dist/host/release-age.d.ts +24 -0
  249. package/dist/host/release-age.js +92 -0
  250. package/dist/host/release-packages.generated.d.ts +1 -0
  251. package/dist/host/release-packages.generated.js +10 -0
  252. package/dist/host/release-probe.d.ts +37 -0
  253. package/dist/host/release-probe.js +156 -0
  254. package/dist/host/runtime/browser-argv.d.ts +1 -0
  255. package/dist/host/runtime/browser-argv.js +9 -0
  256. package/dist/host/runtime/dsh-compat.d.ts +1 -1
  257. package/dist/host/runtime/dsh-compat.js +4 -1
  258. package/dist/host/runtime/front-app.d.ts +6 -0
  259. package/dist/host/runtime/front-app.js +70 -0
  260. package/dist/host/shell-render.d.ts +52 -0
  261. package/dist/host/shell-render.js +117 -0
  262. package/dist/host/shell-text.d.ts +30 -0
  263. package/dist/host/shell-text.js +40 -0
  264. package/dist/host/shell.d.ts +25 -0
  265. package/dist/host/shell.js +55 -0
  266. package/dist/host/site.d.ts +45 -0
  267. package/dist/host/site.js +182 -0
  268. package/dist/host/spec.d.ts +8 -0
  269. package/dist/host/spec.js +24 -0
  270. package/dist/host/submit-confirm.d.ts +19 -0
  271. package/dist/host/submit-confirm.js +45 -0
  272. package/dist/host/supply-index.d.ts +38 -0
  273. package/dist/host/supply-index.js +209 -0
  274. package/dist/host/supply-port.d.ts +5 -0
  275. package/dist/host/supply-port.js +50 -0
  276. package/dist/host/time.d.ts +22 -0
  277. package/dist/host/time.js +33 -0
  278. package/dist/host/tokens.d.ts +26 -0
  279. package/dist/host/tokens.js +154 -0
  280. package/dist/host/tool-approval.d.ts +86 -0
  281. package/dist/host/tool-approval.js +118 -0
  282. package/dist/host/tool-kit.d.ts +8 -0
  283. package/dist/host/tool-kit.js +22 -0
  284. package/dist/host/toolbox-port.d.ts +16 -0
  285. package/dist/host/toolbox-port.js +1 -0
  286. package/dist/host/unit-config.d.ts +34 -0
  287. package/dist/host/unit-config.js +28 -0
  288. package/dist/host/unit-data.d.ts +3 -0
  289. package/dist/host/unit-data.js +127 -0
  290. package/dist/host/unit-face.d.ts +95 -0
  291. package/dist/host/unit-face.js +1 -0
  292. package/dist/host/unit-plugin.d.ts +24 -0
  293. package/dist/host/unit-plugin.js +25 -0
  294. package/dist/host/update-journal-manifest.d.ts +19 -0
  295. package/dist/host/update-journal-manifest.js +134 -0
  296. package/dist/host/update-journal-types.d.ts +33 -0
  297. package/dist/host/update-journal-types.js +2 -0
  298. package/dist/host/update-journal.d.ts +43 -0
  299. package/dist/host/update-journal.js +409 -0
  300. package/dist/host/value-handoff.d.ts +16 -0
  301. package/dist/host/value-handoff.js +22 -0
  302. package/dist/host/version-range.d.ts +2 -0
  303. package/dist/host/version-range.js +13 -0
  304. package/dist/host/version.d.ts +4 -0
  305. package/dist/host/version.js +32 -0
  306. package/dist/host/workspace-store.d.ts +19 -0
  307. package/dist/host/workspace-store.js +133 -0
  308. package/dist/host/write-result.d.ts +1 -0
  309. package/dist/host/write-result.js +18 -0
  310. package/dist/lib/dsh-client.d.ts +1 -1
  311. package/package.json +51 -47
  312. package/src/host/runtime/__tests__/dsh-compat.test.ts +10 -2
  313. package/src/host/runtime/dsh-compat.ts +4 -2
  314. package/src/lib/dsh-client.ts +2 -1
@@ -0,0 +1,412 @@
1
+ import { pathSegmentsProblem } from '../contract/guards.js';
2
+ import { authLossProblemsOf } from './auth-loss.js';
3
+ const METHODS = ['GET', 'POST', 'PUT', 'PATCH', 'DELETE'];
4
+ const RESPONSE_KINDS = ['json', 'text'];
5
+ const CONTENT_TYPES = ['json', 'form'];
6
+ const CREDENTIAL_HEADERS = [
7
+ 'authorization',
8
+ 'cookie',
9
+ 'x-api-key',
10
+ 'x-auth-token',
11
+ 'x-csrf-token',
12
+ 'x-xsrf-token',
13
+ ];
14
+ export const DEFAULT_RECIPE_MAX_BYTES = 2 * 1024 * 1024;
15
+ export const MAX_RECIPE_CALLS = 8;
16
+ const MAX_MAX_BYTES = 8 * 1024 * 1024;
17
+ function recordOf(value) {
18
+ return typeof value === 'object' && value !== null && !Array.isArray(value)
19
+ ? value
20
+ : undefined;
21
+ }
22
+ function textOf(value) {
23
+ return typeof value === 'string' ? value.trim() : '';
24
+ }
25
+ function httpOriginProblem(value) {
26
+ const text = textOf(value);
27
+ if (text === '')
28
+ return 'origin 不能为空';
29
+ try {
30
+ const url = new URL(text);
31
+ if (url.protocol !== 'http:' && url.protocol !== 'https:')
32
+ return 'origin 只认 http(s)';
33
+ if (url.origin !== text)
34
+ return 'origin 只写到域(不带路径、不带尾斜杠)';
35
+ }
36
+ catch {
37
+ return `origin 不是合法地址:${text}`;
38
+ }
39
+ return undefined;
40
+ }
41
+ function relativePathProblem(value, label) {
42
+ const text = textOf(value);
43
+ if (text === '')
44
+ return `${label} 不能为空`;
45
+ if (text.includes('\\'))
46
+ return `${label} 里不许有反斜杠`;
47
+ if (text.startsWith('//'))
48
+ return `${label} 不许用协议相对地址`;
49
+ if (text.includes('?') || text.includes('#'))
50
+ return `${label} 不带查询 / 锚点,参数走 query`;
51
+ if (!text.startsWith('/'))
52
+ return `${label} 要以 / 开头`;
53
+ return undefined;
54
+ }
55
+ function absoluteUrlProblem(value, label) {
56
+ const text = textOf(value);
57
+ if (text === '')
58
+ return `${label} 不能为空`;
59
+ try {
60
+ const url = new URL(text);
61
+ if (url.protocol !== 'http:' && url.protocol !== 'https:')
62
+ return `${label} 只认 http(s)`;
63
+ }
64
+ catch {
65
+ return `${label} 不是合法地址:${text}`;
66
+ }
67
+ return undefined;
68
+ }
69
+ function requestPathProblem(value, origin, label) {
70
+ const text = textOf(value);
71
+ const relative = relativePathProblem(value, label);
72
+ if (origin === undefined) {
73
+ return text.startsWith('/') ? relative : `${label} 要以 / 开头(只写 site 时用站内路径)`;
74
+ }
75
+ if (relative === undefined)
76
+ return undefined;
77
+ if (text.startsWith('/') || text.startsWith('//') || text.includes('\\') || text.includes('?') || text.includes('#')) {
78
+ return relative;
79
+ }
80
+ try {
81
+ const url = new URL(text);
82
+ if (url.protocol !== 'http:' && url.protocol !== 'https:')
83
+ return `${label} 只认 http(s)`;
84
+ if (url.origin !== origin)
85
+ return `${label} 要和 origin 同源`;
86
+ }
87
+ catch {
88
+ return `${label} 要以 / 开头,或者是同源的绝对地址`;
89
+ }
90
+ return undefined;
91
+ }
92
+ function resolvedUrlProblem(value, origin, label) {
93
+ const text = textOf(value);
94
+ if (text === '')
95
+ return `${label} 不能为空`;
96
+ if (text.startsWith('//'))
97
+ return `${label} 不许用协议相对地址`;
98
+ if (text.startsWith('/')) {
99
+ return origin === undefined ? undefined : absoluteUrlProblem(`${origin}${text}`, label);
100
+ }
101
+ return absoluteUrlProblem(text, label);
102
+ }
103
+ function queryProblem(value) {
104
+ if (value === undefined)
105
+ return undefined;
106
+ const map = recordOf(value);
107
+ if (map === undefined)
108
+ return 'query 要是对象';
109
+ for (const [name, entry] of Object.entries(map)) {
110
+ if (name.trim() === '')
111
+ return 'query 的键不能为空';
112
+ if (typeof entry !== 'string' && typeof entry !== 'number' && typeof entry !== 'boolean') {
113
+ return `query.${name} 只能是字符串 / 数字 / 布尔`;
114
+ }
115
+ }
116
+ return undefined;
117
+ }
118
+ function headersProblem(value) {
119
+ if (value === undefined)
120
+ return undefined;
121
+ const map = recordOf(value);
122
+ if (map === undefined)
123
+ return 'headers 要是对象';
124
+ for (const [name, entry] of Object.entries(map)) {
125
+ if (name.trim() === '')
126
+ return 'headers 的键不能为空';
127
+ if (typeof entry !== 'string')
128
+ return `headers.${name} 要是字符串`;
129
+ if (CREDENTIAL_HEADERS.includes(name.toLowerCase())) {
130
+ return `headers 里不许写凭据头 ${name} —— 凭据走 auth.place`;
131
+ }
132
+ }
133
+ return undefined;
134
+ }
135
+ function bodyProblem(value, contentType) {
136
+ if (value === undefined)
137
+ return undefined;
138
+ if (contentType === 'form') {
139
+ const map = recordOf(value);
140
+ if (map === undefined)
141
+ return 'contentType: form 时 body 要是对象';
142
+ for (const [name, entry] of Object.entries(map)) {
143
+ if (typeof entry !== 'string')
144
+ return `contentType: form 时 body.${name} 要是字符串`;
145
+ }
146
+ return undefined;
147
+ }
148
+ try {
149
+ JSON.stringify(value);
150
+ }
151
+ catch {
152
+ return 'body 要能 JSON 序列化';
153
+ }
154
+ return undefined;
155
+ }
156
+ function sourceProblem(value, origin) {
157
+ const source = recordOf(value);
158
+ if (source === undefined)
159
+ return 'auth.source 要是对象';
160
+ const kind = textOf(source['kind']);
161
+ if (kind === 'cookie')
162
+ return undefined;
163
+ if (kind === 'cookieValue') {
164
+ return textOf(source['name']) === '' ? 'auth.source.name 不能为空' : undefined;
165
+ }
166
+ if (kind === 'meta') {
167
+ return textOf(source['name']) === '' ? 'auth.source.name 不能为空' : undefined;
168
+ }
169
+ if (kind === 'global') {
170
+ return textOf(source['path']) === '' ? 'auth.source.path 不能为空' : undefined;
171
+ }
172
+ if (kind === 'storage') {
173
+ if (textOf(source['area']) !== 'local' && textOf(source['area']) !== 'session') {
174
+ return 'auth.source.area 只认 local / session';
175
+ }
176
+ return textOf(source['key']) === '' ? 'auth.source.key 不能为空' : undefined;
177
+ }
178
+ if (kind === 'endpoint') {
179
+ const urlIssue = resolvedUrlProblem(source['url'], origin, 'auth.source.url');
180
+ if (urlIssue !== undefined)
181
+ return urlIssue;
182
+ const method = textOf(source['method']);
183
+ if (method !== '' && method !== 'GET' && method !== 'POST') {
184
+ return 'auth.source.method 只认 GET / POST';
185
+ }
186
+ if (textOf(source['path']) === '')
187
+ return 'auth.source.path(token 在返回里的位置)不能为空';
188
+ return bodyProblem(source['body'], 'json');
189
+ }
190
+ return `不认识的 auth.source.kind:${kind === '' ? '(空)' : kind}`;
191
+ }
192
+ function placeProblem(value, source) {
193
+ const place = recordOf(value);
194
+ if (place === undefined)
195
+ return 'auth.place 要是对象';
196
+ const where = textOf(place['in']);
197
+ if (where === 'cookie') {
198
+ if (source !== undefined && source.kind !== 'cookie') {
199
+ return '凭据不是 cookie,place.in 不能是 cookie';
200
+ }
201
+ return undefined;
202
+ }
203
+ if (where === 'header' || where === 'query') {
204
+ if (textOf(place['name']) === '')
205
+ return 'auth.place.name 不能为空';
206
+ if (source !== undefined && source.kind === 'cookie') {
207
+ return 'cookie 来源没有 token 可放,place.in 要写 cookie';
208
+ }
209
+ return undefined;
210
+ }
211
+ if (where === 'body') {
212
+ if (textOf(place['field']) === '')
213
+ return 'auth.place.field 不能为空';
214
+ if (source !== undefined && source.kind === 'cookie') {
215
+ return 'cookie 来源没有 token 可放,place.in 要写 cookie';
216
+ }
217
+ return undefined;
218
+ }
219
+ return `不认识的 auth.place.in:${where === '' ? '(空)' : where}`;
220
+ }
221
+ function authProblem(value, origin) {
222
+ if (value === undefined)
223
+ return undefined;
224
+ const auth = recordOf(value);
225
+ if (auth === undefined)
226
+ return 'auth 要是对象';
227
+ if (textOf(auth['kind']) === 'none') {
228
+ if (auth['source'] !== undefined || auth['place'] !== undefined) {
229
+ return 'auth.kind: none 时不许带 source / place';
230
+ }
231
+ return undefined;
232
+ }
233
+ if (auth['kind'] !== undefined)
234
+ return 'auth.kind 只认 none';
235
+ const sourceIssue = sourceProblem(auth['source'], origin);
236
+ if (sourceIssue !== undefined)
237
+ return sourceIssue;
238
+ return placeProblem(auth['place'], auth['source']);
239
+ }
240
+ function maxBytesProblem(value) {
241
+ if (value === undefined)
242
+ return undefined;
243
+ if (typeof value !== 'number' || !Number.isInteger(value) || value <= 0)
244
+ return 'response.maxBytes 要是正整数';
245
+ if (value > MAX_MAX_BYTES)
246
+ return `response.maxBytes 最大 ${MAX_MAX_BYTES}`;
247
+ return undefined;
248
+ }
249
+ function responsePathProblem(value) {
250
+ if (value === undefined)
251
+ return undefined;
252
+ if (textOf(value) === '')
253
+ return 'response.path 不能为空';
254
+ return pathSegmentsProblem(value, 'response.path');
255
+ }
256
+ function responseProblem(value) {
257
+ if (value === undefined)
258
+ return undefined;
259
+ const response = recordOf(value);
260
+ if (response === undefined)
261
+ return 'response 要是对象';
262
+ const kind = textOf(response['kind']);
263
+ if (!RESPONSE_KINDS.includes(kind))
264
+ return `response.kind 只认 ${RESPONSE_KINDS.join(' / ')}`;
265
+ const pathIssue = responsePathProblem(response['path']);
266
+ if (pathIssue !== undefined)
267
+ return pathIssue;
268
+ return maxBytesProblem(response['maxBytes']);
269
+ }
270
+ function responseOverrideProblem(value) {
271
+ if (value === undefined)
272
+ return undefined;
273
+ const response = recordOf(value);
274
+ if (response === undefined)
275
+ return 'response 要是对象';
276
+ if (response['kind'] !== undefined && !RESPONSE_KINDS.includes(textOf(response['kind']))) {
277
+ return `response.kind 只认 ${RESPONSE_KINDS.join(' / ')}`;
278
+ }
279
+ const pathIssue = responsePathProblem(response['path']);
280
+ if (pathIssue !== undefined)
281
+ return pathIssue;
282
+ return maxBytesProblem(response['maxBytes']);
283
+ }
284
+ function authOf(recipe) {
285
+ return recipe.auth ?? { source: { kind: 'cookie' }, place: { in: 'cookie' } };
286
+ }
287
+ function overridesProblem(recipe, overrides) {
288
+ if (overrides.path !== undefined) {
289
+ const pathIssue = requestPathProblem(overrides.path, recipe.origin, 'path');
290
+ if (pathIssue !== undefined)
291
+ return pathIssue;
292
+ }
293
+ const queryIssue = queryProblem(overrides.query);
294
+ if (queryIssue !== undefined)
295
+ return queryIssue;
296
+ const headersIssue = headersProblem(overrides.headers);
297
+ if (headersIssue !== undefined)
298
+ return headersIssue;
299
+ const responseIssue = responseOverrideProblem(overrides.response);
300
+ if (responseIssue !== undefined)
301
+ return responseIssue;
302
+ const contentType = recipe.request.contentType ?? 'json';
303
+ const bodyIssue = bodyProblem(overrides.body, contentType);
304
+ if (bodyIssue !== undefined)
305
+ return bodyIssue;
306
+ if (overrides.body !== undefined && recipe.request.method === 'GET') {
307
+ return 'GET 不带 body';
308
+ }
309
+ const auth = authOf(recipe);
310
+ const place = auth.kind === 'none' ? undefined : auth.place;
311
+ if (place?.in === 'body' && overrides.body !== undefined && recordOf(overrides.body) === undefined) {
312
+ return 'auth.place 是 body 时 overrides.body 要是对象';
313
+ }
314
+ return undefined;
315
+ }
316
+ export function recipeProblemOf(recipe, overrides) {
317
+ const box = recordOf(recipe);
318
+ if (box === undefined)
319
+ return '配方要是对象';
320
+ const originText = textOf(box['origin']);
321
+ if (box['site'] !== undefined && textOf(box['site']) === '')
322
+ return 'site 不能为空';
323
+ if (originText === '' && textOf(box['site']) === '')
324
+ return '配方要有 origin 或 site 至少一个';
325
+ if (originText !== '') {
326
+ const originIssue = httpOriginProblem(box['origin']);
327
+ if (originIssue !== undefined)
328
+ return originIssue;
329
+ }
330
+ const origin = originText === '' ? undefined : originText;
331
+ if (box['loginUrl'] !== undefined) {
332
+ const loginIssue = absoluteUrlProblem(box['loginUrl'], 'loginUrl');
333
+ if (loginIssue !== undefined)
334
+ return loginIssue;
335
+ }
336
+ if (box['session'] !== undefined && textOf(box['session']) === '')
337
+ return 'session 不能为空';
338
+ if (box['timeoutMs'] !== undefined) {
339
+ const timeout = box['timeoutMs'];
340
+ if (typeof timeout !== 'number' || !Number.isInteger(timeout) || timeout <= 0) {
341
+ return 'timeoutMs 要是正整数';
342
+ }
343
+ }
344
+ if (box['authLoss'] !== undefined) {
345
+ const issue = authLossProblemsOf('authLoss', box['authLoss'])[0];
346
+ if (issue !== undefined) {
347
+ return issue.problem.startsWith(issue.path) ? issue.problem : `${issue.path}: ${issue.problem}`;
348
+ }
349
+ }
350
+ const request = recordOf(box['request']);
351
+ if (request === undefined)
352
+ return 'request 要是对象';
353
+ const method = textOf(request['method']);
354
+ if (!METHODS.includes(method))
355
+ return `request.method 只认 ${METHODS.join(' / ')}`;
356
+ const pathIssue = requestPathProblem(request['path'], origin, 'request.path');
357
+ if (pathIssue !== undefined)
358
+ return pathIssue;
359
+ const queryIssue = queryProblem(request['query']);
360
+ if (queryIssue !== undefined)
361
+ return queryIssue;
362
+ const headersIssue = headersProblem(request['headers']);
363
+ if (headersIssue !== undefined)
364
+ return headersIssue;
365
+ const contentType = textOf(request['contentType']);
366
+ if (contentType !== '' && !CONTENT_TYPES.includes(contentType)) {
367
+ return `request.contentType 只认 ${CONTENT_TYPES.join(' / ')}`;
368
+ }
369
+ const bodyIssue = bodyProblem(request['body'], contentType === 'form' ? 'form' : 'json');
370
+ if (bodyIssue !== undefined)
371
+ return bodyIssue;
372
+ if (request['body'] !== undefined && method === 'GET')
373
+ return 'GET 不带 body';
374
+ const authIssue = authProblem(box['auth'], origin);
375
+ if (authIssue !== undefined)
376
+ return authIssue;
377
+ const auth = recordOf(box['auth']);
378
+ const place = auth === undefined ? undefined : recordOf(auth['place']);
379
+ if (place !== undefined && textOf(place['in']) === 'body' && request['body'] !== undefined) {
380
+ if (recordOf(request['body']) === undefined)
381
+ return 'auth.place 是 body 时 request.body 要是对象';
382
+ }
383
+ const responseIssue = responseProblem(box['response']);
384
+ if (responseIssue !== undefined)
385
+ return responseIssue;
386
+ if (overrides === undefined)
387
+ return undefined;
388
+ return overridesProblem(recipe, overrides);
389
+ }
390
+ export function callsProblemOf(recipe, calls) {
391
+ const recipeIssue = recipeProblemOf(recipe);
392
+ if (recipeIssue !== undefined)
393
+ return recipeIssue;
394
+ const box = recordOf(calls);
395
+ if (box === undefined)
396
+ return 'calls 要是对象,键就是结果名';
397
+ const names = Object.keys(box);
398
+ if (names.length === 0)
399
+ return 'calls 不能为空';
400
+ if (names.length > MAX_RECIPE_CALLS)
401
+ return `一次最多 ${MAX_RECIPE_CALLS} 条 calls`;
402
+ for (const name of names) {
403
+ if (name.trim() === '')
404
+ return 'calls 的键不能为空';
405
+ if (recordOf(box[name]) === undefined)
406
+ return `calls.${name} 要是对象`;
407
+ const issue = overridesProblem(recipe, box[name]);
408
+ if (issue !== undefined)
409
+ return `calls.${name}:${issue}`;
410
+ }
411
+ return undefined;
412
+ }
@@ -0,0 +1,14 @@
1
+ import type { CallOverrides, RecipeCalls, RequestRecipe } from '../contract/data.js';
2
+ export interface RecipeDescription {
3
+ readonly method: string;
4
+ readonly url: string;
5
+ readonly body?: unknown;
6
+ readonly auth?: {
7
+ readonly source: string;
8
+ readonly place: string;
9
+ readonly name?: string;
10
+ } | undefined;
11
+ }
12
+ export declare function scriptOf(recipe: RequestRecipe, overrides?: CallOverrides): string;
13
+ export declare function describeRecipe(recipe: RequestRecipe, overrides?: CallOverrides): RecipeDescription;
14
+ export declare function scriptOfMany(recipe: RequestRecipe, calls: RecipeCalls): string;