@zonuexe/techbook-mcp 0.1.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.
Files changed (174) hide show
  1. package/.claude/settings.local.json +23 -0
  2. package/.github/workflows/test.yml +36 -0
  3. package/AGENTS.md +72 -0
  4. package/CLAUDE.md +2 -0
  5. package/LICENSE +661 -0
  6. package/README.md +154 -0
  7. package/dist/adapters/cache/memory-cache.d.ts +8 -0
  8. package/dist/adapters/cache/memory-cache.d.ts.map +1 -0
  9. package/dist/adapters/cache/memory-cache.js +23 -0
  10. package/dist/adapters/cache/memory-cache.js.map +1 -0
  11. package/dist/adapters/cache/null-cache.d.ts +8 -0
  12. package/dist/adapters/cache/null-cache.d.ts.map +1 -0
  13. package/dist/adapters/cache/null-cache.js +7 -0
  14. package/dist/adapters/cache/null-cache.js.map +1 -0
  15. package/dist/adapters/html/cheerio-parser.d.ts +5 -0
  16. package/dist/adapters/html/cheerio-parser.d.ts.map +1 -0
  17. package/dist/adapters/html/cheerio-parser.js +45 -0
  18. package/dist/adapters/html/cheerio-parser.js.map +1 -0
  19. package/dist/adapters/http/fetch-client.d.ts +6 -0
  20. package/dist/adapters/http/fetch-client.d.ts.map +1 -0
  21. package/dist/adapters/http/fetch-client.js +43 -0
  22. package/dist/adapters/http/fetch-client.js.map +1 -0
  23. package/dist/adapters/http/mock-client.d.ts +19 -0
  24. package/dist/adapters/http/mock-client.d.ts.map +1 -0
  25. package/dist/adapters/http/mock-client.js +59 -0
  26. package/dist/adapters/http/mock-client.js.map +1 -0
  27. package/dist/adapters/publishers/base.d.ts +24 -0
  28. package/dist/adapters/publishers/base.d.ts.map +1 -0
  29. package/dist/adapters/publishers/base.js +88 -0
  30. package/dist/adapters/publishers/base.js.map +1 -0
  31. package/dist/adapters/publishers/gihyo.d.ts +3 -0
  32. package/dist/adapters/publishers/gihyo.d.ts.map +1 -0
  33. package/dist/adapters/publishers/gihyo.js +75 -0
  34. package/dist/adapters/publishers/gihyo.js.map +1 -0
  35. package/dist/adapters/publishers/lambdanote.d.ts +3 -0
  36. package/dist/adapters/publishers/lambdanote.d.ts.map +1 -0
  37. package/dist/adapters/publishers/lambdanote.js +113 -0
  38. package/dist/adapters/publishers/lambdanote.js.map +1 -0
  39. package/dist/adapters/publishers/registry.d.ts +3 -0
  40. package/dist/adapters/publishers/registry.d.ts.map +1 -0
  41. package/dist/adapters/publishers/registry.js +11 -0
  42. package/dist/adapters/publishers/registry.js.map +1 -0
  43. package/dist/adapters/publishers/tatsu-zine.d.ts +3 -0
  44. package/dist/adapters/publishers/tatsu-zine.d.ts.map +1 -0
  45. package/dist/adapters/publishers/tatsu-zine.js +110 -0
  46. package/dist/adapters/publishers/tatsu-zine.js.map +1 -0
  47. package/dist/adapters/publishers/techbookfest.d.ts +3 -0
  48. package/dist/adapters/publishers/techbookfest.d.ts.map +1 -0
  49. package/dist/adapters/publishers/techbookfest.js +134 -0
  50. package/dist/adapters/publishers/techbookfest.js.map +1 -0
  51. package/dist/application/get-book-detail.d.ts +4 -0
  52. package/dist/application/get-book-detail.d.ts.map +1 -0
  53. package/dist/application/get-book-detail.js +9 -0
  54. package/dist/application/get-book-detail.js.map +1 -0
  55. package/dist/application/search-books.d.ts +11 -0
  56. package/dist/application/search-books.d.ts.map +1 -0
  57. package/dist/application/search-books.js +23 -0
  58. package/dist/application/search-books.js.map +1 -0
  59. package/dist/domain/book.d.ts +32 -0
  60. package/dist/domain/book.d.ts.map +1 -0
  61. package/dist/domain/book.js +2 -0
  62. package/dist/domain/book.js.map +1 -0
  63. package/dist/domain/publisher.d.ts +17 -0
  64. package/dist/domain/publisher.d.ts.map +1 -0
  65. package/dist/domain/publisher.js +2 -0
  66. package/dist/domain/publisher.js.map +1 -0
  67. package/dist/main.d.ts +2 -0
  68. package/dist/main.d.ts.map +1 -0
  69. package/dist/main.js +12 -0
  70. package/dist/main.js.map +1 -0
  71. package/dist/mcp/server.d.ts +5 -0
  72. package/dist/mcp/server.d.ts.map +1 -0
  73. package/dist/mcp/server.js +79 -0
  74. package/dist/mcp/server.js.map +1 -0
  75. package/dist/mcp/tools.d.ts +47 -0
  76. package/dist/mcp/tools.d.ts.map +1 -0
  77. package/dist/mcp/tools.js +53 -0
  78. package/dist/mcp/tools.js.map +1 -0
  79. package/dist/ports/cache.d.ts +6 -0
  80. package/dist/ports/cache.d.ts.map +1 -0
  81. package/dist/ports/cache.js +2 -0
  82. package/dist/ports/cache.js.map +1 -0
  83. package/dist/ports/html-parser.d.ts +14 -0
  84. package/dist/ports/html-parser.d.ts.map +1 -0
  85. package/dist/ports/html-parser.js +2 -0
  86. package/dist/ports/html-parser.js.map +1 -0
  87. package/dist/ports/http.d.ts +16 -0
  88. package/dist/ports/http.d.ts.map +1 -0
  89. package/dist/ports/http.js +2 -0
  90. package/dist/ports/http.js.map +1 -0
  91. package/docs/design-doc.md +365 -0
  92. package/flake.nix +50 -0
  93. package/package.json +29 -0
  94. package/src/adapters/cache/memory-cache.ts +31 -0
  95. package/src/adapters/cache/null-cache.ts +8 -0
  96. package/src/adapters/html/cheerio-parser.ts +49 -0
  97. package/src/adapters/http/fetch-client.ts +47 -0
  98. package/src/adapters/http/mock-client.ts +77 -0
  99. package/src/adapters/publishers/base.ts +129 -0
  100. package/src/adapters/publishers/book-tech.ts +117 -0
  101. package/src/adapters/publishers/born-digital.ts +158 -0
  102. package/src/adapters/publishers/coronasha.ts +139 -0
  103. package/src/adapters/publishers/gihyo.ts +120 -0
  104. package/src/adapters/publishers/lambdanote.ts +146 -0
  105. package/src/adapters/publishers/manatee.ts +112 -0
  106. package/src/adapters/publishers/maruzen-publishing.ts +141 -0
  107. package/src/adapters/publishers/optronics.ts +113 -0
  108. package/src/adapters/publishers/oreilly-japan.ts +138 -0
  109. package/src/adapters/publishers/peaks.ts +98 -0
  110. package/src/adapters/publishers/personal-media.ts +168 -0
  111. package/src/adapters/publishers/registry.ts +36 -0
  112. package/src/adapters/publishers/rutles.ts +161 -0
  113. package/src/adapters/publishers/saiensu.ts +149 -0
  114. package/src/adapters/publishers/seshop.ts +121 -0
  115. package/src/adapters/publishers/tatsu-zine.ts +129 -0
  116. package/src/adapters/publishers/techbookfest.ts +179 -0
  117. package/src/application/get-book-detail.ts +17 -0
  118. package/src/application/search-books.ts +39 -0
  119. package/src/domain/book.ts +35 -0
  120. package/src/domain/publisher.ts +18 -0
  121. package/src/main.ts +13 -0
  122. package/src/mcp/server.ts +103 -0
  123. package/src/mcp/tools.ts +54 -0
  124. package/src/ports/cache.ts +5 -0
  125. package/src/ports/html-parser.ts +15 -0
  126. package/src/ports/http.ts +17 -0
  127. package/tests/fixtures/book-tech-detail.html +51 -0
  128. package/tests/fixtures/book-tech-search.html +91 -0
  129. package/tests/fixtures/born-digital-detail.html +62 -0
  130. package/tests/fixtures/born-digital-search.html +51 -0
  131. package/tests/fixtures/coronasha-detail.html +41 -0
  132. package/tests/fixtures/coronasha-search.html +61 -0
  133. package/tests/fixtures/gihyo-detail.html +42 -0
  134. package/tests/fixtures/gihyo-search.json +54 -0
  135. package/tests/fixtures/lambdanote-search.html +66 -0
  136. package/tests/fixtures/manatee-detail.html +53 -0
  137. package/tests/fixtures/manatee-search.html +59 -0
  138. package/tests/fixtures/maruzen-detail.html +51 -0
  139. package/tests/fixtures/maruzen-search.html +60 -0
  140. package/tests/fixtures/optronics-detail.html +30 -0
  141. package/tests/fixtures/optronics-search.html +75 -0
  142. package/tests/fixtures/oreilly-detail.html +52 -0
  143. package/tests/fixtures/oreilly-ebook-list.html +53 -0
  144. package/tests/fixtures/peaks-detail.html +39 -0
  145. package/tests/fixtures/peaks-top.html +50 -0
  146. package/tests/fixtures/personal-media-detail.html +32 -0
  147. package/tests/fixtures/personal-media-search.html +39 -0
  148. package/tests/fixtures/rutles-detail.html +32 -0
  149. package/tests/fixtures/rutles-search.html +62 -0
  150. package/tests/fixtures/saiensu-detail.html +41 -0
  151. package/tests/fixtures/saiensu-search.html +65 -0
  152. package/tests/fixtures/seshop-detail.html +45 -0
  153. package/tests/fixtures/seshop-search.html +58 -0
  154. package/tests/fixtures/tatsu-zine-detail-free.html +22 -0
  155. package/tests/fixtures/tatsu-zine-search.html +24 -0
  156. package/tests/fixtures/techbookfest-search.json +73 -0
  157. package/tests/unit/adapters/publishers/book-tech.test.ts +183 -0
  158. package/tests/unit/adapters/publishers/born-digital.test.ts +191 -0
  159. package/tests/unit/adapters/publishers/coronasha.test.ts +201 -0
  160. package/tests/unit/adapters/publishers/gihyo.test.ts +135 -0
  161. package/tests/unit/adapters/publishers/lambdanote.test.ts +84 -0
  162. package/tests/unit/adapters/publishers/manatee.test.ts +163 -0
  163. package/tests/unit/adapters/publishers/maruzen-publishing.test.ts +177 -0
  164. package/tests/unit/adapters/publishers/optronics.test.ts +205 -0
  165. package/tests/unit/adapters/publishers/oreilly-japan.test.ts +191 -0
  166. package/tests/unit/adapters/publishers/peaks.test.ts +174 -0
  167. package/tests/unit/adapters/publishers/personal-media.test.ts +196 -0
  168. package/tests/unit/adapters/publishers/rutles.test.ts +170 -0
  169. package/tests/unit/adapters/publishers/saiensu.test.ts +167 -0
  170. package/tests/unit/adapters/publishers/seshop.test.ts +171 -0
  171. package/tests/unit/adapters/publishers/tatsu-zine.test.ts +130 -0
  172. package/tests/unit/adapters/publishers/techbookfest.test.ts +93 -0
  173. package/tsconfig.json +17 -0
  174. package/vitest.config.ts +8 -0
