@tunasand/sdk 0.8.0 → 0.11.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (215) hide show
  1. package/CHANGELOG.md +121 -0
  2. package/README.md +162 -143
  3. package/dist/analytics.js +76 -65
  4. package/dist/app.js +184 -163
  5. package/dist/apps-DIxAWBSZ.js +318 -0
  6. package/dist/astro-image.d.ts +1 -0
  7. package/dist/astro-image.js +33 -0
  8. package/dist/astro-server-Bwau8F6d.js +99 -0
  9. package/dist/astro-server.d.ts +1 -0
  10. package/dist/astro-server.js +1 -0
  11. package/dist/astro.d.ts +1 -0
  12. package/dist/astro.js +306 -0
  13. package/dist/bridge-Dv4NxGZ7.js +81 -0
  14. package/dist/bridge.js +1 -13
  15. package/dist/build-file-DNi0PHC5.js +31 -0
  16. package/dist/cli.js +6212 -8
  17. package/dist/{client-Derrexwr.js → client-C8STAw9T.js} +43 -24
  18. package/dist/code-N8pBUDbq.js +30 -0
  19. package/dist/code.d.ts +1 -0
  20. package/dist/code.js +1 -0
  21. package/dist/collection-nUz1RetA.js +264 -0
  22. package/dist/{declared-DuNMsdXw.js → declared-CE4a61qb.js} +35 -35
  23. package/dist/delivery.js +121 -114
  24. package/dist/dev-operations-Tutwi1On.js +46 -0
  25. package/dist/dev.js +9 -16
  26. package/dist/embeds-B-Dbn64k.js +29 -0
  27. package/dist/end-users.d.ts +1 -0
  28. package/dist/end-users.js +185 -0
  29. package/dist/endUsers-DODfjnv1.js +77 -0
  30. package/dist/{errorLabels-BgtQ_zUn.js → errorLabels-aT2bnMsO.js} +355 -235
  31. package/dist/i18n.js +4 -4
  32. package/dist/ids-DmtIoqBX.js +109 -0
  33. package/dist/integrations.js +95 -24
  34. package/dist/{ja-Du6ooL6i.js → ja-CrY_72Tn.js} +88 -44
  35. package/dist/{ja-CeHU0EaY.js → ja-axQPxMJ-.js} +3 -3
  36. package/dist/operations-CIB99rIY.js +95 -0
  37. package/dist/operations.d.ts +1 -0
  38. package/dist/operations.js +1 -0
  39. package/dist/{page-Bzrj24sJ.js → page-yo1cw1kW.js} +1 -1
  40. package/dist/preview.js +8 -1
  41. package/dist/{profile-1em_lcxq.js → profile-DBsXLvvI.js} +48 -48
  42. package/dist/rich-text.js +16 -16
  43. package/dist/{schema-WnobuwLg.js → schema-Dcg1ajnW.js} +496 -263
  44. package/dist/schema.js +66 -88
  45. package/dist/types/access/src/handoff.d.ts +19 -14
  46. package/dist/types/access/src/index.d.ts +2 -2
  47. package/dist/types/access/src/jws.d.ts +41 -0
  48. package/dist/types/access/src/oidc.d.ts +10 -2
  49. package/dist/types/access/src/signed.d.ts +0 -2
  50. package/dist/types/adapter-cloudflare/src/eventLog/viewSchema.d.ts +11 -0
  51. package/dist/types/contract/src/accountProfile.d.ts +7 -0
  52. package/dist/types/contract/src/apiKeys.d.ts +6 -2
  53. package/dist/types/contract/src/app.d.ts +15 -5
  54. package/dist/types/contract/src/appChannels.d.ts +114 -0
  55. package/dist/types/contract/src/appDefinition.d.ts +11 -5
  56. package/dist/types/contract/src/appDependencies.d.ts +87 -24
  57. package/dist/types/contract/src/appIdentities.d.ts +21 -0
  58. package/dist/types/contract/src/appInbound.d.ts +28 -0
  59. package/dist/types/contract/src/appMail.d.ts +106 -0
  60. package/dist/types/contract/src/appSecrets.d.ts +45 -0
  61. package/dist/types/contract/src/appServer.d.ts +408 -43
  62. package/dist/types/contract/src/approvals.d.ts +1 -1
  63. package/dist/types/contract/src/apps.d.ts +112 -55
  64. package/dist/types/contract/src/auditActions.d.ts +2 -2
  65. package/dist/types/contract/src/auditLabels.d.ts +111 -15
  66. package/dist/types/contract/src/authorize.d.ts +42 -14
  67. package/dist/types/contract/src/bridge.d.ts +34 -35
  68. package/dist/types/contract/src/consents.d.ts +32 -25
  69. package/dist/types/contract/src/deletion.d.ts +18 -0
  70. package/dist/types/contract/src/embeds.d.ts +16 -82
  71. package/dist/types/contract/src/{customerLabels.d.ts → endUserLabels.d.ts} +6 -9
  72. package/dist/types/contract/src/endUsers.d.ts +241 -0
  73. package/dist/types/contract/src/errorLabels.d.ts +63 -36
  74. package/dist/types/contract/src/errorLabelsEn.d.ts +46 -32
  75. package/dist/types/contract/src/errors.d.ts +28 -16
  76. package/dist/types/contract/src/eventSchemas.d.ts +70 -0
  77. package/dist/types/contract/src/eventTraces.d.ts +43 -0
  78. package/dist/types/contract/src/failureStatus.d.ts +14 -22
  79. package/dist/types/contract/src/fieldAccess.d.ts +8 -8
  80. package/dist/types/contract/src/formLabels.d.ts +3 -0
  81. package/dist/types/contract/src/forms.d.ts +4 -0
  82. package/dist/types/contract/src/grants.d.ts +26 -0
  83. package/dist/types/contract/src/headers.d.ts +5 -0
  84. package/dist/types/contract/src/hostingRpc.d.ts +23 -17
  85. package/dist/types/contract/src/identifiers.d.ts +45 -17
  86. package/dist/types/contract/src/ids.d.ts +18 -10
  87. package/dist/types/contract/src/import.d.ts +17 -16
  88. package/dist/types/contract/src/index.d.ts +52 -27
  89. package/dist/types/contract/src/integrationGraph.d.ts +83 -0
  90. package/dist/types/contract/src/issueLabels.d.ts +113 -81
  91. package/dist/types/contract/src/issueLabelsEn.d.ts +57 -41
  92. package/dist/types/contract/src/manage.d.ts +11 -7
  93. package/dist/types/contract/src/manageLabels.d.ts +2 -0
  94. package/dist/types/contract/src/manifestText.d.ts +66 -0
  95. package/dist/types/contract/src/messagePort.d.ts +208 -0
  96. package/dist/types/contract/src/migration.d.ts +2 -2
  97. package/dist/types/contract/src/notices.d.ts +38 -0
  98. package/dist/types/contract/src/operatorOperations.d.ts +0 -63
  99. package/dist/types/contract/src/outbound.d.ts +29 -0
  100. package/dist/types/contract/src/paths.d.ts +13 -0
  101. package/dist/types/contract/src/pending.d.ts +2 -0
  102. package/dist/types/contract/src/permissions.d.ts +7 -11
  103. package/dist/types/contract/src/perspective.d.ts +26 -0
  104. package/dist/types/contract/src/powers.d.ts +5 -0
  105. package/dist/types/contract/src/principal.d.ts +127 -56
  106. package/dist/types/contract/src/recordLabels.d.ts +6 -0
  107. package/dist/types/contract/src/roles.d.ts +7 -4
  108. package/dist/types/contract/src/ruleLabels.d.ts +16 -0
  109. package/dist/types/contract/src/ruleProblems.d.ts +16 -0
  110. package/dist/types/contract/src/schemaLabels.d.ts +8 -0
  111. package/dist/types/contract/src/settingProblems.d.ts +1 -1
  112. package/dist/types/contract/src/settings.d.ts +5 -7
  113. package/dist/types/contract/src/siteDeclaration.d.ts +7 -7
  114. package/dist/types/contract/src/siteIndex.d.ts +76 -0
  115. package/dist/types/contract/src/transfer.d.ts +1 -1
  116. package/dist/types/contract/src/trial.d.ts +4 -1
  117. package/dist/types/contract/src/versions.d.ts +1 -3
  118. package/dist/types/contract/src/viewEvent.d.ts +0 -9
  119. package/dist/types/contract/src/webhooks.d.ts +24 -3
  120. package/dist/types/contract/src/workflow.d.ts +13 -19
  121. package/dist/types/contract/src/workspaceItems.d.ts +20 -6
  122. package/dist/types/rich-text/src/html.d.ts +1 -1
  123. package/dist/types/rich-text/src/index.d.ts +8 -7
  124. package/dist/types/rich-text/src/labels/en.d.ts +1 -1
  125. package/dist/types/rich-text/src/labels/ja.d.ts +2 -2
  126. package/dist/types/rich-text/src/library.d.ts +1 -1
  127. package/dist/types/rich-text/src/media.d.ts +2 -0
  128. package/dist/types/rich-text/src/normalize.d.ts +1 -1
  129. package/dist/types/rich-text/src/problems.d.ts +5 -5
  130. package/dist/types/rich-text/src/profile.d.ts +10 -10
  131. package/dist/types/rich-text/src/render.d.ts +1 -1
  132. package/dist/types/rich-text/src/schema.d.ts +2 -2
  133. package/dist/types/rich-text/src/standard.d.ts +4 -4
  134. package/dist/types/rich-text/src/types.d.ts +2 -2
  135. package/dist/types/schema/src/audience.d.ts +1 -3
  136. package/dist/types/schema/src/capabilities.d.ts +18 -27
  137. package/dist/types/schema/src/changes.d.ts +3 -1
  138. package/dist/types/schema/src/collection.d.ts +138 -111
  139. package/dist/types/schema/src/defaultSchema.d.ts +8 -2
  140. package/dist/types/schema/src/fieldIds.d.ts +18 -0
  141. package/dist/types/schema/src/file.d.ts +22 -11
  142. package/dist/types/schema/src/fileRefs.d.ts +14 -0
  143. package/dist/types/schema/src/fileSignature.d.ts +20 -0
  144. package/dist/types/schema/src/filesCollection.d.ts +7 -0
  145. package/dist/types/schema/src/forms.d.ts +43 -0
  146. package/dist/types/schema/src/imageMetadata.d.ts +9 -0
  147. package/dist/types/schema/src/index.d.ts +18 -10
  148. package/dist/types/schema/src/input.d.ts +1 -1
  149. package/dist/types/schema/src/integrity.d.ts +8 -7
  150. package/dist/types/schema/src/kinds.d.ts +26 -0
  151. package/dist/types/schema/src/labels/en.d.ts +87 -46
  152. package/dist/types/schema/src/labels/ja.d.ts +89 -45
  153. package/dist/types/schema/src/mediaUrl.d.ts +26 -33
  154. package/dist/types/schema/src/page.d.ts +4 -4
  155. package/dist/types/schema/src/problems.d.ts +82 -41
  156. package/dist/types/schema/src/refs.d.ts +0 -9
  157. package/dist/types/schema/src/schema.d.ts +17 -12
  158. package/dist/types/schema/src/selfOps.d.ts +20 -19
  159. package/dist/types/schema/src/traits.d.ts +28 -0
  160. package/dist/types/schema/src/typesSource.d.ts +1 -1
  161. package/dist/types/schema/src/values.d.ts +5 -2
  162. package/dist/types/schema/src/widening.d.ts +3 -0
  163. package/dist/types/sdk/src/analytics.d.ts +2 -1
  164. package/dist/types/sdk/src/app.d.ts +40 -14
  165. package/dist/types/sdk/src/astro-image.d.ts +19 -0
  166. package/dist/types/sdk/src/astro-response.d.ts +6 -0
  167. package/dist/types/sdk/src/astro-server.d.ts +16 -0
  168. package/dist/types/sdk/src/astro.d.ts +19 -0
  169. package/dist/types/sdk/src/bridge.d.ts +2 -4
  170. package/dist/types/sdk/src/code.d.ts +61 -0
  171. package/dist/types/sdk/src/delegation.d.ts +13 -3
  172. package/dist/types/sdk/src/delivery/changes.d.ts +4 -4
  173. package/dist/types/sdk/src/delivery/client.d.ts +33 -22
  174. package/dist/types/sdk/src/delivery/fields.d.ts +3 -3
  175. package/dist/types/sdk/src/delivery/index.d.ts +3 -3
  176. package/dist/types/sdk/src/delivery/media.d.ts +5 -8
  177. package/dist/types/sdk/src/delivery/query.d.ts +15 -11
  178. package/dist/types/sdk/src/delivery/schema.d.ts +1 -1
  179. package/dist/types/sdk/src/delivery/values.d.ts +10 -14
  180. package/dist/types/sdk/src/delivery.d.ts +2 -2
  181. package/dist/types/sdk/src/dev-operations.d.ts +20 -0
  182. package/dist/types/sdk/src/dev.d.ts +6 -5
  183. package/dist/types/sdk/src/end-users.d.ts +190 -0
  184. package/dist/types/sdk/src/i18n.d.ts +2 -2
  185. package/dist/types/sdk/src/integrations.d.ts +14 -21
  186. package/dist/types/sdk/src/operations.d.ts +17 -0
  187. package/dist/types/sdk/src/preview.d.ts +2 -1
  188. package/dist/types/sdk/src/rich-text.d.ts +2 -2
  189. package/dist/types/sdk/src/schema.d.ts +1 -1
  190. package/dist/types/sdk/src/site/artifact.d.ts +64 -0
  191. package/dist/types/sdk/src/site/build-file.d.ts +30 -0
  192. package/dist/types/sdk/src/site/check-code.d.ts +14 -0
  193. package/dist/types/sdk/src/site/check-text.d.ts +19 -0
  194. package/dist/types/sdk/src/site/cli.d.ts +52 -0
  195. package/dist/types/sdk/src/site/content-type.d.ts +2 -0
  196. package/dist/types/sdk/src/site/labels.d.ts +14 -0
  197. package/dist/types/sdk/src/types.d.ts +1 -1
  198. package/dist/{types-B77qvqPJ.js → types-DkO2N7u2.js} +5 -6
  199. package/dist/types.js +1 -1
  200. package/dist/{typesSource-CWybQYus.js → typesSource-VJIxtN9b.js} +17 -15
  201. package/dist/workflow-CUpl6hO_.js +148 -0
  202. package/package.json +32 -6
  203. package/dist/apps-BxnJ1RlU.js +0 -435
  204. package/dist/bridge-DtHw9hS6.js +0 -74
  205. package/dist/collection-BEOxeISR.js +0 -189
  206. package/dist/customers-DTbL0qn6.js +0 -86
  207. package/dist/customers.d.ts +0 -1
  208. package/dist/customers.js +0 -185
  209. package/dist/embeds-B5V54Zur.js +0 -34
  210. package/dist/ids--RF7hGyC.js +0 -36
  211. package/dist/src-sazhzYui.js +0 -71
  212. package/dist/types/contract/src/customers.d.ts +0 -266
  213. package/dist/types/schema/src/legacy.d.ts +0 -2
  214. package/dist/types/schema/src/media.d.ts +0 -5
  215. package/dist/types/sdk/src/customers.d.ts +0 -184
