@shisho/plugin-types 0.0.20 → 0.0.21

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
@@ -15,7 +15,7 @@ The types provide autocompletion for:
15
15
  - **`shisho.*`** - Host APIs (log, config, http, fs, archive, xml, ffmpeg)
16
16
  - **`plugin`** - Hook structure (inputConverter, fileParser, metadataEnricher, outputGenerator)
17
17
  - **Hook contexts** - Typed `context` parameters for each hook method
18
- - **Return types** - `ParsedMetadata`, `ConvertResult`, `EnrichmentResult`, etc.
18
+ - **Return types** - `ParsedMetadata`, `ConvertResult`, `SearchResponse`, etc.
19
19
 
20
20
  ### TypeScript
21
21
 
@@ -23,10 +23,10 @@ If you write your plugin in TypeScript (and compile to JavaScript for deployment
23
23
 
24
24
  ```typescript
25
25
  import type {
26
- EnrichmentResult,
27
26
  FileParserContext,
28
- MetadataEnricherContext,
29
27
  ParsedMetadata,
28
+ SearchContext,
29
+ SearchResponse,
30
30
  ShishoPlugin,
31
31
  } from "@shisho/plugin-types";
32
32
 
@@ -43,16 +43,20 @@ const plugin: ShishoPlugin = {
43
43
  },
44
44
 
45
45
  metadataEnricher: {
46
- enrich(context: MetadataEnricherContext): EnrichmentResult {
46
+ search(context: SearchContext): SearchResponse {
47
47
  const apiKey = shisho.config.get("apiKey");
48
48
  const resp = shisho.http.fetch(
49
- `https://api.example.com/lookup?title=${context.book.title}`,
49
+ `https://api.example.com/search?q=${context.query}`,
50
50
  { method: "GET" },
51
51
  );
52
- const data = resp.json() as { description: string };
52
+ const data = resp.json() as {
53
+ results: Array<{ title: string; description: string }>;
54
+ };
53
55
  return {
54
- modified: true,
55
- metadata: { description: data.description },
56
+ results: data.results.map((r) => ({
57
+ title: r.title,
58
+ description: r.description,
59
+ })),
56
60
  };
57
61
  },
58
62
  },
@@ -80,17 +84,18 @@ var plugin = (function () {
80
84
  },
81
85
 
82
86
  metadataEnricher: {
83
- /** @param {MetadataEnricherContext} context @returns {EnrichmentResult} */
84
- enrich: function (context) {
87
+ /** @param {SearchContext} context @returns {SearchResponse} */
88
+ search: function (context) {
85
89
  var apiKey = shisho.config.get("apiKey");
86
90
  var resp = shisho.http.fetch(
87
- "https://api.example.com/lookup?title=" + context.book.title,
91
+ "https://api.example.com/search?q=" + context.query,
88
92
  { method: "GET" },
89
93
  );
90
94
  var data = resp.json();
91
95
  return {
92
- modified: true,
93
- metadata: { description: data.description },
96
+ results: data.results.map(function (r) {
97
+ return { title: r.title, description: r.description };
98
+ }),
94
99
  };
95
100
  },
96
101
  },
package/hooks.d.ts CHANGED
@@ -1,4 +1,4 @@
1
- import { ParsedMetadata } from "./metadata";
1
+ import { ParsedAuthor, ParsedMetadata } from "./metadata";
2
2
 
3
3
  /** Context passed to inputConverter.convert(). */
4
4
  export interface InputConverterContext {
@@ -51,11 +51,14 @@ export interface SearchContext {
51
51
  /** A single search result from metadataEnricher.search(). */
52
52
  export interface SearchResult {
53
53
  title: string;
54
- authors?: string[];
54
+ authors?: ParsedAuthor[];
55
55
  description?: string;
56
56
  imageUrl?: string;
57
57
  releaseDate?: string;
58
58
  publisher?: string;
59
+ imprint?: string;
60
+ url?: string;
61
+ coverUrl?: string;
59
62
  subtitle?: string;
60
63
  series?: string;
61
64
  seriesNumber?: number;
@@ -63,10 +66,6 @@ export interface SearchResult {
63
66
  tags?: string[];
64
67
  narrators?: string[];
65
68
  identifiers?: Array<{ type: string; value: string }>;
66
- /** Opaque data passed back to enrich(). Use this to store internal IDs. */
67
- providerData?: unknown;
68
- /** Full metadata for passthrough pattern. If provided, enrich() can return it as-is. */
69
- metadata?: ParsedMetadata;
70
69
  }
71
70
 
72
71
  /** Result returned from metadataEnricher.search(). */
@@ -74,38 +73,6 @@ export interface SearchResponse {
74
73
  results: SearchResult[];
75
74
  }
76
75
 
77
- /** Context passed to metadataEnricher.enrich(). */
78
- export interface EnrichContext {
79
- /** The selected search result's providerData. */
80
- selectedResult: unknown;
81
- /** Current book state from the database. */
82
- book: {
83
- id?: number;
84
- title?: string;
85
- subtitle?: string;
86
- description?: string;
87
- series?: Array<{ name: string; number?: number }>;
88
- authors?: Array<{ name: string; role?: string }>;
89
- genres?: string[];
90
- tags?: string[];
91
- identifiers?: Array<{ type: string; value: string }>;
92
- publisher?: string;
93
- };
94
- /** File information. */
95
- file: {
96
- fileType?: string;
97
- filePath?: string;
98
- };
99
- }
100
-
101
- /** Result returned from metadataEnricher.enrich(). */
102
- export interface EnrichmentResult {
103
- /** Whether metadata was modified. */
104
- modified: boolean;
105
- /** Updated metadata (only used if modified is true). */
106
- metadata?: ParsedMetadata;
107
- }
108
-
109
76
  /** Context passed to outputGenerator.generate(). */
110
77
  export interface OutputGeneratorContext {
111
78
  /** Path to the source book file. */
@@ -162,8 +129,6 @@ export interface FileParserHook {
162
129
  export interface MetadataEnricherHook {
163
130
  /** Search for candidate results from external sources. */
164
131
  search(context: SearchContext): SearchResponse;
165
- /** Enrich metadata from a selected search result. */
166
- enrich(context: EnrichContext): EnrichmentResult;
167
132
  }
168
133
 
169
134
  /** Output generator hook. */
package/metadata.d.ts CHANGED
@@ -46,7 +46,7 @@ export interface ParsedMetadata {
46
46
  releaseDate?: string;
47
47
  /** MIME type of cover image (e.g., "image/jpeg"). */
48
48
  coverMimeType?: string;
49
- /** Public URL for cover image. Server downloads at apply time. Lower precedence than coverData. */
49
+ /** Public URL for cover image. Server downloads at apply time. Lower precedence than coverData. Domain must be in httpAccess.domains. */
50
50
  coverUrl?: string;
51
51
  /** Cover image data as ArrayBuffer. */
52
52
  coverData?: ArrayBuffer;
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@shisho/plugin-types",
3
- "version": "0.0.20",
3
+ "version": "0.0.21",
4
4
  "description": "TypeScript type definitions for Shisho plugin development",
5
5
  "homepage": "https://github.com/shishobooks/shisho/blob/master/packages/plugin-types/README.md",
6
6
  "types": "index.d.ts",