@tunasand/sdk 0.8.0 → 0.12.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 (221) hide show
  1. package/CHANGELOG.md +137 -0
  2. package/README.md +165 -144
  3. package/dist/analytics.js +183 -109
  4. package/dist/app.js +276 -166
  5. package/dist/apps-BysPfMuR.js +408 -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-C2Bl-OAF.js +80 -0
  14. package/dist/bridge.js +1 -13
  15. package/dist/build-file-DNi0PHC5.js +31 -0
  16. package/dist/cli.js +6212 -8
  17. package/dist/{client-Derrexwr.js → client-C8STAw9T.js} +43 -24
  18. package/dist/code-N8pBUDbq.js +30 -0
  19. package/dist/code.d.ts +1 -0
  20. package/dist/code.js +1 -0
  21. package/dist/collection-26aglrg6.js +282 -0
  22. package/dist/{declared-DuNMsdXw.js → declared-CE4a61qb.js} +35 -35
  23. package/dist/delivery.js +121 -114
  24. package/dist/dev-operations-Tutwi1On.js +46 -0
  25. package/dist/dev.js +9 -16
  26. package/dist/embeds-DY6O5TrJ.js +29 -0
  27. package/dist/end-users.d.ts +1 -0
  28. package/dist/end-users.js +189 -0
  29. package/dist/endUsers-DODfjnv1.js +77 -0
  30. package/dist/{errorLabels-BgtQ_zUn.js → errorLabels-BK1NJ6Wz.js} +374 -238
  31. package/dist/i18n.js +4 -4
  32. package/dist/ids-DmtIoqBX.js +109 -0
  33. package/dist/integrations.js +95 -24
  34. package/dist/{ja-Du6ooL6i.js → ja-B3lAaOhZ.js} +91 -45
  35. package/dist/{ja-CeHU0EaY.js → ja-axQPxMJ-.js} +3 -3
  36. package/dist/operations-CIB99rIY.js +95 -0
  37. package/dist/operations.d.ts +1 -0
  38. package/dist/operations.js +1 -0
  39. package/dist/{page-Bzrj24sJ.js → page-yo1cw1kW.js} +1 -1
  40. package/dist/paymentPort-p1jV44Zz.js +203 -0
  41. package/dist/preview.js +8 -1
  42. package/dist/{profile-1em_lcxq.js → profile-DBsXLvvI.js} +48 -48
  43. package/dist/rich-text.js +16 -16
  44. package/dist/{schema-WnobuwLg.js → schema-Bs_BUUNv.js} +526 -265
  45. package/dist/schema.js +66 -88
  46. package/dist/types/access/src/handoff.d.ts +19 -14
  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/oidc.d.ts +12 -2
  50. package/dist/types/access/src/signed.d.ts +0 -2
  51. package/dist/types/adapter-cloudflare/src/eventLog/viewSchema.d.ts +11 -0
  52. package/dist/types/contract/src/accountProfile.d.ts +7 -0
  53. package/dist/types/contract/src/api/define.d.ts +165 -0
  54. package/dist/types/contract/src/apiKeys.d.ts +6 -2
  55. package/dist/types/contract/src/app.d.ts +32 -7
  56. package/dist/types/contract/src/appChannels.d.ts +152 -0
  57. package/dist/types/contract/src/appDefinition.d.ts +11 -5
  58. package/dist/types/contract/src/appDependencies.d.ts +107 -24
  59. package/dist/types/contract/src/appIdentities.d.ts +21 -0
  60. package/dist/types/contract/src/appInbound.d.ts +53 -0
  61. package/dist/types/contract/src/appMail.d.ts +106 -0
  62. package/dist/types/contract/src/appSecrets.d.ts +63 -0
  63. package/dist/types/contract/src/appServer.d.ts +460 -45
  64. package/dist/types/contract/src/approvals.d.ts +1 -1
  65. package/dist/types/contract/src/apps.d.ts +126 -60
  66. package/dist/types/contract/src/auditActions.d.ts +2 -2
  67. package/dist/types/contract/src/auditLabels.d.ts +120 -15
  68. package/dist/types/contract/src/authorize.d.ts +42 -14
  69. package/dist/types/contract/src/bridge.d.ts +35 -36
  70. package/dist/types/contract/src/consents.d.ts +29 -27
  71. package/dist/types/contract/src/deletion.d.ts +18 -0
  72. package/dist/types/contract/src/embeds.d.ts +26 -90
  73. package/dist/types/contract/src/{customerLabels.d.ts → endUserLabels.d.ts} +6 -9
  74. package/dist/types/contract/src/endUsers.d.ts +244 -0
  75. package/dist/types/contract/src/errorLabels.d.ts +67 -37
  76. package/dist/types/contract/src/errorLabelsEn.d.ts +50 -33
  77. package/dist/types/contract/src/errors.d.ts +28 -16
  78. package/dist/types/contract/src/eventSchemas.d.ts +70 -0
  79. package/dist/types/contract/src/eventTraces.d.ts +41 -0
  80. package/dist/types/contract/src/failureStatus.d.ts +14 -22
  81. package/dist/types/contract/src/fieldAccess.d.ts +8 -8
  82. package/dist/types/contract/src/formLabels.d.ts +3 -0
  83. package/dist/types/contract/src/forms.d.ts +4 -0
  84. package/dist/types/contract/src/grants.d.ts +26 -0
  85. package/dist/types/contract/src/headers.d.ts +5 -0
  86. package/dist/types/contract/src/hostingRpc.d.ts +44 -19
  87. package/dist/types/contract/src/identifiers.d.ts +45 -17
  88. package/dist/types/contract/src/ids.d.ts +18 -10
  89. package/dist/types/contract/src/import.d.ts +17 -16
  90. package/dist/types/contract/src/index.d.ts +57 -29
  91. package/dist/types/contract/src/integrationGraph.d.ts +83 -0
  92. package/dist/types/contract/src/issueLabels.d.ts +121 -81
  93. package/dist/types/contract/src/issueLabelsEn.d.ts +61 -41
  94. package/dist/types/contract/src/manage.d.ts +16 -7
  95. package/dist/types/contract/src/manageLabels.d.ts +2 -0
  96. package/dist/types/contract/src/manifestText.d.ts +66 -0
  97. package/dist/types/contract/src/messagePort.d.ts +208 -0
  98. package/dist/types/contract/src/migration.d.ts +2 -2
  99. package/dist/types/contract/src/notices.d.ts +37 -0
  100. package/dist/types/contract/src/operationEffects.d.ts +39 -0
  101. package/dist/types/contract/src/operatorOperations.d.ts +104 -110
  102. package/dist/types/contract/src/outbound.d.ts +29 -0
  103. package/dist/types/contract/src/paths.d.ts +13 -0
  104. package/dist/types/contract/src/paymentPort.d.ts +129 -0
  105. package/dist/types/contract/src/pending.d.ts +2 -0
  106. package/dist/types/contract/src/permissions.d.ts +7 -11
  107. package/dist/types/contract/src/perspective.d.ts +26 -0
  108. package/dist/types/contract/src/powers.d.ts +5 -0
  109. package/dist/types/contract/src/principal.d.ts +127 -56
  110. package/dist/types/contract/src/readPages.d.ts +92 -0
  111. package/dist/types/contract/src/recordLabels.d.ts +6 -0
  112. package/dist/types/contract/src/roles.d.ts +7 -4
  113. package/dist/types/contract/src/ruleLabels.d.ts +16 -0
  114. package/dist/types/contract/src/ruleProblems.d.ts +16 -0
  115. package/dist/types/contract/src/schemaLabels.d.ts +8 -0
  116. package/dist/types/contract/src/settingProblems.d.ts +18 -1
  117. package/dist/types/contract/src/settings.d.ts +5 -7
  118. package/dist/types/contract/src/siteDeclaration.d.ts +7 -7
  119. package/dist/types/contract/src/siteIndex.d.ts +76 -0
  120. package/dist/types/contract/src/transfer.d.ts +1 -1
  121. package/dist/types/contract/src/trial.d.ts +4 -1
  122. package/dist/types/contract/src/versions.d.ts +1 -3
  123. package/dist/types/contract/src/viewEvent.d.ts +0 -9
  124. package/dist/types/contract/src/webhooks.d.ts +24 -3
  125. package/dist/types/contract/src/workflow.d.ts +16 -19
  126. package/dist/types/contract/src/workspaceItems.d.ts +23 -7
  127. package/dist/types/contract/src/workspacePaths.d.ts +1 -1
  128. package/dist/types/rich-text/src/html.d.ts +1 -1
  129. package/dist/types/rich-text/src/index.d.ts +8 -7
  130. package/dist/types/rich-text/src/labels/en.d.ts +1 -1
  131. package/dist/types/rich-text/src/labels/ja.d.ts +2 -2
  132. package/dist/types/rich-text/src/library.d.ts +1 -1
  133. package/dist/types/rich-text/src/media.d.ts +2 -0
  134. package/dist/types/rich-text/src/normalize.d.ts +1 -1
  135. package/dist/types/rich-text/src/problems.d.ts +5 -5
  136. package/dist/types/rich-text/src/profile.d.ts +10 -10
  137. package/dist/types/rich-text/src/render.d.ts +1 -1
  138. package/dist/types/rich-text/src/schema.d.ts +2 -2
  139. package/dist/types/rich-text/src/standard.d.ts +4 -4
  140. package/dist/types/rich-text/src/types.d.ts +2 -2
  141. package/dist/types/schema/src/audience.d.ts +1 -3
  142. package/dist/types/schema/src/capabilities.d.ts +18 -27
  143. package/dist/types/schema/src/changes.d.ts +3 -1
  144. package/dist/types/schema/src/collection.d.ts +142 -111
  145. package/dist/types/schema/src/defaultSchema.d.ts +8 -2
  146. package/dist/types/schema/src/fieldIds.d.ts +18 -0
  147. package/dist/types/schema/src/file.d.ts +24 -11
  148. package/dist/types/schema/src/fileRefs.d.ts +14 -0
  149. package/dist/types/schema/src/fileSignature.d.ts +20 -0
  150. package/dist/types/schema/src/filesCollection.d.ts +7 -0
  151. package/dist/types/schema/src/forms.d.ts +43 -0
  152. package/dist/types/schema/src/imageMetadata.d.ts +9 -0
  153. package/dist/types/schema/src/index.d.ts +19 -10
  154. package/dist/types/schema/src/indexes.d.ts +11 -0
  155. package/dist/types/schema/src/input.d.ts +1 -1
  156. package/dist/types/schema/src/integrity.d.ts +8 -7
  157. package/dist/types/schema/src/kinds.d.ts +26 -0
  158. package/dist/types/schema/src/labels/en.d.ts +89 -46
  159. package/dist/types/schema/src/labels/ja.d.ts +92 -46
  160. package/dist/types/schema/src/mediaUrl.d.ts +26 -33
  161. package/dist/types/schema/src/page.d.ts +4 -4
  162. package/dist/types/schema/src/problems.d.ts +85 -42
  163. package/dist/types/schema/src/refs.d.ts +0 -9
  164. package/dist/types/schema/src/schema.d.ts +17 -12
  165. package/dist/types/schema/src/selfOps.d.ts +20 -19
  166. package/dist/types/schema/src/traits.d.ts +28 -0
  167. package/dist/types/schema/src/typesSource.d.ts +1 -1
  168. package/dist/types/schema/src/values.d.ts +5 -2
  169. package/dist/types/schema/src/widening.d.ts +3 -0
  170. package/dist/types/sdk/src/analytics.d.ts +2 -1
  171. package/dist/types/sdk/src/app.d.ts +43 -14
  172. package/dist/types/sdk/src/astro-image.d.ts +19 -0
  173. package/dist/types/sdk/src/astro-response.d.ts +6 -0
  174. package/dist/types/sdk/src/astro-server.d.ts +16 -0
  175. package/dist/types/sdk/src/astro.d.ts +19 -0
  176. package/dist/types/sdk/src/bridge.d.ts +2 -4
  177. package/dist/types/sdk/src/code.d.ts +61 -0
  178. package/dist/types/sdk/src/delegation.d.ts +13 -3
  179. package/dist/types/sdk/src/delivery/changes.d.ts +4 -4
  180. package/dist/types/sdk/src/delivery/client.d.ts +33 -22
  181. package/dist/types/sdk/src/delivery/fields.d.ts +3 -3
  182. package/dist/types/sdk/src/delivery/index.d.ts +3 -3
  183. package/dist/types/sdk/src/delivery/media.d.ts +5 -8
  184. package/dist/types/sdk/src/delivery/query.d.ts +15 -11
  185. package/dist/types/sdk/src/delivery/schema.d.ts +1 -1
  186. package/dist/types/sdk/src/delivery/values.d.ts +10 -14
  187. package/dist/types/sdk/src/delivery.d.ts +2 -2
  188. package/dist/types/sdk/src/dev-operations.d.ts +20 -0
  189. package/dist/types/sdk/src/dev.d.ts +6 -5
  190. package/dist/types/sdk/src/end-users.d.ts +187 -0
  191. package/dist/types/sdk/src/i18n.d.ts +2 -2
  192. package/dist/types/sdk/src/integrations.d.ts +14 -21
  193. package/dist/types/sdk/src/operations.d.ts +17 -0
  194. package/dist/types/sdk/src/preview.d.ts +2 -1
  195. package/dist/types/sdk/src/rich-text.d.ts +2 -2
  196. package/dist/types/sdk/src/schema.d.ts +1 -1
  197. package/dist/types/sdk/src/site/artifact.d.ts +64 -0
  198. package/dist/types/sdk/src/site/build-file.d.ts +30 -0
  199. package/dist/types/sdk/src/site/check-code.d.ts +14 -0
  200. package/dist/types/sdk/src/site/check-text.d.ts +19 -0
  201. package/dist/types/sdk/src/site/cli.d.ts +52 -0
  202. package/dist/types/sdk/src/site/content-type.d.ts +2 -0
  203. package/dist/types/sdk/src/site/labels.d.ts +14 -0
  204. package/dist/types/sdk/src/types.d.ts +1 -1
  205. package/dist/{types-B77qvqPJ.js → types-CYnY-63C.js} +5 -6
  206. package/dist/types.js +1 -1
  207. package/dist/{typesSource-CWybQYus.js → typesSource-BTA9-rcB.js} +17 -15
  208. package/package.json +32 -6
  209. package/dist/apps-BxnJ1RlU.js +0 -435
  210. package/dist/bridge-DtHw9hS6.js +0 -74
  211. package/dist/collection-BEOxeISR.js +0 -189
  212. package/dist/customers-DTbL0qn6.js +0 -86
  213. package/dist/customers.d.ts +0 -1
  214. package/dist/customers.js +0 -185
  215. package/dist/embeds-B5V54Zur.js +0 -34
  216. package/dist/ids--RF7hGyC.js +0 -36
  217. package/dist/src-sazhzYui.js +0 -71
  218. package/dist/types/contract/src/customers.d.ts +0 -266
  219. package/dist/types/schema/src/legacy.d.ts +0 -2
  220. package/dist/types/schema/src/media.d.ts +0 -5
  221. package/dist/types/sdk/src/customers.d.ts +0 -184
