-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathcontract.ts
More file actions
37 lines (30 loc) · 1.21 KB
/
contract.ts
File metadata and controls
37 lines (30 loc) · 1.21 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
export type HookHandler = (ctx: HookContext, data: HookData<any>) => void | Promise<void>;
export interface HookContext {
notify(channel: string, message: string): void;
/** If the hook does't look anything like you expect,
* mark it unrelated so it can proceed to the next script. */
cancelAsUnrecognizable(message?: string): never;
/** If the hook is from the right place, but has an incorrect detail
* (bad signature, invalid field value) mark it as unprocessable.
* This will not be automatically retried. */
cancelAsMalformed(message?: string): never;
// Nice lil helpers.
shortenUrl(url: string): Promise<string>;
trimText(text: string, maxLen: number): string;
}
export interface HookData<T=JSONValue> {
sourceIp?: string;
hookFlavor: string;
hookId: string;
receivedAt: Date;
headers: Headers;
parameters: URLSearchParams;
payload: T;
payloadRaw: string; // for signature verification
payloadType: string;
}
// Structures that JSON can encode directly
export type JSONPrimitive = string | number | boolean | null | undefined;
export type JSONValue = JSONPrimitive | JSONObject | JSONArray;
export type JSONObject = {[key: string]: JSONValue};
export type JSONArray = JSONValue[];