@openfin/cloud-interop-core-api 0.0.1-alpha.9655dc9 → 0.0.1-alpha.97bca7d

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/src/api.d.ts DELETED
@@ -1,88 +0,0 @@
1
- import { EndReportIntentsEvent, Intent, IntentDetailsEvent, IntentResultEvent, InvokeIntentEvent, ReportIntentsEvent } from '@openfin-direct/shared-utils';
2
- import mqtt from 'mqtt';
3
- import { CloudInteropSettings, ConnectParameters, ContextEvent } from './interfaces';
4
- type CreateSessionResponse = {
5
- sessionId: string;
6
- sessionRootTopic: string;
7
- url: string;
8
- token: string;
9
- orgId: string;
10
- sub: string;
11
- platformId: string;
12
- sourceId: string;
13
- };
14
- type EventMap = {
15
- reconnected: () => void;
16
- disconnected: () => void;
17
- context: (event: ContextEvent) => void;
18
- reconnecting: (attemptNo: number) => void;
19
- error: (error: Error) => void;
20
- 'session-expired': () => void;
21
- 'report-intents': (event: ReportIntentsEvent) => void;
22
- 'end-report-intents': (event: EndReportIntentsEvent) => void;
23
- 'intent-details': (event: IntentDetailsEvent) => void;
24
- 'invoke-intent': (event: InvokeIntentEvent) => void;
25
- 'intent-result': (event: IntentResultEvent) => void;
26
- };
27
- /**
28
- * Represents a single connection to a Cloud Interop service
29
- *
30
- * @export
31
- * @class CloudInteropAPI
32
- * @implements {Client}
33
- */
34
- export declare class CloudInteropAPI {
35
- #private;
36
- constructor(cloudInteropSettings: CloudInteropSettings);
37
- get sessionDetails(): CreateSessionResponse | undefined;
38
- get mqttClient(): mqtt.MqttClient | undefined;
39
- /**
40
- * Connects and creates a session on the Cloud Interop service
41
- *
42
- * @param {ConnectParameters} parameters - The parameters to use to connect
43
- * @return {*} {Promise<void>}
44
- * @memberof CloudInteropAPI
45
- * @throws {CloudInteropAPIError} - If an error occurs during connection
46
- * @throws {AuthorizationError} - If the connection is unauthorized
47
- */
48
- connect(parameters: ConnectParameters): Promise<void>;
49
- /**
50
- * Disconnects from the Cloud Interop service
51
- *
52
- * @return {*} {Promise<void>}
53
- * @memberof CloudInteropAPI
54
- * @throws {CloudInteropAPIError} - If an error occurs during disconnection
55
- */
56
- disconnect(): Promise<void>;
57
- /**
58
- * Publishes a new context for the given context group to the other connected sessions
59
- *
60
- * @param {string} contextGroup - The context group to publish to
61
- * @param {object} context - The context to publish
62
- * @return {*} {Promise<void>}
63
- * @memberof CloudInteropAPI
64
- */
65
- setContext(contextGroup: string, context: object): Promise<void>;
66
- /**
67
- * Starts an intent discovery operation
68
- *
69
- * @return {*} {Promise<void>}
70
- * @memberof CloudInteropAPI
71
- * @throws {CloudInteropAPIError} - If an error occurs during intent discovery
72
- */
73
- startIntentDiscovery(): Promise<void>;
74
- /**
75
- * Ends an intent discovery operation
76
- *
77
- * @return {*} {Promise<void>}
78
- * @memberof CloudInteropAPI
79
- * @throws {CloudInteropAPIError} - If an error occurs during stopping intent discovery
80
- */
81
- endIntentDiscovery(): Promise<void>;
82
- raiseIntent(intent: Intent, targetSessionId: string): Promise<void>;
83
- reportSupportedIntents(discoveryId: string, intents: Intent[]): Promise<void>;
84
- sendIntentResult(resultEvent: IntentResultEvent): Promise<void>;
85
- addEventListener<K extends keyof EventMap>(type: K, callback: EventMap[K]): void;
86
- removeEventListener<K extends keyof EventMap>(type: K, callback: EventMap[K]): void;
87
- }
88
- export {};
@@ -1,7 +0,0 @@
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
- }
@@ -1,3 +0,0 @@
1
- export * from './api';
2
- export * from './errors/api.error';
3
- export * from './interfaces';
@@ -1,125 +0,0 @@
1
- export type LogLevel = 'log' | 'debug' | 'info' | 'warn' | 'error';
2
- /**
3
- * Represents a logging function to be used by the cloud interop client
4
- */
5
- export type CloudInteropLogger = (level: LogLevel, message: string) => void;
6
- /**
7
- * Represents the parameters to use to connect to an interop server
8
- */
9
- export type ConnectParameters = {
10
- /**
11
- * ID for a group of shared applications.
12
- * This acts as a namespace for the interop messages that allows separation of messages between different groups of applications for the same user
13
- */
14
- platformId: string;
15
- /**
16
- * An identifier for the source environment e.g. a hostname, a browser name etc.
17
- */
18
- sourceId: string;
19
- /**
20
- * A display name for the source environment e.g. Andys Mobile
21
- */
22
- sourceDisplayName?: string;
23
- /**
24
- * The maximum number of times to retry connecting to the cloud interop service when the connection is dropped
25
- * defaults to 30
26
- */
27
- reconnectRetryLimit?: number;
28
- /**
29
- * Specifies how often keep alive messages should be sent to the cloud interop service in seconds
30
- * defaults to 30
31
- */
32
- keepAliveIntervalSeconds?: number;
33
- /**
34
- * Optional function to call with any logging messages to allow integration with the host application's logging
35
- *
36
- * defaults to console.log
37
- */
38
- logger?: CloudInteropLogger;
39
- /**
40
- * Determines the type of authentication to use with the service gateway
41
- * defaults to 'none'
42
- *
43
- * 'jwt' - Use JWT authentication, in this case jwtAuthenticationParameters must also be provided
44
- * 'basic' - Use basic authentication, in this case basicAuthenticationParameters must also be provided
45
- * 'default' - Authentication will be inherited from the current session
46
- */
47
- authenticationType?: 'jwt' | 'basic' | 'default';
48
- /**
49
- * Optional parameters for basic authentication
50
- */
51
- basicAuthenticationParameters?: {
52
- /**
53
- * The username to use for basic authentication
54
- */
55
- username: string;
56
- /**
57
- * The password to use for basic authentication
58
- */
59
- password: string;
60
- };
61
- /**
62
- * Optional parameters for JWT authentication
63
- */
64
- jwtAuthenticationParameters?: {
65
- /**
66
- * When JWT authentication is being used, this will be invoked just whenever a JWT token is required for a request
67
- */
68
- jwtRequestCallback: () => string | object;
69
- /**
70
- * The id of the service gateway JWT authentication definition to use
71
- *
72
- * Note: Contact Here support to to get your organization's authentication id
73
- */
74
- authenticationId: string;
75
- };
76
- };
77
- export type CloudInteropSettings = {
78
- url: string;
79
- };
80
- /**
81
- * Represents a session
82
- */
83
- export type InteropSession = {
84
- sessionId: string;
85
- };
86
- /**
87
- * Represents a source session
88
- */
89
- export type Source = {
90
- /**
91
- * Source session id
92
- */
93
- sessionId: string;
94
- /**
95
- * source environment id
96
- */
97
- sourceId: string;
98
- /**
99
- * source environment display name
100
- */
101
- sourceDisplayName: string;
102
- };
103
- /**
104
- * Represents a context received from another cloud interop publisher
105
- *
106
- * @export
107
- * @type ContextEvent
108
- * @property {string} contextGroup - The context group
109
- * @property {object} context - The context
110
- * @property {Source} source - The source of the context
111
- */
112
- export type ContextEvent = {
113
- /**
114
- * The context group
115
- */
116
- contextGroup: string;
117
- /**
118
- * The context object
119
- */
120
- context: object;
121
- /**
122
- * The source of the context
123
- */
124
- source: Source;
125
- };
@@ -1 +0,0 @@
1
- export {};
@@ -1 +0,0 @@
1
- export {};
@@ -1,128 +0,0 @@
1
- export declare const DEFAULT_HEADERS: {
2
- 'Content-Type': string;
3
- };
4
- export declare const DEFAULT_AUTH_HEADER: {
5
- Authorization: string;
6
- };
7
- type Method = 'GET' | 'OPTIONS' | 'POST' | 'PUT' | 'PATCH' | 'DELETE';
8
- export declare enum Status {
9
- OK = 200,
10
- Created = 201,
11
- Accepted = 202,
12
- NonAuthoritativeInformation = 203,
13
- NoContent = 204,
14
- ResetContent = 205,
15
- PartialContent = 206,
16
- MultipleChoices = 300,
17
- MovedPermanently = 301,
18
- Found = 302,
19
- SeeOther = 303,
20
- NotModified = 304,
21
- UseProxy = 305,
22
- Unused = 306,
23
- TemporaryRedirect = 307,
24
- PermanentRedirect = 308,
25
- BadRequest = 400,
26
- Unauthorized = 401,
27
- PaymentRequired = 402,
28
- Forbidden = 403,
29
- NotFound = 404,
30
- MethodNotAllowed = 405,
31
- NotAcceptable = 406,
32
- ProxyAuthenticationRequired = 407,
33
- RequestTimeout = 408,
34
- Conflict = 409,
35
- Gone = 410,
36
- LengthRequired = 411,
37
- PreconditionFailed = 412,
38
- RequestEntityTooLarge = 413,
39
- RequestURITooLong = 414,
40
- UnsupportedMediaType = 415,
41
- RequestedRangeNotSatisfiable = 416,
42
- ExpectationFailed = 417,
43
- Imateapot = 418,
44
- MisdirectedRequest = 421,
45
- UnprocessableEntity = 422,
46
- Locked = 423,
47
- TooEarly = 425,
48
- UpgradeRequired = 426,
49
- PreconditionRequired = 428,
50
- TooManyRequests = 429,
51
- RequestHeaderFieldsTooLarge = 431,
52
- UnavailableForLegalReasons = 451,
53
- InternalServerError = 500,
54
- NotImplemented = 501,
55
- BadGateway = 502,
56
- ServiceUnavailable = 503,
57
- GatewayTimeout = 504,
58
- HTTPVersionNotSupported = 505,
59
- VariantAlsoNegotiates = 506,
60
- InsufficientStorage = 507,
61
- NetworkAuthenticationRequired = 511,
62
- Webserverisreturninganunknownerror = 520,
63
- Connectiontimedout = 522,
64
- Atimeoutoccurred = 524
65
- }
66
- /**
67
- * Stub API request, response in test cases.
68
- * - should be initialized and destroyed within the context of a specific case.
69
- * - highly customizable
70
- *
71
- * <pre>
72
- * describe("Fetch API", () => {
73
- * let fetchResolver!: FetchResolver;
74
- * beforeEach(() => {
75
- * fetchResolver = new FetchResolver();
76
- * });
77
- *
78
- * it("should load api", async () => {
79
- * // stub
80
- * fetchResolver.stub( "http://localhost:8080/endpoint", "post", { id: 100 }, { created: true }, 200);
81
- * // fetch
82
- * fetch("http://localhost:8080/endpoint",
83
- * { method: "post", body: JSON.stringify({ id: 100 })}
84
- * ).then((response) => {
85
- * if (response.ok) {
86
- * response.text().then((text) => {
87
- * console.log(text); // { created: true }
88
- * expect(text).toBeEqual({ created: true });
89
- * });
90
- * }
91
- * });
92
- * });
93
- *
94
- * afterEach(() => {
95
- * fetchResolver.clear();
96
- * });
97
- * });
98
- * </pre>
99
- *
100
- * Even though jest executes tests in parallel jest instance,
101
- * We can't go wrong if stubs are cleaned after its use
102
- */
103
- export declare class FetchResolver {
104
- readonly interopUrl: string;
105
- readonly sourceId: string;
106
- readonly platformId: string;
107
- private mocks;
108
- fetchSpy: jest.SpyInstance<Promise<Response>, [input: string | URL | Request, init?: RequestInit | undefined], any>;
109
- constructor(interopUrl?: string, sourceId?: string, platformId?: string);
110
- stubConnect(headers?: Record<string, string>): void;
111
- stubDelete(status?: number): void;
112
- stubFetchWithSourceAndPlatform(url: string, method: Method, headers: any, payload: any, response: any, status: number): void;
113
- stubFetch(url: string, method: Method, headers: any, payload: any, response: any, status: number): void;
114
- /**
115
- *
116
- * @param uri
117
- * @param method
118
- * @param headers pass null to delete headers from requestInit
119
- * @param payload pass null to delete body from requestInit
120
- * @param response
121
- * @param status
122
- */
123
- stub(uri: string, method: Method, headers: any, payload: any, response: any, status: Status): void;
124
- private prettyPrint;
125
- clear(): void;
126
- private init;
127
- }
128
- export {};