-
Notifications
You must be signed in to change notification settings - Fork 164
Expand file tree
/
Copy pathDefaultAppSupport.ts
More file actions
127 lines (112 loc) · 3.76 KB
/
DefaultAppSupport.ts
File metadata and controls
127 lines (112 loc) · 3.76 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
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
114
115
116
117
118
119
120
121
122
123
124
125
126
127
import { AppIdentifier, AppMetadata, ImplementationMetadata, OpenError, ResolveError } from '@finos/fdc3-standard';
import { Context } from '@finos/fdc3-context';
import { AppSupport } from './AppSupport.js';
import { Messaging } from '../Messaging.js';
import {
FindInstancesRequest,
FindInstancesResponse,
GetAppMetadataRequest,
GetAppMetadataResponse,
GetInfoRequest,
GetInfoResponse,
OpenRequest,
OpenResponse,
} from '@finos/fdc3-schema/dist/generated/api/BrowserTypes.js';
import { throwIfUndefined } from '../util/throwIfUndefined.js';
import { Logger } from '../util/Logger.js';
export class DefaultAppSupport implements AppSupport {
readonly messaging: Messaging;
readonly messageExchangeTimeout: number;
readonly appLaunchTimeout: number;
constructor(messaging: Messaging, messageExchangeTimeout: number, appLaunchTimeout: number) {
this.messaging = messaging;
this.messageExchangeTimeout = messageExchangeTimeout;
this.appLaunchTimeout = appLaunchTimeout;
}
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',
this.messageExchangeTimeout
);
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',
this.messageExchangeTimeout
);
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', this.appLaunchTimeout);
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',
this.messageExchangeTimeout
);
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
Logger.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;
}
}
}