@openfin/cloud-interop-core-api 0.0.1-alpha.6d7b62b → 0.0.1-alpha.72529c1

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/dist/api.d.ts ADDED
@@ -0,0 +1,59 @@
1
+ import { AppIdentifier, AppIntent, IntentResult } from '@openfin/shared-utils';
2
+ import mqtt from 'mqtt';
3
+ import { CloudInteropSettings, ConnectParameters, CreateSessionResponse } from './interfaces/connect.interface';
4
+ import { EventMap, RaiseIntentAPIOptions, StartIntentDiscoveryOptions } from './interfaces';
5
+ /**
6
+ * Represents a single connection to a Cloud Interop service
7
+ *
8
+ * @export
9
+ * @class CloudInteropAPI
10
+ * @implements {Client}
11
+ */
12
+ export declare class CloudInteropAPI {
13
+ #private;
14
+ constructor(cloudInteropSettings: CloudInteropSettings);
15
+ get sessionDetails(): CreateSessionResponse | undefined;
16
+ get mqttClient(): mqtt.MqttClient | undefined;
17
+ /**
18
+ * Connects and creates a session on the Cloud Interop service
19
+ *
20
+ * @param {ConnectParameters} parameters - The parameters to use to connect
21
+ * @return {*} {Promise<void>}
22
+ * @memberof CloudInteropAPI
23
+ * @throws {CloudInteropAPIError} - If an error occurs during connection
24
+ * @throws {AuthorizationError} - If the connection is unauthorized
25
+ */
26
+ connect(parameters: ConnectParameters): Promise<void>;
27
+ /**
28
+ * Disconnects from the Cloud Interop service
29
+ *
30
+ * @return {*} {Promise<void>}
31
+ * @memberof CloudInteropAPI
32
+ * @throws {CloudInteropAPIError} - If an error occurs during disconnection
33
+ */
34
+ disconnect(): Promise<void>;
35
+ /**
36
+ * Publishes a new context for the given context group to the other connected sessions
37
+ *
38
+ * @param {string} contextGroup - The context group to publish to
39
+ * @param {object} context - The context to publish
40
+ * @return {*} {Promise<void>}
41
+ * @memberof CloudInteropAPI
42
+ */
43
+ setContext(contextGroup: string, context: object): Promise<void>;
44
+ /**
45
+ * Starts an intent discovery operation
46
+ *
47
+ * @return {*} {Promise<void>}
48
+ * @memberof CloudInteropAPI
49
+ * @throws {CloudInteropAPIError} - If an error occurs during intent discovery
50
+ */
51
+ startIntentDiscovery(options: StartIntentDiscoveryOptions): Promise<void>;
52
+ raiseIntent(options: RaiseIntentAPIOptions): Promise<void>;
53
+ reportAppIntents(discoveryId: string, intents: AppIntent[]): Promise<boolean>;
54
+ sendIntentResult(initiatingSessionId: string, result: IntentResult): Promise<void>;
55
+ parseSessionId(appId: AppIdentifier | string): string;
56
+ addEventListener<K extends keyof EventMap>(type: K, callback: EventMap[K]): void;
57
+ removeEventListener<K extends keyof EventMap>(type: K, callback: EventMap[K]): void;
58
+ once<K extends keyof EventMap>(type: K, callback: EventMap[K]): void;
59
+ }
@@ -0,0 +1,8 @@
1
+ import { EventMap } from '../interfaces';
2
+ export declare class EventController {
3
+ #private;
4
+ addEventListener<K extends keyof EventMap>(type: K, callback: EventMap[K]): void;
5
+ removeEventListener<K extends keyof EventMap>(type: K, callback: EventMap[K]): void;
6
+ once<K extends keyof EventMap>(type: K, callback: EventMap[K]): void;
7
+ emitEvent<K extends keyof EventMap>(type: K, ...args: Parameters<EventMap[K]>): void;
8
+ }
@@ -0,0 +1,2 @@
1
+ export * from './event.controller';
2
+ export * from './intent.controller';
@@ -0,0 +1,13 @@
1
+ import { AppIntent, CommandMessage, IntentResult } from '@openfin/shared-utils';
2
+ import mqtt from 'mqtt';
3
+ import { CloudInteropLogger, ConnectParameters, CreateSessionResponse, RaiseIntentAPIOptions, StartIntentDiscoveryOptions } from '../interfaces';
4
+ import { EventController } from './event.controller';
5
+ export declare class IntentController {
6
+ #private;
7
+ constructor(url: string, mqttClient: mqtt.MqttClient, sessionDetails: CreateSessionResponse, connectionParameters: ConnectParameters, events: EventController, logger: CloudInteropLogger);
8
+ startIntentDiscovery(options: StartIntentDiscoveryOptions): Promise<void>;
9
+ raiseIntent({ raiseOptions, appId }: RaiseIntentAPIOptions): Promise<void>;
10
+ reportAppIntents(discoveryId: string, intents: AppIntent[]): Promise<boolean>;
11
+ sendIntentResult(initiatingSessionId: string, result: IntentResult): Promise<void>;
12
+ handleCommandMessage(message: CommandMessage): void;
13
+ }
@@ -0,0 +1,7 @@
1
+ export declare class CloudInteropAPIError extends Error {
2
+ code: string;
3
+ constructor(message?: string, code?: string, cause?: unknown);
4
+ }
5
+ export declare class AuthorizationError extends CloudInteropAPIError {
6
+ constructor(message?: string, code?: string);
7
+ }
package/dist/index.cjs CHANGED
@@ -1,7 +1,7 @@
1
1
  'use strict';
