@ryusenkei/maezae 0.0.0-stage → 0.2.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/README.md CHANGED
@@ -1,3 +1,49 @@
1
- # Temporary Holding Version
1
+ # @ryusenkei/maezae
2
2
 
3
- This version is a temporary placeholder for this package. An operational version to replace this has been submitted for review and is awaiting a staged release.
3
+ maezae の SDK(導入先のサイト向け)
4
+
5
+ ## エントリポイント
6
+
7
+ | エントリポイント | 内容 |
8
+ | --- | --- |
9
+ | `@ryusenkei/maezae/delivery` | 配信 API `/content/v1` の取得(一覧の絞り込み・`/bundle`・ETag) |
10
+ | `@ryusenkei/maezae/body` | 本文のブロックの型と描画の補助 |
11
+ | `@ryusenkei/maezae/model` | コンテンツスキーマの型・ページのパス・画像の切り抜き |
12
+ | `@ryusenkei/maezae/preview` | プレビューと下書きの取得の署名(ヘッダー `x-preview-signature`) |
13
+ | `@ryusenkei/maezae/integrations` | 外の関数・Webhook が受け取る本文の型と署名の検証(ヘッダー `x-cms-signature`) |
14
+
15
+ ## 取得(Cloudflare Workers の service binding)
16
+
17
+ - バインディング: `services: [{ "binding": "CMS", "service": "<CMS のサーバーの Worker>", "entrypoint": "Delivery" }]`
18
+ - 媒体: URL のホスト名(媒体の管理画面のホスト名)
19
+ - 鍵: 媒体の管理画面の「設定 → 連携」で発行した API の鍵
20
+
21
+ ```ts
22
+ import { createDeliveryClient } from '@ryusenkei/maezae/delivery';
23
+
24
+ const client = createDeliveryClient((path, init) =>
25
+ env.CMS.fetch(`https://<媒体>.maezae.app${path}`, { ...init, headers: { ...init?.headers, authorization: `Bearer ${env.CMS_API_KEY}` } }),
26
+ );
27
+ ```
28
+
29
+ ## プレビュー
30
+
31
+ - CMS は媒体のサイトのオリジンへ、公開のページと同じパスで署名つきのリクエストを送信
32
+ - 鍵: 媒体の管理画面の「設定 → 連携」のプレビューの署名の鍵
33
+
34
+ ```ts
35
+ import { SIGNED_HEADERS, verifyRequest } from '@ryusenkei/maezae/preview';
36
+
37
+ const isPreview = await verifyRequest(env.PREVIEW_TOKEN, request, { header: SIGNED_HEADERS.preview });
38
+ ```
39
+
40
+ ## 外の関数・Webhook の受け手
41
+
42
+ - 鍵: 媒体の管理画面の「設定 → 連携」の登録ごとの署名の鍵
43
+
44
+ ```ts
45
+ import { type PublishCheckRequest, SIGNED_HEADERS, verifyRequest } from '@ryusenkei/maezae/integrations';
46
+
47
+ if (!(await verifyRequest(env.CMS_FUNCTION_SECRET, request, { header: SIGNED_HEADERS.outbound }))) return new Response(null, { status: 401 });
48
+ const body = (await request.json()) as PublishCheckRequest;
49
+ ```
package/dist/body.d.ts ADDED
@@ -0,0 +1,24 @@
1
+ import { _ as Rich, a as PropType, c as Body, d as Inline, f as InlineComponent, g as Mark, h as ListItem, i as PropSchema, l as ComponentBlock, m as List, o as PropsSchema, p as Link, r as DeclaredComponent, s as Block, t as blockSchemaOf, u as HeadingLevel, v as StandardBlock, y as Text } from "./index-C8duwjns.js";
2
+ /** meta description の長さの上限(検索結果で省略されにくい字数の目安) */
3
+ export declare const DESCRIPTION_MAX = 120;
4
+ /**
5
+ * 説明を meta description の長さに調整
6
+ * - 上限を超える場合: 上限までの最後の句点まで
7
+ * - 句点がない場合: 上限で切って省略の記号
8
+ */
9
+ export declare function descriptionOf(excerpt: string, max?: number): string;
10
+ /** 読了時間の既定の分速(字/分) */
11
+ export declare const READING_SPEED = 500;
12
+ /** 断片の列の文字(装飾・リンクは文字、インラインのコンポーネントは中の文字) */
13
+ export declare const plainOf: (rich: Rich) => string;
14
+ /** 本文の注が参照する出典の ID(出現の順、重複あり) */
15
+ export declare function citesOf<M>(body: Body<M>): string[];
16
+ /** 本文の導入の文字(最初の見出しまでの段落をつなげたもの、導入がなければ空) */
17
+ export declare function excerptOf<M>(body: Body<M>): string;
18
+ /** 読了時間(分、本文の文字列の字数を分速 speed で割った概算、1分以上) */
19
+ export declare const readMinOf: <M>(body: Body<M>, speed?: number) => number;
20
+ /** 本文にあるサイト内へのリンク先(`/` で始まる href、重複なし) */
21
+ export declare const linksOf: <M>(body: Body<M>) => string[];
22
+ /** 本文のリンク先として許可する形か(保存の検査とサイトの出力で共通) */
23
+ export declare const isSafeHref: (href: string) => boolean;
24
+ export { type Block, type Body, type ComponentBlock, type DeclaredComponent, type HeadingLevel, type Inline, type InlineComponent, type Link, type List, type ListItem, type Mark, type PropSchema, type PropType, type PropsSchema, type Rich, type StandardBlock, type Text, blockSchemaOf };