@openfin/cloud-api 0.0.1-alpha.0034b20

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.
@@ -0,0 +1,559 @@
1
+ import * as OpenFin from '@openfin/core';
2
+ import OpenFin__default from '@openfin/core';
3
+ import * as NotificationsTypes from '@openfin/workspace/notifications';
4
+
5
+ /**
6
+ * NotificationsClient is a client for accessing and interacting with the Notifications your application has created.
7
+ */
8
+ type NotificationsClient = {
9
+ /**
10
+ * Adds an event listener to the Notifications service.
11
+ *
12
+ * @param event the event name to listen for
13
+ * @param callback the callback to be invoked when the event is emitted
14
+ */
15
+ addEventListener<T extends keyof NotificationEventsMap>(event: T, callback: NotificationEventsMap[T]): void;
16
+ /**
17
+ * Removes an event listener from the Notifications service.
18
+ *
19
+ * @see {NotificationsClient.addEventListener}
20
+ *
21
+ * @remarks If the listener is not found, a warning will be logged to the console.
22
+ */
23
+ removeEventListener<T extends keyof NotificationEventsMap>(event: T, callback: NotificationEventsMap[T]): void;
24
+ /**
25
+ * Creates a new Notification.
26
+ *
27
+ * @remarks `id` should __not__ be provided. Instead, use the id property of the returned notification object. If you supply and `id` property, it will be ignored, with a warning logged to the console.
28
+ *
29
+ * @param args
30
+ */
31
+ createNotification(...args: Parameters<typeof NotificationsTypes.create>): ReturnType<typeof NotificationsTypes.create>;
32
+ /**
33
+ * Updates an existing Notification.
34
+ */
35
+ update(...args: Parameters<typeof NotificationsTypes.update>): ReturnType<typeof NotificationsTypes.update>;
36
+ /**
37
+ * Clears a Notification with the specified id.
38
+ */
39
+ clear(...args: Parameters<typeof NotificationsTypes.clear>): ReturnType<typeof NotificationsTypes.clear>;
40
+ };
41
+ /**
42
+ * @internal
43
+ */
44
+ type FlannelCreateNotificationRequest = {
45
+ version: 1;
46
+ payload: {
47
+ notification: NotificationsTypes.NotificationOptions;
48
+ };
49
+ };
50
+ /**
51
+ * @internal
52
+ */
53
+ type FlannelCreateNotificationResponse = {
54
+ version: 1;
55
+ payload: {
56
+ response: NotificationsTypes.Notification<NotificationsTypes.NotificationOptions>;
57
+ };
58
+ };
59
+ /**
60
+ * @internal
61
+ */
62
+ type FlannelUpdateNotificationRequest = {
63
+ version: 1;
64
+ payload: {
65
+ notification: NotificationsTypes.UpdatableNotificationOptions;
66
+ };
67
+ };
68
+ /**
69
+ * @internal
70
+ */
71
+ type FlannelUpdateNotificationResponse = {
72
+ version: 1;
73
+ payload: {
74
+ response: NotificationsTypes.Notification;
75
+ };
76
+ };
77
+ /**
78
+ * @internal
79
+ */
80
+ type FlannelClearNotificationRequest = {
81
+ version: 1;
82
+ payload: {
83
+ notificationId: string;
84
+ };
85
+ };
86
+ /**
87
+ * @internal
88
+ */
89
+ type FlannelClearNotificationResponse = {
90
+ version: 1;
91
+ payload: {
92
+ response: boolean;
93
+ };
94
+ };
95
+ /**
96
+ * @internal
97
+ */
98
+ type FlannelProvider = {
99
+ 'openfin-cloud-create-notification': (arg0: FlannelCreateNotificationRequest) => Promise<FlannelCreateNotificationResponse>;
100
+ 'openfin-cloud-update-notification': (arg0: FlannelUpdateNotificationRequest) => Promise<FlannelUpdateNotificationResponse>;
101
+ 'openfin-cloud-clear-notification': (arg0: FlannelClearNotificationRequest) => Promise<FlannelClearNotificationResponse>;
102
+ };
103
+ type NotificationEventsMap = {
104
+ 'notification-form-values-changed': (event: NotificationsTypes.NotificationFormValuesChangedEvent & {
105
+ timestamp: Date;
106
+ }) => void;
107
+ 'notification-form-submitted': (event: NotificationsTypes.NotificationFormSubmittedEvent & {
108
+ timestamp: Date;
109
+ }) => void;
110
+ 'notification-action': (event: NotificationsTypes.NotificationActionEvent & {
111
+ timestamp: Date;
112
+ }) => void;
113
+ 'notification-created': (event: NotificationsTypes.NotificationCreatedEvent & {
114
+ timestamp: Date;
115
+ }) => void;
116
+ 'notification-toast-dismissed': (event: NotificationsTypes.NotificationToastDismissedEvent & {
117
+ timestamp: Date;
118
+ }) => void;
119
+ 'notification-closed': (event: NotificationsTypes.NotificationClosedEvent & {
120
+ timestamp: Date;
121
+ }) => void;
122
+ 'notifications-count-changed': (event: NotificationsTypes.NotificationsCountChanged & {
123
+ timestamp: Date;
124
+ }) => void;
125
+ 'notification-reminder-created': (event: NotificationsTypes.NotificationReminderCreatedEvent & {
126
+ timestamp: Date;
127
+ }) => void;
128
+ 'notification-reminder-removed': (event: NotificationsTypes.NotificationReminderRemovedEvent & {
129
+ timestamp: Date;
130
+ }) => void;
131
+ };
132
+ /**
133
+ * @internal
134
+ */
135
+ type FlannelClient = {
136
+ 'openfin-cloud-event': <T extends keyof NotificationEventsMap>(arg0: {
137
+ type: T;
138
+ payload: Parameters<NotificationEventsMap[T]>[0];
139
+ }) => void;
140
+ };
141
+ /**
142
+ * @internal
143
+ */
144
+ type FlannelChannelProvider = {
145
+ /**
146
+ * @internal
147
+ */
148
+ dispatch: <T extends keyof FlannelClient>(to: OpenFin__default.ClientIdentity | OpenFin__default.Identity, action: T, payload: Parameters<FlannelClient[T]>[0]) => Promise<Awaited<ReturnType<FlannelClient[T]>>>;
149
+ /**
150
+ * @internal
151
+ */
152
+ register: <T extends keyof FlannelProvider>(action: T, handler: (payload: Parameters<FlannelProvider[T]>[0], id: OpenFin__default.ProviderIdentity | OpenFin__default.ClientIdentity) => ReturnType<FlannelProvider[T]>) => boolean;
153
+ } & Omit<OpenFin__default.ChannelProvider, 'dispatch' | 'register'>;
154
+
155
+ /**
156
+ * @returns A client for interacting with the OpenFin Notifications service
157
+ *
158
+ * @throws {Error} If the function is called outside of an OpenFin environment
159
+ * @throws {Error} If the function is called outside of an OpenFin View context
160
+ * @throws {Error} If the app UUID cannot be extracted from the current context
161
+ *
162
+ * @example **Basic Usage** Creating a notification, updating it and then clearing it
163
+ * ```ts
164
+ * const notificationsClient = await getNotificationsClient();
165
+ *
166
+ * const notification = await notificationsClient.createNotification({
167
+ * title: 'Hello, World!',
168
+ * body: 'This is a notification from the OpenFin Cloud API',
169
+ * });
170
+ *
171
+ * // Use the `id` from the returned notification to interact with it
172
+ * console.log(notification.id);
173
+ *
174
+ * // Update the notification
175
+ * await notificationsClient.update({
176
+ * id: notification.id,
177
+ * body: 'This is a notification from the OpenFin Cloud API, that has been updated!',
178
+ * })
179
+ *
180
+ * // Clear the notification
181
+ * await notificationsClient.clear(notification.id);
182
+ * ```
183
+ *
184
+ * @example **Advanced Usage** Listening for events
185
+ * ```ts
186
+ * const notificationsClient = await getNotificationsClient();
187
+ *
188
+ * // create the notification
189
+ * const notification = await notificationsClient.createNotification({
190
+ * title: `${window.fin.me.identity.name} Hello, World!`,
191
+ * body: `This is a notification from the cloud API example created at ${new Date().toLocaleTimeString()}`,
192
+ * buttons: [
193
+ * {
194
+ * title: 'Acknowledge',
195
+ * },
196
+ * ],
197
+ * });
198
+ *
199
+ * notificationsClient.addEventListener('notification-action', (event) => {
200
+ * console.log('Notification action:', event);
201
+ * });
202
+ * ```
203
+ */
204
+ declare function getNotificationsClient(): Promise<NotificationsClient>;
205
+
206
+ /**
207
+ * Represents a collection of returned app permissions
208
+ */
209
+ type AppPermissions = {
210
+ permissions: {
211
+ /**
212
+ * The name of the permission
213
+ */
214
+ name: string;
215
+ /**
216
+ * The ID of the permission
217
+ */
218
+ id: string;
219
+ }[];
220
+ };
221
+ /**
222
+ * @returns The app settings that have been set against the current app
223
+ *
224
+ * @throws {Error} If the function is called outside of an OpenFin environment
225
+ * @throws {Error} If the function is called outside of an OpenFin View context
226
+ */
227
+ declare function getAppSettings(): Promise<unknown>;
228
+ /**
229
+ * @returns The app settings that have been set against the current app for the current user
230
+ *
231
+ * @throws {Error} If the function is called outside of an OpenFin environment
232
+ * @throws {Error} If the function is called outside of an OpenFin View context
233
+ */
234
+ declare function getAppUserSettings(): Promise<unknown>;
235
+ /**
236
+ * Assigns a set of user specific settings to the current app
237
+ *
238
+ * @returns The app settings that have been set against the current app for the current user
239
+ *
240
+ * @throws {Error} If the function is called outside of an OpenFin environment
241
+ * @throws {Error} If the function is called outside of an OpenFin View context
242
+ */
243
+ declare function setAppUserSettings(settings: unknown): Promise<unknown>;
244
+ /**
245
+ * @returns The permissions that have been set against the current app for the current user
246
+ *
247
+ * @throws {Error} If the function is called outside of an OpenFin environment
248
+ * @throws {Error} If the function is called outside of an OpenFin View context
249
+ */
250
+ declare function getAppUserPermissions(): Promise<AppPermissions>;
251
+ type LaunchContentOptions = {
252
+ /** Object containing query param values to be appended to content's URL */
253
+ queryParams?: Record<string, string>;
254
+ /** Defines behavior when instance of content is already running.
255
+ * If 'multi', copy of the content will be created.
256
+ * If 'single', the existing instance of content will be focused. */
257
+ instanceMode?: 'single' | 'multi';
258
+ } & ({
259
+ targetType?: 'new-window';
260
+ /** Defines the bounds of the window in which content will open */
261
+ bounds?: Partial<OpenFin__default.Bounds>;
262
+ } | {
263
+ targetType: 'window' | 'view';
264
+ targetIdentity: OpenFin__default.Identity;
265
+ });
266
+ /**
267
+ * A function allowing the easy launching of content
268
+ * @param id The id of the content to launch
269
+ * @returns nothing
270
+ *
271
+ * @throws {Error} If the function is called outside of an OpenFin environment
272
+ * @throws {Error} If the function is called outside of an OpenFin View context
273
+ * @throws {Error} If the function has been unable to look up or launch the content
274
+ * @throws {Error} If the function is unable to find content with the provided id.
275
+ */
276
+ declare function launchContent(id: string, options: LaunchContentOptions): Promise<void>;
277
+ /**
278
+ * A function allowing the easy launching of Supertabs
279
+ * @param id The id of supertab
280
+ * @returns nothing
281
+ *
282
+ * @throws {Error} If the function is called outside of an OpenFin environment
283
+ * @throws {Error} If the function is called outside of an OpenFin View context
284
+ * @throws {Error} If the function has been unable to look up or launch the supertab
285
+ * @throws {Error} If the function is unable to find supertab with the provided id.
286
+ */
287
+ declare function launchSupertab(id: string): Promise<void>;
288
+ /**
289
+ * A function allowing the easy launching of Workspaces
290
+ * @param id The id of workspace
291
+ * @returns nothing
292
+ *
293
+ * @throws {Error} If the function is called outside of an OpenFin environment
294
+ * @throws {Error} If the function is called outside of an OpenFin View context
295
+ * @throws {Error} If the function has been unable to look up or launch the workspace
296
+ * @throws {Error} If the function is unable to find workspace with the provided id.
297
+ */
298
+ declare function launchWorkspace(id: string): Promise<void>;
299
+
300
+ /**
301
+ * Function that is called when the Search Agent receives an action from Here™’s search UI that has been triggered by the user on one of the Agent’s search results.
302
+ *
303
+ * @param action The action that was triggered.
304
+ * @param result The search result that the action was triggered on.
305
+ *
306
+ * @returns Result that includes the URL that Here™ should navigate to, or `undefined` if no navigation is required.
307
+ */
308
+ type OnActionListener = (action: SearchAction, result: SearchResult) => SearchResultActionResponse | Promise<SearchResultActionResponse>;
309
+ /**
310
+ * Function that is called when the Search Agent receives a query from Here™’s search UI
311
+ *
312
+ * @param request Search request data that includes the query.
313
+ *
314
+ * @returns Search response data that includes the search results.
315
+ */
316
+ type OnSearchListener = (request: SearchListenerRequest) => SearchResponse | Promise<SearchResponse>;
317
+ /**
318
+ * An action that can be triggered by a user on a search result returned by a Search Agent.
319
+ *
320
+ * Actions are displayed as buttons alongside search results in Here™’s search UI. That is, except for the first action, which is hidden as it is triggered automatically when the user selects the search result.
321
+ */
322
+ type SearchAction = {
323
+ /**
324
+ * URL or data URI of an icon that will be displayed within the action button when Here™ is in Light mode.
325
+ */
326
+ darkIcon?: string;
327
+ /**
328
+ * A fuller description of the action that will be displayed in Here™’s search UI when the user hovers over the action button.
329
+ */
330
+ description?: string;
331
+ /**
332
+ * URL or data URI of an icon that will be displayed within the action button when Here™ is in Dark mode.
333
+ */
334
+ lightIcon?: string;
335
+ /**
336
+ * Internal identifier for the action which is used to identify the action in the {@link OnActionListener}.
337
+ */
338
+ name: string;
339
+ /**
340
+ * Compact title of the action displayed within the action button.
341
+ */
342
+ title?: string;
343
+ };
344
+ /**
345
+ * A Search Agent returns search results to Here™’s search UI in response to user input, and acts on the user’s actions regarding those results.
346
+ */
347
+ type SearchAgent = {
348
+ /**
349
+ * The Search Agent’s custom configuration data configured via the Admin Console.
350
+ */
351
+ readonly customData: unknown;
352
+ /**
353
+ * Sets whether or not the Search Agent is ready to provide search results.
354
+ *
355
+ * When a Search Agent is first registered, it will not receive search queries until it is set as ready by calling this function.
356
+ *
357
+ * @param ready Whether the Search Agent is ready to provide search results (defaults to `true`).
358
+ */
359
+ isReady: (ready?: boolean) => Promise<void>;
360
+ };
361
+ /**
362
+ * Configuration provided when registering a Search Agent.
363
+ */
364
+ type SearchAgentRegistrationConfig = {
365
+ /**
366
+ * This listener is called when the Search Agent receives an action from Here™’s search UI that has been triggered by the user on one of the Agent’s search results.
367
+ *
368
+ * The listener returns a response back to Here™ that includes a URL to navigate to.
369
+ */
370
+ onAction: OnActionListener;
371
+ /**
372
+ * This listener is called when the Search Agent receives a query from Here™’s search UI and returns relevant search results.
373
+ *
374
+ * Note: When the Search Agent is not ready this listener will not be called.
375
+ */
376
+ onSearch: OnSearchListener;
377
+ };
378
+ /**
379
+ * Search request data provided to the {@link OnSearchListener}.
380
+ */
381
+ type SearchListenerRequest = {
382
+ /**
383
+ * Provides additional context for the search request.
384
+ */
385
+ context: SearchRequestContext;
386
+ /**
387
+ * The query entered by the user in Here™’s search UI.
388
+ */
389
+ query: string;
390
+ /**
391
+ * Provide this signal to any `fetch` requests executed in the {@link OnSearchListener} function as a result of this search request, so that they will be automatically cancelled if a new search request is received before they complete.
392
+ */
393
+ signal: AbortSignal;
394
+ };
395
+ /**
396
+ * Context data included with a search request.
397
+ */
398
+ type SearchRequestContext = {
399
+ /**
400
+ * The page number of the search results to return.
401
+ */
402
+ pageNumber: number;
403
+ /**
404
+ * The number of search results to return per page.
405
+ */
406
+ pageSize: number;
407
+ };
408
+ /**
409
+ * Return type of the {@link OnSearchListener}.
410
+ */
411
+ type SearchResponse = {
412
+ /**
413
+ * The search results to display in Here™’s search UI.
414
+ */
415
+ results: SearchResult[];
416
+ };
417
+ /**
418
+ * A search result returned by a Search Agent in response to a search request.
419
+ */
420
+ type SearchResult = {
421
+ /**
422
+ * Actions that can be triggered by the user against the search result.
423
+ */
424
+ actions: SearchAction[];
425
+ /**
426
+ * Additional data that can be used by the {@link OnActionListener} when an action is triggered.
427
+ */
428
+ data?: Record<string, unknown>;
429
+ /**
430
+ * URL or data URI of an icon that will be displayed with the search result in Here™’s search UI.
431
+ */
432
+ icon?: string;
433
+ /**
434
+ * Unique identifier for the search result.
435
+ */
436
+ key: string;
437
+ /**
438
+ * Secondary text that will be displayed with the search result in Here™’s search UI.
439
+ */
440
+ label?: string;
441
+ /**
442
+ * Primary text that will be displayed with the search result in Here™’s search UI.
443
+ */
444
+ title: string;
445
+ };
446
+ /**
447
+ * Return type of the {@link OnActionListener}.
448
+ */
449
+ type SearchResultActionResponse = {
450
+ /**
451
+ * URL that Here™ should navigate to.
452
+ */
453
+ url: string;
454
+ } | undefined;
455
+
456
+ /**
457
+ * Registers a Search Agent that will provide search results to Here™’s search UI in response to user input and act on the user’s actions regarding those results.
458
+ *
459
+ * @param config The configuration for the Search Agent.
460
+ *
461
+ * @returns A promise that resolves with the Search Agent.
462
+ *
463
+ * @example Registering a basic Search Agent:
464
+ * ```ts
465
+ * // Handle incoming action and return a response that includes the URL to navigate to
466
+ * const onAction: Search.OnActionListener = (action, result) => {
467
+ * const { name } = action;
468
+ * const { data, key } = result;
469
+ * const { owner, searchResultHostUrl } = data as { owner: { id: string, name: string }, searchResultHostUrl: string };
470
+ * const { id: ownerId } = owner;
471
+ * console.log(`Action "${name}" triggered on search result with key "${key}"`);
472
+ * switch (name) {
473
+ * case "view-owner":
474
+ * return { url: `${searchResultHostUrl}/people/${ownerId}` };
475
+ * case "view-result":
476
+ * return { url: `${searchResultHostUrl}/record/${key}` };
477
+ * default:
478
+ * console.warn(`Unknown action: ${name}`);
479
+ * }
480
+ * };
481
+ *
482
+ * // Handle incoming search request and return relevant search results
483
+ * const onSearch: Search.OnSearchListener = ({ context, query, signal }) => {
484
+ * const { pageNumber, pageSize } = context;
485
+ * try {
486
+ * let results: Search.SearchResult[] = [];
487
+ * const url = `https://my-web-app.com/search?q=${query}&page=${pageNumber}&limit=${pageSize}`;
488
+ * const response = await fetch(url, { signal });
489
+ * if (!response.ok) {
490
+ * throw new Error(`Request failed: ${response.status}`);
491
+ * }
492
+ * const { searchResults } = await response.json();
493
+ * results = searchResults.map((result) => {
494
+ * const { iconUrl, id: key, owner, subTitle, title } = result;
495
+ * const { name: ownerName } = owner as { id: string, name: string };
496
+ * return {
497
+ * actions: [
498
+ * {
499
+ * name: "view-result",
500
+ * description: `Go to ${title} in My Web App`,
501
+ * },
502
+ * {
503
+ * name: "view-owner",
504
+ * description: `Go to ${ownerName} in My Web App`,
505
+ * title: "View Owner",
506
+ * },
507
+ * ],
508
+ * data: {
509
+ * owner,
510
+ * searchResultHostUrl: `https://my-web-app.com`,
511
+ * },
512
+ * icon: iconUrl,
513
+ * key,
514
+ * label: subTitle,
515
+ * title,
516
+ * };
517
+ * });
518
+ * console.log("Returning results", results);
519
+ * return { results };
520
+ * } catch (err) {
521
+ * if ((err as Error).name === "AbortError") {
522
+ * // Ignore errors for cancelled requests
523
+ * return { results: [] };
524
+ * }
525
+ * throw err;
526
+ * }
527
+ * };
528
+ *
529
+ * // Register the search agent
530
+ * const searchAgent = await Search.register({ onAction, onSearch });
531
+ *
532
+ * // Set the Search Agent as ready to receive search requests
533
+ * await searchAgent.isReady();
534
+ * ```
535
+ */
536
+ declare function register(config: SearchAgentRegistrationConfig): Promise<SearchAgent>;
537
+
538
+ type index_OnActionListener = OnActionListener;
539
+ type index_OnSearchListener = OnSearchListener;
540
+ type index_SearchAction = SearchAction;
541
+ type index_SearchAgent = SearchAgent;
542
+ type index_SearchAgentRegistrationConfig = SearchAgentRegistrationConfig;
543
+ type index_SearchListenerRequest = SearchListenerRequest;
544
+ type index_SearchRequestContext = SearchRequestContext;
545
+ type index_SearchResponse = SearchResponse;
546
+ type index_SearchResult = SearchResult;
547
+ type index_SearchResultActionResponse = SearchResultActionResponse;
548
+ declare const index_register: typeof register;
549
+ declare namespace index {
550
+ export { type index_OnActionListener as OnActionListener, type index_OnSearchListener as OnSearchListener, type index_SearchAction as SearchAction, type index_SearchAgent as SearchAgent, type index_SearchAgentRegistrationConfig as SearchAgentRegistrationConfig, type index_SearchListenerRequest as SearchListenerRequest, type index_SearchRequestContext as SearchRequestContext, type index_SearchResponse as SearchResponse, type index_SearchResult as SearchResult, type index_SearchResultActionResponse as SearchResultActionResponse, index_register as register };
551
+ }
552
+
553
+ declare global {
554
+ interface Window {
555
+ fin: typeof OpenFin.fin;
556
+ }
557
+ }
558
+
559
+ export { type AppPermissions, type LaunchContentOptions, index as Search, type FlannelChannelProvider as __INTERNAL_FlannelChannelProvider, type FlannelClearNotificationRequest as __INTERNAL_FlannelClearNotificationRequest, type FlannelClearNotificationResponse as __INTERNAL_FlannelClearNotificationResponse, type FlannelCreateNotificationRequest as __INTERNAL_FlannelCreateNotificationRequest, type FlannelCreateNotificationResponse as __INTERNAL_FlannelCreateNotificationResponse, type FlannelUpdateNotificationRequest as __INTERNAL_FlannelUpdateNotificationRequest, type FlannelUpdateNotificationResponse as __INTERNAL_FlannelUpdateNotificationResponse, getAppSettings, getAppUserPermissions, getAppUserSettings, getNotificationsClient, launchContent, launchSupertab, launchWorkspace, setAppUserSettings };