@tunasand/sdk 0.0.0-stage → 0.7.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 (169) hide show
  1. package/CHANGELOG.md +114 -0
  2. package/README.md +516 -2
  3. package/dist/analytics.d.ts +1 -0
  4. package/dist/analytics.js +43 -0
  5. package/dist/app.d.ts +1 -0
  6. package/dist/app.js +825 -0
  7. package/dist/apps-9u4XMi7E.js +114 -0
  8. package/dist/body.d.ts +1 -0
  9. package/dist/body.js +455 -0
  10. package/dist/bridge-DYAYGV7t.js +74 -0
  11. package/dist/bridge.d.ts +1 -0
  12. package/dist/bridge.js +189 -0
  13. package/dist/cli.d.ts +1 -0
  14. package/dist/cli.js +283 -0
  15. package/dist/client-Derrexwr.js +159 -0
  16. package/dist/customers-C_vJY2_v.js +84 -0
  17. package/dist/customers.d.ts +1 -0
  18. package/dist/customers.js +185 -0
  19. package/dist/declared-C_GvPiGF.js +397 -0
  20. package/dist/delivery.d.ts +1 -0
  21. package/dist/delivery.js +394 -0
  22. package/dist/dev.d.ts +1 -0
  23. package/dist/dev.js +93 -0
  24. package/dist/embed-R-OvDYAw.js +90 -0
  25. package/dist/errorLabels-CPKiPabZ.js +1510 -0
  26. package/dist/i18n.d.ts +1 -0
  27. package/dist/i18n.js +4 -0
  28. package/dist/integrations.d.ts +1 -0
  29. package/dist/integrations.js +62 -0
  30. package/dist/ja-C1HEWWTQ.js +241 -0
  31. package/dist/ja-C6lX0CeJ.js +213 -0
  32. package/dist/model-pmXzGX12.js +152 -0
  33. package/dist/model.d.ts +1 -0
  34. package/dist/model.js +345 -0
  35. package/dist/page-E_cYgZx-.js +138 -0
  36. package/dist/preview.d.ts +1 -0
  37. package/dist/preview.js +1 -0
  38. package/dist/profile-D6t1QMQh.js +223 -0
  39. package/dist/schema-BPHL7Qr-.js +115 -0
  40. package/dist/schema-UQJWRyfJ.js +995 -0
  41. package/dist/schema.d.ts +1 -0
  42. package/dist/schema.js +1 -0
  43. package/dist/src-sazhzYui.js +71 -0
  44. package/dist/types/access/src/handoff.d.ts +52 -0
  45. package/dist/types/access/src/index.d.ts +5 -0
  46. package/dist/types/access/src/jws.d.ts +5 -0
  47. package/dist/types/access/src/jwt.d.ts +35 -0
  48. package/dist/types/access/src/oidc.d.ts +50 -0
  49. package/dist/types/access/src/signed.d.ts +15 -0
  50. package/dist/types/analytics/src/day.d.ts +2 -0
  51. package/dist/types/analytics/src/index.d.ts +5 -0
  52. package/dist/types/analytics/src/schedule.d.ts +2 -0
  53. package/dist/types/analytics/src/shared.d.ts +21 -0
  54. package/dist/types/analytics/src/source.d.ts +19 -0
  55. package/dist/types/analytics/src/store.d.ts +24 -0
  56. package/dist/types/analytics/src/view.d.ts +33 -0
  57. package/dist/types/body/src/components.d.ts +25 -0
  58. package/dist/types/body/src/declared.d.ts +34 -0
  59. package/dist/types/body/src/derive.d.ts +13 -0
  60. package/dist/types/body/src/description.d.ts +8 -0
  61. package/dist/types/body/src/embed.d.ts +16 -0
  62. package/dist/types/body/src/href.d.ts +4 -0
  63. package/dist/types/body/src/html.d.ts +30 -0
  64. package/dist/types/body/src/index.d.ts +19 -0
  65. package/dist/types/body/src/inline.d.ts +20 -0
  66. package/dist/types/body/src/labels/en.d.ts +90 -0
  67. package/dist/types/body/src/labels/ja.d.ts +153 -0
  68. package/dist/types/body/src/library.d.ts +113 -0
  69. package/dist/types/body/src/markdown.d.ts +14 -0
  70. package/dist/types/body/src/normalize.d.ts +5 -0
  71. package/dist/types/body/src/problems.d.ts +103 -0
  72. package/dist/types/body/src/profile.d.ts +80 -0
  73. package/dist/types/body/src/render.d.ts +29 -0
  74. package/dist/types/body/src/schema.d.ts +6 -0
  75. package/dist/types/body/src/standard.d.ts +20 -0
  76. package/dist/types/body/src/types.d.ts +140 -0
  77. package/dist/types/cms-contract/src/apiKeys.d.ts +41 -0
  78. package/dist/types/cms-contract/src/app.d.ts +35 -0
  79. package/dist/types/cms-contract/src/appDependencies.d.ts +265 -0
  80. package/dist/types/cms-contract/src/appProblems.d.ts +22 -0
  81. package/dist/types/cms-contract/src/apps.d.ts +195 -0
  82. package/dist/types/cms-contract/src/assets.d.ts +12 -0
  83. package/dist/types/cms-contract/src/authorize.d.ts +146 -0
  84. package/dist/types/cms-contract/src/bridge.d.ts +318 -0
  85. package/dist/types/cms-contract/src/consents.d.ts +97 -0
  86. package/dist/types/cms-contract/src/customerLabels.d.ts +33 -0
  87. package/dist/types/cms-contract/src/customers.d.ts +266 -0
  88. package/dist/types/cms-contract/src/embeds.d.ts +165 -0
  89. package/dist/types/cms-contract/src/errorLabels.d.ts +269 -0
  90. package/dist/types/cms-contract/src/errorLabelsEn.d.ts +228 -0
  91. package/dist/types/cms-contract/src/errors.d.ts +105 -0
  92. package/dist/types/cms-contract/src/failureStatus.d.ts +124 -0
  93. package/dist/types/cms-contract/src/functionLabels.d.ts +5 -0
  94. package/dist/types/cms-contract/src/functions.d.ts +144 -0
  95. package/dist/types/cms-contract/src/identifiers.d.ts +117 -0
  96. package/dist/types/cms-contract/src/import.d.ts +277 -0
  97. package/dist/types/cms-contract/src/issueLabels.d.ts +435 -0
  98. package/dist/types/cms-contract/src/issueLabelsEn.d.ts +217 -0
  99. package/dist/types/cms-contract/src/migration.d.ts +103 -0
  100. package/dist/types/cms-contract/src/paths.d.ts +23 -0
  101. package/dist/types/cms-contract/src/permissionLabels.d.ts +8 -0
  102. package/dist/types/cms-contract/src/permissions.d.ts +77 -0
  103. package/dist/types/cms-contract/src/problems.d.ts +34 -0
  104. package/dist/types/cms-contract/src/roles.d.ts +57 -0
  105. package/dist/types/cms-contract/src/settingProblems.d.ts +13 -0
  106. package/dist/types/cms-contract/src/settings.d.ts +19 -0
  107. package/dist/types/cms-contract/src/siteArtifact.d.ts +45 -0
  108. package/dist/types/cms-contract/src/siteDeclaration.d.ts +70 -0
  109. package/dist/types/cms-contract/src/transfer.d.ts +57 -0
  110. package/dist/types/cms-contract/src/urlLabel.d.ts +13 -0
  111. package/dist/types/cms-contract/src/views.d.ts +21 -0
  112. package/dist/types/cms-contract/src/webhookLabels.d.ts +7 -0
  113. package/dist/types/cms-contract/src/webhooks.d.ts +139 -0
  114. package/dist/types/i18n/src/index.d.ts +50 -0
  115. package/dist/types/i18n/src/problems.d.ts +21 -0
  116. package/dist/types/model/src/asset.d.ts +111 -0
  117. package/dist/types/model/src/audience.d.ts +38 -0
  118. package/dist/types/model/src/brand.d.ts +25 -0
  119. package/dist/types/model/src/capabilities.d.ts +28 -0
  120. package/dist/types/model/src/changes.d.ts +34 -0
  121. package/dist/types/model/src/check.d.ts +15 -0
  122. package/dist/types/model/src/contact.d.ts +22 -0
  123. package/dist/types/model/src/image.d.ts +38 -0
  124. package/dist/types/model/src/index.d.ts +26 -0
  125. package/dist/types/model/src/input.d.ts +26 -0
  126. package/dist/types/model/src/integrity.d.ts +79 -0
  127. package/dist/types/model/src/json.d.ts +2 -0
  128. package/dist/types/model/src/labels/en.d.ts +169 -0
  129. package/dist/types/model/src/labels/ja.d.ts +198 -0
  130. package/dist/types/model/src/legacy.d.ts +2 -0
  131. package/dist/types/model/src/media.d.ts +5 -0
  132. package/dist/types/model/src/mediaUrl.d.ts +67 -0
  133. package/dist/types/model/src/model.d.ts +415 -0
  134. package/dist/types/model/src/page.d.ts +52 -0
  135. package/dist/types/model/src/problems.d.ts +184 -0
  136. package/dist/types/model/src/refs.d.ts +27 -0
  137. package/dist/types/model/src/rules.d.ts +15 -0
  138. package/dist/types/model/src/schema.d.ts +58 -0
  139. package/dist/types/model/src/screens.d.ts +76 -0
  140. package/dist/types/model/src/selfOps.d.ts +30 -0
  141. package/dist/types/model/src/time.d.ts +25 -0
  142. package/dist/types/model/src/typesSource.d.ts +8 -0
  143. package/dist/types/model/src/values.d.ts +24 -0
  144. package/dist/types/platform/src/defaultModel.d.ts +8 -0
  145. package/dist/types/sdk/src/analytics.d.ts +2 -0
  146. package/dist/types/sdk/src/app.d.ts +20 -0
  147. package/dist/types/sdk/src/body.d.ts +2 -0
  148. package/dist/types/sdk/src/bridge.d.ts +92 -0
  149. package/dist/types/sdk/src/cli.d.ts +2 -0
  150. package/dist/types/sdk/src/customers.d.ts +190 -0
  151. package/dist/types/sdk/src/delivery/cache.d.ts +18 -0
  152. package/dist/types/sdk/src/delivery/changes.d.ts +28 -0
  153. package/dist/types/sdk/src/delivery/client.d.ts +90 -0
  154. package/dist/types/sdk/src/delivery/fields.d.ts +48 -0
  155. package/dist/types/sdk/src/delivery/index.d.ts +9 -0
  156. package/dist/types/sdk/src/delivery/media.d.ts +28 -0
  157. package/dist/types/sdk/src/delivery/query.d.ts +85 -0
  158. package/dist/types/sdk/src/delivery/schema.d.ts +19 -0
  159. package/dist/types/sdk/src/delivery/values.d.ts +82 -0
  160. package/dist/types/sdk/src/delivery.d.ts +3 -0
  161. package/dist/types/sdk/src/dev.d.ts +29 -0
  162. package/dist/types/sdk/src/i18n.d.ts +12 -0
  163. package/dist/types/sdk/src/integrations.d.ts +33 -0
  164. package/dist/types/sdk/src/model.d.ts +5 -0
  165. package/dist/types/sdk/src/preview.d.ts +1 -0
  166. package/dist/types/sdk/src/schema.d.ts +21 -0
  167. package/dist/types/sdk/src/site.d.ts +43 -0
  168. package/dist/typesSource-bO0jFw1I.js +88 -0
  169. package/package.json +86 -3
