@openfin/cloud-interop-core-api 0.0.1-alpha.99f112a → 0.0.1-alpha.a27677b
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/bundle.d.ts +1 -1
- package/index.cjs +22 -12
- package/index.mjs +22 -12
- package/package.json +1 -1
package/bundle.d.ts
CHANGED
|
@@ -268,7 +268,7 @@ export declare class CloudInteropAPI {
|
|
|
268
268
|
* @returns {*} {Promise<void>}
|
|
269
269
|
* @memberof CloudInteropAPI
|
|
270
270
|
*/
|
|
271
|
-
setContext(contextGroup: string, context:
|
|
271
|
+
setContext(contextGroup: string, context: InferredContext): Promise<void>;
|
|
272
272
|
/**
|
|
273
273
|
* Starts an intent discovery operation
|
|
274
274
|
*
|
package/index.cjs
CHANGED
|
@@ -162,13 +162,18 @@ class IntentController {
|
|
|
162
162
|
body: JSON.stringify({ findOptions }),
|
|
163
163
|
});
|
|
164
164
|
if (!startResponse.ok) {
|
|
165
|
-
throw new Error(startResponse.statusText);
|
|
165
|
+
throw new Error(`Error creating intent discovery record: ${startResponse.statusText}`);
|
|
166
166
|
}
|
|
167
167
|
// TODO: type this response?
|
|
168
168
|
const json = await startResponse.json();
|
|
169
169
|
this.#discovery.id = json.discoveryId;
|
|
170
170
|
this.#discovery.sessionCount = json.sessionCount;
|
|
171
171
|
this.#discovery.state = 'in-progress';
|
|
172
|
+
if (this.#discovery.sessionCount === 1) {
|
|
173
|
+
// since we have no other connected sessions, we can end discovery immediately
|
|
174
|
+
await this.#endIntentDiscovery(false);
|
|
175
|
+
return;
|
|
176
|
+
}
|
|
172
177
|
// Listen out for discovery results directly sent to us
|
|
173
178
|
await this.#mqttClient.subscribeAsync(`${this.#sessionDetails.sessionRootTopic}/commands/${this.#discovery.id}`);
|
|
174
179
|
this.#discoveryTimeout = setTimeout(() => this.#endIntentDiscovery(), clampedTimeout);
|
|
@@ -179,10 +184,8 @@ class IntentController {
|
|
|
179
184
|
throw new CloudInteropAPIError('Error starting intent discovery', 'ERR_STARTING_INTENT_DISCOVERY', error);
|
|
180
185
|
}
|
|
181
186
|
}
|
|
182
|
-
async #endIntentDiscovery() {
|
|
187
|
+
async #endIntentDiscovery(mqttUnsubscribe = true) {
|
|
183
188
|
if (this.#discovery.state !== 'in-progress') {
|
|
184
|
-
// TODO: remove debug logs
|
|
185
|
-
this.#logger('debug', 'Intent discovery not in progress');
|
|
186
189
|
return;
|
|
187
190
|
}
|
|
188
191
|
if (this.#discoveryTimeout) {
|
|
@@ -192,10 +195,12 @@ class IntentController {
|
|
|
192
195
|
this.#discovery.state = 'ended';
|
|
193
196
|
// emit our aggregated events
|
|
194
197
|
this.#events.emitEvent('aggregate-intent-details', { responses: this.#discovery.pendingIntentDetailsEvents });
|
|
195
|
-
|
|
196
|
-
|
|
197
|
-
this.#
|
|
198
|
-
|
|
198
|
+
if (mqttUnsubscribe) {
|
|
199
|
+
// gracefully end discovery
|
|
200
|
+
await this.#mqttClient.unsubscribeAsync(`${this.#sessionDetails.sessionRootTopic}/commands/${this.#discovery.id}`).catch(() => {
|
|
201
|
+
this.#logger('warn', `Error ending intent discovery: could not unsubscribe from discovery id ${this.#discovery.id}`);
|
|
202
|
+
});
|
|
203
|
+
}
|
|
199
204
|
await fetch(`${this.#url}/api/intents/${this.#sessionDetails.sessionId}/${this.#discovery.id}`, {
|
|
200
205
|
method: 'DELETE',
|
|
201
206
|
headers: getRequestHeaders(this.#connectionParams),
|
|
@@ -204,7 +209,6 @@ class IntentController {
|
|
|
204
209
|
if (!deleteResponse.ok) {
|
|
205
210
|
throw new Error(`Error ending intent discovery: ${deleteResponse.statusText}`);
|
|
206
211
|
}
|
|
207
|
-
this.#logger('debug', 'Intent discovery ended');
|
|
208
212
|
})
|
|
209
213
|
.catch((error) => {
|
|
210
214
|
this.#logger('warn', `Error ending intent discovery: ${error}`);
|
|
@@ -249,7 +253,8 @@ class IntentController {
|
|
|
249
253
|
}
|
|
250
254
|
async sendIntentResult(initiatingSessionId, result) {
|
|
251
255
|
if (!isErrorIntentResult(result)) {
|
|
252
|
-
// cloud-encode the source app id
|
|
256
|
+
// cloud-encode the source app id to support chained intent actions over cloud
|
|
257
|
+
// https://fdc3.finos.org/docs/2.0/api/spec#resolution-object -> "Use metadata about the resolving app instance to target a further intent"
|
|
253
258
|
const source = getSourceFromSession(this.#sessionDetails);
|
|
254
259
|
const encoded = encodeAppId(typeof result.source === 'string' ? result.source : result.source.appId, source);
|
|
255
260
|
result.source = typeof result.source === 'string' ? encoded : { ...result.source, appId: encoded };
|
|
@@ -590,8 +595,13 @@ class CloudInteropAPI {
|
|
|
590
595
|
if (contextEvent.source.sessionId === sessionDetails.sessionId) {
|
|
591
596
|
return;
|
|
592
597
|
}
|
|
593
|
-
const { contextGroup,
|
|
594
|
-
this.#events.emitEvent('context', {
|
|
598
|
+
const { context, payload, contextGroup, channelName, source, history } = contextEvent;
|
|
599
|
+
this.#events.emitEvent('context', {
|
|
600
|
+
contextGroup: channelName || contextGroup,
|
|
601
|
+
context: payload || context,
|
|
602
|
+
source,
|
|
603
|
+
history: { ...history, clientReceived: Date.now() },
|
|
604
|
+
});
|
|
595
605
|
}
|
|
596
606
|
else if (topic.startsWith(`${sessionDetails.sessionRootTopic}/commands`)) {
|
|
597
607
|
this.#handleCommandMessage(messageEnvelope);
|
package/index.mjs
CHANGED
|
@@ -160,13 +160,18 @@ class IntentController {
|
|
|
160
160
|
body: JSON.stringify({ findOptions }),
|
|
161
161
|
});
|
|
162
162
|
if (!startResponse.ok) {
|
|
163
|
-
throw new Error(startResponse.statusText);
|
|
163
|
+
throw new Error(`Error creating intent discovery record: ${startResponse.statusText}`);
|
|
164
164
|
}
|
|
165
165
|
// TODO: type this response?
|
|
166
166
|
const json = await startResponse.json();
|
|
167
167
|
this.#discovery.id = json.discoveryId;
|
|
168
168
|
this.#discovery.sessionCount = json.sessionCount;
|
|
169
169
|
this.#discovery.state = 'in-progress';
|
|
170
|
+
if (this.#discovery.sessionCount === 1) {
|
|
171
|
+
// since we have no other connected sessions, we can end discovery immediately
|
|
172
|
+
await this.#endIntentDiscovery(false);
|
|
173
|
+
return;
|
|
174
|
+
}
|
|
170
175
|
// Listen out for discovery results directly sent to us
|
|
171
176
|
await this.#mqttClient.subscribeAsync(`${this.#sessionDetails.sessionRootTopic}/commands/${this.#discovery.id}`);
|
|
172
177
|
this.#discoveryTimeout = setTimeout(() => this.#endIntentDiscovery(), clampedTimeout);
|
|
@@ -177,10 +182,8 @@ class IntentController {
|
|
|
177
182
|
throw new CloudInteropAPIError('Error starting intent discovery', 'ERR_STARTING_INTENT_DISCOVERY', error);
|
|
178
183
|
}
|
|
179
184
|
}
|
|
180
|
-
async #endIntentDiscovery() {
|
|
185
|
+
async #endIntentDiscovery(mqttUnsubscribe = true) {
|
|
181
186
|
if (this.#discovery.state !== 'in-progress') {
|
|
182
|
-
// TODO: remove debug logs
|
|
183
|
-
this.#logger('debug', 'Intent discovery not in progress');
|
|
184
187
|
return;
|
|
185
188
|
}
|
|
186
189
|
if (this.#discoveryTimeout) {
|
|
@@ -190,10 +193,12 @@ class IntentController {
|
|
|
190
193
|
this.#discovery.state = 'ended';
|
|
191
194
|
// emit our aggregated events
|
|
192
195
|
this.#events.emitEvent('aggregate-intent-details', { responses: this.#discovery.pendingIntentDetailsEvents });
|
|
193
|
-
|
|
194
|
-
|
|
195
|
-
this.#
|
|
196
|
-
|
|
196
|
+
if (mqttUnsubscribe) {
|
|
197
|
+
// gracefully end discovery
|
|
198
|
+
await this.#mqttClient.unsubscribeAsync(`${this.#sessionDetails.sessionRootTopic}/commands/${this.#discovery.id}`).catch(() => {
|
|
199
|
+
this.#logger('warn', `Error ending intent discovery: could not unsubscribe from discovery id ${this.#discovery.id}`);
|
|
200
|
+
});
|
|
201
|
+
}
|
|
197
202
|
await fetch(`${this.#url}/api/intents/${this.#sessionDetails.sessionId}/${this.#discovery.id}`, {
|
|
198
203
|
method: 'DELETE',
|
|
199
204
|
headers: getRequestHeaders(this.#connectionParams),
|
|
@@ -202,7 +207,6 @@ class IntentController {
|
|
|
202
207
|
if (!deleteResponse.ok) {
|
|
203
208
|
throw new Error(`Error ending intent discovery: ${deleteResponse.statusText}`);
|
|
204
209
|
}
|
|
205
|
-
this.#logger('debug', 'Intent discovery ended');
|
|
206
210
|
})
|
|
207
211
|
.catch((error) => {
|
|
208
212
|
this.#logger('warn', `Error ending intent discovery: ${error}`);
|
|
@@ -247,7 +251,8 @@ class IntentController {
|
|
|
247
251
|
}
|
|
248
252
|
async sendIntentResult(initiatingSessionId, result) {
|
|
249
253
|
if (!isErrorIntentResult(result)) {
|
|
250
|
-
// cloud-encode the source app id
|
|
254
|
+
// cloud-encode the source app id to support chained intent actions over cloud
|
|
255
|
+
// https://fdc3.finos.org/docs/2.0/api/spec#resolution-object -> "Use metadata about the resolving app instance to target a further intent"
|
|
251
256
|
const source = getSourceFromSession(this.#sessionDetails);
|
|
252
257
|
const encoded = encodeAppId(typeof result.source === 'string' ? result.source : result.source.appId, source);
|
|
253
258
|
result.source = typeof result.source === 'string' ? encoded : { ...result.source, appId: encoded };
|
|
@@ -588,8 +593,13 @@ class CloudInteropAPI {
|
|
|
588
593
|
if (contextEvent.source.sessionId === sessionDetails.sessionId) {
|
|
589
594
|
return;
|
|
590
595
|
}
|
|
591
|
-
const { contextGroup,
|
|
592
|
-
this.#events.emitEvent('context', {
|
|
596
|
+
const { context, payload, contextGroup, channelName, source, history } = contextEvent;
|
|
597
|
+
this.#events.emitEvent('context', {
|
|
598
|
+
contextGroup: channelName || contextGroup,
|
|
599
|
+
context: payload || context,
|
|
600
|
+
source,
|
|
601
|
+
history: { ...history, clientReceived: Date.now() },
|
|
602
|
+
});
|
|
593
603
|
}
|
|
594
604
|
else if (topic.startsWith(`${sessionDetails.sessionRootTopic}/commands`)) {
|
|
595
605
|
this.#handleCommandMessage(messageEnvelope);
|