@tunasand/sdk 0.0.0-stage → 0.6.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 (168) hide show
  1. package/CHANGELOG.md +106 -0
  2. package/README.md +506 -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 +348 -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-BcyRbv_i.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/views.d.ts +21 -0
  111. package/dist/types/cms-contract/src/webhookLabels.d.ts +7 -0
  112. package/dist/types/cms-contract/src/webhooks.d.ts +139 -0
  113. package/dist/types/i18n/src/index.d.ts +50 -0
  114. package/dist/types/i18n/src/problems.d.ts +21 -0
  115. package/dist/types/model/src/asset.d.ts +111 -0
  116. package/dist/types/model/src/audience.d.ts +38 -0
  117. package/dist/types/model/src/brand.d.ts +25 -0
  118. package/dist/types/model/src/capabilities.d.ts +28 -0
  119. package/dist/types/model/src/changes.d.ts +34 -0
  120. package/dist/types/model/src/check.d.ts +15 -0
  121. package/dist/types/model/src/contact.d.ts +22 -0
  122. package/dist/types/model/src/image.d.ts +38 -0
  123. package/dist/types/model/src/index.d.ts +26 -0
  124. package/dist/types/model/src/input.d.ts +26 -0
  125. package/dist/types/model/src/integrity.d.ts +79 -0
  126. package/dist/types/model/src/json.d.ts +2 -0
  127. package/dist/types/model/src/labels/en.d.ts +169 -0
  128. package/dist/types/model/src/labels/ja.d.ts +198 -0
  129. package/dist/types/model/src/legacy.d.ts +2 -0
  130. package/dist/types/model/src/media.d.ts +5 -0
  131. package/dist/types/model/src/mediaUrl.d.ts +67 -0
  132. package/dist/types/model/src/model.d.ts +415 -0
  133. package/dist/types/model/src/page.d.ts +52 -0
  134. package/dist/types/model/src/problems.d.ts +184 -0
  135. package/dist/types/model/src/refs.d.ts +27 -0
  136. package/dist/types/model/src/rules.d.ts +15 -0
  137. package/dist/types/model/src/schema.d.ts +58 -0
  138. package/dist/types/model/src/screens.d.ts +76 -0
  139. package/dist/types/model/src/selfOps.d.ts +30 -0
  140. package/dist/types/model/src/time.d.ts +25 -0
  141. package/dist/types/model/src/typesSource.d.ts +8 -0
  142. package/dist/types/model/src/values.d.ts +24 -0
  143. package/dist/types/platform/src/defaultModel.d.ts +8 -0
  144. package/dist/types/sdk/src/analytics.d.ts +2 -0
  145. package/dist/types/sdk/src/app.d.ts +20 -0
  146. package/dist/types/sdk/src/body.d.ts +2 -0
  147. package/dist/types/sdk/src/bridge.d.ts +92 -0
  148. package/dist/types/sdk/src/cli.d.ts +2 -0
  149. package/dist/types/sdk/src/customers.d.ts +190 -0
  150. package/dist/types/sdk/src/delivery/cache.d.ts +18 -0
  151. package/dist/types/sdk/src/delivery/changes.d.ts +28 -0
  152. package/dist/types/sdk/src/delivery/client.d.ts +90 -0
  153. package/dist/types/sdk/src/delivery/fields.d.ts +48 -0
  154. package/dist/types/sdk/src/delivery/index.d.ts +9 -0
  155. package/dist/types/sdk/src/delivery/media.d.ts +14 -0
  156. package/dist/types/sdk/src/delivery/query.d.ts +85 -0
  157. package/dist/types/sdk/src/delivery/schema.d.ts +19 -0
  158. package/dist/types/sdk/src/delivery/values.d.ts +82 -0
  159. package/dist/types/sdk/src/delivery.d.ts +3 -0
  160. package/dist/types/sdk/src/dev.d.ts +29 -0
  161. package/dist/types/sdk/src/i18n.d.ts +12 -0
  162. package/dist/types/sdk/src/integrations.d.ts +33 -0
  163. package/dist/types/sdk/src/model.d.ts +5 -0
  164. package/dist/types/sdk/src/preview.d.ts +1 -0
  165. package/dist/types/sdk/src/schema.d.ts +21 -0
  166. package/dist/types/sdk/src/site.d.ts +43 -0
  167. package/dist/typesSource-bO0jFw1I.js +88 -0
  168. package/package.json +86 -3
