@markitdownjs/api 0.1.0 → 0.1.2

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 ADDED
@@ -0,0 +1,21 @@
1
+ MIT License
2
+
3
+ Copyright (c) 2024 MarkItDownJS Contributors
4
+
5
+ Permission is hereby granted, free of charge, to any person obtaining a copy
6
+ of this software and associated documentation files (the "Software"), to deal
7
+ in the Software without restriction, including without limitation the rights
8
+ to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
9
+ copies of the Software, and to permit persons to whom the Software is
10
+ furnished to do so, subject to the following conditions:
11
+
12
+ The above copyright notice and this permission notice shall be included in all
13
+ copies or substantial portions of the Software.
14
+
15
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
16
+ IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
17
+ FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
18
+ AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
19
+ LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
20
+ OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
21
+ SOFTWARE.
package/README.md ADDED
@@ -0,0 +1,60 @@
1
+ # @markitdownjs/api
2
+
3
+ [![npm](https://img.shields.io/npm/v/@markitdownjs/api)](https://www.npmjs.com/package/@markitdownjs/api)
4
+ [![License: MIT](https://img.shields.io/badge/License-MIT-yellow.svg)](https://opensource.org/licenses/MIT)
5
+
6
+ Hono-based HTTP API server for document conversion. Part of [MarkItDownJS](https://github.com/markitdownjs/markitdownjs). Deploy as a standalone microservice or embed in any Node.js app.
7
+
8
+ ## Install
9
+
10
+ ```bash
11
+ npm install @markitdownjs/api @markitdownjs/core
12
+ ```
13
+
14
+ ## Usage
15
+
16
+ ```ts
17
+ import { startServer } from "@markitdownjs/api";
18
+
19
+ startServer({ port: 3000 });
20
+ ```
21
+
22
+ ### Embed in an existing Hono or Node app
23
+
24
+ ```ts
25
+ import { createApp } from "@markitdownjs/api";
26
+ import { MarkItDown } from "@markitdownjs/core";
27
+ import { PdfConverter } from "@markitdownjs/pdf";
28
+
29
+ const parser = new MarkItDown();
30
+ parser.registerConverter(new PdfConverter());
31
+
32
+ const app = createApp({ parser });
33
+ // Mount `app` into your existing Hono/Express instance
34
+ ```
35
+
36
+ ## Endpoints
37
+
38
+ | Method | Path | Description |
39
+ |--------|------|-------------|
40
+ | `POST` | `/convert` | Convert a single file (`multipart/form-data`, field: `file`) |
41
+ | `POST` | `/batch` | Convert multiple files in one request |
42
+ | `GET` | `/health` | Health check — returns `{ status: "ok" }` |
43
+ | `GET` | `/formats` | List registered converter MIME types |
44
+
45
+ ## Docker
46
+
47
+ ```bash
48
+ npx @markitdownjs/cli serve --port 3000
49
+ ```
50
+
51
+ ## API
52
+
53
+ | Export | Description |
54
+ |--------|-------------|
55
+ | `createApp(opts)` | Returns a configured Hono app instance |
56
+ | `startServer(opts)` | Creates the app and starts a Node.js HTTP listener |
57
+
58
+ ## Part of the MarkItDownJS Monorepo
59
+
60
+ [https://github.com/markitdownjs/markitdownjs](https://github.com/markitdownjs/markitdownjs)
package/dist/app.d.ts CHANGED
@@ -1,4 +1,4 @@
1
- import { Hono } from 'hono';
1
+ import { Hono } from "hono";
2
2
  declare const app: Hono<import("hono/types").BlankEnv, import("hono/types").BlankSchema, "/">;
3
3
  export default app;
4
4
  //# sourceMappingURL=app.d.ts.map
package/dist/app.d.ts.map CHANGED
@@ -1 +1 @@
1
- {"version":3,"file":"app.d.ts","sourceRoot":"","sources":["../src/app.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,IAAI,EAAE,MAAM,MAAM,CAAC;AAI5B,QAAA,MAAM,GAAG,4EAAa,CAAC;AAyCvB,eAAe,GAAG,CAAC"}
1
+ {"version":3,"file":"app.d.ts","sourceRoot":"","sources":["../src/app.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,IAAI,EAAE,MAAM,MAAM,CAAC;AAI5B,QAAA,MAAM,GAAG,4EAAa,CAAC;AAsCvB,eAAe,GAAG,CAAC"}
package/dist/app.js CHANGED
@@ -1,23 +1,23 @@
1
- import { Hono } from 'hono';
2
- import { cors } from 'hono/cors';
3
- import { getSupportedExtensions, getSupportedMimeTypes } from '@markitdownjs/shared';
1
+ import { Hono } from "hono";
2
+ import { cors } from "hono/cors";
3
+ import { getSupportedExtensions, getSupportedMimeTypes } from "@markitdownjs/shared";
4
4
  const app = new Hono();
5
- app.use('/*', cors());
6
- app.get('/health', (c) => c.json({ status: 'ok', timestamp: new Date().toISOString() }));
7
- app.get('/formats', async (c) => {
5
+ app.use("/*", cors());
6
+ app.get("/health", (c) => c.json({ status: "ok", timestamp: new Date().toISOString() }));
7
+ app.get("/formats", async (c) => {
8
8
  return c.json({
9
9
  extensions: getSupportedExtensions(),
10
10
  mimeTypes: getSupportedMimeTypes(),
11
11
  });
12
12
  });
13
- app.post('/convert', async (c) => {
13
+ app.post("/convert", async (c) => {
14
14
  try {
15
15
  const body = await c.req.parseBody();
16
- const file = body['file'];
16
+ const file = body["file"];
17
17
  if (!file || !(file instanceof File)) {
18
- return c.json({ error: 'No file provided' }, 400);
18
+ return c.json({ error: "No file provided" }, 400);
19
19
  }
20
- const { MarkItDown } = await import('@markitdownjs/core');
20
+ const { MarkItDown } = await import("@markitdownjs/core");
21
21
  const parser = new MarkItDown();
22
22
  const arrayBuffer = await file.arrayBuffer();
23
23
  const result = await parser.convert({
@@ -28,7 +28,7 @@ app.post('/convert', async (c) => {
28
28
  return c.json(result);
29
29
  }
30
30
  catch (error) {
31
- return c.json({ error: error instanceof Error ? error.message : 'Conversion failed' }, 500);
31
+ return c.json({ error: error instanceof Error ? error.message : "Conversion failed" }, 500);
32
32
  }
33
33
  });
34
34
  export default app;
package/dist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,CAAC,CAAC;IAC9F,CAAC;AACH,CAAC,CAAC,CAAC;AAEH,eAAe,GAAG,CAAC"}
package/dist/index.d.ts CHANGED
@@ -1,3 +1,3 @@
1
- export { default as app } from './app.js';
2
- export { rateLimit, validateFileSize } from './middleware.js';
1
+ export { default as app } from "./app.js";
2
+ export { rateLimit, validateFileSize } from "./middleware.js";
3
3
  //# sourceMappingURL=index.d.ts.map
package/dist/index.js CHANGED
@@ -1,3 +1,3 @@
1
- export { default as app } from './app.js';
2
- export { rateLimit, validateFileSize } from './middleware.js';
1
+ export { default as app } from "./app.js";
2
+ export { rateLimit, validateFileSize } from "./middleware.js";
3
3
  //# sourceMappingURL=index.js.map
@@ -1,4 +1,4 @@
1
- import type { Context, Next } from 'hono';
1
+ import type { Context, Next } from "hono";
2
2
  export declare function rateLimit(options?: {
3
3
  windowMs?: number;
4
4
  max?: number;
@@ -3,7 +3,7 @@ export function rateLimit(options = {}) {
3
3
  const windowMs = options.windowMs ?? 60_000;
4
4
  const max = options.max ?? 100;
5
5
  return async (c, next) => {
6
- const ip = c.req.header('x-forwarded-for') ?? c.req.header('x-real-ip') ?? 'unknown';
6
+ const ip = c.req.header("x-forwarded-for") ?? c.req.header("x-real-ip") ?? "unknown";
7
7
  const now = Date.now();
8
8
  const record = requestCounts.get(ip);
9
9
  if (!record || now > record.resetTime) {
@@ -12,16 +12,16 @@ export function rateLimit(options = {}) {
12
12
  }
13
13
  record.count++;
14
14
  if (record.count > max) {
15
- return c.json({ error: 'Too many requests' }, 429);
15
+ return c.json({ error: "Too many requests" }, 429);
16
16
  }
17
17
  return next();
18
18
  };
19
19
  }
20
20
  const MAX_FILE_SIZE = 50 * 1024 * 1024;
21
21
  export async function validateFileSize(c, next) {
22
- const contentLength = c.req.header('content-length');
22
+ const contentLength = c.req.header("content-length");
23
23
  if (contentLength && parseInt(contentLength, 10) > MAX_FILE_SIZE) {
24
- return c.json({ error: 'File too large. Maximum size is 50MB' }, 413);
24
+ return c.json({ error: "File too large. Maximum size is 50MB" }, 413);
25
25
  }
26
26
  return next();
27
27
  }
package/dist/server.js CHANGED
@@ -1,6 +1,6 @@
1
- import { serve } from '@hono/node-server';
2
- import app from './app.js';
3
- const port = parseInt(process.env.PORT ?? '3000', 10);
1
+ import { serve } from "@hono/node-server";
2
+ import app from "./app.js";
3
+ const port = parseInt(process.env.PORT ?? "3000", 10);
4
4
  serve({ fetch: app.fetch, port }, (info) => {
5
5
  console.log(`MarkItDownJS API server running on http://localhost:${info.port}`);
6
6
  });
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@markitdownjs/api",
3
- "version": "0.1.0",
3
+ "version": "0.1.2",
4
4
  "description": "HTTP API server for MarkItDownJS document conversion",
5
5
  "license": "MIT",
6
6
  "type": "module",
@@ -18,8 +18,8 @@
18
18
  ],
19
19
  "dependencies": {
20
20
  "hono": "^4.0.0",
21
- "@markitdownjs/core": "0.1.0",
22
- "@markitdownjs/shared": "0.1.0"
21
+ "@markitdownjs/core": "0.2.0",
22
+ "@markitdownjs/shared": "0.2.0"
23
23
  },
24
24
  "devDependencies": {
25
25
  "typescript": "^5.5.0",