@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.
- package/CHANGELOG.md +137 -0
- package/README.md +165 -144
- package/dist/analytics.js +183 -109
- package/dist/app.js +276 -166
- package/dist/apps-BysPfMuR.js +408 -0
- package/dist/astro-image.d.ts +1 -0
- package/dist/astro-image.js +33 -0
- package/dist/astro-server-Bwau8F6d.js +99 -0
- package/dist/astro-server.d.ts +1 -0
- package/dist/astro-server.js +1 -0
- package/dist/astro.d.ts +1 -0
- package/dist/astro.js +306 -0
- package/dist/bridge-C2Bl-OAF.js +80 -0
- package/dist/bridge.js +1 -13
- package/dist/build-file-DNi0PHC5.js +31 -0
- package/dist/cli.js +6212 -8
- package/dist/{client-Derrexwr.js → client-C8STAw9T.js} +43 -24
- package/dist/code-N8pBUDbq.js +30 -0
- package/dist/code.d.ts +1 -0
- package/dist/code.js +1 -0
- package/dist/collection-26aglrg6.js +282 -0
- package/dist/{declared-DuNMsdXw.js → declared-CE4a61qb.js} +35 -35
- package/dist/delivery.js +121 -114
- package/dist/dev-operations-Tutwi1On.js +46 -0
- package/dist/dev.js +9 -16
- package/dist/embeds-DY6O5TrJ.js +29 -0
- package/dist/end-users.d.ts +1 -0
- package/dist/end-users.js +189 -0
- package/dist/endUsers-DODfjnv1.js +77 -0
- package/dist/{errorLabels-BgtQ_zUn.js → errorLabels-BK1NJ6Wz.js} +374 -238
- package/dist/i18n.js +4 -4
- package/dist/ids-DmtIoqBX.js +109 -0
- package/dist/integrations.js +95 -24
- package/dist/{ja-Du6ooL6i.js → ja-B3lAaOhZ.js} +91 -45
- package/dist/{ja-CeHU0EaY.js → ja-axQPxMJ-.js} +3 -3
- package/dist/operations-CIB99rIY.js +95 -0
- package/dist/operations.d.ts +1 -0
- package/dist/operations.js +1 -0
- package/dist/{page-Bzrj24sJ.js → page-yo1cw1kW.js} +1 -1
- package/dist/paymentPort-p1jV44Zz.js +203 -0
- package/dist/preview.js +8 -1
- package/dist/{profile-1em_lcxq.js → profile-DBsXLvvI.js} +48 -48
- package/dist/rich-text.js +16 -16
- package/dist/{schema-WnobuwLg.js → schema-Bs_BUUNv.js} +526 -265
- package/dist/schema.js +66 -88
- package/dist/types/access/src/handoff.d.ts +19 -14
- package/dist/types/access/src/index.d.ts +2 -2
- package/dist/types/access/src/jws.d.ts +41 -0
- package/dist/types/access/src/oidc.d.ts +12 -2
- package/dist/types/access/src/signed.d.ts +0 -2
- package/dist/types/adapter-cloudflare/src/eventLog/viewSchema.d.ts +11 -0
- package/dist/types/contract/src/accountProfile.d.ts +7 -0
- package/dist/types/contract/src/api/define.d.ts +165 -0
- package/dist/types/contract/src/apiKeys.d.ts +6 -2
- package/dist/types/contract/src/app.d.ts +32 -7
- package/dist/types/contract/src/appChannels.d.ts +152 -0
- package/dist/types/contract/src/appDefinition.d.ts +11 -5
- package/dist/types/contract/src/appDependencies.d.ts +107 -24
- package/dist/types/contract/src/appIdentities.d.ts +21 -0
- package/dist/types/contract/src/appInbound.d.ts +53 -0
- package/dist/types/contract/src/appMail.d.ts +106 -0
- package/dist/types/contract/src/appSecrets.d.ts +63 -0
- package/dist/types/contract/src/appServer.d.ts +460 -45
- package/dist/types/contract/src/approvals.d.ts +1 -1
- package/dist/types/contract/src/apps.d.ts +126 -60
- package/dist/types/contract/src/auditActions.d.ts +2 -2
- package/dist/types/contract/src/auditLabels.d.ts +120 -15
- package/dist/types/contract/src/authorize.d.ts +42 -14
- package/dist/types/contract/src/bridge.d.ts +35 -36
- package/dist/types/contract/src/consents.d.ts +29 -27
- package/dist/types/contract/src/deletion.d.ts +18 -0
- package/dist/types/contract/src/embeds.d.ts +26 -90
- package/dist/types/contract/src/{customerLabels.d.ts → endUserLabels.d.ts} +6 -9
- package/dist/types/contract/src/endUsers.d.ts +244 -0
- package/dist/types/contract/src/errorLabels.d.ts +67 -37
- package/dist/types/contract/src/errorLabelsEn.d.ts +50 -33
- package/dist/types/contract/src/errors.d.ts +28 -16
- package/dist/types/contract/src/eventSchemas.d.ts +70 -0
- package/dist/types/contract/src/eventTraces.d.ts +41 -0
- package/dist/types/contract/src/failureStatus.d.ts +14 -22
- package/dist/types/contract/src/fieldAccess.d.ts +8 -8
- package/dist/types/contract/src/formLabels.d.ts +3 -0
- package/dist/types/contract/src/forms.d.ts +4 -0
- package/dist/types/contract/src/grants.d.ts +26 -0
- package/dist/types/contract/src/headers.d.ts +5 -0
- package/dist/types/contract/src/hostingRpc.d.ts +44 -19
- package/dist/types/contract/src/identifiers.d.ts +45 -17
- package/dist/types/contract/src/ids.d.ts +18 -10
- package/dist/types/contract/src/import.d.ts +17 -16
- package/dist/types/contract/src/index.d.ts +57 -29
- package/dist/types/contract/src/integrationGraph.d.ts +83 -0
- package/dist/types/contract/src/issueLabels.d.ts +121 -81
- package/dist/types/contract/src/issueLabelsEn.d.ts +61 -41
- package/dist/types/contract/src/manage.d.ts +16 -7
- package/dist/types/contract/src/manageLabels.d.ts +2 -0
- package/dist/types/contract/src/manifestText.d.ts +66 -0
- package/dist/types/contract/src/messagePort.d.ts +208 -0
- package/dist/types/contract/src/migration.d.ts +2 -2
- package/dist/types/contract/src/notices.d.ts +37 -0
- package/dist/types/contract/src/operationEffects.d.ts +39 -0
- package/dist/types/contract/src/operatorOperations.d.ts +104 -110
- package/dist/types/contract/src/outbound.d.ts +29 -0
- package/dist/types/contract/src/paths.d.ts +13 -0
- package/dist/types/contract/src/paymentPort.d.ts +129 -0
- package/dist/types/contract/src/pending.d.ts +2 -0
- package/dist/types/contract/src/permissions.d.ts +7 -11
- package/dist/types/contract/src/perspective.d.ts +26 -0
- package/dist/types/contract/src/powers.d.ts +5 -0
- package/dist/types/contract/src/principal.d.ts +127 -56
- package/dist/types/contract/src/readPages.d.ts +92 -0
- package/dist/types/contract/src/recordLabels.d.ts +6 -0
- package/dist/types/contract/src/roles.d.ts +7 -4
- package/dist/types/contract/src/ruleLabels.d.ts +16 -0
- package/dist/types/contract/src/ruleProblems.d.ts +16 -0
- package/dist/types/contract/src/schemaLabels.d.ts +8 -0
- package/dist/types/contract/src/settingProblems.d.ts +18 -1
- package/dist/types/contract/src/settings.d.ts +5 -7
- package/dist/types/contract/src/siteDeclaration.d.ts +7 -7
- package/dist/types/contract/src/siteIndex.d.ts +76 -0
- package/dist/types/contract/src/transfer.d.ts +1 -1
- package/dist/types/contract/src/trial.d.ts +4 -1
- package/dist/types/contract/src/versions.d.ts +1 -3
- package/dist/types/contract/src/viewEvent.d.ts +0 -9
- package/dist/types/contract/src/webhooks.d.ts +24 -3
- package/dist/types/contract/src/workflow.d.ts +16 -19
- package/dist/types/contract/src/workspaceItems.d.ts +23 -7
- package/dist/types/contract/src/workspacePaths.d.ts +1 -1
- package/dist/types/rich-text/src/html.d.ts +1 -1
- package/dist/types/rich-text/src/index.d.ts +8 -7
- package/dist/types/rich-text/src/labels/en.d.ts +1 -1
- package/dist/types/rich-text/src/labels/ja.d.ts +2 -2
- package/dist/types/rich-text/src/library.d.ts +1 -1
- package/dist/types/rich-text/src/media.d.ts +2 -0
- package/dist/types/rich-text/src/normalize.d.ts +1 -1
- package/dist/types/rich-text/src/problems.d.ts +5 -5
- package/dist/types/rich-text/src/profile.d.ts +10 -10
- package/dist/types/rich-text/src/render.d.ts +1 -1
- package/dist/types/rich-text/src/schema.d.ts +2 -2
- package/dist/types/rich-text/src/standard.d.ts +4 -4
- package/dist/types/rich-text/src/types.d.ts +2 -2
- package/dist/types/schema/src/audience.d.ts +1 -3
- package/dist/types/schema/src/capabilities.d.ts +18 -27
- package/dist/types/schema/src/changes.d.ts +3 -1
- package/dist/types/schema/src/collection.d.ts +142 -111
- package/dist/types/schema/src/defaultSchema.d.ts +8 -2
- package/dist/types/schema/src/fieldIds.d.ts +18 -0
- package/dist/types/schema/src/file.d.ts +24 -11
- package/dist/types/schema/src/fileRefs.d.ts +14 -0
- package/dist/types/schema/src/fileSignature.d.ts +20 -0
- package/dist/types/schema/src/filesCollection.d.ts +7 -0
- package/dist/types/schema/src/forms.d.ts +43 -0
- package/dist/types/schema/src/imageMetadata.d.ts +9 -0
- package/dist/types/schema/src/index.d.ts +19 -10
- package/dist/types/schema/src/indexes.d.ts +11 -0
- package/dist/types/schema/src/input.d.ts +1 -1
- package/dist/types/schema/src/integrity.d.ts +8 -7
- package/dist/types/schema/src/kinds.d.ts +26 -0
- package/dist/types/schema/src/labels/en.d.ts +89 -46
- package/dist/types/schema/src/labels/ja.d.ts +92 -46
- package/dist/types/schema/src/mediaUrl.d.ts +26 -33
- package/dist/types/schema/src/page.d.ts +4 -4
- package/dist/types/schema/src/problems.d.ts +85 -42
- package/dist/types/schema/src/refs.d.ts +0 -9
- package/dist/types/schema/src/schema.d.ts +17 -12
- package/dist/types/schema/src/selfOps.d.ts +20 -19
- package/dist/types/schema/src/traits.d.ts +28 -0
- package/dist/types/schema/src/typesSource.d.ts +1 -1
- package/dist/types/schema/src/values.d.ts +5 -2
- package/dist/types/schema/src/widening.d.ts +3 -0
- package/dist/types/sdk/src/analytics.d.ts +2 -1
- package/dist/types/sdk/src/app.d.ts +43 -14
- package/dist/types/sdk/src/astro-image.d.ts +19 -0
- package/dist/types/sdk/src/astro-response.d.ts +6 -0
- package/dist/types/sdk/src/astro-server.d.ts +16 -0
- package/dist/types/sdk/src/astro.d.ts +19 -0
- package/dist/types/sdk/src/bridge.d.ts +2 -4
- package/dist/types/sdk/src/code.d.ts +61 -0
- package/dist/types/sdk/src/delegation.d.ts +13 -3
- package/dist/types/sdk/src/delivery/changes.d.ts +4 -4
- package/dist/types/sdk/src/delivery/client.d.ts +33 -22
- package/dist/types/sdk/src/delivery/fields.d.ts +3 -3
- package/dist/types/sdk/src/delivery/index.d.ts +3 -3
- package/dist/types/sdk/src/delivery/media.d.ts +5 -8
- package/dist/types/sdk/src/delivery/query.d.ts +15 -11
- package/dist/types/sdk/src/delivery/schema.d.ts +1 -1
- package/dist/types/sdk/src/delivery/values.d.ts +10 -14
- package/dist/types/sdk/src/delivery.d.ts +2 -2
- package/dist/types/sdk/src/dev-operations.d.ts +20 -0
- package/dist/types/sdk/src/dev.d.ts +6 -5
- package/dist/types/sdk/src/end-users.d.ts +187 -0
- package/dist/types/sdk/src/i18n.d.ts +2 -2
- package/dist/types/sdk/src/integrations.d.ts +14 -21
- package/dist/types/sdk/src/operations.d.ts +17 -0
- package/dist/types/sdk/src/preview.d.ts +2 -1
- package/dist/types/sdk/src/rich-text.d.ts +2 -2
- package/dist/types/sdk/src/schema.d.ts +1 -1
- package/dist/types/sdk/src/site/artifact.d.ts +64 -0
- package/dist/types/sdk/src/site/build-file.d.ts +30 -0
- package/dist/types/sdk/src/site/check-code.d.ts +14 -0
- package/dist/types/sdk/src/site/check-text.d.ts +19 -0
- package/dist/types/sdk/src/site/cli.d.ts +52 -0
- package/dist/types/sdk/src/site/content-type.d.ts +2 -0
- package/dist/types/sdk/src/site/labels.d.ts +14 -0
- package/dist/types/sdk/src/types.d.ts +1 -1
- package/dist/{types-B77qvqPJ.js → types-CYnY-63C.js} +5 -6
- package/dist/types.js +1 -1
- package/dist/{typesSource-CWybQYus.js → typesSource-BTA9-rcB.js} +17 -15
- package/package.json +32 -6
- package/dist/apps-BxnJ1RlU.js +0 -435
- package/dist/bridge-DtHw9hS6.js +0 -74
- package/dist/collection-BEOxeISR.js +0 -189
- package/dist/customers-DTbL0qn6.js +0 -86
- package/dist/customers.d.ts +0 -1
- package/dist/customers.js +0 -185
- package/dist/embeds-B5V54Zur.js +0 -34
- package/dist/ids--RF7hGyC.js +0 -36
- package/dist/src-sazhzYui.js +0 -71
- package/dist/types/contract/src/customers.d.ts +0 -266
- package/dist/types/schema/src/legacy.d.ts +0 -2
- package/dist/types/schema/src/media.d.ts +0 -5
- package/dist/types/sdk/src/customers.d.ts +0 -184
|
@@ -0,0 +1,95 @@
|
|
|
1
|
+
import { AsyncLocalStorage } from "node:async_hooks";
|
|
2
|
+
// src/operations.ts
|
|
3
|
+
const KEY = Symbol.for("tunasand.operations");
|
|
4
|
+
const shared = globalThis;
|
|
5
|
+
const scopes = shared[KEY] ??= new AsyncLocalStorage();
|
|
6
|
+
const closed = () => Object.assign(/* @__PURE__ */ new Error("closed"), {
|
|
7
|
+
name: "OperationError",
|
|
8
|
+
code: "closed"
|
|
9
|
+
});
|
|
10
|
+
/** 終わった呼び出しの操作を拒む(先に取り出した値でも使えない) */
|
|
11
|
+
const openOf = (scope) => {
|
|
12
|
+
if (!scope.operations) throw closed();
|
|
13
|
+
return scope.operations;
|
|
14
|
+
};
|
|
15
|
+
const guarded = (scope) => Object.freeze({
|
|
16
|
+
call: async (name, input) => openOf(scope).call(name, input),
|
|
17
|
+
open: async (name, input) => openOf(scope).open(name, input),
|
|
18
|
+
fetch: async (input, init) => openOf(scope).fetch(input, init),
|
|
19
|
+
log: async (level, message) => openOf(scope).log(level, message)
|
|
20
|
+
});
|
|
21
|
+
/**
|
|
22
|
+
* 処理している呼び出しの操作
|
|
23
|
+
* @throws Error `operations_outside_call`(処理の外)、OperationError `closed`(呼び出しの終わりの後)
|
|
24
|
+
*/
|
|
25
|
+
function operations() {
|
|
26
|
+
const scope = scopes.getStore();
|
|
27
|
+
if (!scope) throw new Error("operations_outside_call");
|
|
28
|
+
openOf(scope);
|
|
29
|
+
return guarded(scope);
|
|
30
|
+
}
|
|
31
|
+
/** 本文の終わり、打ち切り、失敗のどれかで1回だけ end を呼ぶ応答(本文のない応答はすぐに呼ぶ) */
|
|
32
|
+
function endingResponse(response, end) {
|
|
33
|
+
if (!response.body) {
|
|
34
|
+
end();
|
|
35
|
+
return response;
|
|
36
|
+
}
|
|
37
|
+
const reader = response.body.getReader();
|
|
38
|
+
const body = new ReadableStream({
|
|
39
|
+
async pull(controller) {
|
|
40
|
+
try {
|
|
41
|
+
const { done, value } = await reader.read();
|
|
42
|
+
if (!done) return controller.enqueue(value);
|
|
43
|
+
end();
|
|
44
|
+
controller.close();
|
|
45
|
+
} catch (e) {
|
|
46
|
+
end();
|
|
47
|
+
controller.error(e);
|
|
48
|
+
}
|
|
49
|
+
},
|
|
50
|
+
async cancel(reason) {
|
|
51
|
+
end();
|
|
52
|
+
await reader.cancel(reason);
|
|
53
|
+
}
|
|
54
|
+
}, { highWaterMark: 0 });
|
|
55
|
+
return new Response(body, {
|
|
56
|
+
status: response.status,
|
|
57
|
+
statusText: response.statusText,
|
|
58
|
+
headers: response.headers
|
|
59
|
+
});
|
|
60
|
+
}
|
|
61
|
+
/** given を、work とその中の非同期の処理の `operations()` にする(応答の本文の終わりに閉じる) */
|
|
62
|
+
async function provideOperations(given, work) {
|
|
63
|
+
const scope = { operations: given };
|
|
64
|
+
const end = () => {
|
|
65
|
+
scope.operations = null;
|
|
66
|
+
};
|
|
67
|
+
try {
|
|
68
|
+
const answer = await scopes.run(scope, async () => work());
|
|
69
|
+
if (answer instanceof Response) return endingResponse(answer, end);
|
|
70
|
+
end();
|
|
71
|
+
return answer;
|
|
72
|
+
} catch (e) {
|
|
73
|
+
end();
|
|
74
|
+
throw e;
|
|
75
|
+
}
|
|
76
|
+
}
|
|
77
|
+
/** 種類ごとの処理の中で `operations()` を使えるようにする(defineCode に渡す) */
|
|
78
|
+
function withOperations(handlers) {
|
|
79
|
+
const { request, event, check, schedule } = handlers;
|
|
80
|
+
return {
|
|
81
|
+
request: request && ((call, given) => provideOperations(given, () => request(call, operations()))),
|
|
82
|
+
event: event && ((call, given) => provideOperations(given, () => event(call, operations()))),
|
|
83
|
+
check: check && ((call, given) => provideOperations(given, () => check(call, operations()))),
|
|
84
|
+
schedule: schedule && ((call, given) => provideOperations(given, () => schedule(call, operations())))
|
|
85
|
+
};
|
|
86
|
+
}
|
|
87
|
+
/** 値の入れ物を作る(work とその中の非同期の処理だけが、その値を読む) */
|
|
88
|
+
function scopedValue() {
|
|
89
|
+
const storage = new AsyncLocalStorage();
|
|
90
|
+
return Object.freeze({
|
|
91
|
+
run: (value, work) => storage.run(value, work),
|
|
92
|
+
get: () => storage.getStore()
|
|
93
|
+
});
|
|
94
|
+
}
|
|
95
|
+
export { withOperations as i, provideOperations as n, scopedValue as r, operations as t };
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export * from './types/sdk/src/operations.js';
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export { t as operations, n as provideOperations, r as scopedValue, i as withOperations } from "./operations-CIB99rIY.js";
|
|
@@ -105,7 +105,7 @@ const matches = (when, record) => !when || when.in.includes(String(record[when.k
|
|
|
105
105
|
const passes = (rule, record, now) => {
|
|
106
106
|
const v = record[rule.key];
|
|
107
107
|
if ("in" in rule) return rule.in.includes(String(v ?? ""));
|
|
108
|
-
if ("
|
|
108
|
+
if ("not_in" in rule) return !rule.not_in.includes(String(v ?? ""));
|
|
109
109
|
if ("truthy" in rule) return Boolean(v);
|
|
110
110
|
return v === void 0 || v === null || v === "" || String(v) <= now;
|
|
111
111
|
};
|
|
@@ -0,0 +1,203 @@
|
|
|
1
|
+
import { n as APP_MANIFEST_KEYS } from "./apps-BysPfMuR.js";
|
|
2
|
+
import { z } from "zod";
|
|
3
|
+
// ../contract/src/import.ts
|
|
4
|
+
/** 1回のリクエストで取り込む件数の上限(画像の取得の時間と、本文の大きさの上限 JSON_BODY_MAX のため) */
|
|
5
|
+
const IMPORT_ITEMS_MAX = 50;
|
|
6
|
+
/** 参照の項目の値で、同じ取り出し元の元の ID を指す形の印({ "$origin": "<元の ID>" }) */
|
|
7
|
+
const ORIGIN_REF = "$origin";
|
|
8
|
+
/** エンドユーザーへの参照のフィールドの値で、人の元の ID を指す形の印({ "$end_user": "<元の ID>" }) */
|
|
9
|
+
const END_USER_REF = "$end_user";
|
|
10
|
+
/** 元の ID を指す値の元の ID(印 marker の1つのキーで値が文字列、ほかは null) */
|
|
11
|
+
function originIdOf(value, marker) {
|
|
12
|
+
if (typeof value !== "object" || value === null || Array.isArray(value)) return null;
|
|
13
|
+
const records = Object.entries(value);
|
|
14
|
+
return records.length === 1 && records[0][0] === marker && typeof records[0][1] === "string" ? records[0][1] : null;
|
|
15
|
+
}
|
|
16
|
+
const isOriginRef = (v) => originIdOf(v, ORIGIN_REF) !== null;
|
|
17
|
+
/** 元の ID を指す参照({ "$origin" })を除いた値(まとまりの中と配列の要素も。循環の1段目の項目) */
|
|
18
|
+
function withoutOrigins(value) {
|
|
19
|
+
if (Array.isArray(value)) return value.filter((v) => !isOriginRef(v)).map(withoutOrigins);
|
|
20
|
+
if (typeof value !== "object" || value === null) return value;
|
|
21
|
+
return Object.fromEntries(Object.entries(value).flatMap(([k, v]) => isOriginRef(v) ? [] : [[k, withoutOrigins(v)]]));
|
|
22
|
+
}
|
|
23
|
+
/** 入力の形のレコードを取り込みの1件に(at は報告の位置、phase はコレクションどうしの循環のフェーズで、1段目は参照を除く) */
|
|
24
|
+
const importItemOfRow = (line, at, phase) => ({
|
|
25
|
+
collection: line.collection,
|
|
26
|
+
...line.new_id !== void 0 && { id: line.new_id },
|
|
27
|
+
fields: phase === 1 ? withoutOrigins(line.fields) : line.fields,
|
|
28
|
+
source: at,
|
|
29
|
+
origin_id: line.id,
|
|
30
|
+
...phase !== void 0 && { phase },
|
|
31
|
+
...line.created_at !== void 0 && { created_at: line.created_at }
|
|
32
|
+
});
|
|
33
|
+
/** 取り込む ID(前後の空白を除き小文字に、changed は大文字を含んでいた) */
|
|
34
|
+
function importIdOf(raw) {
|
|
35
|
+
const trimmed = raw.trim();
|
|
36
|
+
const id = trimmed.toLowerCase();
|
|
37
|
+
return {
|
|
38
|
+
id,
|
|
39
|
+
changed: id !== trimmed
|
|
40
|
+
};
|
|
41
|
+
}
|
|
42
|
+
/** 関係が循環する API のエンドポイント(関係をたどって自分に戻る、自分への関係を含む。参照なしと参照ありの2フェーズで取り込む) */
|
|
43
|
+
function cyclicCollections(apis) {
|
|
44
|
+
const reaches = (from, goal, seen) => Object.values(from.relations).some((target) => {
|
|
45
|
+
if (target === goal) return true;
|
|
46
|
+
if (seen.has(target)) return false;
|
|
47
|
+
seen.add(target);
|
|
48
|
+
const next = apis.find((x) => x.endpoint === target);
|
|
49
|
+
return next ? reaches(next, goal, seen) : false;
|
|
50
|
+
});
|
|
51
|
+
return new Set(apis.filter((a) => reaches(a, a.endpoint, /* @__PURE__ */ new Set())).map((a) => a.endpoint));
|
|
52
|
+
}
|
|
53
|
+
/** 取り込みのイベント(Webhook の名前。対応表を持つ取り込みの実行の完了を1件だけ知らせ、レコードごとの変更のイベントは送らない) */
|
|
54
|
+
const IMPORT_EVENTS = { completed: "import.completed" };
|
|
55
|
+
// ../contract/src/manifestText.ts
|
|
56
|
+
const TEXT_KEYS = [
|
|
57
|
+
"label",
|
|
58
|
+
"description",
|
|
59
|
+
"targets",
|
|
60
|
+
"audit_actions",
|
|
61
|
+
"problems",
|
|
62
|
+
"permissions",
|
|
63
|
+
"ui",
|
|
64
|
+
"settings",
|
|
65
|
+
"collections"
|
|
66
|
+
];
|
|
67
|
+
[...APP_MANIFEST_KEYS.filter((k) => !TEXT_KEYS.includes(k) && k !== "en")];
|
|
68
|
+
/** 画面の文字列の key(同じ key の画面が置き場所ごとにありうる) */
|
|
69
|
+
const uiTextKey = (ui) => typeof ui.key === "string" && typeof ui.slot === "string" ? `${ui.slot}:${ui.key}` : null;
|
|
70
|
+
const isRecord = (v) => typeof v === "object" && v !== null && !Array.isArray(v);
|
|
71
|
+
const records = (v) => Array.isArray(v) ? v.filter(isRecord) : [];
|
|
72
|
+
const without = (value, keys) => Object.fromEntries(Object.entries(value).filter(([k]) => !keys.includes(k)));
|
|
73
|
+
const tableOf = (entries) => {
|
|
74
|
+
const kept = entries.filter((e) => e[1] !== void 0);
|
|
75
|
+
return kept.length ? Object.fromEntries(kept) : void 0;
|
|
76
|
+
};
|
|
77
|
+
const fieldLabels = (fields, prefix = "") => fields.flatMap((f) => [[`${prefix}${String(f.key)}`, typeof f.label === "string" ? f.label : void 0], ...fieldLabels(records(f.fields), `${prefix}${String(f.key)}.`)]);
|
|
78
|
+
const unlabeledFields = (fields) => fields.map((f) => ({
|
|
79
|
+
...without(f, ["label"]),
|
|
80
|
+
...Array.isArray(f.fields) && { fields: unlabeledFields(records(f.fields)) }
|
|
81
|
+
}));
|
|
82
|
+
const compact = (value) => Object.fromEntries(Object.entries(value).filter(([, v]) => v !== void 0));
|
|
83
|
+
/** 読む側の形から登録と保存の形(同梱のアプリのマニフェストを登録の形で扱うときと、試験の材料) */
|
|
84
|
+
function manifestDocumentOf(manifest) {
|
|
85
|
+
const { label, description, targets, audit_actions, problems, en, permissions, ui, settings, collections, ...rest } = manifest;
|
|
86
|
+
const ja = compact({
|
|
87
|
+
label,
|
|
88
|
+
description,
|
|
89
|
+
targets,
|
|
90
|
+
audit_actions,
|
|
91
|
+
problems,
|
|
92
|
+
permissions: tableOf((permissions ?? []).map((p) => [p.id, p.label])),
|
|
93
|
+
ui: tableOf((ui ?? []).flatMap((u) => uiTextKey(u) ? [[uiTextKey(u), u.label]] : [])),
|
|
94
|
+
settings: settings?.length ? Object.fromEntries(settings.map((s) => [s.key, compact({
|
|
95
|
+
label: s.label,
|
|
96
|
+
unit: s.unit
|
|
97
|
+
})])) : void 0,
|
|
98
|
+
collections: collections?.length ? Object.fromEntries(collections.map((c) => [c.name, compact({
|
|
99
|
+
label: c.label,
|
|
100
|
+
fields: tableOf(fieldLabels(c.fields))
|
|
101
|
+
})])) : void 0
|
|
102
|
+
});
|
|
103
|
+
return compact({
|
|
104
|
+
...rest,
|
|
105
|
+
...permissions && { permissions: permissions.map((p) => ({ id: p.id })) },
|
|
106
|
+
...ui && { ui: ui.map((u) => without(u, ["label"])) },
|
|
107
|
+
...settings && { settings: settings.map((s) => without(s, ["label", "unit"])) },
|
|
108
|
+
...collections && { collections: collections.map((c) => ({
|
|
109
|
+
...without(c, ["label", "fields"]),
|
|
110
|
+
fields: unlabeledFields(c.fields)
|
|
111
|
+
})) },
|
|
112
|
+
ja,
|
|
113
|
+
...en && (en.targets || en.problems) && { en: compact({
|
|
114
|
+
targets: en.targets,
|
|
115
|
+
problems: en.problems
|
|
116
|
+
}) }
|
|
117
|
+
});
|
|
118
|
+
}
|
|
119
|
+
// ../contract/src/notices.ts
|
|
120
|
+
/** 通知のポート */
|
|
121
|
+
const NOTICES_PORT = "tunasand:notices@1";
|
|
122
|
+
/**
|
|
123
|
+
* 通知の1件
|
|
124
|
+
* - collection と record は対象の id、at は日時(UTC の ISO 8601)
|
|
125
|
+
* - by: 差出人(account はアカウントの ID、owners は対象のレコードの持ち主、なしは null)
|
|
126
|
+
* - standing: 対応するまで残る件か(偽は、開いたときに既読になる件)
|
|
127
|
+
*/
|
|
128
|
+
const appNotice = z.object({
|
|
129
|
+
kind: z.string().regex(/^[a-z][a-z0-9_]{0,39}$/),
|
|
130
|
+
collection: z.string().min(1).max(100),
|
|
131
|
+
record: z.string().min(1).max(100),
|
|
132
|
+
at: z.iso.datetime(),
|
|
133
|
+
by: z.union([z.object({ account: z.string().min(1).max(100) }), z.literal("owners")]).nullable(),
|
|
134
|
+
standing: z.boolean()
|
|
135
|
+
});
|
|
136
|
+
z.object({ notices: z.array(appNotice) });
|
|
137
|
+
// ../contract/src/workflow.ts
|
|
138
|
+
/** レコードの派生の状態と未公開の変更 */
|
|
139
|
+
function recordStateOf(row) {
|
|
140
|
+
const state = typeof row.scheduled_at === "string" ? "scheduled" : row.status === "published" ? "published" : "draft";
|
|
141
|
+
return {
|
|
142
|
+
state,
|
|
143
|
+
changes: (state === "published" || state === "scheduled") && row.has_draft === true ? "draft" : "none"
|
|
144
|
+
};
|
|
145
|
+
}
|
|
146
|
+
/** 公開中か予約の状態か */
|
|
147
|
+
const isLiveState = (state) => state === "published" || state === "scheduled";
|
|
148
|
+
// ../contract/src/paymentPort.ts
|
|
149
|
+
/** ポートの id */
|
|
150
|
+
const PAYMENT_PORT = "tunasand:payment@1";
|
|
151
|
+
/** 価格の種類(one_time: 買い切り、recurring: 継続) */
|
|
152
|
+
const PRICE_KINDS = ["one_time", "recurring"];
|
|
153
|
+
/** 継続の周期 */
|
|
154
|
+
const PRICE_INTERVALS = ["month", "year"];
|
|
155
|
+
/** 通貨(ISO 4217の小文字。金額は通貨の最小の単位の整数) */
|
|
156
|
+
const PRICE_CURRENCIES = ["jpy", "usd"];
|
|
157
|
+
/** 購入の状態 */
|
|
158
|
+
const PURCHASE_STATUSES = ["paid", "refunded"];
|
|
159
|
+
/** 購読の状態(外部の決済のサービスの購読の状態の語) */
|
|
160
|
+
const SUBSCRIPTION_STATUSES = [
|
|
161
|
+
"incomplete",
|
|
162
|
+
"incomplete_expired",
|
|
163
|
+
"trialing",
|
|
164
|
+
"active",
|
|
165
|
+
"past_due",
|
|
166
|
+
"unpaid",
|
|
167
|
+
"paused",
|
|
168
|
+
"canceled"
|
|
169
|
+
];
|
|
170
|
+
/** 上限(名前の字数、金額、外部の ID とイベントの ID の字数、URL の字数、冪等キーの字数) */
|
|
171
|
+
const PAYMENT_LIMITS = {
|
|
172
|
+
nameMaxChars: 200,
|
|
173
|
+
amountMax: 99999999,
|
|
174
|
+
refMaxChars: 255,
|
|
175
|
+
urlMaxChars: 2e3,
|
|
176
|
+
idempotencyKeyMaxChars: 128
|
|
177
|
+
};
|
|
178
|
+
/** 価格の lookup_key(`<オファーの ID>.<価格の ID>`。価格は作った後に金額と周期を変えない) */
|
|
179
|
+
const priceLookupKeyOf = (offerId, priceId) => `${offerId}.${priceId}`;
|
|
180
|
+
z.string().max(PAYMENT_LIMITS.urlMaxChars).regex(/^https:\/\/\S+$/);
|
|
181
|
+
const ref = z.string().min(1).max(PAYMENT_LIMITS.refMaxChars);
|
|
182
|
+
const instant = z.iso.datetime({ offset: true });
|
|
183
|
+
/** 反映の共通の項目(eventId は外部のサービスのイベントの ID、observedAt はプロバイダーが外部の状態を取得した時刻) */
|
|
184
|
+
const reflectionBase = z.strictObject({
|
|
185
|
+
eventId: ref,
|
|
186
|
+
channelId: ref,
|
|
187
|
+
providerRef: ref,
|
|
188
|
+
offerId: ref,
|
|
189
|
+
priceId: ref,
|
|
190
|
+
endUserId: ref,
|
|
191
|
+
observedAt: instant
|
|
192
|
+
});
|
|
193
|
+
reflectionBase.extend({
|
|
194
|
+
status: z.enum(PURCHASE_STATUSES),
|
|
195
|
+
amount: z.number().int().min(0).max(PAYMENT_LIMITS.amountMax),
|
|
196
|
+
currency: z.enum(PRICE_CURRENCIES)
|
|
197
|
+
});
|
|
198
|
+
reflectionBase.extend({
|
|
199
|
+
status: z.enum(SUBSCRIPTION_STATUSES),
|
|
200
|
+
currentPeriodEnd: instant,
|
|
201
|
+
cancelAtPeriodEnd: z.boolean()
|
|
202
|
+
});
|
|
203
|
+
export { cyclicCollections as _, PRICE_KINDS as a, priceLookupKeyOf as c, NOTICES_PORT as d, manifestDocumentOf as f, ORIGIN_REF as g, IMPORT_ITEMS_MAX as h, PRICE_INTERVALS as i, isLiveState as l, IMPORT_EVENTS as m, PAYMENT_PORT as n, PURCHASE_STATUSES as o, END_USER_REF as p, PRICE_CURRENCIES as r, SUBSCRIPTION_STATUSES as s, PAYMENT_LIMITS as t, recordStateOf as u, importIdOf as v, importItemOfRow as y };
|
package/dist/preview.js
CHANGED
|
@@ -1 +1,8 @@
|
|
|
1
|
-
|
|
1
|
+
import { t as SECRET_TOKEN_PREFIXES } from "./ids-DmtIoqBX.js";
|
|
2
|
+
// src/preview.ts
|
|
3
|
+
/** CMS の転送のチケット(Authorization: Bearer がチケットの形でなければ null。照合は配信 API) */
|
|
4
|
+
function perspectiveTicketOf(request) {
|
|
5
|
+
const bearer = /^Bearer\s+(\S+)$/i.exec(request.headers.get("authorization") ?? "")?.[1];
|
|
6
|
+
return bearer?.startsWith(SECRET_TOKEN_PREFIXES.perspectiveTicket) ? bearer : null;
|
|
7
|
+
}
|
|
8
|
+
export { perspectiveTicketOf };
|
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import { l as
|
|
1
|
+
import { l as richTextProblemText } from "./declared-CE4a61qb.js";
|
|
2
2
|
// ../rich-text/src/types.ts
|
|
3
3
|
/** 名前のついた値の見た目の種類(色・背景・大きさ) */
|
|
4
4
|
const STYLE_KINDS = [
|
|
@@ -22,7 +22,7 @@ const SAFE_HREF = /^(?:https?:\/\/|mailto:|#|\/(?![/\\]))/i;
|
|
|
22
22
|
/** 本文のリンク先として許可する形か(保存の検査とサイトの出力で共通) */
|
|
23
23
|
const isSafeHref = (href) => SAFE_HREF.test(href);
|
|
24
24
|
/** 許可しないリンク先の問題の文言 */
|
|
25
|
-
const unsafeHrefMessage = (href) =>
|
|
25
|
+
const unsafeHrefMessage = (href) => richTextProblemText("link_unsafe", { href });
|
|
26
26
|
// ../rich-text/src/inline.ts
|
|
27
27
|
/** 装飾の順序(外側から内側、Markdown と HTML の入れ子の順) */
|
|
28
28
|
const MARK_ORDER = [
|
|
@@ -69,7 +69,7 @@ const CSS_SIZE = /^(\d{1,4}(\.\d{1,3})?(%|px|em|rem|pt)|xx-small|x-small|small|m
|
|
|
69
69
|
/** 元の CSS の値として描画してよいか(kind は色か大きさ) */
|
|
70
70
|
const isSafeCssValue = (kind, value) => (kind === "size" ? CSS_SIZE : CSS_COLOR).test(value.trim());
|
|
71
71
|
/** 本文を設定で検査(合わない箇所をすべて返却) */
|
|
72
|
-
function
|
|
72
|
+
function checkRichText(body, profile) {
|
|
73
73
|
const problems = [];
|
|
74
74
|
const allowedMarks = new Set(profile.marks);
|
|
75
75
|
body.forEach((block, index) => {
|
|
@@ -81,50 +81,50 @@ function checkBody(body, profile) {
|
|
|
81
81
|
for (const inline of r) {
|
|
82
82
|
if (typeof inline === "string") continue;
|
|
83
83
|
if ("component" in inline) {
|
|
84
|
-
if (plain) add(
|
|
85
|
-
else if (!profile.components.includes(inline.component)) add(
|
|
84
|
+
if (plain) add(richTextProblemText("inline_component_here"));
|
|
85
|
+
else if (!profile.components.includes(inline.component)) add(richTextProblemText("inline_component_unavailable", { name: inline.component }));
|
|
86
86
|
continue;
|
|
87
87
|
}
|
|
88
|
-
if (plain && (inline.marks?.length || inline.link)) add(
|
|
89
|
-
for (const m of inline.marks ?? []) if (!allowedMarks.has(m)) add(
|
|
90
|
-
if (profile.
|
|
91
|
-
if (inline.link?.rel && !profile.
|
|
92
|
-
if (inline.link?.target && !profile.
|
|
88
|
+
if (plain && (inline.marks?.length || inline.link)) add(richTextProblemText("marks_here"));
|
|
89
|
+
for (const m of inline.marks ?? []) if (!allowedMarks.has(m)) add(richTextProblemText("mark_unavailable", { mark: m }));
|
|
90
|
+
if (profile.combine_marks === false && (inline.marks?.length ?? 0) + (inline.link ? 1 : 0) > 1) add(richTextProblemText("marks_combined"));
|
|
91
|
+
if (inline.link?.rel && !profile.link_rels?.includes(inline.link.rel)) add(richTextProblemText("link_rel_unavailable", { rel: inline.link.rel }));
|
|
92
|
+
if (inline.link?.target && !profile.link_targets) add(richTextProblemText("link_target_unavailable"));
|
|
93
93
|
if (inline.link && !isSafeHref(inline.link.href)) add(unsafeHrefMessage(inline.link.href));
|
|
94
94
|
if (inline.style) textStyle(inline.style, plain);
|
|
95
95
|
}
|
|
96
96
|
};
|
|
97
97
|
const textStyle = (style, plain) => {
|
|
98
|
-
if (plain) add(
|
|
98
|
+
if (plain) add(richTextProblemText("text_style_here"));
|
|
99
99
|
for (const kind of STYLE_KINDS) {
|
|
100
100
|
const v = style[kind];
|
|
101
101
|
if (!v) continue;
|
|
102
|
-
const declared = profile.
|
|
103
|
-
if (!declared) add(
|
|
104
|
-
else if (v.name && !declared.some((d) => d.name === v.name)) add(
|
|
102
|
+
const declared = profile.text_style?.[kind];
|
|
103
|
+
if (!declared) add(richTextProblemText("style_unavailable", { kind }));
|
|
104
|
+
else if (v.name && !declared.some((d) => d.name === v.name)) add(richTextProblemText("style_name_unknown", {
|
|
105
105
|
kind,
|
|
106
106
|
name: v.name
|
|
107
107
|
}));
|
|
108
|
-
if (!v.name && !v.value) add(
|
|
109
|
-
if (v.value && !isSafeCssValue(kind, v.value)) add(
|
|
108
|
+
if (!v.name && !v.value) add(richTextProblemText("style_empty", { kind }));
|
|
109
|
+
if (v.value && !isSafeCssValue(kind, v.value)) add(richTextProblemText("style_value_unsafe", {
|
|
110
110
|
kind,
|
|
111
111
|
value: v.value
|
|
112
112
|
}));
|
|
113
113
|
}
|
|
114
|
-
for (const name of style.styles ?? []) if (!profile.
|
|
114
|
+
for (const name of style.styles ?? []) if (!profile.text_style?.styles?.some((d) => d.name === name)) add(richTextProblemText("named_style_unknown", { name }));
|
|
115
115
|
};
|
|
116
116
|
const align = (a) => {
|
|
117
|
-
if (a && !profile.align) add(
|
|
117
|
+
if (a && !profile.align) add(richTextProblemText("align_unavailable"));
|
|
118
118
|
};
|
|
119
119
|
const cell = (c, head) => {
|
|
120
120
|
if (isTableCell(c)) {
|
|
121
|
-
if (!profile.table?.cells) add(
|
|
122
|
-
if ((c.colspan ?? 1) < 1 || (c.rowspan ?? 1) < 1) add(
|
|
123
|
-
c.content.forEach((r) => rich(r, (head || Boolean(c.header)) && profile.plain?.includes("
|
|
124
|
-
} else rich(c, head && profile.plain?.includes("
|
|
121
|
+
if (!profile.table?.cells) add(richTextProblemText("table_cells_unavailable"));
|
|
122
|
+
if ((c.colspan ?? 1) < 1 || (c.rowspan ?? 1) < 1) add(richTextProblemText("table_span_invalid"));
|
|
123
|
+
c.content.forEach((r) => rich(r, (head || Boolean(c.header)) && profile.plain?.includes("table_head")));
|
|
124
|
+
} else rich(c, head && profile.plain?.includes("table_head"));
|
|
125
125
|
};
|
|
126
126
|
const variant = (v, allowed = []) => {
|
|
127
|
-
if (v && !allowed.includes(v)) add(
|
|
127
|
+
if (v && !allowed.includes(v)) add(richTextProblemText("variant_unavailable", { variant: v }));
|
|
128
128
|
};
|
|
129
129
|
const b = block;
|
|
130
130
|
switch (b.type) {
|
|
@@ -134,7 +134,7 @@ function checkBody(body, profile) {
|
|
|
134
134
|
rich(b.content);
|
|
135
135
|
break;
|
|
136
136
|
case "heading":
|
|
137
|
-
if (!profile.headings.includes(b.level)) add(
|
|
137
|
+
if (!profile.headings.includes(b.level)) add(richTextProblemText("heading_unavailable", {
|
|
138
138
|
level: b.level,
|
|
139
139
|
levels: profile.headings.join(", ")
|
|
140
140
|
}));
|
|
@@ -145,12 +145,12 @@ function checkBody(body, profile) {
|
|
|
145
145
|
case "list": {
|
|
146
146
|
const p = profile.list;
|
|
147
147
|
if (!p) {
|
|
148
|
-
add(
|
|
148
|
+
add(richTextProblemText("list_unavailable"));
|
|
149
149
|
break;
|
|
150
150
|
}
|
|
151
|
-
if (!p.nested && b.items.some((i) => i.children)) add(
|
|
151
|
+
if (!p.nested && b.items.some((i) => i.children)) add(richTextProblemText("list_nested_unavailable"));
|
|
152
152
|
const list = (l) => {
|
|
153
|
-
if (l.ordered && !p.ordered) add(
|
|
153
|
+
if (l.ordered && !p.ordered) add(richTextProblemText("list_ordered_unavailable"));
|
|
154
154
|
variant(l.variant, p.variants);
|
|
155
155
|
l.items.forEach((i) => {
|
|
156
156
|
rich(i.content);
|
|
@@ -163,61 +163,61 @@ function checkBody(body, profile) {
|
|
|
163
163
|
case "quote": {
|
|
164
164
|
const p = profile.quote;
|
|
165
165
|
if (!p) {
|
|
166
|
-
add(
|
|
166
|
+
add(richTextProblemText("quote_unavailable"));
|
|
167
167
|
break;
|
|
168
168
|
}
|
|
169
|
-
if (!p.multiple && b.content.length > 1) add(
|
|
170
|
-
if (!p.cite && b.cite) add(
|
|
169
|
+
if (!p.multiple && b.content.length > 1) add(richTextProblemText("quote_single"));
|
|
170
|
+
if (!p.cite && b.cite) add(richTextProblemText("quote_cite_unavailable"));
|
|
171
171
|
if (b.cite?.href && !isSafeHref(b.cite.href)) add(unsafeHrefMessage(b.cite.href));
|
|
172
172
|
variant(b.variant);
|
|
173
173
|
b.content.forEach((r) => rich(r));
|
|
174
174
|
break;
|
|
175
175
|
}
|
|
176
176
|
case "code":
|
|
177
|
-
if (!profile.code) add(
|
|
178
|
-
else if (!profile.code.caption && b.caption) add(
|
|
179
|
-
else if (!profile.code.filename && b.filename) add(
|
|
180
|
-
else if (b.lang && profile.code.
|
|
177
|
+
if (!profile.code) add(richTextProblemText("code_unavailable"));
|
|
178
|
+
else if (!profile.code.caption && b.caption) add(richTextProblemText("code_caption_unavailable"));
|
|
179
|
+
else if (!profile.code.filename && b.filename) add(richTextProblemText("code_filename_unavailable"));
|
|
180
|
+
else if (b.lang && profile.code.component_langs?.[b.lang]) add(richTextProblemText("code_component_lang", {
|
|
181
181
|
lang: b.lang,
|
|
182
|
-
component: profile.code.
|
|
182
|
+
component: profile.code.component_langs[b.lang]
|
|
183
183
|
}));
|
|
184
184
|
variant(b.variant);
|
|
185
185
|
break;
|
|
186
186
|
case "image":
|
|
187
|
-
if (!profile.image) add(
|
|
187
|
+
if (!profile.image) add(richTextProblemText("image_unavailable"));
|
|
188
188
|
else {
|
|
189
|
-
if (b.link && !profile.image.link) add(
|
|
189
|
+
if (b.link && !profile.image.link) add(richTextProblemText("image_link_unavailable"));
|
|
190
190
|
if (b.link && !isSafeHref(b.link.href)) add(unsafeHrefMessage(b.link.href));
|
|
191
|
-
if (b.align && !profile.image.align) add(
|
|
191
|
+
if (b.align && !profile.image.align) add(richTextProblemText("image_align_unavailable"));
|
|
192
192
|
}
|
|
193
193
|
variant(b.variant, profile.image?.variants);
|
|
194
194
|
break;
|
|
195
195
|
case "file":
|
|
196
|
-
if (!profile.file) add(
|
|
196
|
+
if (!profile.file) add(richTextProblemText("file_unavailable"));
|
|
197
197
|
break;
|
|
198
198
|
case "table": {
|
|
199
199
|
const p = profile.table;
|
|
200
200
|
if (!p) {
|
|
201
|
-
add(
|
|
201
|
+
add(richTextProblemText("table_unavailable"));
|
|
202
202
|
break;
|
|
203
203
|
}
|
|
204
|
-
if (p.head === "required" && !b.head) add(
|
|
205
|
-
if (p.caption === "required" && !b.caption) add(
|
|
206
|
-
if (p.caption === "none" && b.caption) add(
|
|
204
|
+
if (p.head === "required" && !b.head) add(richTextProblemText("table_head_required"));
|
|
205
|
+
if (p.caption === "required" && !b.caption) add(richTextProblemText("table_caption_required"));
|
|
206
|
+
if (p.caption === "none" && b.caption) add(richTextProblemText("table_caption_unavailable"));
|
|
207
207
|
variant(b.variant);
|
|
208
|
-
b.head?.forEach((r) => rich(r, profile.plain?.includes("
|
|
208
|
+
b.head?.forEach((r) => rich(r, profile.plain?.includes("table_head")));
|
|
209
209
|
b.rows.forEach((row) => row.forEach((c) => cell(c, false)));
|
|
210
210
|
break;
|
|
211
211
|
}
|
|
212
212
|
case "divider":
|
|
213
|
-
if (!profile.divider) add(
|
|
213
|
+
if (!profile.divider) add(richTextProblemText("divider_unavailable"));
|
|
214
214
|
break;
|
|
215
215
|
case "html":
|
|
216
|
-
if (!profile.html) add(
|
|
216
|
+
if (!profile.html) add(richTextProblemText("html_unavailable"));
|
|
217
217
|
break;
|
|
218
|
-
case "component": if (!profile.components.includes(b.name)) add(
|
|
218
|
+
case "component": if (!profile.components.includes(b.name)) add(richTextProblemText("component_unavailable", { name: b.name }));
|
|
219
219
|
}
|
|
220
220
|
});
|
|
221
221
|
return problems;
|
|
222
222
|
}
|
|
223
|
-
export { mergeStyle as a, ALIGNS as c, MARK_HTML_TAGS as i, cellParagraphs as l, isSafeCssValue as n, sortMarks as o, HTML_TAG_MARKS as r, isSafeHref as s,
|
|
223
|
+
export { mergeStyle as a, ALIGNS as c, MARK_HTML_TAGS as i, cellParagraphs as l, isSafeCssValue as n, sortMarks as o, HTML_TAG_MARKS as r, isSafeHref as s, checkRichText as t, isTableCell as u };
|
package/dist/rich-text.js
CHANGED
|
@@ -1,5 +1,5 @@
|
|
|
1
|
-
import { a as coreComponentOf, c as embedSrcOf, l as
|
|
2
|
-
import { c as ALIGNS, i as MARK_HTML_TAGS, l as cellParagraphs, n as isSafeCssValue, o as sortMarks, s as isSafeHref, t as
|
|
1
|
+
import { a as coreComponentOf, c as embedSrcOf, l as richTextProblemText, n as declaredPropsZod, o as EMBED_PROVIDERS, r as CITE, s as embedOfUrl } from "./declared-CE4a61qb.js";
|
|
2
|
+
import { c as ALIGNS, i as MARK_HTML_TAGS, l as cellParagraphs, n as isSafeCssValue, o as sortMarks, s as isSafeHref, t as checkRichText, u as isTableCell } from "./profile-DBsXLvvI.js";
|
|
3
3
|
import { z } from "zod";
|
|
4
4
|
// ../rich-text/src/description.ts
|
|
5
5
|
/** meta description の長さの上限(検索結果で省略されにくい字数の目安) */
|
|
@@ -81,7 +81,7 @@ const CSS_PROPERTY = {
|
|
|
81
81
|
const EMBED_SANDBOX = "allow-scripts allow-same-origin allow-popups allow-presentation";
|
|
82
82
|
const EMBED_ALLOW = "encrypted-media; picture-in-picture; fullscreen";
|
|
83
83
|
/** 本文を HTML に */
|
|
84
|
-
function
|
|
84
|
+
function richTextToHtml(body, options) {
|
|
85
85
|
const styleAttr = (style) => {
|
|
86
86
|
const decls = Object.keys(CSS_PROPERTY).flatMap((kind) => {
|
|
87
87
|
const v = style[kind];
|
|
@@ -180,7 +180,7 @@ function bodyToHtml(body, options) {
|
|
|
180
180
|
href
|
|
181
181
|
})}>${image ?? ""}${text("link-card-title", p.title)}${text("link-card-desc", p.desc)}${text("link-card-site", p.site)}</a>`;
|
|
182
182
|
}
|
|
183
|
-
case "gallery": return `<div class="gallery">${(Array.isArray(p.items) ? p.items : []).map((i) => `<figure>${imageHtml(i.
|
|
183
|
+
case "gallery": return `<div class="gallery">${(Array.isArray(p.items) ? p.items : []).map((i) => `<figure>${imageHtml(i.file, void 0) ?? ""}${i.caption ? `<figcaption>${esc(i.caption)}</figcaption>` : ""}</figure>`).join("")}</div>`;
|
|
184
184
|
default: return "";
|
|
185
185
|
}
|
|
186
186
|
};
|
|
@@ -205,7 +205,7 @@ function bodyToHtml(body, options) {
|
|
|
205
205
|
return b.caption ? `<figure${attrs({ class: b.variant })}>${pre}<figcaption>${esc(b.caption)}</figcaption></figure>` : pre;
|
|
206
206
|
}
|
|
207
207
|
case "image": {
|
|
208
|
-
const img = imageHtml(b.
|
|
208
|
+
const img = imageHtml(b.file, b.alt);
|
|
209
209
|
if (!img) return "";
|
|
210
210
|
const open = b.link ? linkOpen(b.link) : null;
|
|
211
211
|
return `<figure${attrs({
|
|
@@ -219,7 +219,7 @@ function bodyToHtml(body, options) {
|
|
|
219
219
|
return `<table${attrs({ class: b.variant })}>${b.caption ? `<caption>${esc(b.caption)}</caption>` : ""}${head}${rows}</table>`;
|
|
220
220
|
}
|
|
221
221
|
case "file": {
|
|
222
|
-
const f = options.file?.(b.
|
|
222
|
+
const f = options.file?.(b.file);
|
|
223
223
|
if (!f || !isSafeHref(f.url)) return "";
|
|
224
224
|
return `<p class="file"><a${attrs({ href: f.url })}>${esc(b.label ?? f.url)}</a></p>`;
|
|
225
225
|
}
|
|
@@ -248,7 +248,7 @@ const liftCites = (text) => text.split(CITE_TEXT).flatMap((piece, i) => i % 2 ?
|
|
|
248
248
|
props: { id: piece }
|
|
249
249
|
}] : piece ? [piece] : []);
|
|
250
250
|
const link = z.object({
|
|
251
|
-
href: z.string().min(1,
|
|
251
|
+
href: z.string().min(1, richTextProblemText("link_href_missing")),
|
|
252
252
|
title: z.string().optional(),
|
|
253
253
|
rel: z.string().optional(),
|
|
254
254
|
target: z.literal("_blank").optional()
|
|
@@ -257,7 +257,7 @@ const named = z.object({
|
|
|
257
257
|
name: z.string().min(1).optional(),
|
|
258
258
|
value: z.string().min(1).optional()
|
|
259
259
|
});
|
|
260
|
-
const
|
|
260
|
+
const text_style = z.object({
|
|
261
261
|
color: named.optional(),
|
|
262
262
|
background: named.optional(),
|
|
263
263
|
size: named.optional(),
|
|
@@ -267,7 +267,7 @@ const text = z.object({
|
|
|
267
267
|
text: z.string(),
|
|
268
268
|
marks: z.array(z.enum(MARKS)).optional(),
|
|
269
269
|
link: link.optional(),
|
|
270
|
-
style:
|
|
270
|
+
style: text_style.optional()
|
|
271
271
|
});
|
|
272
272
|
const align = z.enum(ALIGNS).optional();
|
|
273
273
|
/** 部品の props の検査(名前で核のコンポーネント、なければ宣言した部品、どちらもないか種類が違えば null) */
|
|
@@ -285,7 +285,7 @@ const inlineComponentOf = (declared) => z.object({
|
|
|
285
285
|
const props = propsOf(c.component, true, z.never(), declared);
|
|
286
286
|
if (!props) return void ctx.addIssue({
|
|
287
287
|
code: "custom",
|
|
288
|
-
message:
|
|
288
|
+
message: richTextProblemText("inline_component_missing", { name: c.component })
|
|
289
289
|
});
|
|
290
290
|
const r = props.safeParse(c.props ?? {});
|
|
291
291
|
if (!r.success) for (const issue of r.error.issues) ctx.addIssue({
|
|
@@ -365,7 +365,7 @@ function blockSchemaOf(profile, media, declared = []) {
|
|
|
365
365
|
align,
|
|
366
366
|
variant
|
|
367
367
|
}),
|
|
368
|
-
heading.refine((h) => h.content.some((i) => typeof i === "string" ? i.trim() : "text" in i && i.text?.trim()),
|
|
368
|
+
heading.refine((h) => h.content.some((i) => typeof i === "string" ? i.trim() : "text" in i && i.text?.trim()), richTextProblemText("heading_empty")),
|
|
369
369
|
list,
|
|
370
370
|
z.object({
|
|
371
371
|
type: z.literal("quote"),
|
|
@@ -386,7 +386,7 @@ function blockSchemaOf(profile, media, declared = []) {
|
|
|
386
386
|
}),
|
|
387
387
|
z.object({
|
|
388
388
|
type: z.literal("image"),
|
|
389
|
-
media,
|
|
389
|
+
file: media,
|
|
390
390
|
alt: z.string().optional(),
|
|
391
391
|
caption: z.string().optional(),
|
|
392
392
|
link: link.optional(),
|
|
@@ -406,7 +406,7 @@ function blockSchemaOf(profile, media, declared = []) {
|
|
|
406
406
|
}),
|
|
407
407
|
z.object({
|
|
408
408
|
type: z.literal("file"),
|
|
409
|
-
media,
|
|
409
|
+
file: media,
|
|
410
410
|
label: z.string().optional()
|
|
411
411
|
}),
|
|
412
412
|
z.object({ type: z.literal("divider") }),
|
|
@@ -426,7 +426,7 @@ function blockSchemaOf(profile, media, declared = []) {
|
|
|
426
426
|
if (!props) {
|
|
427
427
|
ctx.addIssue({
|
|
428
428
|
code: "custom",
|
|
429
|
-
message:
|
|
429
|
+
message: richTextProblemText("component_missing", { name: out.name })
|
|
430
430
|
});
|
|
431
431
|
return z.NEVER;
|
|
432
432
|
}
|
|
@@ -444,11 +444,11 @@ function blockSchemaOf(profile, media, declared = []) {
|
|
|
444
444
|
props: r.data
|
|
445
445
|
};
|
|
446
446
|
}
|
|
447
|
-
for (const p of
|
|
447
|
+
for (const p of checkRichText([out], profile)) ctx.addIssue({
|
|
448
448
|
code: "custom",
|
|
449
449
|
message: p.message
|
|
450
450
|
});
|
|
451
451
|
return out;
|
|
452
452
|
});
|
|
453
453
|
}
|
|
454
|
-
export { DESCRIPTION_MAX, EMBED_PROVIDERS, READING_SPEED, blockSchemaOf,
|
|
454
|
+
export { DESCRIPTION_MAX, EMBED_PROVIDERS, READING_SPEED, blockSchemaOf, cellParagraphs, citesOf, descriptionOf, embedOfUrl, embedSrcOf, excerptOf, isSafeCssValue, isSafeHref, isTableCell, linksOf, plainOf, readMinOf, richTextToHtml };
|