@tunasand/sdk 0.6.0 → 0.8.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 (186) hide show
  1. package/CHANGELOG.md +116 -84
  2. package/README.md +209 -195
  3. package/dist/analytics.js +638 -2
  4. package/dist/app.js +230 -24
  5. package/dist/apps-BxnJ1RlU.js +435 -0
  6. package/dist/{bridge-DYAYGV7t.js → bridge-DtHw9hS6.js} +3 -3
  7. package/dist/bridge.js +2 -2
  8. package/dist/cli.js +5 -4
  9. package/dist/{model-pmXzGX12.js → collection-BEOxeISR.js} +49 -12
  10. package/dist/{customers-C_vJY2_v.js → customers-DTbL0qn6.js} +5 -3
  11. package/dist/customers.js +2 -2
  12. package/dist/{declared-C_GvPiGF.js → declared-DuNMsdXw.js} +93 -5
  13. package/dist/delivery.js +39 -8
  14. package/dist/embeds-B5V54Zur.js +34 -0
  15. package/dist/{errorLabels-BcyRbv_i.js → errorLabels-BgtQ_zUn.js} +277 -264
  16. package/dist/i18n.js +4 -4
  17. package/dist/ids--RF7hGyC.js +36 -0
  18. package/dist/integrations.js +4 -29
  19. package/dist/{ja-C1HEWWTQ.js → ja-CeHU0EaY.js} +3 -3
  20. package/dist/{ja-C6lX0CeJ.js → ja-Du6ooL6i.js} +12 -11
  21. package/dist/{page-E_cYgZx-.js → page-Bzrj24sJ.js} +4 -4
  22. package/dist/{profile-D6t1QMQh.js → profile-1em_lcxq.js} +5 -5
  23. package/dist/rich-text.d.ts +1 -0
  24. package/dist/{body.js → rich-text.js} +6 -7
  25. package/dist/{schema-UQJWRyfJ.js → schema-WnobuwLg.js} +136 -97
  26. package/dist/schema.js +346 -1
  27. package/dist/types/access/src/handoff.d.ts +3 -3
  28. package/dist/types/access/src/jwt.d.ts +1 -1
  29. package/dist/types/access/src/oidc.d.ts +1 -1
  30. package/dist/types/{cms-contract → contract}/src/apiKeys.d.ts +1 -1
  31. package/dist/types/{cms-contract → contract}/src/app.d.ts +8 -15
  32. package/dist/types/contract/src/appDefinition.d.ts +127 -0
  33. package/dist/types/{cms-contract → contract}/src/appDependencies.d.ts +6 -13
  34. package/dist/types/contract/src/appServer.d.ts +136 -0
  35. package/dist/types/contract/src/approvalLabels.d.ts +26 -0
  36. package/dist/types/contract/src/approvals.d.ts +63 -0
  37. package/dist/types/{cms-contract → contract}/src/apps.d.ts +72 -29
  38. package/dist/types/contract/src/auditActions.d.ts +18 -0
  39. package/dist/types/contract/src/auditLabels.d.ts +127 -0
  40. package/dist/types/{cms-contract → contract}/src/authorize.d.ts +22 -63
  41. package/dist/types/{cms-contract → contract}/src/bridge.d.ts +6 -6
  42. package/dist/types/{cms-contract → contract}/src/customers.d.ts +6 -6
  43. package/dist/types/{cms-contract → contract}/src/embeds.d.ts +13 -7
  44. package/dist/types/{cms-contract → contract}/src/errorLabels.d.ts +18 -16
  45. package/dist/types/{cms-contract → contract}/src/errorLabelsEn.d.ts +9 -7
  46. package/dist/types/{cms-contract → contract}/src/errors.d.ts +11 -11
  47. package/dist/types/{cms-contract → contract}/src/failureStatus.d.ts +4 -3
  48. package/dist/types/contract/src/fieldAccess.d.ts +45 -0
  49. package/dist/types/contract/src/fieldRules.d.ts +41 -0
  50. package/dist/types/{cms-contract/src/assets.d.ts → contract/src/files.d.ts} +5 -5
  51. package/dist/types/{cms-contract → contract}/src/functions.d.ts +3 -3
  52. package/dist/types/contract/src/hostingRpc.d.ts +143 -0
  53. package/dist/types/contract/src/hostnames.d.ts +30 -0
  54. package/dist/types/{cms-contract → contract}/src/identifiers.d.ts +31 -28
  55. package/dist/types/contract/src/ids.d.ts +104 -0
  56. package/dist/types/{cms-contract → contract}/src/import.d.ts +3 -3
  57. package/dist/types/contract/src/importLabels.d.ts +3 -0
  58. package/dist/types/contract/src/index.d.ts +67 -0
  59. package/dist/types/{cms-contract → contract}/src/issueLabels.d.ts +27 -23
  60. package/dist/types/{cms-contract → contract}/src/issueLabelsEn.d.ts +15 -13
  61. package/dist/types/contract/src/labels.d.ts +11 -0
  62. package/dist/types/contract/src/legacyAuditLabels.d.ts +10 -0
  63. package/dist/types/contract/src/livePeriods.d.ts +18 -0
  64. package/dist/types/contract/src/manage.d.ts +47 -0
  65. package/dist/types/contract/src/manageLabels.d.ts +9 -0
  66. package/dist/types/contract/src/mcpAuth.d.ts +139 -0
  67. package/dist/types/contract/src/mcpLabels.d.ts +5 -0
  68. package/dist/types/{cms-contract → contract}/src/migration.d.ts +1 -1
  69. package/dist/types/contract/src/operatorOperations.d.ts +703 -0
  70. package/dist/types/contract/src/operators.d.ts +33 -0
  71. package/dist/types/{cms-contract → contract}/src/paths.d.ts +6 -8
  72. package/dist/types/contract/src/pending.d.ts +4 -0
  73. package/dist/types/{cms-contract → contract}/src/permissions.d.ts +2 -0
  74. package/dist/types/contract/src/principal.d.ts +110 -0
  75. package/dist/types/{cms-contract → contract}/src/problems.d.ts +4 -4
  76. package/dist/types/contract/src/projectRole.d.ts +6 -0
  77. package/dist/types/{cms-contract → contract}/src/roles.d.ts +4 -3
  78. package/dist/types/{cms-contract → contract}/src/settingProblems.d.ts +2 -2
  79. package/dist/types/{cms-contract → contract}/src/settings.d.ts +2 -2
  80. package/dist/types/contract/src/settingsLabels.d.ts +3 -0
  81. package/dist/types/contract/src/slugs.d.ts +6 -0
  82. package/dist/types/{cms-contract → contract}/src/transfer.d.ts +3 -3
  83. package/dist/types/contract/src/trial.d.ts +10 -0
  84. package/dist/types/contract/src/versions.d.ts +9 -0
  85. package/dist/types/{cms-contract → contract}/src/webhooks.d.ts +33 -58
  86. package/dist/types/contract/src/workflow.d.ts +49 -0
  87. package/dist/types/contract/src/workspaceItems.d.ts +73 -0
  88. package/dist/types/contract/src/workspacePaths.d.ts +4 -0
  89. package/dist/types/{body → rich-text}/src/declared.d.ts +2 -2
  90. package/dist/types/{body → rich-text}/src/embed.d.ts +1 -1
  91. package/dist/types/{body → rich-text}/src/labels/ja.d.ts +2 -2
  92. package/dist/types/{body → rich-text}/src/profile.d.ts +1 -1
  93. package/dist/types/{model → schema}/src/audience.d.ts +11 -11
  94. package/dist/types/schema/src/brand.d.ts +5 -0
  95. package/dist/types/{model → schema}/src/capabilities.d.ts +5 -5
  96. package/dist/types/{model → schema}/src/changes.d.ts +6 -6
  97. package/dist/types/{model → schema}/src/check.d.ts +2 -2
  98. package/dist/types/{model/src/model.d.ts → schema/src/collection.d.ts} +25 -23
  99. package/dist/types/{platform/src/defaultModel.d.ts → schema/src/defaultSchema.d.ts} +4 -3
  100. package/dist/types/{model/src/asset.d.ts → schema/src/file.d.ts} +16 -16
  101. package/dist/types/{model → schema}/src/image.d.ts +3 -3
  102. package/dist/types/{model → schema}/src/index.d.ts +11 -10
  103. package/dist/types/{model → schema}/src/input.d.ts +3 -3
  104. package/dist/types/{model → schema}/src/integrity.d.ts +1 -1
  105. package/dist/types/{model → schema}/src/labels/en.d.ts +8 -7
  106. package/dist/types/{model → schema}/src/labels/ja.d.ts +9 -8
  107. package/dist/types/schema/src/legacy.d.ts +2 -0
  108. package/dist/types/{model → schema}/src/media.d.ts +1 -1
  109. package/dist/types/{model → schema}/src/mediaUrl.d.ts +5 -5
  110. package/dist/types/{model → schema}/src/page.d.ts +2 -2
  111. package/dist/types/{model → schema}/src/problems.d.ts +14 -13
  112. package/dist/types/{model → schema}/src/refs.d.ts +1 -1
  113. package/dist/types/{model → schema}/src/rules.d.ts +2 -2
  114. package/dist/types/{model → schema}/src/schema.d.ts +10 -10
  115. package/dist/types/{model → schema}/src/selfOps.d.ts +1 -1
  116. package/dist/types/schema/src/typesSource.d.ts +16 -0
  117. package/dist/types/{model → schema}/src/values.d.ts +2 -2
  118. package/dist/types/sdk/src/analytics.d.ts +2 -2
  119. package/dist/types/sdk/src/app.d.ts +44 -16
  120. package/dist/types/sdk/src/bridge.d.ts +12 -12
  121. package/dist/types/sdk/src/customers.d.ts +14 -20
  122. package/dist/types/sdk/src/delegation.d.ts +39 -0
  123. package/dist/types/sdk/src/delivery/client.d.ts +11 -10
  124. package/dist/types/sdk/src/delivery/fields.d.ts +2 -2
  125. package/dist/types/sdk/src/delivery/index.d.ts +2 -2
  126. package/dist/types/sdk/src/delivery/media.d.ts +17 -3
  127. package/dist/types/sdk/src/delivery/query.d.ts +1 -1
  128. package/dist/types/sdk/src/delivery/schema.d.ts +4 -4
  129. package/dist/types/sdk/src/delivery/values.d.ts +6 -6
  130. package/dist/types/sdk/src/delivery.d.ts +3 -3
  131. package/dist/types/sdk/src/i18n.d.ts +11 -11
  132. package/dist/types/sdk/src/integrations.d.ts +10 -10
  133. package/dist/types/sdk/src/{body.d.ts → rich-text.d.ts} +2 -2
  134. package/dist/types/sdk/src/schema.d.ts +5 -21
  135. package/dist/types/sdk/src/site.d.ts +1 -1
  136. package/dist/types/sdk/src/types.d.ts +21 -0
  137. package/dist/{schema-BPHL7Qr-.js → types-B77qvqPJ.js} +5 -4
  138. package/dist/types.d.ts +1 -0
  139. package/dist/types.js +1 -0
  140. package/dist/{typesSource-bO0jFw1I.js → typesSource-CWybQYus.js} +58 -12
  141. package/package.json +12 -12
  142. package/dist/apps-9u4XMi7E.js +0 -114
  143. package/dist/body.d.ts +0 -1
  144. package/dist/embed-R-OvDYAw.js +0 -90
  145. package/dist/model.d.ts +0 -1
  146. package/dist/model.js +0 -345
  147. package/dist/types/analytics/src/index.d.ts +0 -5
  148. package/dist/types/analytics/src/schedule.d.ts +0 -2
  149. package/dist/types/analytics/src/shared.d.ts +0 -21
  150. package/dist/types/analytics/src/source.d.ts +0 -19
  151. package/dist/types/analytics/src/store.d.ts +0 -24
  152. package/dist/types/model/src/brand.d.ts +0 -25
  153. package/dist/types/model/src/legacy.d.ts +0 -2
  154. package/dist/types/model/src/typesSource.d.ts +0 -8
  155. package/dist/types/sdk/src/model.d.ts +0 -5
  156. /package/dist/types/{cms-contract → contract}/src/appProblems.d.ts +0 -0
  157. /package/dist/types/{cms-contract → contract}/src/consents.d.ts +0 -0
  158. /package/dist/types/{cms-contract → contract}/src/customerLabels.d.ts +0 -0
  159. /package/dist/types/{analytics → contract}/src/day.d.ts +0 -0
  160. /package/dist/types/{cms-contract → contract}/src/functionLabels.d.ts +0 -0
  161. /package/dist/types/{cms-contract → contract}/src/permissionLabels.d.ts +0 -0
  162. /package/dist/types/{cms-contract → contract}/src/siteArtifact.d.ts +0 -0
  163. /package/dist/types/{cms-contract → contract}/src/siteDeclaration.d.ts +0 -0
  164. /package/dist/types/{analytics/src/view.d.ts → contract/src/viewEvent.d.ts} +0 -0
  165. /package/dist/types/{cms-contract → contract}/src/views.d.ts +0 -0
  166. /package/dist/types/{cms-contract → contract}/src/webhookLabels.d.ts +0 -0
  167. /package/dist/types/{body → rich-text}/src/components.d.ts +0 -0
  168. /package/dist/types/{body → rich-text}/src/derive.d.ts +0 -0
  169. /package/dist/types/{body → rich-text}/src/description.d.ts +0 -0
  170. /package/dist/types/{body → rich-text}/src/href.d.ts +0 -0
  171. /package/dist/types/{body → rich-text}/src/html.d.ts +0 -0
  172. /package/dist/types/{body → rich-text}/src/index.d.ts +0 -0
  173. /package/dist/types/{body → rich-text}/src/inline.d.ts +0 -0
  174. /package/dist/types/{body → rich-text}/src/labels/en.d.ts +0 -0
  175. /package/dist/types/{body → rich-text}/src/library.d.ts +0 -0
  176. /package/dist/types/{body → rich-text}/src/markdown.d.ts +0 -0
  177. /package/dist/types/{body → rich-text}/src/normalize.d.ts +0 -0
  178. /package/dist/types/{body → rich-text}/src/problems.d.ts +0 -0
  179. /package/dist/types/{body → rich-text}/src/render.d.ts +0 -0
  180. /package/dist/types/{body → rich-text}/src/schema.d.ts +0 -0
  181. /package/dist/types/{body → rich-text}/src/standard.d.ts +0 -0
  182. /package/dist/types/{body → rich-text}/src/types.d.ts +0 -0
  183. /package/dist/types/{model → schema}/src/contact.d.ts +0 -0
  184. /package/dist/types/{model → schema}/src/json.d.ts +0 -0
  185. /package/dist/types/{model → schema}/src/screens.d.ts +0 -0
  186. /package/dist/types/{model → schema}/src/time.d.ts +0 -0
