@openfin/cloud-api 0.0.1-alpha.fe96ffc → 0.0.1-alpha.fec3349
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/index.cjs +1 -1
- package/dist/index.cjs.map +1 -1
- package/dist/index.d.cts +406 -28
- package/dist/index.d.ts +406 -28
- package/dist/index.js +1 -1
- package/dist/index.js.map +1 -1
- package/package.json +15 -12
package/dist/index.d.ts
CHANGED
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
import * as OpenFin from '@openfin/core';
|
|
2
|
-
import OpenFin__default from '@openfin/core';
|
|
2
|
+
import OpenFin__default, { OpenFin as OpenFin$1 } from '@openfin/core';
|
|
3
3
|
import * as NotificationsTypes from '@openfin/workspace/notifications';
|
|
4
4
|
|
|
5
5
|
/**
|
|
@@ -305,7 +305,7 @@ declare function launchWorkspace(id: string): Promise<void>;
|
|
|
305
305
|
*
|
|
306
306
|
* @returns Result that includes the URL that Here™ should navigate to, or `undefined` if no navigation is required.
|
|
307
307
|
*/
|
|
308
|
-
type OnActionListener = (action: SearchAction, result: SearchResult) => SearchResultActionResponse | Promise<SearchResultActionResponse>;
|
|
308
|
+
type OnActionListener = (action: SearchAction$1, result: SearchResult$1) => SearchResultActionResponse$1 | Promise<SearchResultActionResponse$1>;
|
|
309
309
|
/**
|
|
310
310
|
* Function that is called when the Search Agent receives a query from Here™’s search UI
|
|
311
311
|
*
|
|
@@ -313,13 +313,13 @@ type OnActionListener = (action: SearchAction, result: SearchResult) => SearchRe
|
|
|
313
313
|
*
|
|
314
314
|
* @returns Search response data that includes the search results.
|
|
315
315
|
*/
|
|
316
|
-
type OnSearchListener = (request: SearchListenerRequest) => SearchResponse | Promise<SearchResponse>;
|
|
316
|
+
type OnSearchListener = (request: SearchListenerRequest$1) => SearchResponse$1 | Promise<SearchResponse$1>;
|
|
317
317
|
/**
|
|
318
318
|
* An action that can be triggered by a user on a search result returned by a Search Agent.
|
|
319
319
|
*
|
|
320
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
321
|
*/
|
|
322
|
-
type SearchAction = {
|
|
322
|
+
type SearchAction$1 = {
|
|
323
323
|
/**
|
|
324
324
|
* URL or data URI of an icon that will be displayed within the action button when Here™ is in Light mode.
|
|
325
325
|
*/
|
|
@@ -343,21 +343,48 @@ type SearchAction = {
|
|
|
343
343
|
};
|
|
344
344
|
/**
|
|
345
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
|
+
* @deprecated Use {@link Agent} instead.
|
|
346
348
|
*/
|
|
347
349
|
type SearchAgent = {
|
|
348
|
-
/**
|
|
349
|
-
* The Search Agent’s custom configuration data configured via the Admin Console.
|
|
350
|
-
*/
|
|
351
|
-
readonly customData: unknown;
|
|
352
350
|
/**
|
|
353
351
|
* Sets whether or not the Search Agent is ready to provide search results.
|
|
354
352
|
*
|
|
355
353
|
* When a Search Agent is first registered, it will not receive search queries until it is set as ready by calling this function.
|
|
356
354
|
*
|
|
357
355
|
* @param ready Whether the Search Agent is ready to provide search results (defaults to `true`).
|
|
356
|
+
*
|
|
357
|
+
* @deprecated Use {@link Agent.setIsReady} instead.
|
|
358
358
|
*/
|
|
359
359
|
isReady: (ready?: boolean) => Promise<void>;
|
|
360
360
|
};
|
|
361
|
+
/**
|
|
362
|
+
* The Search Agent’s configuration data as configured in the Here™ Admin Console.
|
|
363
|
+
*
|
|
364
|
+
* @typeParam T Type definition for the `customData` property, containing any custom configuration data specific to the Search Agent.
|
|
365
|
+
*/
|
|
366
|
+
type SearchAgentConfigurationData<T> = {
|
|
367
|
+
/**
|
|
368
|
+
* Custom configuration data specific to the Search Agent.
|
|
369
|
+
*/
|
|
370
|
+
customData?: T;
|
|
371
|
+
/**
|
|
372
|
+
* Optional description of the Search Agent.
|
|
373
|
+
*/
|
|
374
|
+
description?: string;
|
|
375
|
+
/**
|
|
376
|
+
* Unique identifier for the Search Agent.
|
|
377
|
+
*/
|
|
378
|
+
id: string;
|
|
379
|
+
/**
|
|
380
|
+
* The display title of the Search Agent.
|
|
381
|
+
*/
|
|
382
|
+
title: string;
|
|
383
|
+
/**
|
|
384
|
+
* The URL of the Search Agent.
|
|
385
|
+
*/
|
|
386
|
+
url: string;
|
|
387
|
+
};
|
|
361
388
|
/**
|
|
362
389
|
* Configuration provided when registering a Search Agent.
|
|
363
390
|
*/
|
|
@@ -378,11 +405,11 @@ type SearchAgentRegistrationConfig = {
|
|
|
378
405
|
/**
|
|
379
406
|
* Search request data provided to the {@link OnSearchListener}.
|
|
380
407
|
*/
|
|
381
|
-
type SearchListenerRequest = {
|
|
408
|
+
type SearchListenerRequest$1 = {
|
|
382
409
|
/**
|
|
383
410
|
* Provides additional context for the search request.
|
|
384
411
|
*/
|
|
385
|
-
context: SearchRequestContext;
|
|
412
|
+
context: SearchRequestContext$1;
|
|
386
413
|
/**
|
|
387
414
|
* The query entered by the user in Here™’s search UI.
|
|
388
415
|
*/
|
|
@@ -395,7 +422,7 @@ type SearchListenerRequest = {
|
|
|
395
422
|
/**
|
|
396
423
|
* Context data included with a search request.
|
|
397
424
|
*/
|
|
398
|
-
type SearchRequestContext = {
|
|
425
|
+
type SearchRequestContext$1 = {
|
|
399
426
|
/**
|
|
400
427
|
* The page number of the search results to return.
|
|
401
428
|
*/
|
|
@@ -404,24 +431,28 @@ type SearchRequestContext = {
|
|
|
404
431
|
* The number of search results to return per page.
|
|
405
432
|
*/
|
|
406
433
|
pageSize: number;
|
|
434
|
+
/**
|
|
435
|
+
* The unique ID of the query.
|
|
436
|
+
*/
|
|
437
|
+
queryId: string;
|
|
407
438
|
};
|
|
408
439
|
/**
|
|
409
440
|
* Return type of the {@link OnSearchListener}.
|
|
410
441
|
*/
|
|
411
|
-
type SearchResponse = {
|
|
442
|
+
type SearchResponse$1 = {
|
|
412
443
|
/**
|
|
413
444
|
* The search results to display in Here™’s search UI.
|
|
414
445
|
*/
|
|
415
|
-
results: SearchResult[];
|
|
446
|
+
results: SearchResult$1[];
|
|
416
447
|
};
|
|
417
448
|
/**
|
|
418
449
|
* A search result returned by a Search Agent in response to a search request.
|
|
419
450
|
*/
|
|
420
|
-
type SearchResult = {
|
|
451
|
+
type SearchResult$1 = {
|
|
421
452
|
/**
|
|
422
453
|
* Actions that can be triggered by the user against the search result.
|
|
423
454
|
*/
|
|
424
|
-
actions: SearchAction[];
|
|
455
|
+
actions: SearchAction$1[];
|
|
425
456
|
/**
|
|
426
457
|
* Additional data that can be used by the {@link OnActionListener} when an action is triggered.
|
|
427
458
|
*/
|
|
@@ -446,13 +477,35 @@ type SearchResult = {
|
|
|
446
477
|
/**
|
|
447
478
|
* Return type of the {@link OnActionListener}.
|
|
448
479
|
*/
|
|
449
|
-
type SearchResultActionResponse = {
|
|
480
|
+
type SearchResultActionResponse$1 = {
|
|
450
481
|
/**
|
|
451
482
|
* URL that Here™ should navigate to.
|
|
452
483
|
*/
|
|
453
484
|
url: string;
|
|
454
485
|
} | undefined;
|
|
455
486
|
|
|
487
|
+
/**
|
|
488
|
+
* Retrieves the Search Agent’s configuration data, as has been configured in the Here™ Admin Console.
|
|
489
|
+
*
|
|
490
|
+
* @returns A promise that resolves with an object containing properties that match the Search Agent’s configuration.
|
|
491
|
+
*
|
|
492
|
+
* @example Retrieving the Search Agent’s configuration data:
|
|
493
|
+
* ```ts
|
|
494
|
+
* import { Search } from "@openfin/cloud-api";
|
|
495
|
+
*
|
|
496
|
+
* // Get the configuration data
|
|
497
|
+
* const configData = await Search.getAgentConfiguration<{ customField1: string, customField2: string }>();
|
|
498
|
+
*
|
|
499
|
+
* // Pick out the standard configuration properties
|
|
500
|
+
* const { customData, description, id, title, url } = configData;
|
|
501
|
+
*
|
|
502
|
+
* // Pick out the custom configuration properties
|
|
503
|
+
* if (customData) {
|
|
504
|
+
* const { customField1, customField2 } = customData;
|
|
505
|
+
* }
|
|
506
|
+
* ```
|
|
507
|
+
*/
|
|
508
|
+
declare function getAgentConfiguration<T extends object>(): Promise<SearchAgentConfigurationData<T>>;
|
|
456
509
|
/**
|
|
457
510
|
* 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
511
|
*
|
|
@@ -462,6 +515,8 @@ type SearchResultActionResponse = {
|
|
|
462
515
|
*
|
|
463
516
|
* @example Registering a basic Search Agent:
|
|
464
517
|
* ```ts
|
|
518
|
+
* import { Search } from "@openfin/cloud-api";
|
|
519
|
+
*
|
|
465
520
|
* // Handle incoming action and return a response that includes the URL to navigate to
|
|
466
521
|
* const onAction: Search.OnActionListener = (action, result) => {
|
|
467
522
|
* const { name } = action;
|
|
@@ -532,22 +587,345 @@ type SearchResultActionResponse = {
|
|
|
532
587
|
* // Set the Search Agent as ready to receive search requests
|
|
533
588
|
* await searchAgent.isReady();
|
|
534
589
|
* ```
|
|
590
|
+
*
|
|
591
|
+
* @deprecated Use `Agent.register` instead.
|
|
592
|
+
*/
|
|
593
|
+
declare function register$1(config: SearchAgentRegistrationConfig): Promise<SearchAgent>;
|
|
594
|
+
|
|
595
|
+
type index$1_OnActionListener = OnActionListener;
|
|
596
|
+
type index$1_OnSearchListener = OnSearchListener;
|
|
597
|
+
type index$1_SearchAgent = SearchAgent;
|
|
598
|
+
type index$1_SearchAgentConfigurationData<T> = SearchAgentConfigurationData<T>;
|
|
599
|
+
type index$1_SearchAgentRegistrationConfig = SearchAgentRegistrationConfig;
|
|
600
|
+
declare const index$1_getAgentConfiguration: typeof getAgentConfiguration;
|
|
601
|
+
declare namespace index$1 {
|
|
602
|
+
export { type index$1_OnActionListener as OnActionListener, type index$1_OnSearchListener as OnSearchListener, type SearchAction$1 as SearchAction, type index$1_SearchAgent as SearchAgent, type index$1_SearchAgentConfigurationData as SearchAgentConfigurationData, type index$1_SearchAgentRegistrationConfig as SearchAgentRegistrationConfig, type SearchListenerRequest$1 as SearchListenerRequest, type SearchRequestContext$1 as SearchRequestContext, type SearchResponse$1 as SearchResponse, type SearchResult$1 as SearchResult, type SearchResultActionResponse$1 as SearchResultActionResponse, index$1_getAgentConfiguration as getAgentConfiguration, register$1 as register };
|
|
603
|
+
}
|
|
604
|
+
|
|
605
|
+
/**
|
|
606
|
+
* Function that is called when the Agent receives an action from Here™’s search UI that has been triggered by the user on one of the Agent’s search results.
|
|
607
|
+
*
|
|
608
|
+
* @param action The action that was triggered.
|
|
609
|
+
* @param result The search result that the action was triggered on.
|
|
610
|
+
*
|
|
611
|
+
* @returns Result that includes the URL that Here™ should navigate to, or `undefined` if no navigation is required.
|
|
612
|
+
*/
|
|
613
|
+
type OnSearchActionListener = (action: SearchAction, result: SearchResult) => SearchResultActionResponse | Promise<SearchResultActionResponse>;
|
|
614
|
+
/**
|
|
615
|
+
* Function that is called when the Agent receives a query from Here™’s search UI
|
|
616
|
+
*
|
|
617
|
+
* @param request Search request data that includes the query.
|
|
618
|
+
*
|
|
619
|
+
* @returns Search response data that includes the search results.
|
|
620
|
+
*/
|
|
621
|
+
type OnSearchRequestListener = (request: SearchListenerRequest) => SearchResponse | Promise<SearchResponse>;
|
|
622
|
+
/**
|
|
623
|
+
* An action that can be triggered by a user on a search result returned by a Agent.
|
|
624
|
+
*
|
|
625
|
+
* 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.
|
|
626
|
+
*/
|
|
627
|
+
type SearchAction = {
|
|
628
|
+
/**
|
|
629
|
+
* URL or data URI of an icon that will be displayed within the action button when Here™ is in Light mode.
|
|
630
|
+
*/
|
|
631
|
+
darkIcon?: string;
|
|
632
|
+
/**
|
|
633
|
+
* A fuller description of the action that will be displayed in Here™’s search UI when the user hovers over the action button.
|
|
634
|
+
*/
|
|
635
|
+
description?: string;
|
|
636
|
+
/**
|
|
637
|
+
* URL or data URI of an icon that will be displayed within the action button when Here™ is in Dark mode.
|
|
638
|
+
*/
|
|
639
|
+
lightIcon?: string;
|
|
640
|
+
/**
|
|
641
|
+
* Internal identifier for the action which is used to identify the action in the {@link OnSearchActionListener}.
|
|
642
|
+
*/
|
|
643
|
+
name: string;
|
|
644
|
+
/**
|
|
645
|
+
* Compact title of the action displayed within the action button.
|
|
646
|
+
*/
|
|
647
|
+
title?: string;
|
|
648
|
+
};
|
|
649
|
+
/**
|
|
650
|
+
* Search request data provided to the {@link OnSearchRequestListener}.
|
|
651
|
+
*/
|
|
652
|
+
type SearchListenerRequest = {
|
|
653
|
+
/**
|
|
654
|
+
* Provides additional context for the search request.
|
|
655
|
+
*/
|
|
656
|
+
context: SearchRequestContext;
|
|
657
|
+
/**
|
|
658
|
+
* The query entered by the user in Here™’s search UI.
|
|
659
|
+
*/
|
|
660
|
+
query: string;
|
|
661
|
+
/**
|
|
662
|
+
* Provide this signal to any `fetch` requests executed in the {@link OnSearchRequestListener} 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.
|
|
663
|
+
*/
|
|
664
|
+
signal: AbortSignal;
|
|
665
|
+
};
|
|
666
|
+
/**
|
|
667
|
+
* Context data included with a search request.
|
|
668
|
+
*/
|
|
669
|
+
type SearchRequestContext = {
|
|
670
|
+
/**
|
|
671
|
+
* Filters to apply to the search results.
|
|
672
|
+
*/
|
|
673
|
+
filters: string[];
|
|
674
|
+
/**
|
|
675
|
+
* The locale of the client.
|
|
676
|
+
*/
|
|
677
|
+
locale: string;
|
|
678
|
+
/**
|
|
679
|
+
* The page number of the search results to return.
|
|
680
|
+
*/
|
|
681
|
+
pageNumber: number;
|
|
682
|
+
/**
|
|
683
|
+
* The number of search results to return per page.
|
|
684
|
+
*/
|
|
685
|
+
pageSize: number;
|
|
686
|
+
/**
|
|
687
|
+
* The unique ID of the query.
|
|
688
|
+
*/
|
|
689
|
+
queryId: string;
|
|
690
|
+
/**
|
|
691
|
+
* The timezone of the client.
|
|
692
|
+
*/
|
|
693
|
+
timeZone: string;
|
|
694
|
+
};
|
|
695
|
+
/**
|
|
696
|
+
* Return type of the {@link OnSearchRequestListener}.
|
|
697
|
+
*/
|
|
698
|
+
type SearchResponse = {
|
|
699
|
+
/**
|
|
700
|
+
* The search results to display in Here™’s search UI.
|
|
701
|
+
*/
|
|
702
|
+
results: SearchResult[];
|
|
703
|
+
};
|
|
704
|
+
/**
|
|
705
|
+
* A search result returned by a Agent in response to a search request.
|
|
706
|
+
*/
|
|
707
|
+
type SearchResult = {
|
|
708
|
+
/**
|
|
709
|
+
* Actions that can be triggered by the user against the search result.
|
|
710
|
+
*/
|
|
711
|
+
actions: SearchAction[];
|
|
712
|
+
/**
|
|
713
|
+
* Additional data that can be used by the {@link OnSearchActionListener} when an action is triggered.
|
|
714
|
+
*/
|
|
715
|
+
data?: Record<string, unknown>;
|
|
716
|
+
/**
|
|
717
|
+
* URL or data URI of an icon that will be displayed with the search result in Here™’s search UI.
|
|
718
|
+
*/
|
|
719
|
+
icon?: string;
|
|
720
|
+
/**
|
|
721
|
+
* Unique identifier for the search result.
|
|
722
|
+
*/
|
|
723
|
+
key: string;
|
|
724
|
+
/**
|
|
725
|
+
* Secondary text that will be displayed with the search result in Here™’s search UI.
|
|
726
|
+
*/
|
|
727
|
+
label?: string;
|
|
728
|
+
/**
|
|
729
|
+
* Primary text that will be displayed with the search result in Here™’s search UI.
|
|
730
|
+
*/
|
|
731
|
+
title: string;
|
|
732
|
+
};
|
|
733
|
+
/**
|
|
734
|
+
* Return type of the {@link OnSearchActionListener}.
|
|
735
|
+
*/
|
|
736
|
+
type SearchResultActionResponse = {
|
|
737
|
+
/**
|
|
738
|
+
* URL that Here™ should navigate to.
|
|
739
|
+
*/
|
|
740
|
+
url: string;
|
|
741
|
+
} | undefined;
|
|
742
|
+
|
|
743
|
+
type Agent = {
|
|
744
|
+
/**
|
|
745
|
+
* The features supported by the Agent.
|
|
746
|
+
*/
|
|
747
|
+
features: AgentFeatures;
|
|
748
|
+
/**
|
|
749
|
+
* Joins the agent to a specific interop channel.
|
|
750
|
+
*
|
|
751
|
+
* @throws {InteropFeatureNotSupportedError} if the interop feature is not supported by the agent.
|
|
752
|
+
*/
|
|
753
|
+
joinInteropChannel: (channelName: InteropColorChannel) => Promise<void>;
|
|
754
|
+
/**
|
|
755
|
+
* Sets whether or not the Agent is ready.
|
|
756
|
+
*
|
|
757
|
+
* @param ready Whether the Agent is ready (defaults to `true`).
|
|
758
|
+
*/
|
|
759
|
+
setIsReady: (ready?: boolean) => Promise<void>;
|
|
760
|
+
};
|
|
761
|
+
/**
|
|
762
|
+
* The features supported by the Agent.
|
|
763
|
+
*/
|
|
764
|
+
type AgentFeatures = {
|
|
765
|
+
interop?: {
|
|
766
|
+
defaultChannel?: InteropColorChannel;
|
|
767
|
+
fdc3Version: OpenFin$1.FDC3.Version;
|
|
768
|
+
};
|
|
769
|
+
search?: {
|
|
770
|
+
filters?: AgentSearchFilter[];
|
|
771
|
+
supportsPaging: boolean;
|
|
772
|
+
};
|
|
773
|
+
};
|
|
774
|
+
/**
|
|
775
|
+
* Configuration provided when registering a Agent.
|
|
776
|
+
*/
|
|
777
|
+
type AgentRegistrationConfig = {
|
|
778
|
+
/**
|
|
779
|
+
* Search configuration required if the Agent supports search functionality.
|
|
780
|
+
*/
|
|
781
|
+
search?: {
|
|
782
|
+
/**
|
|
783
|
+
* This listener is called when the Agent receives an action from Here™’s search UI that has been triggered by the user on one of the Agent’s search results.
|
|
784
|
+
*
|
|
785
|
+
* The listener returns a response back to Here™ that includes a URL to navigate to.
|
|
786
|
+
*/
|
|
787
|
+
onAction: OnSearchActionListener;
|
|
788
|
+
/**
|
|
789
|
+
* This listener is called when the Agent receives a query from Here™’s search UI and returns relevant search results.
|
|
790
|
+
*
|
|
791
|
+
* Note: When the Agent is not ready this listener will not be called.
|
|
792
|
+
*/
|
|
793
|
+
onSearch: OnSearchRequestListener;
|
|
794
|
+
};
|
|
795
|
+
};
|
|
796
|
+
/**
|
|
797
|
+
* A filter that can be applied to the Agent’s search results.
|
|
798
|
+
*/
|
|
799
|
+
type AgentSearchFilter = {
|
|
800
|
+
icon?: string | {
|
|
801
|
+
dark: string;
|
|
802
|
+
light: string;
|
|
803
|
+
};
|
|
804
|
+
id: string;
|
|
805
|
+
title: string;
|
|
806
|
+
};
|
|
807
|
+
type InteropColorChannel = 'blue' | 'indigo' | 'pink' | 'teal' | 'green' | 'orange' | 'red' | 'yellow' | 'gray' | 'none';
|
|
808
|
+
|
|
809
|
+
/**
|
|
810
|
+
* Retrieves the Agent’s configuration data, as has been configured in the Here™ Admin Console.
|
|
811
|
+
*
|
|
812
|
+
* @returns A promise that resolves with an object containing properties that match the Agent’s configuration.
|
|
813
|
+
*
|
|
814
|
+
* @example Retrieving the Agent’s configuration data:
|
|
815
|
+
* ```ts
|
|
816
|
+
* import { Agent } from "@openfin/cloud-api";
|
|
817
|
+
*
|
|
818
|
+
* // Get the configuration data
|
|
819
|
+
* const configData = await Agent.getConfiguration<{ customField1: string, customField2: string }>();
|
|
820
|
+
*
|
|
821
|
+
* // Pick out the standard configuration properties
|
|
822
|
+
* const { customData, description, id, title, url } = configData;
|
|
823
|
+
*
|
|
824
|
+
* // Pick out the custom configuration properties
|
|
825
|
+
* if (customData) {
|
|
826
|
+
* const { customField1, customField2 } = customData;
|
|
827
|
+
* }
|
|
828
|
+
* ```
|
|
829
|
+
*/
|
|
830
|
+
declare const getConfiguration: <T extends Record<string, unknown>>() => Promise<T>;
|
|
831
|
+
/**
|
|
832
|
+
* Registers an Agent.
|
|
833
|
+
*
|
|
834
|
+
* @param config The configuration for the Agent.
|
|
835
|
+
*
|
|
836
|
+
* @returns A promise that resolves with the Agent.
|
|
837
|
+
*
|
|
838
|
+
* @example Registering an Agent that will provide search results:
|
|
839
|
+
* ```ts
|
|
840
|
+
* import { Agent } from "@openfin/cloud-api";
|
|
841
|
+
*
|
|
842
|
+
* // Handle incoming action and return a response that includes the URL to navigate to
|
|
843
|
+
* const onAction: Agent.OnSearchActionListener = (action, result) => {
|
|
844
|
+
* const { name } = action;
|
|
845
|
+
* const { data, key } = result;
|
|
846
|
+
* const { owner, searchResultHostUrl } = data as { owner: { id: string, name: string }, searchResultHostUrl: string };
|
|
847
|
+
* const { id: ownerId } = owner;
|
|
848
|
+
*
|
|
849
|
+
* console.log(`Action "${name}" triggered on search result with key "${key}"`);
|
|
850
|
+
*
|
|
851
|
+
* switch (name) {
|
|
852
|
+
* case "view-owner":
|
|
853
|
+
* return { url: `${searchResultHostUrl}/people/${ownerId}` };
|
|
854
|
+
* case "view-result":
|
|
855
|
+
* return { url: `${searchResultHostUrl}/record/${key}` };
|
|
856
|
+
* default:
|
|
857
|
+
* console.warn(`Unknown action: ${name}`);
|
|
858
|
+
* }
|
|
859
|
+
* };
|
|
860
|
+
*
|
|
861
|
+
* // Handle incoming search request and return relevant search results
|
|
862
|
+
* const onSearch: Agent.OnSearchRequestListener = ({ context, query, signal }) => {
|
|
863
|
+
* const { pageNumber, pageSize } = context;
|
|
864
|
+
* try {
|
|
865
|
+
* let results: Agent.SearchResult[] = [];
|
|
866
|
+
* const url = `https://my-web-app.com/search?q=${query}&page=${pageNumber}&limit=${pageSize}`;
|
|
867
|
+
* const response = await fetch(url, { signal });
|
|
868
|
+
* if (!response.ok) {
|
|
869
|
+
* throw new Error(`Request failed: ${response.status}`);
|
|
870
|
+
* }
|
|
871
|
+
* const { searchResults } = await response.json();
|
|
872
|
+
* results = searchResults.map((result) => {
|
|
873
|
+
* const { iconUrl, id: key, owner, subTitle, title } = result;
|
|
874
|
+
* const { name: ownerName } = owner as { id: string, name: string };
|
|
875
|
+
* return {
|
|
876
|
+
* actions: [
|
|
877
|
+
* {
|
|
878
|
+
* name: "view-result",
|
|
879
|
+
* description: `Go to ${title} in My Web App`,
|
|
880
|
+
* },
|
|
881
|
+
* {
|
|
882
|
+
* name: "view-owner",
|
|
883
|
+
* description: `Go to ${ownerName} in My Web App`,
|
|
884
|
+
* title: "View Owner",
|
|
885
|
+
* },
|
|
886
|
+
* ],
|
|
887
|
+
* data: {
|
|
888
|
+
* owner,
|
|
889
|
+
* searchResultHostUrl: `https://my-web-app.com`,
|
|
890
|
+
* },
|
|
891
|
+
* icon: iconUrl,
|
|
892
|
+
* key,
|
|
893
|
+
* label: subTitle,
|
|
894
|
+
* title,
|
|
895
|
+
* };
|
|
896
|
+
* });
|
|
897
|
+
* console.log("Returning results", results);
|
|
898
|
+
* return { results };
|
|
899
|
+
* } catch (err) {
|
|
900
|
+
* if ((err as Error).name === "AbortError") {
|
|
901
|
+
* // Ignore errors for cancelled requests
|
|
902
|
+
* return { results: [] };
|
|
903
|
+
* }
|
|
904
|
+
* throw err;
|
|
905
|
+
* }
|
|
906
|
+
* };
|
|
907
|
+
*
|
|
908
|
+
* // Register the agent
|
|
909
|
+
* const agent = await Agent.register({ search: { onAction, onSearch } });
|
|
910
|
+
*
|
|
911
|
+
* // Set the Agent as ready to receive requests
|
|
912
|
+
* await agent.isReady();
|
|
913
|
+
* ```
|
|
535
914
|
*/
|
|
536
|
-
declare function register(config:
|
|
915
|
+
declare function register(config: AgentRegistrationConfig): Promise<Agent>;
|
|
537
916
|
|
|
538
|
-
type
|
|
539
|
-
type
|
|
540
|
-
type
|
|
541
|
-
type
|
|
542
|
-
type
|
|
917
|
+
type index_Agent = Agent;
|
|
918
|
+
type index_AgentFeatures = AgentFeatures;
|
|
919
|
+
type index_AgentRegistrationConfig = AgentRegistrationConfig;
|
|
920
|
+
type index_AgentSearchFilter = AgentSearchFilter;
|
|
921
|
+
type index_InteropColorChannel = InteropColorChannel;
|
|
922
|
+
type index_OnSearchActionListener = OnSearchActionListener;
|
|
923
|
+
type index_OnSearchRequestListener = OnSearchRequestListener;
|
|
543
924
|
type index_SearchListenerRequest = SearchListenerRequest;
|
|
544
|
-
|
|
545
|
-
type index_SearchResponse = SearchResponse;
|
|
546
|
-
type index_SearchResult = SearchResult;
|
|
547
|
-
type index_SearchResultActionResponse = SearchResultActionResponse;
|
|
925
|
+
declare const index_getConfiguration: typeof getConfiguration;
|
|
548
926
|
declare const index_register: typeof register;
|
|
549
927
|
declare namespace index {
|
|
550
|
-
export { type
|
|
928
|
+
export { type index_Agent as Agent, type index_AgentFeatures as AgentFeatures, type index_AgentRegistrationConfig as AgentRegistrationConfig, type index_AgentSearchFilter as AgentSearchFilter, type index_InteropColorChannel as InteropColorChannel, type index_OnSearchActionListener as OnSearchActionListener, type index_OnSearchRequestListener as OnSearchRequestListener, type index_SearchListenerRequest as SearchListenerRequest, index_getConfiguration as getConfiguration, index_register as register };
|
|
551
929
|
}
|
|
552
930
|
|
|
553
931
|
declare global {
|
|
@@ -556,4 +934,4 @@ declare global {
|
|
|
556
934
|
}
|
|
557
935
|
}
|
|
558
936
|
|
|
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 };
|
|
937
|
+
export { index as Agent, type AppPermissions, type LaunchContentOptions, index$1 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 };
|
package/dist/index.js
CHANGED
|
@@ -1,2 +1,2 @@
|
|
|
1
|
-
var He=Object.create;var Cn=Object.defineProperty;var Ke=Object.getOwnPropertyDescriptor;var Ge=Object.getOwnPropertyNames;var je=Object.getPrototypeOf,Xe=Object.prototype.hasOwnProperty;var ze=(o,c)=>()=>(c||o((c={exports:{}}).exports,c),c.exports),Je=(o,c)=>{for(var s in c)Cn(o,s,{get:c[s],enumerable:!0})},Qe=(o,c,s,d)=>{if(c&&typeof c=="object"||typeof c=="function")for(let p of Ge(c))!Xe.call(o,p)&&p!==s&&Cn(o,p,{get:()=>c[p],enumerable:!(d=Ke(c,p))||d.enumerable});return o};var Ye=(o,c,s)=>(s=o!=null?He(je(o)):{},Qe(c||!o||!o.__esModule?Cn(s,"default",{value:o,enumerable:!0}):s,o));var jn=ze((Lt,Gn)=>{"use strict";(()=>{"use strict";var o={d:(n,e)=>{for(var t in e)o.o(e,t)&&!o.o(n,t)&&Object.defineProperty(n,t,{enumerable:!0,get:e[t]})},o:(n,e)=>Object.prototype.hasOwnProperty.call(n,e),r:n=>{typeof Symbol<"u"&&Symbol.toStringTag&&Object.defineProperty(n,Symbol.toStringTag,{value:"Module"}),Object.defineProperty(n,"__esModule",{value:!0})}},c={};o.r(c),o.d(c,{SearchTagBackground:()=>sn,create:()=>Bn,defaultTopic:()=>Vn,subscribe:()=>Mn});var s={};o.r(s),o.d(s,{B:()=>we});var d={};o.r(d),o.d(d,{v:()=>Be});let p="deregistered or does not exist",y=new Error(`provider ${p}`),P=new Error("provider with name already exists"),S=new Error("bad payload"),b=new Error("subscription rejected"),O=new Error(`channel ${p}`),R;function I(){if(R)return R;throw O}function K(){return R}function Rn(n){R=n}var $;(function(n){n.Local="local",n.Dev="dev",n.Staging="staging",n.Prod="prod"})($||($={}));let on=typeof window<"u"&&typeof fin<"u",Yn=(typeof process>"u"||process.env,typeof window<"u"),Zn=Yn?window.origin:$.Local,G=(on&&fin.me.uuid,on&&fin.me.name,on&&fin.me.entityType,$.Local,$.Dev,$.Staging,$.Prod,n=>n.startsWith("http://")||n.startsWith("https://")?n:Zn+n),En=(G("http://localhost:4002"),G("http://localhost:4002"),typeof WORKSPACE_DOCS_PLATFORM_URL<"u"&&G(WORKSPACE_DOCS_PLATFORM_URL),typeof WORKSPACE_DOCS_CLIENT_URL<"u"&&G(WORKSPACE_DOCS_CLIENT_URL),"20.1.1");typeof WORKSPACE_BUILD_SHA<"u"&&WORKSPACE_BUILD_SHA;var j,bn;(function(n){n.Workspace="openfin-workspace",n.OldWorkspace="openfin-browser"})(j||(j={})),function(n){n.FinProtocol="fin-protocol"}(bn||(bn={})),j.Workspace;var v,x,rn,sn;(function(n){n[n.Initial=0]="Initial",n[n.Open=1]="Open",n[n.Close=2]="Close"})(v||(v={})),function(n){n.Fetching="fetching",n.Fetched="fetched",n.Complete="complete"}(x||(x={})),function(n){n.UserAction="user-action",n.FocusChange="focus-change",n.Reload="reload"}(rn||(rn={})),function(n){n.Active="active",n.Default="default"}(sn||(sn={}));let On=`__search-${`${j.OldWorkspace}-home`}-topic__`,X="0",Pn="1",An="2",In="3",Ln="4",z="5",J="6",ne=()=>{},an=new Set;function ee(n){an.add(n)}function te(n){an.delete(n)}let cn=new Set;function oe(n){cn.add(n)}function ie(n){cn.delete(n)}let q=new Map;async function ln(n){q.set(n.id,n);let e=[...an].map(t=>t());await Promise.all(e)}async function Q(n){q.delete(n);let e=[...cn].map(t=>t());await Promise.all(e)}function un(){return[...q.values()]}function Nn(){q.clear()}function L(n){return q.get(n)}function Fn(n,e,t){return{...n,action:t||{...n.actions[0],trigger:rn.UserAction},dispatcherIdentity:e}}function dn(n,e,t="ascending"){let i=n||[];if(!e?.length)return i;let r=[],a=new Map;e.forEach(u=>{if(u.key)return a.set(u.key,u);r.push(u)});let l=i.map(u=>{let{key:h}=u;if(h&&a.has(h)){let C=a.get(h);return a.delete(h),C}return u});return l.push(...a.values(),...r),l=t==="ascending"?l.sort((u,h)=>(u?.score??1/0)-(h?.score??1/0)):l.sort((u,h)=>(h?.score??1/0)-(u?.score??1/0)),l}function kn(n){let e={},t=[],i=[],r=null,a=v.Initial;e.getStatus=()=>a,e.getResultBuffer=()=>t,e.setResultBuffer=u=>{t=u,t?.length&&e.onChange()},e.getRevokedBuffer=()=>i,e.setRevokedBuffer=u=>{i=u,i?.length&&e.onChange()},e.setUpdatedContext=u=>{r=u,e.onChange()},e.getUpdatedContext=()=>r,e.onChange=ne;let l={};return e.res=l,l.close=()=>{a!==v.Close&&(a=v.Close,e.onChange())},l.open=()=>{a!==v.Open&&(a=v.Open,e.onChange())},l.respond=u=>{let h=dn(e.getResultBuffer(),u,n);e.setResultBuffer(h)},l.revoke=(...u)=>{let h=new Set(u),C=e.getResultBuffer().filter(({key:f})=>{let g=h.has(f);return g&&h.delete(f),!g});e.setResultBuffer(C),h.size&&(e.getRevokedBuffer().forEach(f=>h.add(f)),e.setRevokedBuffer([...h]))},l.updateContext=u=>{e.setUpdatedContext(u)},e}function $n(n,e){let t=new Set,i=!1;return{close:()=>{i=!0;for(let r of t)r()},req:{id:n,...e,context:e?.context||{},onClose:r=>{t.add(r),i&&r()},removeListener:r=>{t.delete(r)}}}}function Y(){return{name:fin.me.name,uuid:fin.me.uuid}}let xn=50,re=1e3,se=new Map;function pn(){return se}let ae=100;function ce(){return async n=>{if(!n||!n.id||!n.providerId){let f=S;return console.error(f),{error:f.message}}let{id:e,providerId:t}=n,i=L(t);if(!i){let f=y;return console.error(f),{error:f.message}}let r=pn(),a=r.get(n.id);a||(a=$n(e,n),r.set(n.id,a));let l=kn(),u=()=>{let f=l.getResultBuffer();l.setResultBuffer([]);let g=l.getRevokedBuffer();l.setRevokedBuffer([]);let N=l.getUpdatedContext();l.setUpdatedContext(null);let _=l.getStatus();(async function(D){(await I()).dispatch(X,D)})({id:e,providerId:t,results:f,revoked:g,status:_,context:N})},h=!0,C=!1;l.onChange=()=>{if(h)return h=!1,void u();C||(C=!0,setTimeout(()=>{C=!1,u()},ae))};try{let{results:f,context:g}=await i.onUserInput(a.req,l.res),N=l.getStatus();return{id:e,providerId:t,status:N,results:f,context:g}}catch(f){return console.error(`OpenFin/Workspace/Home. Uncaught exception in search provider ${t} for search ${e}`,"This is likely a bug in the implementation of the search provider.",f),{id:e,providerId:t,error:f?.message}}}}async function _n(n,e){let t=e||await I(),i=Y(),r={...n,identity:i,onResultDispatch:void 0},a=await t.dispatch(An,r);return await ln({identity:i,...n}),a}async function le(n){return await(await I()).dispatch(In,n),Q(n)}async function ue(n,e,t,i){let r=Fn(e,i??Y(),t),a=L(n);if(a){let{onResultDispatch:u}=a;return u?u(r):void 0}let l={providerId:n,result:r};return(await I()).dispatch(z,l)}async function de(n){let e={...n,context:n?.context||{}},t={},i=async function*(a,{setState:l}){let u=await I();for(;;){let h=await u.dispatch(Pn,a),C=h.error;if(C)throw new Error(C);let f=h;if(a.id=f.id,l(f.state),f.done)return f.value;yield f.value}}(e,{setState:a=>{t.state=a}}),r=await i.next();return t.id=e.id||"",t.close=()=>{(async function(a){(await I()).dispatch(J,{id:a})})(t.id)},t.next=()=>{if(r){let a=r;return r=void 0,a}return i.next()},t}async function pe(){return(await I()).dispatch(Ln,null)}async function fe(){let n=await I();R=void 0,Nn(),await n.disconnect()}let he=async()=>{let n=await Tn();for(let e of un())await _n(e,n);return n};async function Tn(){let n=await async function(e){for(let t=0;t<xn;t++)try{return await fin.InterApplicationBus.Channel.connect(e,{wait:!1})}catch(i){if(t===xn-1)throw i;await new Promise(r=>setTimeout(r,re))}}(On);return n.register(X,ce()),n.register(J,e=>{let t=pn(),i=t.get(e.id);i&&(i.close(),t.delete(e.id))}),n.register(z,async(e,t)=>{if(!e||!e.providerId||!e.result)return void console.error(S);let i=L(e.providerId);if(!i)return void console.error(y);let{onResultDispatch:r}=i;return r?(e.result.dispatcherIdentity=e.result.dispatcherIdentity??t,r(e.result)):void 0}),n.onDisconnection(async()=>{if(!K())return;let e=pn();for(let{req:t,close:i}of e.values())i(),e.delete(t.id);Rn(he())}),n}async function we(){let n=K();n||(n=Tn(),Rn(n));let e=await n;return{getAllProviders:pe.bind(null),register:_n.bind(null),search:de.bind(null),deregister:le.bind(null),dispatch:ue.bind(null),disconnect:fe.bind(null),channel:e}}let H;function Z(){if(H)return H;throw O}function ge(){return H}function ye(n){H=n}function me(){H=void 0}let fn=new Set;function Ce(n){fn.add(n)}function ve(n){fn.delete(n)}async function Un(){return[...un()].map(n=>({...n,onUserInput:void 0,onResultDispatch:void 0}))}async function Se(n){if(L(n.id))throw new Error("provider with name already exists");let e=Y();return await ln({identity:e,...n}),{workspaceVersion:En||"",clientAPIVersion:n.clientAPIVersion||""}}async function Re(n){await Q(n)}async function Ee(n,e,t,i){let r=L(n);if(!r)throw y;let{onResultDispatch:a}=r;if(a)return a(Fn(e,i??Y(),t))}async function*be(n,e){let t=function(g,N){let _=[],D=[],W=[],E=[];for(let m of g){let F=kn(m.scoreOrder),k={results:[],provider:{id:m.id,identity:m.identity,title:m.title,scoreOrder:m.scoreOrder,icon:m.icon,dispatchFocusEvents:m.dispatchFocusEvents}};_.push(k),D.push(F);let B=(async()=>{try{let{results:M,context:en}=await m.onUserInput(N,F.res);k.results=dn(k.results||[],M,m.scoreOrder),k.context={...k.context,...en}}catch(M){k.error=M}})();B.finally(()=>{B.done=!0}),E.push(B),W.push(W.length)}return{providerResponses:_,listenerResponses:D,openListenerResponses:W,initialResponsePromises:E}}(n.targets?n.targets.map(g=>L(g)).filter(g=>!!g):[...un().filter(g=>!g.hidden)],n),{providerResponses:i,listenerResponses:r}=t,{openListenerResponses:a,initialResponsePromises:l}=t,u=x.Fetching,h=g=>{u=g,e.setState(u)},C,f=!1;n.onClose(()=>{f=!0,C&&C()});do{let g=!1;if(l.length){let E=[];for(let m of l)m.done?g=!0:E.push(m);l=E,l.length||(h(x.Fetched),g=!0)}let N,_=!1,D=()=>{_=!0,N&&N()},W=[];for(let E of a){let m=r[E],F=i[E],k=m.getStatus();(k===v.Open||u===x.Fetching&&k===v.Initial)&&(W.push(E),m.onChange=D);let B=m.getResultBuffer();B.length&&(m.setResultBuffer([]),F.results=dn(F.results||[],B),g=!0);let M=m.getRevokedBuffer();if(M.length){m.setRevokedBuffer([]);let Ve=new Set(M);F.results=(F.results||[]).filter(({key:qe})=>!Ve.has(qe)),g=!0}let en=m.getUpdatedContext();en&&(m.setUpdatedContext(null),F.context={...F.context,...en},g=!0)}if(a=W,g&&(yield i),f)break;_||(a.length||l.length)&&await Promise.race([...l,new Promise(E=>{N=E}),new Promise(E=>{C=E})])}while(a.length||l.length);return h(x.Complete),i}let hn=0;async function Dn(n){hn+=1;let e=$n(hn.toString(),n),t=be(e.req,{setState:i=>{t.state=i}});return t.id=hn.toString(),t.close=e.close,t.state=x.Fetching,t}let nn=new Map,Oe=1e4;function Pe(){return async n=>{if(!n)return console.error(S),{error:S.message};let e;if(n.id)e=n.id;else{let r=await Dn(n);e=r.id,n.id=r.id,nn.set(e,{generator:r})}let t=nn.get(e);clearTimeout(t.timeout);let i=await t.generator.next();return t.timeout=function(r){return window.setTimeout(()=>{nn.delete(r)},Oe)}(e),{...i,id:n.id,state:t.generator.state}}}function Ae(n,e){return Z().dispatch(n,J,{id:e})}function Ie(){return n=>function(e){let t=nn.get(e);t&&t.generator.close()}(n.id)}async function Le(n,{id:e,query:t,context:i,targets:r=[]}){let a=Z(),l={id:e,query:t,context:i,targets:r,providerId:n.id},u=await a.dispatch(n.identity,X,l),h=u.error;if(h)throw new Error(h);return u}let wn=new Map;function Ne(n,e){return`${n.name}:${n.uuid}:${e}`}let gn=new Map;function Wn(n,e){return`${n}:${e}`}function Fe(n){let e=Ne.bind(null,n.identity),t=Ae.bind(null,n.identity),i=Le.bind(null,n);return async(r,a)=>{let l=e(r.id);if(!wn.has(l)){let f=()=>{t(r.id),wn.delete(l)};wn.set(l,f),r.onClose(f)}let u=Wn(n.id,r.id),h=()=>{gn.delete(u),a.close()};r.onClose(h),gn.set(u,f=>{f.results?.length&&a.respond(f.results),f.revoked?.length&&a.revoke(...f.revoked),f.context&&a.updateContext(f.context),f.status===v.Open&&a.open(),f.status===v.Close&&h()});let C=await i(r);return C.status===v.Open&&a.open(),C.status!==v.Close&&C.status!==v.Initial||h(),C}}function ke(n){return async e=>{let t=Z(),i={providerId:n.id,result:e};return t.dispatch(n.identity,z,i)}}let U=new Map;function yn(n){return`${n.name}-${n.uuid}`}function $e(){return async(n,e)=>{if(!n||!n.id)return console.error(new Error(JSON.stringify(n))),void console.error(S);if(L(n.id))throw P;return n.identity=e,await async function(t){let i=yn(t.identity);U.has(i)||U.set(i,[]),U.get(i).push(t.id),await ln({...t,onUserInput:Fe(t),onResultDispatch:ke(t)})}(n),{workspaceVersion:En||"",clientAPIVersion:n.clientAPIVersion||""}}}function xe(){return(n,e)=>{n?function(t,i){let r=L(t);if(!r)return;if(r.identity.uuid!==i.uuid||r.identity.name!==i.name)throw y;let a=yn(r.identity),l=U.get(a);if(l){let u=l.findIndex(h=>h===t);u!==-1&&(l.splice(u,1),Q(t))}}(n,e):console.error(S)}}let mn=new Set;function _e(n){mn.add(n)}function Te(n){mn.delete(n)}function Ue(){return async n=>{(function(e){let t=yn(e),i=U.get(t);if(i){for(let r of i)Q(r);U.delete(t)}})(n),mn.forEach(e=>e(n))}}async function De(){let n=await(e=On,fin.InterApplicationBus.Channel.create(e));var e;return n.onConnection(async t=>{for(let i of fn)if(!await i(t))throw b}),n.onDisconnection(Ue()),n.register(J,Ie()),n.register(X,t=>{let i=Wn(t.providerId,t.id),r=gn.get(i);r&&r(t)}),n.register(An,$e()),n.register(In,xe()),n.register(Ln,async()=>Un()),n.register(Pn,Pe()),n.register(z,async(t,i)=>{if(!t||!t.providerId||!t.result)return void console.error(S);let r=L(t.providerId);if(!r)throw y;let{onResultDispatch:a}=r;return a?(t.result.dispatcherIdentity=t.result.dispatcherIdentity??i,a(t.result)):void 0}),n}async function We(){let n=Z();me(),await n.destroy(),Nn()}async function Be(){let n=ge();n||(n=await De(),ye(n));let e=ve.bind(null),t=Te.bind(null),i=te.bind(null),r=ie.bind(null);return{getAllProviders:Un.bind(null),search:Dn.bind(null),register:Se.bind(null),deregister:Re.bind(null),onSubscription:Ce.bind(null),onDisconnect:_e.bind(null),onRegister:ee.bind(null),onDeregister:oe.bind(null),dispatch:Ee.bind(null),disconnect:We.bind(null),removeListener:a=>{e(a),t(a),i(a),r(a)},channel:n}}let{v:Bn}=d,{B:Mn}=s,Vn="all",Me={create:Bn,subscribe:Mn,defaultTopic:Vn},qn=()=>{window.search=Me},Hn=n=>{let e=()=>{qn(),window.removeEventListener(n,e)};return e};if(typeof window<"u"){qn();let n="load",e=Hn(n);window.addEventListener(n,e);let t="DOMContentLoaded",i=Hn(t);window.addEventListener(t,i)}Gn.exports=c})()});var w="@openfin/cloud-api";async function A(){try{return await window.fin.View.getCurrentSync().getInfo(),!0}catch{return!1}}function Kn(o){if(o.name.startsWith("internal-generated"))throw new Error("Cannot extract app UUID from identity");return/\/[\d,a-z-]{36}$/.test(o.name)?o.name.split("/")[0]||"":o.name}var V="@openfin/cloud-api";function Ze(){return`${window.fin.me.uuid}-cloud-api-notifications`}var vn=null;async function mt(){return vn||(vn=nt()),vn}async function nt(){if(!window.fin)throw new Error(`\`${V}\`: \`getNotificationsClient\` cannot be used in a non-OpenFin environment`);if(await A()===!1)throw new Error(`${V}: \`getNotificationsClient\` cannot be used in a non-OpenFin environment`);Kn(window.fin.me);let o=await et();console.log(o),o.register("openfin-cloud-event",s=>{for(let d of c.get(s.type)??[])typeof s.payload.timestamp=="string"&&(s.payload.timestamp=new Date(s.payload.timestamp)),d(s.payload)});let c=new Map;return{addEventListener:(s,d)=>{let p=c.get(s)||new Set;p.add(d),c.set(s,p)},removeEventListener:(s,d)=>{let p=c.get(s);if(!p){console.warn(`\`${V}\`: Listener was not found for event. Did you pass a function directly instead of a reference or forget to add the listener?`,s);return}p.delete(d)===!1&&console.warn(`\`${V}\`: Listener was not found for event. Did you pass a function directly instead of a reference?`,s)},update:async s=>(await o.dispatch("openfin-cloud-update-notification",{version:1,payload:{notification:s}})).payload.response,clear:async s=>(await o.dispatch("openfin-cloud-clear-notification",{version:1,payload:{notificationId:s}})).payload.response,createNotification:async s=>(s.id&&console.warn(`\`${V}\`: The \`id\` property is not supported and will be ignored. If you need to use the \`id\` property, you should use the \`id\` property of the returned notification object.`),(await o.dispatch("openfin-cloud-create-notification",{version:1,payload:{notification:{...s,id:void 0}}})).payload.response)}}var tn=null;async function et(){return tn||(tn=tt()),tn}async function tt(){let o=await window.fin.InterApplicationBus.Channel.connect(Ze());return o.onDisconnection(c=>{console.warn(`\`${V}\`: Channel Disconnected from`,c,"Reconnecting..."),tn=null}),o}var Sn;function ot(){return`${window.fin.me.uuid}-client-api`}async function T(){return Sn||(Sn=window.fin.InterApplicationBus.Channel.connect(ot())),Sn}async function St(){if(!window.fin)throw new Error(`\`${w}\`: \`getAppSettings\` cannot be used in a non-OpenFin environment`);if(await A()===!1)throw new Error(`${w}: \`getAppSettings\` cannot be used in a non-OpenFin environment`);return(await T()).dispatch("get-settings")}async function Rt(){if(!window.fin)throw new Error(`\`${w}\`: \`getAppUserSettings\` cannot be used in a non-OpenFin environment`);if(await A()===!1)throw new Error(`${w}: \`getAppUserSettings\` cannot be used in a non-OpenFin environment`);return(await T()).dispatch("get-user-settings")}async function Et(o){if(!window.fin)throw new Error(`\`${w}\`: \`setAppUserSettings\` cannot be used in a non-OpenFin environment`);if(await A()===!1)throw new Error(`${w}: \`setAppUserSettings\` cannot be used in a non-OpenFin environment`);return(await T()).dispatch("set-user-settings",o)}async function bt(){if(!window.fin)throw new Error(`\`${w}\`: \`getAppUserPermissions\` cannot be used in a non-OpenFin environment`);if(await A()===!1)throw new Error(`${w}: \`getAppUserPermissions\` cannot be used in a non-OpenFin environment`);return(await T()).dispatch("get-user-permissions")}async function Ot(o,c){if(!window.fin)throw new Error(`\`${w}\`: \`launchContent\` cannot be used in a non-OpenFin environment`);if(await A()===!1)throw new Error(`${w}: \`launchContent\` cannot be used in a outside of an OpenFin View context`);let s=await T();try{await s.dispatch("launch-content",{id:o,options:c})}catch(d){switch(d instanceof Error?d.message:String(d)){case"UnableToLookup":throw new Error(`${w}: \`launchContent\` was unable to lookup content with id: ${o}`);case"UnableToLaunch":throw new Error(`${w}: \`launchContent\` was unable to launch content with id: ${o}`);case"NoContentFound":throw new Error(`${w}: \`launchContent\` did not find content with id: ${o}`);default:throw new Error(`${w}: \`launchContent\` was unable to look up or launch content with id: ${o} or the content did not exist.`)}}}async function Pt(o){if(!window.fin)throw new Error(`\`${w}\`: \`launchSupertab\` cannot be used in a non-OpenFin environment`);if(await A()===!1)throw new Error(`${w}: \`launchSupertab\` cannot be used in a outside of an OpenFin View context`);let c=await T();try{await c.dispatch("launch-supertab",{id:o})}catch(s){switch(s instanceof Error?s.message:String(s)){case"UnableToLookup":throw new Error(`${w}: \`launchSupertab\` was unable to lookup content with id: ${o}`);case"UnableToLaunch":throw new Error(`${w}: \`launchSupertab\` was unable to launch content with id: ${o}`);case"NoContentFound":throw new Error(`${w}: \`launchSupertab\` did not find content with id: ${o}`);default:throw new Error(`${w}: \`launchSupertab\` was unable to look up or launch content with id: ${o} or the content did not exist.`)}}}async function At(o){if(!window.fin)throw new Error(`\`${w}\`: \`launchWorkspace\` cannot be used in a non-OpenFin environment`);if(await A()===!1)throw new Error(`${w}: \`launchWorkspace\` cannot be used in a outside of an OpenFin View context`);let c=await T();try{await c.dispatch("launch-workspace",{id:o})}catch(s){switch(s instanceof Error?s.message:String(s)){case"UnableToLookup":throw new Error(`${w}: \`launchWorkspace\` was unable to lookup content with id: ${o}`);case"UnableToLaunch":throw new Error(`${w}: \`launchWorkspace\` was unable to launch content with id: ${o}`);case"NoContentFound":throw new Error(`${w}: \`launchWorkspace\` did not find content with id: ${o}`);default:throw new Error(`${w}: \`launchWorkspace\` was unable to look up or launch content with id: ${o} or the content did not exist.`)}}}var Qn={};Je(Qn,{register:()=>Jn});var zn=Ye(jn(),1),it="log-message-",rt="open-url",st="provider-status-",at="registered-",ct="1.0";function lt(o,c){let{data:s,...d}=o;return{...d,data:{customData:s,providerId:c,resultType:"app"}}}function Xn(o){return{...o,data:o.data.customData}}async function ut(o,c,s,d=!0){await c("info",`Setting status as ${d?"ready":"not ready"}`);try{await o.dispatch(`${st}${s}`,{isReady:d})}catch(p){let y=["Error setting provider status",p];console.error(...y),c("error",...y)}}async function dt(o,c,s,...d){try{await o.dispatch(`${it}${c}`,{level:s,message:d})}catch(p){console.error("Error logging message",p)}}async function pt(o,c,s,d,p){let{action:y,dispatcherIdentity:P,...S}=p;await s("info","Handling action",{action:y,dispatcherIdentity:P,result:S});let b;try{let R=Xn(p).actions?.find(({name:K})=>K===y.name);if(!R)throw new Error("Original action not found in search result");b=(await d(R,Xn(p)))?.url}catch(O){throw await s("error","Error handling dispatch",O),O}if(!b){await s("warn","OnActionListener did not return a URL");return}await ht(o,s,c.id,b,P)}async function ft(o,c,s,d){await c("info","Getting search results",{request:d});try{let p=new AbortController;d.onClose(()=>p.abort());let{context:y,query:P}=d,{results:S}=await s({context:y,query:P,signal:p.signal}),b=S.map(O=>lt(O,o.id));return await c("info","Returning results",b),{results:b}}catch(p){let y=["Error handling search",p];throw console.error(...y),c("error",...y),p}}async function ht(o,c,s,d,p){await c("info","Opening URL",{url:d,targetIdentity:p});try{await o.dispatch(rt,{url:d,targetIdentity:p,providerId:s})}catch(y){let P=["Error opening URL",y];console.error(...P),c("error",...P)}}async function Jn(o){let s=(await window.fin.me.getOptions()).customData,{configData:d,id:p,title:y}=s,{onAction:P,onSearch:S}=o,b=await zn.subscribe(),O=b.channel,R=dt.bind(null,O,p);return await b.register({icon:"",id:p,onResultDispatch:pt.bind(null,O,s,R,P),onUserInput:ft.bind(null,s,R,S),title:y}),await b.channel.dispatch(`${at}${p}`,{version:ct}),R("info","Registered search topic",{id:p,title:y}),{customData:d,isReady:ut.bind(null,O,R,p)}}export{Qn as Search,St as getAppSettings,bt as getAppUserPermissions,Rt as getAppUserSettings,mt as getNotificationsClient,Ot as launchContent,Pt as launchSupertab,At as launchWorkspace,Et as setAppUserSettings};
|
|
1
|
+
var tt=Object.create;var En=Object.defineProperty;var ot=Object.getOwnPropertyDescriptor;var rt=Object.getOwnPropertyNames;var it=Object.getPrototypeOf,st=Object.prototype.hasOwnProperty;var at=(t,i)=>()=>(i||t((i={exports:{}}).exports,i),i.exports),Kn=(t,i)=>{for(var r in i)En(t,r,{get:i[r],enumerable:!0})},ct=(t,i,r,a)=>{if(i&&typeof i=="object"||typeof i=="function")for(let d of rt(i))!st.call(t,d)&&d!==r&&En(t,d,{get:()=>i[d],enumerable:!(a=ot(i,d))||a.enumerable});return t};var vn=(t,i,r)=>(r=t!=null?tt(it(t)):{},ct(i||!t||!t.__esModule?En(r,"default",{value:t,enumerable:!0}):r,t));var on=at((no,Xn)=>{"use strict";(()=>{"use strict";var t={d:(n,e)=>{for(var o in e)t.o(e,o)&&!t.o(n,o)&&Object.defineProperty(n,o,{enumerable:!0,get:e[o]})},o:(n,e)=>Object.prototype.hasOwnProperty.call(n,e),r:n=>{typeof Symbol<"u"&&Symbol.toStringTag&&Object.defineProperty(n,Symbol.toStringTag,{value:"Module"}),Object.defineProperty(n,"__esModule",{value:!0})}},i={};t.r(i),t.d(i,{SearchTagBackground:()=>cn,create:()=>Vn,defaultTopic:()=>jn,subscribe:()=>qn});var r={};t.r(r),t.d(r,{B:()=>Oe});var a={};t.r(a),t.d(a,{v:()=>Ye});let d="deregistered or does not exist",h=new Error(`provider ${d}`),m=new Error("provider with name already exists"),w=new Error("bad payload"),C=new Error("subscription rejected"),S=new Error(`channel ${d}`),P;function b(){if(P)return P;throw S}function H(){return P}function In(n){P=n}var O,x,an,cn;(function(n){n[n.Initial=0]="Initial",n[n.Open=1]="Open",n[n.Close=2]="Close"})(O||(O={})),function(n){n.Fetching="fetching",n.Fetched="fetched",n.Complete="complete"}(x||(x={})),function(n){n.UserAction="user-action",n.FocusChange="focus-change",n.Reload="reload"}(an||(an={})),function(n){n.Active="active",n.Default="default"}(cn||(cn={}));let K="0",Pn="1",bn="2",Nn="3",Ln="4",z="5",X="6",ue=()=>{},ln=new Set;function de(n){ln.add(n)}function pe(n){ln.delete(n)}let un=new Set;function fe(n){un.add(n)}function he(n){un.delete(n)}let j=new Map;async function dn(n){j.set(n.id,n);let e=[...ln].map(o=>o());await Promise.all(e)}async function J(n){j.delete(n);let e=[...un].map(o=>o());await Promise.all(e)}function pn(){return[...j.values()]}function Fn(){j.clear()}function L(n){return j.get(n)}function _n(n,e,o){return{...n,action:o||{...n.actions[0],trigger:an.UserAction},dispatcherIdentity:e}}function fn(n,e,o="ascending"){let s=n||[];if(!e?.length)return s;let c=[],l=new Map;e.forEach(p=>{if(p.key)return l.set(p.key,p);c.push(p)});let u=s.map(p=>{let{key:g}=p;if(g&&l.has(g)){let v=l.get(g);return l.delete(g),v}return p});return u.push(...l.values(),...c),u=o==="ascending"?u.sort((p,g)=>(p?.score??1/0)-(g?.score??1/0)):u.sort((p,g)=>(g?.score??1/0)-(p?.score??1/0)),u}function Tn(n){let e={},o=[],s=[],c=null,l=O.Initial;e.getStatus=()=>l,e.getResultBuffer=()=>o,e.setResultBuffer=p=>{o=p,o?.length&&e.onChange()},e.getRevokedBuffer=()=>s,e.setRevokedBuffer=p=>{s=p,s?.length&&e.onChange()},e.setUpdatedContext=p=>{c=p,e.onChange()},e.getUpdatedContext=()=>c,e.onChange=ue;let u={};return e.res=u,u.close=()=>{l!==O.Close&&(l=O.Close,e.onChange())},u.open=()=>{l!==O.Open&&(l=O.Open,e.onChange())},u.respond=p=>{let g=fn(e.getResultBuffer(),p,n);e.setResultBuffer(g)},u.revoke=(...p)=>{let g=new Set(p),v=e.getResultBuffer().filter(({key:f})=>{let R=g.has(f);return R&&g.delete(f),!R});e.setResultBuffer(v),g.size&&(e.getRevokedBuffer().forEach(f=>g.add(f)),e.setRevokedBuffer([...g]))},u.updateContext=p=>{e.setUpdatedContext(p)},e}function xn(n,e){let o=new Set,s=!1;return{close:()=>{s=!0;for(let c of o)c()},req:{id:n,...e,context:e?.context||{},onClose:c=>{o.add(c),s&&c()},removeListener:c=>{o.delete(c)}}}}function Q(){return{name:fin.me.name,uuid:fin.me.uuid}}let kn=50,ge=1e3,we=new Map;function hn(){return we}let ye=100;function me(){return async n=>{if(!n||!n.id||!n.providerId){let f=w;return console.error(f),{error:f.message}}let{id:e,providerId:o}=n,s=L(o);if(!s){let f=h;return console.error(f),{error:f.message}}let c=hn(),l=c.get(n.id);l||(l=xn(e,n),c.set(n.id,l));let u=Tn(),p=()=>{let f=u.getResultBuffer();u.setResultBuffer([]);let R=u.getRevokedBuffer();u.setRevokedBuffer([]);let F=u.getUpdatedContext();u.setUpdatedContext(null);let $=u.getStatus();(async function(M){(await b()).dispatch(K,M)})({id:e,providerId:o,results:f,revoked:R,status:$,context:F})},g=!0,v=!1;u.onChange=()=>{if(g)return g=!1,void p();v||(v=!0,setTimeout(()=>{v=!1,p()},ye))};try{let{results:f,context:R}=await s.onUserInput(l.req,u.res),F=u.getStatus();return{id:e,providerId:o,status:F,results:f,context:R}}catch(f){return console.error(`OpenFin/Workspace/Home. Uncaught exception in search provider ${o} for search ${e}`,"This is likely a bug in the implementation of the search provider.",f),{id:e,providerId:o,error:f?.message}}}}async function $n(n,e){let o=e||await b(),s=Q(),c={...n,identity:s,onResultDispatch:void 0},l=await o.dispatch(bn,c);return await dn({identity:s,...n}),l}async function Ce(n){return await(await b()).dispatch(Nn,n),J(n)}async function Se(n,e,o,s){let c=_n(e,s??Q(),o),l=L(n);if(l){let{onResultDispatch:p}=l;return p?p(c):void 0}let u={providerId:n,result:c};return(await b()).dispatch(z,u)}async function Re(n){let e={...n,context:n?.context||{}},o={},s=async function*(l,{setState:u}){let p=await b();for(;;){let g=await p.dispatch(Pn,l),v=g.error;if(v)throw new Error(v);let f=g;if(l.id=f.id,u(f.state),f.done)return f.value;yield f.value}}(e,{setState:l=>{o.state=l}}),c=await s.next();return o.id=e.id||"",o.close=()=>{(async function(l){(await b()).dispatch(X,{id:l})})(o.id)},o.next=()=>{if(c){let l=c;return c=void 0,l}return s.next()},o}async function Ee(){return(await b()).dispatch(Ln,null)}async function ve(){let n=await b();P=void 0,Fn(),await n.disconnect()}let Ae=async n=>{let e=await Un(n);for(let o of pn())await $n(o,e);return e};async function Un(n){let e=await async function(o){for(let s=0;s<kn;s++)try{return await fin.InterApplicationBus.Channel.connect(o,{wait:!1})}catch(c){if(s===kn-1)throw c;await new Promise(l=>setTimeout(l,ge))}}(n);return e.register(K,me()),e.register(X,o=>{let s=hn(),c=s.get(o.id);c&&(c.close(),s.delete(o.id))}),e.register(z,async(o,s)=>{if(!o||!o.providerId||!o.result)return void console.error(w);let c=L(o.providerId);if(!c)return void console.error(h);let{onResultDispatch:l}=c;return l?(o.result.dispatcherIdentity=o.result.dispatcherIdentity??s,l(o.result)):void 0}),e.onDisconnection(function(o){return async()=>{if(!H())return;let s=hn();for(let{req:c,close:l}of s.values())l(),s.delete(c.id);In(Ae(o))}}(n)),e}async function Oe(n){let e=H();e||(e=Un(n),In(e));let o=await e;return{getAllProviders:Ee.bind(null),register:$n.bind(null),search:Re.bind(null),deregister:Ce.bind(null),dispatch:Se.bind(null),disconnect:ve.bind(null),channel:o}}let G;function Y(){if(G)return G;throw S}function Ie(){return G}function Pe(n){G=n}function be(){G=void 0}let gn=new Set;function Ne(n){gn.add(n)}function Le(n){gn.delete(n)}var k;(function(n){n.Local="local",n.Dev="dev",n.Staging="staging",n.Prod="prod"})(k||(k={}));let wn=typeof window<"u"&&typeof fin<"u",Fe=(typeof process>"u"||process.env,typeof window<"u"),_e=Fe?window.origin:k.Local,Z=(wn&&fin.me.uuid,wn&&fin.me.name,wn&&fin.me.entityType,k.Local,k.Dev,k.Staging,k.Prod,n=>n.startsWith("http://")||n.startsWith("https://")?n:_e+n),Dn=(Z("http://localhost:4002"),Z("http://localhost:4002"),typeof WORKSPACE_DOCS_PLATFORM_URL<"u"&&Z(WORKSPACE_DOCS_PLATFORM_URL),typeof WORKSPACE_DOCS_CLIENT_URL<"u"&&Z(WORKSPACE_DOCS_CLIENT_URL),"20.3.6");typeof WORKSPACE_BUILD_SHA<"u"&&WORKSPACE_BUILD_SHA;async function Mn(){return[...pn()].map(n=>({...n,onUserInput:void 0,onResultDispatch:void 0}))}async function Te(n){if(L(n.id))throw new Error("provider with name already exists");let e=Q();return await dn({identity:e,...n}),{workspaceVersion:Dn||"",clientAPIVersion:n.clientAPIVersion||""}}async function xe(n){await J(n)}async function ke(n,e,o,s){let c=L(n);if(!c)throw h;let{onResultDispatch:l}=c;if(l)return l(_n(e,s??Q(),o))}async function*$e(n,e){let o=function(R,F){let $=[],M=[],B=[],I=[];for(let E of R){let _=Tn(E.scoreOrder),T={results:[],provider:{id:E.id,identity:E.identity,title:E.title,scoreOrder:E.scoreOrder,icon:E.icon,dispatchFocusEvents:E.dispatchFocusEvents}};$.push(T),M.push(_);let W=(async()=>{try{let{results:V,context:en}=await E.onUserInput(F,_.res);T.results=fn(T.results||[],V,E.scoreOrder),T.context={...T.context,...en}}catch(V){T.error=V}})();W.finally(()=>{W.done=!0}),I.push(W),B.push(B.length)}return{providerResponses:$,listenerResponses:M,openListenerResponses:B,initialResponsePromises:I}}(n.targets?n.targets.map(R=>L(R)).filter(R=>!!R):[...pn().filter(R=>!R.hidden)],n),{providerResponses:s,listenerResponses:c}=o,{openListenerResponses:l,initialResponsePromises:u}=o,p=x.Fetching,g=R=>{p=R,e.setState(p)},v,f=!1;n.onClose(()=>{f=!0,v&&v()});do{let R=!1;if(u.length){let I=[];for(let E of u)E.done?R=!0:I.push(E);u=I,u.length||(g(x.Fetched),R=!0)}let F,$=!1,M=()=>{$=!0,F&&F()},B=[];for(let I of l){let E=c[I],_=s[I],T=E.getStatus();(T===O.Open||p===x.Fetching&&T===O.Initial)&&(B.push(I),E.onChange=M);let W=E.getResultBuffer();W.length&&(E.setResultBuffer([]),_.results=fn(_.results||[],W),R=!0);let V=E.getRevokedBuffer();if(V.length){E.setRevokedBuffer([]);let nt=new Set(V);_.results=(_.results||[]).filter(({key:et})=>!nt.has(et)),R=!0}let en=E.getUpdatedContext();en&&(E.setUpdatedContext(null),_.context={..._.context,...en},R=!0)}if(l=B,R&&(yield s),f)break;$||(l.length||u.length)&&await Promise.race([...u,new Promise(I=>{F=I}),new Promise(I=>{v=I})])}while(l.length||u.length);return g(x.Complete),s}let yn=0;async function Bn(n){yn+=1;let e=xn(yn.toString(),n),o=$e(e.req,{setState:s=>{o.state=s}});return o.id=yn.toString(),o.close=e.close,o.state=x.Fetching,o}let nn=new Map,Ue=1e4;function De(){return async n=>{if(!n)return console.error(w),{error:w.message};let e;if(n.id)e=n.id;else{let c=await Bn(n);e=c.id,n.id=c.id,nn.set(e,{generator:c})}let o=nn.get(e);clearTimeout(o.timeout);let s=await o.generator.next();return o.timeout=function(c){return window.setTimeout(()=>{nn.delete(c)},Ue)}(e),{...s,id:n.id,state:o.generator.state}}}function Me(n,e){return Y().dispatch(n,X,{id:e})}function Be(){return n=>function(e){let o=nn.get(e);o&&o.generator.close()}(n.id)}async function We(n,{id:e,query:o,context:s,targets:c=[]}){let l=Y(),u={id:e,query:o,context:s,targets:c,providerId:n.id},p=await l.dispatch(n.identity,K,u),g=p.error;if(g)throw new Error(g);return p}let mn=new Map;function Ve(n,e){return`${n.name}:${n.uuid}:${e}`}let Cn=new Map;function Wn(n,e){return`${n}:${e}`}function qe(n){let e=Ve.bind(null,n.identity),o=Me.bind(null,n.identity),s=We.bind(null,n);return async(c,l)=>{let u=e(c.id);if(!mn.has(u)){let f=()=>{o(c.id),mn.delete(u)};mn.set(u,f),c.onClose(f)}let p=Wn(n.id,c.id),g=()=>{Cn.delete(p),l.close()};c.onClose(g),Cn.set(p,f=>{f.results?.length&&l.respond(f.results),f.revoked?.length&&l.revoke(...f.revoked),f.context&&l.updateContext(f.context),f.status===O.Open&&l.open(),f.status===O.Close&&g()});let v=await s(c);return v.status===O.Open&&l.open(),v.status!==O.Close&&v.status!==O.Initial||g(),v}}function je(n){return async e=>{let o=Y(),s={providerId:n.id,result:e};return o.dispatch(n.identity,z,s)}}let D=new Map;function Sn(n){return`${n.name}-${n.uuid}`}function Ge(){return async(n,e)=>{if(!n||!n.id)return console.error(new Error(JSON.stringify(n))),void console.error(w);if(L(n.id))throw m;return n.identity=e,await async function(o){let s=Sn(o.identity);D.has(s)||D.set(s,[]),D.get(s).push(o.id),await dn({...o,onUserInput:qe(o),onResultDispatch:je(o)})}(n),{workspaceVersion:Dn||"",clientAPIVersion:n.clientAPIVersion||""}}}function He(){return(n,e)=>{n?function(o,s){let c=L(o);if(!c)return;if(c.identity.uuid!==s.uuid||c.identity.name!==s.name)throw h;let l=Sn(c.identity),u=D.get(l);if(u){let p=u.findIndex(g=>g===o);p!==-1&&(u.splice(p,1),J(o))}}(n,e):console.error(w)}}let Rn=new Set;function Ke(n){Rn.add(n)}function ze(n){Rn.delete(n)}function Xe(){return async n=>{(function(e){let o=Sn(e),s=D.get(o);if(s){for(let c of s)J(c);D.delete(o)}})(n),Rn.forEach(e=>e(n))}}async function Je(n){let e=await(o=n,fin.InterApplicationBus.Channel.create(o));var o;return e.onConnection(async s=>{for(let c of gn)if(!await c(s))throw C}),e.onDisconnection(Xe()),e.register(X,Be()),e.register(K,s=>{let c=Wn(s.providerId,s.id),l=Cn.get(c);l&&l(s)}),e.register(bn,Ge()),e.register(Nn,He()),e.register(Ln,async()=>Mn()),e.register(Pn,De()),e.register(z,async(s,c)=>{if(!s||!s.providerId||!s.result)return void console.error(w);let l=L(s.providerId);if(!l)throw h;let{onResultDispatch:u}=l;return u?(s.result.dispatcherIdentity=s.result.dispatcherIdentity??c,u(s.result)):void 0}),e}async function Qe(){let n=Y();be(),await n.destroy(),Fn()}async function Ye(n){let e=Ie();e||(e=await Je(n),Pe(e));let o=Le.bind(null),s=ze.bind(null),c=pe.bind(null),l=he.bind(null);return{getAllProviders:Mn.bind(null),search:Bn.bind(null),register:Te.bind(null),deregister:xe.bind(null),onSubscription:Ne.bind(null),onDisconnect:Ke.bind(null),onRegister:de.bind(null),onDeregister:fe.bind(null),dispatch:ke.bind(null),disconnect:Qe.bind(null),removeListener:u=>{o(u),s(u),c(u),l(u)},channel:e}}let{v:Vn}=a,{B:qn}=r,jn="all",Ze={create:Vn,subscribe:qn,defaultTopic:jn},Gn=()=>{window.search=Ze},Hn=n=>{let e=()=>{Gn(),window.removeEventListener(n,e)};return e};if(typeof window<"u"){Gn();let n="load",e=Hn(n);window.addEventListener(n,e);let o="DOMContentLoaded",s=Hn(o);window.addEventListener(o,s)}Xn.exports=i})()});var y="@openfin/cloud-api";async function N(){try{return await window.fin.View.getCurrentSync().getInfo(),!0}catch{return!1}}function zn(t){if(t.name.startsWith("internal-generated"))throw new Error("Cannot extract app UUID from identity");return/\/[\d,a-z-]{36}$/.test(t.name)?t.name.split("/")[0]||"":t.name}var q="@openfin/cloud-api";function lt(){return`${window.fin.me.uuid}-cloud-api-notifications`}var An=null;async function qt(){return An||(An=ut()),An}async function ut(){if(!window.fin)throw new Error(`\`${q}\`: \`getNotificationsClient\` cannot be used in a non-OpenFin environment`);if(await N()===!1)throw new Error(`${q}: \`getNotificationsClient\` cannot be used in a non-OpenFin environment`);zn(window.fin.me);let t=await dt();console.log(t),t.register("openfin-cloud-event",r=>{for(let a of i.get(r.type)??[])typeof r.payload.timestamp=="string"&&(r.payload.timestamp=new Date(r.payload.timestamp)),a(r.payload)});let i=new Map;return{addEventListener:(r,a)=>{let d=i.get(r)||new Set;d.add(a),i.set(r,d)},removeEventListener:(r,a)=>{let d=i.get(r);if(!d){console.warn(`\`${q}\`: Listener was not found for event. Did you pass a function directly instead of a reference or forget to add the listener?`,r);return}d.delete(a)===!1&&console.warn(`\`${q}\`: Listener was not found for event. Did you pass a function directly instead of a reference?`,r)},update:async r=>(await t.dispatch("openfin-cloud-update-notification",{version:1,payload:{notification:r}})).payload.response,clear:async r=>(await t.dispatch("openfin-cloud-clear-notification",{version:1,payload:{notificationId:r}})).payload.response,createNotification:async r=>(r.id&&console.warn(`\`${q}\`: The \`id\` property is not supported and will be ignored. If you need to use the \`id\` property, you should use the \`id\` property of the returned notification object.`),(await t.dispatch("openfin-cloud-create-notification",{version:1,payload:{notification:{...r,id:void 0}}})).payload.response)}}var tn=null;async function dt(){return tn||(tn=pt()),tn}async function pt(){let t=await window.fin.InterApplicationBus.Channel.connect(lt());return t.onDisconnection(i=>{console.warn(`\`${q}\`: Channel Disconnected from`,i,"Reconnecting..."),tn=null}),t}var On;function ft(){return`${window.fin.me.uuid}-client-api`}async function U(){return On||(On=window.fin.InterApplicationBus.Channel.connect(ft())),On}async function Ht(){if(!window.fin)throw new Error(`\`${y}\`: \`getAppSettings\` cannot be used in a non-OpenFin environment`);if(await N()===!1)throw new Error(`${y}: \`getAppSettings\` cannot be used in a non-OpenFin environment`);return(await U()).dispatch("get-settings")}async function Kt(){if(!window.fin)throw new Error(`\`${y}\`: \`getAppUserSettings\` cannot be used in a non-OpenFin environment`);if(await N()===!1)throw new Error(`${y}: \`getAppUserSettings\` cannot be used in a non-OpenFin environment`);return(await U()).dispatch("get-user-settings")}async function zt(t){if(!window.fin)throw new Error(`\`${y}\`: \`setAppUserSettings\` cannot be used in a non-OpenFin environment`);if(await N()===!1)throw new Error(`${y}: \`setAppUserSettings\` cannot be used in a non-OpenFin environment`);return(await U()).dispatch("set-user-settings",t)}async function Xt(){if(!window.fin)throw new Error(`\`${y}\`: \`getAppUserPermissions\` cannot be used in a non-OpenFin environment`);if(await N()===!1)throw new Error(`${y}: \`getAppUserPermissions\` cannot be used in a non-OpenFin environment`);return(await U()).dispatch("get-user-permissions")}async function Jt(t,i){if(!window.fin)throw new Error(`\`${y}\`: \`launchContent\` cannot be used in a non-OpenFin environment`);if(await N()===!1)throw new Error(`${y}: \`launchContent\` cannot be used in a outside of an OpenFin View context`);let r=await U();try{await r.dispatch("launch-content",{id:t,options:i})}catch(a){switch(a instanceof Error?a.message:String(a)){case"UnableToLookup":throw new Error(`${y}: \`launchContent\` was unable to lookup content with id: ${t}`);case"UnableToLaunch":throw new Error(`${y}: \`launchContent\` was unable to launch content with id: ${t}`);case"NoContentFound":throw new Error(`${y}: \`launchContent\` did not find content with id: ${t}`);default:throw new Error(`${y}: \`launchContent\` was unable to look up or launch content with id: ${t} or the content did not exist.`)}}}async function Qt(t){if(!window.fin)throw new Error(`\`${y}\`: \`launchSupertab\` cannot be used in a non-OpenFin environment`);if(await N()===!1)throw new Error(`${y}: \`launchSupertab\` cannot be used in a outside of an OpenFin View context`);let i=await U();try{await i.dispatch("launch-supertab",{id:t})}catch(r){switch(r instanceof Error?r.message:String(r)){case"UnableToLookup":throw new Error(`${y}: \`launchSupertab\` was unable to lookup content with id: ${t}`);case"UnableToLaunch":throw new Error(`${y}: \`launchSupertab\` was unable to launch content with id: ${t}`);case"NoContentFound":throw new Error(`${y}: \`launchSupertab\` did not find content with id: ${t}`);default:throw new Error(`${y}: \`launchSupertab\` was unable to look up or launch content with id: ${t} or the content did not exist.`)}}}async function Yt(t){if(!window.fin)throw new Error(`\`${y}\`: \`launchWorkspace\` cannot be used in a non-OpenFin environment`);if(await N()===!1)throw new Error(`${y}: \`launchWorkspace\` cannot be used in a outside of an OpenFin View context`);let i=await U();try{await i.dispatch("launch-workspace",{id:t})}catch(r){switch(r instanceof Error?r.message:String(r)){case"UnableToLookup":throw new Error(`${y}: \`launchWorkspace\` was unable to lookup content with id: ${t}`);case"UnableToLaunch":throw new Error(`${y}: \`launchWorkspace\` was unable to launch content with id: ${t}`);case"NoContentFound":throw new Error(`${y}: \`launchWorkspace\` did not find content with id: ${t}`);default:throw new Error(`${y}: \`launchWorkspace\` was unable to look up or launch content with id: ${t} or the content did not exist.`)}}}var ne={};Kn(ne,{getAgentConfiguration:()=>Yn,register:()=>Zn});var Qn=vn(on(),1),ht="[here-agent]",gt="log-message-",wt="open-url",yt="provider-status-",mt="registered-",Ct="1.0";function St(t,i){let{data:r,iconSize:a,rightSideIcon:d,...h}=t;return{...h,data:{customData:r,iconSize:a,providerId:i,resultType:"app",rightSideIcon:d}}}function Jn(t){return{...t,data:t.data.customData}}async function Yn(){let{customData:t}=await window.fin.me.getOptions();return t}function Rt(){return`${window.fin.me.identity.uuid}-cloud-api-search`}async function Et(t,i,r,a=!0){await i("info",`Setting status as ${a?"ready":"not ready"}`);try{await t.dispatch(`${yt}${r}`,{isReady:a})}catch(d){let h=["Error setting provider status",d];console.error(...h),i("error",...h)}}async function vt(t,i,r,...a){try{console.log(ht,...a),await t.dispatch(`${gt}${i}`,{level:r,message:a})}catch(d){console.error("Error logging message",d)}}async function At(t,i,r,a,d){let{action:h,dispatcherIdentity:m,...w}=d;await r("info","Handling action",{action:h,dispatcherIdentity:m,result:w});let C;try{let P=Jn(d).actions?.find(({name:H})=>H===h.name);if(!P)throw new Error("Original action not found in search result");C=(await a(P,Jn(d)))?.url}catch(S){throw await r("error","Error handling dispatch",S),S}if(!C){await r("warn","OnActionListener did not return a URL");return}await It(t,r,i,C,m)}async function Ot(t,i,r,a){await i("info","Getting search results",{request:a});try{let d=new AbortController;a.onClose(()=>d.abort());let{context:h,query:m}=a,{results:w}=await r({context:h,query:m,signal:d.signal}),C=w.map(S=>St(S,t));return await i("info","Returning results",C),{results:C}}catch(d){let h=["Error handling search",d];throw console.error(...h),i("error",...h),d}}async function It(t,i,r,a,d){await i("info","Opening URL",{url:a,targetIdentity:d});try{await t.dispatch(wt,{url:a,targetIdentity:d,providerId:r})}catch(h){let m=["Error opening URL",h];console.error(...m),i("error",...m)}}async function Zn(t){let r=(await window.fin.me.getOptions()).customData,{id:a,title:d}=r,{onAction:h,onSearch:m}=t,w=await Qn.subscribe(Rt()),C=w.channel,S=vt.bind(null,C,a);return await w.register({icon:"",id:a,onResultDispatch:At.bind(null,C,a,S,h),onUserInput:Ot.bind(null,a,S,m),title:d}),await w.channel.dispatch(`${mt}${a}`,{version:Ct}),S("info","Registered search topic",{id:a,title:d}),{isReady:Et.bind(null,C,S,a)}}var le={};Kn(le,{getConfiguration:()=>ae,register:()=>ce});var se=vn(on(),1);var rn=class extends Error{constructor(){super("Interop feature is not supported by the agent")}};async function sn(t,i){try{let r=await window.fin.me.interop.getFDC3(t);i==="none"?(A("Leaving current channel"),await r.leaveCurrentChannel()):(A(`Joining interop channel: ${i}`),await("joinUserChannel"in r?r.joinUserChannel(i):r.joinChannel(i)))}catch(r){A(`Failed to join interop channel: ${i}`,r)}}var ro=vn(on(),1);var Nt=(t,i)=>{let{data:r,iconSize:a,rightSideIcon:d,...h}=t;return{...h,data:{customData:r,iconSize:a,providerId:i,resultType:"app",rightSideIcon:d}}},ee=t=>({...t,data:t.data.customData}),te=()=>`${window.fin.me.identity.uuid}-cloud-api-search`,Lt=async({channel:t,url:i,targetIdentity:r})=>{A("Opening URL",{url:i,targetIdentity:r});try{await t.dispatch(ie,{url:i,targetIdentity:r})}catch(a){console.error("Failed opening URL",a)}},oe=async(t,i,r,a)=>{let{action:d,dispatcherIdentity:h,...m}=a;A("Handling action...",{action:d,dispatcherIdentity:h,result:m});let w;try{let S=ee(a).actions?.find(({name:b})=>b===d.name);if(!S)throw new Error("Original action not found in search result");w=(await r(S,ee(a)))?.url}catch(C){throw A("Error handling dispatch",C),C}if(!w){A("OnActionListener did not return a URL");return}await Lt({channel:t,url:w,targetIdentity:h})},re=async(t,i,r)=>{A("Getting search results...",{request:r});try{let a=new AbortController;r.onClose(()=>a.abort());let{context:d,query:h}=r,{results:m}=await i({context:d,query:h,signal:a.signal}),w=m.map(C=>Nt(C,t));return A("Returning results",w),{results:w}}catch(a){throw new Error("Error handling search request",{cause:a})}};var _t="[here-agent]",Tt="1.0",xt="-enterprise-component-bridge",ie="open-url",kt="set-agent-registered",$t="set-agent-status",ae=async()=>{let{customData:t}=await window.fin.me.getOptions(),i=t,{configurationFields:r}=i;return Object.fromEntries(r?.map(a=>[a.name,a.value])??[])};async function Ut(t,i){if(!t.interop)throw new rn;let{fdc3Version:r}=t.interop;await sn(r,i)}function A(...t){console.log(_t,...t)}var Dt=async(t,i,r=!0)=>{A(`Setting status to ${r?"ready":"not ready"}`);try{await t.dispatch($t,{id:i,isReady:r})}catch(a){throw new Error("Failed to set agent status",{cause:a})}};async function ce(t){let{customData:i}=await window.fin.me.getOptions(),r=i;A("Registering agent...",r);try{let a=`${window.fin.me.identity.uuid}${xt}`,d;try{d=await window.fin.InterApplicationBus.Channel.connect(a,{wait:!1})}catch(S){throw new Error("Failed to connect to enterprise component bridge channel",{cause:S})}let{id:h,features:m,title:w}=r,C={features:m,joinInteropChannel:Ut.bind(null,m),setIsReady:Dt.bind(null,d,h)};if(m.interop){A("Enabling interop features");let{defaultChannel:S,fdc3Version:P}=m.interop;S&&S!=="none"&&await sn(P,S),d.register("on-desktop-app-signals-changed",Mt.bind(null,r))}return m.search&&t.search&&(A("Enabling search features"),await(await se.subscribe(te())).register({icon:"",id:h,onResultDispatch:oe.bind(null,d,h,t.search.onAction),onUserInput:re.bind(null,h,t.search.onSearch),title:w})),await d.dispatch(kt,{id:h,apiVersion:Tt}),A("Registered successfully"),C}catch(a){throw new Error("Failed to register agent",{cause:a})}}function Mt(t,i){A("Desktop app signals changed",i);let r=i,{type:a,id:d,features:h}=t,{fdc3Version:m}=h.interop,w=r.find(C=>a==="agent"?C.appKey===t.name:a==="custom"?C.appKey===d:!1);w&&sn(m,w.selectedColorChannel)}export{le as Agent,ne as Search,Ht as getAppSettings,Xt as getAppUserPermissions,Kt as getAppUserSettings,qt as getNotificationsClient,Jt as launchContent,Qt as launchSupertab,Yt as launchWorkspace,zt as setAppUserSettings};
|
|
2
2
|
//# sourceMappingURL=index.js.map
|