flexorch-sdk 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.
package/LICENSE ADDED
@@ -0,0 +1,21 @@
1
+ MIT License
2
+
3
+ Copyright (c) 2026 Flexorch Technology
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,265 @@
1
+ # flexorch-sdk
2
+
3
+ [![npm version](https://img.shields.io/npm/v/flexorch-sdk)](https://www.npmjs.com/package/flexorch-sdk)
4
+ [![CI](https://github.com/flexorch/flexorch-sdk-js/actions/workflows/ci.yml/badge.svg)](https://github.com/flexorch/flexorch-sdk-js/actions)
5
+ [![License: MIT](https://img.shields.io/badge/License-MIT-blue.svg)](LICENSE)
6
+ [![Node >=18](https://img.shields.io/badge/node-%3E%3D18-brightgreen)](https://nodejs.org)
7
+
8
+ TypeScript/JavaScript SDK for the [FlexOrch](https://flexorch.com) API.
9
+ Turn unstructured documents (PDF, DOCX, TXT, …) into LLM-ready structured datasets.
10
+
11
+ **Zero runtime dependencies** — uses native `fetch` and `FormData`.
12
+
13
+ ---
14
+
15
+ ## Install
16
+
17
+ ```bash
18
+ npm install flexorch-sdk
19
+ ```
20
+
21
+ ---
22
+
23
+ ## Quick start
24
+
25
+ ```typescript
26
+ import { FlexOrchClient } from "flexorch-sdk";
27
+
28
+ const client = new FlexOrchClient(process.env.FLEXORCH_API_KEY);
29
+
30
+ const job = await client.process("contract.pdf", { locale: "tr" });
31
+ const done = await job.wait();
32
+
33
+ console.log(`Grade: ${done.qualityGrade} Score: ${done.qualityScore}`);
34
+
35
+ const dataset = await done.dataset();
36
+ if (dataset) {
37
+ const bytes = await dataset.export("jsonl");
38
+ await fs.writeFile("output.jsonl", bytes);
39
+ console.log(`${dataset.rowCount} rows → output.jsonl`);
40
+ }
41
+ ```
42
+
43
+ The API key is read from `FLEXORCH_API_KEY` if not passed explicitly.
44
+
45
+ ---
46
+
47
+ ## Input formats
48
+
49
+ | Format | Extension |
50
+ |--------|-----------|
51
+ | PDF | `.pdf` |
52
+ | Word | `.docx` |
53
+ | Plain text | `.txt` |
54
+ | Markdown | `.md` |
55
+
56
+ ---
57
+
58
+ ## Export formats
59
+
60
+ | Format | Value |
61
+ |--------|-------|
62
+ | JSON Lines | `"jsonl"` |
63
+ | CSV | `"csv"` |
64
+ | Parquet | `"parquet"` |
65
+ | Excel | `"xlsx"` |
66
+
67
+ ---
68
+
69
+ ## API reference
70
+
71
+ ### `new FlexOrchClient(apiKeyOrOptions?)`
72
+
73
+ ```typescript
74
+ const client = new FlexOrchClient("sk-...");
75
+ // or
76
+ const client = new FlexOrchClient({
77
+ apiKey: "sk-...",
78
+ baseUrl: "https://api.flexorch.com", // default
79
+ timeout: 30_000, // ms, default 30 s
80
+ maxRetries: 3, // default 3
81
+ });
82
+ ```
83
+
84
+ ### `client.process(file, options?)`
85
+
86
+ Upload a single file and create a processing job.
87
+
88
+ ```typescript
89
+ const job = await client.process("invoice.pdf", {
90
+ locale: "tr", // BCP-47 locale hint
91
+ pipelineConfig: {}, // optional pipeline overrides
92
+ });
93
+ ```
94
+
95
+ Returns a `Job` instance.
96
+
97
+ ### `client.processMany(files, options?)`
98
+
99
+ Batch-process multiple files. Returns `Job[]`.
100
+
101
+ ```typescript
102
+ const jobs = await client.processMany(["a.pdf", "b.pdf"], { locale: "en" });
103
+ ```
104
+
105
+ ### `client.processFromS3(connectorId, keys, options?)`
106
+
107
+ Import files from S3 via a registered connector. Returns `Job[]`.
108
+
109
+ ```typescript
110
+ const jobs = await client.processFromS3(conn.id, ["folder/doc.pdf"], { locale: "de" });
111
+ ```
112
+
113
+ ### `client.search(query, options?)`
114
+
115
+ Semantic search across all indexed datasets.
116
+
117
+ ```typescript
118
+ const results = await client.search("net payment terms", { topK: 5 });
119
+ for (const r of results) {
120
+ console.log(r.score, r.text);
121
+ }
122
+ ```
123
+
124
+ ---
125
+
126
+ ### `Job`
127
+
128
+ | Method | Description |
129
+ |--------|-------------|
130
+ | `job.wait(options?)` | Poll until done. Resolves with a completed `Job`. |
131
+ | `job.dataset()` | Fetch the resulting `Dataset` (null if none). |
132
+
133
+ `wait` options: `{ timeout?: number (seconds), pollInterval?: number (ms) }`
134
+
135
+ Throws `JobFailedError` if the job fails, `JobTimeoutError` if timeout is exceeded.
136
+
137
+ ---
138
+
139
+ ### `Dataset`
140
+
141
+ | Method | Description |
142
+ |--------|-------------|
143
+ | `dataset.export(format)` | Download dataset as `Buffer`. |
144
+ | `dataset.exportToS3(connectorId, format, prefix?)` | Push export to S3. |
145
+ | `dataset.index()` | Trigger vector indexing. |
146
+ | `dataset.indexStatus()` | Poll index build status. |
147
+
148
+ Key properties: `id`, `name`, `slug`, `rowCount`, `status`, `qualityGrade`, `qualityScore`, `piiCount`, `createdAt`.
149
+
150
+ ---
151
+
152
+ ### `client.connectors`
153
+
154
+ ```typescript
155
+ const conn = await client.connectors.create("Prod S3", "s3", {
156
+ bucket: "my-bucket",
157
+ region: "eu-central-1",
158
+ accessKeyId: "...",
159
+ secretAccessKey: "...",
160
+ });
161
+
162
+ const result = await client.connectors.test(conn.id);
163
+ // { success: true, latencyMs: 42, message: "OK" }
164
+
165
+ await client.connectors.list();
166
+ await client.connectors.get(id);
167
+ await client.connectors.delete(id);
168
+ ```
169
+
170
+ Supported connector types: `"s3"`, `"gcs"`, `"azure_blob"`.
171
+
172
+ ---
173
+
174
+ ### `client.jobs` / `client.datasets` / `client.usage` / `client.webhooks`
175
+
176
+ ```typescript
177
+ await client.jobs.list();
178
+ await client.jobs.get(id);
179
+ await client.jobs.cancel(id);
180
+
181
+ await client.datasets.list();
182
+ await client.datasets.get(id);
183
+ await client.datasets.delete(id);
184
+
185
+ const snap = await client.usage.current();
186
+ // { periodStart, periodEnd, documentsProcessed, documentsLimit, planTier }
187
+
188
+ await client.webhooks.create("https://example.com/hook", ["job.completed"]);
189
+ await client.webhooks.list();
190
+ await client.webhooks.delete(id);
191
+ ```
192
+
193
+ ---
194
+
195
+ ## Error handling
196
+
197
+ ```typescript
198
+ import {
199
+ FlexOrchError,
200
+ AuthError,
201
+ QuotaError,
202
+ RateLimitError,
203
+ NotFoundError,
204
+ ValidationError,
205
+ ServerError,
206
+ JobFailedError,
207
+ JobTimeoutError,
208
+ } from "flexorch-sdk";
209
+
210
+ try {
211
+ const done = await job.wait({ timeout: 120 });
212
+ } catch (err) {
213
+ if (err instanceof JobFailedError) {
214
+ console.error(`Job ${err.jobId} failed: ${err.failureReason}`);
215
+ } else if (err instanceof QuotaError) {
216
+ console.error("Monthly document quota exceeded");
217
+ } else if (err instanceof RateLimitError) {
218
+ console.error(`Rate limited — retry after ${err.retryAfter}s`);
219
+ } else {
220
+ throw err;
221
+ }
222
+ }
223
+ ```
224
+
225
+ All SDK errors extend `FlexOrchError`. HTTP 4xx/5xx responses map to typed error classes automatically.
226
+
227
+ ---
228
+
229
+ ## Configuration
230
+
231
+ | Option | Env var | Default |
232
+ |--------|---------|---------|
233
+ | `apiKey` | `FLEXORCH_API_KEY` | — |
234
+ | `baseUrl` | `FLEXORCH_BASE_URL` | `https://api.flexorch.com` |
235
+ | `timeout` | — | `30000` ms |
236
+ | `maxRetries` | — | `3` |
237
+
238
+ ---
239
+
240
+ ## Examples
241
+
242
+ | File | Description |
243
+ |------|-------------|
244
+ | [basic-process.ts](examples/basic-process.ts) | Process a single PDF, export JSONL |
245
+ | [batch-process.ts](examples/batch-process.ts) | Process a directory, collect datasets |
246
+ | [s3-import.ts](examples/s3-import.ts) | Register S3 connector, import, export back |
247
+
248
+ ---
249
+
250
+ ## Development
251
+
252
+ ```bash
253
+ npm install
254
+ npm run build # ESM + CJS + .d.ts
255
+ npm test # 36 tests via vitest
256
+ npm run typecheck # tsc --noEmit
257
+ ```
258
+
259
+ See [CONTRIBUTING.md](CONTRIBUTING.md) for contribution guidelines.
260
+
261
+ ---
262
+
263
+ ## License
264
+
265
+ [MIT](LICENSE) — Flexorch Technology 2026
@@ -0,0 +1,87 @@
1
+ // src/models/dataset.ts
2
+ var SUPPORTED_FORMATS = /* @__PURE__ */ new Set([
3
+ "json",
4
+ "jsonl",
5
+ "csv",
6
+ "parquet",
7
+ "md",
8
+ "xml",
9
+ "xlsx",
10
+ "rag"
11
+ ]);
12
+ var Dataset = class _Dataset {
13
+ id;
14
+ name;
15
+ slug;
16
+ status;
17
+ rowCount;
18
+ createdAt;
19
+ availableFormats;
20
+ _transport;
21
+ constructor(data) {
22
+ this.id = data.id;
23
+ this.name = data.name;
24
+ this.slug = data.slug;
25
+ this.status = data.status;
26
+ this.rowCount = data.rowCount;
27
+ this.createdAt = data.createdAt;
28
+ this.availableFormats = data.availableFormats;
29
+ this._transport = data._transport;
30
+ }
31
+ static fromDict(data, transport) {
32
+ const fmt = data["format_summary"] ?? {};
33
+ const files = fmt["files"] ?? {};
34
+ return new _Dataset({
35
+ id: String(data["id"] ?? ""),
36
+ name: String(data["name"] ?? ""),
37
+ slug: String(data["slug"] ?? ""),
38
+ status: String(data["status"] ?? ""),
39
+ rowCount: Number(data["row_count"] ?? 0),
40
+ createdAt: String(data["created_at"] ?? ""),
41
+ availableFormats: Object.keys(files),
42
+ _transport: transport
43
+ });
44
+ }
45
+ async export(format) {
46
+ if (!SUPPORTED_FORMATS.has(format)) {
47
+ throw new Error(`Unsupported format "${format}". Choose from: ${[...SUPPORTED_FORMATS].sort().join(", ")}`);
48
+ }
49
+ return this._transport.getBytes(`/datasets/${this.id}/export`, { format });
50
+ }
51
+ async exportToS3(connectorId, format, prefix = "") {
52
+ if (!SUPPORTED_FORMATS.has(format)) {
53
+ throw new Error(`Unsupported format "${format}". Choose from: ${[...SUPPORTED_FORMATS].sort().join(", ")}`);
54
+ }
55
+ const data = await this._transport.post(`/datasets/${this.id}/export-s3`, {
56
+ format,
57
+ connector_id: connectorId,
58
+ prefix
59
+ });
60
+ return {
61
+ s3Key: String(data["s3_key"] ?? ""),
62
+ sizeBytes: Number(data["size_bytes"] ?? 0)
63
+ };
64
+ }
65
+ async index() {
66
+ const data = await this._transport.post(`/datasets/${this.id}/index`) ?? {};
67
+ return {
68
+ status: String(data["status"] ?? ""),
69
+ message: String(data["message"] ?? "")
70
+ };
71
+ }
72
+ async indexStatus() {
73
+ const data = await this._transport.get(`/datasets/${this.id}/index/status`) ?? {};
74
+ return {
75
+ status: String(data["status"] ?? "not_indexed"),
76
+ chunksIndexed: Number(data["chunks_indexed"] ?? 0),
77
+ totalChunks: Number(data["total_chunks"] ?? 0)
78
+ };
79
+ }
80
+ toString() {
81
+ return `Dataset(id=${this.id}, name=${this.name}, rows=${this.rowCount}, status=${this.status})`;
82
+ }
83
+ };
84
+
85
+ export {
86
+ Dataset
87
+ };
@@ -0,0 +1,6 @@
1
+ import {
2
+ Dataset
3
+ } from "./chunk-7JBTDKMH.js";
4
+ export {
5
+ Dataset
6
+ };