@t4h.framework/hmac 0.2.1 → 0.3.0
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/.ai/skills/framework-hmac/SKILL.md +1 -0
- package/CHANGELOG.md +51 -0
- package/README.md +1 -0
- package/dist/hmac-callback.d.ts +3 -0
- package/dist/hmac-callback.d.ts.map +1 -0
- package/dist/hmac-callback.js +26 -0
- package/dist/hmac-callback.js.map +1 -0
- package/dist/hmac.d.ts +1 -0
- package/dist/hmac.d.ts.map +1 -1
- package/dist/hmac.js +1 -0
- package/dist/hmac.js.map +1 -1
- package/package.json +7 -3
|
@@ -27,6 +27,7 @@ Package path: `framework/packages/hmac`. See [README.md](../../../README.md) for
|
|
|
27
27
|
|-------|---------|
|
|
28
28
|
| `@t4h.framework/hmac` | `HMACAuthorization`, `HMACAuthorizationContext`, `HMACAuthorizationManifest`, `HMACAlgorithm`, `HMAC_DEFAULT_ALGORITHM`, `HMAC_DEFAULT_SIGNATURE_FORMAT`, re-exports authorize module |
|
|
29
29
|
| `@t4h.framework/hmac/authorize` | Default async handler: `(context) => Promise<boolean>` |
|
|
30
|
+
| `@t4h.framework/hmac/callback` | Default export `hmacCallback`: `(auth, request) => Promise<boolean>`, the `hmac` authorizer hosts pass to the core `AsyncActivityCallback.authorize` |
|
|
30
31
|
|
|
31
32
|
```typescript
|
|
32
33
|
import {
|
package/CHANGELOG.md
CHANGED
|
@@ -1,5 +1,56 @@
|
|
|
1
1
|
# @t4h.framework/hmac
|
|
2
2
|
|
|
3
|
+
## 0.3.0
|
|
4
|
+
|
|
5
|
+
### Minor Changes
|
|
6
|
+
|
|
7
|
+
- [#167](https://github.com/tech4humans-brasil/framework/pull/167) [`1b1509f`](https://github.com/tech4humans-brasil/framework/commit/1b1509f9b6d2554dfab1f7633c3d022249e4fa01) Thanks [@gusteycamargo](https://github.com/gusteycamargo)! - Moves the callbacks route helpers from `@t4h.framework/webhook` to
|
|
8
|
+
`@t4h.framework/core`. The route advances any pending async activity, not only
|
|
9
|
+
`webhook()`, and the core already owned its contract (`AsyncActivityCallbackAuth`,
|
|
10
|
+
`GetActivityCallbackUrlClaim`, `AsyncActivityAdvanceContext`).
|
|
11
|
+
|
|
12
|
+
**core**: new `AsyncActivityCallback` namespace with `deriveToken`, `isTokenValid`,
|
|
13
|
+
`parseBody`, `getHeader`, `getBearerToken`, `flattenHeaders`, `authorize` and
|
|
14
|
+
the types `AsyncActivityCallback.Delivery`, `AsyncActivityCallback.Headers`, `AsyncActivityCallback.Json`,
|
|
15
|
+
`AsyncActivityCallback.AuthType`, `AsyncActivityCallback.Authorizer`, `AsyncActivityCallback.Authorizers`.
|
|
16
|
+
`AsyncActivityCallback.authorize(auth, request, authorizers?)` ships `basic`, `header` and
|
|
17
|
+
`bearer`; `hmac` and `jwt` are authorizers the host passes in, so the core does not
|
|
18
|
+
depend on `@t4h.framework/hmac` or `@t4h.framework/jwks`. A declared type without
|
|
19
|
+
a authorizer throws `AsyncActivityCallbackAuthorizerMissingException`; an unknown type throws
|
|
20
|
+
`AsyncActivityCallbackAuthUnsupportedException`.
|
|
21
|
+
|
|
22
|
+
**hmac**: new `@t4h.framework/hmac/callback` entry whose default export is the
|
|
23
|
+
`hmac` callback authorizer, `hmacCallback`.
|
|
24
|
+
|
|
25
|
+
**jwks**: new `@t4h.framework/jwks/callback` entry whose default export is the
|
|
26
|
+
`jwt` callback authorizer, `jwksCallback`.
|
|
27
|
+
|
|
28
|
+
**webhook**: no longer exports `deriveCallbackToken`, `isCallbackTokenValid`,
|
|
29
|
+
`verifyCallbackAuth`, `parseCallbackBody`, `getHeader`, `flattenHeaders` nor
|
|
30
|
+
`CallbackRequest`/`CallbackHeaders`, and no longer depends on `hmac` and `jwks`;
|
|
31
|
+
`WebhookJson` is now an alias of the core `AsyncActivityCallback.Json`. Hosts import the
|
|
32
|
+
helpers from the core `AsyncActivityCallback` namespace and the authorizers from the two entries.
|
|
33
|
+
|
|
34
|
+
**dev**: `@t4h.framework/webhook` becomes an optional peer like the other
|
|
35
|
+
integrations. Only `@t4h.framework/core` is required again, which fixes
|
|
36
|
+
`ERR_MODULE_NOT_FOUND: Cannot find package '@t4h.framework/webhook'` on
|
|
37
|
+
projects that never call `webhook()`. `hmac` and `jwt` callback authorizers are
|
|
38
|
+
loaded from the project when `@t4h.framework/hmac` / `@t4h.framework/jwks` are
|
|
39
|
+
installed; a callback whose declared `auth` needs a missing package answers 500
|
|
40
|
+
naming the package to install.
|
|
41
|
+
|
|
42
|
+
### Patch Changes
|
|
43
|
+
|
|
44
|
+
- Updated dependencies [[`1b1509f`](https://github.com/tech4humans-brasil/framework/commit/1b1509f9b6d2554dfab1f7633c3d022249e4fa01), [`1b1509f`](https://github.com/tech4humans-brasil/framework/commit/1b1509f9b6d2554dfab1f7633c3d022249e4fa01)]:
|
|
45
|
+
- @t4h.framework/core@0.13.0
|
|
46
|
+
|
|
47
|
+
## 0.2.2
|
|
48
|
+
|
|
49
|
+
### Patch Changes
|
|
50
|
+
|
|
51
|
+
- Updated dependencies [[`72e08ff`](https://github.com/tech4humans-brasil/framework/commit/72e08ff86e0ce735ef73ccdf33b0dc01cdb8b6f5)]:
|
|
52
|
+
- @t4h.framework/core@0.12.0
|
|
53
|
+
|
|
3
54
|
## 0.2.1
|
|
4
55
|
|
|
5
56
|
### Patch Changes
|
package/README.md
CHANGED
|
@@ -12,6 +12,7 @@ Requires `@t4h.framework/core` (same major line as this package).
|
|
|
12
12
|
|------------------|---------|
|
|
13
13
|
| `@t4h.framework/hmac` | `HMACAuthorization`, `HMACAuthorizationContext`, `HMACAlgorithm`, and related types |
|
|
14
14
|
| `@t4h.framework/hmac/authorize` | Default async handler invoked by the runtime with the manifest context |
|
|
15
|
+
| `@t4h.framework/hmac/callback` | Default export `hmacCallback`: `hmac` callback authorizer for the core `AsyncActivityCallback.authorize` (`pending({ auth: { type: 'hmac' } })`) |
|
|
15
16
|
|
|
16
17
|
## `HMACAuthorization`
|
|
17
18
|
|
|
@@ -0,0 +1,3 @@
|
|
|
1
|
+
import { AsyncActivityCallback, type AsyncActivityCallbackAuthHmac } from '@t4h.framework/core';
|
|
2
|
+
export default function hmacCallback(auth: AsyncActivityCallbackAuthHmac, request: AsyncActivityCallback.Delivery): Promise<boolean>;
|
|
3
|
+
//# sourceMappingURL=hmac-callback.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"hmac-callback.d.ts","sourceRoot":"","sources":["../src/hmac-callback.ts"],"names":[],"mappings":"AAAA,OAAO,EACL,qBAAqB,EACrB,KAAK,6BAA6B,EACnC,MAAM,qBAAqB,CAAA;AAI5B,wBAA8B,YAAY,CACxC,IAAI,EAAE,6BAA6B,EACnC,OAAO,EAAE,qBAAqB,CAAC,QAAQ,GACtC,OAAO,CAAC,OAAO,CAAC,CA4BlB"}
|
|
@@ -0,0 +1,26 @@
|
|
|
1
|
+
import { AsyncActivityCallback, } from '@t4h.framework/core';
|
|
2
|
+
import hmac from './hmac-authorize.js';
|
|
3
|
+
export default async function hmacCallback(auth, request) {
|
|
4
|
+
const signature = AsyncActivityCallback.getHeader(request.headers, auth.header);
|
|
5
|
+
if (!signature)
|
|
6
|
+
return false;
|
|
7
|
+
const timestamp = auth.timestampHeader
|
|
8
|
+
? AsyncActivityCallback.getHeader(request.headers, auth.timestampHeader)
|
|
9
|
+
: undefined;
|
|
10
|
+
if (auth.timestampHeader && !timestamp)
|
|
11
|
+
return false;
|
|
12
|
+
const rawPayload = (auth.signedPayload ?? '{body}')
|
|
13
|
+
.replaceAll('{timestamp}', timestamp ?? '')
|
|
14
|
+
.replaceAll('{body}', request.rawBody);
|
|
15
|
+
return hmac({
|
|
16
|
+
secret: auth.secret,
|
|
17
|
+
signature,
|
|
18
|
+
rawPayload,
|
|
19
|
+
algorithm: auth.algorithm,
|
|
20
|
+
signatureFormat: auth.signatureFormat,
|
|
21
|
+
signaturePrefix: auth.signaturePrefix,
|
|
22
|
+
timestamp,
|
|
23
|
+
toleranceInSeconds: auth.toleranceInSeconds,
|
|
24
|
+
});
|
|
25
|
+
}
|
|
26
|
+
//# sourceMappingURL=hmac-callback.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"hmac-callback.js","sourceRoot":"","sources":["../src/hmac-callback.ts"],"names":[],"mappings":"AAAA,OAAO,EACL,qBAAqB,GAEtB,MAAM,qBAAqB,CAAA;AAE5B,OAAO,IAAI,MAAM,qBAAqB,CAAA;AAEtC,MAAM,CAAC,OAAO,CAAC,KAAK,UAAU,YAAY,CACxC,IAAmC,EACnC,OAAuC;IAEvC,MAAM,SAAS,GAAG,qBAAqB,CAAC,SAAS,CAC/C,OAAO,CAAC,OAAO,EACf,IAAI,CAAC,MAAM,CACZ,CAAA;IAED,IAAI,CAAC,SAAS;QAAE,OAAO,KAAK,CAAA;IAE5B,MAAM,SAAS,GAAG,IAAI,CAAC,eAAe;QACpC,CAAC,CAAC,qBAAqB,CAAC,SAAS,CAAC,OAAO,CAAC,OAAO,EAAE,IAAI,CAAC,eAAe,CAAC;QACxE,CAAC,CAAC,SAAS,CAAA;IAEb,IAAI,IAAI,CAAC,eAAe,IAAI,CAAC,SAAS;QAAE,OAAO,KAAK,CAAA;IAEpD,MAAM,UAAU,GAAG,CAAC,IAAI,CAAC,aAAa,IAAI,QAAQ,CAAC;SAChD,UAAU,CAAC,aAAa,EAAE,SAAS,IAAI,EAAE,CAAC;SAC1C,UAAU,CAAC,QAAQ,EAAE,OAAO,CAAC,OAAO,CAAC,CAAA;IAExC,OAAO,IAAI,CAAC;QACV,MAAM,EAAE,IAAI,CAAC,MAAM;QACnB,SAAS;QACT,UAAU;QACV,SAAS,EAAE,IAAI,CAAC,SAAS;QACzB,eAAe,EAAE,IAAI,CAAC,eAAe;QACrC,eAAe,EAAE,IAAI,CAAC,eAAe;QACrC,SAAS;QACT,kBAAkB,EAAE,IAAI,CAAC,kBAAkB;KAC5C,CAAC,CAAA;AACJ,CAAC"}
|
package/dist/hmac.d.ts
CHANGED
package/dist/hmac.d.ts.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"hmac.d.ts","sourceRoot":"","sources":["../src/hmac.ts"],"names":[],"mappings":"AAAA,cAAc,qBAAqB,CAAA;AACnC,cAAc,+BAA+B,CAAA"}
|
|
1
|
+
{"version":3,"file":"hmac.d.ts","sourceRoot":"","sources":["../src/hmac.ts"],"names":[],"mappings":"AAAA,cAAc,qBAAqB,CAAA;AACnC,cAAc,oBAAoB,CAAA;AAClC,cAAc,+BAA+B,CAAA"}
|
package/dist/hmac.js
CHANGED
package/dist/hmac.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"hmac.js","sourceRoot":"","sources":["../src/hmac.ts"],"names":[],"mappings":"AAAA,cAAc,qBAAqB,CAAA;AACnC,cAAc,+BAA+B,CAAA"}
|
|
1
|
+
{"version":3,"file":"hmac.js","sourceRoot":"","sources":["../src/hmac.ts"],"names":[],"mappings":"AAAA,cAAc,qBAAqB,CAAA;AACnC,cAAc,oBAAoB,CAAA;AAClC,cAAc,+BAA+B,CAAA"}
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@t4h.framework/hmac",
|
|
3
|
-
"version": "0.
|
|
3
|
+
"version": "0.3.0",
|
|
4
4
|
"description": "HMAC module for the T4H Framework authorization",
|
|
5
5
|
"homepage": "https://github.com/tech4humans-brasil/framework/tree/main/packages/hmac",
|
|
6
6
|
"bugs": "https://github.com/tech4humans-brasil/framework/issues",
|
|
@@ -20,6 +20,10 @@
|
|
|
20
20
|
"./authorize": {
|
|
21
21
|
"types": "./dist/hmac-authorize.d.ts",
|
|
22
22
|
"import": "./dist/hmac-authorize.js"
|
|
23
|
+
},
|
|
24
|
+
"./callback": {
|
|
25
|
+
"types": "./dist/hmac-callback.d.ts",
|
|
26
|
+
"import": "./dist/hmac-callback.js"
|
|
23
27
|
}
|
|
24
28
|
},
|
|
25
29
|
"module": "./dist/hmac.js",
|
|
@@ -37,12 +41,12 @@
|
|
|
37
41
|
"test:watch": "vitest"
|
|
38
42
|
},
|
|
39
43
|
"devDependencies": {
|
|
40
|
-
"@t4h.framework/core": "^0.
|
|
44
|
+
"@t4h.framework/core": "^0.13.0",
|
|
41
45
|
"typescript": "^5.9.3",
|
|
42
46
|
"vitest": "^4.0.18"
|
|
43
47
|
},
|
|
44
48
|
"peerDependencies": {
|
|
45
|
-
"@t4h.framework/core": "^0.
|
|
49
|
+
"@t4h.framework/core": "^0.13.0"
|
|
46
50
|
},
|
|
47
51
|
"packageManager": "yarn@4.12.0",
|
|
48
52
|
"engines": {
|