@@ -0,0 +1,124 @@
1
+ /** 失敗のコードと HTTP の状態 */
2
+ export declare const FAILURE_STATUS: {
3
+ readonly invalid_input: 400;
4
+ readonly submit_unmet: 400;
5
+ readonly publish_unmet: 400;
6
+ readonly save_unmet: 400;
7
+ readonly version_required: 400;
8
+ readonly file_required: 400;
9
+ readonly file_too_large: 400;
10
+ readonly unsupported_image: 400;
11
+ readonly unsupported_file: 400;
12
+ readonly invalid_dimensions: 400;
13
+ readonly https_required: 400;
14
+ readonly invalid_style: 400;
15
+ readonly invalid_slug: 400;
16
+ readonly reserved_slug: 400;
17
+ readonly invalid_id: 400;
18
+ readonly reserved_id: 400;
19
+ readonly tenant_required: 400;
20
+ readonly same_environment: 400;
21
+ readonly ticket_required: 400;
22
+ readonly ticket_invalid: 400;
23
+ readonly login_required: 401;
24
+ readonly unauthorized: 401;
25
+ readonly reauth_required: 401;
26
+ readonly invalid_mcp_token: 401;
27
+ readonly mcp_signature_invalid: 401;
28
+ readonly invalid_account_token: 401;
29
+ readonly preview_token_required: 401;
30
+ readonly api_key_required: 401;
31
+ readonly invalid_api_key: 401;
32
+ readonly invalid_id_token: 401;
33
+ readonly invalid_app_token: 401;
34
+ readonly account_not_found: 403;
35
+ readonly invalid_preview_token: 403;
36
+ readonly api_key_forbidden: 403;
37
+ readonly mcp_not_allowed: 403;
38
+ readonly insufficient_scope: 403;
39
+ readonly admin_only: 403;
40
+ readonly operator_read_only: 403;
41
+ readonly operator_closed: 403;
42
+ readonly not_trial: 403;
43
+ readonly not_live: 403;
44
+ readonly forbidden: 403;
45
+ readonly mfa_required: 403;
46
+ readonly cross_origin: 403;
47
+ readonly editorial_only: 403;
48
+ readonly no_linked_record: 403;
49
+ readonly own_only: 403;
50
+ readonly not_visible: 403;
51
+ readonly published_admin_only: 403;
52
+ readonly cannot_remove_self: 403;
53
+ readonly cannot_change_owner: 403;
54
+ readonly not_found: 404;
55
+ readonly customer_not_linked: 404;
56
+ readonly method_not_allowed: 405;
57
+ readonly customer_pending: 409;
58
+ readonly in_use: 409;
59
+ readonly conflict: 409;
60
+ readonly already_exists: 409;
61
+ readonly duplicate_name: 409;
62
+ readonly duplicate_email: 409;
63
+ readonly duplicate_id: 409;
64
+ readonly duplicate_slug: 409;
65
+ readonly slug_taken: 409;
66
+ readonly version_conflict: 409;
67
+ readonly article_editing: 409;
68
+ readonly invalid_state: 409;
69
+ readonly unpublish_first: 409;
70
+ readonly last_owner: 409;
71
+ readonly last_admin: 409;
72
+ readonly exceeds_own: 403;
73
+ readonly already_linked: 409;
74
+ readonly invalid_invite: 409;
75
+ readonly run_done: 409;
76
+ readonly live_audience: 409;
77
+ readonly already_live: 409;
78
+ readonly target_live: 409;
79
+ readonly target_synthetic: 409;
80
+ readonly cross_tenant: 409;
81
+ readonly target_busy: 409;
82
+ readonly target_frozen: 409;
83
+ readonly not_frozen: 409;
84
+ readonly stale: 409;
85
+ readonly approval_required: 403;
86
+ readonly approval_closed: 409;
87
+ readonly still_frozen: 409;
88
+ readonly schema_values: 409;
89
+ readonly confirm_required: 409;
90
+ readonly pii_unregistered_table: 409;
91
+ readonly environment_limit_exceeded: 409;
92
+ readonly cursor_expired: 410;
93
+ readonly body_too_large: 413;
94
+ readonly rate_limited: 429;
95
+ readonly upstream_failed: 502;
96
+ readonly not_configured: 503;
97
+ readonly unavailable: 503;
98
+ readonly writes_paused: 503;
99
+ readonly environment_frozen: 503;
100
+ readonly audit_unshipped: 503;
101
+ readonly grants_not_revoked: 503;
102
+ readonly notice_failed: 503;
103
+ readonly job_failed: 500;
104
+ readonly internal_error: 500;
105
+ readonly incomplete: 500;
106
+ };
107
+ /** 失敗のコード */
108
+ export type FailureCode = keyof typeof FAILURE_STATUS;
109
+ /** 待てば通る失敗の Retry-After(秒) */
110
+ export declare const RETRY_AFTER_SEC: {
111
+ readonly environment_frozen: 60;
112
+ };
113
+ /** 失敗の応答の見出し(待てば通るコードだけ Retry-After) */
114
+ export declare const retryHeadersOf: (code: FailureCode) => Record<string, string>;
115
+ /**
116
+ * スキーマだけの本番に反映の失敗のコード(サーバーと manage の RPC で共通)
117
+ * - already_live は元が live の環境、invalid_input は保存の検査の誤りか禁止の変更か一意の組の重なり(issues、保存と同じ形)
118
+ * - schema_values は値を失うか補充の要る差か常に止める差(blocked に件数)、confirm_required は承認していない差(pending に ID)
119
+ * - stale は確認のステップの後に版か live の向きか止める差の件数が変わった、environment_frozen は live が切り替えの準備で止まっている(解除を待つ)
120
+ * - incomplete は確定の途中の例外
121
+ */
122
+ export declare const SCHEMA_PROMOTION_ERRORS: readonly ["not_found", "forbidden", "invalid_input", "already_live", "not_configured", "reauth_required", "approval_required", "ticket_invalid", "schema_values", "confirm_required", "stale", "environment_frozen", "incomplete"];
123
+ /** スキーマだけの本番に反映の失敗のコード */
124
+ export type SchemaPromotionError = (typeof SCHEMA_PROMOTION_ERRORS)[number];
@@ -0,0 +1,5 @@
1
+ import type { FunctionHook } from './functions.js';
2
+ /** 時点の表示名 */
3
+ export declare const FUNCTION_HOOK_LABELS: Readonly<Record<FunctionHook, string>>;
4
+ /** 送信記録のイベントの表示名(コレクションの表示名と時点の表示名) */
5
+ export declare const FUNCTION_EVENT_LABEL: (collection: string, hook: string) => string;
@@ -0,0 +1,144 @@
1
+ import type { IssueInput } from './errors.js';
2
+ /** 依頼する時点(save_check はコレクションの保存前、publish_check は提出・公開の前の検査) */
3
+ export declare const FUNCTION_HOOKS: readonly ["save_check", "publish_check", "list_column"];
4
+ /** 依頼する時点 */
5
+ export type FunctionHook = (typeof FUNCTION_HOOKS)[number];
6
+ /** 時間切れ・失敗・不正な応答のときの扱い(block は保存・提出・公開を拒否、pass は通過) */
7
+ export type FunctionOnError = 'block' | 'pass';
8
+ /**
9
+ * 外部関数の登録(url・secret は末尾だけを伏せずに返す)
10
+ * - previousSecret: 鍵の移行の期間の古い鍵の末尾、期間の外は null
11
+ * - lastStatus: 最新の呼び出しで返った HTTP の状態、送れなかったときは0
12
+ * - installationId: 登録簿のアプリのインストールがマニフェストの画面から作った行ならその ID(連携のタブでは変えられない、secret は空)、ほかは null
13
+ */
14
+ export type ExternalFunction = Readonly<{
15
+ id: string;
16
+ installationId: string | null;
17
+ label: string;
18
+ hook: FunctionHook;
19
+ collection: string;
20
+ url: string;
21
+ secret: string;
22
+ previousSecret: string | null;
23
+ onError: FunctionOnError;
24
+ enabled: boolean;
25
+ lastStatus: number | null;
26
+ lastAt: string | null;
27
+ }>;
28
+ /** 本文のコレクションとレコードの指定 */
29
+ export type FunctionRef = Readonly<{
30
+ id: string;
31
+ slug: string;
32
+ }>;
33
+ /** 保存前の検査の本文(record は作成なら null、values は宣言と拡張機能で補正した後の項目の値、user は操作した人のアカウントの ID とロール) */
34
+ export type SaveCheckRequest = Readonly<{
35
+ hook: 'save_check';
36
+ collection: FunctionRef;
37
+ record: FunctionRef | null;
38
+ values: Readonly<Record<string, unknown>>;
39
+ user: Readonly<{
40
+ id: string;
41
+ role: string;
42
+ }>;
43
+ at: string;
44
+ }>;
45
+ /**
46
+ * 外部関数の検査の結果の1件(path は項目の key、message は画面に表示する理由、code は関数が決める問題のコードで省くと invalid、severity は省くと error)
47
+ * - warning は操作を止めず、検査だけの実行(check_record)の結果に出る
48
+ * - 知らないキーは応答の形の誤り(登録の on_error の扱い)。CMS の問題の表と同じ code は、差し込みがそろえば管理画面が表の文で出す
49
+ */
50
+ export type FunctionIssue = IssueInput;
51
+ /**
52
+ * 保存前の検査の応答(HTTP の状態は 2xx、知らないキーは応答の形の誤り)
53
+ * - issues: severity が error のものが1件でもあれば保存を拒否
54
+ * - values: 補正する項目だけの値(入力に重ねる、なしは補正なし)
55
+ */
56
+ export type SaveCheckResponse = Readonly<{
57
+ issues?: readonly FunctionIssue[];
58
+ values?: Readonly<Record<string, unknown>>;
59
+ }>;
60
+ /**
61
+ * 提出・公開前の検査の本文
62
+ * - stage: submit か publish(検査だけの実行は次に進む段階)、values: 保存済みのレコードの値、record: テストの呼び出しだけ null
63
+ * - dryRun: 検査だけの実行なら true(提出・公開の点検では省略)
64
+ */
65
+ export type PublishCheckRequest = Readonly<{
66
+ hook: 'publish_check';
67
+ collection: FunctionRef;
68
+ record: FunctionRef | null;
69
+ stage: 'submit' | 'publish';
70
+ dryRun?: true;
71
+ values: Readonly<Record<string, unknown>>;
72
+ user: Readonly<{
73
+ id: string;
74
+ role: string;
75
+ }>;
76
+ at: string;
77
+ }>;
78
+ /** 提出・公開前の検査の応答(HTTP の状態は 2xx、severity が error の issues が1件でもあれば提出・公開を拒否、値の補正はなし) */
79
+ export type PublishCheckResponse = Readonly<{
80
+ issues?: readonly FunctionIssue[];
81
+ }>;
82
+ /** 一覧の列に1回で送るレコードの ID の件数の上限 */
83
+ export declare const LIST_COLUMN_IDS_MAX = 100;
84
+ /** 一覧の列のセルの文字の長さの上限 */
85
+ export declare const LIST_CELL_TEXT_MAX = 200;
86
+ /** 印のセルの色の種類(neutral は既定) */
87
+ export declare const LIST_CELL_TONES: readonly ["neutral", "ok", "warn", "danger"];
88
+ /** 印のセルの色の種類 */
89
+ export type ListCellTone = (typeof LIST_CELL_TONES)[number];
90
+ /**
91
+ * 一覧の列のセルの宣言(宣言の部品の木の最小の形、見た目の作り直しで部品が増える)
92
+ * - text: 文字、number: 数(右寄せ、並べ替えは数の順)、date: 日付か日時(ISO 8601)
93
+ * - badge: 印(tone は色の種類)、link: 外のページへのリンク(https だけ、新しいタブで開く)
94
+ */
95
+ export type ListCell = Readonly<{
96
+ kind: 'text';
97
+ text: string;
98
+ }> | Readonly<{
99
+ kind: 'number';
100
+ value: number;
101
+ }> | Readonly<{
102
+ kind: 'date';
103
+ value: string;
104
+ }> | Readonly<{
105
+ kind: 'badge';
106
+ text: string;
107
+ tone?: ListCellTone;
108
+ }> | Readonly<{
109
+ kind: 'link';
110
+ text: string;
111
+ url: string;
112
+ }>;
113
+ /** 一覧の列の本文(records は見ている人が閲覧できる表示中のレコード、LIST_COLUMN_IDS_MAX 件まで) */
114
+ export type ListColumnRequest = Readonly<{
115
+ hook: 'list_column';
116
+ collection: FunctionRef;
117
+ records: readonly FunctionRef[];
118
+ user: Readonly<{
119
+ id: string;
120
+ role: string;
121
+ }>;
122
+ at: string;
123
+ }>;
124
+ /** 一覧の列の応答(HTTP の状態は 2xx、cells はレコードの ID ごとのセルで、ない行と null は空のセル、送っていない ID は捨てる) */
125
+ export type ListColumnResponse = Readonly<{
126
+ cells: Readonly<Record<string, ListCell | null>>;
127
+ }>;
128
+ /** 管理画面に返す一覧の列(id は登録の ID、label は列の見出し) */
129
+ export type EmbedColumn = Readonly<{
130
+ id: string;
131
+ label: string;
132
+ }>;
133
+ /** 一覧の列の値(登録の ID ごと、failed は呼び出しの失敗で列を空にする) */
134
+ export type EmbedColumnValues = Readonly<Record<string, Readonly<{
135
+ cells: Readonly<Record<string, ListCell>>;
136
+ }> | Readonly<{
137
+ failed: true;
138
+ }>>>;
139
+ /** 外部関数への依頼の本文 */
140
+ export type FunctionRequest = SaveCheckRequest | PublishCheckRequest | ListColumnRequest;
141
+ /** 送信記録のイベント(<コレクションの id>.<時点>) */
142
+ export declare const functionEventOf: (collection: string, hook: FunctionHook) => string;
143
+ /** 送信記録のイベントの表示名(types はコレクションの id と表示名、形が違えばそのまま) */
144
+ export declare function functionEventLabel(event: string, collections: Readonly<Record<string, string>>): string;
@@ -0,0 +1,117 @@
1
+ /** ID の種類 */
2
+ export declare const ID_KINDS: readonly ["app", "installation", "customer", "event"];
3
+ export type IdKind = (typeof ID_KINDS)[number];
4
+ /** UUID v7 の形(小文字の16進とハイフン) */
5
+ export declare const UUID_V7: RegExp;
6
+ /** 種類の ID の形か(作るのはサーバーで、どの種類も UUID v7) */
7
+ export declare const isIdOf: (_kind: IdKind, value: string) => boolean;
8
+ /**
9
+ * 時刻とバイト列から組む UUID v7(同じ入力には同じ値)
10
+ * - ms: 時刻(ミリ秒、48ビット)
11
+ * - random: 乱数の部分(頭の10バイトを使う。10バイトより短ければ例外)
12
+ */
13
+ export declare function uuidV7From(ms: number, random: Uint8Array): string;
14
+ /**
15
+ * 秘密の値の接頭辞(#683。値から種類が分かり、漏れの検出に使える)
16
+ * - server: 配信 API のサーバーの鍵、personalToken: 個人のトークン、publicClient: 公開のクライアントの識別子
17
+ * - webhook: Webhook と外部関数の署名の鍵(Standard Webhooks)
18
+ * - 顧客の更新の資格は CUSTOMER_TOKEN の refreshPrefix
19
+ */
20
+ export declare const SECRET_PREFIXES: {
21
+ readonly server: "tunasand_sk_";
22
+ readonly personalToken: "tunasand_pat_";
23
+ readonly publicClient: "tunasand_pk_";
24
+ readonly webhook: "whsec_";
25
+ };
26
+ /** アプリが持つコレクションの id の区切り(`<名前空間>__<名前>`) */
27
+ export declare const APP_COLLECTION_SEPARATOR = "__";
28
+ /** コレクションの名前空間の形(登録のときに決め、アプリの識別子に結び付けて変えない。アプリを消しても再利用しない) */
29
+ export declare const APP_NAMESPACE_PATTERN: RegExp;
30
+ /** アプリが持つコレクションの名前空間(アプリが持つコレクションでなければ null) */
31
+ export declare function appNamespaceOf(collectionId: string): string | null;
32
+ /** 操作の履歴の主体の種類(アカウント・運営者・インストール・アカウントの代わり・人の代わり・コア) */
33
+ export declare const ACTOR_KINDS: readonly ["account", "operator", "installation", "on_behalf_of_account", "on_behalf_of_customer", "system"];
34
+ /** 操作の履歴の主体の種類 */
35
+ export type ActorKind = (typeof ACTOR_KINDS)[number];
36
+ /** 操作の履歴の経路(管理画面、MCP、配信 API の鍵、アプリのアカウントの資格) */
37
+ export declare const AUDIT_VIAS: readonly ["cms", "mcp", "api", "app"];
38
+ /** 操作の履歴の経路 */
39
+ export type AuditVia = (typeof AUDIT_VIAS)[number];
40
+ /** 経路から決まる主体の種類(運営者は経路で分からないので、ログインの種類で上書きする) */
41
+ export declare const ACTOR_KIND_OF_VIA: {
42
+ readonly cms: "account";
43
+ readonly mcp: "on_behalf_of_account";
44
+ readonly api: "installation";
45
+ readonly app: "on_behalf_of_account";
46
+ };
47
+ /** 項目の種類「顧客への参照」の名前(値は顧客の ID の文字列) */
48
+ export declare const CUSTOMER_REFERENCE_FIELD = "customer";
49
+ /**
50
+ * 顧客のトークンの形(実装は要望の後、形だけを固定)
51
+ * - JWS のコンパクトな形。発行と検証はどちらも Tunasand だけで、署名の鍵は SECRETS_KEY からプロジェクトごとに HKDF で導く
52
+ * - 更新の資格は refreshPrefix で始まる不透明な値(保存はハッシュだけ、使うたびに作り直す)
53
+ */
54
+ export declare const CUSTOMER_TOKEN: {
55
+ readonly typ: "tunasand-member+jwt";
56
+ readonly alg: "HS256";
57
+ readonly ttlSec: 600;
58
+ readonly refreshPrefix: "tunasand_rt_";
59
+ readonly absoluteSec: number;
60
+ };
61
+ /** 顧客のトークンのクレーム(iss はプロジェクトの CMS のホストの URL、aud はチャネル = インストールの ID、sv は顧客の状態の版、時刻は秒) */
62
+ export type CustomerTokenClaims = Readonly<{
63
+ iss: string;
64
+ sub: string;
65
+ aud: string;
66
+ iat: number;
67
+ exp: number;
68
+ jti: string;
69
+ sv: number;
70
+ }>;
71
+ /**
72
+ * インストールのトークンの形(GitHub App の形: アプリの鍵で署名したアプリの JWT と交換する)
73
+ * - JWS のコンパクトな形。発行と検証はどちらも Tunasand だけで、署名の鍵は SECRETS_KEY からプロジェクトごとに HKDF で導く
74
+ * - アプリの JWT: ES256 か RS256、iss はアプリの ID、aud はプロジェクトの配信の基点、exp − iat は appJwtMaxSec 秒まで
75
+ * - 時計のずれ: iat の未来と exp の過去を skewSec 秒まで許す
76
+ */
77
+ export declare const INSTALLATION_TOKEN: {
78
+ readonly typ: "tunasand-installation+jwt";
79
+ readonly alg: "HS256";
80
+ readonly ttlSec: 3600;
81
+ readonly appJwtMaxSec: 600;
82
+ readonly skewSec: 60;
83
+ };
84
+ /**
85
+ * アカウントの資格の API のトークンの形(アプリのサーバーが画面のトークンをトークンの交換で替えたもの)
86
+ * - JWS のコンパクトな形。発行と検証はどちらも Tunasand だけで、署名の鍵は SECRETS_KEY からプロジェクトごとに HKDF で導く
87
+ * - 主体は人 ∩ インストールの能力。更新の資格はなく、続けるときは新しい画面のトークンで替え直す
88
+ */
89
+ export declare const ACCOUNT_TOKEN: {
90
+ readonly typ: "tunasand-account+jwt";
91
+ readonly alg: "HS256";
92
+ readonly ttlSec: 600;
93
+ };
94
+ /** アカウントの資格の API のトークンのクレーム(iss は発行した環境の CMS の URL、sub はアカウントの ID、aud はクライアントの ID、env は発行した環境の ID、時刻は秒) */
95
+ export type AccountTokenClaims = Readonly<{
96
+ iss: string;
97
+ sub: string;
98
+ aud: string;
99
+ env: string;
100
+ iat: number;
101
+ exp: number;
102
+ jti: string;
103
+ }>;
104
+ /**
105
+ * インストールのトークンのクレーム(iss はプロジェクトの配信の基点、sub はインストールの ID、aud はアプリの ID、ver はインストールのバージョン、時刻は秒)
106
+ * - env は発行した環境の ID。署名の鍵はプロジェクトの単位で、環境のコピーでインストールの ID もコピーされるので、環境はこのクレームで縛る
107
+ */
108
+ export type InstallationTokenClaims = Readonly<{
109
+ iss: string;
110
+ sub: string;
111
+ aud: string;
112
+ env: string;
113
+ iat: number;
114
+ exp: number;
115
+ jti: string;
116
+ ver: number | null;
117
+ }>;
@@ -0,0 +1,277 @@
1
+ import type { IssueSeverity } from './errors.js';
2
+ import type { ReadbackItem } from './migration.js';
3
+ /** 1回のリクエストで取り込む件数の上限(画像の取得の時間と、本文の大きさの上限 JSON_BODY_MAX のため) */
4
+ export declare const IMPORT_ITEMS_MAX = 50;
5
+ /** 1回のリクエストで取り込む人の数の上限(/api/transfer/customers) */
6
+ export declare const CUSTOMERS_IMPORT_MAX = 50;
7
+ /** 対応表の人の予約のコレクション(コレクションの id に使えない $ で始める) */
8
+ export declare const CUSTOMER_MAP_TYPE = "$customer";
9
+ /**
10
+ * 取り込む1件(fields は項目の key と値、source は報告に載せる元の位置: ファイルの行・元の CMS の ID など)
11
+ * - origin_id: 対応表を持つ取り込み(リクエストの origin)の元の ID
12
+ * 参照の項目は { "$origin": "<元の ID>" }、顧客フィールドは { "$customer": "<元の ID>" } で指せる(まとまりの中も)。元の ID は正規化しない
13
+ * - phase: コレクションどうしの循環のフェーズ(値の1は参照なしの下書きで作って2段目待ち、値の2は参照を足して元の状態に。なしは1回で)
14
+ * - originals: 元の HTML(項目の key ごと、取り込みのやり直しと写せなかった表現の対応の追加だけに使う)
15
+ * - created_at: 元の作成の日時(ISO 8601、時差つき)。作るときだけレコードの作成の日時に当て、更新では変えない
16
+ * - overwrite: 取り込みの後に画面で直した行も取り出し元の値で当てる(対応表を持つ取り込みだけ。本番では承認した申請の後だけ)
17
+ */
18
+ export type ImportItem = Readonly<{
19
+ collection: string;
20
+ id?: string;
21
+ fields: Readonly<Record<string, unknown>>;
22
+ source?: string;
23
+ origin_id?: string;
24
+ phase?: 1 | 2;
25
+ originals?: Readonly<Record<string, string>>;
26
+ created_at?: string;
27
+ overwrite?: true;
28
+ }>;
29
+ /**
30
+ * 取り込みの入力の形の行(JSON Lines の1行、kind は row。取り出し元ごとの読む側が出し、共通の取り込みが読む)
31
+ * - source は取り出し元、id は元の ID(正規化しない)、type はコレクションの id、fields は項目の値
32
+ * - 参照の項目は { "$origin": "<参照先のコレクションの元の ID>" }、顧客フィールドは { "$customer": "<人の元の ID>" }
33
+ * - new_id: 作るレコードの ID(元の ID を URL に保つ取り出し元。なしは自動の ID)
34
+ * - created_at: 元の作成の日時(作るときだけ当てる)
35
+ * - 人(kind は customer)は /api/transfer/customers の1人の形
36
+ */
37
+ export type ImportRowLine = Readonly<{
38
+ kind: 'row';
39
+ source: string;
40
+ id: string;
41
+ collection: string;
42
+ fields: Readonly<Record<string, unknown>>;
43
+ new_id?: string;
44
+ created_at?: string;
45
+ }>;
46
+ /** 参照の項目の値で、同じ取り出し元の元の ID を指す形の印({ "$origin": "<元の ID>" }) */
47
+ export declare const ORIGIN_REF = "$origin";
48
+ /** 顧客フィールドの値で、人の元の ID を指す形の印({ "$customer": "<元の ID>" }) */
49
+ export declare const CUSTOMER_REF = "$customer";
50
+ /** 元の ID を指す値の元の ID(印 marker の1つのキーで値が文字列、ほかは null) */
51
+ export declare function originIdOf(value: unknown, marker: string): string | null;
52
+ /**
53
+ * 取り込みの入力の形のレコード(kind は customer)。kind と source を除いた値が /api/transfer/customers の1人
54
+ * - identities は発行者の設定の id と外部 ID、grants は対象のコレクションと対象と期間
55
+ * - 権利の対象は行の ID か { "$origin": "<元の ID>" }、endsOn の省略は対象のコレクションの期間の規則で null は無期限
56
+ * - created_at は元の作成の日時(作るときだけ人の作成の日時に当てる)
57
+ */
58
+ export type ImportCustomerLine = Readonly<{
59
+ kind: 'customer';
60
+ source: string;
61
+ id: string;
62
+ status?: string;
63
+ identities?: readonly Readonly<{
64
+ provider: string;
65
+ subject: string;
66
+ }>[];
67
+ grants?: readonly Readonly<{
68
+ targetCollection: string;
69
+ target: string | Readonly<{
70
+ $origin: string;
71
+ }>;
72
+ startsOn: string;
73
+ endsOn?: string | null;
74
+ key?: string;
75
+ }>[];
76
+ created_at?: string;
77
+ }>;
78
+ /** 取り込みの入力の形の1行 */
79
+ export type ImportLine = ImportRowLine | ImportCustomerLine;
80
+ /** RFC 8785(JCS)の正規化した JSON(undefined の項目は除く。数は ECMAScript の表記で、JSON.stringify と同じ) */
81
+ export declare function canonicalJson(value: unknown): string;
82
+ /** 正規化した JSON の SHA-256(16進) */
83
+ export declare function canonicalHash(value: unknown): Promise<string>;
84
+ /** 元の ID を指す参照({ "$origin" })を除いた値(まとまりの中と配列の要素も。循環の1段目の項目) */
85
+ export declare function withoutOrigins(value: unknown): unknown;
86
+ /** 入力の形のレコードを取り込みの1件に(at は報告の位置、phase はコレクションどうしの循環のフェーズで、1段目は参照を除く) */
87
+ export declare const importItemOfRow: (line: ImportRowLine, at: string, phase?: 1 | 2) => ImportItem;
88
+ /** 取り込みの問題の種類 */
89
+ export declare const IMPORT_PROBLEMS: readonly ["unknown_collection", "forbidden", "invalid_id", "id_conflict", "duplicate_id", "unknown_field", "invalid_value", "image_failed", "markdown", "save_rejected", "reference_lowercased", "origin_missing", "map_conflict", "map_unavailable", "identity_taken"];
90
+ export type ImportProblemCode = (typeof IMPORT_PROBLEMS)[number];
91
+ /**
92
+ * 取り込みの問題(severity が error は取り込まない、warning は取り込んで報告、path は項目の key・まとまりの中はドットで連結)
93
+ * - code: 取り込みの問題の種類、message: 英語の文
94
+ * - problem・params: 検査の問題のコードと差し込み(画面は文言の表で引く、問題でない文はなし)
95
+ */
96
+ export type ImportProblem = Readonly<{
97
+ path: string;
98
+ code: ImportProblemCode;
99
+ message: string;
100
+ problem?: string;
101
+ params?: Readonly<Record<string, string | number>>;
102
+ severity: IssueSeverity;
103
+ }>;
104
+ /**
105
+ * 1件の結果(created は作成、ready はテスト実行で作成できる、skipped は問題で取り込まない)
106
+ * - unchanged は対応表のハッシュが同じで飛ばした、conflict は対応表と行が合わず書かない
107
+ */
108
+ export type ImportItemReport = Readonly<{
109
+ source: string;
110
+ collection: string;
111
+ id: string | null;
112
+ status: 'created' | 'updated' | 'ready' | 'skipped' | 'unchanged' | 'conflict';
113
+ issues: readonly ImportProblem[];
114
+ }>;
115
+ /** 画像の結果(checked はテスト実行で取得できた、asset は保存した画像の ID) */
116
+ export type ImportImage = Readonly<{
117
+ url: string;
118
+ status: 'imported' | 'existing' | 'checked' | 'failed';
119
+ asset: string | null;
120
+ message: string | null;
121
+ }>;
122
+ /** 小文字に変換した ID(paths はコレクションのページの旧と新のパス、ページのないコレクションは null) */
123
+ export type ImportIdChange = Readonly<{
124
+ collection: string;
125
+ from: string;
126
+ to: string;
127
+ source: string;
128
+ paths: Readonly<{
129
+ from: string;
130
+ to: string;
131
+ }> | null;
132
+ }>;
133
+ /** 変換でぶつかる ID(ids は元の ID、existing は変換後の ID のレコードがすでにある) */
134
+ export type ImportIdConflict = Readonly<{
135
+ collection: string;
136
+ id: string;
137
+ ids: readonly string[];
138
+ sources: readonly string[];
139
+ existing: boolean;
140
+ }>;
141
+ /** 取り込みの報告 */
142
+ export type ImportReport = Readonly<{
143
+ dryRun: boolean;
144
+ summary: Readonly<{
145
+ items: number;
146
+ created: number;
147
+ updated: number;
148
+ ready: number;
149
+ skipped: number;
150
+ unchanged: number;
151
+ conflict: number;
152
+ images: Readonly<Record<ImportImage['status'], number>>;
153
+ }>;
154
+ items: readonly ImportItemReport[];
155
+ images: readonly ImportImage[];
156
+ idChanges: readonly ImportIdChange[];
157
+ idConflicts: readonly ImportIdConflict[];
158
+ /** 上限を超えて残さなかった元の HTML(レコードの ID と項目の key) */
159
+ originalsTooLarge?: readonly Readonly<{
160
+ id: string;
161
+ field: string;
162
+ }>[];
163
+ }>;
164
+ /** 取り込む ID(前後の空白を除き小文字に、changed は大文字を含んでいた) */
165
+ export declare function importIdOf(raw: string): Readonly<{
166
+ id: string;
167
+ changed: boolean;
168
+ }>;
169
+ /** 入力の中の ID の計画(conflicts は大文字と小文字の違いだけでぶつかる組み合わせ、duplicates は同じ ID が複数、どちらも位置 index の集合で除外) */
170
+ export type ImportIdPlan = Readonly<{
171
+ conflicts: readonly ImportIdConflict[];
172
+ excluded: ReadonlySet<number>;
173
+ duplicates: ReadonlySet<number>;
174
+ }>;
175
+ /** 入力の中で ID がぶつかるレコード(コレクションごと、ID のないレコードは自動の ID で対象外) */
176
+ export declare function planImportIds(items: readonly ImportItem[]): ImportIdPlan;
177
+ /** 報告に載せる元の位置(指定がなければ入力の何件目か) */
178
+ export declare const sourceOf: (item: ImportItem, index: number) => string;
179
+ /** 件数を数え直した報告 */
180
+ export declare function importReportOf(dryRun: boolean, parts: Omit<ImportReport, 'dryRun' | 'summary'>): ImportReport;
181
+ /** 分けて送った取り込みの報告を1つに(同じ URL の画像は先の結果) */
182
+ export declare function mergeImportReports(dryRun: boolean, reports: readonly ImportReport[], extra?: Partial<Omit<ImportReport, 'dryRun' | 'summary'>>): ImportReport;
183
+ /** 関係でつながる API(endpoint と、関係の項目の fieldId から先のエンドポイント) */
184
+ type RelatedApi = Readonly<{
185
+ endpoint: string;
186
+ relations: Readonly<Record<string, string>>;
187
+ }>;
188
+ /** 関係の先を先にした取り込みの順(循環は残りをそのままの順) */
189
+ export declare function importOrderOf<A extends RelatedApi>(apis: readonly A[]): A[];
190
+ /** 関係が循環する API のエンドポイント(関係をたどって自分に戻る、自分への関係を含む。参照なしと参照ありの2フェーズで取り込む) */
191
+ export declare function cyclicCollections(apis: readonly RelatedApi[]): Set<string>;
192
+ /** microCMS から取り込む API(schema は API のスキーマの JSON、relations は関係の項目の fieldId と先のエンドポイント) */
193
+ export type MicroCmsApiInput = Readonly<{
194
+ endpoint: string;
195
+ label: string;
196
+ format: 'list' | 'object';
197
+ schema: unknown;
198
+ relations: Readonly<Record<string, string>>;
199
+ privateMedia?: boolean;
200
+ }>;
201
+ /** 移行元の変換の注意(path はコレクションの id と項目、code・params はアプリの問題の表のコードと差し込み、message は英語の文) */
202
+ export type SourceNote = Readonly<{
203
+ path: string;
204
+ code?: string;
205
+ params?: Readonly<Record<string, string | number>>;
206
+ message: string;
207
+ severity: IssueSeverity;
208
+ }>;
209
+ /** 本文の変換で捨てたもの(what は要素・属性・style の項目・class) */
210
+ export type SourceDropped = Readonly<{
211
+ what: string;
212
+ count: number;
213
+ }>;
214
+ /** 本文の変換で捨てたものの記事と項目ごとの内訳(id は microCMS のレコードの ID、field は本文の項目の key) */
215
+ export type SourceDroppedRow = SourceDropped & Readonly<{
216
+ id: string;
217
+ field: string;
218
+ }>;
219
+ /**
220
+ * microCMS のコンテンツの1ページの取り込みの結果(source は対応表の取り出し元)
221
+ * - next は次のページの offset、なしは終わり、dropped は捨てたものの合計、droppedRows は記事と項目ごと、tooLarge は大きすぎて残さなかった元の HTML
222
+ */
223
+ export type SourceContentResult = Readonly<{
224
+ source: string;
225
+ report: ImportReport;
226
+ total: number;
227
+ next: number | null;
228
+ dropped: readonly SourceDropped[];
229
+ droppedRows: readonly SourceDroppedRow[];
230
+ tooLarge: readonly Readonly<{
231
+ id: string;
232
+ field: string;
233
+ }>[];
234
+ }>;
235
+ /** microCMS のコンテンツの1ページの入力の形のレコード(書き込まない。next は次のページの offset、なしは終わり) */
236
+ export type SourceLinesResult = Readonly<{
237
+ lines: readonly ImportRowLine[];
238
+ total: number;
239
+ next: number | null;
240
+ dropped: readonly SourceDropped[];
241
+ }>;
242
+ /**
243
+ * microCMS のコンテンツの1ページの検証の結果(書き込まない)
244
+ * - source は対応表の取り出し元、type は取り込み先のコレクション、next は次のページの offset でなしは終わり
245
+ * - rerun: 同じページをもう一度取り込むとどうなるか(テスト実行)。changed は unchanged でない行(位置、新しい ID、状態)
246
+ * - readback: 保存したレコードの読み戻し。problems は match でないレコード(位置、コレクション、新しい ID、状態、項目の道)
247
+ * - 元の ID と項目の値を含めない
248
+ */
249
+ export type SourceVerifyResult = Readonly<{
250
+ source: string;
251
+ collection: string;
252
+ total: number;
253
+ next: number | null;
254
+ rerun: Readonly<{
255
+ unchanged: number;
256
+ changed: readonly Readonly<{
257
+ source: string;
258
+ id: string | null;
259
+ status: ImportItemReport['status'];
260
+ }>[];
261
+ }>;
262
+ readback: Readonly<{
263
+ match: number;
264
+ problems: readonly ReadbackItem[];
265
+ }>;
266
+ }>;
267
+ /** 取り込みのイベント(Webhook の名前。対応表を持つ取り込みの実行の完了を1件だけ知らせ、レコードごとの変更のイベントは送らない) */
268
+ export declare const IMPORT_EVENTS: {
269
+ readonly completed: "import.completed";
270
+ };
271
+ /** 取り込みの完了のイベントの値(runId は実行の ID、source は取り出し元、rows はこの実行が対応表に書いた行のコレクションごとの数で、飛ばしたレコードは数えない) */
272
+ export type ImportCompletedData = Readonly<{
273
+ runId: string;
274
+ source: string;
275
+ rows: Readonly<Record<string, number>>;
276
+ }>;
277
+ export {};