@@ -0,0 +1,435 @@
1
+ import { c as selfOpsOf, n as fieldDefSchema, t as RESERVED_FIELD_KEYS } from "./schema-WnobuwLg.js";
2
+ import { t as CUSTOMERS_KEY_TARGET } from "./customers-DTbL0qn6.js";
3
+ import { z } from "zod";
4
+ // ../contract/src/appDependencies.ts
5
+ /** 宣言の上限(計画のノードの数は一括の大きさを抑えるため。全部か無しなので分けられない) */
6
+ const APP_DEPENDENCY_LIMITS = {
7
+ entriesMax: 100,
8
+ textMax: 500,
9
+ planNodesMax: 20
10
+ };
11
+ [...RESERVED_FIELD_KEYS];
12
+ const PORT_ID = /^[a-z][a-z0-9-]{0,31}:[a-z][a-z0-9_-]{0,63}@[1-9]\d{0,3}$/;
13
+ const SETTING_KEY = /^[a-z][a-zA-Z0-9_]{0,63}(\.[a-z][a-zA-Z0-9_]{0,63}){0,3}$/;
14
+ const COLLECTION_NAME = /^[a-z][a-z0-9_-]{0,63}$/;
15
+ const settingKey = z.string().regex(SETTING_KEY);
16
+ const settingValue = z.union([
17
+ z.boolean(),
18
+ z.string().max(APP_DEPENDENCY_LIMITS.textMax),
19
+ z.number()
20
+ ]);
21
+ const list = (item) => z.array(item).max(APP_DEPENDENCY_LIMITS.entriesMax);
22
+ const label = z.string().trim().min(1).max(80);
23
+ const yen = z.number().int().nonnegative();
24
+ const dependencySchema = z.strictObject({
25
+ app: z.string().min(1).max(64),
26
+ kind: z.enum(["required", "optional"]),
27
+ major: z.number().int().positive(),
28
+ minVersion: z.number().int().positive().optional(),
29
+ defaults: z.record(settingKey, settingValue).optional(),
30
+ expose: list(settingKey).optional()
31
+ });
32
+ const settingSchema = z.strictObject({
33
+ key: settingKey,
34
+ label,
35
+ type: z.enum([
36
+ "boolean",
37
+ "text",
38
+ "number",
39
+ "select"
40
+ ]),
41
+ options: list(z.string().min(1).max(80)).min(1).optional(),
42
+ default: settingValue.optional(),
43
+ requires: z.string().min(1).max(64).optional(),
44
+ min: z.number().optional(),
45
+ unit: z.string().min(1).max(20).optional()
46
+ }).refine((s) => s.type === "select" === (s.options !== void 0), { path: ["options"] }).refine((s) => s.default === void 0 || (s.type === "select" ? s.options?.includes(String(s.default)) : typeof s.default === (s.type === "text" ? "string" : s.type)), { path: ["default"] });
47
+ const collectionSchema = z.strictObject({
48
+ name: z.string().regex(COLLECTION_NAME),
49
+ label,
50
+ internal: z.boolean().optional(),
51
+ private: z.boolean().optional(),
52
+ fields: list(fieldDefSchema)
53
+ });
54
+ z.object({
55
+ major: z.number().int().positive().optional(),
56
+ requires: list(dependencySchema).optional(),
57
+ uses: list(z.strictObject({
58
+ port: z.string().regex(PORT_ID),
59
+ required: z.boolean()
60
+ })).optional(),
61
+ provides: list(z.strictObject({
62
+ port: z.string().regex(PORT_ID),
63
+ route: z.string().startsWith("/api/").max(2048)
64
+ })).optional(),
65
+ collections: list(collectionSchema).optional(),
66
+ settings: list(settingSchema).optional(),
67
+ price: z.strictObject({
68
+ setup: yen.optional(),
69
+ monthly: yen.optional(),
70
+ usage: z.string().trim().min(1).max(APP_DEPENDENCY_LIMITS.textMax).optional(),
71
+ currency: z.literal("JPY")
72
+ }).optional()
73
+ });
74
+ // ../contract/src/principal.ts
75
+ /** 管理者のロールの ID(roles.ts の ADMIN_ROLE と同じ値、循環の import を避けて持つ) */
76
+ const ADMIN_ROLE_ID = "admin";
77
+ /** 判定で主体を絞る種類(顧客の操作の選べる主体と、判定の観測) */
78
+ const actingKindOf = (principal) => {
79
+ if (principal.effective.form === "capabilities") return principal.chain.length > 0 ? "on_behalf_of_customer" : "installation";
80
+ return principal.chain.length > 0 ? "on_behalf_of_account" : "account";
81
+ };
82
+ /** 主体の文脈のアカウントの代理(なければ null) */
83
+ const accountDelegationOf = (principal) => principal.effective.form === "roles" ? principal.chain[0] ?? null : null;
84
+ /** 主体の文脈の顧客の代理(なければ null) */
85
+ const customerOf = (principal) => principal.effective.form === "capabilities" ? principal.chain[0] ?? null : null;
86
+ /** ログインしたアカウントの要求の認証情報の種類(アプリのアカウントのトークン、MCP の接続、ログインのセッション) */
87
+ const viaOfUser = (user) => user.app ? "account_token" : user.mcp ? "mcp" : "session";
88
+ /** ログインしたアカウントの主体の文脈(アプリのアカウントの資格と MCP の接続はアカウントの代理で、委ねた能力の外では管理者として扱わない。運営者はアカウントと同じ) */
89
+ function principalOfUser(user) {
90
+ const delegation = user.app ? {
91
+ kind: "app",
92
+ installationId: user.app.installation,
93
+ capabilities: user.app.capabilities,
94
+ consented: user.app.consented ?? user.app.capabilities
95
+ } : user.mcp ? {
96
+ kind: "mcp_client",
97
+ capabilities: user.mcp.capabilities,
98
+ staffCollections: user.mcp.staffCollections
99
+ } : null;
100
+ return {
101
+ account: {
102
+ kind: "person",
103
+ id: user.id ?? ""
104
+ },
105
+ effective: {
106
+ form: "roles",
107
+ permissions: user.permissions,
108
+ admin: user.role === ADMIN_ROLE_ID
109
+ },
110
+ chain: delegation ? [delegation] : [],
111
+ via: viaOfUser(user)
112
+ };
113
+ }
114
+ // ../contract/src/authorize.ts
115
+ /** 判定の操作(コレクションの操作と顧客の操作) */
116
+ const OPERATIONS = [
117
+ "read",
118
+ "read_drafts",
119
+ "read_customers",
120
+ "create",
121
+ "update",
122
+ "publish",
123
+ "delete",
124
+ "submit",
125
+ "verify",
126
+ "read_state",
127
+ "link",
128
+ "create_candidate",
129
+ "issue_token",
130
+ "refresh_token",
131
+ "migrate_links",
132
+ "read_identities",
133
+ "write_grants",
134
+ "update_status",
135
+ "read_display_name",
136
+ "read_consents",
137
+ "check_consent",
138
+ "write_consents",
139
+ "write_suppression",
140
+ "read_self",
141
+ "create_self",
142
+ "update_self",
143
+ "delete_self"
144
+ ];
145
+ /** 鍵の別名 verify_customers がまとめる顧客の操作 */
146
+ const VERIFY_CUSTOMERS_COVERS = [
147
+ "verify",
148
+ "read_state",
149
+ "link",
150
+ "create_candidate"
151
+ ];
152
+ /** ロールの操作(コレクションと顧客の操作から、ロールの表の操作へ) */
153
+ const ROLE_ACTION_OF = {
154
+ read: "read",
155
+ read_drafts: "read",
156
+ read_customers: "read",
157
+ create: "create",
158
+ update: "update",
159
+ publish: "publish",
160
+ delete: "delete",
161
+ submit: "create",
162
+ verify: "read",
163
+ read_state: "read",
164
+ link: "update",
165
+ create_candidate: "create",
166
+ issue_token: "read",
167
+ refresh_token: "read",
168
+ migrate_links: "update",
169
+ read_identities: "read",
170
+ write_grants: "update",
171
+ update_status: "update",
172
+ read_display_name: "read",
173
+ read_consents: "read",
174
+ check_consent: "read",
175
+ write_consents: "update",
176
+ write_suppression: "update",
177
+ read_self: "read",
178
+ create_self: "create",
179
+ update_self: "update",
180
+ delete_self: "delete"
181
+ };
182
+ /** 顧客の操作の選べる主体(#606、D3-1。表にない操作は主体で絞らない。運営者はアカウントと同じ) */
183
+ const CUSTOMERS_PRINCIPALS = {
184
+ create: ["account", "installation"],
185
+ create_candidate: ["account", "installation"],
186
+ read_consents: [
187
+ "account",
188
+ "installation",
189
+ "on_behalf_of_account"
190
+ ],
191
+ check_consent: ["installation"],
192
+ write_consents: [
193
+ "account",
194
+ "installation",
195
+ "on_behalf_of_customer"
196
+ ],
197
+ write_suppression: ["account", "installation"]
198
+ };
199
+ /** 人の代わりにコレクションを問わず許す操作か(コレクションの read と read_customers、顧客の write_consents) */
200
+ const customerScopeAllows = (target, operation) => operation === "read" || operation === "read_customers" || target === "@customers" && operation === "write_consents";
201
+ /** 人の代わりだけの操作(コレクションの宣言 selfOps の操作) */
202
+ const SELF_OPERATIONS = [
203
+ "read_self",
204
+ "create_self",
205
+ "update_self",
206
+ "delete_self"
207
+ ];
208
+ /** 本人のレコード(顧客フィールドの印 `self` が本人を指すレコード)の操作(レコードの値の self が要る) */
209
+ const ROW_OPERATIONS = [
210
+ "read_self",
211
+ "update_self",
212
+ "delete_self"
213
+ ];
214
+ /** コレクションごとに受けるかが決まる人の代わりの操作(宣言の操作とエンドポイントの submit) */
215
+ const CUSTOMER_TYPE_OPERATIONS = [...SELF_OPERATIONS, "submit"];
216
+ /** コレクションを名指しした能力の操作(* と別名を当てない) */
217
+ const namedOpsOf = (capabilities, target) => target !== "*" && Object.hasOwn(capabilities, target) ? capabilities[target] : [];
218
+ /**
219
+ * 人の代わりのコレクションの人の操作の判定(row は行の値、null はレコードを読む前の authorizeReach)
220
+ * - コレクション type が target でない・渡らない、コレクションが本人の確認の方法で受けない操作は customer_scope
221
+ * - read_self・update_self・delete_self は本人のレコードだけ(self が渡らなければ拒む)
222
+ */
223
+ function byCustomerOperation(principal, target, operation, collection, row) {
224
+ if (!collection || collection.id !== target || !selfOpsOf(collection, principal.proof).includes(operation)) return deny("customer_scope", "not_found");
225
+ if (row && ROW_OPERATIONS.includes(operation) && row.self !== true) return deny("row_owner", "not_found");
226
+ if (operation === "submit" && principal.proof === "id_token") return byCapabilities(principal.capabilities, target, operation);
227
+ return namedOpsOf(principal.capabilities, target).includes(operation) ? allow : deny("not_permitted");
228
+ }
229
+ /** 能力の別名(顧客の create_candidate と create は互いに満たす) */
230
+ const CUSTOMERS_ALIASES = {
231
+ create: "create_candidate",
232
+ create_candidate: "create"
233
+ };
234
+ /** アカウントだけの対象か(設定の領域 settings:<領域> と管理の権限 manage:<チェック>。* を当てず、明示した行だけ) */
235
+ const isSettings = (target) => target.startsWith("settings:") || target.startsWith("manage:");
236
+ /** 設定の領域と管理の権限の委ねた操作か(* を当てず、対象を名指しした能力だけ) */
237
+ const settingsDelegated = (capabilities, target, operation) => Object.hasOwn(capabilities, target) && capabilities[target].includes(operation);
238
+ const allow = { allowed: true };
239
+ const deny = (cause, reason = "forbidden") => ({
240
+ allowed: false,
241
+ reason,
242
+ cause
243
+ });
244
+ /** 権限が足りない拒否に、足りない操作を付ける(応答の params.required と画面が必要なロールを引く) */
245
+ const withRequired = (decision, operation) => !decision.allowed && decision.reason === "forbidden" ? {
246
+ ...decision,
247
+ required: { operation }
248
+ } : decision;
249
+ /** ロールの表の段階(すべての対象の * は鍵の API_KEY_ALL_TYPES と同じ値。設定の領域には * を当てず、明示した行だけ) */
250
+ const levelIn = (permissions, target, action) => permissions[target]?.[action] ?? (isSettings(target) ? void 0 : permissions["*"]?.[action]) ?? "none";
251
+ /** ロールの段階での判定(own は持ち主のレコードだけ) */
252
+ function byRole(permissions, target, action, owned) {
253
+ const level = levelIn(permissions, target, action);
254
+ if (level === "all") return allow;
255
+ if (level === "own") return owned ? allow : deny("row_owner");
256
+ return deny("not_permitted");
257
+ }
258
+ /** 鍵の能力での判定(read は read_drafts でも満たす、verify_customers は別名) */
259
+ function byCapabilities(capabilities, target, operation) {
260
+ const ops = [...Object.hasOwn(capabilities, target) ? capabilities[target] : [], ...Object.hasOwn(capabilities, "*") ? capabilities["*"] : []];
261
+ if (ops.includes(operation) || operation === "read" && ops.includes("read_drafts")) return allow;
262
+ const alias = "verify_customers";
263
+ const selfOps = Object.hasOwn(capabilities, "@customers") ? capabilities[CUSTOMERS_KEY_TARGET] : [];
264
+ if (target === "@customers" && ops.includes(alias) && VERIFY_CUSTOMERS_COVERS.includes(operation)) return allow;
265
+ const customersAlias = target === "@customers" ? CUSTOMERS_ALIASES[operation] : void 0;
266
+ if (customersAlias && ops.includes(customersAlias)) return allow;
267
+ if (operation === "submit" && (ops.includes(alias) || selfOps.includes(alias))) return allow;
268
+ return deny("not_permitted");
269
+ }
270
+ /** 行やロールの段階より前の判定(null はロールの段階へ進む、row の null は行を読む前の authorizeReach) */
271
+ function decideBeforeRole(principal, target, operation, collection, row) {
272
+ const kinds = target === "@customers" ? CUSTOMERS_PRINCIPALS[operation] : void 0;
273
+ const customer = customerOf(principal);
274
+ if (SELF_OPERATIONS.includes(operation) && !customer) return deny("principal_kind");
275
+ if (principal.effective.form === "capabilities") {
276
+ if (isSettings(target)) return deny("humans_only");
277
+ if (customer && target !== "@customers" && CUSTOMER_TYPE_OPERATIONS.includes(operation)) return byCustomerOperation(customer, target, operation, collection, row);
278
+ if (customer && !customerScopeAllows(target, operation)) return deny("customer_scope", "not_found");
279
+ if (kinds && !kinds.includes(actingKindOf(principal))) return deny("principal_kind");
280
+ return byCapabilities(principal.effective.capabilities, target, operation);
281
+ }
282
+ const delegation = accountDelegationOf(principal);
283
+ if (isSettings(target) && delegation && !settingsDelegated(delegation.capabilities, target, operation)) return deny("humans_only");
284
+ if (kinds && !kinds.includes(actingKindOf(principal))) return deny("principal_kind");
285
+ if (delegation && !isSettings(target) && !byCapabilities(delegation.capabilities, target, operation === "read" ? "read_drafts" : operation).allowed) return deny("not_granted");
286
+ if (isSettings(target) && principal.effective.admin) return allow;
287
+ return null;
288
+ }
289
+ /** ロールの表(能力の主体は decideBeforeRole で決まり、ここへは来ない) */
290
+ const permissionsOf = (principal) => principal.effective.form === "roles" ? principal.effective.permissions : {};
291
+ function decideOnce(principal, target, operation, row, collection) {
292
+ const early = decideBeforeRole(principal, target, operation, collection, row);
293
+ if (early) return early;
294
+ return byRow(permissionsOf(principal), target, operation, row);
295
+ }
296
+ /** ロールの段階とレコードの値での判定 */
297
+ function byRow(permissions, target, operation, row) {
298
+ const action = ROLE_ACTION_OF[operation];
299
+ const owned = row.owned ?? false;
300
+ if (action === "read") return byRole(permissions, target, "read", owned || (row.published ?? false));
301
+ const base = byRole(permissions, target, action, owned);
302
+ if (!base.allowed || action === "publish" || action === "create" || !row.published) return base;
303
+ return byRole(permissions, target, "publish", owned).allowed ? allow : deny("published");
304
+ }
305
+ /**
306
+ * プロジェクトの管理の操作(決定は tunasand#579・tunasand#717: console・CLI・後の MCP の道具が同じ API を呼び、ここで判定する)
307
+ * - create_project: 組織にプロジェクトを作る
308
+ * - create_environment・copy_environment・delete_environment: 環境を作る・コピーする・削除する
309
+ * - promote: エイリアス(live など)の向きを切り替える、promote_schema: 環境のスキーマを live に反映する
310
+ * - freeze: live の書き込みを止める・戻す(切り替えの前の停止)
311
+ * - freeze_hold: 止めたまま残す停止(監視が知らせないので運営者だけ)、delete_project: プロジェクトを削除する
312
+ */
313
+ const MANAGEMENT_OPERATIONS = [
314
+ "create_project",
315
+ "create_environment",
316
+ "copy_environment",
317
+ "delete_environment",
318
+ "promote",
319
+ "promote_schema",
320
+ "freeze",
321
+ "freeze_hold",
322
+ "delete_project"
323
+ ];
324
+ /** 管理の操作ごとに要る組織のロール */
325
+ const MANAGEMENT_ROLES = {
326
+ create_project: ["owner"],
327
+ create_environment: ["owner"],
328
+ copy_environment: ["owner"],
329
+ delete_environment: ["owner"],
330
+ promote: ["owner"],
331
+ promote_schema: ["owner"],
332
+ freeze: ["owner"],
333
+ freeze_hold: [],
334
+ delete_project: ["owner"]
335
+ };
336
+ /** 管理の操作か */
337
+ const isManagementOperation = (operation) => MANAGEMENT_OPERATIONS.includes(operation);
338
+ /**
339
+ * プロジェクトのアカウントに開く管理の操作と、要る管理の権限(ほかの操作は組織の owner)
340
+ * - 本番に届く実行(停止、重い差のスキーマの反映)は、実行の関数が承認した申請を別に求める(kernel の projects/authority.ts)
341
+ */
342
+ const PROJECT_ACCOUNT_CHECKS = {
343
+ create_environment: "manage:environments",
344
+ copy_environment: "manage:environments",
345
+ freeze: "manage:environments",
346
+ promote_schema: "manage:schema"
347
+ };
348
+ /** 管理の操作の判定(ほかの組織は存在を見せない、ロールが足りなければ要るロールを付ける) */
349
+ function byManagement(principal, operation, target) {
350
+ if (principal.kind === "platform_operator") return allow;
351
+ if (principal.kind === "project_account") {
352
+ if (target.projectId !== principal.projectId) return deny("not_member", "not_found");
353
+ const check = PROJECT_ACCOUNT_CHECKS[operation];
354
+ if (check && (principal.admin || levelIn(principal.permissions, check, "update") === "all")) return allow;
355
+ return {
356
+ allowed: false,
357
+ reason: "forbidden",
358
+ cause: "not_permitted",
359
+ required: { operation }
360
+ };
361
+ }
362
+ if (target.organizationId !== principal.organizationId) return deny("not_member", "not_found");
363
+ const roles = MANAGEMENT_ROLES[operation];
364
+ return roles.includes(principal.role) ? allow : {
365
+ allowed: false,
366
+ reason: "forbidden",
367
+ cause: "not_permitted",
368
+ required: {
369
+ operation,
370
+ roles
371
+ }
372
+ };
373
+ }
374
+ function authorize(principal, operation, target, { row = {}, collection } = {}) {
375
+ if (isManagementOperation(operation)) return byManagement(principal, operation, target);
376
+ return withRequired(decideOnce(principal, target, operation, row, collection), operation);
377
+ }
378
+ // ../contract/src/permissions.ts
379
+ /** 操作 */
380
+ const ACTIONS = [
381
+ "read",
382
+ "create",
383
+ "update",
384
+ "publish",
385
+ "delete"
386
+ ];
387
+ /** 操作できるか(owned は自分が持ち主の行か、承認が必要は不可。判定は判定の関数 authorize) */
388
+ const allows = (user, target, action, owned = false) => authorize(principalOfUser(user), action, target, { row: { owned } }).allowed;
389
+ /** 項目の値の ID(ID・ID の配列・JSON の配列の文字列) */
390
+ const idsOf = (value) => {
391
+ if (Array.isArray(value)) return value.map(String);
392
+ if (typeof value !== "string" || !value) return [];
393
+ if (!value.startsWith("[")) return [value];
394
+ try {
395
+ const parsed = JSON.parse(value);
396
+ return Array.isArray(parsed) ? parsed.map(String) : [];
397
+ } catch {
398
+ return [];
399
+ }
400
+ };
401
+ /**
402
+ * レコードの持ち主か
403
+ * - 持ち主の項目がある対象: 項目の値に、アカウントが結び付くレコードを含む
404
+ * - 結び付くコレクションのレコード: 結び付くレコードそのもの
405
+ * - ほかの対象: 作成したアカウント(レコードの created_by、アカウントの ID)
406
+ */
407
+ const ownsRow = (user, target, row) => {
408
+ const field = user.link.owners[target];
409
+ if (field) return user.recordId !== null && idsOf(row[field]).includes(user.recordId);
410
+ if (target === user.link.collection) return user.recordId !== null && row.id === user.recordId;
411
+ return typeof row.created_by === "string" && row.created_by === user.id;
412
+ };
413
+ // ../contract/src/settings.ts
414
+ const PREFIX$1 = "settings:";
415
+ /** 権限の表での設定の領域の id */
416
+ const settingsTarget = (area) => `${PREFIX$1}${area}`;
417
+ Object.fromEntries(ACTIONS.map((a) => [a, "all"]));
418
+ /** 設定を扱える(管理者のロールの)アカウントか */
419
+ const isAdmin = (user) => user.role === "admin" && !user.app && !user.mcp;
420
+ // ../contract/src/manage.ts
421
+ const PREFIX = "manage:";
422
+ /** 権限の表での管理の権限の id */
423
+ const manageTarget = (check) => `${PREFIX}${check}`;
424
+ /**
425
+ * アプリの鍵の用途(登録する公開鍵の JWK の use)
426
+ * - runtime: アプリの JWT をインストールのトークンに交換する鍵(サイトの実行時に持つ。use なしか sig)
427
+ * - deploy: ホスティングするサイトへのアップロードだけに使う鍵(サイトの実行時に持たせない。交換には使えない)
428
+ */
429
+ const APP_KEY_USES = {
430
+ runtime: "sig",
431
+ deploy: "tunasand-deploy"
432
+ };
433
+ new Set(OPERATIONS);
434
+ settingsTarget("data"), settingsTarget("customers"), manageTarget("schema");
435
+ export { accountDelegationOf as a, ownsRow as i, isAdmin as n, customerOf as o, allows as r, principalOfUser as s, APP_KEY_USES as t };
@@ -1,4 +1,4 @@
1
- // ../cms-contract/src/bridge.ts
1
+ // ../contract/src/bridge.ts
2
2
  /** メッセージの名前の頭(外に見える識別子、改名はここだけ) */
