@tunasand/sdk 0.7.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 (285) hide show
  1. package/CHANGELOG.md +233 -88
  2. package/README.md +296 -273
  3. package/dist/analytics.js +657 -10
  4. package/dist/app.js +323 -96
  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 +2 -14
  15. package/dist/build-file-DNi0PHC5.js +31 -0
  16. package/dist/cli.js +6214 -9
  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-C_GvPiGF.js → declared-CE4a61qb.js} +124 -36
  23. package/dist/delivery.js +124 -132
  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/{customers-C_vJY2_v.js → endUsers-DODfjnv1.js} +31 -38
  30. package/dist/{errorLabels-CPKiPabZ.js → errorLabels-aT2bnMsO.js} +593 -460
  31. package/dist/i18n.js +4 -4
  32. package/dist/ids-DmtIoqBX.js +109 -0
  33. package/dist/integrations.js +95 -49
  34. package/dist/{ja-C6lX0CeJ.js → ja-CrY_72Tn.js} +99 -54
  35. package/dist/{ja-C1HEWWTQ.js → ja-axQPxMJ-.js} +6 -6
  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-E_cYgZx-.js → page-yo1cw1kW.js} +5 -5
  40. package/dist/preview.js +8 -1
  41. package/dist/{profile-D6t1QMQh.js → profile-DBsXLvvI.js} +52 -52
  42. package/dist/rich-text.d.ts +1 -0
  43. package/dist/{body.js → rich-text.js} +20 -21
  44. package/dist/schema-Dcg1ajnW.js +1267 -0
  45. package/dist/schema.js +324 -1
  46. package/dist/types/access/src/handoff.d.ts +22 -17
  47. package/dist/types/access/src/index.d.ts +2 -2
  48. package/dist/types/access/src/jws.d.ts +41 -0
  49. package/dist/types/access/src/jwt.d.ts +1 -1
  50. package/dist/types/access/src/oidc.d.ts +11 -3
  51. package/dist/types/access/src/signed.d.ts +0 -2
  52. package/dist/types/adapter-cloudflare/src/eventLog/viewSchema.d.ts +11 -0
  53. package/dist/types/contract/src/accountProfile.d.ts +7 -0
  54. package/dist/types/{cms-contract → contract}/src/apiKeys.d.ts +7 -3
  55. package/dist/types/contract/src/app.d.ts +38 -0
  56. package/dist/types/contract/src/appChannels.d.ts +114 -0
  57. package/dist/types/contract/src/appDefinition.d.ts +133 -0
  58. package/dist/types/{cms-contract → contract}/src/appDependencies.d.ts +91 -35
  59. package/dist/types/contract/src/appIdentities.d.ts +21 -0
  60. package/dist/types/contract/src/appInbound.d.ts +28 -0
  61. package/dist/types/contract/src/appMail.d.ts +106 -0
  62. package/dist/types/contract/src/appSecrets.d.ts +45 -0
  63. package/dist/types/contract/src/appServer.d.ts +501 -0
  64. package/dist/types/contract/src/approvalLabels.d.ts +26 -0
  65. package/dist/types/contract/src/approvals.d.ts +63 -0
  66. package/dist/types/contract/src/apps.d.ts +295 -0
  67. package/dist/types/contract/src/auditActions.d.ts +18 -0
  68. package/dist/types/contract/src/auditLabels.d.ts +223 -0
  69. package/dist/types/contract/src/authorize.d.ts +133 -0
  70. package/dist/types/{cms-contract → contract}/src/bridge.d.ts +39 -40
  71. package/dist/types/{cms-contract → contract}/src/consents.d.ts +32 -25
  72. package/dist/types/contract/src/deletion.d.ts +18 -0
  73. package/dist/types/contract/src/embeds.d.ts +105 -0
  74. package/dist/types/{cms-contract/src/customerLabels.d.ts → contract/src/endUserLabels.d.ts} +6 -9
  75. package/dist/types/contract/src/endUsers.d.ts +241 -0
  76. package/dist/types/{cms-contract → contract}/src/errorLabels.d.ts +76 -47
  77. package/dist/types/{cms-contract → contract}/src/errorLabelsEn.d.ts +52 -36
  78. package/dist/types/contract/src/errors.d.ts +117 -0
  79. package/dist/types/contract/src/eventSchemas.d.ts +70 -0
  80. package/dist/types/contract/src/eventTraces.d.ts +43 -0
  81. package/dist/types/{cms-contract → contract}/src/failureStatus.d.ts +16 -23
  82. package/dist/types/contract/src/fieldAccess.d.ts +45 -0
  83. package/dist/types/contract/src/fieldRules.d.ts +41 -0
  84. package/dist/types/{cms-contract/src/assets.d.ts → contract/src/files.d.ts} +5 -5
  85. package/dist/types/contract/src/formLabels.d.ts +3 -0
  86. package/dist/types/contract/src/forms.d.ts +4 -0
  87. package/dist/types/{cms-contract → contract}/src/functions.d.ts +3 -3
  88. package/dist/types/contract/src/grants.d.ts +26 -0
  89. package/dist/types/contract/src/headers.d.ts +5 -0
  90. package/dist/types/contract/src/hostingRpc.d.ts +149 -0
  91. package/dist/types/contract/src/hostnames.d.ts +30 -0
  92. package/dist/types/contract/src/identifiers.d.ts +148 -0
  93. package/dist/types/contract/src/ids.d.ts +112 -0
  94. package/dist/types/{cms-contract → contract}/src/import.d.ts +20 -19
  95. package/dist/types/contract/src/importLabels.d.ts +3 -0
  96. package/dist/types/contract/src/index.d.ts +92 -0
  97. package/dist/types/contract/src/integrationGraph.d.ts +83 -0
  98. package/dist/types/{cms-contract → contract}/src/issueLabels.d.ts +135 -99
  99. package/dist/types/{cms-contract → contract}/src/issueLabelsEn.d.ts +70 -52
  100. package/dist/types/contract/src/labels.d.ts +11 -0
  101. package/dist/types/contract/src/legacyAuditLabels.d.ts +10 -0
  102. package/dist/types/contract/src/livePeriods.d.ts +18 -0
  103. package/dist/types/contract/src/manage.d.ts +51 -0
  104. package/dist/types/contract/src/manageLabels.d.ts +11 -0
  105. package/dist/types/contract/src/manifestText.d.ts +66 -0
  106. package/dist/types/contract/src/mcpAuth.d.ts +139 -0
  107. package/dist/types/contract/src/mcpLabels.d.ts +5 -0
  108. package/dist/types/contract/src/messagePort.d.ts +208 -0
  109. package/dist/types/{cms-contract → contract}/src/migration.d.ts +3 -3
  110. package/dist/types/contract/src/notices.d.ts +38 -0
  111. package/dist/types/contract/src/operatorOperations.d.ts +640 -0
  112. package/dist/types/contract/src/operators.d.ts +33 -0
  113. package/dist/types/contract/src/outbound.d.ts +29 -0
  114. package/dist/types/contract/src/paths.d.ts +34 -0
  115. package/dist/types/contract/src/pending.d.ts +6 -0
  116. package/dist/types/{cms-contract → contract}/src/permissions.d.ts +9 -11
  117. package/dist/types/contract/src/perspective.d.ts +26 -0
  118. package/dist/types/contract/src/powers.d.ts +5 -0
  119. package/dist/types/contract/src/principal.d.ts +181 -0
  120. package/dist/types/{cms-contract → contract}/src/problems.d.ts +4 -4
  121. package/dist/types/contract/src/projectRole.d.ts +6 -0
  122. package/dist/types/contract/src/recordLabels.d.ts +6 -0
  123. package/dist/types/{cms-contract → contract}/src/roles.d.ts +10 -6
  124. package/dist/types/contract/src/ruleLabels.d.ts +16 -0
  125. package/dist/types/contract/src/ruleProblems.d.ts +16 -0
  126. package/dist/types/contract/src/schemaLabels.d.ts +8 -0
  127. package/dist/types/{cms-contract → contract}/src/settingProblems.d.ts +3 -3
  128. package/dist/types/{cms-contract → contract}/src/settings.d.ts +6 -8
  129. package/dist/types/contract/src/settingsLabels.d.ts +3 -0
  130. package/dist/types/{cms-contract → contract}/src/siteDeclaration.d.ts +7 -7
  131. package/dist/types/contract/src/siteIndex.d.ts +76 -0
  132. package/dist/types/contract/src/slugs.d.ts +6 -0
  133. package/dist/types/{cms-contract → contract}/src/transfer.d.ts +4 -4
  134. package/dist/types/contract/src/trial.d.ts +13 -0
  135. package/dist/types/contract/src/versions.d.ts +7 -0
  136. package/dist/types/{analytics/src/view.d.ts → contract/src/viewEvent.d.ts} +0 -9
  137. package/dist/types/contract/src/webhooks.d.ts +135 -0
  138. package/dist/types/contract/src/workflow.d.ts +43 -0
  139. package/dist/types/contract/src/workspaceItems.d.ts +87 -0
  140. package/dist/types/contract/src/workspacePaths.d.ts +4 -0
  141. package/dist/types/{body → rich-text}/src/declared.d.ts +2 -2
  142. package/dist/types/{body → rich-text}/src/embed.d.ts +1 -1
  143. package/dist/types/{body → rich-text}/src/html.d.ts +1 -1
  144. package/dist/types/{body → rich-text}/src/index.d.ts +8 -7
  145. package/dist/types/{body → rich-text}/src/labels/en.d.ts +1 -1
  146. package/dist/types/{body → rich-text}/src/labels/ja.d.ts +4 -4
  147. package/dist/types/{body → rich-text}/src/library.d.ts +1 -1
  148. package/dist/types/rich-text/src/media.d.ts +2 -0
  149. package/dist/types/{body → rich-text}/src/normalize.d.ts +1 -1
  150. package/dist/types/{body → rich-text}/src/problems.d.ts +5 -5
  151. package/dist/types/{body → rich-text}/src/profile.d.ts +11 -11
  152. package/dist/types/{body → rich-text}/src/render.d.ts +1 -1
  153. package/dist/types/{body → rich-text}/src/schema.d.ts +2 -2
  154. package/dist/types/{body → rich-text}/src/standard.d.ts +4 -4
  155. package/dist/types/{body → rich-text}/src/types.d.ts +2 -2
  156. package/dist/types/schema/src/audience.d.ts +36 -0
  157. package/dist/types/schema/src/brand.d.ts +5 -0
  158. package/dist/types/schema/src/capabilities.d.ts +19 -0
  159. package/dist/types/{model → schema}/src/changes.d.ts +9 -7
  160. package/dist/types/{model → schema}/src/check.d.ts +2 -2
  161. package/dist/types/{model/src/model.d.ts → schema/src/collection.d.ts} +150 -121
  162. package/dist/types/schema/src/defaultSchema.d.ts +15 -0
  163. package/dist/types/schema/src/fieldIds.d.ts +18 -0
  164. package/dist/types/{model/src/asset.d.ts → schema/src/file.d.ts} +36 -25
  165. package/dist/types/schema/src/fileRefs.d.ts +14 -0
  166. package/dist/types/schema/src/fileSignature.d.ts +20 -0
  167. package/dist/types/schema/src/filesCollection.d.ts +7 -0
  168. package/dist/types/schema/src/forms.d.ts +43 -0
  169. package/dist/types/{model → schema}/src/image.d.ts +3 -3
  170. package/dist/types/schema/src/imageMetadata.d.ts +9 -0
  171. package/dist/types/schema/src/index.d.ts +35 -0
  172. package/dist/types/{model → schema}/src/input.d.ts +3 -3
  173. package/dist/types/{model → schema}/src/integrity.d.ts +9 -8
  174. package/dist/types/schema/src/kinds.d.ts +26 -0
  175. package/dist/types/{model → schema}/src/labels/en.d.ts +93 -51
  176. package/dist/types/{model → schema}/src/labels/ja.d.ts +97 -52
  177. package/dist/types/schema/src/mediaUrl.d.ts +60 -0
  178. package/dist/types/{model → schema}/src/page.d.ts +6 -6
  179. package/dist/types/{model → schema}/src/problems.d.ts +95 -53
  180. package/dist/types/{model → schema}/src/refs.d.ts +1 -10
  181. package/dist/types/{model → schema}/src/rules.d.ts +2 -2
  182. package/dist/types/{model → schema}/src/schema.d.ts +25 -20
  183. package/dist/types/schema/src/selfOps.d.ts +31 -0
  184. package/dist/types/{model/src/capabilities.d.ts → schema/src/traits.d.ts} +6 -6
  185. package/dist/types/schema/src/typesSource.d.ts +16 -0
  186. package/dist/types/{model → schema}/src/values.d.ts +7 -4
  187. package/dist/types/schema/src/widening.d.ts +3 -0
  188. package/dist/types/sdk/src/analytics.d.ts +3 -2
  189. package/dist/types/sdk/src/app.d.ts +70 -16
  190. package/dist/types/sdk/src/astro-image.d.ts +19 -0
  191. package/dist/types/sdk/src/astro-response.d.ts +6 -0
  192. package/dist/types/sdk/src/astro-server.d.ts +16 -0
  193. package/dist/types/sdk/src/astro.d.ts +19 -0
  194. package/dist/types/sdk/src/bridge.d.ts +13 -15
  195. package/dist/types/sdk/src/code.d.ts +61 -0
  196. package/dist/types/sdk/src/delegation.d.ts +49 -0
  197. package/dist/types/sdk/src/delivery/changes.d.ts +4 -4
  198. package/dist/types/sdk/src/delivery/client.d.ts +40 -28
  199. package/dist/types/sdk/src/delivery/fields.d.ts +5 -5
  200. package/dist/types/sdk/src/delivery/index.d.ts +3 -3
  201. package/dist/types/sdk/src/delivery/media.d.ts +8 -11
  202. package/dist/types/sdk/src/delivery/query.d.ts +16 -12
  203. package/dist/types/sdk/src/delivery/schema.d.ts +5 -5
  204. package/dist/types/sdk/src/delivery/values.d.ts +16 -20
  205. package/dist/types/sdk/src/delivery.d.ts +3 -3
  206. package/dist/types/sdk/src/dev-operations.d.ts +20 -0
  207. package/dist/types/sdk/src/dev.d.ts +6 -5
  208. package/dist/types/sdk/src/end-users.d.ts +190 -0
  209. package/dist/types/sdk/src/i18n.d.ts +11 -11
  210. package/dist/types/sdk/src/integrations.d.ts +20 -27
  211. package/dist/types/sdk/src/operations.d.ts +17 -0
  212. package/dist/types/sdk/src/preview.d.ts +2 -1
  213. package/dist/types/sdk/src/rich-text.d.ts +2 -0
  214. package/dist/types/sdk/src/schema.d.ts +5 -21
  215. package/dist/types/sdk/src/site/artifact.d.ts +64 -0
  216. package/dist/types/sdk/src/site/build-file.d.ts +30 -0
  217. package/dist/types/sdk/src/site/check-code.d.ts +14 -0
  218. package/dist/types/sdk/src/site/check-text.d.ts +19 -0
  219. package/dist/types/sdk/src/site/cli.d.ts +52 -0
  220. package/dist/types/sdk/src/site/content-type.d.ts +2 -0
  221. package/dist/types/sdk/src/site/labels.d.ts +14 -0
  222. package/dist/types/sdk/src/site.d.ts +1 -1
  223. package/dist/types/sdk/src/types.d.ts +21 -0
  224. package/dist/{schema-BPHL7Qr-.js → types-DkO2N7u2.js} +9 -9
  225. package/dist/types.d.ts +1 -0
  226. package/dist/types.js +1 -0
  227. package/dist/typesSource-VJIxtN9b.js +136 -0
  228. package/dist/workflow-CUpl6hO_.js +148 -0
  229. package/package.json +42 -16
  230. package/dist/apps-9u4XMi7E.js +0 -114
  231. package/dist/body.d.ts +0 -1
  232. package/dist/bridge-DYAYGV7t.js +0 -74
  233. package/dist/customers.d.ts +0 -1
  234. package/dist/customers.js +0 -185
  235. package/dist/embed-R-OvDYAw.js +0 -90
  236. package/dist/model-pmXzGX12.js +0 -152
  237. package/dist/model.d.ts +0 -1
  238. package/dist/model.js +0 -345
  239. package/dist/schema-UQJWRyfJ.js +0 -995
  240. package/dist/src-sazhzYui.js +0 -71
  241. package/dist/types/analytics/src/index.d.ts +0 -5
  242. package/dist/types/analytics/src/schedule.d.ts +0 -2
  243. package/dist/types/analytics/src/shared.d.ts +0 -21
  244. package/dist/types/analytics/src/source.d.ts +0 -19
  245. package/dist/types/analytics/src/store.d.ts +0 -24
  246. package/dist/types/cms-contract/src/app.d.ts +0 -35
  247. package/dist/types/cms-contract/src/apps.d.ts +0 -195
  248. package/dist/types/cms-contract/src/authorize.d.ts +0 -146
  249. package/dist/types/cms-contract/src/customers.d.ts +0 -266
  250. package/dist/types/cms-contract/src/embeds.d.ts +0 -165
  251. package/dist/types/cms-contract/src/errors.d.ts +0 -105
  252. package/dist/types/cms-contract/src/identifiers.d.ts +0 -117
  253. package/dist/types/cms-contract/src/paths.d.ts +0 -23
  254. package/dist/types/cms-contract/src/urlLabel.d.ts +0 -13
  255. package/dist/types/cms-contract/src/webhooks.d.ts +0 -139
  256. package/dist/types/model/src/audience.d.ts +0 -38
  257. package/dist/types/model/src/brand.d.ts +0 -25
  258. package/dist/types/model/src/index.d.ts +0 -26
  259. package/dist/types/model/src/legacy.d.ts +0 -2
  260. package/dist/types/model/src/media.d.ts +0 -5
  261. package/dist/types/model/src/mediaUrl.d.ts +0 -67
  262. package/dist/types/model/src/selfOps.d.ts +0 -30
  263. package/dist/types/model/src/typesSource.d.ts +0 -8
  264. package/dist/types/platform/src/defaultModel.d.ts +0 -8
  265. package/dist/types/sdk/src/body.d.ts +0 -2
  266. package/dist/types/sdk/src/customers.d.ts +0 -190
  267. package/dist/types/sdk/src/model.d.ts +0 -5
  268. package/dist/typesSource-bO0jFw1I.js +0 -88
  269. /package/dist/types/{cms-contract → contract}/src/appProblems.d.ts +0 -0
  270. /package/dist/types/{analytics → contract}/src/day.d.ts +0 -0
  271. /package/dist/types/{cms-contract → contract}/src/functionLabels.d.ts +0 -0
  272. /package/dist/types/{cms-contract → contract}/src/permissionLabels.d.ts +0 -0
  273. /package/dist/types/{cms-contract → contract}/src/siteArtifact.d.ts +0 -0
  274. /package/dist/types/{cms-contract → contract}/src/views.d.ts +0 -0
  275. /package/dist/types/{cms-contract → contract}/src/webhookLabels.d.ts +0 -0
  276. /package/dist/types/{body → rich-text}/src/components.d.ts +0 -0
  277. /package/dist/types/{body → rich-text}/src/derive.d.ts +0 -0
  278. /package/dist/types/{body → rich-text}/src/description.d.ts +0 -0
  279. /package/dist/types/{body → rich-text}/src/href.d.ts +0 -0
  280. /package/dist/types/{body → rich-text}/src/inline.d.ts +0 -0
  281. /package/dist/types/{body → rich-text}/src/markdown.d.ts +0 -0
  282. /package/dist/types/{model → schema}/src/contact.d.ts +0 -0
  283. /package/dist/types/{model → schema}/src/json.d.ts +0 -0
  284. /package/dist/types/{model → schema}/src/screens.d.ts +0 -0
  285. /package/dist/types/{model → schema}/src/time.d.ts +0 -0
