Skip to content

Commit 894487a

Browse files
authored
[feat] add sendFailedScreen to envoyResponse typing (#98)
* add sendFailedScreen to envoyResponse typing * update version to 2.4.1
1 parent ad5d9fc commit 894487a

File tree

7 files changed

+87
-7
lines changed

7 files changed

+87
-7
lines changed

docs/interfaces/envoyresponse.md

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -24,6 +24,7 @@ Use to type your `res` object in Envoy event handlers.
2424
- [sendFailed](envoyresponse.md#sendfailed)
2525
- [sendIgnored](envoyresponse.md#sendignored)
2626
- [sendOngoing](envoyresponse.md#sendongoing)
27+
- [sendFailedScreen](envoyresponse.md#sendFailedScreen)
2728

2829
## Properties
2930

@@ -61,6 +62,12 @@ ___
6162

6263
Marks the job as "failed". The message will be communicated to the Envoy Dashboard user.
6364

65+
### sendFailedScreen
66+
67+
**sendFailedScreen**: (`message`: `string`, `debugInfo?`: `unknown`, ...`attachments`: `EnvoyPluginScreenerJobAttachment`, ) => `void`
68+
69+
Halts processing of the job. The message will be communicated to the Envoy Dashboard user and a pop up modal for access approval will be displayed.
70+
6471
#### Type declaration
6572

6673
▸ (`message`, `debugInfo?`, ...`attachments`): `void`

package-lock.json

Lines changed: 1 addition & 1 deletion
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

package.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
{
22
"name": "@envoy/envoy-integrations-sdk",
3-
"version": "2.4.0",
3+
"version": "2.4.1",
44
"description": "SDK for building Envoy integrations.",
55
"main": "dist/index.js",
66
"types": "dist/index.d.ts",

src/sdk/EnvoyPluginJob.ts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -70,9 +70,9 @@ export default class EnvoyPluginJob {
7070
}
7171

7272
/**
73-
* Reports that the job is ignored.
73+
* Reports that the job is failed.
7474
*
75-
* Instead of calling this directly, you can return a 400 response from the job's event handler,
75+
* Instead of calling this directly, you can return a 412 response from the job's event handler,
7676
* using {@link EnvoyRequest.sendFailed}.
7777
*/
7878
fail(message: string, reason: string): Promise<void> {

src/sdk/EnvoyPluginJobAttachment.ts

Lines changed: 57 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,17 @@ export interface EnvoyPluginTextJobAttachment {
99
value: string;
1010
}
1111

12+
/**
13+
* Display some JSON data in Envoy's dashboard.
14+
*
15+
* @category Attachment
16+
*/
17+
export interface EnvoyPluginJSONJobAttachment {
18+
type: 'json';
19+
label: string;
20+
value: unknown;
21+
}
22+
1223
/**
1324
* Display a link in Envoy's dashboard.
1425
*
@@ -34,6 +45,50 @@ export interface EnvoyPluginCredentialJobAttachment extends EnvoyPluginTextJobAt
3445
};
3546
}
3647

48+
/**
49+
* Display a screener report in Envoy's dashboard,
50+
* and allow for approval or rejection.
51+
*
52+
* @category Attachment
53+
*/
54+
export interface EnvoyPluginScreenerJobAttachment extends EnvoyPluginJSONJobAttachment {
55+
label: string;
56+
value: ScreenerDetails;
57+
}
58+
59+
/**
60+
* Screener report definitions
61+
*/
62+
export interface ScreenerDetails {
63+
input: {
64+
fields: ScreenerInputField[];
65+
}
66+
matches: ScreenerMatch[];
67+
}
68+
69+
export interface ScreenerMatch {
70+
headers: ScreenerMatchHeaders;
71+
'visible-fields-count': number;
72+
fields: ScreenerMatchField[];
73+
}
74+
75+
export interface ScreenerMatchHeaders {
76+
name: string; // ex: Tags
77+
value: string; // ex: Content
78+
}
79+
80+
export interface ScreenerMatchField {
81+
name: string;
82+
value: string;
83+
type: 'text' | 'image';
84+
}
85+
86+
export interface ScreenerInputField {
87+
name: string;
88+
value: string;
89+
type: 'text' | 'image';
90+
}
91+
3792
/**
3893
* Attachments to jobs, which will be displayed in the Envoy dashboard.
3994
* Some attachments like `credential_image` can show up in other places,
@@ -44,6 +99,7 @@ export interface EnvoyPluginCredentialJobAttachment extends EnvoyPluginTextJobAt
4499
type EnvoyPluginJobAttachment =
45100
| EnvoyPluginTextJobAttachment
46101
| EnvoyPluginLinkJobAttachment
47-
| EnvoyPluginCredentialJobAttachment;
102+
| EnvoyPluginCredentialJobAttachment
103+
| EnvoyPluginScreenerJobAttachment;
48104

49105
export default EnvoyPluginJobAttachment;

src/sdk/EnvoyResponse.ts

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
import { Response } from 'express';
2-
import EnvoyPluginJobAttachment from './EnvoyPluginJobAttachment';
2+
import EnvoyPluginJobAttachment, { EnvoyPluginScreenerJobAttachment } from './EnvoyPluginJobAttachment';
33
import EnvoyOptionsRouteResponseBody from '../internal/EnvoyOptionsRouteResponseBody';
44
import EnvoySelectedValuesRouteResponseBody from '../internal/EnvoySelectedValuesRouteResponseBody';
55
import EnvoyRemoteValueRouteResponseBody from '../internal/EnvoyRemoteValueRouteResponseBody';
@@ -26,6 +26,10 @@ export default interface EnvoyResponse<Body = unknown> extends Response {
2626
* Marks the job as "failed". The message will be communicated to the Envoy Dashboard user.
2727
*/
2828
sendFailed: (message: string, debugInfo?: unknown, ...attachments: Array<EnvoyPluginJobAttachment>) => void;
29+
/**
30+
* Marks the job as "failed". The message will be communicated to the Envoy Dashboard user.
31+
*/
32+
sendFailedScreen: (message: string, debugInfo?: unknown, attachment?: EnvoyPluginScreenerJobAttachment) => void;
2933
}
3034

3135
/**

src/sdk/middleware.ts

Lines changed: 14 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@ import HttpStatus from '../internal/HttpStatus';
55
import EnvoySignatureVerifier, { EnvoySignatureVerifierOptions } from '../util/EnvoySignatureVerifier';
66
import EnvoyRequest, { VERIFIED, VerifiedRequest } from './EnvoyRequest';
77
import EnvoyResponse from './EnvoyResponse';
8-
import EnvoyPluginJobAttachment from './EnvoyPluginJobAttachment';
8+
import EnvoyPluginJobAttachment, { EnvoyPluginScreenerJobAttachment } from './EnvoyPluginJobAttachment';
99
import EnvoyPluginSDK from './EnvoyPluginSDK';
1010
import EnvoyPluginAPI from './EnvoyPluginAPI';
1111

@@ -77,6 +77,19 @@ export function envoyMiddleware(options?: EnvoySignatureVerifierOptions): Reques
7777
envoyResponse.setHeader('Content-Type', 'application/json');
7878
envoyResponse.end(JSON.stringify({ message, debugInfo, attachments }));
7979
};
80+
81+
/**
82+
* Respond with "failed" for screener in case of screener matches.
83+
*/
84+
envoyResponse.sendFailedScreen = (
85+
message = '',
86+
debugInfo: unknown = {},
87+
attachment?: EnvoyPluginScreenerJobAttachment,
88+
) => {
89+
envoyResponse.statusCode = HttpStatus.FAILED;
90+
envoyResponse.setHeader('Content-Type', 'application/json');
91+
envoyResponse.end(JSON.stringify({ message, debugInfo, attachment }));
92+
};
8093
next();
8194
} catch (error) {
8295
next(error);

0 commit comments

Comments
 (0)