3
3
  const BRIDGE_NAMESPACE = "tunasand.bridge";
4
4
  /** 規約の版 */
@@ -6,7 +6,7 @@ const BRIDGE_VERSION = 1;
6
6
  /**
7
7
  * 画面のトークン(アカウントの資格、Shopify のセッションのトークンと同じ形の JWT、設計は docs/app-screens.md の「アカウントの資格」)
8
8
  * - 署名は HS256 で、鍵はクライアントの秘密(インストールにつなぐまでは外の画面の登録の鍵)。アプリのサーバーは手元で検証でき、API は呼べない
9
- * - iss はプロジェクトの管理画面のオリジン(https://<dest>)で、製品名の定数を持たない。skewSec は検証の時計のずれの許容(秒)
9
+ * - iss はプロジェクトのワークスペースのオリジン(https://<dest>)で、製品名の定数を持たない。skewSec は検証の時計のずれの許容(秒)
10
10
  */
11
11
  const SESSION_TOKEN = {
12
12
  ttlSec: 60,
@@ -46,7 +46,7 @@ const BRIDGE_API_METHODS = [
46
46
  ];
47
47
  /**
48
48
  * 見た目のトークンの名前(実験的)
49
- * - 管理画面の見た目の作り直しで名前と値が変わる。版で固定しないので、アプリは値がないときの既定を持つ
49
+ * - ワークスペースの見た目の作り直しで名前と値が変わる。版で固定しないので、アプリは値がないときの既定を持つ
50
50
  * - アプリの側では applyTheme が CSS の変数 --theme-<名前> として当てる
51
51
  */
52
52
  const BRIDGE_THEME_TOKENS = [
package/dist/bridge.js CHANGED
@@ -1,4 +1,4 @@
1
- import { a as BRIDGE_THEME_VAR_PREFIX, c as isBridgeMessage, i as BRIDGE_THEME_TOKENS, n as BRIDGE_ERRORS, o as BRIDGE_VERSION, r as BRIDGE_NAMESPACE, t as BRIDGE_API_METHODS } from "./bridge-DYAYGV7t.js";
1
+ import { a as BRIDGE_THEME_VAR_PREFIX, c as isBridgeMessage, i as BRIDGE_THEME_TOKENS, n as BRIDGE_ERRORS, o as BRIDGE_VERSION, r as BRIDGE_NAMESPACE, t as BRIDGE_API_METHODS } from "./bridge-DtHw9hS6.js";
2
2
  // src/bridge.ts
3
3
  /** 依頼の失敗(code は理由) */
4
4
  var BridgeRequestError = class extends Error {
@@ -18,7 +18,7 @@ var BridgeConnectError = class extends Error {
18
18
  };
19
19
  const DEFAULT_TIMEOUT_MS = 1e4;
20
20
  const HELLO_INTERVAL_MS = 500;
21
- /** 管理画面とつなぐ(iframe の外、時間切れは BridgeConnectError) */
21
+ /** ワークスペースとつなぐ(iframe の外、時間切れは BridgeConnectError) */
22
22
  function connectBridge(options = {}) {
23
23
  const win = options.window ?? globalThis.window;
24
24
  if (!win || win.parent === win) return Promise.reject(new BridgeConnectError("not inside an iframe"));
package/dist/cli.js CHANGED
@@ -1,9 +1,10 @@
1
1
  #!/usr/bin/env node
2
- import { r as runTypesCli } from "./schema-BPHL7Qr-.js";
3
- import { t as APP_KEY_USES } from "./apps-9u4XMi7E.js";
2
+ import { r as runTypesCli } from "./types-B77qvqPJ.js";
3
+ import { t as APP_KEY_USES } from "./apps-BxnJ1RlU.js";
4
+ import { t as newUuidV7 } from "./ids--RF7hGyC.js";
4
5
  import { readFileSync, readdirSync, statSync, writeFileSync } from "node:fs";
5
6
  import { join, relative, resolve, sep } from "node:path";
6
- // ../cms-contract/src/siteArtifact.ts
7
+ // ../contract/src/siteArtifact.ts
7
8
  /** 成果物の先頭の印と上限(大きさはバイト。資産の1つの上限は Workers の静的な資産の上限) */
8
9
  const SITE_ARTIFACT = {
9
10
  magic: "TUNASANDSITE1\n",
@@ -171,7 +172,7 @@ async function generateDeployKey() {
171
172
  name: "ECDSA",
172
173
  namedCurve: "P-256"
173
174
  }, true, ["sign", "verify"]);
174
- const kid = crypto.randomUUID();
175
+ const kid = newUuidV7();
175
176
  const { key_ops: _, ext: __, ...pub } = await crypto.subtle.exportKey("jwk", pair.publicKey);
176
177
  return {
177
178
  privateJwk: {
@@ -1,4 +1,4 @@
1
- // ../model/src/model.ts
1
+ // ../schema/src/collection.ts
2
2
  /** 個人の情報の分類(identifier は直接の識別子、contact は連絡先、freetext は自由記述、sensitive は機微、none は対象外) */
3
3
  const PII_CLASSES = [
4
4
  "identifier",
@@ -52,15 +52,15 @@ const FIELD_ROLES = [
52
52
  "date",
53
53
  "months"
54
54
  ];
55
- /** メディアのコレクションの id(項目の種類 media の accept と同じ、レコードは表 assets) */
55
+ /** メディアのコレクションの id(項目の種類 media の accept と同じ、レコードは表 files) */
56
56
  const MEDIA_COLLECTION_IDS = ["image", "video"];
57
- /** メディアのコレクションか(画像・動画、レコードは表 assets で一覧・作成・配信の対象外) */
57
+ /** メディアのコレクションか(画像・動画、レコードは表 files で一覧・作成・配信の対象外) */
58
58
  const isMediaCollection = (collection) => MEDIA_COLLECTION_IDS.includes(collection.id);
59
59
  /** オブジェクト形式のコレクションか(レコードは表 records の id がコレクションの id の1行、一覧・作成の対象外) */
60
60
  const isSingleton = (collection) => collection.format === "object" && !isMediaCollection(collection);
61
61
  /** 公開の管理(なしは none) */
62
62
  const publishingOf = (collection) => collection.publishing ?? "none";
63
- /** 顧客への参照の項目の種類(cms-contract の CUSTOMER_REFERENCE_FIELD と同じ値) */
63
+ /** 顧客への参照の項目の種類(contract の CUSTOMER_REFERENCE_FIELD と同じ値) */
64
64
  const CUSTOMER_FIELD_TYPE = "customer";
65
65
  /** 配信しない一覧のコレクションのアンケートの形か(顧客フィールドが1つ、オブジェクト形式は除く。customers/survey.ts のエンドポイントの対象) */
66
66
  const isSurveyShape = (collection) => collection.private === true && collection.format !== "object" && collection.fields.filter((f) => f.type === "customer").length === 1;
@@ -81,7 +81,7 @@ function audienceOf(f, collection) {
81
81
  const innerAudienceOf = (f, outer) => narrower(selfAudienceOf(f) ?? outer, outer);
82
82
  /** 個人の情報を持つコレクションか(顧客フィールドを持つコレクション、submit を受けるアンケートの形もこの形): 足す項目に見える範囲の明示を求め、既定は狭い側 */
83
83
  const isPersonalCollection = (collection) => collection.fields.some((f) => f.type === CUSTOMER_FIELD_TYPE);
84
- /** 足す項目の既定の見える範囲(非公開のコレクションは宣言なしの読み、個人の情報を持つコレクションは staff、ほかは public。管理画面の既定と保存の規則が共有) */
84
+ /** 足す項目の既定の見える範囲(非公開のコレクションは宣言なしの読み、個人の情報を持つコレクションは staff、ほかは public。ワークスペースの既定と保存の規則が共有) */
85
85
  function addedFieldAudienceOf(collection) {
86
86
  if (collection.private) return isSurveyShape(collection) ? "self" : "staff";
87
87
  return isPersonalCollection(collection) ? "staff" : "public";
@@ -114,18 +114,26 @@ const isListCollection = (collection) => !isMediaCollection(collection) && !isSi
114
114
  * - 提出と差し戻し・担当者: レビューありのコレクションだけ(usesReview)
115
115
  */
116
116
  const isPublishable = (collection) => publishingOf(collection) !== "none" && isListCollection(collection);
117
- /** 非公開のコレクションか(顧客の台帳・アンケートなど) */
117
+ /**
118
+ * レビューのワークフローを持つコレクションか(レビューありの一覧のコレクション)
119
+ * - 機能: 提出と差し戻し・担当者(レビューを担当するアカウント)
120
+ * - 下書きと公開のコレクション: 担当者の表示・割り当て・一括の割り当てを出さない
121
+ */
122
+ const usesReview = (collection) => publishingOf(collection) === "review" && isListCollection(collection);
123
+ /** コレクションのレコードを表 records に保存するか(メディアのコレクションを除くすべて) */
124
+ const isStoredCollection = (collection) => !isMediaCollection(collection);
125
+ /** 非公開のコレクションか(顧客のレジストリ・アンケートなど) */
118
126
  const isPrivateCollection = (collection) => collection.private === true;
119
127
  /** コンテンツスキーマのコレクション(id から、なければ例外: 導入先の設定の誤り) */
120
- function collectionOf(model, id) {
121
- const collection = model.collections.find((t) => t.id === id);
128
+ function collectionOf(collectionSchema, id) {
129
+ const collection = collectionSchema.collections.find((t) => t.id === id);
122
130
  if (!collection) throw new Error(`content schema has no collection ${id}`);
123
131
  return collection;
124
132
  }
125
133
  /** UUID の形(経路の値が id かスラッグかの引き分け。スラッグはハイフンを持てないので UUID の形にならない) */
126
134
  const isUuidShape = (value) => /^[0-9a-f]{8}-[0-9a-f]{4}-[0-9a-f]{4}-[0-9a-f]{4}-[0-9a-f]{12}$/.test(value);
127
135
  /** 経路・入力の値のコレクション(UUID の形なら id、ほかはスラッグで引く。なければ undefined) */
128
- const collectionByRef = (model, ref) => model.collections.find(isUuidShape(ref) ? (c) => c.id === ref : (c) => c.slug === ref);
136
+ const collectionByRef = (schema, ref) => schema.collections.find(isUuidShape(ref) ? (c) => c.id === ref : (c) => c.slug === ref);
129
137
  /** 選択肢の項目の選択肢(まとまりの中の項目は `links.kind` の形、選択肢の項目でなければ空) */
130
138
  function optionsOf(collection, key) {
131
139
  const [head, ...rest] = key.split(".");
@@ -133,6 +141,18 @@ function optionsOf(collection, key) {
133
141
  for (const k of rest) field = field?.type === "group" ? field.fields.find((f) => f.key === k) : void 0;
134
142
  return field?.type === "select" ? field.options : [];
135
143
  }
144
+ /** セレクトの項目の定義(なければ null) */
145
+ const selectOf = (collection, key) => {
146
+ const field = collection.fields.find((f) => f.key === key);
147
+ return field?.type === "select" ? field : null;
148
+ };
149
+ /** 新しいレコードの初期値(セレクトは項目の initial、なければ先頭の選択肢、セレクトでなければ空文字) */
150
+ const initialValueOf = (collection, key) => {
151
+ const field = selectOf(collection, key);
152
+ return field ? field.initial ?? field.options[0]?.value ?? "" : "";
153
+ };
154
+ /** 選択肢の表示名(なければ値のまま) */
155
+ const optionLabelOf = (collection, key, value) => optionsOf(collection, key).find((o) => o.value === value)?.label ?? value;
136
156
  /** 連番の項目か(integrity.ts) */
137
157
  const isSequenceField = (f) => f.type === "number" && f.sequence === true;
138
158
  /** 入力する項目か(計算の項目と連番を除く) */
@@ -140,13 +160,30 @@ const isInputField = (f) => !f.computed && !isSequenceField(f);
140
160
  /** 役割ごとに受け付ける項目(宣言の検査と、宣言のないコレクションの推測で共通) */
141
161
  const ROLE_ACCEPTS = {
142
162
  title: (f) => (f.type === "text" || f.type === "long_text") && !f.multiple && isInputField(f),
143
- image: (f) => f.type === "media" && !f.multiple && (!f.accept || f.accept.includes("image")),
163
+ image: (f) => f.type === "file" && !f.multiple && (!f.accept || f.accept.includes("image")),
144
164
  body: (f) => f.type === "rich_text",
145
165
  summary: (f) => (f.type === "text" || f.type === "long_text") && !f.multiple,
146
166
  date: (f) => f.type === "date" || f.type === "datetime",
147
167
  months: (f) => f.type === "number" && isInputField(f)
148
168
  };
149
- ROLE_ACCEPTS.image, ROLE_ACCEPTS.body;
169
+ /** 宣言のないコレクションの推測(題は複数でない文字の項目、画像は複数でない画像の項目、本文は本文の項目の先頭、要約・日付・期間は推測なし) */
170
+ const ROLE_GUESSES = {
171
+ title: (f) => f.type === "text" && ROLE_ACCEPTS.title(f),
172
+ image: ROLE_ACCEPTS.image,
173
+ body: ROLE_ACCEPTS.body,
174
+ summary: null,
175
+ date: null,
176
+ months: null
177
+ };
150
178
  /** 役割の項目が受け付ける項目か(宣言の検査に使用) */
151
179
  const acceptsRole = (role, f) => ROLE_ACCEPTS[role](f);
152
- export { isSurveyShape as C, isSingleton as S, optionsOf as T, isDeliveredAudience as _, PII_CLASSES as a, isPublishable as b, acceptsRole as c, cascadeTargetsOf as d, collectionByRef as f, innerAudienceOf as g, grantedKeysOf as h, ON_DELETE as i, audienceOf as l, declaredAudienceOf as m, CUSTOMER_FIELD_TYPE as n, SELF_OPS as o, collectionOf as p, FIELD_ROLES as r, SLUG_MODES as s, AUDIENCES as t, cascadeDepths as u, isListCollection as v, narrower as w, isSequenceField as x, isPrivateCollection as y };
180
+ function roleFieldOf(collection, role) {
181
+ const key = collection.roles?.[role];
182
+ if (key !== void 0) {
183
+ const declared = collection.fields.find((f) => f.key === key);
184
+ return declared && ROLE_ACCEPTS[role](declared) ? declared : null;
185
+ }
186
+ const guess = ROLE_GUESSES[role];
187
+ return guess ? collection.fields.find(guess) ?? null : null;
188
+ }
189
+ export { publishingOf as A, isSequenceField as C, narrower as D, isSurveyShape as E, usesReview as M, optionLabelOf as O, isPublishable as S, isStoredCollection as T, innerAudienceOf as _, PII_CLASSES as a, isPersonalCollection as b, acceptsRole as c, cascadeTargetsOf as d, collectionByRef as f, initialValueOf as g, grantedKeysOf as h, ON_DELETE as i, roleFieldOf as j, optionsOf as k, audienceOf as l, declaredAudienceOf as m, CUSTOMER_FIELD_TYPE as n, SELF_OPS as o, collectionOf as p, FIELD_ROLES as r, SLUG_MODES as s, AUDIENCES as t, cascadeDepths as u, isDeliveredAudience as v, isSingleton as w, isPrivateCollection as x, isListCollection as y };
@@ -1,4 +1,4 @@
1
- // ../cms-contract/src/customerLabels.ts
1
+ // ../contract/src/customerLabels.ts
2
2
  /** 顧客の設定の問題の文(値の範囲は customers.ts の上限から) */
3
3
  const customersSettingsIssues = (v) => ({
4
4
  shape: "顧客の設定の形が不正",
@@ -17,7 +17,9 @@ const customersSettingsIssues = (v) => ({
17
17
  jwksIp: "公開鍵の取得先のホストに IP アドレスは使えない",
18
18
  jwksOwn: "公開鍵の取得先に Tunasand のドメインは使えない"
19
19
  });
20
- // ../cms-contract/src/customers.ts
20
+ // ../contract/src/customers.ts
21
+ /** 顧客の API の鍵の権限とロールの権限の対象(コレクションの id と重ならない) */
22
+ const CUSTOMERS_KEY_TARGET = "@customers";
21
23
  /** 人の状態(有効・停止・退会)。見られるかはアクセス権が決め、状態は停止と退会で照合と配信のエンドポイントを閉じる */
22
24
  const CUSTOMER_STATUSES = [
23
25
  "active",
@@ -81,4 +83,4 @@ const SELF_API_ERRORS = [
81
83
  "invalid_state",
82
84
  "rate_limited"
83
85
  ];
84
- export { SELF_API_ERRORS as a, CUSTOMER_STATUSES as i, CUSTOMER_API_ERRORS as n, CUSTOMER_EVENTS as r, CUSTOMERS_LIMITS as t };
86
+ export { CUSTOMER_STATUSES as a, CUSTOMER_EVENTS as i, CUSTOMERS_LIMITS as n, SELF_API_ERRORS as o, CUSTOMER_API_ERRORS as r, CUSTOMERS_KEY_TARGET as t };
package/dist/customers.js CHANGED
@@ -1,6 +1,6 @@
1
- import { a as SELF_API_ERRORS, i as CUSTOMER_STATUSES, n as CUSTOMER_API_ERRORS, r as CUSTOMER_EVENTS, t as CUSTOMERS_LIMITS } from "./customers-C_vJY2_v.js";
1
+ import { a as CUSTOMER_STATUSES, i as CUSTOMER_EVENTS, n as CUSTOMERS_LIMITS, o as SELF_API_ERRORS, r as CUSTOMER_API_ERRORS } from "./customers-DTbL0qn6.js";
2
2
  import { n as DeliveryError, t as DELIVERY_PATH } from "./client-Derrexwr.js";
3
- import { h as grantedKeysOf } from "./model-pmXzGX12.js";
3
+ import { h as grantedKeysOf } from "./collection-BEOxeISR.js";
4
4
  // src/customers.ts
5
5
  /** エラーの応答の本文を読む(JSON でなければ空) */
6
6
  const failureOf = (text) => {