@tesouro/embedded-components-widget-token 0.2.221 → 0.2.238

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/dist/index.js CHANGED
@@ -1,6 +1,2 @@
1
- import { DEFAULT_EXPIRATION_IN_SECONDS as r, configureCreateWidgetToken as t, createWidgetToken as T } from "./index2.js";
2
- export {
3
- r as DEFAULT_EXPIRATION_IN_SECONDS,
4
- t as configureCreateWidgetToken,
5
- T as createWidgetToken
6
- };
1
+ import { DEFAULT_EXPIRATION_IN_SECONDS as e, configureCreateWidgetToken as t, createWidgetToken as n } from "./index2.js";
2
+ export { e as DEFAULT_EXPIRATION_IN_SECONDS, t as configureCreateWidgetToken, n as createWidgetToken };
package/dist/index2.js CHANGED
@@ -1,82 +1,53 @@
1
- import d from "crypto";
2
- import { EncryptJWT as y } from "jose";
3
- const k = 480;
4
- async function T({
5
- clientId: e,
6
- clientSecret: o,
7
- widgetSecret: r,
8
- userId: i,
9
- userEmail: s,
10
- organizationReference: a,
11
- expirationInSeconds: c = k
12
- }) {
13
- if (!r || !e || !o)
14
- throw new Error(
15
- "Missing required parameters for widget token generation: clientId, clientSecret, and widgetSecret are required"
16
- );
17
- const t = Math.floor(Date.now() / 1e3), n = t + c, u = new TextEncoder().encode(r), f = {
18
- sub: i,
19
- // Subject (user identifier)
20
- email: s,
21
- // Email claim
22
- aud: "tesouro",
23
- // Audience
24
- iss: e,
25
- // Issuer
26
- exp: n,
27
- // Expiration
28
- iat: t
29
- // Issued at
30
- }, g = Buffer.from(JSON.stringify({ alg: "none", typ: "JWT" })).toString(
31
- "base64url"
32
- ) + "." + Buffer.from(JSON.stringify(f)).toString("base64url") + ".", p = {
33
- aud: "tesouro",
34
- client_id: e,
35
- client_secret: o,
36
- exp: n,
37
- grant_type: "urn:ietf:params:oauth:grant-type:token-exchange",
38
- iat: t,
39
- iss: e,
40
- jti: d.randomUUID(),
41
- ...a ? { organization_reference: a } : {},
42
- subject_token: g,
43
- subject_token_type: "urn:ietf:params:oauth:token-type:access_token"
44
- };
45
- return { widgetToken: await new y(p).setProtectedHeader({
46
- alg: "A256KW",
47
- enc: "A256GCM",
48
- kid: e,
49
- typ: "JWT",
50
- cty: "JWT"
51
- }).encrypt(u), exp: n };
1
+ import e from "crypto";
2
+ import { EncryptJWT as t } from "jose";
3
+ //#region src/lib/createWidgetToken.ts
4
+ var n = 480;
5
+ async function r({ clientId: n, clientSecret: r, widgetSecret: i, userId: a, userEmail: o, organizationReference: s, expirationInSeconds: c = 480 }) {
6
+ if (!i || !n || !r) throw Error("Missing required parameters for widget token generation: clientId, clientSecret, and widgetSecret are required");
7
+ let l = Math.floor(Date.now() / 1e3), u = l + c, d = new TextEncoder().encode(i), f = {
8
+ sub: a,
9
+ email: o,
10
+ aud: "tesouro",
11
+ iss: n,
12
+ exp: u,
13
+ iat: l
14
+ }, p = Buffer.from(JSON.stringify({
15
+ alg: "none",
16
+ typ: "JWT"
17
+ })).toString("base64url") + "." + Buffer.from(JSON.stringify(f)).toString("base64url") + ".", m = {
18
+ aud: "tesouro",
19
+ client_id: n,
20
+ client_secret: r,
21
+ exp: u,
22
+ grant_type: "urn:ietf:params:oauth:grant-type:token-exchange",
23
+ iat: l,
24
+ iss: n,
25
+ jti: e.randomUUID(),
26
+ ...s ? { organization_reference: s } : {},
27
+ subject_token: p,
28
+ subject_token_type: "urn:ietf:params:oauth:token-type:access_token"
29
+ };
30
+ return {
31
+ widgetToken: await new t(m).setProtectedHeader({
32
+ alg: "A256KW",
33
+ enc: "A256GCM",
34
+ kid: n,
35
+ typ: "JWT",
36
+ cty: "JWT"
37
+ }).encrypt(d),
38
+ exp: u
39
+ };
52
40
  }
53
- function b({
54
- clientId: e,
55
- clientSecret: o,
56
- widgetSecret: r,
57
- organizationReference: i,
58
- expirationInSeconds: s
59
- }) {
60
- return ({
61
- userId: a,
62
- userEmail: c,
63
- // Defaults to the partner-config value bound at configure time. A per-call
64
- // override supports partners whose single client serves multiple
65
- // organizations; it must still be resolved server-side, never from the browser.
66
- organizationReference: t = i,
67
- expirationInSeconds: n = s
68
- }) => T({
69
- clientId: e,
70
- clientSecret: o,
71
- widgetSecret: r,
72
- userId: a,
73
- userEmail: c,
74
- organizationReference: t,
75
- expirationInSeconds: n
76
- });
41
+ function i({ clientId: e, clientSecret: t, widgetSecret: n, organizationReference: i, expirationInSeconds: a }) {
42
+ return ({ userId: o, userEmail: s, organizationReference: c = i, expirationInSeconds: l = a }) => r({
43
+ clientId: e,
44
+ clientSecret: t,
45
+ widgetSecret: n,
46
+ userId: o,
47
+ userEmail: s,
48
+ organizationReference: c,
49
+ expirationInSeconds: l
50
+ });
77
51
  }
78
- export {
79
- k as DEFAULT_EXPIRATION_IN_SECONDS,
80
- b as configureCreateWidgetToken,
81
- T as createWidgetToken
82
- };
52
+ //#endregion
53
+ export { n as DEFAULT_EXPIRATION_IN_SECONDS, i as configureCreateWidgetToken, r as createWidgetToken };
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@tesouro/embedded-components-widget-token",
3
- "version": "0.2.221",
3
+ "version": "0.2.238",
4
4
  "license": "Apache-2.0",
5
5
  "type": "module",
6
6
  "repository": {