note-blog-kit 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/LICENSE +21 -0
- package/README.md +340 -2
- package/dist/cli/index.js +32 -0
- package/dist/index.cjs +2 -0
- package/dist/index.d.cts +76 -0
- package/dist/index.d.ts +76 -0
- package/dist/index.js +1 -0
- package/dist/iterate-articles-9dzDflSn.d.ts +84 -0
- package/dist/iterate-articles-BeI9bBh3.d.cts +84 -0
- package/dist/next/index.cjs +378 -0
- package/dist/next/index.d.cts +103 -0
- package/dist/next/index.d.ts +103 -0
- package/dist/next/index.js +375 -0
- package/dist/react/index.cjs +409 -0
- package/dist/react/index.d.cts +190 -0
- package/dist/react/index.d.ts +190 -0
- package/dist/react/index.js +404 -0
- package/dist/server/index.cjs +626 -0
- package/dist/server/index.d.cts +109 -0
- package/dist/server/index.d.ts +109 -0
- package/dist/server/index.js +610 -0
- package/dist/styles.css +427 -0
- package/package.json +109 -3
|
@@ -0,0 +1,109 @@
|
|
|
1
|
+
import { NoteArticle } from '../index.cjs';
|
|
2
|
+
export { NoteArticlePage, NoteArticleSummary, NoteAuthor, NoteEmbed, NoteEyecatch, NoteSource, NoteTocItem } from '../index.cjs';
|
|
3
|
+
import { N as NoteRequestOptions } from '../iterate-articles-BeI9bBh3.cjs';
|
|
4
|
+
export { I as IterateArticlesOptions, a as IterateArticlesResult, b as ListAllArticlesResult, L as ListArticlesOptions, i as iterateArticles, l as listAllArticles, c as listArticles } from '../iterate-articles-BeI9bBh3.cjs';
|
|
5
|
+
|
|
6
|
+
/** エラーの種類を表す安定した識別子 */
|
|
7
|
+
type NoteErrorCode = 'NOTE_NOT_FOUND' | 'NOTE_HTTP_ERROR' | 'NOTE_NETWORK_ERROR' | 'NOTE_TIMEOUT' | 'NOTE_SCHEMA_ERROR';
|
|
8
|
+
/** エラーのコンストラクタに渡す共通のオプション(ライブラリ内部用) */
|
|
9
|
+
interface NoteErrorOptions {
|
|
10
|
+
/** 元になったエラー */
|
|
11
|
+
cause?: unknown;
|
|
12
|
+
}
|
|
13
|
+
/**
|
|
14
|
+
* note-blog-kit/server が投げるエラーの基底クラス。
|
|
15
|
+
*
|
|
16
|
+
* 判定は `instanceof` ではなく {@link isNoteError} と `code` で行うことを推奨する
|
|
17
|
+
* (ESM と CJS が混在したり、パッケージが重複して読み込まれたりすると `instanceof` は一致しないことがある)。
|
|
18
|
+
* `isNoteError(error) && error.code === 'NOTE_HTTP_ERROR'` のように書くと `error.status` まで型が絞られる。
|
|
19
|
+
*
|
|
20
|
+
* コンストラクタはライブラリ内部で使うもので、利用者が作ることは想定していない。
|
|
21
|
+
*/
|
|
22
|
+
declare class NoteError extends Error {
|
|
23
|
+
name: string;
|
|
24
|
+
readonly code: NoteErrorCode;
|
|
25
|
+
constructor(message: string, options: NoteErrorOptions & {
|
|
26
|
+
code: NoteErrorCode;
|
|
27
|
+
});
|
|
28
|
+
}
|
|
29
|
+
/** ユーザーや記事が見つからない(HTTP 404) */
|
|
30
|
+
declare class NoteNotFoundError extends NoteError {
|
|
31
|
+
name: string;
|
|
32
|
+
readonly code: "NOTE_NOT_FOUND";
|
|
33
|
+
/** リクエストした URL */
|
|
34
|
+
readonly url: string;
|
|
35
|
+
constructor(message: string, options: NoteErrorOptions & {
|
|
36
|
+
url: string;
|
|
37
|
+
});
|
|
38
|
+
}
|
|
39
|
+
/** 404 以外の 2xx でない HTTP ステータス */
|
|
40
|
+
declare class NoteHttpError extends NoteError {
|
|
41
|
+
name: string;
|
|
42
|
+
readonly code: "NOTE_HTTP_ERROR";
|
|
43
|
+
readonly status: number;
|
|
44
|
+
/** リクエストした URL */
|
|
45
|
+
readonly url: string;
|
|
46
|
+
constructor(message: string, options: NoteErrorOptions & {
|
|
47
|
+
status: number;
|
|
48
|
+
url: string;
|
|
49
|
+
});
|
|
50
|
+
}
|
|
51
|
+
/** 通信そのものの失敗(DNS・接続断・リダイレクトの拒否など) */
|
|
52
|
+
declare class NoteNetworkError extends NoteError {
|
|
53
|
+
name: string;
|
|
54
|
+
readonly code: "NOTE_NETWORK_ERROR";
|
|
55
|
+
constructor(message: string, options?: NoteErrorOptions);
|
|
56
|
+
}
|
|
57
|
+
/** 応答がタイムアウトまでに返らなかった */
|
|
58
|
+
declare class NoteTimeoutError extends NoteError {
|
|
59
|
+
name: string;
|
|
60
|
+
readonly code: "NOTE_TIMEOUT";
|
|
61
|
+
constructor(message: string, options?: NoteErrorOptions);
|
|
62
|
+
}
|
|
63
|
+
/** レスポンスのどこが想定と違ったか(デバッグ用。文言は互換性の対象外) */
|
|
64
|
+
interface NoteSchemaIssue {
|
|
65
|
+
/** `data.contents.0.key` のようなドット区切りのパス */
|
|
66
|
+
readonly path: string;
|
|
67
|
+
readonly message: string;
|
|
68
|
+
}
|
|
69
|
+
/** note のレスポンスの形が想定と違う(API の仕様変更など) */
|
|
70
|
+
declare class NoteSchemaError extends NoteError {
|
|
71
|
+
name: string;
|
|
72
|
+
readonly code: "NOTE_SCHEMA_ERROR";
|
|
73
|
+
readonly issues: readonly NoteSchemaIssue[];
|
|
74
|
+
constructor(message: string, options: NoteErrorOptions & {
|
|
75
|
+
issues: readonly NoteSchemaIssue[];
|
|
76
|
+
});
|
|
77
|
+
}
|
|
78
|
+
/** note-blog-kit/server が投げるエラーのいずれか。`code` で判別できる */
|
|
79
|
+
type AnyNoteError = NoteNotFoundError | NoteHttpError | NoteNetworkError | NoteTimeoutError | NoteSchemaError;
|
|
80
|
+
/**
|
|
81
|
+
* note-blog-kit のエラーかどうかを `name`・`message`・`code` で判定する。
|
|
82
|
+
* パッケージの重複や別の realm(vm など)由来で `instanceof` が一致しない場合でも判定できる。
|
|
83
|
+
*/
|
|
84
|
+
declare function isNoteError(value: unknown): value is AnyNoteError;
|
|
85
|
+
|
|
86
|
+
/** {@link getArticle} のオプション */
|
|
87
|
+
interface GetArticleOptions extends NoteRequestOptions {
|
|
88
|
+
/** 記事キー(例: n55256baa5425。記事 URL の /n/ の後ろ)。n と英小文字・数字のみ */
|
|
89
|
+
key: string;
|
|
90
|
+
}
|
|
91
|
+
/**
|
|
92
|
+
* 記事1件を取得する(サーバー専用。note は CORS に対応していない)。
|
|
93
|
+
* 本文(`bodyHtml`)はサニタイズ済み。有料記事は無料部分だけで、`isPartial` が true になる。
|
|
94
|
+
* 有料記事の `toc` は有料部分の見出しも含むため、一部の `id` は `bodyHtml` の中にない。
|
|
95
|
+
*
|
|
96
|
+
* note の API は記事キーだけで誰の記事でも返す。ページの URL から受け取ったキーをそのまま渡す場合は、
|
|
97
|
+
* 他人の記事を表示しないよう、`article.author.urlname` が自分のユーザー名か確かめること。
|
|
98
|
+
*
|
|
99
|
+
* @throws {TypeError} key やオプションが不正なとき
|
|
100
|
+
* @throws {NoteNotFoundError} 記事が見つからないとき
|
|
101
|
+
* @throws {NoteHttpError} その他の 2xx でないステータス
|
|
102
|
+
* @throws {NoteNetworkError} 通信に失敗したとき
|
|
103
|
+
* @throws {NoteTimeoutError} タイムアウトしたとき
|
|
104
|
+
* @throws {NoteSchemaError} レスポンスの形が想定と違うとき
|
|
105
|
+
*/
|
|
106
|
+
declare function getArticle(options: GetArticleOptions): Promise<NoteArticle>;
|
|
107
|
+
|
|
108
|
+
export { NoteArticle, NoteError, NoteHttpError, NoteNetworkError, NoteNotFoundError, NoteRequestOptions, NoteSchemaError, NoteTimeoutError, getArticle, isNoteError };
|
|
109
|
+
export type { AnyNoteError, GetArticleOptions, NoteErrorCode, NoteErrorOptions, NoteSchemaIssue };
|
|
@@ -0,0 +1,109 @@
|
|
|
1
|
+
import { NoteArticle } from '../index.js';
|
|
2
|
+
export { NoteArticlePage, NoteArticleSummary, NoteAuthor, NoteEmbed, NoteEyecatch, NoteSource, NoteTocItem } from '../index.js';
|
|
3
|
+
import { N as NoteRequestOptions } from '../iterate-articles-9dzDflSn.js';
|
|
4
|
+
export { I as IterateArticlesOptions, a as IterateArticlesResult, b as ListAllArticlesResult, L as ListArticlesOptions, i as iterateArticles, l as listAllArticles, c as listArticles } from '../iterate-articles-9dzDflSn.js';
|
|
5
|
+
|
|
6
|
+
/** エラーの種類を表す安定した識別子 */
|
|
7
|
+
type NoteErrorCode = 'NOTE_NOT_FOUND' | 'NOTE_HTTP_ERROR' | 'NOTE_NETWORK_ERROR' | 'NOTE_TIMEOUT' | 'NOTE_SCHEMA_ERROR';
|
|
8
|
+
/** エラーのコンストラクタに渡す共通のオプション(ライブラリ内部用) */
|
|
9
|
+
interface NoteErrorOptions {
|
|
10
|
+
/** 元になったエラー */
|
|
11
|
+
cause?: unknown;
|
|
12
|
+
}
|
|
13
|
+
/**
|
|
14
|
+
* note-blog-kit/server が投げるエラーの基底クラス。
|
|
15
|
+
*
|
|
16
|
+
* 判定は `instanceof` ではなく {@link isNoteError} と `code` で行うことを推奨する
|
|
17
|
+
* (ESM と CJS が混在したり、パッケージが重複して読み込まれたりすると `instanceof` は一致しないことがある)。
|
|
18
|
+
* `isNoteError(error) && error.code === 'NOTE_HTTP_ERROR'` のように書くと `error.status` まで型が絞られる。
|
|
19
|
+
*
|
|
20
|
+
* コンストラクタはライブラリ内部で使うもので、利用者が作ることは想定していない。
|
|
21
|
+
*/
|
|
22
|
+
declare class NoteError extends Error {
|
|
23
|
+
name: string;
|
|
24
|
+
readonly code: NoteErrorCode;
|
|
25
|
+
constructor(message: string, options: NoteErrorOptions & {
|
|
26
|
+
code: NoteErrorCode;
|
|
27
|
+
});
|
|
28
|
+
}
|
|
29
|
+
/** ユーザーや記事が見つからない(HTTP 404) */
|
|
30
|
+
declare class NoteNotFoundError extends NoteError {
|
|
31
|
+
name: string;
|
|
32
|
+
readonly code: "NOTE_NOT_FOUND";
|
|
33
|
+
/** リクエストした URL */
|
|
34
|
+
readonly url: string;
|
|
35
|
+
constructor(message: string, options: NoteErrorOptions & {
|
|
36
|
+
url: string;
|
|
37
|
+
});
|
|
38
|
+
}
|
|
39
|
+
/** 404 以外の 2xx でない HTTP ステータス */
|
|
40
|
+
declare class NoteHttpError extends NoteError {
|
|
41
|
+
name: string;
|
|
42
|
+
readonly code: "NOTE_HTTP_ERROR";
|
|
43
|
+
readonly status: number;
|
|
44
|
+
/** リクエストした URL */
|
|
45
|
+
readonly url: string;
|
|
46
|
+
constructor(message: string, options: NoteErrorOptions & {
|
|
47
|
+
status: number;
|
|
48
|
+
url: string;
|
|
49
|
+
});
|
|
50
|
+
}
|
|
51
|
+
/** 通信そのものの失敗(DNS・接続断・リダイレクトの拒否など) */
|
|
52
|
+
declare class NoteNetworkError extends NoteError {
|
|
53
|
+
name: string;
|
|
54
|
+
readonly code: "NOTE_NETWORK_ERROR";
|
|
55
|
+
constructor(message: string, options?: NoteErrorOptions);
|
|
56
|
+
}
|
|
57
|
+
/** 応答がタイムアウトまでに返らなかった */
|
|
58
|
+
declare class NoteTimeoutError extends NoteError {
|
|
59
|
+
name: string;
|
|
60
|
+
readonly code: "NOTE_TIMEOUT";
|
|
61
|
+
constructor(message: string, options?: NoteErrorOptions);
|
|
62
|
+
}
|
|
63
|
+
/** レスポンスのどこが想定と違ったか(デバッグ用。文言は互換性の対象外) */
|
|
64
|
+
interface NoteSchemaIssue {
|
|
65
|
+
/** `data.contents.0.key` のようなドット区切りのパス */
|
|
66
|
+
readonly path: string;
|
|
67
|
+
readonly message: string;
|
|
68
|
+
}
|
|
69
|
+
/** note のレスポンスの形が想定と違う(API の仕様変更など) */
|
|
70
|
+
declare class NoteSchemaError extends NoteError {
|
|
71
|
+
name: string;
|
|
72
|
+
readonly code: "NOTE_SCHEMA_ERROR";
|
|
73
|
+
readonly issues: readonly NoteSchemaIssue[];
|
|
74
|
+
constructor(message: string, options: NoteErrorOptions & {
|
|
75
|
+
issues: readonly NoteSchemaIssue[];
|
|
76
|
+
});
|
|
77
|
+
}
|
|
78
|
+
/** note-blog-kit/server が投げるエラーのいずれか。`code` で判別できる */
|
|
79
|
+
type AnyNoteError = NoteNotFoundError | NoteHttpError | NoteNetworkError | NoteTimeoutError | NoteSchemaError;
|
|
80
|
+
/**
|
|
81
|
+
* note-blog-kit のエラーかどうかを `name`・`message`・`code` で判定する。
|
|
82
|
+
* パッケージの重複や別の realm(vm など)由来で `instanceof` が一致しない場合でも判定できる。
|
|
83
|
+
*/
|
|
84
|
+
declare function isNoteError(value: unknown): value is AnyNoteError;
|
|
85
|
+
|
|
86
|
+
/** {@link getArticle} のオプション */
|
|
87
|
+
interface GetArticleOptions extends NoteRequestOptions {
|
|
88
|
+
/** 記事キー(例: n55256baa5425。記事 URL の /n/ の後ろ)。n と英小文字・数字のみ */
|
|
89
|
+
key: string;
|
|
90
|
+
}
|
|
91
|
+
/**
|
|
92
|
+
* 記事1件を取得する(サーバー専用。note は CORS に対応していない)。
|
|
93
|
+
* 本文(`bodyHtml`)はサニタイズ済み。有料記事は無料部分だけで、`isPartial` が true になる。
|
|
94
|
+
* 有料記事の `toc` は有料部分の見出しも含むため、一部の `id` は `bodyHtml` の中にない。
|
|
95
|
+
*
|
|
96
|
+
* note の API は記事キーだけで誰の記事でも返す。ページの URL から受け取ったキーをそのまま渡す場合は、
|
|
97
|
+
* 他人の記事を表示しないよう、`article.author.urlname` が自分のユーザー名か確かめること。
|
|
98
|
+
*
|
|
99
|
+
* @throws {TypeError} key やオプションが不正なとき
|
|
100
|
+
* @throws {NoteNotFoundError} 記事が見つからないとき
|
|
101
|
+
* @throws {NoteHttpError} その他の 2xx でないステータス
|
|
102
|
+
* @throws {NoteNetworkError} 通信に失敗したとき
|
|
103
|
+
* @throws {NoteTimeoutError} タイムアウトしたとき
|
|
104
|
+
* @throws {NoteSchemaError} レスポンスの形が想定と違うとき
|
|
105
|
+
*/
|
|
106
|
+
declare function getArticle(options: GetArticleOptions): Promise<NoteArticle>;
|
|
107
|
+
|
|
108
|
+
export { NoteArticle, NoteError, NoteHttpError, NoteNetworkError, NoteNotFoundError, NoteRequestOptions, NoteSchemaError, NoteTimeoutError, getArticle, isNoteError };
|
|
109
|
+
export type { AnyNoteError, GetArticleOptions, NoteErrorCode, NoteErrorOptions, NoteSchemaIssue };
|