@@ -1,9 +1,17 @@
1
1
  import type { Collection, CollectionSchema } from '../../schema/src/index.js';
2
- import type { z } from 'zod';
3
- import type { AppRoute, AppRouteMethod } from './app.js';
4
- import type { IssueInput } from './errors.js';
2
+ import type { ApiRoute, ListSpec } from './api/define.js';
3
+ import type { AppContext, AppRoute, AppRouteMethod } from './app.js';
4
+ import type { AppNotice, NOTICES_PORT } from './notices.js';
5
+ import type { ERROR_STATUS, ErrorParams, IssueInput } from './errors.js';
5
6
  import type { AppDefinition, AppSetupContext } from './appDefinition.js';
6
- import type { User } from './roles.js';
7
+ import type { ConsentState } from './consents.js';
8
+ import type { EndUserStatus } from './endUsers.js';
9
+ import type { AppChannel, AppChannelsPort } from './appChannels.js';
10
+ import type { AppHmacCheck, AppOperatorSecrets } from './appSecrets.js';
11
+ import type { AppDispatched, AppDispatchRequest, AppInboundOutcome, AppInboundRequest } from './appInbound.js';
12
+ import type { AppInboundMail, AppMailPort } from './appMail.js';
13
+ import type { PAYMENT_PORT, PaymentCheckout, PaymentCheckoutRequest, PaymentPortalRequest, PurchaseReflection, ReflectionResult, SubscriptionReflection } from './paymentPort.js';
14
+ import type { MESSAGE_PORT, MESSAGE_RECEIVED, MessageProviderResult, MessageReceived, MessageReceivedInput, MessageSendRequest, MessageSendResult } from './messagePort.js';
7
15
  declare const APP_SCOPE: unique symbol;
