-
Notifications
You must be signed in to change notification settings - Fork 135
/
Copy pathDefaultAppSupport.ts
113 lines (99 loc) · 3.36 KB
/
DefaultAppSupport.ts
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
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
import { AppIdentifier, AppMetadata, ImplementationMetadata, OpenError, ResolveError } from '@finos/fdc3-standard';
import { Context } from '@finos/fdc3-context';
import { AppSupport } from './AppSupport';
import { Messaging } from '../Messaging';
import {
FindInstancesRequest,
FindInstancesResponse,
GetAppMetadataRequest,
GetAppMetadataResponse,
GetInfoRequest,
GetInfoResponse,
OpenRequest,
OpenResponse,
} from '@finos/fdc3-schema/dist/generated/api/BrowserTypes';
import { throwIfUndefined } from '../util';
export class DefaultAppSupport implements AppSupport {
readonly messaging: Messaging;
constructor(messaging: Messaging) {
this.messaging = messaging;
}
async findInstances(app: AppIdentifier): Promise<AppIdentifier[]> {
const request: FindInstancesRequest = {
type: 'findInstancesRequest',
payload: {
app,
},
meta: this.messaging.createMeta(),
};
const out = await this.messaging.exchange<FindInstancesResponse>(request, 'findInstancesResponse');
return out.payload.appIdentifiers ?? [];
}
async getAppMetadata(app: AppIdentifier): Promise<AppMetadata> {
const request: GetAppMetadataRequest = {
type: 'getAppMetadataRequest',
payload: {
app: app as AppIdentifier,
},
meta: this.messaging.createMeta(),
};
const response = await this.messaging.exchange<GetAppMetadataResponse>(request, 'getAppMetadataResponse');
throwIfUndefined(
response.payload.appMetadata,
'Invalid response from Desktop Agent to getAppMetadata!',
response,
ResolveError.TargetAppUnavailable
);
return response.payload.appMetadata!;
}
async open(app: AppIdentifier, context?: Context | undefined): Promise<AppIdentifier> {
const request: OpenRequest = {
type: 'openRequest',
payload: {
app: {
appId: app.appId,
instanceId: app.instanceId,
},
context,
},
meta: this.messaging.createMeta(),
};
const response = await this.messaging.exchange<OpenResponse>(request, 'openResponse', OpenError.AppTimeout);
throwIfUndefined(
response.payload.appIdentifier,
'Invalid response from Desktop Agent to open!',
response,
OpenError.AppNotFound
);
return response.payload.appIdentifier!;
}
async getImplementationMetadata(): Promise<ImplementationMetadata> {
const request: GetInfoRequest = {
type: 'getInfoRequest',
payload: {},
meta: this.messaging.createMeta(),
};
const response = await this.messaging.exchange<GetInfoResponse>(
request,
'getInfoResponse',
'timed out waiting for getInfo response!'
);
if (response.payload.implementationMetadata) {
return response.payload.implementationMetadata;
} else {
//This will only happen if the DA implementation returns an invalid message with a missing implementationMetadata property
console.error('Invalid response from Desktop Agent to open!', response);
const unknownImpl: ImplementationMetadata = {
fdc3Version: 'unknown',
provider: 'unknown',
appMetadata: { appId: 'unknown', instanceId: 'unknown' },
optionalFeatures: {
OriginatingAppMetadata: false,
UserChannelMembershipAPIs: false,
DesktopAgentBridging: false,
},
};
return unknownImpl;
}
}
}