@docgl/sdk 0.0.5

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 ADDED
@@ -0,0 +1,99 @@
1
+ # @docgl/sdk — TypeScript / JavaScript SDK
2
+
3
+ Official TypeScript SDK for the [Docgl](https://docgl.com) document generation API.
4
+
5
+ ## Requirements
6
+
7
+ - Node.js **≥ 18** (uses the built-in `fetch` API)
8
+ - TypeScript **≥ 5** (optional but recommended)
9
+
10
+ ## Installation
11
+
12
+ ```bash
13
+ npm install @docgl/sdk
14
+ # or
15
+ yarn add @docgl/sdk
16
+ # or
17
+ pnpm add @docgl/sdk
18
+ ```
19
+
20
+ ## Quick start
21
+
22
+ ```ts
23
+ import { DocglClient } from "@docgl/sdk";
24
+
25
+ const docgl = new DocglClient(process.env.DOCGL_API_TOKEN!);
26
+
27
+ // 1. Queue document generation
28
+ const { queued, errors } = await docgl.generate({
29
+ documents: [
30
+ {
31
+ uuid: "your-template-uuid",
32
+ filename: "invoice-001.pdf",
33
+ data: [
34
+ {
35
+ customer_name: "Acme Corp",
36
+ invoice_number: "INV-001",
37
+ total: 1500,
38
+ },
39
+ ],
40
+ },
41
+ ],
42
+ // Optional: route output to your own storage bucket
43
+ // storageConfigUuid: "your-storage-config-uuid",
44
+ });
45
+
46
+ console.log("Queued:", queued);
47
+ // [{ jobId: "42", filename: "invoice-001.pdf" }]
48
+
49
+ // 2. Poll for status
50
+ const status = await docgl.getStatus(queued[0].jobId);
51
+ console.log(status.status); // "waiting" | "active" | "completed" | "failed"
52
+ ```
53
+
54
+ ## API
55
+
56
+ ### `new DocglClient(token)`
57
+
58
+ | Param | Type | Description |
59
+ |---|---|---|
60
+ | `token` | `string` | Your Docgl API token |
61
+
62
+ ### `client.generate(request)`
63
+
64
+ Queues one or more documents for PDF generation. Returns `202 Accepted` immediately.
65
+
66
+ **Returns:** `Promise<GenerateResponse>`
67
+
68
+ ### `client.getStatus(jobId)`
69
+
70
+ Returns the current status of a queued generation job.
71
+
72
+ **Returns:** `Promise<JobStatusResponse>`
73
+
74
+ #### Job status values
75
+
76
+ | Value | Description |
77
+ |---|---|
78
+ | `waiting` | In the queue, not yet started |
79
+ | `active` | Currently being processed |
80
+ | `completed` | PDF rendered successfully |
81
+ | `failed` | Generation failed — check `failedReason` |
82
+ | `delayed` | Scheduled to run later |
83
+ | `prioritized` | Waiting with elevated priority |
84
+ | `waiting-children` | Waiting for child jobs to complete |
85
+ | `unknown` | Job not found (may have been cleaned up) |
86
+
87
+ ## Error handling
88
+
89
+ ```ts
90
+ import { DocglClient, DocglError } from "@docgl/sdk";
91
+
92
+ try {
93
+ await docgl.generate({ documents: [] });
94
+ } catch (err) {
95
+ if (err instanceof DocglError) {
96
+ console.error(err.status, err.body);
97
+ }
98
+ }
99
+ ```
@@ -0,0 +1,46 @@
1
+ import type { GenerateRequest, GenerateResponse, JobStatusResponse } from "./types";
2
+ /** Error thrown when the Docgl API returns a non-2xx response */
3
+ export declare class DocglError extends Error {
4
+ readonly status: number;
5
+ readonly body: unknown;
6
+ constructor(status: number, body: unknown);
7
+ }
8
+ /**
9
+ * Official Docgl API client.
10
+ *
11
+ * @example
12
+ * ```ts
13
+ * const docgl = new DocglClient("your-api-token");
14
+ *
15
+ * const { queued } = await docgl.generate({
16
+ * documents: [{
17
+ * uuid: "template-uuid",
18
+ * filename: "invoice.pdf",
19
+ * data: [{ customer_name: "Acme Corp", total: 1500 }],
20
+ * }],
21
+ * });
22
+ *
23
+ * const status = await docgl.getStatus(queued[0].jobId);
24
+ * console.log(status.status); // "completed"
25
+ * ```
26
+ */
27
+ export declare class DocglClient {
28
+ private readonly token;
29
+ constructor(token: string);
30
+ private get authHeaders();
31
+ private handleResponse;
32
+ /**
33
+ * Queue one or more documents for generation.
34
+ *
35
+ * The API returns immediately with HTTP 202. Use {@link getStatus} to poll
36
+ * each `jobId` until `status` is `"completed"` or `"failed"`.
37
+ */
38
+ generate(request: GenerateRequest): Promise<GenerateResponse>;
39
+ /**
40
+ * Poll the status of a previously queued generation job.
41
+ *
42
+ * @param jobId - The `jobId` returned by {@link generate}
43
+ */
44
+ getStatus(jobId: string): Promise<JobStatusResponse>;
45
+ }
46
+ //# sourceMappingURL=client.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"client.d.ts","sourceRoot":"","sources":["../src/client.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EACV,eAAe,EACf,gBAAgB,EAChB,iBAAiB,EAClB,MAAM,SAAS,CAAC;AAIjB,iEAAiE;AACjE,qBAAa,UAAW,SAAQ,KAAK;aAEjB,MAAM,EAAE,MAAM;aACd,IAAI,EAAE,OAAO;gBADb,MAAM,EAAE,MAAM,EACd,IAAI,EAAE,OAAO;CAKhC;AAED;;;;;;;;;;;;;;;;;;GAkBG;AACH,qBAAa,WAAW;IACtB,OAAO,CAAC,QAAQ,CAAC,KAAK,CAAS;gBAEnB,KAAK,EAAE,MAAM;IAKzB,OAAO,KAAK,WAAW,GAItB;YAEa,cAAc;IAQ5B;;;;;OAKG;IACG,QAAQ,CAAC,OAAO,EAAE,eAAe,GAAG,OAAO,CAAC,gBAAgB,CAAC;IAYnE;;;;OAIG;IACG,SAAS,CAAC,KAAK,EAAE,MAAM,GAAG,OAAO,CAAC,iBAAiB,CAAC;CAO3D"}
package/dist/client.js ADDED
@@ -0,0 +1,80 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.DocglClient = exports.DocglError = void 0;
4
+ const BASE_URL = "https://api.docgl.com";
5
+ /** Error thrown when the Docgl API returns a non-2xx response */
6
+ class DocglError extends Error {
7
+ constructor(status, body) {
8
+ super(`Docgl API error ${status}: ${JSON.stringify(body)}`);
9
+ this.status = status;
10
+ this.body = body;
11
+ this.name = "DocglError";
12
+ }
13
+ }
14
+ exports.DocglError = DocglError;
15
+ /**
16
+ * Official Docgl API client.
17
+ *
18
+ * @example
19
+ * ```ts
20
+ * const docgl = new DocglClient("your-api-token");
21
+ *
22
+ * const { queued } = await docgl.generate({
23
+ * documents: [{
24
+ * uuid: "template-uuid",
25
+ * filename: "invoice.pdf",
26
+ * data: [{ customer_name: "Acme Corp", total: 1500 }],
27
+ * }],
28
+ * });
29
+ *
30
+ * const status = await docgl.getStatus(queued[0].jobId);
31
+ * console.log(status.status); // "completed"
32
+ * ```
33
+ */
34
+ class DocglClient {
35
+ constructor(token) {
36
+ if (!token)
37
+ throw new Error("Docgl API token is required");
38
+ this.token = token;
39
+ }
40
+ get authHeaders() {
41
+ return {
42
+ Authorization: `Bearer ${this.token}`,
43
+ };
44
+ }
45
+ async handleResponse(res) {
46
+ if (res.ok) {
47
+ return res.json();
48
+ }
49
+ const body = await res.json().catch(() => ({ message: res.statusText }));
50
+ throw new DocglError(res.status, body);
51
+ }
52
+ /**
53
+ * Queue one or more documents for generation.
54
+ *
55
+ * The API returns immediately with HTTP 202. Use {@link getStatus} to poll
56
+ * each `jobId` until `status` is `"completed"` or `"failed"`.
57
+ */
58
+ async generate(request) {
59
+ const res = await fetch(`${BASE_URL}/api/generate`, {
60
+ method: "POST",
61
+ headers: {
62
+ ...this.authHeaders,
63
+ "Content-Type": "application/json",
64
+ },
65
+ body: JSON.stringify(request),
66
+ });
67
+ return this.handleResponse(res);
68
+ }
69
+ /**
70
+ * Poll the status of a previously queued generation job.
71
+ *
72
+ * @param jobId - The `jobId` returned by {@link generate}
73
+ */
74
+ async getStatus(jobId) {
75
+ const res = await fetch(`${BASE_URL}/api/generate/${encodeURIComponent(jobId)}`, { headers: this.authHeaders });
76
+ return this.handleResponse(res);
77
+ }
78
+ }
79
+ exports.DocglClient = DocglClient;
80
+ //# sourceMappingURL=client.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"client.js","sourceRoot":"","sources":["../src/client.ts"],"names":[],"mappings":";;;AAMA,MAAM,QAAQ,GAAG,uBAAuB,CAAC;AAEzC,iEAAiE;AACjE,MAAa,UAAW,SAAQ,KAAK;IACnC,YACkB,MAAc,EAC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Ac,CAAmB,GAAG,CAAC,CAAC;IACpD,CAAC;IAED;;;;OAIG;IACH,KAAK,CAAC,SAAS,CAAC,KAAa;QAC3B,MAAM,GAAG,GAAG,MAAM,KAAK,CACrB,GAAG,QAAQ,iBAAiB,kBAAkB,CAAC,KAAK,CAAC,EAAE,EACvD,EAAE,OAAO,EAAE,IAAI,CAAC,WAAW,EAAE,CAC9B,CAAC;QACF,OAAO,IAAI,CAAC,cAAc,CAAoB,GAAG,CAAC,CAAC;IACrD,CAAC;CACF;AApDD,kCAoDC"}
@@ -0,0 +1,3 @@
1
+ export { DocglClient, DocglError } from "./client";
2
+ export type { GenerateRequest, GenerateResponse, JobStatusResponse, JobStatus, DocumentInput, DocumentVariables, VariableValue, TableRow, QueuedJob, ValidationError, } from "./types";
3
+ //# sourceMappingURL=index.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,WAAW,EAAE,UAAU,EAAE,MAAM,UAAU,CAAC;AACnD,YAAY,EACV,eAAe,EACf,gBAAgB,EAChB,iBAAiB,EACjB,SAAS,EACT,aAAa,EACb,iBAAiB,EACjB,aAAa,EACb,QAAQ,EACR,SAAS,EACT,eAAe,GAChB,MAAM,SAAS,CAAC"}
package/dist/index.js ADDED
@@ -0,0 +1,7 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.DocglError = exports.DocglClient = void 0;
4
+ var client_1 = require("./client");
5
+ Object.defineProperty(exports, "DocglClient", { enumerable: true, get: function () { return client_1.DocglClient; } });
6
+ Object.defineProperty(exports, "DocglError", { enumerable: true, get: function () { return client_1.DocglError; } });
7
+ //# sourceMappingURL=index.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"index.js","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":";;;AAAA,mCAAmD;AAA1C,qGAAA,WAAW,OAAA;AAAE,oGAAA,UAAU,OAAA"}
@@ -0,0 +1,55 @@
1
+ /** A single cell value inside a table row */
2
+ export type TableRow = Record<string, string | number>;
3
+ /** All allowed values for a document variable */
4
+ export type VariableValue = string | number | TableRow[];
5
+ /** Key-value map of variables for one document render */
6
+ export type DocumentVariables = Record<string, VariableValue>;
7
+ /** A single document to be rendered */
8
+ export interface DocumentInput {
9
+ /** UUID of the template registered in Docgl */
10
+ uuid: string;
11
+ /** Output filename (e.g. "invoice-001.pdf") */
12
+ filename: string;
13
+ /**
14
+ * Array of variable maps. Each entry produces one rendered PDF.
15
+ * Provide multiple entries to batch-render the same template with
16
+ * different data in a single request.
17
+ */
18
+ data: DocumentVariables[];
19
+ }
20
+ /** Body sent to POST /api/generate */
21
+ export interface GenerateRequest {
22
+ documents: DocumentInput[];
23
+ /**
24
+ * UUID of a storage configuration registered in Docgl.
25
+ * When provided, the generated PDF is uploaded to your storage bucket.
26
+ */
27
+ storageConfigUuid?: string;
28
+ }
29
+ /** A successfully queued job entry */
30
+ export interface QueuedJob {
31
+ jobId: string;
32
+ filename: string;
33
+ }
34
+ /** A document that failed validation */
35
+ export interface ValidationError {
36
+ filename: string;
37
+ errors: string[];
38
+ }
39
+ /** Response from POST /api/generate (HTTP 202) */
40
+ export interface GenerateResponse {
41
+ message: string;
42
+ queued: QueuedJob[];
43
+ errors?: ValidationError[];
44
+ }
45
+ /** Possible states of a generation job */
46
+ export type JobStatus = "waiting" | "active" | "completed" | "failed" | "delayed" | "prioritized" | "waiting-children" | "unknown";
47
+ /** Response from GET /api/generate/:jobId (HTTP 200) */
48
+ export interface JobStatusResponse {
49
+ jobId: string;
50
+ filename: string | null;
51
+ status: JobStatus;
52
+ result: unknown | null;
53
+ failedReason: string | null;
54
+ }
55
+ //# sourceMappingURL=types.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"types.d.ts","sourceRoot":"","sources":["../src/types.ts"],"names":[],"mappings":"AAIA,6CAA6C;AAC7C,MAAM,MAAM,QAAQ,GAAG,MAAM,C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GAAG,IAAI,CAAC;IACvB,YAAY,EAAE,MAAM,GAAG,IAAI,CAAC;CAC7B"}
package/dist/types.js ADDED
@@ -0,0 +1,6 @@
1
+ "use strict";
2
+ // ---------------------------------------------------------------------------
3
+ // Request types
4
+ // ---------------------------------------------------------------------------
5
+ Object.defineProperty(exports, "__esModule", { value: true });
6
+ //# sourceMappingURL=types.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"types.js","sourceRoot":"","sources":["../src/types.ts"],"names":[],"mappings":";AAAA,8EAA8E;AAC9E,gBAAgB;AAChB,8EAA8E"}
package/package.json ADDED
@@ -0,0 +1,49 @@
1
+ {
2
+ "name": "@docgl/sdk",
3
+ "version": "0.0.5",
4
+ "description": "Official TypeScript/JavaScript SDK for the Docgl API",
5
+ "main": "dist/index.js",
6
+ "module": "dist/index.mjs",
7
+ "types": "dist/index.d.ts",
8
+ "exports": {
9
+ ".": {
10
+ "import": "./dist/index.mjs",
11
+ "require": "./dist/index.js",
12
+ "types": "./dist/index.d.ts"
13
+ }
14
+ },
15
+ "files": [
16
+ "dist"
17
+ ],
18
+ "scripts": {
19
+ "build": "tsc",
20
+ "dev": "tsc --watch",
21
+ "typecheck": "tsc --noEmit"
22
+ },
23
+ "engines": {
24
+ "node": ">=18"
25
+ },
26
+ "keywords": [
27
+ "docgl",
28
+ "pdf",
29
+ "sdk",
30
+ "document",
31
+ "generation"
32
+ ],
33
+ "license": "MIT",
34
+ "author": "Docgl",
35
+ "repository": {
36
+ "type": "git",
37
+ "url": "https://github.com/docgl-sdk/typescript.git"
38
+ },
39
+ "bugs": {
40
+ "url": "https://github.com/docgl-sdk/typescript/issues"
41
+ },
42
+ "homepage": "https://github.com/docgl-sdk/typescript#readme",
43
+ "publishConfig": {
44
+ "access": "public"
45
+ },
46
+ "devDependencies": {
47
+ "typescript": "^5.4.0"
48
+ }
49
+ }