@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
@@ -0,0 +1,45 @@
1
+ /** 秘密値の宣言(key は outbound の auth.secret で指す名前) */
2
+ export type AppSecretDeclaration = Readonly<{
3
+ key: string;
4
+ label: string;
5
+ }>;
6
+ /** 入力した秘密値の状態(tail は末尾、値が短ければ null) */
7
+ export type AppSecretState = Readonly<{
8
+ key: string;
9
+ label: string;
10
+ configured: boolean;
11
+ tail: string | null;
12
+ updatedAt: string | null;
13
+ }>;
14
+ /** 秘密値の上限(値の字数、末尾の字数、末尾を返す値の最小の字数) */
15
+ export declare const APP_SECRET_LIMITS: {
16
+ readonly valueMaxChars: 4096;
17
+ readonly tailChars: 4;
18
+ readonly tailMinChars: 8;
19
+ };
20
+ /** 秘密値のキーの形 */
21
+ export declare const APP_SECRET_KEY: RegExp;
22
+ /** 署名の検証のハッシュと、署名の表記 */
23
+ export declare const APP_HMAC_HASHES: readonly ["SHA-256", "SHA-512"];
24
+ export type AppHmacHash = (typeof APP_HMAC_HASHES)[number];
25
+ export declare const APP_SIGNATURE_ENCODINGS: readonly ["base64", "hex"];
26
+ export type AppSignatureEncoding = (typeof APP_SIGNATURE_ENCODINGS)[number];
27
+ /** 署名の検証の指定(body はパースの前の本文、signature は表記 encoding の署名。既定は SHA-256 と base64) */
28
+ export type AppHmacCheck = Readonly<{
29
+ body: string | Uint8Array;
30
+ signature: string;
31
+ hash?: AppHmacHash;
32
+ encoding?: AppSignatureEncoding;
33
+ }>;
34
+ /** 画面と API に出す末尾(値が tailMinChars 未満なら null) */
35
+ export declare const secretTailOf: (value: string) => string | null;
36
+ /** 宣言の上限(件数、見出しの字数) */
37
+ export declare const APP_SECRET_DECLARATION_LIMITS: {
38
+ readonly entriesMax: 20;
39
+ readonly labelMaxChars: 80;
40
+ };
41
+ /**
42
+ * マニフェストの secrets と、outbound の auth が指す秘密値の誤りの箇所(マニフェストの道)
43
+ * - outbound の auth.secret は secrets で宣言したキーか、channelKeys(チャネルの種類の秘密値のキー)でなければならない
44
+ */
45
+ export declare function appSecretsProblems(secrets: unknown, outbound: unknown, channelKeys?: readonly string[]): string[];
@@ -0,0 +1,501 @@
1
+ import type { Collection, CollectionSchema } from '../../schema/src/index.js';
2
+ import type { AppRoute, AppRouteMethod } from './app.js';
3
+ import type { ERROR_STATUS, ErrorParams, IssueInput } from './errors.js';
4
+ import type { AppDefinition, AppSetupContext } from './appDefinition.js';
5
+ import type { ConsentState } from './consents.js';
6
+ import type { EndUserStatus } from './endUsers.js';
7
+ import type { AppChannel, AppChannelsPort } from './appChannels.js';
8
+ import type { AppHmacCheck } from './appSecrets.js';
9
+ import type { AppInboundRequest } from './appInbound.js';
10
+ import type { AppInboundMail, AppMailPort } from './appMail.js';
11
+ import type { MESSAGE_PORT, MESSAGE_RECEIVED, MessageProviderResult, MessageReceived, MessageReceivedInput, MessageSendRequest, MessageSendResult } from './messagePort.js';
12
+ declare const APP_SCOPE: unique symbol;
13
+ /** 呼び出しのプロジェクトの文脈(中身はコアだけが読む) */
14
+ export type AppScope = Readonly<{
15
+ readonly [APP_SCOPE]: true;
16
+ }>;
17
+ /** レコードの行(列の名前と値) */
18
+ export type AppRow = Readonly<Record<string, string | number | null>>;
19
+ /** 規則を掛ける段階 */
20
+ export type RuleStage = 'submit' | 'publish';
21
+ /** 規則に合わない箇所 */
22
+ export type Problem = IssueInput;
23
+ /** 規則(C は点検の材料) */
24
+ export type Rule<C> = Readonly<{
25
+ id: string;
26
+ label: string;
27
+ stages: readonly RuleStage[];
28
+ check: (ctx: C) => Promise<readonly Problem[]> | readonly Problem[];
29
+ }>;
30
+ /** コレクションの規則の材料 */
31
+ export type RecordRuleContext = Readonly<{
32
+ scope: AppScope;
33
+ id: string;
34
+ row: AppRow;
35
+ collection: Collection;
36
+ }>;
37
+ /** コレクションの規則(collection はコレクションの id かマニフェストのコレクションの名前、提出・公開の前にコアの規則の後で点検。名前は作ったか当てたコレクションに掛かる) */
38
+ export type CollectionRule = Rule<RecordRuleContext> & Readonly<{
39
+ collection: string;
40
+ }>;
41
+ /** 定期の処理(run の戻り値は件数、null は設定なしで未実行) */
42
+ export type AppJob = Readonly<{
43
+ label: string;
44
+ run: (scope: AppScope) => Promise<number | null>;
45
+ /** 未実行のときの理由(履歴の画面の表示) */
46
+ skipped?: string;
47
+ /** 閲覧数の集計と同じ間隔で実行するか(その間隔のない環境と、なしは毎日3時) */
48
+ frequent?: boolean;
49
+ }>;
50
+ /** 保存前の検査の引数(values は検査済みの入力にフィールドの宣言と前のアプリの補正を適用した値、id は作成なら null) */
51
+ export type SaveCheckContext = Readonly<{
52
+ scope: AppScope;
53
+ values: Readonly<Record<string, unknown>>;
54
+ id: string | null;
55
+ }>;
56
+ /** 保存前の検査の結果(values は補正した値、problems は拒否の理由) */
57
+ export type SaveCheckResult = Readonly<{
58
+ values: Readonly<Record<string, unknown>>;
59
+ }> | Readonly<{
60
+ problems: readonly Problem[];
61
+ }>;
62
+ /** コレクションの保存前の検査(collection はコレクションの id) */
63
+ export type SaveCheck = Readonly<{
64
+ collection: string;
65
+ check: (ctx: SaveCheckContext) => Promise<SaveCheckResult> | SaveCheckResult;
66
+ }>;
67
+ /** 配信で見えるレコード(collection はコレクションの id) */
68
+ export type VisibleRecords = Readonly<{
69
+ collection: string;
70
+ ids: readonly string[];
71
+ }>;
72
+ /**
73
+ * 配信 API の経路の処理に渡す文脈(defer は応答の後へ回す処理、実行の文脈がない呼び出しではなし)
74
+ * - visible: ids のうち、この要求の見え方(読む版と権限)で配信の API が返すレコード。collection はスラッグか id で、配信するコレクションでなければ null
75
+ */
76
+ export type AppDeliveryContext = Readonly<{
77
+ scope: AppScope;
78
+ params: Readonly<Record<string, string>>;
79
+ defer?: (task: Promise<unknown>) => void;
80
+ visible: (collection: string, ids: readonly string[]) => Promise<VisibleRecords | null>;
81
+ }>;
82
+ /** アプリの公開の API の経路の公開の API の基点からのパス(アプリが外に出す操作は apps/<名前空間> の下) */
83
+ export declare const appDeliveryPathOf: (namespace: string, path: `/${string}`) => `/${string}`;
84
+ /** アプリの単位の受信の経路のために予約した、名前空間の下の区間(アプリの公開の API の経路に使えない) */
85
+ export declare const APP_INBOUND_SEGMENT = "/inbound";
86
+ /** アプリの公開の API の経路が予約の区間の下か */
87
+ export declare const isReservedAppDeliveryPath: (path: string) => boolean;
88
+ /** 公開の API の経路(path はアプリの名前空間 /v1/apps/<名前空間> からの経路、ログインなし。鍵の判定はすべてのコレクションの read) */
89
+ export type AppDeliveryRoute = Readonly<{
90
+ method: AppRouteMethod;
91
+ path: `/${string}`;
92
+ handle: (request: Request, ctx: AppDeliveryContext) => Promise<Response>;
93
+ }>;
94
+ /** 集計の作り直しの広さ(recent は直近の期間、full は元のデータが残る全体) */
95
+ export type AggregateExtent = 'recent' | 'full';
96
+ /**
97
+ * 集計の作り直し(アプリのコレクションの集計を書く処理。書くのは records の rebuild)
98
+ * - コアが定期(recent、間隔はコアの1か所の定数)と、管理者の手動・環境のコピーの後(full)に実行する
99
+ * - 何度流しても同じ結果にする。戻り値は書いた行の数、元のデータの接続がなければ null(未実行)
100
+ */
101
+ export type AggregateRebuild = Readonly<{
102
+ label: string;
103
+ rebuild: (scope: AppScope, extent: AggregateExtent) => Promise<number | null>;
104
+ /** 未実行のときの理由(履歴の画面の表示) */
105
+ skipped?: string;
106
+ }>;
107
+ /** 集計の作り直しの処理の ID(実行の記録と、運営者の経路の名指し) */
108
+ export declare const aggregateJobIdOf: (app: string, collection: string) => string;
109
+ /** サーバーの側の内容 */
110
+ export type AppServerParts = Readonly<{
111
+ /** 管理の API の経路(/api の下) */
112
+ routes?: readonly AppRoute[];
113
+ /** 配信 API の経路 */
114
+ deliveryRoutes?: readonly AppDeliveryRoute[];
115
+ /** 定期の処理(キーは処理の ID、アプリをまたいで一意) */
116
+ jobs?: Readonly<Record<string, AppJob>>;
117
+ /** 集計の作り直し(キーはマニフェストの集計のコレクションの名前) */
118
+ aggregates?: Readonly<Record<string, AggregateRebuild>>;
119
+ /** コレクションの作成・保存の前の検査(登録の順に補正を重ね、拒否は最初のアプリの理由) */
120
+ saveChecks?: readonly SaveCheck[];
121
+ /** コレクションの提出・公開の前の規則(コアの規則の後に点検) */
122
+ rules?: readonly CollectionRule[];
123
+ /** 提供する公開の前の検査(コレクションが publishChecks に id を宣言したときだけ掛かる) */
124
+ publishChecks?: readonly Rule<RecordRuleContext>[];
125
+ /** 編集中の版を受け付けるコレクションの id(公開が承認の人に、公開中のレコードの保存と変更の破棄を許す) */
126
+ draftCollections?: (scope: AppScope) => Promise<readonly string[]>;
127
+ /** 外部の接続の判定(キーは manifest.connections の id、なしは未接続) */
128
+ connections?: Readonly<Record<string, (scope: AppScope) => boolean>>;
129
+ /** 提供するポートの処理(マニフェストの provides で route を持たないポート) */
130
+ provides?: Readonly<{
131
+ [MESSAGE_PORT]?: AppMessageProvider;
132
+ }>;
133
+ /** 外のサービスから受ける経路の処理(キーはマニフェストの inbound の name。主体はインストール済みアプリ自身、例外は送り手の再送) */
134
+ inbound?: Readonly<Record<string, (scope: AppScope, request: AppInboundRequest) => Promise<void>>>;
135
+ /** 受けたメールの処理(マニフェストで mail.inbound を宣言したアプリだけ。mail.channelId は受けたチャネル。主体はインストール済みアプリ自身、例外は送り手の再送) */
136
+ inboundMail?: (scope: AppScope, mail: AppInboundMail) => Promise<void>;
137
+ /** 受けるポートのイベント(マニフェストの uses で宣言したポートのもの) */
138
+ on?: Readonly<{
139
+ [MESSAGE_RECEIVED]?: (scope: AppScope, event: MessageReceived) => Promise<void>;
140
+ }>;
141
+ /** マニフェストのコレクションのレコードの作成、保存、削除、復元の確定の後に知るフック(AppSavedContext。失敗は送り直すので、何度呼ばれても同じ結果にする) */
142
+ afterSave?: (ctx: AppSavedContext) => Promise<void>;
143
+ }>;
144
+ /**
145
+ * 確定の後のフックの引数
146
+ * - collection: マニフェストのコレクションの名前(records が受ける名前)。宣言のコレクション(作ったものと当てたもの)の保存だけが届く
147
+ * - changed: 値の変わったマニフェストのフィールドの key(値は渡さない。今の値は records で読み、消えたレコードは get が null)
148
+ * - 取り込みの実行の中の保存は届かない
149
+ */
150
+ export type AppSavedContext = Readonly<{
151
+ scope: AppScope;
152
+ collection: string;
153
+ id: string;
154
+ changed: readonly string[];
155
+ }>;
156
+ /**
157
+ * メッセージのポートのプロバイダーの処理
158
+ * - send: コアが能力、テスト環境、同意と抑止を確かめた後に呼ぶ。宛先の解決と内容の検査はプロバイダー。一時的な失敗は例外
159
+ * - channel: 送るチャネル(依頼の channelId のチャネルか、プロジェクトの既定のチャネル)。channel_kinds で送信の種類を宣言しないプロバイダーは null
160
+ */
161
+ export type AppMessageProvider = Readonly<{
162
+ send: (scope: AppScope, request: MessageSendRequest, channel: AppChannel | null) => Promise<MessageProviderResult>;
163
+ }>;
164
+ /** アプリ用の状態の置き場の上限(キーの字数、値の JSON の UTF-8 のバイト数、インストールごとのキーの数) */
165
+ export declare const APP_STATE_LIMITS: {
166
+ readonly keyMaxChars: 200;
167
+ readonly valueMaxBytes: 16384;
168
+ readonly keysMax: 200;
169
+ };
170
+ /** レコードの占有の上限(seconds は延長しない占有が効く秒数で、期限のない占有は作れない。画面が延長する間隔の4倍で、隠れたタブのタイマーの間引きに耐える長さ) */
171
+ export declare const APP_HOLD_LIMITS: {
172
+ readonly seconds: 120;
173
+ readonly clientMaxChars: 200;
174
+ };
175
+ /** 占有するレコード(client は持ち主を示す値。レコードの書き込みのヘッダー x-record-hold と同じ値の書き込みは止めない) */
176
+ export type AppHoldTarget = Readonly<{
177
+ collection: string;
178
+ record: string;
179
+ client: string;
180
+ }>;
181
+ /**
182
+ * アプリ用の状態の置き場(インストール済みアプリごとのキーと値。個人情報を入れない、業務のデータは宣言のコレクションに置く)
183
+ * - 値は JSON にできる値。get はないキーで null
184
+ * - 空か長いキーと大きい値は invalid_input(target は key か value)
185
+ * - キーの数の上限は invalid_state(reason は app_state_keys_full)
186
+ * - hold と release はレコードの占有。経路を呼んだ人の操作として、その人が更新できるレコードだけを占有する
187
+ * - hold の held が false ならほかの占有があり、holder はその人の表示名
188
+ */
189
+ export type AppStatePort = Readonly<{
190
+ get: (scope: AppScope, key: string) => Promise<AppPortResult<unknown>>;
191
+ set: (scope: AppScope, key: string, value: unknown) => Promise<AppPortResult<void>>;
192
+ delete: (scope: AppScope, key: string) => Promise<AppPortResult<void>>;
193
+ hold: (scope: AppScope, target: AppHoldTarget) => Promise<AppPortResult<Readonly<{
194
+ held: boolean;
195
+ holder: string | null;
196
+ }>>>;
197
+ release: (scope: AppScope, target: AppHoldTarget) => Promise<AppPortResult<void>>;
198
+ }>;
199
+ /** レコードの絞り込みの上限(値の一覧の件数) */
200
+ export declare const APP_RECORD_QUERY_LIMITS: {
201
+ readonly valuesMax: 100;
202
+ };
203
+ /** アプリのレコード(id とフィールドの key ごとの値) */
204
+ export type AppRecord = Readonly<{
205
+ id: string;
206
+ } & Record<string, unknown>>;
207
+ /**
208
+ * レコードの絞り込み
209
+ * - where: id とフィールドの key ごとの値の一致で、すべての条件を満たすレコード
210
+ * 値の一覧はどれかとの一致(空は0件、APP_RECORD_QUERY_LIMITS の件数まで)で、集計では使えない
211
+ * - range: 集計の時刻のフィールドの範囲(両端を含む)
212
+ */
213
+ export type AppRecordQuery = Readonly<{
214
+ where?: Readonly<Record<string, string | number | boolean | null | readonly string[]>>;
215
+ range?: Readonly<{
216
+ from?: string;
217
+ to?: string;
218
+ }>;
219
+ }>;
220
+ /** 一覧の1ページの指定(limit は件数で既定50・最大100、超える指定は invalid_input。cursor は前のページの next) */
221
+ export type AppPageRequest = Readonly<{
222
+ limit?: number;
223
+ cursor?: string;
224
+ }>;
225
+ /**
226
+ * レコードの1ページ(集計は id の順、ほかは作成の新しい順)
227
+ * - next は続きのカーソルで、終わりは null。1要求で走査する行の数に上限があり、当たると records が limit 件に満たなくても next を返す
228
+ */
229
+ export type AppRecordPage = Readonly<{
230
+ records: readonly AppRecord[];
231
+ next: string | null;
232
+ }>;
233
+ /**
234
+ * 一覧のページを next が尽きるまで読む(ページ送りの画面を持たない利用者の仮の形。1要求ごとの上限は効き、拒否はそのページの拒否)
235
+ */
236
+ export declare function allRecordPages(read: (page: AppPageRequest) => Promise<AppPortResult<AppRecordPage>>): Promise<AppPortResult<AppRecord[]>>;
237
+ /**
238
+ * 書き込みの条件(collection と record は対象の id。版 version と遷移の印 transition_id が、書き込む時点でこの値のときだけ書く)
239
+ * - 印のないレコードの transition_id は null
240
+ * - 対象は主体が読めるレコードだけ。読めない、ない、一致しないは、どれも invalid_state の condition_unmet
241
+ */
242
+ export type AppRecordCondition = Readonly<{
243
+ collection: string;
244
+ record: string;
245
+ version: number;
246
+ transition_id: string | null;
247
+ }>;
248
+ /** 集計の行(フィールドの key ごとの値) */
249
+ export type AggregateValues = Readonly<Record<string, string | number | null>>;
250
+ /** 集計のまとめ(by の次元ごとに、値を宣言の求め方で時刻をまたいでまとめる。where と range は絞り込みと同じ) */
251
+ export type AggregateRollup = AppRecordQuery & Readonly<{
252
+ by: readonly string[];
253
+ }>;
254
+ /** 集計の作り直しの範囲(時刻のフィールドの値、両端を含む) */
255
+ export type AggregateRange = Readonly<{
256
+ from: string;
257
+ to: string;
258
+ }>;
259
+ /**
260
+ * アプリの口の呼ぶ側の誤りのコード(アプリのコードを直すまで回復しない。結果にせず、このコードを code に持つ UsageError を投げる)
261
+ * - 宣言のないコレクション・イベント・秘密値・ポート・メール・チャネルの種類、未登録の発行者、DB だけの文脈、この環境に入っていない
262
+ */
263
+ export declare const APP_USAGE_ERRORS: readonly ["app_collection_undeclared", "app_event_undeclared", "app_secret_undeclared", "app_port_undeclared", "app_scope_without_bindings", "app_not_installed", "end_user_identity_unregistered", "app_channel_undeclared", "app_mail_undeclared"];
264
+ /** アプリの口の拒否のコード(API のエラーのコード) */
265
+ export type AppPortErrorCode = keyof typeof ERROR_STATUS;
266
+ /** アプリの口の拒否(業務の失敗と外から来た値の不一致。params と issues は API のエラーの本文と同じ) */
267
+ export type AppPortFailure = Readonly<{
268
+ ok: false;
269
+ error: AppPortErrorCode;
270
+ params?: ErrorParams;
271
+ issues?: readonly IssueInput[];
272
+ }>;
273
+ /**
274
+ * アプリの口の結果(ok で分ける Result の形に、拒否の params と issues を足したもの)
275
+ * - 呼ぶ側の誤りは APP_USAGE_ERRORS の UsageError、一時的な失敗は例外で、結果にしない
276
+ */
277
+ export type AppPortResult<T> = Readonly<{
278
+ ok: true;
279
+ value: T;
280
+ }> | AppPortFailure;
281
+ /**
282
+ * 業務のデータの読み書きの口(collection はマニフェストのコレクションの名前)
283
+ * - 主体はインストール済みアプリ自身で、変更の履歴と操作の履歴にインストールが残る。権限はマニフェストの宣言のコレクションだけ
284
+ * - 規則・保存前の検査・削除の可否と on_delete は、人の操作と同じ書き込みの入口が当てる
285
+ * - update は送った項目だけを置き換える
286
+ * - when の対象を読む主体は、同梱のアプリの管理の API の経路では呼んだ人、ほかはアプリ自身
287
+ * - 保存前の検査と規則の scope(DB だけの文脈)では使えない(app_scope_without_bindings)
288
+ */
289
+ export type AppRecordsPort = Readonly<{
290
+ list: (scope: AppScope, collection: string, page?: AppPageRequest) => Promise<AppPortResult<AppRecordPage>>;
291
+ get: (scope: AppScope, collection: string, id: string) => Promise<AppPortResult<AppRecord | null>>;
292
+ /** where と range の絞り込みの1ページ(where の条件は走査した行に当て、外れた行も走査の数に入る) */
293
+ query: (scope: AppScope, collection: string, query: AppRecordQuery & AppPageRequest) => Promise<AppPortResult<AppRecordPage>>;
294
+ /**
295
+ * 一意の組(コレクションの宣言 unique か、unique を付けたエンドユーザーへの参照のフィールド)の値で1件
296
+ * - values のキーは組の項目と同じ集合。合う組がなければ invalid_input、読めないかなければ null
297
+ */
298
+ find: (scope: AppScope, collection: string, values: Readonly<Record<string, string | number>>) => Promise<AppPortResult<AppRecord | null>>;
299
+ create: (scope: AppScope, collection: string, values: Readonly<Record<string, unknown>>, when?: AppRecordCondition) => Promise<AppPortResult<Readonly<{
300
+ id: string;
301
+ }>>>;
302
+ update: (scope: AppScope, collection: string, id: string, values: Readonly<Record<string, unknown>>, when?: AppRecordCondition) => Promise<AppPortResult<void>>;
303
+ delete: (scope: AppScope, collection: string, id: string) => Promise<AppPortResult<void>>;
304
+ /** マニフェストのコレクションのこの環境の id(利用者の権限で管理の API を呼ぶとき、権限の表と作成の依頼のキー。宣言のない名前は app_collection_undeclared) */
305
+ collectionId: (scope: AppScope, collection: string) => Promise<string>;
306
+ /** 集計のコレクションの range の行を rows で置き換える(range が null は全体。集計でないコレクションは invalid_state、利用者の書き込みは集計に効かない) */
307
+ rebuild: (scope: AppScope, collection: string, range: AggregateRange | null, rows: readonly AggregateValues[]) => Promise<AppPortResult<number>>;
308
+ /** 集計のコレクションの行を次元でまとめる(by は宣言の次元だけ、集計でないコレクションは invalid_state) */
309
+ rollup: (scope: AppScope, collection: string, rollup: AggregateRollup) => Promise<AppPortResult<readonly AggregateValues[]>>;
310
+ }>;
311
+ /**
312
+ * エンドユーザーの操作の口
313
+ * - 主体はインストール済みアプリ自身で、操作の履歴にインストールが残る
314
+ * - 許可はマニフェストの能力 `@end_users` の `update_status`(setStatus)、`delete`(erase)、`ensure`(ensure)、
315
+ * `read_identities`(findBySubject、subjectOf)、`write_consents`(recordConsent、setChannelBlock)
316
+ * - setStatus は同じ状態なら何もしない。erase は本人の削除の求めと同じ戻せない削除
317
+ * - ensure・findBySubject・subjectOf は、このインストールがマニフェストの identities で登録した issuer と audience の組だけ
318
+ * (ほかは end_user_identity_unregistered)。ensure は紐付けがなければエンドユーザーを作り、セッションは出さない
319
+ * - recordConsent・setChannelBlock は、このインストールに結んだ、マニフェストの channel_kinds の種類のチャネルの ID だけ(ほかは
320
+ * app_channel_undeclared)。同意とブロックはチャネルごと。記録の取り方は opt_in で、チャネルのアプリの記録を本人の証明とする(チャネルが署名などで確かめた
321
+ * 本人の操作を受けて呼ぶ)。本人の証明つきの opt_in の granted はブロックを外す
322
+ */
323
+ export type AppEndUsersPort = Readonly<{
324
+ setStatus: (scope: AppScope, endUserId: string, status: EndUserStatus) => Promise<AppPortResult<void>>;
325
+ erase: (scope: AppScope, endUserId: string) => Promise<AppPortResult<void>>;
326
+ ensure: (scope: AppScope, identity: AppEndUserIdentity) => Promise<AppPortResult<Readonly<{
327
+ endUserId: string;
328
+ created: boolean;
329
+ }>>>;
330
+ findBySubject: (scope: AppScope, identity: AppEndUserIdentity) => Promise<AppPortResult<string | null>>;
331
+ subjectOf: (scope: AppScope, endUserId: string, issuer: AppEndUserIssuer) => Promise<AppPortResult<string | null>>;
332
+ recordConsent: (scope: AppScope, endUserId: string, consent: AppChannelConsent) => Promise<AppPortResult<void>>;
333
+ setChannelBlock: (scope: AppScope, endUserId: string, channelId: string, blocked: boolean) => Promise<AppPortResult<void>>;
334
+ }>;
335
+ /** チャネルでの同意の記録(channelId はチャネルの ID、key は重複を除くキーで、同じキーの再送は記録しない) */
336
+ export type AppChannelConsent = Readonly<{
337
+ channelId: string;
338
+ purpose: string;
339
+ state: ConsentState;
340
+ key?: string;
341
+ }>;
342
+ /** 登録した発行者(ID トークンの iss と aud) */
343
+ export type AppEndUserIssuer = Readonly<{
344
+ issuer: string;
345
+ audience: string;
346
+ }>;
347
+ /** 本人の外部の ID(subject は発行者の sub) */
348
+ export type AppEndUserIdentity = AppEndUserIssuer & Readonly<{
349
+ subject: string;
350
+ }>;
351
+ /** ファイルの読み出しの上限(バイト数) */
352
+ export declare const APP_FILE_LIMITS: {
353
+ readonly readMaxBytes: 10485760;
354
+ };
355
+ /**
356
+ * ファイルの読み出しの口
357
+ * - read: 宣言のコレクション(既存に当てたものを含む)のレコードの、宣言した1つのファイルの項目が指すファイルの実体
358
+ * レコードはインストール済みアプリ自身の読み取りの判定を通す。読めない・ないレコードと空の項目は null
359
+ * - 画像はメタ情報(位置など)をマスクした実体。マスクできない画像は null
360
+ * - 宣言のないコレクションと項目、繰り返しの項目は app_collection_undeclared。上限を超える実体は file_too_large
361
+ */
362
+ export type AppFilesPort = Readonly<{
363
+ read: (scope: AppScope, target: Readonly<{
364
+ collection: string;
365
+ record: string;
366
+ field: string;
367
+ }>) => Promise<AppPortResult<Blob | null>>;
368
+ }>;
369
+ /**
370
+ * アプリのイベントを出す口(外には apps.<名前空間>.<name>、本文は AppEventData)
371
+ * - name はマニフェストの emits の名前だけ(ほかは app_event_undeclared)。対象は主体が読めるレコードだけ
372
+ * - 主体: 管理の API の経路では呼んだ人、ほかではインストール済みアプリ自身
373
+ * - outbox に書き、Webhook へはその後に配る。読めないレコードは not_found
374
+ */
375
+ export type AppEventsPort = Readonly<{
376
+ emit: (scope: AppScope, name: string, target: Readonly<{
377
+ collection: string;
378
+ record: string;
379
+ }>) => Promise<AppPortResult<void>>;
380
+ }>;
381
+ /**
382
+ * アプリの秘密値の口(マニフェストの secrets で宣言したキーだけ。値は返さない)
383
+ * - verifyHmac: 秘密値を鍵にした HMAC の署名の検証(定数時間で比較。未設定は false)
384
+ * - configured: 値が入力済みか
385
+ * - 宣言にないキーは app_secret_undeclared の UsageError
386
+ */
387
+ export type AppSecretsPort = Readonly<{
388
+ verifyHmac: (scope: AppScope, key: string, check: AppHmacCheck) => Promise<AppPortResult<boolean>>;
389
+ configured: (scope: AppScope, key: string) => Promise<AppPortResult<boolean>>;
390
+ }>;
391
+ /** アプリがアカウントへ送れる知らせの種類(レコードの新着、担当の割り当て。件名と本文はコアの定型) */
392
+ export declare const APP_NOTICE_KINDS: readonly ["record_received", "record_assigned"];
393
+ export type AppNoticeKind = (typeof APP_NOTICE_KINDS)[number];
394
+ /** アカウントへの知らせの上限(1回の宛先の数) */
395
+ export declare const APP_NOTIFY_LIMITS: {
396
+ readonly accountsMax: 50;
397
+ };
398
+ /**
399
+ * アカウントへの知らせの依頼
400
+ * - accounts: 宛先のアカウントの ID(APP_NOTIFY_LIMITS の数まで、重なりは1つ)
401
+ * - target: collection はマニフェストのコレクションの名前、record はレコードの id
402
+ * - key: 依頼を見分ける鍵(ログに残す。重複を除くのは呼ぶアプリ)
403
+ */
404
+ export type AppNotifyRequest = Readonly<{
405
+ accounts: readonly string[];
406
+ target: Readonly<{
407
+ collection: string;
408
+ record: string;
409
+ }>;
410
+ kind: AppNoticeKind;
411
+ key: string;
412
+ }>;
413
+ /**
414
+ * 宛先ごとの結果(reason はコード)
415
+ * - skipped: not_member(プロジェクトのメンバーでない)、not_visible(宛先の権限でそのレコードを読めない)、account_missing、not_configured
416
+ * - failed: 送信の失敗(rejected、invalid_input、provider_error)
417
+ */
418
+ export type AppNotifyResult = Readonly<{
419
+ account: string;
420
+ result: 'sent';
421
+ } | {
422
+ account: string;
423
+ result: 'skipped' | 'failed';
424
+ reason: string;
425
+ }>;
426
+ /**
427
+ * アカウントへのメールの口(件名と本文はコアの定型で、レコードの値を含めない)
428
+ * - 宛先ごとに、メンバーか、宛先のアカウントの権限でそのレコードを読めるかを確かめてから送る。例外にせず結果で返す
429
+ * - 宣言のないコレクションは app_collection_undeclared の UsageError、宛先の数の超過は invalid_input
430
+ */
431
+ export type AppNotifyPort = (scope: AppScope, request: AppNotifyRequest) => Promise<AppPortResult<readonly AppNotifyResult[]>>;
432
+ /**
433
+ * メッセージのポートの口(マニフェストの uses と provides の宣言の範囲だけ)
434
+ * - send: 使う側の送信。宣言の能力の外は rejected、テスト環境、同意なし、抑止は skipped で、プロバイダーを呼ばない
435
+ * 送信のモードを決められない実行は unavailable(送り直す)
436
+ * - received: プロバイダーの受信。使う側のアプリの on に渡し、本文を保存しない
437
+ * 形の誤りと結んでいない受信のチャネルは invalid_input、受け手の失敗は例外(チャネルの再送に任せる)
438
+ */
439
+ export type AppMessagesPort = Readonly<{
440
+ send: (scope: AppScope, request: MessageSendRequest) => Promise<AppPortResult<MessageSendResult>>;
441
+ received: (scope: AppScope, input: MessageReceivedInput) => Promise<AppPortResult<void>>;
442
+ }>;
443
+ /** マニフェストのコレクションの解決(collection はコレクションの id、fields はマニフェストのフィールドの key → この環境のフィールドの key) */
444
+ export type AppCollectionTarget = Readonly<{
445
+ collection: string;
446
+ fields: Readonly<Record<string, string>>;
447
+ }>;
448
+ /** スラッグの解決(collection はコレクションの id、ids はスラッグ → レコードの id で、見つからないスラッグは含まない) */
449
+ export type ResolvedSlugs = Readonly<{
450
+ collection: string;
451
+ ids: Readonly<Record<string, string>>;
452
+ }>;
453
+ /** 日ごとの閲覧数(kind と id はサイトが送った値のまま) */
454
+ export type DailyViews = Readonly<{
455
+ date: string;
456
+ kind: string;
457
+ id: string;
458
+ views: number;
459
+ }>;
460
+ /** 外部の接続の読み込み元(キーは manifest.connections の id) */
461
+ export type AppConnections = Readonly<{
462
+ /** サイトが記録した閲覧の日ごとの数(since 以降の日付) */
463
+ 'analytics-engine': Readonly<{
464
+ daily: (since: string) => Promise<readonly DailyViews[]>;
465
+ }>;
466
+ }>;
467
+ /**
468
+ * サーバーの側の組み立ての引数(settingsOf は画面で保存した値を含む設定値、schema は組み立ての時点のコンテンツスキーマ)
469
+ * - collections: マニフェストのコレクションの名前の解決。当てていない、コレクションかフィールドが今のスキーマにない、この環境に入っていなければ null
470
+ * - resolveSlugs: 配信するコレクションのスラッグか id(旧いスラッグも)と、レコードのスラッグ(旧いスラッグも)を id に
471
+ * 配信の API が出す値だけを返し、配信しないコレクションは null
472
+ * - connection: 外部の接続の読み込み元(この環境で接続していなければ null)
473
+ */
474
+ export type AppServerContext<S> = AppSetupContext<S> & Readonly<{
475
+ settingsOf: (scope: AppScope) => Promise<S>;
476
+ schema: CollectionSchema;
477
+ state: AppStatePort;
478
+ secrets: AppSecretsPort;
479
+ messages: AppMessagesPort;
480
+ /** メールの送信とドメイン(AppMailPort) */
481
+ mail: AppMailPort;
482
+ /** アプリのチャネル(AppChannelsPort) */
483
+ channels: AppChannelsPort;
484
+ records: AppRecordsPort;
485
+ files: AppFilesPort;
486
+ endUsers: AppEndUsersPort;
487
+ events: AppEventsPort;
488
+ collections: (scope: AppScope, name: string) => Promise<AppCollectionTarget | null>;
489
+ resolveSlugs: (scope: AppScope, collection: string, slugs: readonly string[]) => Promise<ResolvedSlugs | null>;
490
+ connection: <K extends keyof AppConnections>(scope: AppScope, id: K) => AppConnections[K] | null;
491
+ /** アカウントへのメール(AppNotifyPort) */
492
+ notify: AppNotifyPort;
493
+ /** マニフェストの outbound の宣言に当たる要求だけの外への要求(イベントと定期の処理から。経路の処理は AppContext の egress) */
494
+ egress: (scope: AppScope, input: string | URL, init?: RequestInit) => Promise<Response>;
495
+ }>;
496
+ /** アプリのサーバーの側(S はアプリの設定値、create は組み立ての時点で1回) */
497
+ export type AppServer<S = unknown> = Readonly<{
498
+ app: AppDefinition<S>;
499
+ create(ctx: AppServerContext<S>): AppServerParts;
500
+ }>;
501
+ export {};
@@ -0,0 +1,26 @@
1
+ /** 申請の種類の表示名 */
2
+ export declare const APPROVAL_KIND_LABELS: {
3
+ readonly schema: "スキーマの変更を本番に反映";
4
+ readonly promote: "本番の切り替え";
5
+ readonly freeze: "本番の書き込みの停止";
6
+ readonly delete_environment: "環境の削除";
7
+ readonly reimport: "本番への取り込み直し(画面で直したレコードの上書き)";
8
+ };
9
+ /** 申請の状態の表示名 */
10
+ export declare const APPROVAL_STATE_LABELS: {
11
+ readonly pending: "承認待ち";
12
+ readonly approved: "実行中";
13
+ readonly applied: "反映済み";
14
+ readonly failed: "失敗";
15
+ readonly rejected: "却下";
16
+ readonly cancelled: "取り下げ";
17
+ readonly expired: "期限切れ";
18
+ readonly revoked: "取り消し";
19
+ };
20
+ /** 一括の取り消しの対象の表示名 */
21
+ export declare const REVOKE_TARGET_LABELS: {
22
+ readonly sessions: "ワークスペースのログイン";
23
+ readonly mcp: "AI の接続";
24
+ readonly approvals: "承認待ちの申請";
25
+ readonly api_keys: "API キー";
26
+ };
@@ -0,0 +1,63 @@
1
+ /**
2
+ * 申請の種類(schema は重い差を含むスキーマの変更、promote は live の切り替え、freeze は live の書き込みの停止、delete_environment は環境の削除)
3
+ * - reimport は移した後の live への取り込み直しで、取り込みの後に画面で直したレコードとエンドユーザーを取り出し元の値で上書きする(tunasand#713)
4
+ * 承認は REIMPORT_WINDOW_MS の間、その取り出し元の上書きの取り込みを通す(足すだけの取り込み直しは軽い操作で申請なし)
5
+ */
6
+ export declare const APPROVAL_KINDS: readonly ["schema", "promote", "freeze", "delete_environment", "reimport"];
7
+ /** 申請の種類 */
8
+ export type ApprovalKind = (typeof APPROVAL_KINDS)[number];
9
+ /** 操作の重さ */
10
+ export type OperationWeight = 'light' | 'heavy' | 'human_only';
11
+ /** 本番に届く操作の重さ(スキーマは差の性質で light と heavy に分ける。heavy の差を含むときだけ申請) */
12
+ export declare const PRODUCTION_OPERATIONS: {
13
+ readonly schema: "heavy";
14
+ readonly promote: "heavy";
15
+ readonly freeze: "heavy";
16
+ readonly delete_environment: "heavy";
17
+ readonly reimport: "human_only";
18
+ };
19
+ /** 承認した取り込み直しの上書きを通す時間(1時間、承認の時刻から) */
20
+ export declare const REIMPORT_WINDOW_MS: number;
21
+ /** 申請の経路(cms はワークスペース、mcp は AI の接続) */
22
+ export declare const APPROVAL_VIAS: readonly ["cms", "mcp"];
23
+ /** 申請の経路 */
24
+ export type ApprovalVia = (typeof APPROVAL_VIAS)[number];
25
+ /** 経路から申請できる種類か(human_only はワークスペースだけ) */
26
+ export declare const requestableVia: (kind: ApprovalKind, via: ApprovalVia) => boolean;
27
+ /**
28
+ * 申請の状態
29
+ * - pending → approved(承認して実行中)→ applied(実行した)か failed(実行できなかった、error にコード)
30
+ * approved のまま APPROVAL_STUCK_MS を過ぎたら、実行の途中で止まった(Worker の停止など)として運営者に知らせる
31
+ * - pending から rejected(承認者が断った)、cancelled(申請した人がやめた)、expired(期限切れ)、revoked(一括の取り消し)
32
+ */
33
+ export declare const APPROVAL_STATES: readonly ["pending", "approved", "applied", "failed", "rejected", "cancelled", "expired", "revoked"];
34
+ /** 申請の状態 */
35
+ export type ApprovalState = (typeof APPROVAL_STATES)[number];
36
+ /** 申請の期限(7日) */
37
+ export declare const APPROVAL_TTL_MS: number;
38
+ /** 承認して実行中のまま、途中で止まったとみなすまでの時間(15分、承認の実行の Worker の上限より長い) */
39
+ export declare const APPROVAL_STUCK_MS: number;
40
+ /** 承認の前のログインし直しからの秒数(2分。1回のログインし直しで承認できるのは1件だけ) */
41
+ export declare const APPROVAL_REAUTH_MAX_AGE_SEC = 120;
42
+ /** 申請の表示(API と画面で共通。requestedBy と decidedBy は主体の ID で、表示名は呼び元が引く。environment は対象の環境の ID) */
43
+ export type ApprovalView = Readonly<{
44
+ id: string;
45
+ kind: ApprovalKind;
46
+ environment: string;
47
+ state: ApprovalState;
48
+ via: ApprovalVia;
49
+ requestedBy: string;
50
+ decidedBy: string | null;
51
+ error: string | null;
52
+ createdAt: string;
53
+ decidedAt: string | null;
54
+ expiresAt: string;
55
+ summary: unknown;
56
+ }>;
57
+ /**
58
+ * 一括の取り消しの対象(console のプロジェクトの資格の取り消し、決定は tunasand#598)
59
+ * - sessions はワークスペースのセッション、mcp は AI の接続、approvals は承認待ちの申請、api_keys は API の鍵(止めるとサイトが止まるので既定で外す)
60
+ */
61
+ export declare const REVOKE_TARGETS: readonly ["sessions", "mcp", "approvals", "api_keys"];
62
+ /** 一括の取り消しの対象 */
63
+ export type RevokeTarget = (typeof REVOKE_TARGETS)[number];