@peektravel/app-utilities 0.7.0 → 0.7.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 +6 -3
- package/dist/index.cjs +10 -4
- package/dist/index.cjs.map +1 -1
- package/dist/index.d.cts +10 -5
- package/dist/index.d.ts +10 -5
- package/dist/index.js +10 -4
- package/dist/index.js.map +1 -1
- package/docs/webhooks.md +9 -5
- package/llms.txt +5 -3
- package/package.json +1 -1
package/README.md
CHANGED
|
@@ -276,8 +276,9 @@ app.post("/waiver-webhook", (req, res) => {
|
|
|
276
276
|
app.post("/install-webhook", async (req, res) => {
|
|
277
277
|
let event: InstallWebhook;
|
|
278
278
|
try {
|
|
279
|
-
//
|
|
280
|
-
|
|
279
|
+
// Token rides in the `x-peek-auth` header (a `Bearer ` prefix is stripped for you):
|
|
280
|
+
const token = req.header("x-peek-auth") ?? "";
|
|
281
|
+
event = parseInstallWebhook(token, req.body, process.env.PEEK_INTERNAL_SECRET!);
|
|
281
282
|
} catch {
|
|
282
283
|
return res.sendStatus(401); // bad signature / issuer / audience / expired
|
|
283
284
|
}
|
|
@@ -301,7 +302,9 @@ is the receiver's job**. `parseWaiverWebhook` also takes an optional
|
|
|
301
302
|
below.
|
|
302
303
|
|
|
303
304
|
`parseInstallWebhook(token, body, secret)` is different: the delivery carries a
|
|
304
|
-
signed `app_registry_v2` JWT plus a JSON body.
|
|
305
|
+
signed `app_registry_v2` JWT plus a JSON body. Peek sends the token in the
|
|
306
|
+
`x-peek-auth` header — pass that value straight in (`token` accepts it with or
|
|
307
|
+
without a `Bearer ` prefix). It validates the HMAC signature,
|
|
305
308
|
expiry, issuer, and `"Joken"` audience (the same checks as `verifyPeekAuthToken`,
|
|
306
309
|
throwing the underlying `jsonwebtoken` error — or `InvalidPeekTokenError` when a
|
|
307
310
|
present `user` block has no `id`), then returns one flat, JSON-safe
|
package/dist/index.cjs
CHANGED
|
@@ -2061,8 +2061,13 @@ var GraphQLClient = class {
|
|
|
2061
2061
|
};
|
|
2062
2062
|
var PEEK_TOKEN_ISSUER = "app_registry_v2";
|
|
2063
2063
|
var PEEK_TOKEN_AUDIENCE = "Joken";
|
|
2064
|
+
var BEARER_PREFIX = "bearer ";
|
|
2065
|
+
function stripBearer(token) {
|
|
2066
|
+
const trimmed = token.trim();
|
|
2067
|
+
return trimmed.toLowerCase().startsWith(BEARER_PREFIX) ? trimmed.slice(BEARER_PREFIX.length).trim() : trimmed;
|
|
2068
|
+
}
|
|
2064
2069
|
function verifyPeekJwt(token, secret) {
|
|
2065
|
-
return jwt__namespace.verify(token, secret, {
|
|
2070
|
+
return jwt__namespace.verify(stripBearer(token), secret, {
|
|
2066
2071
|
issuer: PEEK_TOKEN_ISSUER,
|
|
2067
2072
|
audience: PEEK_TOKEN_AUDIENCE
|
|
2068
2073
|
});
|
|
@@ -3586,9 +3591,10 @@ var PeekAccessService = class {
|
|
|
3586
3591
|
* decoded claims.
|
|
3587
3592
|
*
|
|
3588
3593
|
* Validates the HMAC signature (using this service's `jwtSecret`), the token
|
|
3589
|
-
* expiry, the `"app_registry_v2"` issuer, and the `"Joken"` audience.
|
|
3590
|
-
*
|
|
3591
|
-
*
|
|
3594
|
+
* expiry, the `"app_registry_v2"` issuer, and the `"Joken"` audience. Pass the
|
|
3595
|
+
* raw `x-peek-auth` request header value — a leading `Bearer ` prefix, if
|
|
3596
|
+
* present, is stripped for you. Throws from the `jsonwebtoken` library on any
|
|
3597
|
+
* failure — callers should catch to distinguish error kinds:
|
|
3592
3598
|
*
|
|
3593
3599
|
* - `JsonWebTokenError` — signature invalid, wrong issuer/audience, or token
|
|
3594
3600
|
* malformed
|