@truto/truto-jsonata 1.0.43 → 1.0.45

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
@@ -1008,61 +1008,6 @@ expression2.evaluate({ text: text2, algorithm: algorithm2, secret: secret2, outp
1008
1008
 
1009
1009
  </details>
1010
1010
 
1011
- <details>
1012
- <summary>signJwt(payload, secretOrPrivateKey, headers = { alg: 'HS256', typ: 'JWT' })</summary>
1013
-
1014
- Generates a signed JWT using the JOSE library. This function now accepts headers directly and extracts JWT claims (like `exp`, `nbf`, `iat`) directly from the payload. The `alg` in the header defaults to 'HS256' if not provided.
1015
-
1016
- **Example:**
1017
-
1018
- ```javascript
1019
- import trutoJsonata from '@truto/truto-jsonata';
1020
-
1021
- const payload = {
1022
- sub: '1234567890',
1023
- name: 'John Doe',
1024
- exp: Math.floor(Date.now() / 1000) + 3600, // Expires in 1 hour
1025
- iat: Math.floor(Date.now() / 1000) // Issued at current time
1026
- };
1027
- const secretOrPrivateKey = 'your-256-bit-secret';
1028
- const headers = { alg: 'HS256', kid: 'custom-key-id' }; // Optional custom headers
1029
-
1030
- const expression = trutoJsonata('$signJwt(payload, secretOrPrivateKey, headers)');
1031
- expression.evaluate({ payload, secretOrPrivateKey, headers }).then(result => {
1032
- console.log(result);
1033
- // Output: "eyJhbGciOiJIUzI1NiIsImtpZCI6ImN1c3RvbS1rZXktaWQiLCJ0eXAiOiJKV1QifQ.eyJzdWIiOiIxMjM0NTY3ODkwIiwibmFtZSI6IkpvaG4gRG9lIiwiZXhwIjoxNzA3MjMzNjAwLCJpYXQiOjE3MDcyMzAwMDB9.<signature>"
1034
- });
1035
- ```
1036
-
1037
- **Google Service Account Example:**
1038
-
1039
- ```javascript
1040
- import trutoJsonata from '@truto/truto-jsonata';
1041
-
1042
- const serviceAccountPayload = {
1043
- "iss": "service-account@my-project.iam.gserviceaccount.com",
1044
- "sub": ,
1045
- "scope": ,
1046
- "aud": ,
1047
- "iat": Math.floor(Date.now() / 1000),
1048
- "exp": Math.floor(Date.now() / 1000) + 3600 /
1049
- };
1050
-
1051
- const serviceAccountHeaders = { alg: 'HS256' }; // Algorithm can be HS256 for testing, or RS256 with proper private key
1052
-
1053
- const serviceAccountExpression = trutoJsonata('$signJwt(serviceAccountPayload, serviceAccountSecret, serviceAccountHeaders)');
1054
- serviceAccountExpression.evaluate({
1055
- serviceAccountPayload,
1056
- serviceAccountSecret,
1057
- serviceAccountHeaders
1058
- }).then(result => {
1059
- console.log(result);
1060
- // Output: Signed JWT string for Google service account
1061
- });
1062
- ```
1063
-
1064
- </details>
1065
-
1066
1011
  <details>
1067
1012
  <summary>xmlToJs(xml, options = { compact: true, spaces: 4 } )</summary>
1068
1013
 
@@ -1587,6 +1532,44 @@ Output:
1587
1532
 
1588
1533
  </details>
1589
1534
 
1535
+ <details>
1536
+ <summary>convertMdToPdf(markdown, options = { title: '', pageSize: 'a4', embedImages: false, pageMargins: [40, 60, 40, 60], defaultStyle: { fontSize: 12, lineHeight: 1.4 } })</summary>
1537
+
1538
+ Converts Markdown text to a PDF `Blob` using jsPDF.
1539
+
1540
+ **Example:**
1541
+
1542
+ ```javascript
1543
+ import trutoJsonata from '@truto/truto-jsonata'
1544
+
1545
+ const markdown = `# Title\n\nThis is a paragraph.`
1546
+ const expression = trutoJsonata("$convertMdToPdf(markdown)")
1547
+ expression.evaluate({ markdown }).then(blob => {
1548
+ console.log(blob) // Blob { type: 'application/pdf' }
1549
+ })
1550
+ ```
1551
+
1552
+ **Options:**
1553
+ - `title`: Optional document title
1554
+ - `pageSize`: jsPDF page size (e.g., `'a4'`, `'LETTER'`)
1555
+ - `embedImages`: Reserved for future use
1556
+ - `pageMargins`: `[left, top, right, bottom]` in points
1557
+ - `defaultStyle`: `{ fontSize: number, lineHeight: number }`
1558
+
1559
+ If your transport requires a JSON-serializable value, convert the PDF Blob to a data URI string and decode it later:
1560
+
1561
+ ```javascript
1562
+ import trutoJsonata from '@truto/truto-jsonata'
1563
+
1564
+ const markdown = `# Report\nGenerated content`
1565
+ const expr = trutoJsonata("$getDataUri($convertMdToPdf(markdown), 'application/pdf')")
1566
+ expr.evaluate({ markdown }).then(dataUri => {
1567
+ // dataUri starts with 'data:application/pdf;base64,'
1568
+ console.log(typeof dataUri, dataUri.startsWith('data:application/pdf;base64,'))
1569
+ })
1570
+ ```
1571
+ </details>
1572
+
1590
1573
  ---
1591
1574
 
1592
1575
  ### Array and Object Utilities (Lodash Enhancements)