@@ -0,0 +1,167 @@
1
+ import { describe, it, expect } from "vitest";
2
+ import { readFile } from "node:fs/promises";
3
+ import { join } from "node:path";
4
+ import { saiensuAdapter } from "../../../../src/adapters/publishers/saiensu.js";
5
+ import { MockHttpClient } from "../../../../src/adapters/http/mock-client.js";
6
+ import { CheerioHtmlParser } from "../../../../src/adapters/html/cheerio-parser.js";
7
+ import { NullCacheStore } from "../../../../src/adapters/cache/null-cache.js";
8
+
9
+ const FIXTURES_DIR = join(import.meta.dirname, "../../../fixtures");
10
+
11
+ function makeDeps(http: MockHttpClient) {
12
+ return { http, parser: new CheerioHtmlParser(), cache: new NullCacheStore() };
13
+ }
14
+
15
+ async function loadFixture(name: string): Promise<string> {
16
+ return readFile(join(FIXTURES_DIR, name), "utf-8");
17
+ }
18
+
19
+ describe("saiensuAdapter", () => {
20
+ describe("search()", () => {
21
+ it("電子書籍のみ BookRecord[] を返す(紙は除外)", async () => {
22
+ const body = await loadFixture("saiensu-search.html");
23
+ const http = new MockHttpClient().addResponse(
24
+ "https://www.saiensu.co.jp/search/",
25
+ { status: 200, body },
26
+ );
27
+
28
+ const results = await saiensuAdapter.search({ title: "統計" }, makeDeps(http));
29
+
30
+ // フィクスチャには電子1件・紙1件あり、電子のみ返す
31
+ expect(results).toHaveLength(1);
32
+ expect(results[0]).toMatchObject({
33
+ title: "統計リテラシーI【電子版】 ―記述統計から推測統計へ",
34
+ authors: ["堀井俊佑"],
35
+ publisher: "サイエンス社",
36
+ url: "https://www.saiensu.co.jp/search/?isbn=978-4-7819-9049-1&y=2026",
37
+ isbn: "9784781990491",
38
+ price: 2695,
39
+ publishedAt: "2026-03-25",
40
+ });
41
+ });
42
+
43
+ it("coverImageUrl が設定される", async () => {
44
+ const body = await loadFixture("saiensu-search.html");
45
+ const http = new MockHttpClient().addResponse(
46
+ "https://www.saiensu.co.jp/search/",
47
+ { status: 200, body },
48
+ );
49
+
50
+ const results = await saiensuAdapter.search({ title: "統計" }, makeDeps(http));
51
+
52
+ expect(results[0].coverImageUrl).toBe(
53
+ "https://www.saiensu.co.jp/bookThumbs/2026-978-4-7819-9049-1.jpg",
54
+ );
55
+ });
56
+
57
+ it("ebookStores にサイエンス社(DRM付き)が含まれる", async () => {
58
+ const body = await loadFixture("saiensu-search.html");
59
+ const http = new MockHttpClient().addResponse(
60
+ "https://www.saiensu.co.jp/search/",
61
+ { status: 200, body },
62
+ );
63
+
64
+ const results = await saiensuAdapter.search({ title: "統計" }, makeDeps(http));
65
+
66
+ expect(results[0].ebookStores).toEqual([
67
+ {
68
+ name: "サイエンス社",
69
+ url: "https://www.saiensu.co.jp/search/?isbn=978-4-7819-9049-1&y=2026",
70
+ drm: "password_pdf",
71
+ },
72
+ ]);
73
+ });
74
+
75
+ it("著者の所属・役割語を除去する", async () => {
76
+ const body = await loadFixture("saiensu-search.html");
77
+ const http = new MockHttpClient().addResponse(
78
+ "https://www.saiensu.co.jp/search/",
79
+ { status: 200, body },
80
+ );
81
+
82
+ const results = await saiensuAdapter.search({ title: "統計" }, makeDeps(http));
83
+
84
+ expect(results[0].authors).toEqual(["堀井俊佑"]);
85
+ });
86
+
87
+ it("title も author も空の場合は [] を返しHTTPを呼ばない", async () => {
88
+ const http = new MockHttpClient();
89
+
90
+ const results = await saiensuAdapter.search({}, makeDeps(http));
91
+
92
+ expect(results).toEqual([]);
93
+ expect(http.calls).toHaveLength(0);
94
+ });
95
+
96
+ it("検索リクエストに keyword が含まれる", async () => {
97
+ const body = await loadFixture("saiensu-search.html");
98
+ const http = new MockHttpClient().addResponse(
99
+ "https://www.saiensu.co.jp/search/",
100
+ { status: 200, body },
101
+ );
102
+
103
+ await saiensuAdapter.search({ title: "意味論" }, makeDeps(http));
104
+
105
+ expect(http.calls[0]).toContain("keyword=%E6%84%8F%E5%91%B3%E8%AB%96");
106
+ });
107
+ });
108
+
109
+ describe("getDetail()", () => {
110
+ it("詳細情報を返す", async () => {
111
+ const body = await loadFixture("saiensu-detail.html");
112
+ const http = new MockHttpClient().addResponse(
113
+ "https://www.saiensu.co.jp/search/?isbn=978-4-7819-9049-1&y=2026",
114
+ { status: 200, body },
115
+ );
116
+
117
+ const book = await saiensuAdapter.getDetail(
118
+ "https://www.saiensu.co.jp/search/?isbn=978-4-7819-9049-1&y=2026",
119
+ makeDeps(http),
120
+ );
121
+
122
+ expect(book).toMatchObject({
123
+ title: "統計リテラシーI【電子版】 ―記述統計から推測統計へ",
124
+ publisher: "サイエンス社",
125
+ isbn: "9784781990491",
126
+ price: 2695,
127
+ publishedAt: "2026-03-25",
128
+ });
129
+ });
130
+
131
+ it("著者の所属・役割語を除去する", async () => {
132
+ const body = await loadFixture("saiensu-detail.html");
133
+ const http = new MockHttpClient().addResponse(
134
+ "https://www.saiensu.co.jp/search/?isbn=978-4-7819-9049-1&y=2026",
135
+ { status: 200, body },
136
+ );
137
+
138
+ const book = await saiensuAdapter.getDetail(
139
+ "https://www.saiensu.co.jp/search/?isbn=978-4-7819-9049-1&y=2026",
140
+ makeDeps(http),
141
+ );
142
+
143
+ expect(book.authors).toEqual(["堀井俊佑"]);
144
+ });
145
+
146
+ it("ebookStores にサイエンス社(DRM付き)が含まれる", async () => {
147
+ const body = await loadFixture("saiensu-detail.html");
148
+ const http = new MockHttpClient().addResponse(
149
+ "https://www.saiensu.co.jp/search/?isbn=978-4-7819-9049-1&y=2026",
150
+ { status: 200, body },
151
+ );
152
+
153
+ const book = await saiensuAdapter.getDetail(
154
+ "https://www.saiensu.co.jp/search/?isbn=978-4-7819-9049-1&y=2026",
155
+ makeDeps(http),
156
+ );
157
+
158
+ expect(book.ebookStores).toEqual([
159
+ {
160
+ name: "サイエンス社",
161
+ url: "https://www.saiensu.co.jp/search/?isbn=978-4-7819-9049-1&y=2026",
162
+ drm: "password_pdf",
163
+ },
164
+ ]);
165
+ });
166
+ });
167
+ });
@@ -0,0 +1,171 @@
1
+ import { describe, it, expect } from "vitest";
2
+ import { readFile } from "node:fs/promises";
3
+ import { join } from "node:path";
4
+ import { seshopAdapter } from "../../../../src/adapters/publishers/seshop.js";
5
+ import { MockHttpClient } from "../../../../src/adapters/http/mock-client.js";
6
+ import { CheerioHtmlParser } from "../../../../src/adapters/html/cheerio-parser.js";
7
+ import { NullCacheStore } from "../../../../src/adapters/cache/null-cache.js";
8
+
9
+ const FIXTURES_DIR = join(import.meta.dirname, "../../../fixtures");
10
+
11
+ function makeDeps(http: MockHttpClient) {
12
+ return { http, parser: new CheerioHtmlParser(), cache: new NullCacheStore() };
13
+ }
14
+
15
+ async function loadFixture(name: string): Promise<string> {
16
+ return readFile(join(FIXTURES_DIR, name), "utf-8");
17
+ }
18
+
19
+ describe("seshopAdapter", () => {
20
+ describe("search()", () => {
21
+ it("電子書籍のみ BookRecord[] を返す(紙書籍は除外)", async () => {
22
+ const body = await loadFixture("seshop-search.html");
23
+ const http = new MockHttpClient().addResponse(
24
+ "https://www.seshop.com/search",
25
+ { status: 200, body },
26
+ );
27
+
28
+ const results = await seshopAdapter.search({ title: "TypeScript" }, makeDeps(http));
29
+
30
+ // フィクスチャには電子2件・紙1件あり、電子のみ返す
31
+ expect(results).toHaveLength(2);
32
+ expect(results[0]).toMatchObject({
33
+ title: "TypeScript入門【PDF版】",
34
+ publisher: "翔泳社",
35
+ url: "https://www.seshop.com/product/detail/26500",
36
+ price: 3520,
37
+ publishedAt: "2024-06-10",
38
+ });
39
+ });
40
+
41
+ it("coverImageUrl が設定される", async () => {
42
+ const body = await loadFixture("seshop-search.html");
43
+ const http = new MockHttpClient().addResponse(
44
+ "https://www.seshop.com/search",
45
+ { status: 200, body },
46
+ );
47
+
48
+ const results = await seshopAdapter.search({ title: "TypeScript" }, makeDeps(http));
49
+
50
+ expect(results[0].coverImageUrl).toBe(
51
+ "https://www.seshop.com/static/images/product/26500/L.png",
52
+ );
53
+ });
54
+
55
+ it("ebookStores に SEshop (social DRM) が含まれる", async () => {
56
+ const body = await loadFixture("seshop-search.html");
57
+ const http = new MockHttpClient().addResponse(
58
+ "https://www.seshop.com/search",
59
+ { status: 200, body },
60
+ );
61
+
62
+ const results = await seshopAdapter.search({ title: "TypeScript" }, makeDeps(http));
63
+
64
+ expect(results[0].ebookStores).toEqual([
65
+ {
66
+ name: "SEshop",
67
+ url: "https://www.seshop.com/product/detail/26500",
68
+ drm: "social",
69
+ },
70
+ ]);
71
+ });
72
+
73
+ it("title も author も空の場合は [] を返しHTTPを呼ばない", async () => {
74
+ const http = new MockHttpClient();
75
+
76
+ const results = await seshopAdapter.search({}, makeDeps(http));
77
+
78
+ expect(results).toEqual([]);
79
+ expect(http.calls).toHaveLength(0);
80
+ });
81
+
82
+ it("検索リクエストに keyword と category_id=327 が含まれる", async () => {
83
+ const body = await loadFixture("seshop-search.html");
84
+ const http = new MockHttpClient().addResponse(
85
+ "https://www.seshop.com/search",
86
+ { status: 200, body },
87
+ );
88
+
89
+ await seshopAdapter.search({ title: "TypeScript" }, makeDeps(http));
90
+
91
+ expect(http.calls[0]).toContain("keyword=TypeScript");
92
+ expect(http.calls[0]).toContain("category_id=327");
93
+ });
94
+ });
95
+
96
+ describe("getDetail()", () => {
97
+ it("詳細情報を返す", async () => {
98
+ const body = await loadFixture("seshop-detail.html");
99
+ const http = new MockHttpClient().addResponse(
100
+ "https://www.seshop.com/product/detail/26500",
101
+ { status: 200, body },
102
+ );
103
+
104
+ const book = await seshopAdapter.getDetail(
105
+ "https://www.seshop.com/product/detail/26500",
106
+ makeDeps(http),
107
+ );
108
+
109
+ expect(book).toMatchObject({
110
+ title: "TypeScript入門【PDF版】",
111
+ publisher: "翔泳社",
112
+ isbn: "9784798190014",
113
+ price: 3520,
114
+ publishedAt: "2024-06-10",
115
+ });
116
+ });
117
+
118
+ it("複数著者を取得する", async () => {
119
+ const body = await loadFixture("seshop-detail.html");
120
+ const http = new MockHttpClient().addResponse(
121
+ "https://www.seshop.com/product/detail/26500",
122
+ { status: 200, body },
123
+ );
124
+
125
+ const book = await seshopAdapter.getDetail(
126
+ "https://www.seshop.com/product/detail/26500",
127
+ makeDeps(http),
128
+ );
129
+
130
+ expect(book.authors).toEqual(["山田 太郎", "鈴木 花子"]);
131
+ });
132
+
133
+ it("coverImageUrl が設定される", async () => {
134
+ const body = await loadFixture("seshop-detail.html");
135
+ const http = new MockHttpClient().addResponse(
136
+ "https://www.seshop.com/product/detail/26500",
137
+ { status: 200, body },
138
+ );
139
+
140
+ const book = await seshopAdapter.getDetail(
141
+ "https://www.seshop.com/product/detail/26500",
142
+ makeDeps(http),
143
+ );
144
+
145
+ expect(book.coverImageUrl).toBe(
146
+ "https://www.seshop.com/static/images/product/26500/L.png",
147
+ );
148
+ });
149
+
150
+ it("ebookStores に SEshop (social DRM) が含まれる", async () => {
151
+ const body = await loadFixture("seshop-detail.html");
152
+ const http = new MockHttpClient().addResponse(
153
+ "https://www.seshop.com/product/detail/26500",
154
+ { status: 200, body },
155
+ );
156
+
157
+ const book = await seshopAdapter.getDetail(
158
+ "https://www.seshop.com/product/detail/26500",
159
+ makeDeps(http),
160
+ );
161
+
162
+ expect(book.ebookStores).toEqual([
163
+ {
164
+ name: "SEshop",
165
+ url: "https://www.seshop.com/product/detail/26500",
166
+ drm: "social",
167
+ },
168
+ ]);
169
+ });
170
+ });
171
+ });
@@ -0,0 +1,130 @@
1
+ import { describe, it, expect } from "vitest";
2
+ import { readFile } from "node:fs/promises";
3
+ import { join } from "node:path";
4
+ import { tatsuZineAdapter } from "../../../../src/adapters/publishers/tatsu-zine.js";
5
+ import { MockHttpClient } from "../../../../src/adapters/http/mock-client.js";
6
+ import { CheerioHtmlParser } from "../../../../src/adapters/html/cheerio-parser.js";
7
+ import { NullCacheStore } from "../../../../src/adapters/cache/null-cache.js";
8
+
9
+ const FIXTURES_DIR = join(import.meta.dirname, "../../../fixtures");
10
+
11
+ function makeDeps(http: MockHttpClient) {
12
+ return { http, parser: new CheerioHtmlParser(), cache: new NullCacheStore() };
13
+ }
14
+
15
+ async function loadFixture(name: string): Promise<string> {
16
+ return readFile(join(FIXTURES_DIR, name), "utf-8");
17
+ }
18
+
19
+ describe("tatsuZineAdapter", () => {
20
+ describe("search()", () => {
21
+ it("検索結果から BookRecord[] を返す", async () => {
22
+ const body = await loadFixture("tatsu-zine-search.html");
23
+ const http = new MockHttpClient().addResponse(
24
+ "https://tatsu-zine.com/books/",
25
+ { status: 200, body },
26
+ );
27
+
28
+ const results = await tatsuZineAdapter.search({ title: "Go" }, makeDeps(http));
29
+
30
+ expect(results).toHaveLength(2);
31
+ expect(results[0]).toMatchObject({
32
+ title: "Goプログラミング実践入門",
33
+ authors: ["Sau Sheong Chang", "武舎 広幸"],
34
+ publisher: "達人出版会",
35
+ });
36
+ expect(results[0].url).toBe("https://tatsu-zine.com/books/go-programming");
37
+ });
38
+
39
+ it("ebookStores に達人出版会(ソーシャルDRM)が含まれる", async () => {
40
+ const body = await loadFixture("tatsu-zine-search.html");
41
+ const http = new MockHttpClient().addResponse(
42
+ "https://tatsu-zine.com/books/",
43
+ { status: 200, body },
44
+ );
45
+
46
+ const results = await tatsuZineAdapter.search({ title: "Go" }, makeDeps(http));
47
+
48
+ expect(results[0].ebookStores).toEqual([
49
+ { name: "達人出版会", url: "https://tatsu-zine.com/books/go-programming", drm: "social" },
50
+ ]);
51
+ });
52
+
53
+ it("limit を適用する", async () => {
54
+ const body = await loadFixture("tatsu-zine-search.html");
55
+ const http = new MockHttpClient().addResponse(
56
+ "https://tatsu-zine.com/books/",
57
+ { status: 200, body },
58
+ );
59
+
60
+ const results = await tatsuZineAdapter.search({ title: "Go", limit: 1 }, makeDeps(http));
61
+
62
+ expect(results).toHaveLength(1);
63
+ });
64
+
65
+ it("title も author も空の場合は [] を返しHTTPを呼ばない", async () => {
66
+ const http = new MockHttpClient();
67
+ const results = await tatsuZineAdapter.search({}, makeDeps(http));
68
+
69
+ expect(results).toEqual([]);
70
+ expect(http.calls).toHaveLength(0);
71
+ });
72
+
73
+ it("検索リクエストに search パラメータが含まれる", async () => {
74
+ const body = await loadFixture("tatsu-zine-search.html");
75
+ const http = new MockHttpClient().addResponse(
76
+ "https://tatsu-zine.com/books/",
77
+ { status: 200, body },
78
+ );
79
+
80
+ await tatsuZineAdapter.search({ title: "Go言語" }, makeDeps(http));
81
+
82
+ expect(http.calls[0]).toContain("search=Go%E8%A8%80%E8%AA%9E");
83
+ });
84
+ });
85
+
86
+ describe("getDetail()", () => {
87
+ it("詳細情報を返す(達人出版会は常にソーシャルDRM)", async () => {
88
+ const body = await loadFixture("tatsu-zine-detail-free.html");
89
+ const http = new MockHttpClient().addResponse(
90
+ "https://tatsu-zine.com/books/go-programming",
91
+ { status: 200, body },
92
+ );
93
+
94
+ const book = await tatsuZineAdapter.getDetail(
95
+ "https://tatsu-zine.com/books/go-programming",
96
+ makeDeps(http),
97
+ );
98
+
99
+ expect(book).toMatchObject({
100
+ title: "Goプログラミング実践入門",
101
+ authors: ["Sau Sheong Chang", "武舎 広幸"],
102
+ publisher: "インプレス",
103
+ price: 3520,
104
+ });
105
+ // 達人出版会は「ソーシャルDRM」と明記がなくても全書籍で購入者情報を印字
106
+ expect(book.ebookStores).toEqual([
107
+ { name: "達人出版会", url: "https://tatsu-zine.com/books/go-programming", drm: "social" },
108
+ ]);
109
+ });
110
+
111
+ it("出版社が達人出版会自身の場合はフォールバックする", async () => {
112
+ const body = `<!DOCTYPE html><html><body>
113
+ <h1>達人出版会刊行の本</h1>
114
+ <img src="/images/books/999/cover.jpg">
115
+ <dl><dt>著者</dt><dd>著者名(著)</dd><dt>定価</dt><dd>2,200円 (2,000円+税)</dd></dl>
116
+ </body></html>`;
117
+ const http = new MockHttpClient().addResponse(
118
+ "https://tatsu-zine.com/books/some-book",
119
+ { status: 200, body },
120
+ );
121
+
122
+ const book = await tatsuZineAdapter.getDetail(
123
+ "https://tatsu-zine.com/books/some-book",
124
+ makeDeps(http),
125
+ );
126
+
127
+ expect(book.publisher).toBe("達人出版会");
128
+ });
129
+ });
130
+ });
@@ -0,0 +1,93 @@
1
+ import { describe, it, expect } from "vitest";
2
+ import { readFile } from "node:fs/promises";
3
+ import { join } from "node:path";
4
+ import { techbookfestAdapter } from "../../../../src/adapters/publishers/techbookfest.js";
5
+ import { MockHttpClient } from "../../../../src/adapters/http/mock-client.js";
6
+ import { CheerioHtmlParser } from "../../../../src/adapters/html/cheerio-parser.js";
7
+ import { NullCacheStore } from "../../../../src/adapters/cache/null-cache.js";
8
+
9
+ const FIXTURES_DIR = join(import.meta.dirname, "../../../fixtures");
10
+
11
+ const XSRF_TOKEN = "test-xsrf-token-abc123";
12
+
13
+ function makeDeps(http: MockHttpClient) {
14
+ return { http, parser: new CheerioHtmlParser(), cache: new NullCacheStore() };
15
+ }
16
+
17
+ /** トップページ GET → XSRF-TOKEN → GraphQL POST の 2 ステップを登録する */
18
+ async function makeSearchHttp(fixtureName: string): Promise<MockHttpClient> {
19
+ const body = await readFile(join(FIXTURES_DIR, fixtureName), "utf-8");
20
+ return new MockHttpClient()
21
+ .addResponse("https://techbookfest.org", {
22
+ status: 200,
23
+ body: "",
24
+ headers: { "set-cookie": `XSRF-TOKEN=${encodeURIComponent(XSRF_TOKEN)}; Path=/; Secure` },
25
+ })
26
+ .addPostResponse("https://techbookfest.org/api/graphql", { status: 200, body });
27
+ }
28
+
29
+ describe("techbookfestAdapter", () => {
30
+ describe("search()", () => {
31
+ it("GraphQL レスポンスから BookRecord[] を返す", async () => {
32
+ const http = await makeSearchHttp("techbookfest-search.json");
33
+
34
+ const results = await techbookfestAdapter.search({ title: "TypeScript", limit: 10 }, makeDeps(http));
35
+
36
+ expect(results).toHaveLength(3);
37
+ expect(results[0]).toMatchObject({
38
+ title: "TypeScriptで学ぶデザインパターン",
39
+ authors: ["サークル名A"],
40
+ publisher: "技術書典",
41
+ url: "https://techbookfest.org/product/01HXXXX1",
42
+ price: 1000,
43
+ publishedAt: "2024-01-15",
44
+ });
45
+ expect(results[0].coverImageUrl).toBe("https://techbookfest.org/api/image/01HXXXX1.png");
46
+ });
47
+
48
+ it("ebookStores に技術書典(DRMフリー)が含まれる", async () => {
49
+ const http = await makeSearchHttp("techbookfest-search.json");
50
+
51
+ const results = await techbookfestAdapter.search({ title: "TypeScript" }, makeDeps(http));
52
+
53
+ expect(results[0].ebookStores).toEqual([
54
+ { name: "技術書典", url: "https://techbookfest.org/product/01HXXXX1", drm: "free" },
55
+ ]);
56
+ });
57
+
58
+ it("coverImage が null の場合 coverImageUrl は undefined", async () => {
59
+ const http = await makeSearchHttp("techbookfest-search.json");
60
+
61
+ const results = await techbookfestAdapter.search({ title: "TypeScript" }, makeDeps(http));
62
+
63
+ const book = results.find(b => b.url === "https://techbookfest.org/product/01HXXXX2");
64
+ expect(book?.coverImageUrl).toBeUndefined();
65
+ });
66
+
67
+ it("title も author も空の場合は [] を返しHTTPを呼ばない", async () => {
68
+ const http = new MockHttpClient();
69
+ const results = await techbookfestAdapter.search({}, makeDeps(http));
70
+
71
+ expect(results).toEqual([]);
72
+ expect(http.calls).toHaveLength(0);
73
+ });
74
+
75
+ it("トップページ GET で XSRF-TOKEN を取得してから GraphQL に POST する", async () => {
76
+ const http = await makeSearchHttp("techbookfest-search.json");
77
+
78
+ await techbookfestAdapter.search({ title: "TypeScript" }, makeDeps(http));
79
+
80
+ expect(http.calls[0]).toBe("https://techbookfest.org");
81
+ expect(http.calls[1]).toBe("https://techbookfest.org/api/graphql");
82
+ });
83
+
84
+ it("price が 0 の書籍も返す", async () => {
85
+ const http = await makeSearchHttp("techbookfest-search.json");
86
+
87
+ const results = await techbookfestAdapter.search({ title: "TypeScript" }, makeDeps(http));
88
+
89
+ const freeBook = results.find(b => b.url === "https://techbookfest.org/product/01HXXXX3");
90
+ expect(freeBook?.price).toBe(0);
91
+ });
92
+ });
93
+ });
package/tsconfig.json ADDED
@@ -0,0 +1,17 @@
1
+ {
2
+ "compilerOptions": {
3
+ "target": "ES2022",
4
+ "module": "NodeNext",
5
+ "moduleResolution": "NodeNext",
6
+ "outDir": "./dist",
7
+ "rootDir": "./src",
8
+ "strict": true,
9
+ "esModuleInterop": true,
10
+ "skipLibCheck": true,
11
+ "declaration": true,
12
+ "declarationMap": true,
13
+ "sourceMap": true
14
+ },
15
+ "include": ["src/**/*"],
16
+ "exclude": ["node_modules", "dist"]
17
+ }
@@ -0,0 +1,8 @@
1
+ import { defineConfig } from "vitest/config";
2
+
3
+ export default defineConfig({
4
+ test: {
5
+ include: ["tests/**/*.test.ts"],
6
+ environment: "node",
7
+ },
8
+ });