package/dist/app.js CHANGED
@@ -1,12 +1,13 @@
1
- import { _ as JSON_BODY_MAX, d as problemEnglish, g as ERROR_STATUS, h as apiIssueText, i as errorText, n as errorBodyFor } from "./errorLabels-BgtQ_zUn.js";
2
- import { t as newUuidV7 } from "./ids--RF7hGyC.js";
3
- import { c as formatMessage, d as problemOf, f as problemText } from "./ja-CeHU0EaY.js";
4
- import { o as TOKEN_EXCHANGE } from "./embeds-B5V54Zur.js";
5
- import { a as accountDelegationOf, i as ownsRow, n as isAdmin, o as customerOf, r as allows, s as principalOfUser } from "./apps-BxnJ1RlU.js";
6
- import { S as isPublishable, b as isPersonalCollection, j as roleFieldOf, l as audienceOf, t as AUDIENCES } from "./collection-BEOxeISR.js";
7
- import { a as CUSTOMER_STATUSES, t as CUSTOMERS_KEY_TARGET } from "./customers-DTbL0qn6.js";
8
- import { l as bodyProblemText, s as embedOfUrl } from "./declared-DuNMsdXw.js";
9
- import { a as mergeStyle, c as ALIGNS, n as isSafeCssValue, o as sortMarks, r as HTML_TAG_MARKS, s as isSafeHref, u as isTableCell } from "./profile-1em_lcxq.js";
1
+ import { _ as JSON_BODY_MAX, a as problemBodyWithoutType, f as problemEnglish, g as apiIssueText, o as problemResponse, r as errorText } from "./errorLabels-aT2bnMsO.js";
2
+ import { i as newUuidV7 } from "./ids-DmtIoqBX.js";
3
+ import { c as formatMessage, d as problemOf, f as problemText } from "./ja-axQPxMJ-.js";
4
+ import { a as APP_CHANNEL_LIMITS, c as ADMIN_AREA_OPERATION, d as BUNDLED_APP_IDS, f as MESSAGE_LIMITS, h as MESSAGE_SKIP_REASONS, i as APP_CHANNEL_KIND_LIMITS, m as MESSAGE_RECEIVED, o as CHANNEL_ADDRESS_KINDS, p as MESSAGE_PORT, r as appToolPrefixOf, s as CHANNEL_CAPABILITIES, u as INSTALLATION_TOKEN } from "./apps-DIxAWBSZ.js";
5
+ import { r as TOKEN_EXCHANGE } from "./embeds-B-Dbn64k.js";
6
+ import { a as END_USER_REF, c as ORIGIN_REF, d as importItemOfRow, i as manifestDocumentOf, l as cyclicCollections, n as recordStateOf, r as NOTICES_PORT, s as IMPORT_ITEMS_MAX, t as isLiveState, u as importIdOf } from "./workflow-CUpl6hO_.js";
7
+ import { a as END_USER_STATUSES, t as END_USERS_KEY_TARGET } from "./endUsers-DODfjnv1.js";
8
+ import { l as richTextProblemText, s as embedOfUrl } from "./declared-CE4a61qb.js";
9
+ import { a as mergeStyle, c as ALIGNS, n as isSafeCssValue, o as sortMarks, r as HTML_TAG_MARKS, s as isSafeHref, u as isTableCell } from "./profile-DBsXLvvI.js";
10
+ import { T as isPublishable, t as AUDIENCES } from "./collection-nUz1RetA.js";
10
11
  import { parseDocument } from "htmlparser2";
