@tunasand/sdk 0.0.0-stage → 0.7.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/CHANGELOG.md +114 -0
- package/README.md +516 -2
- package/dist/analytics.d.ts +1 -0
- package/dist/analytics.js +43 -0
- package/dist/app.d.ts +1 -0
- package/dist/app.js +825 -0
- package/dist/apps-9u4XMi7E.js +114 -0
- package/dist/body.d.ts +1 -0
- package/dist/body.js +455 -0
- package/dist/bridge-DYAYGV7t.js +74 -0
- package/dist/bridge.d.ts +1 -0
- package/dist/bridge.js +189 -0
- package/dist/cli.d.ts +1 -0
- package/dist/cli.js +283 -0
- package/dist/client-Derrexwr.js +159 -0
- package/dist/customers-C_vJY2_v.js +84 -0
- package/dist/customers.d.ts +1 -0
- package/dist/customers.js +185 -0
- package/dist/declared-C_GvPiGF.js +397 -0
- package/dist/delivery.d.ts +1 -0
- package/dist/delivery.js +394 -0
- package/dist/dev.d.ts +1 -0
- package/dist/dev.js +93 -0
- package/dist/embed-R-OvDYAw.js +90 -0
- package/dist/errorLabels-CPKiPabZ.js +1510 -0
- package/dist/i18n.d.ts +1 -0
- package/dist/i18n.js +4 -0
- package/dist/integrations.d.ts +1 -0
- package/dist/integrations.js +62 -0
- package/dist/ja-C1HEWWTQ.js +241 -0
- package/dist/ja-C6lX0CeJ.js +213 -0
- package/dist/model-pmXzGX12.js +152 -0
- package/dist/model.d.ts +1 -0
- package/dist/model.js +345 -0
- package/dist/page-E_cYgZx-.js +138 -0
- package/dist/preview.d.ts +1 -0
- package/dist/preview.js +1 -0
- package/dist/profile-D6t1QMQh.js +223 -0
- package/dist/schema-BPHL7Qr-.js +115 -0
- package/dist/schema-UQJWRyfJ.js +995 -0
- package/dist/schema.d.ts +1 -0
- package/dist/schema.js +1 -0
- package/dist/src-sazhzYui.js +71 -0
- package/dist/types/access/src/handoff.d.ts +52 -0
- package/dist/types/access/src/index.d.ts +5 -0
- package/dist/types/access/src/jws.d.ts +5 -0
- package/dist/types/access/src/jwt.d.ts +35 -0
- package/dist/types/access/src/oidc.d.ts +50 -0
- package/dist/types/access/src/signed.d.ts +15 -0
- package/dist/types/analytics/src/day.d.ts +2 -0
- package/dist/types/analytics/src/index.d.ts +5 -0
- package/dist/types/analytics/src/schedule.d.ts +2 -0
- package/dist/types/analytics/src/shared.d.ts +21 -0
- package/dist/types/analytics/src/source.d.ts +19 -0
- package/dist/types/analytics/src/store.d.ts +24 -0
- package/dist/types/analytics/src/view.d.ts +33 -0
- package/dist/types/body/src/components.d.ts +25 -0
- package/dist/types/body/src/declared.d.ts +34 -0
- package/dist/types/body/src/derive.d.ts +13 -0
- package/dist/types/body/src/description.d.ts +8 -0
- package/dist/types/body/src/embed.d.ts +16 -0
- package/dist/types/body/src/href.d.ts +4 -0
- package/dist/types/body/src/html.d.ts +30 -0
- package/dist/types/body/src/index.d.ts +19 -0
- package/dist/types/body/src/inline.d.ts +20 -0
- package/dist/types/body/src/labels/en.d.ts +90 -0
- package/dist/types/body/src/labels/ja.d.ts +153 -0
- package/dist/types/body/src/library.d.ts +113 -0
- package/dist/types/body/src/markdown.d.ts +14 -0
- package/dist/types/body/src/normalize.d.ts +5 -0
- package/dist/types/body/src/problems.d.ts +103 -0
- package/dist/types/body/src/profile.d.ts +80 -0
- package/dist/types/body/src/render.d.ts +29 -0
- package/dist/types/body/src/schema.d.ts +6 -0
- package/dist/types/body/src/standard.d.ts +20 -0
- package/dist/types/body/src/types.d.ts +140 -0
- package/dist/types/cms-contract/src/apiKeys.d.ts +41 -0
- package/dist/types/cms-contract/src/app.d.ts +35 -0
- package/dist/types/cms-contract/src/appDependencies.d.ts +265 -0
- package/dist/types/cms-contract/src/appProblems.d.ts +22 -0
- package/dist/types/cms-contract/src/apps.d.ts +195 -0
- package/dist/types/cms-contract/src/assets.d.ts +12 -0
- package/dist/types/cms-contract/src/authorize.d.ts +146 -0
- package/dist/types/cms-contract/src/bridge.d.ts +318 -0
- package/dist/types/cms-contract/src/consents.d.ts +97 -0
- package/dist/types/cms-contract/src/customerLabels.d.ts +33 -0
- package/dist/types/cms-contract/src/customers.d.ts +266 -0
- package/dist/types/cms-contract/src/embeds.d.ts +165 -0
- package/dist/types/cms-contract/src/errorLabels.d.ts +269 -0
- package/dist/types/cms-contract/src/errorLabelsEn.d.ts +228 -0
- package/dist/types/cms-contract/src/errors.d.ts +105 -0
- package/dist/types/cms-contract/src/failureStatus.d.ts +124 -0
- package/dist/types/cms-contract/src/functionLabels.d.ts +5 -0
- package/dist/types/cms-contract/src/functions.d.ts +144 -0
- package/dist/types/cms-contract/src/identifiers.d.ts +117 -0
- package/dist/types/cms-contract/src/import.d.ts +277 -0
- package/dist/types/cms-contract/src/issueLabels.d.ts +435 -0
- package/dist/types/cms-contract/src/issueLabelsEn.d.ts +217 -0
- package/dist/types/cms-contract/src/migration.d.ts +103 -0
- package/dist/types/cms-contract/src/paths.d.ts +23 -0
- package/dist/types/cms-contract/src/permissionLabels.d.ts +8 -0
- package/dist/types/cms-contract/src/permissions.d.ts +77 -0
- package/dist/types/cms-contract/src/problems.d.ts +34 -0
- package/dist/types/cms-contract/src/roles.d.ts +57 -0
- package/dist/types/cms-contract/src/settingProblems.d.ts +13 -0
- package/dist/types/cms-contract/src/settings.d.ts +19 -0
- package/dist/types/cms-contract/src/siteArtifact.d.ts +45 -0
- package/dist/types/cms-contract/src/siteDeclaration.d.ts +70 -0
- package/dist/types/cms-contract/src/transfer.d.ts +57 -0
- package/dist/types/cms-contract/src/urlLabel.d.ts +13 -0
- package/dist/types/cms-contract/src/views.d.ts +21 -0
- package/dist/types/cms-contract/src/webhookLabels.d.ts +7 -0
- package/dist/types/cms-contract/src/webhooks.d.ts +139 -0
- package/dist/types/i18n/src/index.d.ts +50 -0
- package/dist/types/i18n/src/problems.d.ts +21 -0
- package/dist/types/model/src/asset.d.ts +111 -0
- package/dist/types/model/src/audience.d.ts +38 -0
- package/dist/types/model/src/brand.d.ts +25 -0
- package/dist/types/model/src/capabilities.d.ts +28 -0
- package/dist/types/model/src/changes.d.ts +34 -0
- package/dist/types/model/src/check.d.ts +15 -0
- package/dist/types/model/src/contact.d.ts +22 -0
- package/dist/types/model/src/image.d.ts +38 -0
- package/dist/types/model/src/index.d.ts +26 -0
- package/dist/types/model/src/input.d.ts +26 -0
- package/dist/types/model/src/integrity.d.ts +79 -0
- package/dist/types/model/src/json.d.ts +2 -0
- package/dist/types/model/src/labels/en.d.ts +169 -0
- package/dist/types/model/src/labels/ja.d.ts +198 -0
- package/dist/types/model/src/legacy.d.ts +2 -0
- package/dist/types/model/src/media.d.ts +5 -0
- package/dist/types/model/src/mediaUrl.d.ts +67 -0
- package/dist/types/model/src/model.d.ts +415 -0
- package/dist/types/model/src/page.d.ts +52 -0
- package/dist/types/model/src/problems.d.ts +184 -0
- package/dist/types/model/src/refs.d.ts +27 -0
- package/dist/types/model/src/rules.d.ts +15 -0
- package/dist/types/model/src/schema.d.ts +58 -0
- package/dist/types/model/src/screens.d.ts +76 -0
- package/dist/types/model/src/selfOps.d.ts +30 -0
- package/dist/types/model/src/time.d.ts +25 -0
- package/dist/types/model/src/typesSource.d.ts +8 -0
- package/dist/types/model/src/values.d.ts +24 -0
- package/dist/types/platform/src/defaultModel.d.ts +8 -0
- package/dist/types/sdk/src/analytics.d.ts +2 -0
- package/dist/types/sdk/src/app.d.ts +20 -0
- package/dist/types/sdk/src/body.d.ts +2 -0
- package/dist/types/sdk/src/bridge.d.ts +92 -0
- package/dist/types/sdk/src/cli.d.ts +2 -0
- package/dist/types/sdk/src/customers.d.ts +190 -0
- package/dist/types/sdk/src/delivery/cache.d.ts +18 -0
- package/dist/types/sdk/src/delivery/changes.d.ts +28 -0
- package/dist/types/sdk/src/delivery/client.d.ts +90 -0
- package/dist/types/sdk/src/delivery/fields.d.ts +48 -0
- package/dist/types/sdk/src/delivery/index.d.ts +9 -0
- package/dist/types/sdk/src/delivery/media.d.ts +28 -0
- package/dist/types/sdk/src/delivery/query.d.ts +85 -0
- package/dist/types/sdk/src/delivery/schema.d.ts +19 -0
- package/dist/types/sdk/src/delivery/values.d.ts +82 -0
- package/dist/types/sdk/src/delivery.d.ts +3 -0
- package/dist/types/sdk/src/dev.d.ts +29 -0
- package/dist/types/sdk/src/i18n.d.ts +12 -0
- package/dist/types/sdk/src/integrations.d.ts +33 -0
- package/dist/types/sdk/src/model.d.ts +5 -0
- package/dist/types/sdk/src/preview.d.ts +1 -0
- package/dist/types/sdk/src/schema.d.ts +21 -0
- package/dist/types/sdk/src/site.d.ts +43 -0
- package/dist/typesSource-bO0jFw1I.js +88 -0
- package/package.json +86 -3
|
@@ -0,0 +1,114 @@
|
|
|
1
|
+
import { n as fieldDefSchema, t as RESERVED_FIELD_KEYS } from "./schema-UQJWRyfJ.js";
|
|
2
|
+
import "./customers-C_vJY2_v.js";
|
|
3
|
+
import { z } from "zod";
|
|
4
|
+
// ../cms-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-z0-9_]{0,63}$/;
|
|
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
|
+
}).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"] });
|
|
45
|
+
const collectionSchema = z.strictObject({
|
|
46
|
+
name: z.string().regex(COLLECTION_NAME),
|
|
47
|
+
label,
|
|
48
|
+
internal: z.boolean().optional(),
|
|
49
|
+
private: z.boolean().optional(),
|
|
50
|
+
fields: list(fieldDefSchema)
|
|
51
|
+
});
|
|
52
|
+
z.object({
|
|
53
|
+
major: z.number().int().positive().optional(),
|
|
54
|
+
requires: list(dependencySchema).optional(),
|
|
55
|
+
uses: list(z.strictObject({
|
|
56
|
+
port: z.string().regex(PORT_ID),
|
|
57
|
+
required: z.boolean()
|
|
58
|
+
})).optional(),
|
|
59
|
+
provides: list(z.strictObject({
|
|
60
|
+
port: z.string().regex(PORT_ID),
|
|
61
|
+
route: z.string().startsWith("/api/").max(2048)
|
|
62
|
+
})).optional(),
|
|
63
|
+
collections: list(collectionSchema).optional(),
|
|
64
|
+
settings: list(settingSchema).optional(),
|
|
65
|
+
price: z.strictObject({
|
|
66
|
+
setup: yen.optional(),
|
|
67
|
+
monthly: yen.optional(),
|
|
68
|
+
usage: z.string().trim().min(1).max(APP_DEPENDENCY_LIMITS.textMax).optional(),
|
|
69
|
+
currency: z.literal("JPY")
|
|
70
|
+
}).optional()
|
|
71
|
+
});
|
|
72
|
+
// ../cms-contract/src/authorize.ts
|
|
73
|
+
/** 判定の操作(コレクションの操作と顧客の操作) */
|
|
74
|
+
const OPERATIONS = [
|
|
75
|
+
"read",
|
|
76
|
+
"read_drafts",
|
|
77
|
+
"read_customers",
|
|
78
|
+
"create",
|
|
79
|
+
"update",
|
|
80
|
+
"publish",
|
|
81
|
+
"delete",
|
|
82
|
+
"submit",
|
|
83
|
+
"verify",
|
|
84
|
+
"read_state",
|
|
85
|
+
"link",
|
|
86
|
+
"create_candidate",
|
|
87
|
+
"issue_token",
|
|
88
|
+
"refresh_token",
|
|
89
|
+
"migrate_links",
|
|
90
|
+
"read_identities",
|
|
91
|
+
"write_grants",
|
|
92
|
+
"update_status",
|
|
93
|
+
"read_display_name",
|
|
94
|
+
"read_consents",
|
|
95
|
+
"check_consent",
|
|
96
|
+
"write_consents",
|
|
97
|
+
"write_suppression",
|
|
98
|
+
"read_self",
|
|
99
|
+
"create_self",
|
|
100
|
+
"update_self",
|
|
101
|
+
"delete_self"
|
|
102
|
+
];
|
|
103
|
+
// ../cms-contract/src/apps.ts
|
|
104
|
+
/**
|
|
105
|
+
* アプリの鍵の用途(登録する公開鍵の JWK の use)
|
|
106
|
+
* - runtime: アプリの JWT をインストールのトークンに交換する鍵(サイトの実行時に持つ。use なしか sig)
|
|
107
|
+
* - deploy: ホスティングするサイトへのアップロードだけに使う鍵(サイトの実行時に持たせない。交換には使えない)
|
|
108
|
+
*/
|
|
109
|
+
const APP_KEY_USES = {
|
|
110
|
+
runtime: "sig",
|
|
111
|
+
deploy: "tunasand-deploy"
|
|
112
|
+
};
|
|
113
|
+
new Set(OPERATIONS);
|
|
114
|
+
export { APP_KEY_USES as t };
|
package/dist/body.d.ts
ADDED
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export * from './types/sdk/src/body.js';
|
package/dist/body.js
ADDED
|
@@ -0,0 +1,455 @@
|
|
|
1
|
+
import { i as bodyProblemText, n as embedOfUrl, r as embedSrcOf, t as EMBED_PROVIDERS } from "./embed-R-OvDYAw.js";
|
|
2
|
+
import { a as coreComponentOf, n as declaredPropsZod, r as CITE } from "./declared-C_GvPiGF.js";
|
|
3
|
+
import { c as ALIGNS, i as MARK_HTML_TAGS, l as cellParagraphs, n as isSafeCssValue, o as sortMarks, s as isSafeHref, t as checkBody, u as isTableCell } from "./profile-D6t1QMQh.js";
|
|
4
|
+
import { z } from "zod";
|
|
5
|
+
// ../body/src/description.ts
|
|
6
|
+
/** meta description の長さの上限(検索結果で省略されにくい字数の目安) */
|
|
7
|
+
const DESCRIPTION_MAX = 120;
|
|
8
|
+
/**
|
|
9
|
+
* 説明を meta description の長さに調整
|
|
10
|
+
* - 上限を超える場合: 上限までの最後の句点まで
|
|
11
|
+
* - 句点がない場合: 上限で切って省略の記号
|
|
12
|
+
*/
|
|
13
|
+
function descriptionOf(excerpt, max = 120) {
|
|
14
|
+
if ([...excerpt].length <= max) return excerpt;
|
|
15
|
+
const head = [...excerpt].slice(0, max).join("");
|
|
16
|
+
const end = head.lastIndexOf("。");
|
|
17
|
+
return end > 0 ? head.slice(0, end + 1) : `${[...head].slice(0, max - 1).join("")}…`;
|
|
18
|
+
}
|
|
19
|
+
// ../body/src/derive.ts
|
|
20
|
+
/** 読了時間の既定の分速(字/分) */
|
|
21
|
+
const READING_SPEED = 500;
|
|
22
|
+
const listRich = (list) => list.items.flatMap((i) => [i.content, ...i.children ? listRich(i.children) : []]);
|
|
23
|
+
/** 本文にある断片の列(段落・見出し・リスト・引用・表のセル) */
|
|
24
|
+
function richIn(body) {
|
|
25
|
+
return body.flatMap((b) => {
|
|
26
|
+
switch (b.type) {
|
|
27
|
+
case "paragraph":
|
|
28
|
+
case "heading": return [b.content];
|
|
29
|
+
case "list": return listRich(b);
|
|
30
|
+
case "quote": return [...b.content];
|
|
31
|
+
case "table": return [...b.head ?? [], ...b.rows.flat().flatMap(cellParagraphs)];
|
|
32
|
+
default: return [];
|
|
33
|
+
}
|
|
34
|
+
});
|
|
35
|
+
}
|
|
36
|
+
/** 断片の列の文字(装飾・リンクは文字、インラインのコンポーネントは中の文字) */
|
|
37
|
+
const plainOf = (rich) => rich.map((i) => typeof i === "string" ? i : i.text ?? "").join("");
|
|
38
|
+
/** 本文の注が参照する出典の ID(出現の順、重複あり) */
|
|
39
|
+
function citesOf(body) {
|
|
40
|
+
return richIn(body).flatMap((rich) => rich.flatMap((i) => typeof i === "object" && "component" in i && i.component === "cite" && i.props?.id ? [i.props.id] : []));
|
|
41
|
+
}
|
|
42
|
+
/** 本文の導入の文字(最初の見出しまでの段落をつなげたもの、導入がなければ空) */
|
|
43
|
+
function excerptOf(body) {
|
|
44
|
+
const end = body.findIndex((b) => b.type === "heading");
|
|
45
|
+
return (end < 0 ? body : body.slice(0, end)).flatMap((b) => b.type === "paragraph" ? [plainOf(b.content).replaceAll("\n", "").trim()] : []).filter(Boolean).join("");
|
|
46
|
+
}
|
|
47
|
+
/** 字数に数えない項目(ブロック・コンポーネント・表示の種類・装飾の名前、保存の形に依存する文字) */
|
|
48
|
+
const UNREAD = /* @__PURE__ */ new Set([
|
|
49
|
+
"type",
|
|
50
|
+
"name",
|
|
51
|
+
"component",
|
|
52
|
+
"variant",
|
|
53
|
+
"marks",
|
|
54
|
+
"style",
|
|
55
|
+
"align",
|
|
56
|
+
"colspan",
|
|
57
|
+
"rowspan",
|
|
58
|
+
"header"
|
|
59
|
+
]);
|
|
60
|
+
const chars = (v) => typeof v === "string" ? v.length : Array.isArray(v) ? v.reduce((n, x) => n + chars(x), 0) : v && typeof v === "object" ? Object.entries(v).reduce((n, [k, x]) => n + (UNREAD.has(k) ? 0 : chars(x)), 0) : 0;
|
|
61
|
+
/** 読了時間(分、本文の文字列の字数を分速 speed で割った概算、1分以上) */
|
|
62
|
+
const readMinOf = (body, speed = 500) => Math.max(1, Math.round(chars(body) / speed));
|
|
63
|
+
const hrefs = (v) => Array.isArray(v) ? v.flatMap(hrefs) : v && typeof v === "object" ? Object.entries(v).flatMap(([k, x]) => k === "href" && typeof x === "string" ? [x] : hrefs(x)) : [];
|
|
64
|
+
/** 本文にあるサイト内へのリンク先(`/` で始まる href、重複なし) */
|
|
65
|
+
const linksOf = (body) => [...new Set(hrefs(body).filter((h) => h.startsWith("/")))];
|
|
66
|
+
// ../body/src/render.ts
|
|
67
|
+
const ESCAPES = {
|
|
68
|
+
"&": "&",
|
|
69
|
+
"<": "<",
|
|
70
|
+
">": ">",
|
|
71
|
+
"\"": """,
|
|
72
|
+
"'": "'"
|
|
73
|
+
};
|
|
74
|
+
const esc = (s) => s.replace(/[&<>"']/g, (c) => ESCAPES[c]);
|
|
75
|
+
const attrs = (pairs) => Object.entries(pairs).filter(([, v]) => v !== void 0 && v !== null && v !== false && v !== "").map(([k, v]) => ` ${k}="${esc(String(v))}"`).join("");
|
|
76
|
+
const CSS_PROPERTY = {
|
|
77
|
+
color: "color",
|
|
78
|
+
background: "background-color",
|
|
79
|
+
size: "font-size"
|
|
80
|
+
};
|
|
81
|
+
/** iframe の許可(サービスの再生に要るものだけ) */
|
|
82
|
+
const EMBED_SANDBOX = "allow-scripts allow-same-origin allow-popups allow-presentation";
|
|
83
|
+
const EMBED_ALLOW = "encrypted-media; picture-in-picture; fullscreen";
|
|
84
|
+
/** 本文を HTML に */
|
|
85
|
+
function bodyToHtml(body, options) {
|
|
86
|
+
const styleAttr = (style) => {
|
|
87
|
+
const decls = Object.keys(CSS_PROPERTY).flatMap((kind) => {
|
|
88
|
+
const v = style[kind];
|
|
89
|
+
if (!v) return [];
|
|
90
|
+
const value = (v.name ? options.named?.(kind, v.name) : void 0) ?? v.value;
|
|
91
|
+
return value && isSafeCssValue(kind, value) ? [`${CSS_PROPERTY[kind]}: ${value}`] : [];
|
|
92
|
+
});
|
|
93
|
+
const classes = (style.styles ?? []).map((n) => options.styleClass?.(n) ?? n);
|
|
94
|
+
return attrs({
|
|
95
|
+
class: classes.join(" "),
|
|
96
|
+
style: decls.join("; ")
|
|
97
|
+
});
|
|
98
|
+
};
|
|
99
|
+
const linkOpen = (link) => isSafeHref(link.href) ? `<a${attrs({
|
|
100
|
+
href: link.href,
|
|
101
|
+
title: link.title,
|
|
102
|
+
target: link.target,
|
|
103
|
+
rel: link.target ? [.../* @__PURE__ */ new Set([...link.rel?.split(/\s+/) ?? [], "noopener"])].join(" ") : link.rel
|
|
104
|
+
})}>` : null;
|
|
105
|
+
const inline = (i) => {
|
|
106
|
+
if (typeof i === "string") return esc(i).replaceAll("\n", "<br>");
|
|
107
|
+
if ("component" in i) return options.inlineComponent?.(i.component, i.props ?? {}, i.text ?? "") ?? esc(i.text ?? "");
|
|
108
|
+
let html = esc(i.text).replaceAll("\n", "<br>");
|
|
109
|
+
for (const m of sortMarks(i.marks).reverse()) html = `<${MARK_HTML_TAGS[m]}>${html}</${MARK_HTML_TAGS[m]}>`;
|
|
110
|
+
if (i.style) {
|
|
111
|
+
const a = styleAttr(i.style);
|
|
112
|
+
if (a) html = `<span${a}>${html}</span>`;
|
|
113
|
+
}
|
|
114
|
+
if (i.link) {
|
|
115
|
+
const open = linkOpen(i.link);
|
|
116
|
+
if (open) html = `${open}${html}</a>`;
|
|
117
|
+
}
|
|
118
|
+
return html;
|
|
119
|
+
};
|
|
120
|
+
const rich = (r) => r.map(inline).join("");
|
|
121
|
+
const list = (l) => {
|
|
122
|
+
const tag = l.ordered ? "ol" : "ul";
|
|
123
|
+
return `<${tag}${attrs({ class: l.variant })}>${l.items.map((item) => `<li>${rich(item.content)}${item.children ? list(item.children) : ""}</li>`).join("")}</${tag}>`;
|
|
124
|
+
};
|
|
125
|
+
const cell = (c, header) => {
|
|
126
|
+
if (!isTableCell(c)) return `<${header ? "th" : "td"}>${rich(c)}</${header ? "th" : "td"}>`;
|
|
127
|
+
const tag = c.header || header ? "th" : "td";
|
|
128
|
+
const content = c.content.length > 1 ? c.content.map((p) => `<p>${rich(p)}</p>`).join("") : rich(c.content[0] ?? []);
|
|
129
|
+
return `<${tag}${attrs({
|
|
130
|
+
colspan: c.colspan,
|
|
131
|
+
rowspan: c.rowspan,
|
|
132
|
+
style: c.align ? `text-align: ${c.align}` : void 0
|
|
133
|
+
})}>${content}</${tag}>`;
|
|
134
|
+
};
|
|
135
|
+
const imageHtml = (media, alt) => {
|
|
136
|
+
const img = options.image(media);
|
|
137
|
+
if (!img || !isSafeHref(img.url)) return null;
|
|
138
|
+
return `<img${attrs({
|
|
139
|
+
src: img.url,
|
|
140
|
+
width: img.width,
|
|
141
|
+
height: img.height,
|
|
142
|
+
alt: alt ?? img.alt ?? "",
|
|
143
|
+
loading: "lazy"
|
|
144
|
+
})}>`;
|
|
145
|
+
};
|
|
146
|
+
const component = (b) => {
|
|
147
|
+
const custom = options.component?.(b, render);
|
|
148
|
+
if (custom !== null && custom !== void 0) return custom;
|
|
149
|
+
const p = b.props ?? {};
|
|
150
|
+
switch (b.name) {
|
|
151
|
+
case "embed": {
|
|
152
|
+
const provider = p.provider;
|
|
153
|
+
const id = typeof p.id === "string" ? p.id : "";
|
|
154
|
+
if (!id) return "";
|
|
155
|
+
const src = embedSrcOf({
|
|
156
|
+
provider,
|
|
157
|
+
id,
|
|
158
|
+
...typeof p.start === "number" ? { start: p.start } : {}
|
|
159
|
+
});
|
|
160
|
+
return `<div${attrs({
|
|
161
|
+
class: "embed",
|
|
162
|
+
"data-provider": provider
|
|
163
|
+
})}><iframe${attrs({
|
|
164
|
+
src,
|
|
165
|
+
title: typeof p.title === "string" ? p.title : provider,
|
|
166
|
+
width: p.width,
|
|
167
|
+
height: p.height,
|
|
168
|
+
loading: "lazy",
|
|
169
|
+
sandbox: EMBED_SANDBOX,
|
|
170
|
+
allow: EMBED_ALLOW,
|
|
171
|
+
referrerpolicy: "strict-origin-when-cross-origin"
|
|
172
|
+
})}></iframe></div>`;
|
|
173
|
+
}
|
|
174
|
+
case "link-card": {
|
|
175
|
+
const href = typeof p.href === "string" ? p.href : void 0;
|
|
176
|
+
if (!href || !isSafeHref(href)) return "";
|
|
177
|
+
const image = p.image ? imageHtml(p.image, "") : null;
|
|
178
|
+
const text = (cls, v) => typeof v === "string" && v ? `<span${attrs({ class: cls })}>${esc(v)}</span>` : "";
|
|
179
|
+
return `<a${attrs({
|
|
180
|
+
class: "link-card",
|
|
181
|
+
href
|
|
182
|
+
})}>${image ?? ""}${text("link-card-title", p.title)}${text("link-card-desc", p.desc)}${text("link-card-site", p.site)}</a>`;
|
|
183
|
+
}
|
|
184
|
+
case "gallery": return `<div class="gallery">${(Array.isArray(p.items) ? p.items : []).map((i) => `<figure>${imageHtml(i.media, void 0) ?? ""}${i.caption ? `<figcaption>${esc(i.caption)}</figcaption>` : ""}</figure>`).join("")}</div>`;
|
|
185
|
+
default: return "";
|
|
186
|
+
}
|
|
187
|
+
};
|
|
188
|
+
const block = (b) => {
|
|
189
|
+
switch (b.type) {
|
|
190
|
+
case "paragraph": return `<p${attrs({
|
|
191
|
+
class: b.variant,
|
|
192
|
+
style: b.align ? `text-align: ${b.align}` : void 0
|
|
193
|
+
})}>${rich(b.content)}</p>`;
|
|
194
|
+
case "heading": return `<h${b.level}${attrs({
|
|
195
|
+
id: b.id,
|
|
196
|
+
class: b.variant,
|
|
197
|
+
style: b.align ? `text-align: ${b.align}` : void 0
|
|
198
|
+
})}>${rich(b.content)}</h${b.level}>`;
|
|
199
|
+
case "list": return list(b);
|
|
200
|
+
case "quote": {
|
|
201
|
+
const cite = b.cite ? `<cite>${b.cite.href && isSafeHref(b.cite.href) ? `<a${attrs({ href: b.cite.href })}>${esc(b.cite.label)}</a>` : esc(b.cite.label)}</cite>` : "";
|
|
202
|
+
return `<blockquote${attrs({ class: b.variant })}>${b.content.map((p) => `<p>${rich(p)}</p>`).join("")}${cite}</blockquote>`;
|
|
203
|
+
}
|
|
204
|
+
case "code": {
|
|
205
|
+
const pre = `<pre${attrs({ "data-filename": b.filename })}><code${attrs({ class: b.lang ? `language-${b.lang}` : void 0 })}>${esc(b.code)}</code></pre>`;
|
|
206
|
+
return b.caption ? `<figure${attrs({ class: b.variant })}>${pre}<figcaption>${esc(b.caption)}</figcaption></figure>` : pre;
|
|
207
|
+
}
|
|
208
|
+
case "image": {
|
|
209
|
+
const img = imageHtml(b.media, b.alt);
|
|
210
|
+
if (!img) return "";
|
|
211
|
+
const open = b.link ? linkOpen(b.link) : null;
|
|
212
|
+
return `<figure${attrs({
|
|
213
|
+
class: b.variant,
|
|
214
|
+
style: b.align ? `text-align: ${b.align}` : void 0
|
|
215
|
+
})}>${open ? `${open}${img}</a>` : img}${b.caption ? `<figcaption>${esc(b.caption)}</figcaption>` : ""}</figure>`;
|
|
216
|
+
}
|
|
217
|
+
case "table": {
|
|
218
|
+
const head = b.head ? `<thead><tr>${b.head.map((h) => cell(h, true)).join("")}</tr></thead>` : "";
|
|
219
|
+
const rows = `<tbody>${b.rows.map((r) => `<tr>${r.map((c) => cell(c, false)).join("")}</tr>`).join("")}</tbody>`;
|
|
220
|
+
return `<table${attrs({ class: b.variant })}>${b.caption ? `<caption>${esc(b.caption)}</caption>` : ""}${head}${rows}</table>`;
|
|
221
|
+
}
|
|
222
|
+
case "file": {
|
|
223
|
+
const f = options.file?.(b.media);
|
|
224
|
+
if (!f || !isSafeHref(f.url)) return "";
|
|
225
|
+
return `<p class="file"><a${attrs({ href: f.url })}>${esc(b.label ?? f.url)}</a></p>`;
|
|
226
|
+
}
|
|
227
|
+
case "divider": return "<hr>";
|
|
228
|
+
case "html": return options.allowHtml ? b.html : "";
|
|
229
|
+
case "component": return component(b);
|
|
230
|
+
}
|
|
231
|
+
};
|
|
232
|
+
const render = (blocks) => blocks.map(block).join("");
|
|
233
|
+
return render(body);
|
|
234
|
+
}
|
|
235
|
+
// ../body/src/schema.ts
|
|
236
|
+
const MARKS = [
|
|
237
|
+
"strong",
|
|
238
|
+
"em",
|
|
239
|
+
"code",
|
|
240
|
+
"strike",
|
|
241
|
+
"mark",
|
|
242
|
+
"sup",
|
|
243
|
+
"sub",
|
|
244
|
+
"underline"
|
|
245
|
+
];
|
|
246
|
+
const CITE_TEXT = /:cite\{#([^\s}]+)\}/g;
|
|
247
|
+
const liftCites = (text) => text.split(CITE_TEXT).flatMap((piece, i) => i % 2 ? [{
|
|
248
|
+
component: CITE,
|
|
249
|
+
props: { id: piece }
|
|
250
|
+
}] : piece ? [piece] : []);
|
|
251
|
+
const link = z.object({
|
|
252
|
+
href: z.string().min(1, bodyProblemText("link_href_missing")),
|
|
253
|
+
title: z.string().optional(),
|
|
254
|
+
rel: z.string().optional(),
|
|
255
|
+
target: z.literal("_blank").optional()
|
|
256
|
+
});
|
|
257
|
+
const named = z.object({
|
|
258
|
+
name: z.string().min(1).optional(),
|
|
259
|
+
value: z.string().min(1).optional()
|
|
260
|
+
});
|
|
261
|
+
const textStyle = z.object({
|
|
262
|
+
color: named.optional(),
|
|
263
|
+
background: named.optional(),
|
|
264
|
+
size: named.optional(),
|
|
265
|
+
styles: z.array(z.string().min(1)).optional()
|
|
266
|
+
});
|
|
267
|
+
const text = z.object({
|
|
268
|
+
text: z.string(),
|
|
269
|
+
marks: z.array(z.enum(MARKS)).optional(),
|
|
270
|
+
link: link.optional(),
|
|
271
|
+
style: textStyle.optional()
|
|
272
|
+
});
|
|
273
|
+
const align = z.enum(ALIGNS).optional();
|
|
274
|
+
/** 部品の props の検査(名前で核のコンポーネント、なければ宣言した部品、どちらもないか種類が違えば null) */
|
|
275
|
+
function propsOf(name, inline, media, declared) {
|
|
276
|
+
const core = coreComponentOf(name);
|
|
277
|
+
if (core) return Boolean(core.inline) === inline ? core.props(media) : null;
|
|
278
|
+
const d = declared.find((c) => c.name === name);
|
|
279
|
+
return d && Boolean(d.inline) === inline ? declaredPropsZod(d) : null;
|
|
280
|
+
}
|
|
281
|
+
const inlineComponentOf = (declared) => z.object({
|
|
282
|
+
component: z.string().min(1),
|
|
283
|
+
props: z.record(z.string(), z.string()).optional(),
|
|
284
|
+
text: z.string().optional()
|
|
285
|
+
}).superRefine((c, ctx) => {
|
|
286
|
+
const props = propsOf(c.component, true, z.never(), declared);
|
|
287
|
+
if (!props) return void ctx.addIssue({
|
|
288
|
+
code: "custom",
|
|
289
|
+
message: bodyProblemText("inline_component_missing", { name: c.component })
|
|
290
|
+
});
|
|
291
|
+
const r = props.safeParse(c.props ?? {});
|
|
292
|
+
if (!r.success) for (const issue of r.error.issues) ctx.addIssue({
|
|
293
|
+
code: "custom",
|
|
294
|
+
message: issue.message,
|
|
295
|
+
path: ["props", ...issue.path]
|
|
296
|
+
});
|
|
297
|
+
});
|
|
298
|
+
/** インラインの1要素(component を持つ要素は部品としてだけ検査、union で文字の形に落ちて部品の検査を素通りしないため) */
|
|
299
|
+
function inlineItemOf(declared) {
|
|
300
|
+
const component = inlineComponentOf(declared);
|
|
301
|
+
const plain = z.union([z.string(), text]);
|
|
302
|
+
return z.unknown().transform((value, ctx) => {
|
|
303
|
+
const r = (typeof value === "object" && value !== null && "component" in value ? component : plain).safeParse(value);
|
|
304
|
+
if (r.success) return r.data;
|
|
305
|
+
for (const issue of r.error.issues) ctx.addIssue({
|
|
306
|
+
code: "custom",
|
|
307
|
+
message: issue.message,
|
|
308
|
+
path: issue.path
|
|
309
|
+
});
|
|
310
|
+
return z.NEVER;
|
|
311
|
+
});
|
|
312
|
+
}
|
|
313
|
+
const richOf = (cites, declared) => z.array(inlineItemOf(declared)).transform((items) => cites ? items.flatMap((item) => typeof item === "string" ? liftCites(item) : [item]) : items);
|
|
314
|
+
const variant = z.string().optional();
|
|
315
|
+
/** 本文の1ブロックの検査(profile は本文の設定、media は画像の参照の検査、declared は導入先が宣言した部品) */
|
|
316
|
+
function blockSchemaOf(profile, media, declared = []) {
|
|
317
|
+
const rich = richOf(profile.components.includes(CITE), declared);
|
|
318
|
+
const list = z.object({
|
|
319
|
+
type: z.literal("list"),
|
|
320
|
+
ordered: z.boolean().optional(),
|
|
321
|
+
items: z.array(z.object({
|
|
322
|
+
content: rich,
|
|
323
|
+
get children() {
|
|
324
|
+
return list.optional();
|
|
325
|
+
}
|
|
326
|
+
})),
|
|
327
|
+
variant
|
|
328
|
+
});
|
|
329
|
+
const heading = z.object({
|
|
330
|
+
type: z.literal("heading"),
|
|
331
|
+
level: z.union([
|
|
332
|
+
z.literal(1),
|
|
333
|
+
z.literal(2),
|
|
334
|
+
z.literal(3),
|
|
335
|
+
z.literal(4),
|
|
336
|
+
z.literal(5),
|
|
337
|
+
z.literal(6)
|
|
338
|
+
]),
|
|
339
|
+
content: rich,
|
|
340
|
+
id: z.string().optional(),
|
|
341
|
+
align,
|
|
342
|
+
variant
|
|
343
|
+
});
|
|
344
|
+
const span = z.number().int().min(1).max(1e3).optional();
|
|
345
|
+
const tableCell = z.object({
|
|
346
|
+
content: z.array(rich),
|
|
347
|
+
header: z.boolean().optional(),
|
|
348
|
+
colspan: span,
|
|
349
|
+
rowspan: span,
|
|
350
|
+
align
|
|
351
|
+
});
|
|
352
|
+
const cell = z.unknown().transform((value, ctx) => {
|
|
353
|
+
const r = (Array.isArray(value) ? rich : tableCell).safeParse(value);
|
|
354
|
+
if (r.success) return r.data;
|
|
355
|
+
for (const issue of r.error.issues) ctx.addIssue({
|
|
356
|
+
code: "custom",
|
|
357
|
+
message: issue.message,
|
|
358
|
+
path: issue.path
|
|
359
|
+
});
|
|
360
|
+
return z.NEVER;
|
|
361
|
+
});
|
|
362
|
+
return z.discriminatedUnion("type", [
|
|
363
|
+
z.object({
|
|
364
|
+
type: z.literal("paragraph"),
|
|
365
|
+
content: rich,
|
|
366
|
+
align,
|
|
367
|
+
variant
|
|
368
|
+
}),
|
|
369
|
+
heading.refine((h) => h.content.some((i) => typeof i === "string" ? i.trim() : "text" in i && i.text?.trim()), bodyProblemText("heading_empty")),
|
|
370
|
+
list,
|
|
371
|
+
z.object({
|
|
372
|
+
type: z.literal("quote"),
|
|
373
|
+
content: z.array(rich),
|
|
374
|
+
cite: z.object({
|
|
375
|
+
label: z.string(),
|
|
376
|
+
href: z.string().optional()
|
|
377
|
+
}).optional(),
|
|
378
|
+
variant
|
|
379
|
+
}),
|
|
380
|
+
z.object({
|
|
381
|
+
type: z.literal("code"),
|
|
382
|
+
code: z.string(),
|
|
383
|
+
lang: z.string().optional(),
|
|
384
|
+
caption: z.string().optional(),
|
|
385
|
+
filename: z.string().optional(),
|
|
386
|
+
variant
|
|
387
|
+
}),
|
|
388
|
+
z.object({
|
|
389
|
+
type: z.literal("image"),
|
|
390
|
+
media,
|
|
391
|
+
alt: z.string().optional(),
|
|
392
|
+
caption: z.string().optional(),
|
|
393
|
+
link: link.optional(),
|
|
394
|
+
align: z.enum([
|
|
395
|
+
"left",
|
|
396
|
+
"center",
|
|
397
|
+
"right"
|
|
398
|
+
]).optional(),
|
|
399
|
+
variant
|
|
400
|
+
}),
|
|
401
|
+
z.object({
|
|
402
|
+
type: z.literal("table"),
|
|
403
|
+
head: z.array(rich).optional(),
|
|
404
|
+
rows: z.array(z.array(cell)),
|
|
405
|
+
caption: z.string().optional(),
|
|
406
|
+
variant
|
|
407
|
+
}),
|
|
408
|
+
z.object({
|
|
409
|
+
type: z.literal("file"),
|
|
410
|
+
media,
|
|
411
|
+
label: z.string().optional()
|
|
412
|
+
}),
|
|
413
|
+
z.object({ type: z.literal("divider") }),
|
|
414
|
+
z.object({
|
|
415
|
+
type: z.literal("html"),
|
|
416
|
+
html: z.string()
|
|
417
|
+
}),
|
|
418
|
+
z.object({
|
|
419
|
+
type: z.literal("component"),
|
|
420
|
+
name: z.string().min(1),
|
|
421
|
+
props: z.unknown()
|
|
422
|
+
})
|
|
423
|
+
]).transform((block, ctx) => {
|
|
424
|
+
let out = block;
|
|
425
|
+
if (out.type === "component") {
|
|
426
|
+
const props = propsOf(out.name, false, media, declared);
|
|
427
|
+
if (!props) {
|
|
428
|
+
ctx.addIssue({
|
|
429
|
+
code: "custom",
|
|
430
|
+
message: bodyProblemText("component_missing", { name: out.name })
|
|
431
|
+
});
|
|
432
|
+
return z.NEVER;
|
|
433
|
+
}
|
|
434
|
+
const r = props.safeParse(out.props);
|
|
435
|
+
if (!r.success) {
|
|
436
|
+
for (const issue of r.error.issues) ctx.addIssue({
|
|
437
|
+
code: "custom",
|
|
438
|
+
message: issue.message,
|
|
439
|
+
path: ["props", ...issue.path]
|
|
440
|
+
});
|
|
441
|
+
return z.NEVER;
|
|
442
|
+
}
|
|
443
|
+
out = {
|
|
444
|
+
...out,
|
|
445
|
+
props: r.data
|
|
446
|
+
};
|
|
447
|
+
}
|
|
448
|
+
for (const p of checkBody([out], profile)) ctx.addIssue({
|
|
449
|
+
code: "custom",
|
|
450
|
+
message: p.message
|
|
451
|
+
});
|
|
452
|
+
return out;
|
|
453
|
+
});
|
|
454
|
+
}
|
|
455
|
+
export { DESCRIPTION_MAX, EMBED_PROVIDERS, READING_SPEED, blockSchemaOf, bodyToHtml, cellParagraphs, citesOf, descriptionOf, embedOfUrl, embedSrcOf, excerptOf, isSafeCssValue, isSafeHref, isTableCell, linksOf, plainOf, readMinOf };
|
|
@@ -0,0 +1,74 @@
|
|
|
1
|
+
// ../cms-contract/src/bridge.ts
|
|
2
|
+
/** メッセージの名前の頭(外に見える識別子、改名はここだけ) */
|
|
3
|
+
const BRIDGE_NAMESPACE = "tunasand.bridge";
|
|
4
|
+
/** 規約の版 */
|
|
5
|
+
const BRIDGE_VERSION = 1;
|
|
6
|
+
/**
|
|
7
|
+
* 画面のトークン(アカウントの資格、Shopify のセッションのトークンと同じ形の JWT、設計は docs/app-screens.md の「アカウントの資格」)
|
|
8
|
+
* - 署名は HS256 で、鍵はクライアントの秘密(インストールにつなぐまでは外の画面の登録の鍵)。アプリのサーバーは手元で検証でき、API は呼べない
|
|
9
|
+
* - iss はプロジェクトの管理画面のオリジン(https://<dest>)で、製品名の定数を持たない。skewSec は検証の時計のずれの許容(秒)
|
|
10
|
+
*/
|
|
11
|
+
const SESSION_TOKEN = {
|
|
12
|
+
ttlSec: 60,
|
|
13
|
+
skewSec: 10
|
|
14
|
+
};
|
|
15
|
+
const isSec = (v) => typeof v === "number" && Number.isFinite(v);
|
|
16
|
+
/**
|
|
17
|
+
* 署名を確認した JWT のクレームが画面のトークンとして合うか、合えばクレーム
|
|
18
|
+
* - 発行者が https://<dest> かその下の /env/<…>、宛先 clientId、環境、期間、寿命。時計のずれは skewSec 秒まで
|
|
19
|
+
*/
|
|
20
|
+
function sessionTokenClaimsOf(claims, clientId, nowSec) {
|
|
21
|
+
const { iss, aud, sub, dest, env, iat, nbf, exp, jti, prf } = claims;
|
|
22
|
+
const { skewSec, ttlSec } = SESSION_TOKEN;
|
|
23
|
+
if (typeof iss !== "string" || typeof dest !== "string" || iss !== `https://${dest}` && !iss.startsWith(`https://${dest}/env/`) || aud !== clientId) return null;
|
|
24
|
+
if (typeof sub !== "string" || typeof env !== "string" || typeof jti !== "string" || typeof prf !== "string") return null;
|
|
25
|
+
if (!isSec(iat) || !isSec(nbf) || !isSec(exp) || nbf > nowSec + skewSec || exp <= nowSec - skewSec || exp - iat > ttlSec) return null;
|
|
26
|
+
return {
|
|
27
|
+
iss,
|
|
28
|
+
aud,
|
|
29
|
+
sub,
|
|
30
|
+
dest,
|
|
31
|
+
env,
|
|
32
|
+
iat,
|
|
33
|
+
nbf,
|
|
34
|
+
exp,
|
|
35
|
+
jti,
|
|
36
|
+
prf
|
|
37
|
+
};
|
|
38
|
+
}
|
|
39
|
+
/** API の依頼(サーバーのないアプリ)のメソッド */
|
|
40
|
+
const BRIDGE_API_METHODS = [
|
|
41
|
+
"GET",
|
|
42
|
+
"POST",
|
|
43
|
+
"PUT",
|
|
44
|
+
"PATCH",
|
|
45
|
+
"DELETE"
|
|
46
|
+
];
|
|
47
|
+
/**
|
|
48
|
+
* 見た目のトークンの名前(実験的)
|
|
49
|
+
* - 管理画面の見た目の作り直しで名前と値が変わる。版で固定しないので、アプリは値がないときの既定を持つ
|
|
50
|
+
* - アプリの側では applyTheme が CSS の変数 --theme-<名前> として当てる
|
|
51
|
+
*/
|
|
52
|
+
const BRIDGE_THEME_TOKENS = [
|
|
53
|
+
"accent",
|
|
54
|
+
"text",
|
|
55
|
+
"muted",
|
|
56
|
+
"surface",
|
|
57
|
+
"border",
|
|
58
|
+
"radius",
|
|
59
|
+
"font-family",
|
|
60
|
+
"font-size"
|
|
61
|
+
];
|
|
62
|
+
/** アプリの側の CSS の変数の頭 */
|
|
63
|
+
const BRIDGE_THEME_VAR_PREFIX = "--theme-";
|
|
64
|
+
/** 依頼の失敗の理由 */
|
|
65
|
+
const BRIDGE_ERRORS = [
|
|
66
|
+
"unsupported",
|
|
67
|
+
"invalid",
|
|
68
|
+
"forbidden",
|
|
69
|
+
"rate_limited",
|
|
70
|
+
"failed"
|
|
71
|
+
];
|
|
72
|
+
/** 名前の頭と版を持つ値か */
|
|
73
|
+
const isBridgeMessage = (data) => !!data && typeof data === "object" && data.ns === "tunasand.bridge" && typeof data.v === "number";
|
|
74
|
+
export { BRIDGE_THEME_VAR_PREFIX as a, isBridgeMessage as c, BRIDGE_THEME_TOKENS as i, sessionTokenClaimsOf as l, BRIDGE_ERRORS as n, BRIDGE_VERSION as o, BRIDGE_NAMESPACE as r, SESSION_TOKEN as s, BRIDGE_API_METHODS as t };
|
package/dist/bridge.d.ts
ADDED
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export * from './types/sdk/src/bridge.js';
|