@sokel-dev/plugin-sdk 0.3.0 → 0.4.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/README.md +61 -46
- package/README.zh-CN.md +95 -0
- package/dist/src/auth.d.ts +12 -8
- package/dist/src/auth.js +2 -9
- package/dist/src/auth.js.map +1 -1
- package/dist/src/contract.d.ts +13 -9
- package/dist/src/contract.js +8 -10
- package/dist/src/contract.js.map +1 -1
- package/dist/src/env.d.ts +1 -6
- package/dist/src/env.js +6 -3
- package/dist/src/env.js.map +1 -1
- package/dist/src/events.d.ts +32 -23
- package/dist/src/events.js +32 -31
- package/dist/src/events.js.map +1 -1
- package/dist/src/index.d.ts +4 -2
- package/dist/src/index.js +6 -2
- package/dist/src/index.js.map +1 -1
- package/dist/src/nats.d.ts +13 -15
- package/dist/src/nats.js +70 -54
- package/dist/src/nats.js.map +1 -1
- package/dist/src/plugin.d.ts +24 -19
- package/dist/src/plugin.js +42 -29
- package/dist/src/plugin.js.map +1 -1
- package/dist/src/runtime.d.ts +30 -23
- package/dist/src/runtime.js +28 -25
- package/dist/src/runtime.js.map +1 -1
- package/dist/src/webhook.d.ts +15 -10
- package/dist/src/webhook.js +8 -12
- package/dist/src/webhook.js.map +1 -1
- package/package.json +1 -1
package/dist/src/runtime.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"runtime.js","sourceRoot":"","sources":["../../src/runtime.ts"],"names":[],"mappings":"AAAA
|
|
1
|
+
{"version":3,"file":"runtime.js","sourceRoot":"","sources":["../../src/runtime.ts"],"names":[],"mappings":"AAAA,mCAAmC;AACnC,sCAAsC;AA6BtC,+FAA+F;AAC/F,qCAAqC;AACrC,MAAM,WAAW,GAA2B;IAC1C,MAAM,EAAE,WAAW,EAAE,OAAO,EAAE,YAAY,EAAE,MAAM,EAAE,kBAAkB,EAAE,MAAM,EAAE,iBAAiB;IACjG,MAAM,EAAE,YAAY,EAAE,MAAM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K,EAAE,IAAI,EAAE,IAAI,CAAC,MAAM,EAAE,IAAI,EAAE,CAAC;QAC/D,CAAC;QACD,OAAO,IAAI,CAAC,KAAK,CAAC,WAAW,CAAC,KAAK,EAAE,KAAK,EAAE,gBAAgB,CAAC,IAAI,CAAC,CAAC,CAAC;IACtE,CAAC;CACF"}
|
package/dist/src/webhook.d.ts
CHANGED
|
@@ -1,9 +1,12 @@
|
|
|
1
1
|
/**
|
|
2
|
-
*
|
|
2
|
+
* Webhooks relayed by the platform: upstream system -> platform /hooks/{token} -> a __webhook__
|
|
3
|
+
* frame lands here (protocol §7b).
|
|
3
4
|
*
|
|
4
|
-
* handler
|
|
5
|
-
*
|
|
6
|
-
*
|
|
5
|
+
* What the handler is responsible for: verifying the upstream signature using the secret in the
|
|
6
|
+
* credential (every vendor signs differently — the platform does not know the upstream, the plugin
|
|
7
|
+
* does), parsing the body, pushing typed events with ctx.trigger (which reuses the declared-event
|
|
8
|
+
* check and the platform's deduplication), and deciding the response (GitLab wants a 2xx, Feishu's
|
|
9
|
+
* URL verification wants the challenge echoed back).
|
|
7
10
|
*/
|
|
8
11
|
export interface WebhookFrame {
|
|
9
12
|
method?: string;
|
|
@@ -12,27 +15,29 @@ export interface WebhookFrame {
|
|
|
12
15
|
headers?: Record<string, string>;
|
|
13
16
|
body_b64?: string;
|
|
14
17
|
}
|
|
15
|
-
/**
|
|
18
|
+
/** One inbound webhook (the platform has already stripped Cookie and other platform-side headers). */
|
|
16
19
|
export declare class WebhookRequest {
|
|
17
20
|
readonly method: string;
|
|
18
21
|
readonly path: string;
|
|
19
22
|
readonly query: string;
|
|
20
23
|
readonly headers: Record<string, string>;
|
|
21
|
-
/** body
|
|
24
|
+
/** The body travels as base64 to keep the exact bytes: HMAC-style verification has to see them
|
|
25
|
+
* byte for byte, and re-encoding the JSON would break the signature. */
|
|
22
26
|
readonly body: Buffer;
|
|
23
27
|
constructor(frame: WebhookFrame);
|
|
24
|
-
/**
|
|
28
|
+
/** Case-insensitive header lookup (HTTP semantics: X-Gitlab-Event and x-gitlab-event both hit). */
|
|
25
29
|
header(name: string): string;
|
|
26
|
-
/** body
|
|
30
|
+
/** Parse the body as JSON. Throws on bad input: malformed JSON upstream should fail visibly. */
|
|
27
31
|
json<T = unknown>(): T;
|
|
28
32
|
}
|
|
29
|
-
/**
|
|
33
|
+
/** The reply sent back upstream. status=0 plus an error means the plugin failed to handle it (the
|
|
34
|
+
* platform translates that into a 5xx). */
|
|
30
35
|
export interface WebhookResponse {
|
|
31
36
|
status: number;
|
|
32
37
|
headers?: Record<string, string>;
|
|
33
38
|
body?: Buffer | string;
|
|
34
39
|
}
|
|
35
40
|
export declare function ok(): WebhookResponse;
|
|
36
|
-
/**
|
|
41
|
+
/** For the cases that must return a body (Feishu's URL-verification challenge, say). */
|
|
37
42
|
export declare function text(status: number, body: string): WebhookResponse;
|
|
38
43
|
export declare function responseFrame(resp: WebhookResponse, events: number): Record<string, unknown>;
|
package/dist/src/webhook.js
CHANGED
|
@@ -1,17 +1,13 @@
|
|
|
1
|
-
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
* handler 的职责:用凭证里的 secret 验上游签名(各家算法不同,平台不懂上游、插件懂)→
|
|
5
|
-
* 解析 body → ctx.trigger 推 typed 事件(走既有声明校验与平台去重)→ 返回响应
|
|
6
|
-
* (GitLab 要 2xx、飞书 URL 校验要回 challenge,由 handler 决定)。
|
|
7
|
-
*/
|
|
8
|
-
/** 一次入站 webhook(平台已剥掉 Cookie 等平台侧头)。 */
|
|
1
|
+
// Copyright 2026 The Sokel Authors
|
|
2
|
+
// SPDX-License-Identifier: Apache-2.0
|
|
3
|
+
/** One inbound webhook (the platform has already stripped Cookie and other platform-side headers). */
|
|
9
4
|
export class WebhookRequest {
|
|
10
5
|
method;
|
|
11
6
|
path;
|
|
12
7
|
query;
|
|
13
8
|
headers;
|
|
14
|
-
/** body
|
|
9
|
+
/** The body travels as base64 to keep the exact bytes: HMAC-style verification has to see them
|
|
10
|
+
* byte for byte, and re-encoding the JSON would break the signature. */
|
|
15
11
|
body;
|
|
16
12
|
constructor(frame) {
|
|
17
13
|
this.method = frame.method ?? "POST";
|
|
@@ -20,7 +16,7 @@ export class WebhookRequest {
|
|
|
20
16
|
this.headers = frame.headers ?? {};
|
|
21
17
|
this.body = Buffer.from(frame.body_b64 ?? "", "base64");
|
|
22
18
|
}
|
|
23
|
-
/**
|
|
19
|
+
/** Case-insensitive header lookup (HTTP semantics: X-Gitlab-Event and x-gitlab-event both hit). */
|
|
24
20
|
header(name) {
|
|
25
21
|
const lowered = name.toLowerCase();
|
|
26
22
|
for (const [k, v] of Object.entries(this.headers)) {
|
|
@@ -29,7 +25,7 @@ export class WebhookRequest {
|
|
|
29
25
|
}
|
|
30
26
|
return "";
|
|
31
27
|
}
|
|
32
|
-
/** body
|
|
28
|
+
/** Parse the body as JSON. Throws on bad input: malformed JSON upstream should fail visibly. */
|
|
33
29
|
json() {
|
|
34
30
|
return JSON.parse(this.body.toString("utf8"));
|
|
35
31
|
}
|
|
@@ -37,7 +33,7 @@ export class WebhookRequest {
|
|
|
37
33
|
export function ok() {
|
|
38
34
|
return { status: 200 };
|
|
39
35
|
}
|
|
40
|
-
/**
|
|
36
|
+
/** For the cases that must return a body (Feishu's URL-verification challenge, say). */
|
|
41
37
|
export function text(status, body) {
|
|
42
38
|
return { status, body };
|
|
43
39
|
}
|
package/dist/src/webhook.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"webhook.js","sourceRoot":"","sources":["../../src/webhook.ts"],"names":[],"mappings":"AAAA
|
|
1
|
+
{"version":3,"file":"webhook.js","sourceRoot":"","sources":["../../src/webhook.ts"],"names":[],"mappings":"AAAA,mCAAmC;AACnC,sCAAsC;AAqBtC,sGAAsG;AACtG,MAAM,OAAO,cAAc;IAChB,MAAM,CAAS;IACf,IAAI,CAAS;IACb,KAAK,CAAS;IACd,OAAO,CAAyB;IACzC;4EACwE;IAC/D,IAAI,CAAS;IAEtB,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AC,CAAC,CAAC,CAAC,MAAM,CAAC,IAAI,CAAC,IAAI,CAAC,IAAa,CAAC,CAAC;IACzF,OAAO;QACL,MAAM,EAAE,IAAI,CAAC,MAAM,IAAI,GAAG;QAC1B,OAAO,EAAE,IAAI,CAAC,OAAO,IAAI,IAAI;QAC7B,QAAQ,EAAE,IAAI,CAAC,QAAQ,CAAC,QAAQ,CAAC;QACjC,MAAM;KACP,CAAC;AACJ,CAAC"}
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@sokel-dev/plugin-sdk",
|
|
3
|
-
"version": "0.
|
|
3
|
+
"version": "0.4.0",
|
|
4
4
|
"description": "Sokel plugin SDK for Node.js — declare the contract in sokel.yaml, implement typed handlers.",
|
|
5
5
|
"license": "Apache-2.0",
|
|
6
6
|
"homepage": "https://github.com/sokel-dev/sokel-plugin-sdk/tree/main/sdk-node",
|