@truto/truto-jsonata 1.0.42 → 1.0.44
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 +0 -55
- package/dist/browser/index.js +35 -1082
- package/dist/browser/index.js.map +5 -31
- package/dist/cjs/index.cjs +35 -1082
- package/dist/cjs/index.cjs.map +5 -31
- package/dist/esm/index.js +35 -31
- package/dist/esm/index.js.map +6 -7
- package/package.json +1 -2
- package/dist/functions/signJwt.d.ts +0 -2
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
|
|