@@ -0,0 +1,152 @@
1
+ // ../model/src/model.ts
2
+ /** 個人の情報の分類(identifier は直接の識別子、contact は連絡先、freetext は自由記述、sensitive は機微、none は対象外) */
3
+ const PII_CLASSES = [
4
+ "identifier",
5
+ "contact",
6
+ "freetext",
7
+ "sensitive",
8
+ "none"
9
+ ];
10
+ /** 見える範囲(狭い順は public → granted → self → staff) */
11
+ const AUDIENCES = [
12
+ "public",
13
+ "granted",
14
+ "self",
15
+ "staff"
16
+ ];
17
+ /** 見える範囲の値か */
18
+ const isAudience = (v) => typeof v === "string" && AUDIENCES.includes(v);
19
+ /** 狭いほうの見える範囲 */
20
+ const narrower = (a, b) => AUDIENCES.indexOf(a) >= AUDIENCES.indexOf(b) ? a : b;
21
+ /**
22
+ * 項目が宣言した見える範囲(audience と旧い印の狭いほう、どちらもなければ undefined)
23
+ * - 旧い印: 非公開 private は staff、顧客だけ customersOnly は granted(旧い形のファイルと SDK の as const の定義)
24
+ */
25
+ function declaredAudienceOf(f) {
26
+ const own = isAudience(f.audience) ? f.audience : void 0;
27
+ const legacy = f.private === true ? "staff" : f.customersOnly === true ? "granted" : void 0;
28
+ return own && legacy ? narrower(own, legacy) : own ?? legacy;
29
+ }
30
+ /** 指す先が消えたときの扱い(cascade は一緒に消す、anonymize は結び付きと宣言した項目を空にして残す、clear は結び付きを空に、restrict は指す先を消せない) */
31
+ const ON_DELETE = [
32
+ "cascade",
33
+ "anonymize",
34
+ "clear",
35
+ "restrict"
36
+ ];
37
+ /** レコードのスラッグの決め方 */
38
+ const SLUG_MODES = ["auto", "editor"];
39
+ /** コレクションが宣言で受ける人の操作(#712) */
40
+ const SELF_OPS = [
41
+ "read_self",
42
+ "create_self",
43
+ "update_self",
44
+ "delete_self"
45
+ ];
46
+ /** 項目の役割(製品の処理がコレクションごとの key によらず参照する項目) */
47
+ const FIELD_ROLES = [
48
+ "title",
49
+ "image",
50
+ "body",
51
+ "summary",
52
+ "date",
53
+ "months"
54
+ ];
55
+ /** メディアのコレクションの id(項目の種類 media の accept と同じ、レコードは表 assets) */
56
+ const MEDIA_COLLECTION_IDS = ["image", "video"];
57
+ /** メディアのコレクションか(画像・動画、レコードは表 assets で一覧・作成・配信の対象外) */
58
+ const isMediaCollection = (collection) => MEDIA_COLLECTION_IDS.includes(collection.id);
59
+ /** オブジェクト形式のコレクションか(レコードは表 records の id がコレクションの id の1行、一覧・作成の対象外) */
60
+ const isSingleton = (collection) => collection.format === "object" && !isMediaCollection(collection);
61
+ /** 公開の管理(なしは none) */
62
+ const publishingOf = (collection) => collection.publishing ?? "none";
63
+ /** 顧客への参照の項目の種類(cms-contract の CUSTOMER_REFERENCE_FIELD と同じ値) */
64
+ const CUSTOMER_FIELD_TYPE = "customer";
65
+ /** 配信しない一覧のコレクションのアンケートの形か(顧客フィールドが1つ、オブジェクト形式は除く。customers/survey.ts のエンドポイントの対象) */
66
+ const isSurveyShape = (collection) => collection.private === true && collection.format !== "object" && collection.fields.filter((f) => f.type === "customer").length === 1;
67
+ /** 項目自身の見える範囲(audience が不正なら staff、なければ宣言、宣言がなければ undefined) */
68
+ const selfAudienceOf = (f) => f.audience !== void 0 && !isAudience(f.audience) ? "staff" : declaredAudienceOf(f);
69
+ /**
70
+ * 最上位の項目の見える範囲(読み替えの唯一の関数: 配信、判定、スキーマの読み込みと保存の検査が使う、保存の形には書き戻さない)
71
+ * - 項目自身の見える範囲(不正は staff、audience と旧い印の狭いほう)があればそれ
72
+ * - 宣言なし(旧い形): 顧客フィールドは staff、非公開のコレクションはアンケートの形なら本人 self・ほかは staff、配信するコレクションは public
73
+ */
74
+ function audienceOf(f, collection) {
75
+ const own = selfAudienceOf(f);
76
+ if (own) return own;
77
+ if (f.type === "customer") return "staff";
78
+ return collection.private ? addedFieldAudienceOf(collection) : "public";
79
+ }
80
+ /** まとまりの中の項目の見える範囲(項目自身の見える範囲か外側の狭いほう) */
81
+ const innerAudienceOf = (f, outer) => narrower(selfAudienceOf(f) ?? outer, outer);
82
+ /** 個人の情報を持つコレクションか(顧客フィールドを持つコレクション、submit を受けるアンケートの形もこの形): 足す項目に見える範囲の明示を求め、既定は狭い側 */
83
+ const isPersonalCollection = (collection) => collection.fields.some((f) => f.type === CUSTOMER_FIELD_TYPE);
84
+ /** 足す項目の既定の見える範囲(非公開のコレクションは宣言なしの読み、個人の情報を持つコレクションは staff、ほかは public。管理画面の既定と保存の規則が共有) */
85
+ function addedFieldAudienceOf(collection) {
86
+ if (collection.private) return isSurveyShape(collection) ? "self" : "staff";
87
+ return isPersonalCollection(collection) ? "staff" : "public";
88
+ }
89
+ /** コレクションの最上位の参照の項目で cascade のものが指すコレクションの id */
90
+ const cascadeTargetsOf = (collection) => collection.fields.flatMap((f) => f.type === "reference" && f.onDelete === "cascade" && f.to ? [f.to] : []);
91
+ /**
92
+ * 人から cascade でたどれるコレクションと最も浅い深さ(顧客フィールドの cascade のコレクションを1、参照の cascade を1段ごとに足す)
93
+ * - 循環はコレクションの数で打ち切る(循環の検査は schema.ts)
94
+ */
95
+ function cascadeDepths(collections) {
96
+ const depth = /* @__PURE__ */ new Map();
97
+ const visit = (id, d) => {
98
+ if (d > collections.length || (depth.get(id) ?? Infinity) <= d) return;
99
+ depth.set(id, d);
100
+ for (const h of collections.filter((collection) => cascadeTargetsOf(collection).includes(id))) visit(h.id, d + 1);
101
+ };
102
+ for (const collection of collections) if (collection.fields.some((f) => f.type === "customer" && f.onDelete === "cascade")) visit(collection.id, 1);
103
+ return depth;
104
+ }
105
+ /** 配信 API に出す見える範囲か(公開とアクセス権) */
106
+ const isDeliveredAudience = (a) => a === "public" || a === "granted";
107
+ /** アクセス権の項目の key(コレクションの最上位) */
108
+ const grantedKeysOf = (collection) => collection.fields.filter((f) => audienceOf(f, collection) === "granted").map((f) => f.key);
109
+ /** 一覧でレコードを追加・管理するコレクションか(オブジェクト形式のコレクション・メディアのコレクションを除く) */
110
+ const isListCollection = (collection) => !isMediaCollection(collection) && !isSingleton(collection);
111
+ /**
112
+ * 編集の機能を持つコレクションか(公開の管理がある一覧のコレクション)
113
+ * - 機能: 版・楽観ロック・編集中のリース・コメント・公開の前の点検
114
+ * - 提出と差し戻し・担当者: レビューありのコレクションだけ(usesReview)
115
+ */
116
+ const isPublishable = (collection) => publishingOf(collection) !== "none" && isListCollection(collection);
117
+ /** 非公開のコレクションか(顧客の台帳・アンケートなど) */
118
+ const isPrivateCollection = (collection) => collection.private === true;
119
+ /** コンテンツスキーマのコレクション(id から、なければ例外: 導入先の設定の誤り) */
120
+ function collectionOf(model, id) {
121
+ const collection = model.collections.find((t) => t.id === id);
122
+ if (!collection) throw new Error(`content schema has no collection ${id}`);
123
+ return collection;
124
+ }
125
+ /** UUID の形(経路の値が id かスラッグかの引き分け。スラッグはハイフンを持てないので UUID の形にならない) */
126
+ 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
+ /** 経路・入力の値のコレクション(UUID の形なら id、ほかはスラッグで引く。なければ undefined) */
128
+ const collectionByRef = (model, ref) => model.collections.find(isUuidShape(ref) ? (c) => c.id === ref : (c) => c.slug === ref);
129
+ /** 選択肢の項目の選択肢(まとまりの中の項目は `links.kind` の形、選択肢の項目でなければ空) */
130
+ function optionsOf(collection, key) {
131
+ const [head, ...rest] = key.split(".");
132
+ let field = collection.fields.find((f) => f.key === head);
133
+ for (const k of rest) field = field?.type === "group" ? field.fields.find((f) => f.key === k) : void 0;
134
+ return field?.type === "select" ? field.options : [];
135
+ }
136
+ /** 連番の項目か(integrity.ts) */
137
+ const isSequenceField = (f) => f.type === "number" && f.sequence === true;
138
+ /** 入力する項目か(計算の項目と連番を除く) */
139
+ const isInputField = (f) => !f.computed && !isSequenceField(f);
140
+ /** 役割ごとに受け付ける項目(宣言の検査と、宣言のないコレクションの推測で共通) */
141
+ const ROLE_ACCEPTS = {
142
+ 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")),
144
+ body: (f) => f.type === "rich_text",
145
+ summary: (f) => (f.type === "text" || f.type === "long_text") && !f.multiple,
146
+ date: (f) => f.type === "date" || f.type === "datetime",
147
+ months: (f) => f.type === "number" && isInputField(f)
148
+ };
149
+ ROLE_ACCEPTS.image, ROLE_ACCEPTS.body;
150
+ /** 役割の項目が受け付ける項目か(宣言の検査に使用) */
151
+ 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 };
@@ -0,0 +1 @@
1
+ export * from './types/sdk/src/model.js';
package/dist/model.js ADDED
@@ -0,0 +1,345 @@
1
+ import { p as collectionOf } from "./model-pmXzGX12.js";
2
+ import { a as cropRect, c as stillOf, i as coverStart, l as createClock, n as publicPathOf, o as croppedHotspot, r as coverPosition, s as objectPosition, t as pagePathOf, u as isDateOnly } from "./page-E_cYgZx-.js";
3
+ import { n as PRODUCT_FIELD_LABELS } from "./ja-C6lX0CeJ.js";
4
+ import { i as modelProblemText, r as parseModel } from "./schema-UQJWRyfJ.js";
5
+ import { t as typesSourceOf } from "./typesSource-bO0jFw1I.js";
6
+ import { z } from "zod";
7
+ // ../model/src/asset.ts
8
+ const unit = z.number().min(0).max(1);
9
+ /** 見せたい点の検査 */
10
+ const hotspotSchema = z.object({
11
+ x: unit,
12
+ y: unit,
13
+ width: unit.optional(),
14
+ height: unit.optional()
15
+ });
16
+ z.object({
17
+ top: unit,
18
+ bottom: unit,
19
+ left: unit,
20
+ right: unit
21
+ }).refine((c) => c.left + c.right <= .9 && c.top + c.bottom <= .9, modelProblemText("crop_too_large"));
22
+ const mediaBase = z.object({
23
+ src: z.string().min(1),
24
+ width: z.number().int().positive(),
25
+ height: z.number().int().positive(),
26
+ alt: z.string(),
27
+ hotspot: hotspotSchema.optional()
28
+ });
29
+ /** 解決後の素材の検査(src は URL、ビルドで読み込んだ画像は JSON に含めないため対象外) */
30
+ const mediaSchema = z.union([mediaBase.extend({ kind: z.literal("image") }), mediaBase.extend({
31
+ kind: z.literal("video"),
32
+ poster: mediaBase
33
+ })]);
34
+ z.object({ asset: z.string().min(1) });
35
+ // ../model/src/media.ts
36
+ const file = [
37
+ {
38
+ key: "mime_type",
39
+ label: PRODUCT_FIELD_LABELS.mimeType,
40
+ type: "text",
41
+ required: "save",
42
+ description: PRODUCT_FIELD_LABELS.mimeTypeDescription
43
+ },
44
+ {
45
+ key: "size",
46
+ label: PRODUCT_FIELD_LABELS.size,
47
+ type: "number",
48
+ required: "save",
49
+ description: PRODUCT_FIELD_LABELS.sizeDescription
50
+ },
51
+ {
52
+ key: "width",
53
+ label: PRODUCT_FIELD_LABELS.width,
54
+ type: "number",
55
+ required: "save",
56
+ description: "px"
57
+ },
58
+ {
59
+ key: "height",
60
+ label: PRODUCT_FIELD_LABELS.height,
61
+ type: "number",
62
+ required: "save",
63
+ description: "px"
64
+ },
65
+ {
66
+ key: "alt",
67
+ label: PRODUCT_FIELD_LABELS.alt,
68
+ type: "text",
69
+ description: PRODUCT_FIELD_LABELS.altDescription
70
+ }
71
+ ];
72
+ /** 画像のコレクション */
73
+ const IMAGE_TYPE = {
74
+ id: "image",
75
+ slug: "image",
76
+ label: PRODUCT_FIELD_LABELS.image,
77
+ description: PRODUCT_FIELD_LABELS.imageDescription,
78
+ fields: file
79
+ };
80
+ /** 動画のコレクション(配信と再生は最初に使用する場所が決まったときに実装) */
81
+ const VIDEO_TYPE = {
82
+ id: "video",
83
+ slug: "video",
84
+ label: PRODUCT_FIELD_LABELS.video,
85
+ fields: [
86
+ ...file,
87
+ {
88
+ key: "duration",
89
+ label: PRODUCT_FIELD_LABELS.duration,
90
+ type: "number",
91
+ description: PRODUCT_FIELD_LABELS.durationDescription
92
+ },
93
+ {
94
+ key: "poster",
95
+ label: PRODUCT_FIELD_LABELS.poster,
96
+ type: "media",
97
+ accept: ["image"],
98
+ description: PRODUCT_FIELD_LABELS.posterDescription
99
+ }
100
+ ]
101
+ };
102
+ // ../model/src/screens.ts
103
+ /** メニューのグループの id(運用のサイドバーのグループはこの1つだけ) */
104
+ const MENU_GROUP_ID = "collections";
105
+ const COLLECTION_PREFIX = "collection:";
106
+ /** メニュー項目の id(コレクション) */
107
+ const collectionItem = (collection) => `${COLLECTION_PREFIX}${collection}`;
108
+ /** メニューにある全項目の id(グループの中も、上から順) */
109
+ const menuItemsOf = (menu) => menu.flatMap((e) => typeof e === "string" ? [e] : e.items);
110
+ /** 編集画面に配置した項目の id(セクションの順) */
111
+ const placedItemsOf = (layout) => layout.sections.flatMap((s) => s.items);
112
+ const id = z.string().regex(/^[a-z][a-z0-9_:-]*$/, modelProblemText("invalid_screen_id"));
113
+ const item = z.string().min(1);
114
+ const unique = (values) => new Set(values).size === values.length;
115
+ const group = z.object({
116
+ id: z.literal(MENU_GROUP_ID),
117
+ collapsed: z.boolean().optional(),
118
+ items: z.array(item)
119
+ });
120
+ const section = z.object({
121
+ id,
122
+ label: z.string().trim(),
123
+ collapsed: z.boolean().optional(),
124
+ items: z.array(item)
125
+ });
126
+ const layout = z.object({
127
+ sections: z.array(section),
128
+ hidden: z.array(item).optional()
129
+ }).refine((l) => unique(l.sections.map((s) => s.id)), { message: modelProblemText("duplicate_section_id") }).refine((l) => unique([...placedItemsOf(l), ...l.hidden ?? []]), { message: modelProblemText("duplicate_placement") });
130
+ const screensSchema = z.object({
131
+ menu: z.array(z.union([item, group])).refine((m) => m.filter((e) => typeof e !== "string").length <= 1, { message: modelProblemText("duplicate_menu_group") }).refine((m) => unique(menuItemsOf(m)), { message: modelProblemText("duplicate_menu_item") }),
132
+ editors: z.record(z.string(), layout).default({}),
133
+ columns: z.record(z.string(), z.array(item).refine(unique, { message: modelProblemText("duplicate_column") })).default({})
134
+ });
135
+ /** 画面の設定の JSON を検査(形の誤りは ZodError) */
136
+ const parseScreens = (json) => screensSchema.parse(json);
137
+ // ../cms-contract/src/transfer.ts
138
+ /** スキーマと設定の形式の名前 */
139
+ const CONFIG_FORMAT = "cms-config";
140
+ /** 中立の既定のスキーマ(新しいプロジェクトの作成で適用するコレクション: post・author・tag・image・video、設定の移入の土台) */
141
+ const DEFAULT_SCHEMA = { collections: [
142
+ {
143
+ id: "post",
144
+ slug: "post",
145
+ label: "投稿",
146
+ publishing: "review",
147
+ roles: {
148
+ title: "title",
149
+ image: "image",
150
+ body: "body"
151
+ },
152
+ fields: [
153
+ {
154
+ key: "title",
155
+ label: "タイトル",
156
+ type: "text",
157
+ required: "save"
158
+ },
159
+ {
160
+ key: "writers",
161
+ label: "著者",
162
+ type: "reference",
163
+ to: "author",
164
+ multiple: true
165
+ },
166
+ {
167
+ key: "image",
168
+ label: "メインの画像",
169
+ type: "media",
170
+ accept: ["image"]
171
+ },
172
+ {
173
+ key: "body",
174
+ label: "本文",
175
+ type: "rich_text",
176
+ profile: {
177
+ headings: [
178
+ 2,
179
+ 3,
180
+ 4
181
+ ],
182
+ marks: [
183
+ "strong",
184
+ "em",
185
+ "code",
186
+ "strike"
187
+ ],
188
+ list: {
189
+ ordered: true,
190
+ nested: true
191
+ },
192
+ quote: {
193
+ multiple: true,
194
+ cite: true
195
+ },
196
+ code: { caption: false },
197
+ table: {
198
+ head: "optional",
199
+ caption: "optional"
200
+ },
201
+ divider: true,
202
+ components: ["gallery", "link-card"]
203
+ }
204
+ },
205
+ {
206
+ key: "revised_at",
207
+ label: "更新日時",
208
+ type: "datetime"
209
+ },
210
+ {
211
+ key: "tags",
212
+ label: "タグ",
213
+ type: "reference",
214
+ to: "tag",
215
+ multiple: true
216
+ },
217
+ {
218
+ key: "excerpt",
219
+ label: "抜粋",
220
+ type: "long_text",
221
+ computed: {
222
+ kind: "excerpt",
223
+ from: "body"
224
+ }
225
+ },
226
+ {
227
+ key: "read_min",
228
+ label: "読了の分",
229
+ type: "number",
230
+ computed: {
231
+ kind: "read_min",
232
+ from: "body"
233
+ }
234
+ },
235
+ {
236
+ key: "links",
237
+ label: "リンク先",
238
+ type: "text",
239
+ multiple: true,
240
+ computed: {
241
+ kind: "links",
242
+ from: "body"
243
+ }
244
+ }
245
+ ],
246
+ pages: [{
247
+ path: "/posts/{slug}",
248
+ public: [{
249
+ key: "status",
250
+ in: ["published"]
251
+ }, {
252
+ key: "published_at",
253
+ notFuture: true
254
+ }]
255
+ }]
256
+ },
257
+ {
258
+ id: "author",
259
+ slug: "author",
260
+ label: "著者",
261
+ roles: {
262
+ title: "name",
263
+ image: "portrait"
264
+ },
265
+ fields: [
266
+ {
267
+ key: "name",
268
+ label: "名前",
269
+ type: "text",
270
+ required: "save"
271
+ },
272
+ {
273
+ key: "bio",
274
+ label: "紹介",
275
+ type: "long_text"
276
+ },
277
+ {
278
+ key: "portrait",
279
+ label: "顔の画像",
280
+ type: "media",
281
+ accept: ["image"]
282
+ }
283
+ ],
284
+ pages: [{ path: "/authors/{slug}" }]
285
+ },
286
+ {
287
+ id: "tag",
288
+ slug: "tag",
289
+ label: "タグ",
290
+ roles: { title: "label" },
291
+ fields: [{
292
+ key: "label",
293
+ label: "名前",
294
+ type: "text",
295
+ required: "save"
296
+ }]
297
+ },
298
+ IMAGE_TYPE,
299
+ VIDEO_TYPE
300
+ ] };
301
+ /** 既定の画面設定(新しいプロジェクトの作成で適用する中立の値、移入する screens の土台) */
302
+ const DEFAULT_SCREENS = {
303
+ menu: [
304
+ "calendar",
305
+ {
306
+ id: "collections",
307
+ items: [
308
+ collectionItem("post"),
309
+ collectionItem("tag"),
310
+ collectionItem("author")
311
+ ]
312
+ },
313
+ "media"
314
+ ],
315
+ editors: { post: { sections: [
316
+ {
317
+ id: "classify",
318
+ label: "分類",
319
+ items: ["writers", "tags"]
320
+ },
321
+ {
322
+ id: "publish",
323
+ label: "公開",
324
+ items: ["published_at", "revised_at"]
325
+ },
326
+ {
327
+ id: "excerpt",
328
+ label: "説明",
329
+ items: ["excerpt"]
330
+ },
331
+ {
332
+ id: "image",
333
+ label: "メインの画像",
334
+ items: ["image"]
335
+ }
336
+ ] } },
337
+ columns: { post: [
338
+ "status",
339
+ "writers",
340
+ "assignee",
341
+ "published_at",
342
+ "updated_at"
343
+ ] }
344
+ };
345
+ export { CONFIG_FORMAT, DEFAULT_SCHEMA, DEFAULT_SCREENS, IMAGE_TYPE, VIDEO_TYPE, collectionOf, coverPosition, coverStart, createClock, cropRect, croppedHotspot, isDateOnly, mediaSchema, objectPosition, pagePathOf, parseModel, parseScreens, publicPathOf, stillOf, typesSourceOf };
@@ -0,0 +1,138 @@
1
+ // ../model/src/time.ts
2
+ const DATE_ONLY = /^\d{4}-\d{2}-\d{2}$/;
3
+ const SQLITE = /^\d{4}-\d{2}-\d{2} \d{2}:\d{2}:\d{2}(\.\d+)?$/;
4
+ const DAY_MS = 864e5;
5
+ /** 日付だけの値(`YYYY-MM-DD`)か */
6
+ const isDateOnly = (value) => DATE_ONLY.test(value);
7
+ /** タイムゾーンの日時の変換を作成 */
8
+ function createClock(timeZone) {
9
+ const format = new Intl.DateTimeFormat("en-CA", {
10
+ timeZone,
11
+ year: "numeric",
12
+ month: "2-digit",
13
+ day: "2-digit",
14
+ hour: "2-digit",
15
+ minute: "2-digit",
16
+ second: "2-digit",
17
+ hourCycle: "h23"
18
+ });
19
+ const partsOf = (ms) => Object.fromEntries(format.formatToParts(new Date(ms)).map((p) => [p.type, p.value]));
20
+ const offsetOf = (ms) => {
21
+ const p = partsOf(ms);
22
+ return Date.UTC(+p.year, +p.month - 1, +p.day, +p.hour, +p.minute, +p.second) - Math.floor(ms / 1e3) * 1e3;
23
+ };
24
+ const fromLocal = (date, time = "00:00") => {
25
+ const wall = Date.parse(`${date}T${time}:00Z`);
26
+ const first = wall - offsetOf(wall);
27
+ return new Date(wall - offsetOf(first)).toISOString();
28
+ };
29
+ const toDateTime = (value) => {
30
+ const ms = DATE_ONLY.test(value) ? Date.parse(fromLocal(value)) : SQLITE.test(value) ? Date.parse(`${value.replace(" ", "T")}Z`) : Date.parse(value);
31
+ return Number.isNaN(ms) ? null : new Date(ms).toISOString();
32
+ };
33
+ const local = (value) => partsOf(Date.parse(toDateTime(value) ?? value));
34
+ const dateOf = (value) => {
35
+ if (DATE_ONLY.test(value)) return value;
36
+ const p = local(value);
37
+ return `${p.year}-${p.month}-${p.day}`;
38
+ };
39
+ return {
40
+ nowIso: () => (/* @__PURE__ */ new Date()).toISOString(),
41
+ fromLocal,
42
+ toDateTime,
43
+ dateOf,
44
+ timeOf: (value) => {
45
+ const p = local(value);
46
+ return `${p.hour}:${p.minute}`;
47
+ },
48
+ endOfDay: (date) => (/* @__PURE__ */ new Date(Date.parse(fromLocal(new Date(Date.parse(`${date}T00:00:00Z`) + DAY_MS).toISOString().slice(0, 10))) - 1)).toISOString(),
49
+ today: (now = Date.now()) => dateOf(new Date(now).toISOString())
50
+ };
51
+ }
52
+ // ../model/src/image.ts
53
+ /** 静止画として表示する画像(動画は代わりの画像 poster) */
54
+ const stillOf = (media) => media.kind === "video" ? media.poster : media;
55
+ /** 見せたい点を CSS の object-position に(なしは undefined で中央、枠の比が分からない表示の代わり) */
56
+ const objectPosition = (hotspot) => hotspot && `${Math.round(hotspot.x * 1e3) / 10}% ${Math.round(hotspot.y * 1e3) / 10}%`;
57
+ /**
58
+ * 枠を覆う表示で、枠に見える範囲(窓)の始まりの位置: 1次元、画像に対する割合で0〜1 - window
59
+ * - 見せたい範囲の中心を窓の中央に寄せ、画像の端を越えるときは端と同じ位置
60
+ * - 範囲が窓に収まる大きさなら、この位置で範囲は必ず窓に入る(範囲が窓より大きいときは範囲の中央を表示)
61
+ * - center なしは中央、CMS のプレビュー(apps/admin の crop.ts)とサイトの表示で共通
62
+ */
63
+ function coverStart(center, window) {
64
+ const max = Math.max(0, 1 - window);
65
+ return center === void 0 ? max / 2 : Math.min(max, Math.max(0, center - window / 2));
66
+ }
67
+ /**
68
+ * 枠を覆う表示(object-fit: cover)の object-position: 見せたい範囲が枠に入る位置
69
+ * - size: 画像の幅と高さ、frame: 枠の幅 / 高さ(なしは見せたい点の百分率で代用)
70
+ * - 帯や余白はなし、枠いっぱいに画像を敷いたまま位置だけを合わせる
71
+ */
72
+ function coverPosition(hotspot, size, frame) {
73
+ if (!hotspot) return void 0;
74
+ if (!frame) return objectPosition(hotspot);
75
+ const ratio = size.width / size.height;
76
+ const [ww, wh] = ratio > frame ? [frame / ratio, 1] : [1, ratio / frame];
77
+ const percent = (center, window) => window >= 1 ? 50 : Math.round(coverStart(center, window) / (1 - window) * 1e3) / 10;
78
+ return `${percent(hotspot.x, ww)}% ${percent(hotspot.y, wh)}%`;
79
+ }
80
+ /** 切り抜きの割合から、元画像での画素の範囲 */
81
+ function cropRect(width, height, crop) {
82
+ return {
83
+ left: Math.round(width * crop.left),
84
+ top: Math.round(height * crop.top),
85
+ width: Math.max(1, Math.round(width * (1 - crop.left - crop.right))),
86
+ height: Math.max(1, Math.round(height * (1 - crop.top - crop.bottom)))
87
+ };
88
+ }
89
+ const unit = (v) => Math.round(Math.min(1, Math.max(0, v)) * 1e4) / 1e4;
90
+ /** 元の画像に対する見せたい点を、切り抜いた後の画像に対する割合に変換(範囲の外は端に寄せる) */
91
+ function croppedHotspot(hotspot, crop) {
92
+ const w = 1 - crop.left - crop.right;
93
+ const h = 1 - crop.top - crop.bottom;
94
+ return {
95
+ x: unit((hotspot.x - crop.left) / w),
96
+ y: unit((hotspot.y - crop.top) / h),
97
+ ...hotspot.width !== void 0 && hotspot.height !== void 0 ? {
98
+ width: unit(hotspot.width / w),
99
+ height: unit(hotspot.height / h)
100
+ } : {}
101
+ };
102
+ }
103
+ // ../model/src/page.ts
104
+ const matches = (when, record) => !when || when.in.includes(String(record[when.key]));
105
+ const passes = (rule, record, now) => {
106
+ const v = record[rule.key];
107
+ if ("in" in rule) return rule.in.includes(String(v ?? ""));
108
+ if ("notIn" in rule) return !rule.notIn.includes(String(v ?? ""));
109
+ if ("truthy" in rule) return Boolean(v);
110
+ return v === void 0 || v === null || v === "" || String(v) <= now;
111
+ };
112
+ /** レコードに当てはまるページの宣言(なければ null) */
113
+ const pageOf = (collection, record) => collection.pages?.find((p) => matches(p.when, record)) ?? null;
114
+ /** 雛形の {key} をレコードの値に置き換え(値がなければ null) */
115
+ const fill = (path, record) => {
116
+ let missing = false;
117
+ const filled = path.replace(/\{([A-Za-z0-9_-]+)\}/g, (_, key) => {
118
+ const v = record[key];
119
+ if (v === void 0 || v === null) missing = true;
120
+ return String(v ?? "");
121
+ });
122
+ return missing ? null : filled;
123
+ };
124
+ /** ページのパス(ページのないコレクション・レコードは null、公開の状態は見ない) */
125
+ function pagePathOf(collection, record) {
126
+ const page = pageOf(collection, record);
127
+ return page ? fill(page.path, record) : null;
128
+ }
129
+ /** レコードがサイトで公開中のページを持つか(雛形の値は見ない、作成前の入力にも使用、now は今の時刻の ISO 文字列) */
130
+ function hasPublicPage(collection, record, now) {
131
+ const page = pageOf(collection, record);
132
+ return page !== null && (page.public ?? []).every((r) => passes(r, record, now));
133
+ }
134
+ /** 公開中のページのパス(公開前・予約中・ページのないレコードは null、now は今の時刻の ISO 文字列) */
135
+ function publicPathOf(collection, record, now) {
136
+ return hasPublicPage(collection, record, now) ? pagePathOf(collection, record) : null;
137
+ }
138
+ export { cropRect as a, stillOf as c, coverStart as i, createClock as l, publicPathOf as n, croppedHotspot as o, coverPosition as r, objectPosition as s, pagePathOf as t, isDateOnly as u };
@@ -0,0 +1 @@
1
+ export * from './types/sdk/src/preview.js';
@@ -0,0 +1 @@
1
+ export { n as SIGNED_HEADERS } from "./src-sazhzYui.js";