@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,19 +1,19 @@
1
- import { _ as innerAudienceOf, l as audienceOf, v as isDeliveredAudience, x as isPrivateCollection } from "./collection-BEOxeISR.js";
1
+ import { S as isDeliveredAudience, T as isPrivateCollection, u as audienceOf, x as innerAudienceOf } from "./collection-26aglrg6.js";
2
2
  // ../schema/src/values.ts
3
3
  /** まとまりの中の配信する項目(外側の見える範囲 outer の中で、本人とスタッフの項目を除く) */
4
4
  const deliveredInner = (fields, outer) => fields.flatMap((f) => {
5
5
  const own = innerAudienceOf(f, outer);
6
6
  if (!isDeliveredAudience(own)) return [];
7
- return [f.type === "group" ? {
7
+ return [f.type === "object" ? {
8
8
  ...f,
9
9
  fields: deliveredInner(f.fields, own)
10
10
  } : f];
11
11
  });
12
- /** 配信する項目(本人とスタッフの項目と顧客フィールドを除く、まとまりの中も) */
12
+ /** 配信する項目(本人とスタッフの項目とエンドユーザーへの参照のフィールドを除く、まとまりの中も) */
13
13
  const deliveredFields = (collection) => collection.fields.flatMap((f) => {
14
14
  const own = audienceOf(f, collection);
15
15
  if (!isDeliveredAudience(own)) return [];
16
- return [f.type === "group" ? {
16
+ return [f.type === "object" ? {
17
17
  ...f,
18
18
  fields: deliveredInner(f.fields, own)
19
19
  } : f];
@@ -32,7 +32,7 @@ const GENERATED_TYPES = {
32
32
  text: true,
33
33
  long_text: true,
34
34
  datetime: true,
35
- customer: true,
35
+ end_user: true,
36
36
  email: true,
37
37
  phone: true,
38
38
  url: true,
@@ -41,9 +41,10 @@ const GENERATED_TYPES = {
41
41
  number: true,
42
42
  boolean: true,
43
43
  select: true,
44
+ status: true,
44
45
  file: true,
45
46
  rich_text: true,
46
- group: true
47
+ object: true
47
48
  };
48
49
  /** 生成できない項目の型(code は unknown_field_type、path はコレクションのスラッグからの項目の key の道) */
49
50
  var UnknownFieldTypeError = class extends Error {
@@ -61,7 +62,7 @@ function unknownFieldOf(fields, at) {
61
62
  for (const f of fields) {
62
63
  const path = `${at}.${f.key}`;
63
64
  if (!Object.hasOwn(GENERATED_TYPES, f.type)) return new UnknownFieldTypeError(path, String(f.type));
64
- const inner = f.type === "group" ? unknownFieldOf(f.fields, path) : null;
65
+ const inner = f.type === "object" ? unknownFieldOf(f.fields, path) : null;
65
66
  if (inner) return inner;
66
67
  }
67
68
  return null;
@@ -73,7 +74,7 @@ function singleOf(f, indent) {
73
74
  case "text":
74
75
  case "long_text":
75
76
  case "datetime":
76
- case "customer":
77
+ case "end_user":
77
78
  case "email":
78
79
  case "phone":
79
80
  case "url": return "string";
@@ -81,10 +82,11 @@ function singleOf(f, indent) {
81
82
  case "reference": return "RecordRef";
82
83
  case "number": return "number";
83
84
  case "boolean": return "boolean";
84
- case "select": return f.options.map((o) => JSON.stringify(o.value)).join(" | ") || "string";
85
+ case "select":
86
+ case "status": return f.options.map((o) => JSON.stringify(o.value)).join(" | ") || "string";
85
87
  case "file": return "DeliveredFile | null";
86
88
  case "rich_text": return "Body<DeliveredFile | null>";
87
- case "group": return `{\n${fieldsOf(f.fields, `${indent} `, () => false)}\n${indent}}`;
89
+ case "object": return `{\n${fieldsOf(f.fields, `${indent} `, () => false)}\n${indent}}`;
88
90
  }
89
91
  }
90
92
  /** 項目の値の型(SDK の FieldValue と同じ、複数は readonly の配列、値なしは null) */
@@ -94,15 +96,15 @@ const valueOf = (f, indent) => {
94
96
  return one.endsWith(" | null") ? one : `${one} | null`;
95
97
  };
96
98
  /** 項目の種類(まとまりの中を含む、配信する項目 deliveredFields の結果に当てる) */
97
- const kindsOf = (fields) => fields.flatMap((f) => [f.type, ...f.type === "group" ? kindsOf(f.fields) : []]);
98
- /** 項目の並び(optional は省略可の項目: 最上位のアクセス権の項目は read_customers を持たない鍵の応答にないため) */
99
+ const kindsOf = (fields) => fields.flatMap((f) => [f.type, ...f.type === "object" ? kindsOf(f.fields) : []]);
100
+ /** 項目の並び(optional は省略可の項目: 最上位のアクセス権の項目は read_entitled を持たない鍵の応答にないため) */
99
101
  const fieldsOf = (fields, indent, optional) => fields.map((f) => `${indent}readonly ${propertyName(f.key)}${optional(f) ? "?" : ""}: ${valueOf(f, indent)};`).join("\n");
100
- const typeOf = (t) => `export type ${pascal(t.slug)} = Readonly<{\n id: string;\n slug: string;\n _meta: ItemMeta;\n${fieldsOf(deliveredFields(t), " ", (f) => audienceOf(f, t) === "granted")}\n}>;`;
102
+ const typeOf = (t) => `export type ${pascal(t.slug)} = Readonly<{\n id: string;\n slug: string;\n _meta: ItemMeta;\n${fieldsOf(deliveredFields(t), " ", (f) => audienceOf(f, t) === "entitled")}\n}>;`;
101
103
  /**
102
104
  * スキーマから配信 API の値の型の定義(TypeScript のアプリの文)
103
105
  * - コレクションごとに `export type <PascalCase のコレクションのスラッグ>`
104
106
  * - 全体の対応 `CmsTypes`(キーはスラッグ)とスラッグの一覧 `COLLECTION_SLUGS`
105
- * - types: 配信するコレクションだけ(メディアのコレクションを除いた一覧、配信 API の `/collections` の値)。非公開のコレクションは渡されても除く
107
+ * - types: 配信するコレクションだけ(files のコレクションを除いた一覧、配信 API の `/collections` の値)。非公開のコレクションは渡されても除く
106
108
  * - 例外: 生成できない項目の型(CMS が SDK より新しい型を返した)は UnknownFieldTypeError
107
109
  */
108
110
  function typesSourceOf(collectionSchema) {
@@ -119,7 +121,7 @@ function typesSourceOf(collectionSchema) {
119
121
  ...uses("reference") ? ["RecordRef"] : []
120
122
  ].sort();
121
123
  return [
122
- "// Generated from the CMS schema (GET /content/v1/collections). Do not edit; regenerate with tunasand types.",
124
+ "// Generated from the CMS schema (GET /v1/collections). Do not edit; regenerate with tunasand types.",
123
125
  importLine(delivery, `${SDK}/delivery`),
124
126
  ...uses("rich_text") ? [importLine(["Body"], `${SDK}/rich-text`)] : [],
125
127
  ...uses("date") ? [importLine(["DateString"], `${SDK}/schema`)] : [],
package/package.json CHANGED
@@ -1,7 +1,7 @@
1
1
  {
2
2
  "name": "@tunasand/sdk",
3
- "version": "0.8.0",
4
- "description": "tunasand の導入先のサイト向けの SDK(配信 API の取得・本文の型・プレビューの署名・手元の開発の配信 API)",
3
+ "version": "0.12.0",
4
+ "description": "tunasand の導入先のサイト向けの SDK(配信 API の取得・本文の型・プレビューの受け口・手元の開発の配信 API)",
5
5
  "license": "UNLICENSED",
6
6
  "author": "RYUSENKEI",
7
7
  "repository": {
@@ -44,14 +44,30 @@
44
44
  "types": "./dist/dev.d.ts",
45
45
  "default": "./dist/dev.js"
46
46
  },
47
- "./customers": {
48
- "types": "./dist/customers.d.ts",
49
- "default": "./dist/customers.js"
47
+ "./end-users": {
48
+ "types": "./dist/end-users.d.ts",
49
+ "default": "./dist/end-users.js"
50
50
  },
51
51
  "./app": {
52
52
  "types": "./dist/app.d.ts",
53
53
  "default": "./dist/app.js"
54
54
  },
55
+ "./code": {
56
+ "types": "./dist/code.d.ts",
57
+ "default": "./dist/code.js"
58
+ },
59
+ "./operations": {
60
+ "types": "./dist/operations.d.ts",
61
+ "default": "./dist/operations.js"
62
+ },
63
+ "./astro": {
64
+ "types": "./dist/astro.d.ts",
65
+ "default": "./dist/astro.js"
66
+ },
67
+ "./astro/server": {
68
+ "types": "./dist/astro-server.d.ts",
69
+ "default": "./dist/astro-server.js"
70
+ },
55
71
  "./i18n": {
56
72
  "types": "./dist/i18n.d.ts",
57
73
  "default": "./dist/i18n.js"
@@ -72,16 +88,26 @@
72
88
  "access": "public"
73
89
  },
74
90
  "dependencies": {
75
- "@ryusenkei/web": "^0.14.0",
91
+ "@ryusenkei/web": "^0.16.0",
76
92
  "htmlparser2": "^10.1.0",
77
93
  "use-intl": "^4.15.1",
78
94
  "zod": "^4.6.7"
79
95
  },
80
96
  "devDependencies": {
81
97
  "@types/node": "^26.6.6",
98
+ "acorn": "^8.19.0",
99
+ "astro": "^7.4.4",
82
100
  "tsdown": "^0.23.7",
83
101
  "typescript": "^5.9.3"
84
102
  },
103
+ "peerDependencies": {
104
+ "astro": ">=7 <8"
105
+ },
106
+ "peerDependenciesMeta": {
107
+ "astro": {
108
+ "optional": true
109
+ }
110
+ },
85
111
  "scripts": {
86
112
  "build": "node scripts/build.ts && node ../../scripts/check-dist.ts",
87
113
  "typecheck": "tsc"
@@ -1,435 +0,0 @@
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 };