qorstack-report-sdk 0.0.1

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,370 @@
1
+ # Qorstack Report SDK
2
+
3
+ The official SDK for Qorstack Report, a powerful API for generating PDF reports from Microsoft Word (DOCX) templates.
4
+ This SDK simplifies the integration of Qorstack Report into your **Node.js** and **.NET** applications.
5
+
6
+ ## Features
7
+
8
+ - **Template-Based Rendering**: Generate PDFs from templates stored in your Qorstack Report account.
9
+ - **Dynamic File Rendering**: Generate PDFs directly from a base64-encoded DOCX file.
10
+ - **Comprehensive Data Binding**:
11
+ - Text replacement
12
+ - Dynamic tables (with merge and collapse support)
13
+ - Images (from URL or Base64)
14
+ - QR Codes and Barcodes
15
+ - Conditional logic (hide/show sections)
16
+ - **Cross-Platform Support**: Fully typed libraries for TypeScript/Node.js and C#/.NET 8.0+.
17
+
18
+ ---
19
+
20
+ ## Installation
21
+
22
+ ### Node.js (TypeScript/JavaScript)
23
+
24
+ ```bash
25
+ npm install qorstack-report-sdk
26
+ # or
27
+ yarn add qorstack-report-sdk
28
+ ```
29
+
30
+ ### .NET (C#)
31
+
32
+ ```bash
33
+ dotnet add package Qorstack.Report.Sdk
34
+ ```
35
+
36
+ ---
37
+
38
+ ## Authentication
39
+
40
+ To use the SDK, you need an **API Key** from the Qorstack Portal.
41
+
42
+ 1. Log in to the Qorstack Portal.
43
+ 2. Navigate to **Settings > API Keys**.
44
+ 3. Create a new API Key.
45
+
46
+ ---
47
+
48
+ ## Getting Started
49
+
50
+ ### Node.js Setup
51
+
52
+ ```typescript
53
+ import { QorstackApi } from "qorstack-report-sdk";
54
+
55
+ // 1. Initialize the client with API Key
56
+ const qorstackApi = new QorstackApi({
57
+ securityData: {
58
+ headers: {
59
+ "X-API-KEY": "YOUR_API_KEY_HERE",
60
+ },
61
+ },
62
+ });
63
+
64
+ // OR: Initialize with custom Base URL and API Key
65
+ const qorstackApiCustom = new QorstackApi({
66
+ baseUrl: "https://your-custom-url.com",
67
+ securityData: {
68
+ headers: {
69
+ "X-API-KEY": "YOUR_API_KEY_HERE",
70
+ },
71
+ },
72
+ });
73
+ ```
74
+
75
+ ### .NET Setup
76
+
77
+ ```csharp
78
+ using Qorstack.Report.Sdk;
79
+ using System.Net.Http;
80
+
81
+ // 1. Initialize the Client with API Key
82
+ var qorstackApi = new QorstackApi(apiKey: "YOUR_API_KEY_HERE");
83
+
84
+ // OR: Initialize with custom Base URL and API Key
85
+ var qorstackApiCustom = new QorstackApi("https://your-custom-url.com", "YOUR_API_KEY_HERE");
86
+ ```
87
+
88
+ ---
89
+
90
+ ## Usage Examples
91
+
92
+ This section demonstrates how to construct request objects for various scenarios.
93
+
94
+ ### 1. Generate PDF from Template (`PdfFromTemplateRequest`)
95
+
96
+ This is the most common use case. You reference a `templateKey` stored in the system.
97
+
98
+ #### Full Feature Example (Text, Table, Image, QR, Barcode)
99
+
100
+ **Node.js (TypeScript)**
101
+
102
+ ```typescript
103
+ // Prepare table rows
104
+ const tableRows = data.map((item, index) => ({
105
+ no: index + 1,
106
+ category: item.category,
107
+ description: item.description,
108
+ qty: item.quantity,
109
+ unit_price: item.price,
110
+ amount: item.total,
111
+ }));
112
+
113
+ const response = await qorstackApi.render.postRenderTemplatePdf({
114
+ templateKey: "RENDOX-7326-758-974-2067",
115
+ fileName: "Full_Report_Example",
116
+ replace: {
117
+ customer_name: "Example Company Ltd.",
118
+ document_date: new Date().toLocaleDateString("en-GB"), // dd/MM/yyyy
119
+ total_amount: "1,500.00",
120
+ },
121
+ table: [
122
+ {
123
+ rows: tableRows,
124
+ verticalMerge: ["category"],
125
+ collapse: ["description"],
126
+ },
127
+ ],
128
+ image: {
129
+ header_logo: {
130
+ src: "https://example.com/logo.png",
131
+ width: 200,
132
+ fit: "contain",
133
+ },
134
+ },
135
+ qrcode: {
136
+ payment_qr: {
137
+ text: "https://payment.link/123456",
138
+ size: 150,
139
+ },
140
+ },
141
+ barcode: {
142
+ product_barcode: {
143
+ text: "PROD-123456789",
144
+ format: "Code128",
145
+ width: 300,
146
+ height: 80,
147
+ },
148
+ },
149
+ });
150
+
151
+ console.log("Download URL:", response.data.downloadUrl);
152
+ ```
153
+
154
+ **C# (.NET)**
155
+
156
+ ```csharp
157
+ var data = await _exampleService.GetDataAsync(id);
158
+
159
+ var tableRows = data.Select((item, index) => new Dictionary<string, object>
160
+ {
161
+ { "no", index + 1 },
162
+ { "category", item.Category },
163
+ { "description", item.Description },
164
+ { "qty", item.Quantity },
165
+ { "unit_price", item.Price },
166
+ { "amount", item.Total }
167
+ }).ToList();
168
+
169
+ var request = new PdfFromTemplateRequest
170
+ {
171
+ TemplateKey = "RENDOX-7326-758-974-2067",
172
+ FileName = "Full_Report_Example",
173
+ Replace = new()
174
+ {
175
+ { "customer_name", "Example Company Ltd." },
176
+ { "document_date", DateTime.Now.ToString("dd/MM/yyyy") },
177
+ { "total_amount", "1,500.00" }
178
+ },
179
+ Table = new()
180
+ {
181
+ new()
182
+ {
183
+ Rows = tableRows,
184
+ VerticalMerge = new() { "category" },
185
+ Collapse = new() { "description" }
186
+ }
187
+ },
188
+ Image = new()
189
+ {
190
+ {
191
+ "header_logo",
192
+ new() { Src = "https://example.com/logo.png", Width = 200, Fit = "contain" }
193
+ }
194
+ },
195
+ QrCode = new()
196
+ {
197
+ {
198
+ "payment_qr",
199
+ new() { Text = "https://payment.link/123456", Size = 150 }
200
+ }
201
+ },
202
+ Barcode = new()
203
+ {
204
+ {
205
+ "product_barcode",
206
+ new() { Text = "PROD-123456789", Format = "Code128", Width = 300, Height = 80 }
207
+ }
208
+ }
209
+ };
210
+
211
+ var response = await qorstackApi.PostRenderTemplatePdfAsync(request);
212
+ ```
213
+
214
+ ---
215
+
216
+ ### 2. Generate PDF from File (`PdfFromFileRequest`)
217
+
218
+ Use this when you want to send the DOCX template file directly with the request.
219
+
220
+ **Node.js (TypeScript)**
221
+
222
+ ```typescript
223
+ import * as fs from "fs";
224
+
225
+ // Read local file as Base64
226
+ const fileBuffer = fs.readFileSync("template.docx");
227
+ const base64File = fileBuffer.toString("base64");
228
+
229
+ const response = await qorstackApi.render.postRenderDocxPdf({
230
+ fileBase64: base64File,
231
+ fileName: "OnDemand_Report",
232
+ replace: {
233
+ title: "Report Title",
234
+ },
235
+ table: [
236
+ {
237
+ rows: [
238
+ { item: "Item A", price: 100 },
239
+ { item: "Item B", price: 200 },
240
+ ],
241
+ },
242
+ ],
243
+ });
244
+ ```
245
+
246
+ **C# (.NET)**
247
+
248
+ ```csharp
249
+ byte[] fileBytes = await File.ReadAllBytesAsync("template.docx");
250
+
251
+ var request = new PdfFromFileRequest
252
+ {
253
+ FileBase64 = Convert.ToBase64String(fileBytes),
254
+ FileName = "OnDemand_Report",
255
+ Replace = new()
256
+ {
257
+ { "title", "Report Title" }
258
+ },
259
+ Table = new()
260
+ {
261
+ new()
262
+ {
263
+ Rows = new()
264
+ {
265
+ new Dictionary<string, object> { { "item", "Item A" }, { "price", 100 } },
266
+ new Dictionary<string, object> { { "item", "Item B" }, { "price", 200 } }
267
+ }
268
+ }
269
+ }
270
+ };
271
+
272
+ var response = await qorstackApi.PostRenderDocxPdfAsync(request);
273
+ ```
274
+
275
+ ---
276
+
277
+ ## Data Binding Reference
278
+
279
+ The Qorstack Report engine supports various data types. Here is how to structure your request object.
280
+
281
+ ### Text Replacement (`replace`)
282
+
283
+ Simple key-value pairs to replace text placeholders like `{{customerName}}`.
284
+
285
+ ```json
286
+ "replace": {
287
+ "customerName": "Acme Corp",
288
+ "totalAmount": "$1,050.00"
289
+ }
290
+ ```
291
+
292
+ ### Tables (`table`)
293
+
294
+ Populates rows in a table. The `rows` array contains objects where keys match the columns in your Word table.
295
+
296
+ ```json
297
+ "table": [
298
+ {
299
+ "rows": [
300
+ { "name": "Value A", "last_name": "Value B" },
301
+ { "name": "Value C", "last_name": "Value D" }
302
+ ],
303
+ "verticalMerge": ["category"],
304
+ "collapse": ["description"]
305
+ }
306
+ ]
307
+ ```
308
+
309
+ ### Images (`image`)
310
+
311
+ Replaces placeholders like `{{image:logo}}`. Supports URLs or Base64.
312
+
313
+ - `src`: Image URL or Base64 string.
314
+ - `width`, `height`: Optional dimensions in pixels.
315
+ - `fit`: Optional ("contain", "cover", "fill").
316
+
317
+ ```json
318
+ "image": {
319
+ "logo": {
320
+ "src": "https://example.com/logo.png",
321
+ "width": 150,
322
+ "height": 50
323
+ }
324
+ }
325
+ ```
326
+
327
+ ### QR Codes (`qrcode`)
328
+
329
+ Generates QR codes for placeholders like `{{qr:website}}`.
330
+
331
+ ```json
332
+ "qrcode": {
333
+ "website": {
334
+ "text": "https://qorstack.dev",
335
+ "size": 200,
336
+ "color": "#000000"
337
+ }
338
+ }
339
+ ```
340
+
341
+ ### Barcodes (`barcode`)
342
+
343
+ Generates barcodes for placeholders like `{{barcode:productId}}`.
344
+
345
+ - `format`: Default is "Code128".
346
+
347
+ ```json
348
+ "barcode": {
349
+ "productId": {
350
+ "text": "1234567890",
351
+ "format": "Code128",
352
+ "includeText": true
353
+ }
354
+ }
355
+ ```
356
+
357
+ ---
358
+
359
+ ## Error Handling
360
+
361
+ The SDK throws exceptions when the API returns an error (e.g., 400 Bad Request, 401 Unauthorized).
362
+
363
+ - **Node.js**: The promise will reject with the error response.
364
+ - **.NET**: `ApiException` or `ApiException<ProblemDetails>` will be thrown. You can access `ex.Result` to get detailed error messages from the server.
365
+
366
+ ---
367
+
368
+ ## License
369
+
370
+ MIT License. See [LICENSE](LICENSE) for details.