@openfin/cloud-interop-core-api 0.0.1-alpha.01680d7 → 0.0.1-alpha.0179e6f
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 +16 -12
- package/index.mjs +16 -12
- package/package.json +2 -2
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
|
@@ -1,9 +1,11 @@
|
|
|
1
1
|
'use strict';
|
|
2
2
|
|
|
3
3
|
var buffer = require('buffer');
|
|
4
|
+
require('fs');
|
|
5
|
+
require('path');
|
|
4
6
|
var mqtt = require('mqtt');
|
|
5
7
|
|
|
6
|
-
var
|
|
8
|
+
var u=n=>{let e=n.replaceAll("-","+").replaceAll("_","/");return e.padEnd(e.length+(4-e.length%4)%4,"=")};
|
|
7
9
|
|
|
8
10
|
class CloudInteropAPIError extends Error {
|
|
9
11
|
code;
|
|
@@ -51,11 +53,11 @@ class EventController {
|
|
|
51
53
|
const isErrorIntentResult = (result) => 'error' in result;
|
|
52
54
|
|
|
53
55
|
const APP_ID_DELIM = '::';
|
|
54
|
-
const getRequestHeaders = (connectionParameters) => {
|
|
56
|
+
const getRequestHeaders = async (connectionParameters) => {
|
|
55
57
|
const headers = {};
|
|
56
58
|
headers['Content-Type'] = 'application/json';
|
|
57
59
|
if (connectionParameters.authenticationType === 'jwt' && connectionParameters.jwtAuthenticationParameters) {
|
|
58
|
-
const tokenResult = connectionParameters.jwtAuthenticationParameters.jwtRequestCallback();
|
|
60
|
+
const tokenResult = await connectionParameters.jwtAuthenticationParameters.jwtRequestCallback();
|
|
59
61
|
if (!tokenResult) {
|
|
60
62
|
throw new Error('jwtRequestCallback must return a token');
|
|
61
63
|
}
|
|
@@ -160,7 +162,7 @@ class IntentController {
|
|
|
160
162
|
try {
|
|
161
163
|
const startResponse = await fetch(`${this.#url}/api/intents/${this.#sessionDetails.sessionId}`, {
|
|
162
164
|
method: 'POST',
|
|
163
|
-
headers: getRequestHeaders(this.#connectionParams),
|
|
165
|
+
headers: await getRequestHeaders(this.#connectionParams),
|
|
164
166
|
body: JSON.stringify({ findOptions }),
|
|
165
167
|
});
|
|
166
168
|
if (!startResponse.ok) {
|
|
@@ -205,7 +207,7 @@ class IntentController {
|
|
|
205
207
|
}
|
|
206
208
|
await fetch(`${this.#url}/api/intents/${this.#sessionDetails.sessionId}/${this.#discovery.id}`, {
|
|
207
209
|
method: 'DELETE',
|
|
208
|
-
headers: getRequestHeaders(this.#connectionParams),
|
|
210
|
+
headers: await getRequestHeaders(this.#connectionParams),
|
|
209
211
|
})
|
|
210
212
|
.then((deleteResponse) => {
|
|
211
213
|
if (!deleteResponse.ok) {
|
|
@@ -226,7 +228,7 @@ class IntentController {
|
|
|
226
228
|
}
|
|
227
229
|
const postResponse = await fetch(`${this.#url}/api/intents/${this.#sessionDetails.sessionId}/sessions/${targetSessionId}`, {
|
|
228
230
|
method: 'POST',
|
|
229
|
-
headers: getRequestHeaders(this.#connectionParams),
|
|
231
|
+
headers: await getRequestHeaders(this.#connectionParams),
|
|
230
232
|
body: JSON.stringify({ raiseOptions }),
|
|
231
233
|
});
|
|
232
234
|
if (!postResponse.ok) {
|
|
@@ -240,7 +242,7 @@ class IntentController {
|
|
|
240
242
|
try {
|
|
241
243
|
const reportResponse = await fetch(`${this.#url}/api/intents/${this.#sessionDetails.sessionId}/${discoveryId}`, {
|
|
242
244
|
method: 'POST',
|
|
243
|
-
headers: getRequestHeaders(this.#connectionParams),
|
|
245
|
+
headers: await getRequestHeaders(this.#connectionParams),
|
|
244
246
|
body: JSON.stringify({ intents }),
|
|
245
247
|
});
|
|
246
248
|
if (reportResponse.ok) {
|
|
@@ -264,7 +266,7 @@ class IntentController {
|
|
|
264
266
|
const { sessionId } = getSourceFromSession(this.#sessionDetails);
|
|
265
267
|
const resultResponse = await fetch(`${this.#url}/api/intents/${initiatingSessionId}/result/${sessionId}`, {
|
|
266
268
|
method: 'POST',
|
|
267
|
-
headers: getRequestHeaders(this.#connectionParams),
|
|
269
|
+
headers: await getRequestHeaders(this.#connectionParams),
|
|
268
270
|
body: JSON.stringify({ result }),
|
|
269
271
|
});
|
|
270
272
|
if (!resultResponse.ok) {
|
|
@@ -348,6 +350,7 @@ class CloudInteropAPI {
|
|
|
348
350
|
#reconnectRetryLimit = 30;
|
|
349
351
|
#keepAliveIntervalSeconds = 30;
|
|
350
352
|
#logger = (level, message) => {
|
|
353
|
+
// eslint-disable-next-line security/detect-object-injection -- level is restricted to the LogLevel union
|
|
351
354
|
console[level](message);
|
|
352
355
|
};
|
|
353
356
|
#reconnectRetries = 0;
|
|
@@ -383,7 +386,7 @@ class CloudInteropAPI {
|
|
|
383
386
|
const { sourceId, platformId } = this.#connectionParams;
|
|
384
387
|
const createSessionResponse = await fetch(`${this.#cloudInteropSettings.url}/api/sessions`, {
|
|
385
388
|
method: 'POST',
|
|
386
|
-
headers: getRequestHeaders(this.#connectionParams),
|
|
389
|
+
headers: await getRequestHeaders(this.#connectionParams),
|
|
387
390
|
body: JSON.stringify({ sourceId: sourceId.trim(), platformId }),
|
|
388
391
|
});
|
|
389
392
|
if (!createSessionResponse.ok) {
|
|
@@ -421,6 +424,7 @@ class CloudInteropAPI {
|
|
|
421
424
|
// TODO: Dynamic intent discovery
|
|
422
425
|
// search for any ongoing discoveries in DB and fire report-intents on self
|
|
423
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
|
|
424
428
|
this.#mqttClient.on('error', async (error) => {
|
|
425
429
|
// We will receive errors for each failed reconnection attempt
|
|
426
430
|
// We don't want to disconnect on these else we will never reconnect
|
|
@@ -513,7 +517,7 @@ class CloudInteropAPI {
|
|
|
513
517
|
};
|
|
514
518
|
const postResponse = await fetch(`${this.#cloudInteropSettings.url}/api/context-groups/${this.#sessionDetails.sessionId}/${contextGroup}`, {
|
|
515
519
|
method: 'POST',
|
|
516
|
-
headers: getRequestHeaders(this.#connectionParams),
|
|
520
|
+
headers: await getRequestHeaders(this.#connectionParams),
|
|
517
521
|
body: JSON.stringify(payload),
|
|
518
522
|
});
|
|
519
523
|
if (!postResponse.ok) {
|
|
@@ -573,7 +577,7 @@ class CloudInteropAPI {
|
|
|
573
577
|
}
|
|
574
578
|
const disconnectResponse = await fetch(`${this.#cloudInteropSettings.url}/api/sessions/${this.#sessionDetails.sessionId}`, {
|
|
575
579
|
method: 'DELETE',
|
|
576
|
-
headers: getRequestHeaders(this.#connectionParams),
|
|
580
|
+
headers: await getRequestHeaders(this.#connectionParams),
|
|
577
581
|
});
|
|
578
582
|
if (disconnectResponse.status !== 200) {
|
|
579
583
|
throw new CloudInteropAPIError('Error during session tear down - unexpected status', 'ERR_DISCONNECT', new Error(disconnectResponse.statusText));
|
|
@@ -686,7 +690,7 @@ class CloudInteropAPI {
|
|
|
686
690
|
}
|
|
687
691
|
const payload = parts[1];
|
|
688
692
|
// Decode base64url encoded payload
|
|
689
|
-
const decodedBytes = buffer.Buffer.from(
|
|
693
|
+
const decodedBytes = buffer.Buffer.from(u(payload), 'base64');
|
|
690
694
|
const payloadJson = decodedBytes.toString('utf8');
|
|
691
695
|
// Parse JSON to get the exp claim
|
|
692
696
|
const claims = JSON.parse(payloadJson);
|
package/index.mjs
CHANGED
|
@@ -1,7 +1,9 @@
|
|
|
1
1
|
import { Buffer } from 'buffer';
|
|
2
|
+
import 'fs';
|
|
3
|
+
import 'path';
|
|
2
4
|
import mqtt from 'mqtt';
|
|
3
5
|
|
|
4
|
-
var
|
|
6
|
+
var u=n=>{let e=n.replaceAll("-","+").replaceAll("_","/");return e.padEnd(e.length+(4-e.length%4)%4,"=")};
|
|
5
7
|
|
|
6
8
|
class CloudInteropAPIError extends Error {
|
|
7
9
|
code;
|
|
@@ -49,11 +51,11 @@ class EventController {
|
|
|
49
51
|
const isErrorIntentResult = (result) => 'error' in result;
|
|
50
52
|
|
|
51
53
|
const APP_ID_DELIM = '::';
|
|
52
|
-
const getRequestHeaders = (connectionParameters) => {
|
|
54
|
+
const getRequestHeaders = async (connectionParameters) => {
|
|
53
55
|
const headers = {};
|
|
54
56
|
headers['Content-Type'] = 'application/json';
|
|
55
57
|
if (connectionParameters.authenticationType === 'jwt' && connectionParameters.jwtAuthenticationParameters) {
|
|
56
|
-
const tokenResult = connectionParameters.jwtAuthenticationParameters.jwtRequestCallback();
|
|
58
|
+
const tokenResult = await connectionParameters.jwtAuthenticationParameters.jwtRequestCallback();
|
|
57
59
|
if (!tokenResult) {
|
|
58
60
|
throw new Error('jwtRequestCallback must return a token');
|
|
59
61
|
}
|
|
@@ -158,7 +160,7 @@ class IntentController {
|
|
|
158
160
|
try {
|
|
159
161
|
const startResponse = await fetch(`${this.#url}/api/intents/${this.#sessionDetails.sessionId}`, {
|
|
160
162
|
method: 'POST',
|
|
161
|
-
headers: getRequestHeaders(this.#connectionParams),
|
|
163
|
+
headers: await getRequestHeaders(this.#connectionParams),
|
|
162
164
|
body: JSON.stringify({ findOptions }),
|
|
163
165
|
});
|
|
164
166
|
if (!startResponse.ok) {
|
|
@@ -203,7 +205,7 @@ class IntentController {
|
|
|
203
205
|
}
|
|
204
206
|
await fetch(`${this.#url}/api/intents/${this.#sessionDetails.sessionId}/${this.#discovery.id}`, {
|
|
205
207
|
method: 'DELETE',
|
|
206
|
-
headers: getRequestHeaders(this.#connectionParams),
|
|
208
|
+
headers: await getRequestHeaders(this.#connectionParams),
|
|
207
209
|
})
|
|
208
210
|
.then((deleteResponse) => {
|
|
209
211
|
if (!deleteResponse.ok) {
|
|
@@ -224,7 +226,7 @@ class IntentController {
|
|
|
224
226
|
}
|
|
225
227
|
const postResponse = await fetch(`${this.#url}/api/intents/${this.#sessionDetails.sessionId}/sessions/${targetSessionId}`, {
|
|
226
228
|
method: 'POST',
|
|
227
|
-
headers: getRequestHeaders(this.#connectionParams),
|
|
229
|
+
headers: await getRequestHeaders(this.#connectionParams),
|
|
228
230
|
body: JSON.stringify({ raiseOptions }),
|
|
229
231
|
});
|
|
230
232
|
if (!postResponse.ok) {
|
|
@@ -238,7 +240,7 @@ class IntentController {
|
|
|
238
240
|
try {
|
|
239
241
|
const reportResponse = await fetch(`${this.#url}/api/intents/${this.#sessionDetails.sessionId}/${discoveryId}`, {
|
|
240
242
|
method: 'POST',
|
|
241
|
-
headers: getRequestHeaders(this.#connectionParams),
|
|
243
|
+
headers: await getRequestHeaders(this.#connectionParams),
|
|
242
244
|
body: JSON.stringify({ intents }),
|
|
243
245
|
});
|
|
244
246
|
if (reportResponse.ok) {
|
|
@@ -262,7 +264,7 @@ class IntentController {
|
|
|
262
264
|
const { sessionId } = getSourceFromSession(this.#sessionDetails);
|
|
263
265
|
const resultResponse = await fetch(`${this.#url}/api/intents/${initiatingSessionId}/result/${sessionId}`, {
|
|
264
266
|
method: 'POST',
|
|
265
|
-
headers: getRequestHeaders(this.#connectionParams),
|
|
267
|
+
headers: await getRequestHeaders(this.#connectionParams),
|
|
266
268
|
body: JSON.stringify({ result }),
|
|
267
269
|
});
|
|
268
270
|
if (!resultResponse.ok) {
|
|
@@ -346,6 +348,7 @@ class CloudInteropAPI {
|
|
|
346
348
|
#reconnectRetryLimit = 30;
|
|
347
349
|
#keepAliveIntervalSeconds = 30;
|
|
348
350
|
#logger = (level, message) => {
|
|
351
|
+
// eslint-disable-next-line security/detect-object-injection -- level is restricted to the LogLevel union
|
|
349
352
|
console[level](message);
|
|
350
353
|
};
|
|
351
354
|
#reconnectRetries = 0;
|
|
@@ -381,7 +384,7 @@ class CloudInteropAPI {
|
|
|
381
384
|
const { sourceId, platformId } = this.#connectionParams;
|
|
382
385
|
const createSessionResponse = await fetch(`${this.#cloudInteropSettings.url}/api/sessions`, {
|
|
383
386
|
method: 'POST',
|
|
384
|
-
headers: getRequestHeaders(this.#connectionParams),
|
|
387
|
+
headers: await getRequestHeaders(this.#connectionParams),
|
|
385
388
|
body: JSON.stringify({ sourceId: sourceId.trim(), platformId }),
|
|
386
389
|
});
|
|
387
390
|
if (!createSessionResponse.ok) {
|
|
@@ -419,6 +422,7 @@ class CloudInteropAPI {
|
|
|
419
422
|
// TODO: Dynamic intent discovery
|
|
420
423
|
// search for any ongoing discoveries in DB and fire report-intents on self
|
|
421
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
|
|
422
426
|
this.#mqttClient.on('error', async (error) => {
|
|
423
427
|
// We will receive errors for each failed reconnection attempt
|
|
424
428
|
// We don't want to disconnect on these else we will never reconnect
|
|
@@ -511,7 +515,7 @@ class CloudInteropAPI {
|
|
|
511
515
|
};
|
|
512
516
|
const postResponse = await fetch(`${this.#cloudInteropSettings.url}/api/context-groups/${this.#sessionDetails.sessionId}/${contextGroup}`, {
|
|
513
517
|
method: 'POST',
|
|
514
|
-
headers: getRequestHeaders(this.#connectionParams),
|
|
518
|
+
headers: await getRequestHeaders(this.#connectionParams),
|
|
515
519
|
body: JSON.stringify(payload),
|
|
516
520
|
});
|
|
517
521
|
if (!postResponse.ok) {
|
|
@@ -571,7 +575,7 @@ class CloudInteropAPI {
|
|
|
571
575
|
}
|
|
572
576
|
const disconnectResponse = await fetch(`${this.#cloudInteropSettings.url}/api/sessions/${this.#sessionDetails.sessionId}`, {
|
|
573
577
|
method: 'DELETE',
|
|
574
|
-
headers: getRequestHeaders(this.#connectionParams),
|
|
578
|
+
headers: await getRequestHeaders(this.#connectionParams),
|
|
575
579
|
});
|
|
576
580
|
if (disconnectResponse.status !== 200) {
|
|
577
581
|
throw new CloudInteropAPIError('Error during session tear down - unexpected status', 'ERR_DISCONNECT', new Error(disconnectResponse.statusText));
|
|
@@ -684,7 +688,7 @@ class CloudInteropAPI {
|
|
|
684
688
|
}
|
|
685
689
|
const payload = parts[1];
|
|
686
690
|
// Decode base64url encoded payload
|
|
687
|
-
const decodedBytes = Buffer.from(
|
|
691
|
+
const decodedBytes = Buffer.from(u(payload), 'base64');
|
|
688
692
|
const payloadJson = decodedBytes.toString('utf8');
|
|
689
693
|
// Parse JSON to get the exp claim
|
|
690
694
|
const claims = JSON.parse(payloadJson);
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@openfin/cloud-interop-core-api",
|
|
3
|
-
"version": "0.0.1-alpha.
|
|
3
|
+
"version": "0.0.1-alpha.0179e6f",
|
|
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": "
|
|
12
|
+
"mqtt": "catalog:",
|
|
13
13
|
"zod": "catalog:"
|
|
14
14
|
}
|
|
15
15
|
}
|