@openfin/cloud-interop-core-api 0.0.1-alpha.c459095 → 0.0.1-alpha.c4f1368

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 CHANGED
@@ -364,7 +364,7 @@ export declare type ConnectParameters = {
364
364
  /**
365
365
  * When JWT authentication is being used, this will be invoked just whenever a JWT token is required for a request
366
366
  */
367
- jwtRequestCallback: () => string | object;
367
+ jwtRequestCallback: () => string | object | Promise<string | object>;
368
368
  /**
369
369
  * The id of the service gateway JWT authentication definition to use
370
370
  *
package/index.cjs CHANGED
@@ -53,11 +53,11 @@ class EventController {
53
53
  const isErrorIntentResult = (result) => 'error' in result;
54
54
 
55
55
  const APP_ID_DELIM = '::';
56
- const getRequestHeaders = (connectionParameters) => {
56
+ const getRequestHeaders = async (connectionParameters) => {
57
57
  const headers = {};
58
58
  headers['Content-Type'] = 'application/json';
59
59
  if (connectionParameters.authenticationType === 'jwt' && connectionParameters.jwtAuthenticationParameters) {
60
- const tokenResult = connectionParameters.jwtAuthenticationParameters.jwtRequestCallback();
60
+ const tokenResult = await connectionParameters.jwtAuthenticationParameters.jwtRequestCallback();
61
61
  if (!tokenResult) {
62
62
  throw new Error('jwtRequestCallback must return a token');
63
63
  }
@@ -162,7 +162,7 @@ class IntentController {
162
162
  try {
163
163
  const startResponse = await fetch(`${this.#url}/api/intents/${this.#sessionDetails.sessionId}`, {
164
164
  method: 'POST',
165
- headers: getRequestHeaders(this.#connectionParams),
165
+ headers: await getRequestHeaders(this.#connectionParams),
166
166
  body: JSON.stringify({ findOptions }),
167
167
  });
168
168
  if (!startResponse.ok) {
@@ -207,7 +207,7 @@ class IntentController {
207
207
  }
208
208
  await fetch(`${this.#url}/api/intents/${this.#sessionDetails.sessionId}/${this.#discovery.id}`, {
209
209
  method: 'DELETE',
210
- headers: getRequestHeaders(this.#connectionParams),
210
+ headers: await getRequestHeaders(this.#connectionParams),
211
211
  })
212
212
  .then((deleteResponse) => {
213
213
  if (!deleteResponse.ok) {
@@ -228,7 +228,7 @@ class IntentController {
228
228
  }
229
229
  const postResponse = await fetch(`${this.#url}/api/intents/${this.#sessionDetails.sessionId}/sessions/${targetSessionId}`, {
230
230
  method: 'POST',
231
- headers: getRequestHeaders(this.#connectionParams),
231
+ headers: await getRequestHeaders(this.#connectionParams),
232
232
  body: JSON.stringify({ raiseOptions }),
233
233
  });
234
234
  if (!postResponse.ok) {
@@ -242,7 +242,7 @@ class IntentController {
242
242
  try {
243
243
  const reportResponse = await fetch(`${this.#url}/api/intents/${this.#sessionDetails.sessionId}/${discoveryId}`, {
244
244
  method: 'POST',
245
- headers: getRequestHeaders(this.#connectionParams),
245
+ headers: await getRequestHeaders(this.#connectionParams),
246
246
  body: JSON.stringify({ intents }),
247
247
  });
248
248
  if (reportResponse.ok) {
@@ -266,7 +266,7 @@ class IntentController {
266
266
  const { sessionId } = getSourceFromSession(this.#sessionDetails);
267
267
  const resultResponse = await fetch(`${this.#url}/api/intents/${initiatingSessionId}/result/${sessionId}`, {
268
268
  method: 'POST',
269
- headers: getRequestHeaders(this.#connectionParams),
269
+ headers: await getRequestHeaders(this.#connectionParams),
270
270
  body: JSON.stringify({ result }),
271
271
  });
272
272
  if (!resultResponse.ok) {
@@ -350,6 +350,7 @@ class CloudInteropAPI {
350
350
  #reconnectRetryLimit = 30;
351
351
  #keepAliveIntervalSeconds = 30;
352
352
  #logger = (level, message) => {
353
+ // eslint-disable-next-line security/detect-object-injection -- level is restricted to the LogLevel union
353
354
  console[level](message);
354
355
  };
355
356
  #reconnectRetries = 0;
@@ -385,7 +386,7 @@ class CloudInteropAPI {
385
386
  const { sourceId, platformId } = this.#connectionParams;
386
387
  const createSessionResponse = await fetch(`${this.#cloudInteropSettings.url}/api/sessions`, {
387
388
  method: 'POST',
388
- headers: getRequestHeaders(this.#connectionParams),
389
+ headers: await getRequestHeaders(this.#connectionParams),
389
390
  body: JSON.stringify({ sourceId: sourceId.trim(), platformId }),
390
391
  });
391
392
  if (!createSessionResponse.ok) {
@@ -423,6 +424,7 @@ class CloudInteropAPI {
423
424
  // TODO: Dynamic intent discovery
424
425
  // search for any ongoing discoveries in DB and fire report-intents on self
425
426
  this.#logger('log', `Cloud Interop successfully connected to ${this.#cloudInteropSettings.url}`);
427
+ // eslint-disable-next-line security-node/detect-unhandled-event-errors -- this callback handles MQTT error events
426
428
  this.#mqttClient.on('error', async (error) => {
427
429
  // We will receive errors for each failed reconnection attempt
428
430
  // We don't want to disconnect on these else we will never reconnect
@@ -515,7 +517,7 @@ class CloudInteropAPI {
515
517
  };
516
518
  const postResponse = await fetch(`${this.#cloudInteropSettings.url}/api/context-groups/${this.#sessionDetails.sessionId}/${contextGroup}`, {
517
519
  method: 'POST',
518
- headers: getRequestHeaders(this.#connectionParams),
520
+ headers: await getRequestHeaders(this.#connectionParams),
519
521
  body: JSON.stringify(payload),
520
522
  });
521
523
  if (!postResponse.ok) {
@@ -575,7 +577,7 @@ class CloudInteropAPI {
575
577
  }
576
578
  const disconnectResponse = await fetch(`${this.#cloudInteropSettings.url}/api/sessions/${this.#sessionDetails.sessionId}`, {
577
579
  method: 'DELETE',
578
- headers: getRequestHeaders(this.#connectionParams),
580
+ headers: await getRequestHeaders(this.#connectionParams),
579
581
  });
580
582
  if (disconnectResponse.status !== 200) {
581
583
  throw new CloudInteropAPIError('Error during session tear down - unexpected status', 'ERR_DISCONNECT', new Error(disconnectResponse.statusText));
package/index.mjs CHANGED
@@ -51,11 +51,11 @@ class EventController {
51
51
  const isErrorIntentResult = (result) => 'error' in result;
52
52
 
53
53
  const APP_ID_DELIM = '::';
54
- const getRequestHeaders = (connectionParameters) => {
54
+ const getRequestHeaders = async (connectionParameters) => {
55
55
  const headers = {};
56
56
  headers['Content-Type'] = 'application/json';
57
57
  if (connectionParameters.authenticationType === 'jwt' && connectionParameters.jwtAuthenticationParameters) {
58
- const tokenResult = connectionParameters.jwtAuthenticationParameters.jwtRequestCallback();
58
+ const tokenResult = await connectionParameters.jwtAuthenticationParameters.jwtRequestCallback();
59
59
  if (!tokenResult) {
60
60
  throw new Error('jwtRequestCallback must return a token');
61
61
  }
@@ -160,7 +160,7 @@ class IntentController {
160
160
  try {
161
161
  const startResponse = await fetch(`${this.#url}/api/intents/${this.#sessionDetails.sessionId}`, {
162
162
  method: 'POST',
163
- headers: getRequestHeaders(this.#connectionParams),
163
+ headers: await getRequestHeaders(this.#connectionParams),
164
164
  body: JSON.stringify({ findOptions }),
165
165
  });
166
166
  if (!startResponse.ok) {
@@ -205,7 +205,7 @@ class IntentController {
205
205
  }
206
206
  await fetch(`${this.#url}/api/intents/${this.#sessionDetails.sessionId}/${this.#discovery.id}`, {
207
207
  method: 'DELETE',
208
- headers: getRequestHeaders(this.#connectionParams),
208
+ headers: await getRequestHeaders(this.#connectionParams),
209
209
  })
210
210
  .then((deleteResponse) => {
211
211
  if (!deleteResponse.ok) {
@@ -226,7 +226,7 @@ class IntentController {
226
226
  }
227
227
  const postResponse = await fetch(`${this.#url}/api/intents/${this.#sessionDetails.sessionId}/sessions/${targetSessionId}`, {
228
228
  method: 'POST',
229
- headers: getRequestHeaders(this.#connectionParams),
229
+ headers: await getRequestHeaders(this.#connectionParams),
230
230
  body: JSON.stringify({ raiseOptions }),
231
231
  });
232
232
  if (!postResponse.ok) {
@@ -240,7 +240,7 @@ class IntentController {
240
240
  try {
241
241
  const reportResponse = await fetch(`${this.#url}/api/intents/${this.#sessionDetails.sessionId}/${discoveryId}`, {
242
242
  method: 'POST',
243
- headers: getRequestHeaders(this.#connectionParams),
243
+ headers: await getRequestHeaders(this.#connectionParams),
244
244
  body: JSON.stringify({ intents }),
245
245
  });
246
246
  if (reportResponse.ok) {
@@ -264,7 +264,7 @@ class IntentController {
264
264
  const { sessionId } = getSourceFromSession(this.#sessionDetails);
265
265
  const resultResponse = await fetch(`${this.#url}/api/intents/${initiatingSessionId}/result/${sessionId}`, {
266
266
  method: 'POST',
267
- headers: getRequestHeaders(this.#connectionParams),
267
+ headers: await getRequestHeaders(this.#connectionParams),
268
268
  body: JSON.stringify({ result }),
269
269
  });
270
270
  if (!resultResponse.ok) {
@@ -348,6 +348,7 @@ class CloudInteropAPI {
348
348
  #reconnectRetryLimit = 30;
349
349
  #keepAliveIntervalSeconds = 30;
350
350
  #logger = (level, message) => {
351
+ // eslint-disable-next-line security/detect-object-injection -- level is restricted to the LogLevel union
351
352
  console[level](message);
352
353
  };
353
354
  #reconnectRetries = 0;
@@ -383,7 +384,7 @@ class CloudInteropAPI {
383
384
  const { sourceId, platformId } = this.#connectionParams;
384
385
  const createSessionResponse = await fetch(`${this.#cloudInteropSettings.url}/api/sessions`, {
385
386
  method: 'POST',
386
- headers: getRequestHeaders(this.#connectionParams),
387
+ headers: await getRequestHeaders(this.#connectionParams),
387
388
  body: JSON.stringify({ sourceId: sourceId.trim(), platformId }),
388
389
  });
389
390
  if (!createSessionResponse.ok) {
@@ -421,6 +422,7 @@ class CloudInteropAPI {
421
422
  // TODO: Dynamic intent discovery
422
423
  // search for any ongoing discoveries in DB and fire report-intents on self
423
424
  this.#logger('log', `Cloud Interop successfully connected to ${this.#cloudInteropSettings.url}`);
425
+ // eslint-disable-next-line security-node/detect-unhandled-event-errors -- this callback handles MQTT error events
424
426
  this.#mqttClient.on('error', async (error) => {
425
427
  // We will receive errors for each failed reconnection attempt
426
428
  // We don't want to disconnect on these else we will never reconnect
@@ -513,7 +515,7 @@ class CloudInteropAPI {
513
515
  };
514
516
  const postResponse = await fetch(`${this.#cloudInteropSettings.url}/api/context-groups/${this.#sessionDetails.sessionId}/${contextGroup}`, {
515
517
  method: 'POST',
516
- headers: getRequestHeaders(this.#connectionParams),
518
+ headers: await getRequestHeaders(this.#connectionParams),
517
519
  body: JSON.stringify(payload),
518
520
  });
519
521
  if (!postResponse.ok) {
@@ -573,7 +575,7 @@ class CloudInteropAPI {
573
575
  }
574
576
  const disconnectResponse = await fetch(`${this.#cloudInteropSettings.url}/api/sessions/${this.#sessionDetails.sessionId}`, {
575
577
  method: 'DELETE',
576
- headers: getRequestHeaders(this.#connectionParams),
578
+ headers: await getRequestHeaders(this.#connectionParams),
577
579
  });
578
580
  if (disconnectResponse.status !== 200) {
579
581
  throw new CloudInteropAPIError('Error during session tear down - unexpected status', 'ERR_DISCONNECT', new Error(disconnectResponse.statusText));
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@openfin/cloud-interop-core-api",
3
- "version": "0.0.1-alpha.c459095",
3
+ "version": "0.0.1-alpha.c4f1368",
4
4
  "description": "",
5
5
  "type": "module",
6
6
  "main": "./index.cjs",
@@ -9,7 +9,7 @@
9
9
  "author": "support@here.io",
10
10
  "license": "SEE LICENSE IN LICENSE.md",
11
11
  "dependencies": {
12
- "mqtt": "^5.15.1",
12
+ "mqtt": "catalog:",
13
13
  "zod": "catalog:"
14
14
  }
15
15
  }