@tunasand/sdk 0.8.0 → 0.11.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 +121 -0
- package/README.md +162 -143
- package/dist/analytics.js +76 -65
- package/dist/app.js +184 -163
- package/dist/apps-DIxAWBSZ.js +318 -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-Dv4NxGZ7.js +81 -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-nUz1RetA.js +264 -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-B-Dbn64k.js +29 -0
- package/dist/end-users.d.ts +1 -0
- package/dist/end-users.js +185 -0
- package/dist/endUsers-DODfjnv1.js +77 -0
- package/dist/{errorLabels-BgtQ_zUn.js → errorLabels-aT2bnMsO.js} +355 -235
- 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-CrY_72Tn.js} +88 -44
- 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/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-Dcg1ajnW.js} +496 -263
- 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 +10 -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/apiKeys.d.ts +6 -2
- package/dist/types/contract/src/app.d.ts +15 -5
- package/dist/types/contract/src/appChannels.d.ts +114 -0
- package/dist/types/contract/src/appDefinition.d.ts +11 -5
- package/dist/types/contract/src/appDependencies.d.ts +87 -24
- package/dist/types/contract/src/appIdentities.d.ts +21 -0
- package/dist/types/contract/src/appInbound.d.ts +28 -0
- package/dist/types/contract/src/appMail.d.ts +106 -0
- package/dist/types/contract/src/appSecrets.d.ts +45 -0
- package/dist/types/contract/src/appServer.d.ts +408 -43
- package/dist/types/contract/src/approvals.d.ts +1 -1
- package/dist/types/contract/src/apps.d.ts +112 -55
- package/dist/types/contract/src/auditActions.d.ts +2 -2
- package/dist/types/contract/src/auditLabels.d.ts +111 -15
- package/dist/types/contract/src/authorize.d.ts +42 -14
- package/dist/types/contract/src/bridge.d.ts +34 -35
- package/dist/types/contract/src/consents.d.ts +32 -25
- package/dist/types/contract/src/deletion.d.ts +18 -0
- package/dist/types/contract/src/embeds.d.ts +16 -82
- package/dist/types/contract/src/{customerLabels.d.ts → endUserLabels.d.ts} +6 -9
- package/dist/types/contract/src/endUsers.d.ts +241 -0
- package/dist/types/contract/src/errorLabels.d.ts +63 -36
- package/dist/types/contract/src/errorLabelsEn.d.ts +46 -32
- 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 +43 -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 +23 -17
- 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 +52 -27
- package/dist/types/contract/src/integrationGraph.d.ts +83 -0
- package/dist/types/contract/src/issueLabels.d.ts +113 -81
- package/dist/types/contract/src/issueLabelsEn.d.ts +57 -41
- package/dist/types/contract/src/manage.d.ts +11 -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 +38 -0
- package/dist/types/contract/src/operatorOperations.d.ts +0 -63
- 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/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/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 +1 -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 +13 -19
- package/dist/types/contract/src/workspaceItems.d.ts +20 -6
- 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 +138 -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 +22 -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 +18 -10
- 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 +87 -46
- package/dist/types/schema/src/labels/ja.d.ts +89 -45
- 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 +82 -41
- 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 +40 -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 +190 -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-DkO2N7u2.js} +5 -6
- package/dist/types.js +1 -1
- package/dist/{typesSource-CWybQYus.js → typesSource-VJIxtN9b.js} +17 -15
- package/dist/workflow-CUpl6hO_.js +148 -0
- 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
|
@@ -1,10 +1,10 @@
|
|
|
1
|
-
import { c as formatMessage, f as problemText, l as problemFactory, n as
|
|
1
|
+
import { c as formatMessage, f as problemText, l as problemFactory, n as CORE_COMPONENT_LABELS, r as RICH_TEXT_PROBLEM_MESSAGES, t as BODY_GUIDE_LABELS } from "./ja-axQPxMJ-.js";
|
|
2
2
|
import { z } from "zod";
|
|
3
3
|
// ../rich-text/src/problems.ts
|
|
4
4
|
/** 本文の検査の問題を作る */
|
|
5
|
-
const
|
|
5
|
+
const richTextProblem = problemFactory(RICH_TEXT_PROBLEM_MESSAGES);
|
|
6
6
|
/** 問題の英語の既定の文(zod の message と検査の issues に入れ、problemOf で戻す) */
|
|
7
|
-
const
|
|
7
|
+
const richTextProblemText = (code, ...params) => problemText(richTextProblem(code, ...params));
|
|
8
8
|
/** Markdown の説明の文言 */
|
|
9
9
|
const guideText = (key, ...params) => formatMessage(BODY_GUIDE_LABELS[key], params[0]);
|
|
10
10
|
/** 部品の説明の文言(核の部品の説明と、宣言した部品の説明の組み立て) */
|
|
@@ -107,8 +107,8 @@ function embedSrcOf(target) {
|
|
|
107
107
|
// ../rich-text/src/library.ts
|
|
108
108
|
/** 注のコンポーネントの名前(本文からの算出 citesOf が参照) */
|
|
109
109
|
const CITE = "cite";
|
|
110
|
-
const https = z.string().regex(/^https:\/\//,
|
|
111
|
-
const caption = z.string().min(1,
|
|
110
|
+
const https = z.string().regex(/^https:\/\//, richTextProblemText("url_https"));
|
|
111
|
+
const caption = z.string().min(1, richTextProblemText("caption_missing"));
|
|
112
112
|
const datum = z.object({
|
|
113
113
|
label: z.string(),
|
|
114
114
|
value: z.number()
|
|
@@ -168,7 +168,7 @@ const CORE_COMPONENTS = [
|
|
|
168
168
|
inline: true,
|
|
169
169
|
description: componentText("citeDescription"),
|
|
170
170
|
example: componentText("citeExample"),
|
|
171
|
-
props: () => z.object({ id: z.string().min(1,
|
|
171
|
+
props: () => z.object({ id: z.string().min(1, richTextProblemText("cite_source_missing")) })
|
|
172
172
|
},
|
|
173
173
|
{
|
|
174
174
|
name: "pending",
|
|
@@ -188,7 +188,7 @@ const CORE_COMPONENTS = [
|
|
|
188
188
|
}] }),
|
|
189
189
|
from: (_, content) => ({ text: content[0]?.type === "paragraph" ? plain(content[0].content) : "" })
|
|
190
190
|
},
|
|
191
|
-
props: () => z.object({ text: z.string().min(1,
|
|
191
|
+
props: () => z.object({ text: z.string().min(1, richTextProblemText("speech_missing")) })
|
|
192
192
|
},
|
|
193
193
|
{
|
|
194
194
|
name: "chart",
|
|
@@ -219,8 +219,8 @@ const CORE_COMPONENTS = [
|
|
|
219
219
|
})
|
|
220
220
|
},
|
|
221
221
|
props: () => z.object({
|
|
222
|
-
source: z.string().min(1,
|
|
223
|
-
alt: z.string().min(1,
|
|
222
|
+
source: z.string().min(1, richTextProblemText("diagram_source_missing")),
|
|
223
|
+
alt: z.string().min(1, richTextProblemText("diagram_alt_missing")),
|
|
224
224
|
caption
|
|
225
225
|
})
|
|
226
226
|
},
|
|
@@ -231,18 +231,18 @@ const CORE_COMPONENTS = [
|
|
|
231
231
|
markdown: {
|
|
232
232
|
to: (p) => ({ content: p.items.map((i) => ({
|
|
233
233
|
type: "image",
|
|
234
|
-
|
|
234
|
+
file: i.file,
|
|
235
235
|
...i.caption ? { caption: i.caption } : {}
|
|
236
236
|
})) }),
|
|
237
237
|
from: (_, content) => ({ items: content.flatMap((b) => b.type === "image" ? [{
|
|
238
|
-
|
|
238
|
+
file: b.file,
|
|
239
239
|
...b.caption ? { caption: b.caption } : {}
|
|
240
240
|
}] : []) })
|
|
241
241
|
},
|
|
242
242
|
props: (media) => z.object({ items: z.array(z.object({
|
|
243
|
-
media,
|
|
243
|
+
file: media,
|
|
244
244
|
caption: z.string().optional()
|
|
245
|
-
})).min(2,
|
|
245
|
+
})).min(2, richTextProblemText("gallery_min")) })
|
|
246
246
|
},
|
|
247
247
|
{
|
|
248
248
|
name: "link-card",
|
|
@@ -262,7 +262,7 @@ const CORE_COMPONENTS = [
|
|
|
262
262
|
}).filter((e) => typeof e[1] === "string" && e[1] !== "")),
|
|
263
263
|
content: image ? [{
|
|
264
264
|
type: "image",
|
|
265
|
-
|
|
265
|
+
file: image
|
|
266
266
|
}] : []
|
|
267
267
|
};
|
|
268
268
|
},
|
|
@@ -275,18 +275,18 @@ const CORE_COMPONENTS = [
|
|
|
275
275
|
"desc"
|
|
276
276
|
]),
|
|
277
277
|
...attrs["fetched-at"] ? { fetchedAt: attrs["fetched-at"] } : {},
|
|
278
|
-
...content[0]?.type === "image" ? { image: content[0].
|
|
278
|
+
...content[0]?.type === "image" ? { image: content[0].file } : {}
|
|
279
279
|
})
|
|
280
280
|
},
|
|
281
281
|
props: (media) => z.union([z.object({
|
|
282
282
|
href: https,
|
|
283
|
-
title: z.string().min(1,
|
|
283
|
+
title: z.string().min(1, richTextProblemText("link_title_missing")),
|
|
284
284
|
site: z.string().optional(),
|
|
285
285
|
desc: z.string().optional(),
|
|
286
286
|
image: media.optional(),
|
|
287
287
|
fetchedAt: z.string().optional()
|
|
288
288
|
}), z.object({
|
|
289
|
-
ref: z.string().regex(/^[\w-]+\/[\w-]+$/,
|
|
289
|
+
ref: z.string().regex(/^[\w-]+\/[\w-]+$/, richTextProblemText("link_ref_format")),
|
|
290
290
|
title: z.string().optional(),
|
|
291
291
|
site: z.string().optional(),
|
|
292
292
|
desc: z.string().optional(),
|
|
@@ -325,7 +325,7 @@ const CORE_COMPONENTS = [
|
|
|
325
325
|
},
|
|
326
326
|
props: () => z.object({
|
|
327
327
|
provider: z.enum(EMBED_PROVIDERS),
|
|
328
|
-
id: z.string().regex(/^[\w-]+(\/[\w-]+)?$/,
|
|
328
|
+
id: z.string().regex(/^[\w-]+(\/[\w-]+)?$/, richTextProblemText("embed_id_invalid")),
|
|
329
329
|
url: https,
|
|
330
330
|
width: z.number().int().positive().optional(),
|
|
331
331
|
height: z.number().int().positive().optional(),
|
|
@@ -368,7 +368,7 @@ const CORE_COMPONENTS = [
|
|
|
368
368
|
label: z.string().optional(),
|
|
369
369
|
items: z.array(z.object({
|
|
370
370
|
href: https,
|
|
371
|
-
title: z.string().min(1,
|
|
371
|
+
title: z.string().min(1, richTextProblemText("link_title_missing")),
|
|
372
372
|
site: z.string().optional()
|
|
373
373
|
}))
|
|
374
374
|
})
|
|
@@ -392,55 +392,55 @@ const propSchema = z.lazy(() => z.object({
|
|
|
392
392
|
description: z.string().optional(),
|
|
393
393
|
enum: z.array(z.string().min(1)).min(1).optional(),
|
|
394
394
|
items: propSchema.optional(),
|
|
395
|
-
properties: z.record(z.string().regex(KEY,
|
|
395
|
+
properties: z.record(z.string().regex(KEY, richTextProblemText("prop_key_format")), propSchema).optional(),
|
|
396
396
|
required: z.array(z.string()).optional()
|
|
397
397
|
}).strict().superRefine((p, ctx) => {
|
|
398
398
|
if (p.enum && p.type !== "string") ctx.addIssue({
|
|
399
399
|
code: "custom",
|
|
400
|
-
message:
|
|
400
|
+
message: richTextProblemText("prop_enum_string"),
|
|
401
401
|
path: ["enum"]
|
|
402
402
|
});
|
|
403
403
|
if (p.type === "array" !== (p.items !== void 0)) ctx.addIssue({
|
|
404
404
|
code: "custom",
|
|
405
|
-
message:
|
|
405
|
+
message: richTextProblemText("prop_items"),
|
|
406
406
|
path: ["items"]
|
|
407
407
|
});
|
|
408
408
|
if ((p.properties || p.required) && p.type !== "object") ctx.addIssue({
|
|
409
409
|
code: "custom",
|
|
410
|
-
message:
|
|
410
|
+
message: richTextProblemText("prop_properties_object"),
|
|
411
411
|
path: ["properties"]
|
|
412
412
|
});
|
|
413
413
|
for (const key of p.required ?? []) if (!p.properties?.[key]) ctx.addIssue({
|
|
414
414
|
code: "custom",
|
|
415
|
-
message:
|
|
415
|
+
message: richTextProblemText("prop_required_missing", { key }),
|
|
416
416
|
path: ["required"]
|
|
417
417
|
});
|
|
418
418
|
}));
|
|
419
419
|
const declaredComponent = z.object({
|
|
420
|
-
name: z.string().regex(NAME,
|
|
421
|
-
label: z.string().min(1,
|
|
420
|
+
name: z.string().regex(NAME, richTextProblemText("component_name_format")),
|
|
421
|
+
label: z.string().min(1, richTextProblemText("component_label_missing")),
|
|
422
422
|
description: z.string().optional(),
|
|
423
423
|
inline: z.boolean().optional(),
|
|
424
424
|
props: z.object({
|
|
425
425
|
type: z.literal("object"),
|
|
426
|
-
properties: z.record(z.string().regex(KEY,
|
|
426
|
+
properties: z.record(z.string().regex(KEY, richTextProblemText("prop_key_format")), propSchema),
|
|
427
427
|
required: z.array(z.string()).optional()
|
|
428
428
|
}).strict()
|
|
429
429
|
}).strict().superRefine((d, ctx) => {
|
|
430
430
|
if (coreComponentOf(d.name) || RESERVED_BLOCK_NAMES.has(d.name) || RESERVED_INLINE_NAMES.has(d.name)) ctx.addIssue({
|
|
431
431
|
code: "custom",
|
|
432
|
-
message:
|
|
432
|
+
message: richTextProblemText("component_name_reserved", { name: d.name }),
|
|
433
433
|
path: ["name"]
|
|
434
434
|
});
|
|
435
435
|
for (const key of d.props.required ?? []) if (!d.props.properties[key]) ctx.addIssue({
|
|
436
436
|
code: "custom",
|
|
437
|
-
message:
|
|
437
|
+
message: richTextProblemText("prop_required_missing", { key }),
|
|
438
438
|
path: ["props", "required"]
|
|
439
439
|
});
|
|
440
440
|
if (d.inline) {
|
|
441
441
|
for (const [key, p] of Object.entries(d.props.properties)) if (p.type !== "string") ctx.addIssue({
|
|
442
442
|
code: "custom",
|
|
443
|
-
message:
|
|
443
|
+
message: richTextProblemText("inline_prop_string", { key }),
|
|
444
444
|
path: [
|
|
445
445
|
"props",
|
|
446
446
|
"properties",
|
|
@@ -455,7 +455,7 @@ const declaredComponentsSchema = z.array(declaredComponent).superRefine((list, c
|
|
|
455
455
|
list.forEach((d, i) => {
|
|
456
456
|
if (seen.has(d.name)) ctx.addIssue({
|
|
457
457
|
code: "custom",
|
|
458
|
-
message:
|
|
458
|
+
message: richTextProblemText("component_name_duplicate", { name: d.name }),
|
|
459
459
|
path: [i, "name"]
|
|
460
460
|
});
|
|
461
461
|
seen.add(d.name);
|
|
@@ -463,11 +463,11 @@ const declaredComponentsSchema = z.array(declaredComponent).superRefine((list, c
|
|
|
463
463
|
});
|
|
464
464
|
/** 1つの引数の検査(label はメッセージの項目名) */
|
|
465
465
|
function propZod(p, label) {
|
|
466
|
-
const wrong = { error: (iss) => iss.input === void 0 ?
|
|
466
|
+
const wrong = { error: (iss) => iss.input === void 0 ? richTextProblemText("prop_missing", { label }) : richTextProblemText("prop_shape", { label }) };
|
|
467
467
|
switch (p.type) {
|
|
468
468
|
case "string": return p.enum ? z.enum(p.enum, wrong) : z.string(wrong);
|
|
469
469
|
case "number": return z.number(wrong);
|
|
470
|
-
case "integer": return z.number(wrong).int(
|
|
470
|
+
case "integer": return z.number(wrong).int(richTextProblemText("prop_integer", { label }));
|
|
471
471
|
case "boolean": return z.boolean(wrong);
|
|
472
472
|
case "array": return z.array(propZod(p.items, label), wrong);
|
|
473
473
|
case "object": return objectZod(p.properties ?? {}, p.required ?? [], wrong);
|
|
@@ -479,7 +479,7 @@ const propsCache = /* @__PURE__ */ new WeakMap();
|
|
|
479
479
|
/** 宣言した部品の引数の検査(宣言ごとに作成を再利用) */
|
|
480
480
|
function declaredPropsZod(d) {
|
|
481
481
|
let schema = propsCache.get(d);
|
|
482
|
-
if (!schema) propsCache.set(d, schema = objectZod(d.props.properties, d.props.required ?? [], { error: () =>
|
|
482
|
+
if (!schema) propsCache.set(d, schema = objectZod(d.props.properties, d.props.required ?? [], { error: () => richTextProblemText("component_props_shape", { label: d.label }) }));
|
|
483
483
|
return schema;
|
|
484
484
|
}
|
|
485
|
-
export { coreComponentOf as a, embedSrcOf as c, CORE_COMPONENTS as i,
|
|
485
|
+
export { coreComponentOf as a, embedSrcOf as c, CORE_COMPONENTS as i, richTextProblemText as l, declaredPropsZod as n, EMBED_PROVIDERS as o, CITE as r, embedOfUrl as s, declaredComponentsSchema as t };
|
package/dist/delivery.js
CHANGED
|
@@ -1,8 +1,15 @@
|
|
|
1
|
-
import { a as listParams, i as subPath, n as
|
|
2
|
-
import { a as
|
|
3
|
-
import {
|
|
4
|
-
import {
|
|
1
|
+
import { a as listParams, i as subPath, n as createDeliveryClient, o as PERSPECTIVE_QUERY, r as recordsPath, s as DELIVERY_MARK_HEADERS, t as DeliveryError } from "./client-C8STAw9T.js";
|
|
2
|
+
import { a as parseInfraId, r as isUuid, t as SECRET_TOKEN_PREFIXES } from "./ids-DmtIoqBX.js";
|
|
3
|
+
import { a as cropRect, l as createClock, o as croppedHotspot, t as pagePathOf } from "./page-yo1cw1kW.js";
|
|
4
|
+
import { N as optionsOf, p as collectionByRef } from "./collection-nUz1RetA.js";
|
|
5
5
|
// src/delivery/cache.ts
|
|
6
|
+
/** 公開中以外の版のクエリか */
|
|
7
|
+
const asksUnpublished = (params) => params.has(PERSPECTIVE_QUERY.perspective) && params.get(PERSPECTIVE_QUERY.perspective) !== "published" || params.has(PERSPECTIVE_QUERY.revision) || params.has(PERSPECTIVE_QUERY.at);
|
|
8
|
+
/** Bearer が読み取りのトークンかチケットか(応答は資格ごとに違うため保持しない) */
|
|
9
|
+
const isReadCredential = (headers) => {
|
|
10
|
+
const bearer = headers.get("authorization")?.replace(/^Bearer\s+/i, "") ?? "";
|
|
11
|
+
return bearer.startsWith(SECRET_TOKEN_PREFIXES.readToken) || bearer.startsWith(SECRET_TOKEN_PREFIXES.perspectiveTicket);
|
|
12
|
+
};
|
|
6
13
|
/** 保持した日時(ミリ秒)を置く内部のヘッダー */
|
|
7
14
|
const CACHED_AT = "x-tunasand-cached-at";
|
|
8
15
|
/** 失敗のときに返せるように保持する期間(秒) */
|
|
@@ -35,7 +42,7 @@ function cachedDelivery(delivery, { cache, origin, freshSec = 30 }) {
|
|
|
35
42
|
return async (path, init = {}) => {
|
|
36
43
|
const headers = new Headers(init.headers);
|
|
37
44
|
const key = `${origin}${path}`;
|
|
38
|
-
if ((init.method ?? "GET").toUpperCase() !== "GET" || headers.has("if-none-match") || new URL(key).searchParams
|
|
45
|
+
if ((init.method ?? "GET").toUpperCase() !== "GET" || headers.has("if-none-match") || asksUnpublished(new URL(key).searchParams) || isReadCredential(headers)) return delivery(path, init);
|
|
39
46
|
const cached = await cache.match(key).catch(() => null) ?? null;
|
|
40
47
|
if (cached && Date.now() - Number(cached.headers.get(CACHED_AT)) < freshSec * 1e3) return fromCache(cached, cached.body);
|
|
41
48
|
const etag = cached?.headers.get("etag");
|
|
@@ -47,7 +54,7 @@ function cachedDelivery(delivery, { cache, origin, freshSec = 30 }) {
|
|
|
47
54
|
headers
|
|
48
55
|
});
|
|
49
56
|
} catch (e) {
|
|
50
|
-
if (cached) return fromCache(cached, cached.body, {
|
|
57
|
+
if (cached) return fromCache(cached, cached.body, { [DELIVERY_MARK_HEADERS.stale]: "1" });
|
|
51
58
|
throw e;
|
|
52
59
|
}
|
|
53
60
|
if (res.status === 304 && cached) {
|
|
@@ -55,14 +62,14 @@ function cachedDelivery(delivery, { cache, origin, freshSec = 30 }) {
|
|
|
55
62
|
await store(key, cached, body);
|
|
56
63
|
return fromCache(cached, body);
|
|
57
64
|
}
|
|
58
|
-
if (res.status === 200 && !res.headers.has(
|
|
65
|
+
if (res.status === 200 && !res.headers.has(DELIVERY_MARK_HEADERS.partial) && !res.headers.has(DELIVERY_MARK_HEADERS.stale)) {
|
|
59
66
|
const body = await res.text();
|
|
60
67
|
await store(key, res, body);
|
|
61
68
|
return fromCache(res, body);
|
|
62
69
|
}
|
|
63
70
|
if (cached && (res.status === 429 || res.status >= 500)) {
|
|
64
71
|
await res.body?.cancel();
|
|
65
|
-
return fromCache(cached, cached.body, {
|
|
72
|
+
return fromCache(cached, cached.body, { [DELIVERY_MARK_HEADERS.stale]: "1" });
|
|
66
73
|
}
|
|
67
74
|
return res;
|
|
68
75
|
};
|
|
@@ -96,7 +103,7 @@ function memoryDeliveryCache(maxEntries = 500) {
|
|
|
96
103
|
}
|
|
97
104
|
// src/delivery/changes.ts
|
|
98
105
|
/**
|
|
99
|
-
* since から
|
|
106
|
+
* since から has_more がなくなるまで読み、ページごとに apply を呼ぶ(戻り値は次回の since)
|
|
100
107
|
* - apply が成功してから次のページへ進む(失敗したら例外で止まり、保存済みの since から再開できる)
|
|
101
108
|
* - 410(保存の期間を過ぎた cursor): DeliveryError、since を null にして全件から取り直す
|
|
102
109
|
*/
|
|
@@ -105,102 +112,105 @@ async function readChanges(client, since, apply, { limit } = {}) {
|
|
|
105
112
|
for (;;) {
|
|
106
113
|
const page = await client.changes(cursor, limit === void 0 ? {} : { limit });
|
|
107
114
|
await apply(page);
|
|
108
|
-
cursor = page.
|
|
109
|
-
if (!page.
|
|
115
|
+
cursor = page.next_cursor;
|
|
116
|
+
if (!page.has_more) return cursor;
|
|
110
117
|
}
|
|
111
118
|
}
|
|
112
|
-
|
|
113
|
-
|
|
114
|
-
const
|
|
115
|
-
|
|
116
|
-
|
|
117
|
-
|
|
118
|
-
|
|
119
|
-
|
|
120
|
-
|
|
121
|
-
|
|
122
|
-
|
|
123
|
-
|
|
124
|
-
|
|
125
|
-
|
|
126
|
-
"application/vnd.openxmlformats-officedocument.spreadsheetml.sheet": "xlsx",
|
|
127
|
-
"application/vnd.openxmlformats-officedocument.presentationml.presentation": "pptx"
|
|
128
|
-
};
|
|
129
|
-
/** 形式の実体の種類 */
|
|
130
|
-
const mediaKindOf = (mimeType) => mimeType.startsWith("image/") ? "image" : mimeType.startsWith("video/") ? "video" : "other";
|
|
131
|
-
/** 形式の拡張子(配信しない形式は null) */
|
|
132
|
-
const mediaExtOf = (mimeType) => EXTENSIONS[mimeType] ?? null;
|
|
133
|
-
/** 拡張子の形式(配信しない拡張子は null) */
|
|
134
|
-
const mediaMimeOf = (ext) => Object.entries(EXTENSIONS).find(([, e]) => e === ext)?.[0] ?? null;
|
|
135
|
-
const SEGMENT = /^[A-Za-z0-9_-]+$/;
|
|
136
|
-
/** 実体の ID の形か(CMS の /media と配信の Worker の共通、保存先のほかのキーを ID として読ませない) */
|
|
137
|
-
const isMediaId = (id) => SEGMENT.test(id);
|
|
138
|
-
/** 配信 URL のパス(プロジェクト・ID の形が不正、配信しない形式なら null) */
|
|
139
|
-
function mediaPathOf({ kind, project, id, mimeType, width, height }) {
|
|
140
|
-
const ext = mediaExtOf(mimeType);
|
|
141
|
-
if (!ext || !SEGMENT.test(project) || !isMediaId(id) || mediaKindOf(mimeType) !== kind) return null;
|
|
142
|
-
if (kind === "image") return `/images/${project}/${id}-${Math.round(width)}x${Math.round(height)}.${ext}`;
|
|
143
|
-
return kind === "video" ? `/videos/${project}/${id}.${ext}` : `/files/${project}/${id}.${ext}`;
|
|
119
|
+
/** 署名の期限の上限(秒、運用の仮置き) */
|
|
120
|
+
const SIGNATURE_MAX_TTL_SEC = 604800;
|
|
121
|
+
const VERSION = "v1";
|
|
122
|
+
const SIGNATURE = /^v1\.(exact|any)\.([A-Za-z0-9_-]{8})\.(\d{1,12})\.([A-Za-z0-9_-]{43})$/;
|
|
123
|
+
/** URL の署名(署名がちょうど1つで、形が合うときだけ) */
|
|
124
|
+
function signedOf(url) {
|
|
125
|
+
const values = url.searchParams.getAll("sig");
|
|
126
|
+
const m = values.length === 1 ? SIGNATURE.exec(values[0]) : null;
|
|
127
|
+
return m && {
|
|
128
|
+
scope: m[1],
|
|
129
|
+
keyId: m[2],
|
|
130
|
+
exp: Number(m[3]),
|
|
131
|
+
mac: m[4]
|
|
132
|
+
};
|
|
144
133
|
}
|
|
145
|
-
|
|
146
|
-
const
|
|
147
|
-
const
|
|
148
|
-
|
|
149
|
-
|
|
150
|
-
|
|
151
|
-
|
|
152
|
-
const [, project, id, width, height, ext] = image;
|
|
153
|
-
return mediaMimeOf(ext)?.startsWith("image/") ? {
|
|
154
|
-
kind: "image",
|
|
155
|
-
project,
|
|
156
|
-
id,
|
|
157
|
-
ext,
|
|
158
|
-
width: Number(width),
|
|
159
|
-
height: Number(height)
|
|
160
|
-
} : null;
|
|
161
|
-
}
|
|
162
|
-
const video = VIDEO_PATH.exec(pathname);
|
|
163
|
-
if (video) {
|
|
164
|
-
const [, project, id, ext] = video;
|
|
165
|
-
return mediaMimeOf(ext)?.startsWith("video/") ? {
|
|
166
|
-
kind: "video",
|
|
167
|
-
project,
|
|
168
|
-
id,
|
|
169
|
-
ext
|
|
170
|
-
} : null;
|
|
171
|
-
}
|
|
172
|
-
const file = FILE_PATH.exec(pathname);
|
|
173
|
-
if (file) {
|
|
174
|
-
const [, project, id, ext] = file;
|
|
175
|
-
const mime = mediaMimeOf(ext);
|
|
176
|
-
return mime && mediaKindOf(mime) === "other" ? {
|
|
177
|
-
kind: "other",
|
|
178
|
-
project,
|
|
179
|
-
id,
|
|
180
|
-
ext
|
|
181
|
-
} : null;
|
|
182
|
-
}
|
|
183
|
-
return null;
|
|
134
|
+
/** 署名の範囲(署名なしと、形が違う署名は null) */
|
|
135
|
+
const signatureScopeOf = (url) => signedOf(url)?.scope ?? null;
|
|
136
|
+
const encode = (text) => new TextEncoder().encode(text);
|
|
137
|
+
const base64url = (buf) => btoa(String.fromCharCode(...new Uint8Array(buf))).replaceAll("+", "-").replaceAll("/", "_").replace(/=+$/, "");
|
|
138
|
+
/** 鍵の ID */
|
|
139
|
+
async function keyIdOf(secret) {
|
|
140
|
+
return base64url(await crypto.subtle.digest("SHA-256", encode(`tunasand:file-signing-key:${secret}`))).slice(0, 8);
|
|
184
141
|
}
|
|
185
|
-
|
|
186
|
-
|
|
187
|
-
|
|
188
|
-
|
|
142
|
+
/** exact の署名の対象のクエリ(sig を除く全部。鍵の順に並べ、同じ鍵の中の順は保つ) */
|
|
143
|
+
const queryOf = (url) => {
|
|
144
|
+
const params = new URLSearchParams(url.search);
|
|
145
|
+
params.delete("sig");
|
|
146
|
+
params.sort();
|
|
147
|
+
return params.toString();
|
|
148
|
+
};
|
|
149
|
+
async function macOf(secret, url, { scope, keyId, exp }) {
|
|
150
|
+
const key = await crypto.subtle.importKey("raw", encode(secret), {
|
|
189
151
|
name: "HMAC",
|
|
190
152
|
hash: "SHA-256"
|
|
191
153
|
}, false, ["sign"]);
|
|
192
|
-
|
|
154
|
+
const target = [
|
|
155
|
+
"tunasand:file",
|
|
156
|
+
VERSION,
|
|
157
|
+
scope,
|
|
158
|
+
keyId,
|
|
159
|
+
url.host,
|
|
160
|
+
url.pathname,
|
|
161
|
+
exp,
|
|
162
|
+
...scope === "exact" ? [queryOf(url)] : []
|
|
163
|
+
];
|
|
164
|
+
return base64url(await crypto.subtle.sign("HMAC", key, encode(target.join("\n"))));
|
|
193
165
|
}
|
|
194
166
|
/**
|
|
195
|
-
*
|
|
196
|
-
* - secret:
|
|
167
|
+
* 署名つきのファイルの URL(クエリ sig を付ける。前の署名は置き換える)
|
|
168
|
+
* - secret: プロジェクトの署名の鍵、scope: 既定は exact(変換を足してから署名する)
|
|
169
|
+
* - expiresInSec: 期限までの秒(既定は3600、1から SIGNATURE_MAX_TTL_SEC まで。ほかは例外 invalid_expiry)、now: 今の UNIX ミリ秒
|
|
197
170
|
*/
|
|
198
171
|
async function signMediaUrl(url, secret, options = {}) {
|
|
172
|
+
const { scope = "exact", expiresInSec = 3600, now = Date.now() } = options;
|
|
173
|
+
if (!Number.isInteger(expiresInSec) || expiresInSec < 1 || expiresInSec > 604800) throw new Error(`invalid_expiry: 1〜${SIGNATURE_MAX_TTL_SEC}`);
|
|
199
174
|
const u = new URL(url);
|
|
200
|
-
|
|
201
|
-
|
|
202
|
-
|
|
203
|
-
|
|
175
|
+
u.searchParams.delete("sig");
|
|
176
|
+
const exp = Math.floor(now / 1e3) + expiresInSec;
|
|
177
|
+
const keyId = await keyIdOf(secret);
|
|
178
|
+
const mac = await macOf(secret, u, {
|
|
179
|
+
scope,
|
|
180
|
+
keyId,
|
|
181
|
+
exp
|
|
182
|
+
});
|
|
183
|
+
u.searchParams.set("sig", [
|
|
184
|
+
VERSION,
|
|
185
|
+
scope,
|
|
186
|
+
keyId,
|
|
187
|
+
exp,
|
|
188
|
+
mac
|
|
189
|
+
].join("."));
|
|
190
|
+
return u.href;
|
|
191
|
+
}
|
|
192
|
+
const SEGMENT = /^[A-Za-z0-9_-]+$/;
|
|
193
|
+
/** 実体の ID の形か(CMS の /media、保存先のほかのキーを ID として読ませない) */
|
|
194
|
+
const isMediaId = (id) => SEGMENT.test(id);
|
|
195
|
+
const PROJECT_SLOT = "{project}";
|
|
196
|
+
/** 配信のオリジンのひな形から、プロジェクトの配信のオリジン(project は基盤の ID(base32)、ひな形に {project} がなければ null) */
|
|
197
|
+
function mediaOriginOf(template, project) {
|
|
198
|
+
if (!template.includes(PROJECT_SLOT) || !SEGMENT.test(project)) return null;
|
|
199
|
+
const origin = template.replace(PROJECT_SLOT, project.toLowerCase());
|
|
200
|
+
return URL.canParse(origin) ? new URL(origin).origin : null;
|
|
201
|
+
}
|
|
202
|
+
/** 実体の配信の URL(オリジンか ID の形が違えば null) */
|
|
203
|
+
function mediaUrlIn(template, project, id) {
|
|
204
|
+
const origin = isMediaId(id) ? mediaOriginOf(template, project) : null;
|
|
205
|
+
return origin && `${origin}${mediaPathOf(id)}`;
|
|
206
|
+
}
|
|
207
|
+
/** 実体の配信 URL のパス */
|
|
208
|
+
const mediaPathOf = (id) => `/${id}`;
|
|
209
|
+
const FILE_PATH = /^\/([0-9a-f]{8}-[0-9a-f]{4}-[0-9a-f]{4}-[0-9a-f]{4}-[0-9a-f]{12})$/;
|
|
210
|
+
/** 配信 URL のパスを解析(実体の UUID だけのパスのほかは null) */
|
|
211
|
+
function parseMediaPath(pathname) {
|
|
212
|
+
const id = FILE_PATH.exec(pathname)?.[1];
|
|
213
|
+
return id ? { id } : null;
|
|
204
214
|
}
|
|
205
215
|
/** 幅・高さの上限(画素) */
|
|
206
216
|
const IMAGE_SIZE_MAX = 4096;
|
|
@@ -217,9 +227,13 @@ const FORMATS = [
|
|
|
217
227
|
"webp",
|
|
218
228
|
"avif"
|
|
219
229
|
];
|
|
220
|
-
/**
|
|
230
|
+
/**
|
|
231
|
+
* URL に画像の変換のクエリを設定(ほかのクエリは残す)
|
|
232
|
+
* - 署名つきの URL は、範囲が any のものだけ(exact は変換も署名の対象なので、変換を足してから署名する。失敗は例外 exact_signed_url)
|
|
233
|
+
*/
|
|
221
234
|
function withImageParams(url, params) {
|
|
222
235
|
const u = new URL(url);
|
|
236
|
+
if (u.searchParams.has("sig") && signatureScopeOf(u) !== "any") throw new Error("exact_signed_url: add image params before signing (withImageParams, then signMediaUrl)");
|
|
223
237
|
const { rect, ...rest } = params;
|
|
224
238
|
for (const [k, v] of Object.entries(rest)) if (v !== void 0) u.searchParams.set(k, String(v));
|
|
225
239
|
if (rect) u.searchParams.set("rect", [
|
|
@@ -272,22 +286,13 @@ function imageParamsOf(query) {
|
|
|
272
286
|
}
|
|
273
287
|
// src/delivery/media.ts
|
|
274
288
|
/**
|
|
275
|
-
* 実体の ID から配信の URL を作る(origin
|
|
276
|
-
* -
|
|
277
|
-
* -
|
|
289
|
+
* 実体の ID から配信の URL を作る(origin は配信のオリジンのひな形 https://{project}.tunasandusercontent.com)
|
|
290
|
+
* - 配信 API の url と同じ値になる。寸法は URL になく、配信 API の応答から読む
|
|
291
|
+
* - ひな形に {project} がないとき、ID の形が違うとき(プロジェクトの UUID の形を含む)は null。非公開の実体は signMediaUrl で署名してから使う
|
|
278
292
|
*/
|
|
279
|
-
function mediaUrlOf(origin, { project, id
|
|
293
|
+
function mediaUrlOf(origin, { project, id }) {
|
|
280
294
|
const projectId = parseInfraId(project);
|
|
281
|
-
|
|
282
|
-
const path = mediaPathOf({
|
|
283
|
-
kind: mediaKindOf(mimeType),
|
|
284
|
-
project: projectId,
|
|
285
|
-
id,
|
|
286
|
-
mimeType,
|
|
287
|
-
width,
|
|
288
|
-
height
|
|
289
|
-
});
|
|
290
|
-
return path ? `${origin.replace(/\/$/, "")}${path}` : null;
|
|
295
|
+
return projectId && isUuid(id) ? mediaUrlIn(origin, projectId, id) : null;
|
|
291
296
|
}
|
|
292
297
|
/** 配信 URL の画像の切り抜き(クエリ rect、範囲なしは元の URL) */
|
|
293
298
|
const deliveredImageUrl = (src, rect) => rect ? withImageParams(src, { rect }) : src;
|
|
@@ -302,21 +307,23 @@ function mediaOf(base, imageUrl) {
|
|
|
302
307
|
const src = a.url ?? `${base}/${a.id}`;
|
|
303
308
|
const transform = imageUrl ?? (a.url ? deliveredImageUrl : void 0);
|
|
304
309
|
const alt = a.alt ?? "";
|
|
310
|
+
const width = a.width ?? 0;
|
|
311
|
+
const height = a.height ?? 0;
|
|
305
312
|
if (!transform || a.kind !== "image") return {
|
|
306
313
|
src,
|
|
307
|
-
width
|
|
308
|
-
height
|
|
314
|
+
width,
|
|
315
|
+
height,
|
|
309
316
|
alt,
|
|
310
317
|
...a.hotspot ? { hotspot: a.hotspot } : {}
|
|
311
318
|
};
|
|
312
319
|
if (!a.crop) return {
|
|
313
320
|
src: transform(src),
|
|
314
|
-
width
|
|
315
|
-
height
|
|
321
|
+
width,
|
|
322
|
+
height,
|
|
316
323
|
alt,
|
|
317
324
|
...a.hotspot ? { hotspot: a.hotspot } : {}
|
|
318
325
|
};
|
|
319
|
-
const rect = cropRect(
|
|
326
|
+
const rect = cropRect(width, height, a.crop);
|
|
320
327
|
return {
|
|
321
328
|
src: transform(src, rect),
|
|
322
329
|
width: rect.width,
|
|
@@ -376,4 +383,4 @@ function createDeliveryClock(timeZone) {
|
|
|
376
383
|
})
|
|
377
384
|
};
|
|
378
385
|
}
|
|
379
|
-
export {
|
|
386
|
+
export { DeliveryError, SIGNATURE_MAX_TTL_SEC, cachedDelivery, createDeliveryClient, createDeliveryClock, deliveredImageUrl, fieldOf, imageParamsOf, limitOf, listParams, mediaOf, mediaUrlOf, memoryDeliveryCache, optionLabels, pagePath, parseMediaPath, readChanges, recordsPath, signMediaUrl, subPath, withImageParams };
|
|
@@ -0,0 +1,46 @@
|
|
|
1
|
+
import { createHash } from "node:crypto";
|
|
2
|
+
import { existsSync, readFileSync, readdirSync } from "node:fs";
|
|
3
|
+
import { join } from "node:path";
|
|
4
|
+
// src/dev-operations.ts
|
|
5
|
+
/** キーの順によらない JSON */
|
|
6
|
+
const stable = (value) => JSON.stringify(value, (_, v) => typeof v === "object" && v !== null && !Array.isArray(v) ? Object.fromEntries(Object.entries(v).sort(([a], [b]) => a < b ? -1 : 1)) : v) ?? "null";
|
|
7
|
+
/** 記録のファイルの名前(操作の名前、種類、入力のハッシュ) */
|
|
8
|
+
const operationFixtureName = (name, returns, input = null) => `${createHash("sha256").update(`${returns} ${name}\n${stable(input)}`).digest("hex").slice(0, 16)}.json`;
|
|
9
|
+
const read = (file) => JSON.parse(readFileSync(file, "utf8"));
|
|
10
|
+
/** ディレクトリの記録の全部 */
|
|
11
|
+
const operationFixtures = (dir) => readdirSync(dir).filter((f) => f.endsWith(".json")).sort().map((f) => read(join(dir, f)));
|
|
12
|
+
const failed = (code) => Object.assign(new Error(code), {
|
|
13
|
+
name: "OperationError",
|
|
14
|
+
code
|
|
15
|
+
});
|
|
16
|
+
/** 記録を再生する操作(記録は呼ぶたびに読む) */
|
|
17
|
+
function fixtureOperations(dir) {
|
|
18
|
+
const found = (name, returns, input) => {
|
|
19
|
+
const file = join(dir, operationFixtureName(name, returns, input));
|
|
20
|
+
if (existsSync(file)) return read(file);
|
|
21
|
+
if (!operationFixtures(dir).some((f) => f.name === name && f.returns === returns)) throw failed("unknown_operation");
|
|
22
|
+
console.error(`no operation fixture: ${returns} ${name} (${operationFixtureName(name, returns, input)})`);
|
|
23
|
+
throw failed("failed");
|
|
24
|
+
};
|
|
25
|
+
return {
|
|
26
|
+
call: async (name, input = null) => found(name, "json", input).result,
|
|
27
|
+
open: async (name, input = null) => {
|
|
28
|
+
const { status, headers, body } = found(name, "bytes", input);
|
|
29
|
+
return new Response([
|
|
30
|
+
204,
|
|
31
|
+
205,
|
|
32
|
+
304
|
|
33
|
+
].includes(status) ? null : Buffer.from(body, "base64"), {
|
|
34
|
+
status,
|
|
35
|
+
headers
|
|
36
|
+
});
|
|
37
|
+
},
|
|
38
|
+
fetch: async () => {
|
|
39
|
+
throw failed("denied");
|
|
40
|
+
},
|
|
41
|
+
log: async (level, message) => {
|
|
42
|
+
console.error(`[${level}] ${message}`);
|
|
43
|
+
}
|
|
44
|
+
};
|
|
45
|
+
}
|
|
46
|
+
export { operationFixtureName as n, operationFixtures as r, fixtureOperations as t };
|