package/dist/app.js CHANGED
@@ -1,11 +1,15 @@
1
- import { g as JSON_BODY_MAX, h as ERROR_STATUS, n as errorBodyFor } from "./errorLabels-CPKiPabZ.js";
2
- import { c as formatMessage, d as problemOf, f as problemText } from "./ja-C1HEWWTQ.js";
3
- import { i as CUSTOMER_STATUSES } from "./customers-C_vJY2_v.js";
4
- import { i as bodyProblemText, n as embedOfUrl } from "./embed-R-OvDYAw.js";
5
- 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-D6t1QMQh.js";
6
- import { b as isPublishable, t as AUDIENCES } from "./model-pmXzGX12.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";
7
11
  import { parseDocument } from "htmlparser2";
8
- // ../body/src/normalize.ts
12
+ // ../rich-text/src/normalize.ts
9
13
  const keyOf = (inline) => "component" in inline ? null : JSON.stringify([
10
14
  sortMarks(inline.marks),
11
15
  inline.link ?? null,
@@ -51,7 +55,7 @@ const normalizeCell = (cell) => isTableCell(cell) ? {
51
55
  content: cell.content.map(normalizeRich)
52
56
  } : normalizeRich(cell);
53
57
  /** 本文を正規化 */
54
- function normalizeBody(body) {
58
+ function normalizeRichText(body) {
55
59
  return body.map((block) => {
56
60
  switch (block.type) {
57
61
  case "paragraph":
@@ -73,7 +77,7 @@ function normalizeBody(body) {
73
77
  }
74
78
  });
75
79
  }
76
- // ../body/src/html.ts
80
+ // ../rich-text/src/html.ts
77
81
  /** 内容ごと捨てる要素 */
78
82
  const DANGEROUS = /* @__PURE__ */ new Set([
79
83
  "script",
@@ -178,7 +182,7 @@ const intOf = (v) => {
178
182
  return Number.isFinite(n) && n > 0 ? n : void 0;
179
183
  };
180
184
  /** HTML を本文に(コピーできないものは dropped) */
181
- function bodyFromHtml(html, options) {
185
+ function richTextFromHtml(html, options) {
182
186
  const counts = /* @__PURE__ */ new Map();
183
187
  const drop = (what) => counts.set(what, (counts.get(what) ?? 0) + 1);
184
188
  const alignOf = (el) => {
@@ -187,9 +191,9 @@ function bodyFromHtml(html, options) {
187
191
  };
188
192
  /** 要素の属性と style のうち、コピーできないものを数える(used はコピーした style の項目) */
189
193
  const audit = (el, used = []) => {
190
- for (const name of Object.keys(el.attribs)) if (name.startsWith("on")) drop(bodyProblemText("drop_attribute", { name }));
191
- else if (!SILENT_ATTRS.has(name) && !name.startsWith("data-") && !name.startsWith("aria-")) drop(bodyProblemText("drop_attribute", { name }));
192
- 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 }));
193
197
  };
194
198
  const classesOf = (el) => (el.attribs.class ?? "").split(/\s+/).filter(Boolean);
195
199
  /** span などの見た目(コピーできない class と style の項目は数える) */
@@ -202,7 +206,7 @@ function bodyFromHtml(html, options) {
202
206
  if (!value) continue;
203
207
  used.push(key);
204
208
  if (!isSafeCssValue(kind, value)) {
205
- drop(bodyProblemText("drop_style_value", { key }));
209
+ drop(richTextProblemText("drop_style_value", { key }));
206
210
  continue;
207
211
  }
208
212
  const name = options.nameOf?.(kind, value);
@@ -214,7 +218,7 @@ function bodyFromHtml(html, options) {
214
218
  if (decls.has("text-align")) used.push("text-align");
215
219
  const kept = classesOf(el).filter((c) => {
216
220
  if (options.styleClass?.(c)) return true;
217
- drop(bodyProblemText("drop_class", { name: c }));
221
+ drop(richTextProblemText("drop_class", { name: c }));
218
222
  return false;
219
223
  });
220
224
  if (kept.length) style.styles = kept;
@@ -225,7 +229,7 @@ function bodyFromHtml(html, options) {
225
229
  const href = el.attribs.href?.trim();
226
230
  if (!href) return void 0;
227
231
  if (!isSafeHref(href)) {
228
- drop(bodyProblemText("drop_unsafe_link"));
232
+ drop(richTextProblemText("drop_unsafe_link"));
229
233
  return;
230
234
  }
231
235
  const rel = el.attribs.rel?.trim();
@@ -251,7 +255,7 @@ function bodyFromHtml(html, options) {
251
255
  if (!isElement(node)) return [];
252
256
  const name = node.name.toLowerCase();
253
257
  if (DANGEROUS.has(name) || name === "iframe") {
254
- drop(bodyProblemText("drop_element", { name }));
258
+ drop(richTextProblemText("drop_element", { name }));
255
259
  return [];
256
260
  }
257
261
  if (name === "br") return ["\n"];
@@ -260,7 +264,7 @@ function bodyFromHtml(html, options) {
260
264
  img: node,
261
265
  ...ctx.link ? { link: ctx.link } : {}
262
266
  });
263
- else drop(bodyProblemText("drop_inline_image"));
267
+ else drop(richTextProblemText("drop_inline_image"));
264
268
  return [];
265
269
  }
266
270
  const mark = HTML_TAG_MARKS[name];
@@ -285,7 +289,7 @@ function bodyFromHtml(html, options) {
285
289
  style: mergeStyle(ctx.style, style)
286
290
  });
287
291
  }
288
- if (!BLOCK_TAGS.has(name)) drop(bodyProblemText("drop_element", { name }));
292
+ if (!BLOCK_TAGS.has(name)) drop(richTextProblemText("drop_element", { name }));
289
293
  return inlines(node.children, ctx);
290
294
  });
291
295
  /** 断片の列(images があれば中の画像をそこへ集める) */
@@ -309,7 +313,7 @@ function bodyFromHtml(html, options) {
309
313
  const hasText = (r) => r.some((i) => typeof i === "string" ? i.trim() : "text" in i ? (i.text ?? "").trim() : true);
310
314
  /** 集めた画像を画像のブロックに(where は数える場所) */
311
315
  const hoistedBlocks = (images, where) => images.flatMap(({ img, link }) => {
312
- drop(bodyProblemText("drop_hoisted_image", { where }));
316
+ drop(richTextProblemText("drop_hoisted_image", { where }));
313
317
  const image = imageOf(img, link ? { link } : {});
314
318
  return image ? [image] : [];
315
319
  });
@@ -328,7 +332,7 @@ function bodyFromHtml(html, options) {
328
332
  };
329
333
  /** キャプション・表の説明の文字(文字だけの項目のため、装飾は捨てて数える、中の画像は images へ) */
330
334
  const captionText = (el, images) => {
331
- 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"));
332
336
  return textOf(el.children.filter((c) => !(isElement(c) && c.name === "img"))).trim();
333
337
  };
334
338
  const HEADINGS = /* @__PURE__ */ new Set([
@@ -360,38 +364,38 @@ function bodyFromHtml(html, options) {
360
364
  const name = el.name.toLowerCase();
361
365
  if (name === "p") push(rich(el.children, images));
362
366
  else if (name === "ul" || name === "ol") {
363
- drop(bodyProblemText("drop_flattened", {
367
+ drop(richTextProblemText("drop_flattened", {
364
368
  where,
365
369
  what: "list"
366
370
  }));
367
371
  listParagraphs(listOf(el, images), "").forEach(push);
368
372
  } else if (HEADINGS.has(name)) {
369
- drop(bodyProblemText("drop_flattened", {
373
+ drop(richTextProblemText("drop_flattened", {
370
374
  where,
371
375
  what: "heading"
372
376
  }));
373
377
  push(rich(el.children, images));
374
378
  } else if (name === "blockquote") {
375
- drop(bodyProblemText("drop_flattened", {
379
+ drop(richTextProblemText("drop_flattened", {
376
380
  where,
377
381
  what: "quote"
378
382
  }));
379
383
  paragraphsOf(el.children, where, images).forEach(push);
380
384
  } else if (name === "pre") {
381
- drop(bodyProblemText("drop_flattened", {
385
+ drop(richTextProblemText("drop_flattened", {
382
386
  where,
383
387
  what: "code"
384
388
  }));
385
389
  push([textOf(el.children).replace(/\n$/, "")]);
386
390
  } else if (name === "table") {
387
- drop(bodyProblemText("drop_flattened", {
391
+ drop(richTextProblemText("drop_flattened", {
388
392
  where,
389
393
  what: "table"
390
394
  }));
391
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])])));
392
396
  } else if (name === "img") images.push({ img: el });
393
397
  else if (name === "figure") {
394
- drop(bodyProblemText("drop_flattened", {
398
+ drop(richTextProblemText("drop_flattened", {
395
399
  where,
396
400
  what: "figure"
397
401
  }));
@@ -402,7 +406,7 @@ function bodyFromHtml(html, options) {
402
406
  const figcaption = findDeep(el, (e) => e.name === "figcaption");
403
407
  if (figcaption) push([captionText(figcaption, [])]);
404
408
  } else if (CONTAINERS.has(name)) paragraphsOf(el.children, where, images).forEach(push);
405
- else drop(bodyProblemText("drop_inner_element", {
409
+ else drop(richTextProblemText("drop_inner_element", {
406
410
  where,
407
411
  name
408
412
  }));
@@ -427,7 +431,7 @@ function bodyFromHtml(html, options) {
427
431
  };
428
432
  const embedBlock = (url, el) => {
429
433
  if (!url || !URL.parse(url)) {
430
- drop(bodyProblemText("drop_embed_no_url"));
434
+ drop(richTextProblemText("drop_embed_no_url"));
431
435
  return null;
432
436
  }
433
437
  const target = embedOfUrl(url);
@@ -444,7 +448,7 @@ function bodyFromHtml(html, options) {
444
448
  }
445
449
  };
446
450
  if (!url.startsWith("https://")) {
447
- drop(bodyProblemText("drop_embed_not_https"));
451
+ drop(richTextProblemText("drop_embed_not_https"));
448
452
  return null;
449
453
  }
450
454
  return {
@@ -476,7 +480,7 @@ function bodyFromHtml(html, options) {
476
480
  const imageOf = (img, extra = {}) => {
477
481
  const src = img.attribs.src?.trim();
478
482
  if (!src) {
479
- drop(bodyProblemText("drop_image_no_src"));
483
+ drop(richTextProblemText("drop_image_no_src"));
480
484
  return null;
481
485
  }
482
486
  const alt = img.attribs.alt?.trim();
@@ -484,7 +488,7 @@ function bodyFromHtml(html, options) {
484
488
  const height = intOf(img.attribs.height);
485
489
  return {
486
490
  type: "image",
487
- media: options.image(src, {
491
+ file: options.image(src, {
488
492
  ...alt ? { alt } : {},
489
493
  ...width ? { width } : {},
490
494
  ...height ? { height } : {}
@@ -497,11 +501,11 @@ function bodyFromHtml(html, options) {
497
501
  const listOf = (el, images) => {
498
502
  const items = el.children.filter(isElement).flatMap((li) => {
499
503
  if (li.name !== "li") {
500
- drop(bodyProblemText("drop_list_element", { name: li.name }));
504
+ drop(richTextProblemText("drop_list_element", { name: li.name }));
501
505
  return [];
502
506
  }
503
507
  const nestedLists = li.children.filter((c) => isElement(c) && (c.name === "ul" || c.name === "ol"));
504
- if (nestedLists.length > 1) drop(bodyProblemText("drop_extra_nested_list"));
508
+ if (nestedLists.length > 1) drop(richTextProblemText("drop_extra_nested_list"));
505
509
  const inner = li.children.filter((c) => !nestedLists.includes(c));
506
510
  const paragraphs = inner.filter((c) => isElement(c) && c.name === "p");
507
511
  const content = paragraphs.length ? normalizeRich(paragraphs.flatMap((p, i) => [...i ? ["\n"] : [], ...rich(p.children, images)])) : rich(inner, images);
@@ -527,7 +531,7 @@ function bodyFromHtml(html, options) {
527
531
  if (!isElement(c)) continue;
528
532
  if (c.name === "tr") rows.push(c);
529
533
  else if (c.name === "thead" || c.name === "tbody" || c.name === "tfoot") collect(c);
530
- 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 }));
531
535
  }
532
536
  };
533
537
  collect(el);
@@ -574,7 +578,7 @@ function bodyFromHtml(html, options) {
574
578
  return DANGEROUS.has(name) || BLOCK_TAGS.has(name) || name === "a" && el.attribs["data-embed-type"] === "file" && Boolean(options.file);
575
579
  }, (run) => out.push(...paragraphBlocks(run, void 0)), (el) => {
576
580
  const name = el.name.toLowerCase();
577
- if (DANGEROUS.has(name)) drop(bodyProblemText("drop_element", { name }));
581
+ if (DANGEROUS.has(name)) drop(richTextProblemText("drop_element", { name }));
578
582
  else if (name === "a") out.push(fileOf(el));
579
583
  else out.push(...blockOf(el));
580
584
  });
@@ -616,7 +620,7 @@ function bodyFromHtml(html, options) {
616
620
  const name = textOf(a.children).trim();
617
621
  return {
618
622
  type: "file",
619
- media: options.file(a.attribs.href ?? "", {
623
+ file: options.file(a.attribs.href ?? "", {
620
624
  ...a.attribs["data-mime-type"] ? { mime: a.attribs["data-mime-type"] } : {},
621
625
  ...name ? { name } : {}
622
626
  }),
@@ -714,17 +718,31 @@ function bodyFromHtml(html, options) {
714
718
  }
715
719
  };
716
720
  return {
717
- body: normalizeBody(blocks(parseDocument(html, { decodeEntities: true }).children)),
721
+ body: normalizeRichText(blocks(parseDocument(html, { decodeEntities: true }).children)),
718
722
  dropped: [...counts].map(([what, count]) => ({
719
723
  what,
720
724
  count
721
725
  }))
722
726
  };
723
727
  }
724
- // ../cms-contract/src/app.ts
725
- /** サーバーの側の宣言(コレクションの確認だけ) */
726
- const defineAppServer = (manifest) => manifest;
727
- // ../cms-contract/src/appProblems.ts
728
+ // ../contract/src/appMail.ts
729
+ /** 能力の要素(送信、受信) */
730
+ const MAIL_CAPABILITIES = {
731
+ send: "mail:send",
732
+ inbound: "mail:inbound"
733
+ };
734
+ /**
735
+ * 送らなかった理由
736
+ * - suppressed: 抑止の一覧、no_consent: 同意の目的で送れない
737
+ * - domain_unverified: 差出人のドメインが検証されていない、test_environment: live 以外の環境
738
+ */
739
+ const APP_MAIL_SKIP_REASONS = [
740
+ "suppressed",
741
+ "no_consent",
742
+ "domain_unverified",
743
+ "test_environment"
744
+ ];
745
+ // ../contract/src/appProblems.ts
728
746
  /** 問題の表から、問題を作る関数(差し込みの不足は型の誤り) */
729
747
  function appProblems(tables) {
730
748
  const of = (code, params) => ({
@@ -746,56 +764,202 @@ function appProblems(tables) {
746
764
  }
747
765
  };
748
766
  }
749
- // ../cms-contract/src/import.ts
750
- /** 1回のリクエストで取り込む件数の上限(画像の取得の時間と、本文の大きさの上限 JSON_BODY_MAX のため) */
751
- const IMPORT_ITEMS_MAX = 50;
752
- /** 参照の項目の値で、同じ取り出し元の元の ID を指す形の印({ "$origin": "<元の ID>" }) */
753
- const ORIGIN_REF = "$origin";
754
- /** 顧客フィールドの値で、人の元の ID を指す形の印({ "$customer": "<元の ID>" }) */
755
- const CUSTOMER_REF = "$customer";
756
- /** 元の ID を指す値の元の ID(印 marker の1つのキーで値が文字列、ほかは null) */
757
- function originIdOf(value, marker) {
758
- if (typeof value !== "object" || value === null || Array.isArray(value)) return null;
759
- const records = Object.entries(value);
760
- return records.length === 1 && records[0][0] === marker && typeof records[0][1] === "string" ? records[0][1] : null;
767
+ // ../contract/src/settingProblems.ts
768
+ /** アプリの設定値の問題(key は設定値のキー、params は文に差し込む値) */
769
+ var SettingProblem = class extends Error {
770
+ key;
771
+ problem;
772
+ params;
773
+ constructor(key, problem, params = {}) {
774
+ super(`app setting ${key}: ${problem}${Object.keys(params).length ? ` ${JSON.stringify(params)}` : ""}`);
775
+ this.name = "SettingProblem";
776
+ this.key = key;
777
+ this.problem = problem;
778
+ this.params = params;
779
+ }
780
+ };
781
+ /** 設定値の問題の既定の形(field は項目名) */
782
+ const settingProblemText = (p, field) => problemText({
783
+ code: `setting_${p.problem}`,
784
+ params: {
785
+ ...p.params,
786
+ field
787
+ }
788
+ });
789
+ // ../contract/src/workspaceItems.ts
790
+ /** 日付のフィールドの予定が持つ source(`field:<コレクション>.<フィールド>`) */
791
+ const calendarFieldSource = (f) => `field:${f.collection}.${f.field}`;
792
+ // ../contract/src/appDefinition.ts
793
+ /** 設定値のないアプリの設定値の解釈 */
794
+ const NO_SETTINGS = { parse: () => ({}) };
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;
761
811
  }
762
- const isOriginRef = (v) => originIdOf(v, ORIGIN_REF) !== null;
763
- /** 元の ID を指す参照({ "$origin" })を除いた値(まとまりの中と配列の要素も。循環の1段目の項目) */
764
- function withoutOrigins(value) {
765
- if (Array.isArray(value)) return value.filter((v) => !isOriginRef(v)).map(withoutOrigins);
766
- if (typeof value !== "object" || value === null) return value;
767
- return Object.fromEntries(Object.entries(value).flatMap(([k, v]) => isOriginRef(v) ? [] : [[k, withoutOrigins(v)]]));
812
+ /** 外への読み込みの宛先の宣言に URL が当たるか(宣言は https のオリジン、ホスト名の先頭の `*.` は1つ以上の区間。https だけ、ポートの指定なし) */
813
+ function egressAllows(declared, url) {
814
+ if (url.protocol !== "https:" || url.port !== "") return false;
815
+ return declared.some((d) => {
816
+ const m = /^https:\/\/(\*\.)?([a-z0-9.-]+)$/.exec(d);
817
+ if (!m) return false;
818
+ return m[1] ? url.hostname.endsWith(`.${m[2]}`) : url.hostname === m[2];
819
+ });
768
820
  }
769
- /** 入力の形のレコードを取り込みの1件に(at は報告の位置、phase はコレクションどうしの循環のフェーズで、1段目は参照を除く) */
770
- const importItemOfRow = (line, at, phase) => ({
771
- collection: line.collection,
772
- ...line.new_id !== void 0 && { id: line.new_id },
773
- fields: phase === 1 ? withoutOrigins(line.fields) : line.fields,
774
- source: at,
775
- origin_id: line.id,
776
- ...phase !== void 0 && { phase },
777
- ...line.created_at !== void 0 && { created_at: line.created_at }
778
- });
779
- /** 取り込む ID(前後の空白を除き小文字に、changed は大文字を含んでいた) */
780
- function importIdOf(raw) {
781
- const trimmed = raw.trim();
782
- const id = trimmed.toLowerCase();
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);
783
842
  return {
784
- id,
785
- changed: id !== trimmed
843
+ ok: true,
844
+ value: records
786
845
  };
787
846
  }
788
- /** 関係が循環する API のエンドポイント(関係をたどって自分に戻る、自分への関係を含む。参照なしと参照ありの2フェーズで取り込む) */
789
- function cyclicCollections(apis) {
790
- const reaches = (from, goal, seen) => Object.values(from.relations).some((target) => {
791
- if (target === goal) return true;
792
- if (seen.has(target)) return false;
793
- seen.add(target);
794
- const next = apis.find((x) => x.endpoint === target);
795
- return next ? reaches(next, goal, seen) : false;
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 };
868
+ // ../contract/src/workspacePaths.ts
869
+ /** ワークスペースのコレクションの経路(URL はレコードのスラッグ、record を省くと一覧) */
870
+ const workspaceRecordPath = (collection, record) => `/collections/${encodeURIComponent(collection.slug)}/records${record === void 0 ? "" : `/${encodeURIComponent(String(record.slug))}`}`;
871
+ // src/delegation.ts
872
+ /** アプリの JWT の有効の秒数(INSTALLATION_TOKEN.appJwtMaxSec の内) */
873
+ const ASSERTION_TTL_SEC = 60;
874
+ const base64Url = (bytes) => btoa(String.fromCharCode(...bytes)).replace(/\+/g, "-").replace(/\//g, "_").replace(/=+$/, "");
875
+ const textPart = (value) => base64Url(new TextEncoder().encode(JSON.stringify(value)));
876
+ /** アプリの JWT(iss はアプリの ID、aud は配信の基点) */
877
+ async function appAssertion(key, claims, nowMs = Date.now()) {
878
+ const { kid, ...jwk } = key.jwk;
879
+ const pq = jwk.kty === "AKP";
880
+ const signer = await crypto.subtle.importKey("jwk", {
881
+ ...jwk,
882
+ key_ops: ["sign"]
883
+ }, pq ? { name: "ML-DSA-44" } : {
884
+ name: "ECDSA",
885
+ namedCurve: "P-256"
886
+ }, false, ["sign"]);
887
+ const iat = Math.floor(nowMs / 1e3);
888
+ const input = `${textPart({
889
+ alg: pq ? "ML-DSA-44" : "ES256",
890
+ typ: "JWT",
891
+ ...kid && { kid }
892
+ })}.${textPart({
893
+ iss: claims.appId,
894
+ aud: claims.audience,
895
+ iat,
896
+ exp: iat + Math.min(ASSERTION_TTL_SEC, INSTALLATION_TOKEN.appJwtMaxSec)
897
+ })}`;
898
+ const signature = new Uint8Array(await crypto.subtle.sign(pq ? { name: "ML-DSA-44" } : {
899
+ name: "ECDSA",
900
+ hash: "SHA-256"
901
+ }, signer, new TextEncoder().encode(input)));
902
+ return `${input}.${base64Url(signature)}`;
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
+ }
914
+ /** 代理の委任の主張をアカウントの資格のトークンに替える */
915
+ const exchangeDelegation = (input) => exchanged(input, input.delegation);
916
+ /** 画面のトークンをアカウントの資格のトークンに替える(結果の形は exchangeDelegation と同じ) */
917
+ const exchangeSessionToken = (input) => exchanged(input, input.sessionToken);
918
+ async function exchanged(input, subject) {
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
+ };
926
+ const body = new URLSearchParams({
927
+ grant_type: TOKEN_EXCHANGE.grantType,
928
+ subject_token: subject,
929
+ subject_token_type: TOKEN_EXCHANGE.subjectTokenType,
930
+ client_assertion_type: TOKEN_EXCHANGE.clientAssertionType,
931
+ client_assertion: await appAssertion(input.key, {
932
+ appId: input.appId,
933
+ audience
934
+ })
796
935
  });
797
- return new Set(apis.filter((a) => reaches(a, a.endpoint, /* @__PURE__ */ new Set())).map((a) => a.endpoint));
936
+ const res = await send(new Request(`${input.base}/api/embeds/token`, {
937
+ method: "POST",
938
+ headers: { "content-type": "application/x-www-form-urlencoded" },
939
+ body: body.toString()
940
+ }));
941
+ const parsed = await res.json().catch(() => null);
942
+ if (res.ok && typeof parsed?.access_token === "string") return {
943
+ ok: true,
944
+ token: parsed.access_token,
945
+ expiresIn: Number(parsed.expires_in ?? 0)
946
+ };
947
+ return {
948
+ ok: false,
949
+ error: typeof parsed?.error === "string" ? parsed.error : "upstream",
950
+ status: res.status
951
+ };
798
952
  }
953
+ /** アカウントの資格のトークンで管理 API を呼ぶクライアント(path は /api の下、base は環境の CMS の URL) */
954
+ const bearerClient = (input) => ({ fetch: (path, init = {}) => {
955
+ const headers = new Headers(init.headers);
956
+ headers.set("authorization", `Bearer ${input.token}`);
957
+ const request = new Request(`${input.base}${path}`, {
958
+ ...init,
959
+ headers
960
+ });
961
+ return input.fetch ? input.fetch(request) : fetch(request);
962
+ } });
799
963
  // src/app.ts
800
964
  /** 相関の ID のヘッダー(CMS の応答とログと同じ名前) */
801
965
  const REQUEST_ID_HEADER = "x-request-id";
@@ -810,16 +974,79 @@ const appIssue = (i) => ({
810
974
  severity: i.severity ?? "error"
811
975
  });
812
976
  /** エラーの応答(CMS の API と同じ形、相関の ID は要求の x-request-id。extra は issues などの足し) */
813
- function appFailure(request, code, params, extra = {}) {
814
- const given = request.headers.get(REQUEST_ID_HEADER);
815
- const requestId = given && REQUEST_ID_FORM.test(given) ? given : crypto.randomUUID();
816
- return Response.json({
817
- ...errorBodyFor(code, requestId, params),
818
- ...extra,
819
- requestId
820
- }, {
821
- status: ERROR_STATUS[code],
822
- headers: { [REQUEST_ID_HEADER]: requestId }
977
+ const appFailure = appFailureOf({});
978
+ /** エラーの応答を作る関数(targets はアプリの対象の英語の名前、キーは対象の id。message の対象の名前に使う) */
979
+ function appFailureOf(targets) {
980
+ return (request, code, params, extra = {}) => {
981
+ const given = request.headers.get(REQUEST_ID_HEADER);
982
+ const requestId = given && REQUEST_ID_FORM.test(given) ? given : newUuidV7();
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 });
990
+ };
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
+ }
1007
+ /** 本文の JSON(空の本文は empty、壊れた JSON は400の応答) */
1008
+ async function appJson(request, empty = null) {
1009
+ const text = await request.text();
1010
+ if (!text.trim()) return empty;
1011
+ try {
1012
+ return JSON.parse(text);
1013
+ } catch {
1014
+ return appFailure(request, "invalid_input", void 0, { issues: [appIssue({
1015
+ path: "",
1016
+ message: apiIssueText("body_not_json")
1017
+ })] });
1018
+ }
1019
+ }
1020
+ /** 入力の誤りの応答(zod の問題を CMS の API と同じ issues の形に。problems はアプリの英語の問題の文、キーは問題のコード) */
1021
+ function appInvalid(request, error, problems = {}) {
1022
+ const issues = error.issues.map((i) => {
1023
+ const path = i.path.join(".");
1024
+ const p = problemOf(i.message);
1025
+ if (!p) return appIssue({
1026
+ path,
1027
+ code: i.code,
1028
+ message: i.message
1029
+ });
1030
+ return appIssue({
1031
+ path,
1032
+ code: p.code,
1033
+ message: problemEnglish(i.message, problems),
1034
+ ...Object.keys(p.params).length > 0 && { params: p.params }
1035
+ });
823
1036
  });
1037
+ return appFailure(request, "invalid_input", void 0, { issues });
1038
+ }
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 ごとの可否。失敗は例外) */
1047
+ async function appUser(ctx) {
1048
+ const res = await ctx.cms.fetch("/api/me");
1049
+ if (!res.ok) throw new Error(`app_user_unavailable: ${res.status}`);
1050
+ return await res.json();
824
1051
  }
825
- export { AUDIENCES, CUSTOMER_REF, CUSTOMER_STATUSES, IMPORT_ITEMS_MAX, JSON_BODY_MAX, ORIGIN_REF, appFailure, appIssue, appProblems, bodyFromHtml, cyclicCollections, defineAppServer, importIdOf, importItemOfRow, isPublishable };
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 };