2
2
 
3
- var buffer = require('buffer');
4
3
  var mqtt = require('mqtt');
4
+ var sharedUtils = require('@openfin/shared-utils');
5
5
 
6
6
  class CloudInteropAPIError extends Error {
7
7
  code;
@@ -57,11 +57,11 @@ const getRequestHeaders = (connectionParameters) => {
57
57
  }
58
58
  headers['x-of-auth-id'] = connectionParameters.jwtAuthenticationParameters.authenticationId;
59
59
  headers['Authorization'] =
60
- typeof tokenResult === 'string' ? `Bearer ${tokenResult}` : `Bearer ${buffer.Buffer.from(JSON.stringify(tokenResult)).toString('base64')}`;
60
+ typeof tokenResult === 'string' ? `Bearer ${tokenResult}` : `Bearer ${Buffer.from(JSON.stringify(tokenResult)).toString('base64')}`;
61
61
  }
62
62
  if (connectionParameters.authenticationType === 'basic' && connectionParameters.basicAuthenticationParameters) {
63
63
  const { username, password } = connectionParameters.basicAuthenticationParameters;
64
- headers['Authorization'] = `Basic ${buffer.Buffer.from(`${username}:${password}`).toString('base64')}`;
64
+ headers['Authorization'] = `Basic ${Buffer.from(`${username}:${password}`).toString('base64')}`;
65
65
  }
66
66
  return headers;
67
67
  };
@@ -379,7 +379,7 @@ class CloudInteropAPI {
379
379
  // The server can then tidy up. So it needs every for this client to do that, the session details is perfect
380
380
  will: {
381
381
  topic: 'interop/lastwill',
382
- payload: buffer.Buffer.from(JSON.stringify(this.#sessionDetails)),
382
+ payload: Buffer.from(JSON.stringify(this.#sessionDetails)),
383
383
  qos: 0,
384
384
  retain: false,
385
385
  },
@@ -628,3 +628,9 @@ class CloudInteropAPI {
628
628
  exports.AuthorizationError = AuthorizationError;
629
629
  exports.CloudInteropAPI = CloudInteropAPI;
630
630
  exports.CloudInteropAPIError = CloudInteropAPIError;
631
+ Object.keys(sharedUtils).forEach(function (k) {
632
+ if (k !== 'default' && !Object.prototype.hasOwnProperty.call(exports, k)) Object.defineProperty(exports, k, {
633
+ enumerable: true,
634
+ get: function () { return sharedUtils[k]; }
635
+ });
636
+ });
@@ -0,0 +1,6 @@
1
+ export * from './api';
2
+ export * from './errors/api.error';
3
+ export * from './interfaces/connect.interface';
4
+ export * from './interfaces/event.interface';
5
+ export * from './interfaces/intents.interface';
6
+ export * from '@openfin/shared-utils';