@layer-drone/protocol 0.0.6 → 0.0.7
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.d.mts +1 -0
- package/dist/index.d.ts +1 -0
- package/dist/index.js +9 -1
- package/dist/index.mjs +9 -1
- package/package.json +5 -2
- package/src/event/parser.ts +13 -3
package/dist/index.d.mts
CHANGED
|
@@ -1,6 +1,7 @@
|
|
|
1
1
|
import * as _hey_api_client_fetch from '@hey-api/client-fetch';
|
|
2
2
|
import { TDataShape, Options as Options$1, Client } from '@hey-api/client-fetch';
|
|
3
3
|
import { z } from 'zod';
|
|
4
|
+
import { Request } from 'express';
|
|
4
5
|
|
|
5
6
|
type GetProvenanceCryptoKeyResponse = {
|
|
6
7
|
KeyId: string;
|
package/dist/index.d.ts
CHANGED
|
@@ -1,6 +1,7 @@
|
|
|
1
1
|
import * as _hey_api_client_fetch from '@hey-api/client-fetch';
|
|
2
2
|
import { TDataShape, Options as Options$1, Client } from '@hey-api/client-fetch';
|
|
3
3
|
import { z } from 'zod';
|
|
4
|
+
import { Request } from 'express';
|
|
4
5
|
|
|
5
6
|
type GetProvenanceCryptoKeyResponse = {
|
|
6
7
|
KeyId: string;
|
package/dist/index.js
CHANGED
|
@@ -349,7 +349,7 @@ var Event = import_zod.z.union([
|
|
|
349
349
|
// src/event/parser.ts
|
|
350
350
|
var WEBHOOK_SECRET_HEADER = "X-Webhook-Secret";
|
|
351
351
|
function parseWebhookEvent(req, webhookSecret) {
|
|
352
|
-
const secret = req.headers
|
|
352
|
+
const secret = getSecretHeader(req.headers);
|
|
353
353
|
if (typeof secret !== "string") {
|
|
354
354
|
throw new Error("Webhook request signature is not a string");
|
|
355
355
|
}
|
|
@@ -362,6 +362,14 @@ function parseWebhookEvent(req, webhookSecret) {
|
|
|
362
362
|
return Event.parse(JSON.parse(req.body.toString("utf-8")));
|
|
363
363
|
}
|
|
364
364
|
__name(parseWebhookEvent, "parseWebhookEvent");
|
|
365
|
+
function getSecretHeader(headers) {
|
|
366
|
+
let value = headers[WEBHOOK_SECRET_HEADER] ?? headers[WEBHOOK_SECRET_HEADER.toLowerCase()];
|
|
367
|
+
if (Array.isArray(value)) {
|
|
368
|
+
value = value[0];
|
|
369
|
+
}
|
|
370
|
+
return value;
|
|
371
|
+
}
|
|
372
|
+
__name(getSecretHeader, "getSecretHeader");
|
|
365
373
|
// Annotate the CommonJS export names for ESM import in node:
|
|
366
374
|
0 && (module.exports = {
|
|
367
375
|
Event,
|
package/dist/index.mjs
CHANGED
|
@@ -303,7 +303,7 @@ var Event = z.union([
|
|
|
303
303
|
// src/event/parser.ts
|
|
304
304
|
var WEBHOOK_SECRET_HEADER = "X-Webhook-Secret";
|
|
305
305
|
function parseWebhookEvent(req, webhookSecret) {
|
|
306
|
-
const secret = req.headers
|
|
306
|
+
const secret = getSecretHeader(req.headers);
|
|
307
307
|
if (typeof secret !== "string") {
|
|
308
308
|
throw new Error("Webhook request signature is not a string");
|
|
309
309
|
}
|
|
@@ -316,6 +316,14 @@ function parseWebhookEvent(req, webhookSecret) {
|
|
|
316
316
|
return Event.parse(JSON.parse(req.body.toString("utf-8")));
|
|
317
317
|
}
|
|
318
318
|
__name(parseWebhookEvent, "parseWebhookEvent");
|
|
319
|
+
function getSecretHeader(headers) {
|
|
320
|
+
let value = headers[WEBHOOK_SECRET_HEADER] ?? headers[WEBHOOK_SECRET_HEADER.toLowerCase()];
|
|
321
|
+
if (Array.isArray(value)) {
|
|
322
|
+
value = value[0];
|
|
323
|
+
}
|
|
324
|
+
return value;
|
|
325
|
+
}
|
|
326
|
+
__name(getSecretHeader, "getSecretHeader");
|
|
319
327
|
export {
|
|
320
328
|
Event,
|
|
321
329
|
apiTokenControllerCreateToken,
|
package/package.json
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@layer-drone/protocol",
|
|
3
3
|
"description": "Layer Drone protocol SDK with typed API client and event parsing",
|
|
4
|
-
"version": "0.0.
|
|
4
|
+
"version": "0.0.7",
|
|
5
5
|
"license": "MIT",
|
|
6
6
|
"files": [
|
|
7
7
|
"dist",
|
|
@@ -17,7 +17,9 @@
|
|
|
17
17
|
},
|
|
18
18
|
"devDependencies": {
|
|
19
19
|
"@hey-api/openapi-ts": "^0.64.11",
|
|
20
|
+
"@types/express": "^4",
|
|
20
21
|
"@types/node": "^20.3.1",
|
|
22
|
+
"express": "^4",
|
|
21
23
|
"json-schema-to-zod": "^2.6.1",
|
|
22
24
|
"ts-loader": "^9.4.3",
|
|
23
25
|
"ts-node": "^10.9.2",
|
|
@@ -36,6 +38,7 @@
|
|
|
36
38
|
"lint": "eslint \"{src,apps,libs,test}/**/*.ts\"",
|
|
37
39
|
"generate-api": "openapi-ts",
|
|
38
40
|
"generate-event": "ts-node ./scripts/generate-event-type.ts",
|
|
39
|
-
"generate": "pnpm generate-api && pnpm generate-event && pnpm lint --fix && pnpm build"
|
|
41
|
+
"generate": "pnpm generate-api && pnpm generate-event && pnpm lint --fix && pnpm build",
|
|
42
|
+
"sonar": "sonar"
|
|
40
43
|
}
|
|
41
44
|
}
|
package/src/event/parser.ts
CHANGED
|
@@ -1,11 +1,11 @@
|
|
|
1
|
+
import type { Request } from "express";
|
|
2
|
+
|
|
1
3
|
import { Event } from "./types.gen";
|
|
2
4
|
|
|
3
5
|
const WEBHOOK_SECRET_HEADER = "X-Webhook-Secret";
|
|
4
6
|
|
|
5
7
|
export function parseWebhookEvent(req: Request, webhookSecret: string) {
|
|
6
|
-
const secret
|
|
7
|
-
req.headers[WEBHOOK_SECRET_HEADER] ||
|
|
8
|
-
req.headers[WEBHOOK_SECRET_HEADER.toLowerCase()];
|
|
8
|
+
const secret = getSecretHeader(req.headers);
|
|
9
9
|
if (typeof secret !== "string") {
|
|
10
10
|
throw new Error("Webhook request signature is not a string");
|
|
11
11
|
}
|
|
@@ -17,3 +17,13 @@ export function parseWebhookEvent(req: Request, webhookSecret: string) {
|
|
|
17
17
|
}
|
|
18
18
|
return Event.parse(JSON.parse(req.body.toString("utf-8")));
|
|
19
19
|
}
|
|
20
|
+
|
|
21
|
+
function getSecretHeader(headers: Request["headers"]) {
|
|
22
|
+
let value =
|
|
23
|
+
headers[WEBHOOK_SECRET_HEADER] ??
|
|
24
|
+
headers[WEBHOOK_SECRET_HEADER.toLowerCase()];
|
|
25
|
+
if (Array.isArray(value)) {
|
|
26
|
+
value = value[0];
|
|
27
|
+
}
|
|
28
|
+
return value;
|
|
29
|
+
}
|