11
12
  // ../rich-text/src/normalize.ts
12
13
  const keyOf = (inline) => "component" in inline ? null : JSON.stringify([
@@ -54,7 +55,7 @@ const normalizeCell = (cell) => isTableCell(cell) ? {
54
55
  content: cell.content.map(normalizeRich)
55
56
  } : normalizeRich(cell);
56
57
  /** 本文を正規化 */
57
- function normalizeBody(body) {
58
+ function normalizeRichText(body) {
58
59
  return body.map((block) => {
59
60
  switch (block.type) {
60
61
  case "paragraph":
@@ -181,7 +182,7 @@ const intOf = (v) => {
181
182
  return Number.isFinite(n) && n > 0 ? n : void 0;
182
183
  };
183
184
  /** HTML を本文に(コピーできないものは dropped) */
184
- function bodyFromHtml(html, options) {
185
+ function richTextFromHtml(html, options) {
185
186
  const counts = /* @__PURE__ */ new Map();
186
187
  const drop = (what) => counts.set(what, (counts.get(what) ?? 0) + 1);
187
188
  const alignOf = (el) => {
@@ -190,9 +191,9 @@ function bodyFromHtml(html, options) {
190
191
  };
191
192
  /** 要素の属性と style のうち、コピーできないものを数える(used はコピーした style の項目) */
192
193
  const audit = (el, used = []) => {
193
- for (const name of Object.keys(el.attribs)) if (name.startsWith("on")) drop(bodyProblemText("drop_attribute", { name }));
194
- else if (!SILENT_ATTRS.has(name) && !name.startsWith("data-") && !name.startsWith("aria-")) drop(bodyProblemText("drop_attribute", { name }));
195
- for (const key of declarations(el).keys()) if (!used.includes(key)) drop(bodyProblemText("drop_style", { key }));
194
+ for (const name of Object.keys(el.attribs)) if (name.startsWith("on")) drop(richTextProblemText("drop_attribute", { name }));
195
+ else if (!SILENT_ATTRS.has(name) && !name.startsWith("data-") && !name.startsWith("aria-")) drop(richTextProblemText("drop_attribute", { name }));
196
+ for (const key of declarations(el).keys()) if (!used.includes(key)) drop(richTextProblemText("drop_style", { key }));
196
197
  };
197
198
  const classesOf = (el) => (el.attribs.class ?? "").split(/\s+/).filter(Boolean);
198
199
  /** span などの見た目(コピーできない class と style の項目は数える) */
@@ -205,7 +206,7 @@ function bodyFromHtml(html, options) {
205
206
  if (!value) continue;
206
207
  used.push(key);
207
208
  if (!isSafeCssValue(kind, value)) {
208
- drop(bodyProblemText("drop_style_value", { key }));
209
+ drop(richTextProblemText("drop_style_value", { key }));
209
210
  continue;
210
211
  }
211
212
  const name = options.nameOf?.(kind, value);
@@ -217,7 +218,7 @@ function bodyFromHtml(html, options) {
217
218
  if (decls.has("text-align")) used.push("text-align");
218
219
  const kept = classesOf(el).filter((c) => {
219
220
  if (options.styleClass?.(c)) return true;
220
- drop(bodyProblemText("drop_class", { name: c }));
221
+ drop(richTextProblemText("drop_class", { name: c }));
221
222
  return false;
222
223
  });
223
224
  if (kept.length) style.styles = kept;
@@ -228,7 +229,7 @@ function bodyFromHtml(html, options) {
228
229
  const href = el.attribs.href?.trim();
229
230
  if (!href) return void 0;
230
231
  if (!isSafeHref(href)) {
231
- drop(bodyProblemText("drop_unsafe_link"));
232
+ drop(richTextProblemText("drop_unsafe_link"));
232
233
  return;
233
234
  }
234
235
  const rel = el.attribs.rel?.trim();
@@ -254,7 +255,7 @@ function bodyFromHtml(html, options) {
254
255
  if (!isElement(node)) return [];
255
256
  const name = node.name.toLowerCase();
256
257
  if (DANGEROUS.has(name) || name === "iframe") {
257
- drop(bodyProblemText("drop_element", { name }));
258
+ drop(richTextProblemText("drop_element", { name }));
258
259
  return [];
259
260
  }
260
261
  if (name === "br") return ["\n"];
@@ -263,7 +264,7 @@ function bodyFromHtml(html, options) {
263
264
  img: node,
264
265
  ...ctx.link ? { link: ctx.link } : {}
265
266
  });
266
- else drop(bodyProblemText("drop_inline_image"));
267
+ else drop(richTextProblemText("drop_inline_image"));
267
268
  return [];
268
269
  }
269
270
  const mark = HTML_TAG_MARKS[name];
@@ -288,7 +289,7 @@ function bodyFromHtml(html, options) {
288
289
  style: mergeStyle(ctx.style, style)
289
290
  });
290
291
  }
291
- if (!BLOCK_TAGS.has(name)) drop(bodyProblemText("drop_element", { name }));
292
+ if (!BLOCK_TAGS.has(name)) drop(richTextProblemText("drop_element", { name }));
292
293
  return inlines(node.children, ctx);
293
294
  });
294
295
  /** 断片の列(images があれば中の画像をそこへ集める) */
@@ -312,7 +313,7 @@ function bodyFromHtml(html, options) {
312
313
  const hasText = (r) => r.some((i) => typeof i === "string" ? i.trim() : "text" in i ? (i.text ?? "").trim() : true);
313
314
  /** 集めた画像を画像のブロックに(where は数える場所) */
314
315
  const hoistedBlocks = (images, where) => images.flatMap(({ img, link }) => {
315
- drop(bodyProblemText("drop_hoisted_image", { where }));
316
+ drop(richTextProblemText("drop_hoisted_image", { where }));
316
317
  const image = imageOf(img, link ? { link } : {});
317
318
  return image ? [image] : [];
318
319
  });
@@ -331,7 +332,7 @@ function bodyFromHtml(html, options) {
331
332
  };
332
333
  /** キャプション・表の説明の文字(文字だけの項目のため、装飾は捨てて数える、中の画像は images へ) */
333
334
  const captionText = (el, images) => {
334
- if (rich(el.children, images).some((i) => typeof i !== "string")) drop(bodyProblemText("drop_caption_marks"));
335
+ if (rich(el.children, images).some((i) => typeof i !== "string")) drop(richTextProblemText("drop_caption_marks"));
335
336
  return textOf(el.children.filter((c) => !(isElement(c) && c.name === "img"))).trim();
336
337
  };
337
338
  const HEADINGS = /* @__PURE__ */ new Set([
@@ -363,38 +364,38 @@ function bodyFromHtml(html, options) {
363
364
  const name = el.name.toLowerCase();
364
365
  if (name === "p") push(rich(el.children, images));
365
366
  else if (name === "ul" || name === "ol") {
366
- drop(bodyProblemText("drop_flattened", {
367
+ drop(richTextProblemText("drop_flattened", {
367
368
  where,
368
369
  what: "list"
369
370
  }));
370
371
  listParagraphs(listOf(el, images), "").forEach(push);
371
372
  } else if (HEADINGS.has(name)) {
372
- drop(bodyProblemText("drop_flattened", {
373
+ drop(richTextProblemText("drop_flattened", {
373
374
  where,
374
375
  what: "heading"
375
376
  }));
376
377
  push(rich(el.children, images));
377
378
  } else if (name === "blockquote") {
378
- drop(bodyProblemText("drop_flattened", {
379
+ drop(richTextProblemText("drop_flattened", {
379
380
  where,
380
381
  what: "quote"
381
382
  }));
382
383
  paragraphsOf(el.children, where, images).forEach(push);
383
384
  } else if (name === "pre") {
384
- drop(bodyProblemText("drop_flattened", {
385
+ drop(richTextProblemText("drop_flattened", {
385
386
  where,
386
387
  what: "code"
387
388
  }));
388
389
  push([textOf(el.children).replace(/\n$/, "")]);
389
390
  } else if (name === "table") {
390
- drop(bodyProblemText("drop_flattened", {
391
+ drop(richTextProblemText("drop_flattened", {
391
392
  where,
392
393
  what: "table"
393
394
  }));
394
395
  for (const tr of findAll(el, (e) => e.name === "tr")) push(normalizeRich(tr.children.filter((c) => isElement(c) && (c.name === "td" || c.name === "th")).flatMap((td, i) => [...i ? [" / "] : [], ...paragraphsOf(td.children, where, images).flatMap((r, j) => [...j ? [" "] : [], ...r])])));
395
396
  } else if (name === "img") images.push({ img: el });
396
397
  else if (name === "figure") {
397
- drop(bodyProblemText("drop_flattened", {
398
+ drop(richTextProblemText("drop_flattened", {
398
399
  where,
399
400
  what: "figure"
400
401
  }));
@@ -405,7 +406,7 @@ function bodyFromHtml(html, options) {
405
406
  const figcaption = findDeep(el, (e) => e.name === "figcaption");
406
407
  if (figcaption) push([captionText(figcaption, [])]);
407
408
  } else if (CONTAINERS.has(name)) paragraphsOf(el.children, where, images).forEach(push);
408
- else drop(bodyProblemText("drop_inner_element", {
409
+ else drop(richTextProblemText("drop_inner_element", {
409
410
  where,
410
411
  name
411
412
  }));
@@ -430,7 +431,7 @@ function bodyFromHtml(html, options) {
430
431
  };
431
432
  const embedBlock = (url, el) => {
432
433
  if (!url || !URL.parse(url)) {
433
- drop(bodyProblemText("drop_embed_no_url"));
434
+ drop(richTextProblemText("drop_embed_no_url"));
434
435
  return null;
435
436
  }
436
437
  const target = embedOfUrl(url);
@@ -447,7 +448,7 @@ function bodyFromHtml(html, options) {
447
448
  }
448
449
  };
449
450
  if (!url.startsWith("https://")) {
450
- drop(bodyProblemText("drop_embed_not_https"));
451
+ drop(richTextProblemText("drop_embed_not_https"));
451
452
  return null;
452
453
  }
453
454
  return {
@@ -479,7 +480,7 @@ function bodyFromHtml(html, options) {
479
480
  const imageOf = (img, extra = {}) => {
480
481
  const src = img.attribs.src?.trim();
481
482
  if (!src) {
482
- drop(bodyProblemText("drop_image_no_src"));
483
+ drop(richTextProblemText("drop_image_no_src"));
483
484
  return null;
484
485
  }
485
486
  const alt = img.attribs.alt?.trim();
@@ -487,7 +488,7 @@ function bodyFromHtml(html, options) {
487
488
  const height = intOf(img.attribs.height);
488
489
  return {
489
490
  type: "image",
490
- media: options.image(src, {
491
+ file: options.image(src, {
491
492
  ...alt ? { alt } : {},
492
493
  ...width ? { width } : {},
493
494
  ...height ? { height } : {}
@@ -500,11 +501,11 @@ function bodyFromHtml(html, options) {
500
501
  const listOf = (el, images) => {
501
502
  const items = el.children.filter(isElement).flatMap((li) => {
502
503
  if (li.name !== "li") {
503
- drop(bodyProblemText("drop_list_element", { name: li.name }));
504
+ drop(richTextProblemText("drop_list_element", { name: li.name }));
504
505
  return [];
505
506
  }
506
507
  const nestedLists = li.children.filter((c) => isElement(c) && (c.name === "ul" || c.name === "ol"));
507
- if (nestedLists.length > 1) drop(bodyProblemText("drop_extra_nested_list"));
508
+ if (nestedLists.length > 1) drop(richTextProblemText("drop_extra_nested_list"));
508
509
  const inner = li.children.filter((c) => !nestedLists.includes(c));
509
510
  const paragraphs = inner.filter((c) => isElement(c) && c.name === "p");
510
511
  const content = paragraphs.length ? normalizeRich(paragraphs.flatMap((p, i) => [...i ? ["\n"] : [], ...rich(p.children, images)])) : rich(inner, images);
@@ -530,7 +531,7 @@ function bodyFromHtml(html, options) {
530
531
  if (!isElement(c)) continue;
531
532
  if (c.name === "tr") rows.push(c);
532
533
  else if (c.name === "thead" || c.name === "tbody" || c.name === "tfoot") collect(c);
533
- else if (c.name !== "caption" && c.name !== "colgroup") drop(bodyProblemText("drop_table_element", { name: c.name }));
534
+ else if (c.name !== "caption" && c.name !== "colgroup") drop(richTextProblemText("drop_table_element", { name: c.name }));
534
535
  }
535
536
  };
536
537
  collect(el);
@@ -577,7 +578,7 @@ function bodyFromHtml(html, options) {
577
578
  return DANGEROUS.has(name) || BLOCK_TAGS.has(name) || name === "a" && el.attribs["data-embed-type"] === "file" && Boolean(options.file);
578
579
  }, (run) => out.push(...paragraphBlocks(run, void 0)), (el) => {
579
580
  const name = el.name.toLowerCase();
580
- if (DANGEROUS.has(name)) drop(bodyProblemText("drop_element", { name }));
581
+ if (DANGEROUS.has(name)) drop(richTextProblemText("drop_element", { name }));
581
582
  else if (name === "a") out.push(fileOf(el));
582
583
  else out.push(...blockOf(el));
583
584
  });
@@ -619,7 +620,7 @@ function bodyFromHtml(html, options) {
619
620
  const name = textOf(a.children).trim();
620
621
  return {
621
622
  type: "file",
622
- media: options.file(a.attribs.href ?? "", {
623
+ file: options.file(a.attribs.href ?? "", {
623
624
  ...a.attribs["data-mime-type"] ? { mime: a.attribs["data-mime-type"] } : {},
624
625
  ...name ? { name } : {}
625
626
  }),
@@ -717,27 +718,30 @@ function bodyFromHtml(html, options) {
717
718
  }
718
719
  };
719
720
  return {
720
- body: normalizeBody(blocks(parseDocument(html, { decodeEntities: true }).children)),
721
+ body: normalizeRichText(blocks(parseDocument(html, { decodeEntities: true }).children)),
721
722
  dropped: [...counts].map(([what, count]) => ({
722
723
  what,
723
724
  count
724
725
  }))
725
726
  };
726
727
  }
727
- // ../contract/src/identifiers.ts
728
+ // ../contract/src/appMail.ts
729
+ /** 能力の要素(送信、受信) */
730
+ const MAIL_CAPABILITIES = {
731
+ send: "mail:send",
732
+ inbound: "mail:inbound"
733
+ };
728
734
  /**
729
- * インストールのトークンの形(GitHub App の形: アプリの鍵で署名したアプリの JWT と交換する)
730
- * - JWS のコンパクトな形。発行と検証はどちらも Tunasand だけで、署名の鍵は SECRETS_KEY からプロジェクトごとに HKDF で導く
731
- * - アプリの JWT: ES256 か RS256、iss はアプリの ID、aud はプロジェクトの配信の基点、exp − iat は appJwtMaxSec 秒まで
732
- * - 時計のずれ: iat の未来と exp の過去を skewSec 秒まで許す
735
+ * 送らなかった理由
736
+ * - suppressed: 抑止の一覧、no_consent: 同意の目的で送れない
737
+ * - domain_unverified: 差出人のドメインが検証されていない、test_environment: live 以外の環境
733
738
  */
734
- const INSTALLATION_TOKEN = {
735
- typ: "tunasand-installation+jwt",
736
- alg: "HS256",
737
- ttlSec: 3600,
738
- appJwtMaxSec: 600,
739
- skewSec: 60
740
- };
739
+ const APP_MAIL_SKIP_REASONS = [
740
+ "suppressed",
741
+ "no_consent",
742
+ "domain_unverified",
743
+ "test_environment"
744
+ ];
741
745
  // ../contract/src/appProblems.ts
742
746
  /** 問題の表から、問題を作る関数(差し込みの不足は型の誤り) */
743
747
  function appProblems(tables) {
@@ -774,107 +778,37 @@ var SettingProblem = class extends Error {
774
778
  this.params = params;
775
779
  }
776
780
  };
781
+ /** 設定値の問題の既定の形(field は項目名) */
782
+ const settingProblemText = (p, field) => problemText({
783
+ code: `setting_${p.problem}`,
784
+ params: {
785
+ ...p.params,
786
+ field
787
+ }
788
+ });
777
789
  // ../contract/src/workspaceItems.ts
778
790
  /** 日付のフィールドの予定が持つ source(`field:<コレクション>.<フィールド>`) */
779
791
  const calendarFieldSource = (f) => `field:${f.collection}.${f.field}`;
780
792
  // ../contract/src/appDefinition.ts
781
793
  /** 設定値のないアプリの設定値の解釈 */
782
794
  const NO_SETTINGS = { parse: () => ({}) };
783
- // ../contract/src/fieldAccess.ts
784
- const ALL = /* @__PURE__ */ new Set([
785
- "public",
786
- "granted",
787
- "self",
788
- "staff"
789
- ]);
790
- /** 配信 API に出せる見える範囲(公開とアクセス権、* の範囲) */
791
- const DELIVERED = /* @__PURE__ */ new Set(["public", "granted"]);
792
- /** MCP にスタッフの項目を出すコレクションの見える範囲(本人の項目は除く) */
793
- const STAFF_FOR_MCP = /* @__PURE__ */ new Set([
794
- "public",
795
- "granted",
796
- "staff"
797
- ]);
798
- /** 能力のうちコレクション target を名指しした操作(* を除く) */
799
- const namedOps = (capabilities, target) => Object.hasOwn(capabilities, target) && target !== "*" ? capabilities[target] : [];
800
- /** 能力の操作(名指しと * の和) */
801
- const opsOf = (capabilities, target) => [...namedOps(capabilities, target), ...Object.hasOwn(capabilities, "*") ? capabilities["*"] : []];
802
- const READS = ["read", "read_drafts"];
803
- /** 主体がコレクションのレコードで見られる見える範囲 */
804
- function audiencesFor(reader, collection) {
805
- if (reader === "system") return ALL;
806
- if (reader.effective.form === "roles") {
807
- const delegation = accountDelegationOf(reader);
808
- if (!delegation) return ALL;
809
- if (delegation.kind === "app") return namedOps(delegation.consented, collection.id).some((op) => READS.includes(op)) ? ALL : DELIVERED;
810
- const { permissions } = reader.effective;
811
- return (permissions[collection.id]?.read ?? permissions["*"]?.read ?? "none") !== "none" && !isPersonalCollection(collection) && delegation.staffCollections.includes(collection.id) ? STAFF_FOR_MCP : DELIVERED;
812
- }
813
- const { capabilities } = reader.effective;
814
- if (!customerOf(reader) && namedOps(capabilities, collection.id).some((op) => READS.includes(op))) return ALL;
815
- const out = /* @__PURE__ */ new Set(["public"]);
816
- if (opsOf(capabilities, collection.id).includes("read_customers")) out.add("granted");
817
- return out;
818
- }
819
- /** コレクションの最上位の項目を見られるか(読み替えは schema のパッケージの audienceOf) */
820
- const canReadField = (audiences, field, collection) => audiences.has(audienceOf(field, collection));
821
- /** レコードの題(題の項目を見られなければレコードの ID、題の項目がなければ ID) */
822
- function titleFor(audiences, collection, values, id) {
823
- const field = roleFieldOf(collection, "title");
824
- const value = field && canReadField(audiences, field, collection) ? values[field.key] : null;
825
- return typeof value === "string" && value ? value : id;
826
- }
827
- // ../contract/src/import.ts
828
- /** 1回のリクエストで取り込む件数の上限(画像の取得の時間と、本文の大きさの上限 JSON_BODY_MAX のため) */
829
- const IMPORT_ITEMS_MAX = 50;
830
- /** 参照の項目の値で、同じ取り出し元の元の ID を指す形の印({ "$origin": "<元の ID>" }) */
831
- const ORIGIN_REF = "$origin";
832
- /** 顧客フィールドの値で、人の元の ID を指す形の印({ "$customer": "<元の ID>" }) */
833
- const CUSTOMER_REF = "$customer";
834
- /** 元の ID を指す値の元の ID(印 marker の1つのキーで値が文字列、ほかは null) */
835
- function originIdOf(value, marker) {
836
- if (typeof value !== "object" || value === null || Array.isArray(value)) return null;
837
- const records = Object.entries(value);
838
- return records.length === 1 && records[0][0] === marker && typeof records[0][1] === "string" ? records[0][1] : null;
839
- }
840
- const isOriginRef = (v) => originIdOf(v, ORIGIN_REF) !== null;
841
- /** 元の ID を指す参照({ "$origin" })を除いた値(まとまりの中と配列の要素も。循環の1段目の項目) */
842
- function withoutOrigins(value) {
843
- if (Array.isArray(value)) return value.filter((v) => !isOriginRef(v)).map(withoutOrigins);
844
- if (typeof value !== "object" || value === null) return value;
845
- return Object.fromEntries(Object.entries(value).flatMap(([k, v]) => isOriginRef(v) ? [] : [[k, withoutOrigins(v)]]));
846
- }
847
- /** 入力の形のレコードを取り込みの1件に(at は報告の位置、phase はコレクションどうしの循環のフェーズで、1段目は参照を除く) */
848
- const importItemOfRow = (line, at, phase) => ({
849
- collection: line.collection,
850
- ...line.new_id !== void 0 && { id: line.new_id },
851
- fields: phase === 1 ? withoutOrigins(line.fields) : line.fields,
852
- source: at,
853
- origin_id: line.id,
854
- ...phase !== void 0 && { phase },
855
- ...line.created_at !== void 0 && { created_at: line.created_at }
856
- });
857
- /** 取り込む ID(前後の空白を除き小文字に、changed は大文字を含んでいた) */
858
- function importIdOf(raw) {
859
- const trimmed = raw.trim();
860
- const id = trimmed.toLowerCase();
861
- return {
862
- id,
863
- changed: id !== trimmed
864
- };
865
- }
866
- /** 関係が循環する API のエンドポイント(関係をたどって自分に戻る、自分への関係を含む。参照なしと参照ありの2フェーズで取り込む) */
867
- function cyclicCollections(apis) {
868
- const reaches = (from, goal, seen) => Object.values(from.relations).some((target) => {
869
- if (target === goal) return true;
870
- if (seen.has(target)) return false;
871
- seen.add(target);
872
- const next = apis.find((x) => x.endpoint === target);
873
- return next ? reaches(next, goal, seen) : false;
874
- });
875
- return new Set(apis.filter((a) => reaches(a, a.endpoint, /* @__PURE__ */ new Set())).map((a) => a.endpoint));
876
- }
877
795
  // ../contract/src/app.ts
796
+ /**
797
+ * 管理の API の一覧を、続きのカーソル next_cursor が尽きるまで読む(読めなければその応答)
798
+ * - path は一覧の経路(クエリを含めてよい)。1要求ごとに件数と走査の上限は効く
799
+ */
800
+ async function cmsListAll(cms, path) {
801
+ const items = [];
802
+ let next = null;
803
+ do {
804
+ const res = await cms.fetch(next === null ? path : `${path}${path.includes("?") ? "&" : "?"}cursor=${encodeURIComponent(next)}`);
805
+ if (!res.ok) return res;
806
+ const page = await res.json();
807
+ items.push(...page.data);
808
+ next = page.next_cursor;
809
+ } while (next !== null);
810
+ return items;
811
+ }
878
812
  /** 外への読み込みの宛先の宣言に URL が当たるか(宣言は https のオリジン、ホスト名の先頭の `*.` は1つ以上の区間。https だけ、ポートの指定なし) */
879
813
  function egressAllows(declared, url) {
880
814
  if (url.protocol !== "https:" || url.port !== "") return false;
@@ -884,6 +818,53 @@ function egressAllows(declared, url) {
884
818
  return m[1] ? url.hostname.endsWith(`.${m[2]}`) : url.hostname === m[2];
885
819
  });
886
820
  }
821
+ // ../contract/src/appServer.ts
822
+ /** 集計の作り直しの処理の ID(実行の記録と、運営者の経路の名指し) */
823
+ const aggregateJobIdOf = (app, collection) => `${app}.${collection}`;
824
+ /** アプリ用の状態の置き場の上限(キーの字数、値の JSON の UTF-8 のバイト数、インストールごとのキーの数) */
825
+ const APP_STATE_LIMITS = {
826
+ keyMaxChars: 200,
827
+ valueMaxBytes: 16384,
828
+ keysMax: 200
829
+ };
830
+ /**
831
+ * 一覧のページを next が尽きるまで読む(ページ送りの画面を持たない利用者の仮の形。1要求ごとの上限は効き、拒否はそのページの拒否)
832
+ */
833
+ async function allRecordPages(read) {
834
+ const records = [];
835
+ let cursor;
836
+ do {
837
+ const page = await read(cursor === void 0 ? {} : { cursor });
838
+ if (!page.ok) return page;
839
+ records.push(...page.value.records);
840
+ cursor = page.value.next ?? void 0;
841
+ } while (cursor !== void 0);
842
+ return {
843
+ ok: true,
844
+ value: records
845
+ };
846
+ }
847
+ /**
848
+ * アプリの口の呼ぶ側の誤りのコード(アプリのコードを直すまで回復しない。結果にせず、このコードを code に持つ UsageError を投げる)
849
+ * - 宣言のないコレクション・イベント・秘密値・ポート・メール・チャネルの種類、未登録の発行者、DB だけの文脈、この環境に入っていない
850
+ */
851
+ const APP_USAGE_ERRORS = [
852
+ "app_collection_undeclared",
853
+ "app_event_undeclared",
854
+ "app_secret_undeclared",
855
+ "app_port_undeclared",
856
+ "app_scope_without_bindings",
857
+ "app_not_installed",
858
+ "end_user_identity_unregistered",
859
+ "app_channel_undeclared",
860
+ "app_mail_undeclared"
861
+ ];
862
+ /** ファイルの読み出しの上限(バイト数) */
863
+ const APP_FILE_LIMITS = { readMaxBytes: 10485760 };
864
+ /** アプリがアカウントへ送れる知らせの種類(レコードの新着、担当の割り当て。件名と本文はコアの定型) */
865
+ const APP_NOTICE_KINDS = ["record_received", "record_assigned"];
866
+ /** アカウントへの知らせの上限(1回の宛先の数) */
867
+ const APP_NOTIFY_LIMITS = { accountsMax: 50 };
887
868
  // ../contract/src/workspacePaths.ts
888
869
  /** ワークスペースのコレクションの経路(URL はレコードのスラッグ、record を省くと一覧) */
889
870
  const workspaceRecordPath = (collection, record) => `/collections/${encodeURIComponent(collection.slug)}/records${record === void 0 ? "" : `/${encodeURIComponent(String(record.slug))}`}`;
@@ -892,19 +873,20 @@ const workspaceRecordPath = (collection, record) => `/collections/${encodeURICom
892
873
  const ASSERTION_TTL_SEC = 60;
893
874
  const base64Url = (bytes) => btoa(String.fromCharCode(...bytes)).replace(/\+/g, "-").replace(/\//g, "_").replace(/=+$/, "");
894
875
  const textPart = (value) => base64Url(new TextEncoder().encode(JSON.stringify(value)));
895
- /** アプリの JWT(iss はアプリの ID、aud は環境の CMS の URL) */
876
+ /** アプリの JWT(iss はアプリの ID、aud は配信の基点) */
896
877
  async function appAssertion(key, claims, nowMs = Date.now()) {
897
878
  const { kid, ...jwk } = key.jwk;
879
+ const pq = jwk.kty === "AKP";
898
880
  const signer = await crypto.subtle.importKey("jwk", {
899
881
  ...jwk,
900
882
  key_ops: ["sign"]
901
- }, {
883
+ }, pq ? { name: "ML-DSA-44" } : {
902
884
  name: "ECDSA",
903
885
  namedCurve: "P-256"
904
886
  }, false, ["sign"]);
905
887
  const iat = Math.floor(nowMs / 1e3);
906
888
  const input = `${textPart({
907
- alg: "ES256",
889
+ alg: pq ? "ML-DSA-44" : "ES256",
908
890
  typ: "JWT",
909
891
  ...kid && { kid }
910
892
  })}.${textPart({
@@ -913,23 +895,42 @@ async function appAssertion(key, claims, nowMs = Date.now()) {
913
895
  iat,
914
896
  exp: iat + Math.min(ASSERTION_TTL_SEC, INSTALLATION_TOKEN.appJwtMaxSec)
915
897
  })}`;
916
- const signature = new Uint8Array(await crypto.subtle.sign({
898
+ const signature = new Uint8Array(await crypto.subtle.sign(pq ? { name: "ML-DSA-44" } : {
917
899
  name: "ECDSA",
918
900
  hash: "SHA-256"
919
901
  }, signer, new TextEncoder().encode(input)));
920
902
  return `${input}.${base64Url(signature)}`;
921
903
  }
904
+ /** 交換するトークンの iss(配信の基点。読めなければ null。署名は交換の側が検証する) */
905
+ function issuerOf(token) {
906
+ try {
907
+ const part = token.split(".")[1] ?? "";
908
+ const claims = JSON.parse(atob(part.replace(/-/g, "+").replace(/_/g, "/")));
909
+ return typeof claims.iss === "string" ? claims.iss : null;
910
+ } catch {
911
+ return null;
912
+ }
913
+ }
922
914
  /** 代理の委任の主張をアカウントの資格のトークンに替える */
923
- async function exchangeDelegation(input) {
915
+ const exchangeDelegation = (input) => exchanged(input, input.delegation);
916
+ /** 画面のトークンをアカウントの資格のトークンに替える(結果の形は exchangeDelegation と同じ) */
917
+ const exchangeSessionToken = (input) => exchanged(input, input.sessionToken);
918
+ async function exchanged(input, subject) {
924
919
  const send = input.fetch ?? ((request) => fetch(request));
920
+ const audience = issuerOf(subject);
921
+ if (!audience) return {
922
+ ok: false,
923
+ error: "invalid_grant",
924
+ status: 0
925
+ };
925
926
  const body = new URLSearchParams({
926
927
  grant_type: TOKEN_EXCHANGE.grantType,
927
- subject_token: input.delegation,
928
+ subject_token: subject,
928
929
  subject_token_type: TOKEN_EXCHANGE.subjectTokenType,
929
930
  client_assertion_type: TOKEN_EXCHANGE.clientAssertionType,
930
931
  client_assertion: await appAssertion(input.key, {
931
932
  appId: input.appId,
932
- audience: input.base
933
+ audience
933
934
  })
934
935
  });
935
936
  const res = await send(new Request(`${input.base}/api/embeds/token`, {
@@ -979,17 +980,30 @@ function appFailureOf(targets) {
979
980
  return (request, code, params, extra = {}) => {
980
981
  const given = request.headers.get(REQUEST_ID_HEADER);
981
982
  const requestId = given && REQUEST_ID_FORM.test(given) ? given : newUuidV7();
982
- return Response.json({
983
- ...errorBodyFor(code, requestId, params),
984
- message: errorText(code, params, targets),
985
- ...extra,
986
- requestId
987
- }, {
988
- status: ERROR_STATUS[code],
989
- headers: { [REQUEST_ID_HEADER]: requestId }
990
- });
983
+ const { issues, ...rest } = extra;
984
+ return problemResponse(problemBodyWithoutType(code, requestId, {
985
+ ...params && { params },
986
+ detail: errorText(code, params, targets),
987
+ ...rest,
988
+ ...issues && { issues: [...issues] }
989
+ }), { [REQUEST_ID_HEADER]: requestId });
991
990
  };
992
991
  }
992
+ /** アプリの口の拒否の応答(CMS の API と同じ problem+json。状態はコードから) */
993
+ const appPortResponse = (request, failure) => appFailure(request, failure.error, failure.params, failure.issues?.length ? { issues: failure.issues.map(appIssue) } : {});
994
+ /** 値のない成功の結果 */
995
+ const PORT_DONE = {
996
+ ok: true,
997
+ value: void 0
998
+ };
999
+ /**
1000
+ * 結果の値(拒否は app_port_refused: <コード> の Error で投げる)
1001
+ * - 拒否を想定しない処理(定期の処理が自分のコレクションを読むなど)だけで使う。利用者の操作の拒否は appPortResponse で返す
1002
+ */
1003
+ function portValue(result) {
1004
+ if (result.ok) return result.value;
1005
+ throw new Error(`app_port_refused: ${result.error}`);
1006
+ }
993
1007
  /** 本文の JSON(空の本文は empty、壊れた JSON は400の応答) */
994
1008
  async function appJson(request, empty = null) {
995
1009
  const text = await request.text();
@@ -1022,10 +1036,17 @@ function appInvalid(request, error, problems = {}) {
1022
1036
  });
1023
1037
  return appFailure(request, "invalid_input", void 0, { issues });
1024
1038
  }
1025
- /** 呼んだ人のアカウント(管理の API の /api/me、失敗は例外) */
1039
+ /** 呼んだ人がコレクションに行える操作の ID(管理の API の /api/schema の viewer_can。record.list、record.create など、失敗は例外) */
1040
+ async function appCollectionCan(ctx, collection) {
1041
+ const res = await ctx.cms.fetch("/api/schema");
1042
+ if (!res.ok) throw new Error(`app_schema_unavailable: ${res.status}`);
1043
+ const { viewer_can: viewerCan } = await res.json();
1044
+ return viewerCan?.[collection] ?? [];
1045
+ }
1046
+ /** 呼んだ人のアカウント(管理の API の /api/me、can は操作の ID ごとの可否。失敗は例外) */
1026
1047
  async function appUser(ctx) {
1027
1048
  const res = await ctx.cms.fetch("/api/me");
1028
1049
  if (!res.ok) throw new Error(`app_user_unavailable: ${res.status}`);
1029
1050
  return await res.json();
1030
1051
  }
1031
- export { AUDIENCES, CUSTOMERS_KEY_TARGET, CUSTOMER_REF, CUSTOMER_STATUSES, IMPORT_ITEMS_MAX, JSON_BODY_MAX, NO_SETTINGS, ORIGIN_REF, SettingProblem, allows, appAssertion, appFailure, appFailureOf, appInvalid, appIssue, appJson, appProblems, appUser, audiencesFor, bearerClient, bodyFromHtml, calendarFieldSource, canReadField, cyclicCollections, egressAllows, exchangeDelegation, importIdOf, importItemOfRow, isAdmin, isPublishable, newUuidV7, ownsRow, principalOfUser, titleFor, workspaceRecordPath };
1052
+ export { ADMIN_AREA_OPERATION, APP_CHANNEL_KIND_LIMITS, APP_CHANNEL_LIMITS, APP_FILE_LIMITS, APP_MAIL_SKIP_REASONS, APP_NOTICE_KINDS, APP_NOTIFY_LIMITS, APP_STATE_LIMITS, APP_USAGE_ERRORS, AUDIENCES, BUNDLED_APP_IDS, CHANNEL_ADDRESS_KINDS, CHANNEL_CAPABILITIES, END_USERS_KEY_TARGET, END_USER_REF, END_USER_STATUSES, IMPORT_ITEMS_MAX, JSON_BODY_MAX, MAIL_CAPABILITIES, MESSAGE_LIMITS, MESSAGE_PORT, MESSAGE_RECEIVED, MESSAGE_SKIP_REASONS, NOTICES_PORT, NO_SETTINGS, ORIGIN_REF, PORT_DONE, SettingProblem, aggregateJobIdOf, allRecordPages, appAssertion, appCollectionCan, appFailure, appFailureOf, appInvalid, appIssue, appJson, appPortResponse, appProblems, appToolPrefixOf, appUser, bearerClient, calendarFieldSource, cmsListAll, cyclicCollections, egressAllows, exchangeDelegation, exchangeSessionToken, importIdOf, importItemOfRow, isLiveState, isPublishable, manifestDocumentOf, newUuidV7, portValue, recordStateOf, richTextFromHtml, settingProblemText, workspaceRecordPath };