-
Notifications
You must be signed in to change notification settings - Fork 165
Expand file tree
/
Copy pathsupport.ts
More file actions
76 lines (70 loc) · 2.03 KB
/
support.ts
File metadata and controls
76 lines (70 loc) · 2.03 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
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
import { AgentResponseMessage, AppRequestMessage } from '@finos/fdc3-schema/dist/generated/api/BrowserTypes.js';
import { AppRegistration, ServerContext } from '../ServerContext.js';
import { AppIdentifier } from '@finos/fdc3-standard';
/** Interface representing a full specified app identifier (instanceId is optional in the API type). */
export interface FullAppIdentifier {
readonly appId: string;
readonly instanceId: string;
}
export function isFullAppIdentifier(identifier: AppIdentifier | FullAppIdentifier): identifier is FullAppIdentifier {
const typedIdentifier = identifier as FullAppIdentifier;
return typedIdentifier.instanceId !== undefined && typedIdentifier.appId !== undefined;
}
export function successResponse(
sc: ServerContext<AppRegistration>,
request: AppRequestMessage,
to: FullAppIdentifier,
payload: AgentResponseMessage['payload'],
type: AgentResponseMessage['type']
) {
return successResponseId(sc, request.meta.requestUuid, to, payload, type);
}
export function errorResponse(
sc: ServerContext<AppRegistration>,
request: AppRequestMessage,
to: FullAppIdentifier,
error: string,
type: AgentResponseMessage['type']
) {
return errorResponseId(sc, request.meta.requestUuid, to, error, type);
}
export function successResponseId(
sc: ServerContext<AppRegistration>,
requestId: string,
to: FullAppIdentifier,
payload: AgentResponseMessage['payload'],
type: AgentResponseMessage['type']
) {
const msg = {
meta: {
responseUuid: sc.createUUID(),
requestUuid: requestId,
timestamp: new Date(),
},
type,
payload,
};
sc.post(msg, to.instanceId!);
}
export function errorResponseId(
sc: ServerContext<AppRegistration>,
requestId: string,
to: FullAppIdentifier,
error: string,
type: AgentResponseMessage['type']
) {
sc.post(
{
meta: {
responseUuid: sc.createUUID(),
requestUuid: requestId,
timestamp: new Date(),
},
type,
payload: {
error,
},
} as AgentResponseMessage,
to.instanceId!
);
}