8
16
  /** 呼び出しのプロジェクトの文脈(中身はコアだけが読む) */
9
17
  export type AppScope = Readonly<{
@@ -29,7 +37,7 @@ export type RecordRuleContext = Readonly<{
29
37
  row: AppRow;
30
38
  collection: Collection;
31
39
  }>;
32
- /** コレクションの規則(collection はコレクションの id、提出・公開の前にコアの規則の後で点検) */
40
+ /** コレクションの規則(collection はコレクションの id かマニフェストのコレクションの名前、提出・公開の前にコアの規則の後で点検。名前は作ったか当てたコレクションに掛かる) */
33
41
  export type CollectionRule = Rule<RecordRuleContext> & Readonly<{
34
42
  collection: string;
35
43
  }>;
@@ -39,34 +47,16 @@ export type AppJob = Readonly<{
39
47
  run: (scope: AppScope) => Promise<number | null>;
40
48
  /** 未実行のときの理由(履歴の画面の表示) */
41
49
  skipped?: string;
42
- /** 独自の間隔(Cron の式と表示名、null・なしは毎日3時の Cron で実行) */
43
- every?: (scope: AppScope) => Readonly<{
44
- cron: string;
45
- label: string;
46
- }> | null;
47
- }>;
48
- /** 操作の履歴の規則(path は /api/ の後、一致した1つ目の括弧が対象の ID、target は対象の id) */
49
- export type AuditRule = readonly [method: string, path: RegExp, action: string, target: string, targetLabel?: string];
50
- /**
51
- * マスタ(コレクションの項目から参照しない一覧。API・作成の依頼・操作の履歴はコア)
52
- * - kind: 権限の表のキーで作成の依頼の対象、操作の履歴の対象
53
- * - fields: 名前以外の項目の検査(作成の依頼の値 fields に同じキーで保存)
54
- * - unique: 名前の重複を比較する範囲の項目(なしは表の全体)
55
- */
56
- export type AppMaster = Readonly<{
57
- kind: string;
58
- path: string;
59
- table: string;
60
- label: string;
61
- fields: Readonly<Partial<Record<'medium' | 'prompt', z.ZodType<string>>>>;
62
- unique?: 'medium';
50
+ /** 閲覧数の集計と同じ間隔で実行するか(その間隔のない環境と、なしは毎日3時) */
51
+ frequent?: boolean;
63
52
  }>;
64
53
  /** 保存前の検査の引数(values は検査済みの入力にフィールドの宣言と前のアプリの補正を適用した値、id は作成なら null) */
54
+ /** 保存前の検査の引数(live は保存するコレクションのゴミ箱の外のレコードの数で、件数の記録から読む) */
65
55
  export type SaveCheckContext = Readonly<{
66
56
  scope: AppScope;
67
- user: User;
68
57
  values: Readonly<Record<string, unknown>>;
69
58
  id: string | null;
59
+ live: () => Promise<number>;
70
60
  }>;
71
61
  /** 保存前の検査の結果(values は補正した値、problems は拒否の理由) */
72
62
  export type SaveCheckResult = Readonly<{
@@ -74,63 +64,488 @@ export type SaveCheckResult = Readonly<{
74
64
  }> | Readonly<{
75
65
  problems: readonly Problem[];
76
66
  }>;
77
- /** コレクションの保存前の検査(collection はコレクションの id) */
67
+ /** コレクションの保存前の検査(collection はマニフェストのコレクションの名前) */
78
68
  export type SaveCheck = Readonly<{
79
69
  collection: string;
80
70
  check: (ctx: SaveCheckContext) => Promise<SaveCheckResult> | SaveCheckResult;
81
71
  }>;
82
- /** 配信 API の経路の処理に渡す文脈(defer は応答の後へ回す処理、実行の文脈がない呼び出しではなし) */
72
+ /** 配信で見えるレコード(collection はコレクションの id) */
73
+ export type VisibleRecords = Readonly<{
74
+ collection: string;
75
+ ids: readonly string[];
76
+ }>;
77
+ /**
78
+ * 配信 API の経路の処理に渡す文脈(defer は応答の後へ回す処理、実行の文脈がない呼び出しではなし)
79
+ * - visible: ids のうち、この要求の見え方(読む版と権限)で配信の API が返すレコード。collection はスラッグか id で、配信するコレクションでなければ null
80
+ */
83
81
  export type AppDeliveryContext = Readonly<{
84
82
  scope: AppScope;
85
83
  params: Readonly<Record<string, string>>;
86
84
  defer?: (task: Promise<unknown>) => void;
85
+ visible: (collection: string, ids: readonly string[]) => Promise<VisibleRecords | null>;
87
86
  }>;
88
- /** 配信 API の経路(path は /content/v1 からの経路、ログインなし。鍵の判定はすべてのコレクションの read) */
87
+ /** アプリの公開の API の経路の公開の API の基点からのパス(アプリが外に出す操作は apps/<名前空間> の下) */
88
+ export declare const appDeliveryPathOf: (namespace: string, path: `/${string}`) => `/${string}`;
89
+ /** アプリの単位の受信の経路のために予約した、名前空間の下の区間(アプリの公開の API の経路に使えない) */
90
+ export declare const APP_INBOUND_SEGMENT = "/inbound";
91
+ /** アプリの公開の API の経路が予約の区間の下か */
92
+ export declare const isReservedAppDeliveryPath: (path: string) => boolean;
93
+ /**
94
+ * 公開の API の経路(path はアプリの名前空間 /v1/apps/<名前空間> からの経路、ログインなし。鍵の判定はすべてのコレクションの read)
95
+ * - summary・response・list はマスタの経路の宣言と同じ意味
96
+ */
89
97
  export type AppDeliveryRoute = Readonly<{
90
98
  method: AppRouteMethod;
91
99
  path: `/${string}`;
100
+ summary: string;
101
+ response: ApiRoute['response'];
102
+ list?: ListSpec;
92
103
  handle: (request: Request, ctx: AppDeliveryContext) => Promise<Response>;
93
104
  }>;
94
- /** 画像の ID を含みうる表と列 */
95
- export type FileColumns = Readonly<{
96
- table: string;
97
- columns: readonly string[];
105
+ /** 集計の作り直しの広さ(recent は直近の期間、full は元のデータが残る全体) */
106
+ export type AggregateExtent = 'recent' | 'full';
107
+ /**
108
+ * 集計の作り直し(アプリのコレクションの集計を書く処理。書くのは records の rebuild)
109
+ * - コアが定期(recent、間隔はコアの1か所の定数)と、管理者の手動・環境のコピーの後(full)に実行する
110
+ * - 何度流しても同じ結果にする。戻り値は書いた行の数、元のデータの接続がなければ null(未実行)
111
+ */
112
+ export type AggregateRebuild = Readonly<{
113
+ label: string;
114
+ rebuild: (scope: AppScope, extent: AggregateExtent) => Promise<number | null>;
115
+ /** 未実行のときの理由(履歴の画面の表示) */
116
+ skipped?: string;
98
117
  }>;
118
+ /** 集計の作り直しの処理の ID(実行の記録と、運営者の経路の名指し) */
119
+ export declare const aggregateJobIdOf: (app: string, collection: string) => string;
99
120
  /** サーバーの側の内容 */
100
121
  export type AppServerParts = Readonly<{
101
122
  /** 管理の API の経路(/api の下) */
102
123
  routes?: readonly AppRoute[];
103
124
  /** 配信 API の経路 */
104
125
  deliveryRoutes?: readonly AppDeliveryRoute[];
105
- /** 外への読み込みの宛先(https のオリジン、ホスト名の先頭の `*.` は1つ以上の区間) */
106
- egress?: readonly string[];
107
126
  /** 定期の処理(キーは処理の ID、アプリをまたいで一意) */
108
127
  jobs?: Readonly<Record<string, AppJob>>;
128
+ /** 集計の作り直し(キーはマニフェストの集計のコレクションの名前) */
129
+ aggregates?: Readonly<Record<string, AggregateRebuild>>;
109
130
  /** コレクションの作成・保存の前の検査(登録の順に補正を重ね、拒否は最初のアプリの理由) */
110
131
  saveChecks?: readonly SaveCheck[];
111
132
  /** コレクションの提出・公開の前の規則(コアの規則の後に点検) */
112
133
  rules?: readonly CollectionRule[];
113
134
  /** 提供する公開の前の検査(コレクションが publishChecks に id を宣言したときだけ掛かる) */
114
135
  publishChecks?: readonly Rule<RecordRuleContext>[];
115
- /** 操作の履歴に記録する規則(変更の API) */
116
- audit?: readonly AuditRule[];
117
- /** マスタ */
118
- masters?: readonly AppMaster[];
119
- /** 履歴に表示する対象の名前の列(キーは対象の id、値は表と列) */
120
- titles?: Readonly<Record<string, readonly [table: string, column: string]>>;
121
- /** 画像の使用中の判定に加える列 */
122
- files?: readonly FileColumns[];
136
+ /** 編集中の版を受け付けるコレクションの id(公開が承認の人に、公開中のレコードの保存と変更の破棄を許す) */
137
+ draftCollections?: (scope: AppScope) => Promise<readonly string[]>;
123
138
  /** 外部の接続の判定(キーは manifest.connections の id、なしは未接続) */
124
139
  connections?: Readonly<Record<string, (scope: AppScope) => boolean>>;
140
+ /** 提供するポートの処理(マニフェストの provides で route を持たないポート) */
141
+ provides?: Readonly<{
142
+ [MESSAGE_PORT]?: AppMessageProvider;
143
+ [PAYMENT_PORT]?: AppPaymentProvider;
144
+ [NOTICES_PORT]?: AppNoticesProvider;
145
+ }>;
146
+ /**
147
+ * 外のサービスから受ける経路の処理(キーはマニフェストの inbound の name。主体はインストール済みアプリ自身)
148
+ * 例外は送り手の再送、直らない拒否は AppInboundOutcome の refused
149
+ */
150
+ inbound?: Readonly<Record<string, (scope: AppScope, request: AppInboundRequest) => Promise<AppInboundOutcome | void>>>;
151
+ /** 受けたメールの処理(マニフェストで mail.inbound を宣言したアプリだけ。mail.channelId は受けたチャネル。主体はインストール済みアプリ自身、例外は送り手の再送) */
152
+ inboundMail?: (scope: AppScope, mail: AppInboundMail) => Promise<void>;
153
+ /** 受けるポートのイベント(マニフェストの uses で宣言したポートのもの) */
154
+ on?: Readonly<{
155
+ [MESSAGE_RECEIVED]?: (scope: AppScope, event: MessageReceived) => Promise<void>;
156
+ }>;
157
+ /** マニフェストのコレクションのレコードの作成、保存、削除、復元の確定の後に知るフック(AppSavedContext。失敗は送り直すので、何度呼ばれても同じ結果にする) */
158
+ afterSave?: (ctx: AppSavedContext) => Promise<void>;
159
+ }>;
160
+ /** 通知のポートの提供者(見ている人の文脈で呼ばれ、params は空。失敗と遅さは、ほかの提供者に及ぼさず欠けたことになる) */
161
+ export type AppNoticesProvider = (ctx: AppContext) => Promise<readonly AppNotice[]>;
162
+ /**
163
+ * 確定の後のフックの引数
164
+ * - collection: マニフェストのコレクションの名前(records が受ける名前)。宣言のコレクション(作ったものと当てたもの)の保存だけが届く
165
+ * - changed: 値の変わったマニフェストのフィールドの key(値は渡さない。今の値は records で読み、消えたレコードは get が null)
166
+ * - 取り込みの実行の中の保存は届かない
167
+ */
168
+ export type AppSavedContext = Readonly<{
169
+ scope: AppScope;
170
+ collection: string;
171
+ id: string;
172
+ changed: readonly string[];
173
+ }>;
174
+ /**
175
+ * メッセージのポートのプロバイダーの処理
176
+ * - send: コアが能力、テスト環境、同意と抑止を確かめた後に呼ぶ。宛先の解決と内容の検査はプロバイダー。一時的な失敗は例外
177
+ * - channel: 送るチャネル(依頼の channelId のチャネルか、プロジェクトの既定のチャネル)。channel_kinds で送信の種類を宣言しないプロバイダーは null
178
+ */
179
+ export type AppMessageProvider = Readonly<{
180
+ send: (scope: AppScope, request: MessageSendRequest, channel: AppChannel | null) => Promise<MessageProviderResult>;
181
+ }>;
182
+ /**
183
+ * 決済のポートのプロバイダーの処理(コアがオファー、価格、購入者を確かめた後に呼ぶ)
184
+ * - checkout: 支払いの画面の URL を作る。外部の価格は request.price.lookupKey で対応づけ、なければ作る
185
+ * - portal: 購入者の顧客の支払いの画面(解約、支払い方法、領収書)の URL を作る
186
+ * - channel: 依頼の決済のチャネル(依頼の channelId のチャネルか、プロバイダーの決済の種類の既定のチャネル)
187
+ * - 外部のサービスの一時的な失敗は例外
188
+ */
189
+ export type AppPaymentProvider = Readonly<{
190
+ checkout: (scope: AppScope, request: PaymentCheckoutRequest, channel: AppChannel) => Promise<PaymentCheckout>;
191
+ portal: (scope: AppScope, request: PaymentPortalRequest, channel: AppChannel) => Promise<Readonly<{
192
+ url: string;
193
+ }>>;
194
+ }>;
195
+ /**
196
+ * 決済の結果の反映の口(決済のポートのプロバイダーだけ。paymentPort.ts)
197
+ * - 主体はインストール済みアプリ自身で、許可はマニフェストの能力 `@end_users` の `write_entitlements`
198
+ * - channelId はこのインストールに結んだ、決済の能力のあるチャネルだけ(ほかは app_channel_undeclared)
199
+ * - 拒否は AppPortError
200
+ */
201
+ export type AppPaymentsPort = Readonly<{
202
+ reflectPurchase: (scope: AppScope, reflection: PurchaseReflection) => Promise<AppPortResult<ReflectionResult>>;
203
+ reflectSubscription: (scope: AppScope, reflection: SubscriptionReflection) => Promise<AppPortResult<ReflectionResult>>;
204
+ }>;
205
+ /** アプリ用の状態の置き場の上限(キーの字数、値の JSON の UTF-8 のバイト数、インストールごとのキーの数) */
206
+ export declare const APP_STATE_LIMITS: {
207
+ readonly keyMaxChars: 200;
208
+ readonly valueMaxBytes: 16384;
209
+ readonly keysMax: 200;
210
+ };
211
+ /** レコードの占有の上限(seconds は延長しない占有が効く秒数で、期限のない占有は作れない。画面が延長する間隔の4倍で、隠れたタブのタイマーの間引きに耐える長さ) */
212
+ export declare const APP_HOLD_LIMITS: {
213
+ readonly seconds: 120;
214
+ readonly clientMaxChars: 200;
215
+ };
216
+ /** 占有するレコード(client は持ち主を示す値。レコードの書き込みのヘッダー x-record-hold と同じ値の書き込みは止めない) */
217
+ export type AppHoldTarget = Readonly<{
218
+ collection: string;
219
+ record: string;
220
+ client: string;
221
+ }>;
222
+ /**
223
+ * アプリ用の状態の置き場(インストール済みアプリごとのキーと値。個人情報を入れない、業務のデータは宣言のコレクションに置く)
224
+ * - 値は JSON にできる値。get はないキーで null
225
+ * - getMany は複数のキーの値を1回で読む(ないキーは null。キーの数は keysMax まで、超えると invalid_input で target は keys)
226
+ * - 空か長いキーと大きい値は invalid_input(target は key か value)
227
+ * - キーの数の上限は invalid_state(reason は app_state_keys_full)
228
+ * - hold と release はレコードの占有。経路を呼んだ人の操作として、その人が更新できるレコードだけを占有する
229
+ * - hold の held が false ならほかの占有があり、holder はその人の表示名
230
+ */
231
+ export type AppStatePort = Readonly<{
232
+ get: (scope: AppScope, key: string) => Promise<AppPortResult<unknown>>;
233
+ getMany: (scope: AppScope, keys: readonly string[]) => Promise<AppPortResult<Readonly<Record<string, unknown>>>>;
234
+ set: (scope: AppScope, key: string, value: unknown) => Promise<AppPortResult<void>>;
235
+ delete: (scope: AppScope, key: string) => Promise<AppPortResult<void>>;
236
+ hold: (scope: AppScope, target: AppHoldTarget) => Promise<AppPortResult<Readonly<{
237
+ held: boolean;
238
+ holder: string | null;
239
+ }>>>;
240
+ release: (scope: AppScope, target: AppHoldTarget) => Promise<AppPortResult<void>>;
241
+ }>;
242
+ /** レコードの絞り込みの上限(値の一覧の件数) */
243
+ export declare const APP_RECORD_QUERY_LIMITS: {
244
+ readonly valuesMax: 100;
245
+ };
246
+ /** アプリのレコード(id とフィールドの key ごとの値) */
247
+ export type AppRecord = Readonly<{
248
+ id: string;
249
+ } & Record<string, unknown>>;
250
+ /**
251
+ * レコードの絞り込み
252
+ * - where: id とフィールドの key ごとの値の一致で、すべての条件を満たすレコード
253
+ * 値の一覧はどれかとの一致(空は0件、APP_RECORD_QUERY_LIMITS の件数まで)で、集計では使えない
254
+ * - range: 集計の時刻のフィールドの範囲(両端を含む)
255
+ */
256
+ export type AppRecordQuery = Readonly<{
257
+ where?: Readonly<Record<string, string | number | boolean | null | readonly string[]>>;
258
+ range?: Readonly<{
259
+ from?: string;
260
+ to?: string;
261
+ }>;
262
+ }>;
263
+ /** 一覧の1ページの指定(limit は件数で既定50・最大100、超える指定は invalid_input。cursor は前のページの next) */
264
+ export type AppPageRequest = Readonly<{
265
+ limit?: number;
266
+ cursor?: string;
267
+ }>;
268
+ /**
269
+ * レコードの1ページ(集計は id の順、ほかは作成の新しい順)
270
+ * - next は続きのカーソルで、終わりは null。1要求で走査する行の数に上限があり、当たると records が limit 件に満たなくても next を返す
271
+ */
272
+ export type AppRecordPage = Readonly<{
273
+ records: readonly AppRecord[];
274
+ next: string | null;
275
+ }>;
276
+ /**
277
+ * 一覧のページを next が尽きるまで読む(ページ送りの画面を持たない利用者の仮の形。1要求ごとの上限は効き、拒否はそのページの拒否)
278
+ */
279
+ export declare function allRecordPages(read: (page: AppPageRequest) => Promise<AppPortResult<AppRecordPage>>): Promise<AppPortResult<AppRecord[]>>;
280
+ /**
281
+ * 書き込みの条件(collection と record は対象の id。版 version と遷移の印 transition_id が、書き込む時点でこの値のときだけ書く)
282
+ * - 印のないレコードの transition_id は null
283
+ * - 対象は主体が読めるレコードだけ。読めない、ない、一致しないは、どれも invalid_state の condition_unmet
284
+ */
285
+ export type AppRecordCondition = Readonly<{
286
+ collection: string;
287
+ record: string;
288
+ version: number;
289
+ transition_id: string | null;
290
+ }>;
291
+ /** 集計の行(フィールドの key ごとの値) */
292
+ export type AggregateValues = Readonly<Record<string, string | number | null>>;
293
+ /** 集計のまとめ(by の次元ごとに、値を宣言の求め方で時刻をまたいでまとめる。where と range は絞り込みと同じ) */
294
+ export type AggregateRollup = AppRecordQuery & Readonly<{
295
+ by: readonly string[];
296
+ }>;
297
+ /** 集計の作り直しの範囲(時刻のフィールドの値、両端を含む) */
298
+ export type AggregateRange = Readonly<{
299
+ from: string;
300
+ to: string;
301
+ }>;
302
+ /**
303
+ * アプリの口の呼ぶ側の誤りのコード(アプリのコードを直すまで回復しない。結果にせず、このコードを code に持つ UsageError を投げる)
304
+ * - 宣言のないコレクション・イベント・秘密値・ポート・メール・チャネルの種類、未登録の発行者、DB だけの文脈、この環境に入っていない
305
+ */
306
+ 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"];
307
+ /** アプリの口の拒否のコード(API のエラーのコード) */
308
+ export type AppPortErrorCode = keyof typeof ERROR_STATUS;
309
+ /** アプリの口の拒否(業務の失敗と外から来た値の不一致。params と issues は API のエラーの本文と同じ) */
310
+ export type AppPortFailure = Readonly<{
311
+ ok: false;
312
+ error: AppPortErrorCode;
313
+ params?: ErrorParams;
314
+ issues?: readonly IssueInput[];
315
+ }>;
316
+ /**
317
+ * アプリの口の結果(ok で分ける Result の形に、拒否の params と issues を足したもの)
318
+ * - 呼ぶ側の誤りは APP_USAGE_ERRORS の UsageError、一時的な失敗は例外で、結果にしない
319
+ */
320
+ export type AppPortResult<T> = Readonly<{
321
+ ok: true;
322
+ value: T;
323
+ }> | AppPortFailure;
324
+ /**
325
+ * 業務のデータの読み書きの口(collection はマニフェストのコレクションの名前)
326
+ * - 主体はインストール済みアプリ自身で、変更の履歴と操作の履歴にインストールが残る。権限はマニフェストの宣言のコレクションだけ
327
+ * - 規則・保存前の検査・削除の可否と on_delete は、人の操作と同じ書き込みの入口が当てる
328
+ * - update は送った項目だけを置き換える
329
+ * - when の対象を読む主体は、同梱のアプリの管理の API の経路では呼んだ人、ほかはアプリ自身
330
+ * - 保存前の検査と規則の scope(DB だけの文脈)では使えない(app_scope_without_bindings)
331
+ */
332
+ export type AppRecordsPort = Readonly<{
333
+ list: (scope: AppScope, collection: string, page?: AppPageRequest) => Promise<AppPortResult<AppRecordPage>>;
334
+ get: (scope: AppScope, collection: string, id: string) => Promise<AppPortResult<AppRecord | null>>;
335
+ /** where と range の絞り込みの1ページ(where の条件は走査した行に当て、外れた行も走査の数に入る) */
336
+ query: (scope: AppScope, collection: string, query: AppRecordQuery & AppPageRequest) => Promise<AppPortResult<AppRecordPage>>;
337
+ /**
338
+ * 一意の組(コレクションの宣言 unique か、unique を付けたエンドユーザーへの参照のフィールド)の値で1件
339
+ * - values のキーは組の項目と同じ集合。合う組がなければ invalid_input、読めないかなければ null
340
+ */
341
+ find: (scope: AppScope, collection: string, values: Readonly<Record<string, string | number>>) => Promise<AppPortResult<AppRecord | null>>;
342
+ create: (scope: AppScope, collection: string, values: Readonly<Record<string, unknown>>, when?: AppRecordCondition) => Promise<AppPortResult<Readonly<{
343
+ id: string;
344
+ }>>>;
345
+ update: (scope: AppScope, collection: string, id: string, values: Readonly<Record<string, unknown>>, when?: AppRecordCondition) => Promise<AppPortResult<void>>;
346
+ delete: (scope: AppScope, collection: string, id: string) => Promise<AppPortResult<void>>;
347
+ /** マニフェストのコレクションのこの環境の id(利用者の権限で管理の API を呼ぶとき、権限の表と作成の依頼のキー。宣言のない名前は app_collection_undeclared) */
348
+ collectionId: (scope: AppScope, collection: string) => Promise<string>;
349
+ /** 集計のコレクションの range の行を rows で置き換える(range が null は全体。集計でないコレクションは invalid_state、利用者の書き込みは集計に効かない) */
350
+ rebuild: (scope: AppScope, collection: string, range: AggregateRange | null, rows: readonly AggregateValues[]) => Promise<AppPortResult<number>>;
351
+ /** 集計のコレクションの行を次元でまとめる(by は宣言の次元だけ、集計でないコレクションは invalid_state) */
352
+ rollup: (scope: AppScope, collection: string, rollup: AggregateRollup) => Promise<AppPortResult<readonly AggregateValues[]>>;
353
+ }>;
354
+ /**
355
+ * エンドユーザーの操作の口
356
+ * - 主体はインストール済みアプリ自身で、操作の履歴にインストールが残る
357
+ * - 許可はマニフェストの能力 `@end_users` の `update_status`(setStatus)、`delete`(erase)、`ensure`(ensure)、
358
+ * `read_identities`(findBySubject、subjectOf)、`write_consents`(recordConsent、setChannelBlock)
359
+ * - setStatus は同じ状態なら何もしない。erase は本人の削除の求めと同じ戻せない削除
360
+ * - ensure・findBySubject・subjectOf は、このインストールがマニフェストの identities で登録した issuer と audience の組だけ
361
+ * (ほかは end_user_identity_unregistered)。ensure は紐付けがなければエンドユーザーを作り、セッションは出さない
362
+ * - recordConsent・setChannelBlock は、このインストールに結んだ、マニフェストの channel_kinds の種類のチャネルの ID だけ(ほかは
363
+ * app_channel_undeclared)。同意とブロックはチャネルごと。記録の取り方は opt_in で、チャネルのアプリの記録を本人の証明とする(チャネルが署名などで確かめた
364
+ * 本人の操作を受けて呼ぶ)。本人の証明つきの opt_in の granted はブロックを外す
365
+ */
366
+ export type AppEndUsersPort = Readonly<{
367
+ setStatus: (scope: AppScope, endUserId: string, status: EndUserStatus) => Promise<AppPortResult<void>>;
368
+ erase: (scope: AppScope, endUserId: string) => Promise<AppPortResult<void>>;
369
+ ensure: (scope: AppScope, identity: AppEndUserIdentity) => Promise<AppPortResult<Readonly<{
370
+ endUserId: string;
371
+ created: boolean;
372
+ }>>>;
373
+ findBySubject: (scope: AppScope, identity: AppEndUserIdentity) => Promise<AppPortResult<string | null>>;
374
+ subjectOf: (scope: AppScope, endUserId: string, issuer: AppEndUserIssuer) => Promise<AppPortResult<string | null>>;
375
+ recordConsent: (scope: AppScope, endUserId: string, consent: AppChannelConsent) => Promise<AppPortResult<void>>;
376
+ setChannelBlock: (scope: AppScope, endUserId: string, channelId: string, blocked: boolean) => Promise<AppPortResult<void>>;
377
+ }>;
378
+ /** チャネルでの同意の記録(channelId はチャネルの ID、key は重複を除くキーで、同じキーの再送は記録しない) */
379
+ export type AppChannelConsent = Readonly<{
380
+ channelId: string;
381
+ purpose: string;
382
+ state: ConsentState;
383
+ key?: string;
384
+ }>;
385
+ /** 登録した発行者(ID トークンの iss と aud) */
386
+ export type AppEndUserIssuer = Readonly<{
387
+ issuer: string;
388
+ audience: string;
389
+ }>;
390
+ /** 本人の外部の ID(subject は発行者の sub) */
391
+ export type AppEndUserIdentity = AppEndUserIssuer & Readonly<{
392
+ subject: string;
393
+ }>;
394
+ /** ファイルの読み出しの上限(バイト数) */
395
+ export declare const APP_FILE_LIMITS: {
396
+ readonly readMaxBytes: 10485760;
397
+ };
398
+ /**
399
+ * ファイルの読み出しの口
400
+ * - read: 宣言のコレクション(既存に当てたものを含む)のレコードの、宣言した1つのファイルの項目が指すファイルの実体
401
+ * レコードはインストール済みアプリ自身の読み取りの判定を通す。読めない・ないレコードと空の項目は null
402
+ * - 画像はメタ情報(位置など)をマスクした実体。マスクできない画像は null
403
+ * - 宣言のないコレクションと項目、繰り返しの項目は app_collection_undeclared。上限を超える実体は file_too_large
404
+ */
405
+ export type AppFilesPort = Readonly<{
406
+ read: (scope: AppScope, target: Readonly<{
407
+ collection: string;
408
+ record: string;
409
+ field: string;
410
+ }>) => Promise<AppPortResult<Blob | null>>;
411
+ }>;
412
+ /**
413
+ * アプリのイベントを出す口(外には apps.<名前空間>.<name>、本文は AppEventData)
414
+ * - name はマニフェストの emits の名前だけ(ほかは app_event_undeclared)。対象は主体が読めるレコードだけ
415
+ * - 主体: 管理の API の経路では呼んだ人、ほかではインストール済みアプリ自身
416
+ * - outbox に書き、Webhook へはその後に配る。読めないレコードは not_found
417
+ */
418
+ export type AppEventsPort = Readonly<{
419
+ emit: (scope: AppScope, name: string, target: Readonly<{
420
+ collection: string;
421
+ record: string;
422
+ }>) => Promise<AppPortResult<void>>;
125
423
  }>;
126
- /** サーバーの側の組み立ての引数(settingsOf は画面で保存した値を含む設定値、schema は組み立ての時点のコンテンツスキーマ) */
424
+ /**
425
+ * アプリの秘密値の口(マニフェストの secrets で宣言したキーだけ。値は返さない)
426
+ * - verifyHmac: 秘密値を鍵にした HMAC の署名の検証(定数時間で比較。未設定は false)
427
+ * - configured: 値が入力済みか
428
+ * - 宣言にないキーは app_secret_undeclared の UsageError
429
+ */
430
+ export type AppSecretsPort = Readonly<{
431
+ verifyHmac: (scope: AppScope, key: string, check: AppHmacCheck) => Promise<AppPortResult<boolean>>;
432
+ configured: (scope: AppScope, key: string) => Promise<AppPortResult<boolean>>;
433
+ }>;
434
+ /** アプリがアカウントへ送れる知らせの種類(レコードの新着、担当の割り当て。件名と本文はコアの定型) */
435
+ export declare const APP_NOTICE_KINDS: readonly ["record_received", "record_assigned"];
436
+ export type AppNoticeKind = (typeof APP_NOTICE_KINDS)[number];
437
+ /** アカウントへの知らせの上限(1回の宛先の数) */
438
+ export declare const APP_NOTIFY_LIMITS: {
439
+ readonly accountsMax: 50;
440
+ };
441
+ /**
442
+ * アカウントへの知らせの依頼
443
+ * - accounts: 宛先のアカウントの ID(APP_NOTIFY_LIMITS の数まで、重なりは1つ)
444
+ * - target: collection はマニフェストのコレクションの名前、record はレコードの id
445
+ * - key: 依頼を見分ける鍵(ログに残す。重複を除くのは呼ぶアプリ)
446
+ */
447
+ export type AppNotifyRequest = Readonly<{
448
+ accounts: readonly string[];
449
+ target: Readonly<{
450
+ collection: string;
451
+ record: string;
452
+ }>;
453
+ kind: AppNoticeKind;
454
+ key: string;
455
+ }>;
456
+ /**
457
+ * 宛先ごとの結果(reason はコード)
458
+ * - skipped: not_member(プロジェクトのメンバーでない)、not_visible(宛先の権限でそのレコードを読めない)、account_missing、not_configured
459
+ * - failed: 送信の失敗(rejected、invalid_input、provider_error)
460
+ */
461
+ export type AppNotifyResult = Readonly<{
462
+ account: string;
463
+ result: 'sent';
464
+ } | {
465
+ account: string;
466
+ result: 'skipped' | 'failed';
467
+ reason: string;
468
+ }>;
469
+ /**
470
+ * アカウントへのメールの口(件名と本文はコアの定型で、レコードの値を含めない)
471
+ * - 宛先ごとに、メンバーか、宛先のアカウントの権限でそのレコードを読めるかを確かめてから送る。例外にせず結果で返す
472
+ * - 宣言のないコレクションは app_collection_undeclared の UsageError、宛先の数の超過は invalid_input
473
+ */
474
+ export type AppNotifyPort = (scope: AppScope, request: AppNotifyRequest) => Promise<AppPortResult<readonly AppNotifyResult[]>>;
475
+ /**
476
+ * メッセージのポートの口(マニフェストの uses と provides の宣言の範囲だけ)
477
+ * - send: 使う側の送信。宣言の能力の外は rejected、テスト環境、同意なし、抑止は skipped で、プロバイダーを呼ばない
478
+ * 送信のモードを決められない実行は unavailable(送り直す)
479
+ * - received: プロバイダーの受信。使う側のアプリの on に渡し、本文を保存しない
480
+ * 形の誤りと結んでいない受信のチャネルは invalid_input、受け手の失敗は例外(チャネルの再送に任せる)
481
+ */
482
+ export type AppMessagesPort = Readonly<{
483
+ send: (scope: AppScope, request: MessageSendRequest) => Promise<AppPortResult<MessageSendResult>>;
484
+ received: (scope: AppScope, input: MessageReceivedInput) => Promise<AppPortResult<void>>;
485
+ }>;
486
+ /** マニフェストのコレクションの解決(collection はコレクションの id、fields はマニフェストのフィールドの key → この環境のフィールドの key) */
487
+ export type AppCollectionTarget = Readonly<{
488
+ collection: string;
489
+ fields: Readonly<Record<string, string>>;
490
+ }>;
491
+ /** スラッグの解決(collection はコレクションの id、ids はスラッグ → レコードの id で、見つからないスラッグは含まない) */
492
+ export type ResolvedSlugs = Readonly<{
493
+ collection: string;
494
+ ids: Readonly<Record<string, string>>;
495
+ }>;
496
+ /** 日ごとの閲覧数(kind と id はサイトが送った値のまま) */
497
+ export type DailyViews = Readonly<{
498
+ date: string;
499
+ kind: string;
500
+ id: string;
501
+ views: number;
502
+ }>;
503
+ /** 外部の接続の読み込み元(キーは manifest.connections の id) */
504
+ export type AppConnections = Readonly<{
505
+ /** サイトが記録した閲覧の日ごとの数(since 以降の日付) */
506
+ 'analytics-engine': Readonly<{
507
+ daily: (since: string) => Promise<readonly DailyViews[]>;
508
+ }>;
509
+ }>;
510
+ /**
511
+ * サーバーの側の組み立ての引数(settingsOf は画面で保存した値を含む設定値、schema は組み立ての時点のコンテンツスキーマ)
512
+ * - collections: マニフェストのコレクションの名前の解決。当てていない、コレクションかフィールドが今のスキーマにない、この環境に入っていなければ null
513
+ * - resolveSlugs: 配信するコレクションのスラッグか id(旧いスラッグも)と、レコードのスラッグ(旧いスラッグも)を id に
514
+ * 配信の API が出す値だけを返し、配信しないコレクションは null
515
+ * - connection: 外部の接続の読み込み元(この環境で接続していなければ null)
516
+ */
127
517
  export type AppServerContext<S> = AppSetupContext<S> & Readonly<{
128
518
  settingsOf: (scope: AppScope) => Promise<S>;
129
519
  schema: CollectionSchema;
520
+ state: AppStatePort;
521
+ secrets: AppSecretsPort;
522
+ messages: AppMessagesPort;
523
+ /** メールの送信とドメイン(AppMailPort) */
524
+ mail: AppMailPort;
525
+ /** アプリのチャネル(AppChannelsPort) */
526
+ channels: AppChannelsPort;
527
+ records: AppRecordsPort;
528
+ files: AppFilesPort;
529
+ endUsers: AppEndUsersPort;
530
+ /** 決済の結果の反映(AppPaymentsPort) */
531
+ payments: AppPaymentsPort;
532
+ events: AppEventsPort;
533
+ collections: (scope: AppScope, name: string) => Promise<AppCollectionTarget | null>;
534
+ resolveSlugs: (scope: AppScope, collection: string, slugs: readonly string[]) => Promise<ResolvedSlugs | null>;
535
+ connection: <K extends keyof AppConnections>(scope: AppScope, id: K) => AppConnections[K] | null;
536
+ /** アカウントへのメール(AppNotifyPort) */
537
+ notify: AppNotifyPort;
538
+ /** マニフェストの outbound の宣言に当たる要求だけの外への要求(イベントと定期の処理から。経路の処理は AppContext の egress) */
539
+ egress: (scope: AppScope, input: string | URL, init?: RequestInit) => Promise<Response>;
130
540
  }>;
131
541
  /** アプリのサーバーの側(S はアプリの設定値、create は組み立ての時点で1回) */
132
542
  export type AppServer<S = unknown> = Readonly<{
133
543
  app: AppDefinition<S>;
134
544
  create(ctx: AppServerContext<S>): AppServerParts;
545
+ /**
546
+ * アプリの単位の受信の振り分け(キーは dispatch: 'app' の inbound の name。同梱のアプリだけ)
547
+ * プロジェクトの文脈の外で呼ぶので create の外に置く。署名の検証は operator の秘密値で行う
548
+ */
549
+ inboundDispatch?: Readonly<Record<string, (request: AppDispatchRequest, operator: AppOperatorSecrets) => Promise<AppDispatched>>>;
135
550
  }>;
136
551
  export {};
@@ -1,6 +1,6 @@
1
1
  /**
2
2
  * 申請の種類(schema は重い差を含むスキーマの変更、promote は live の切り替え、freeze は live の書き込みの停止、delete_environment は環境の削除)
3
- * - reimport は移した後の live への取り込み直しで、取り込みの後に画面で直したレコードと顧客を取り出し元の値で上書きする(tunasand#713)
3
+ * - reimport は移した後の live への取り込み直しで、取り込みの後に画面で直したレコードとエンドユーザーを取り出し元の値で上書きする(tunasand#713)
4
4
  * 承認は REIMPORT_WINDOW_MS の間、その取り出し元の上書きの取り込みを通す(足すだけの取り込み直しは軽い操作で申請なし)
5
5
  */
6
6
  export declare const APPROVAL_KINDS: readonly ["schema", "promote", "freeze", "delete_environment", "reimport"];