Huge News!Announcing our $40M Series B led by Abstract Ventures.Learn More
Socket
Sign inDemoInstall
Socket

@openfin/cloud-api

Package Overview
Dependencies
Maintainers
0
Versions
369
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

@openfin/cloud-api - npm Package Compare versions

Comparing version 0.0.1-alpha.78bf5df to 0.0.1-alpha.78c94f6

318

dist/index.d.ts
import * as OpenFin from '@openfin/core';
import OpenFin__default from '@openfin/core';
import * as NotificationsTypes from 'openfin-notifications';
import * as NotificationsTypes from '@openfin/workspace/notifications';

@@ -155,7 +155,2 @@ /**

declare global {
interface Window {
fin: typeof OpenFin.fin;
}
}
/**

@@ -224,3 +219,3 @@ * @returns A client for interacting with the OpenFin Notifications service

*/
permissionId: string;
id: string;
}[];

@@ -258,3 +253,310 @@ };

declare function getAppUserPermissions(): Promise<AppPermissions>;
type LaunchContentOptions = {
/** Object containing query param values to be appended to content's URL */
queryParams?: Record<string, string>;
/** Defines behavior when instance of content is already running.
* If 'multi', copy of the content will be created.
* If 'single', the existing instance of content will be focused. */
instanceMode?: 'single' | 'multi';
} & ({
targetType?: 'new-window';
/** Defines the bounds of the window in which content will open */
bounds?: Partial<OpenFin__default.Bounds>;
} | {
targetType: 'window' | 'view';
targetIdentity: OpenFin__default.Identity;
});
/**
* A function allowing the easy launching of content
* @param id The id of the content to launch
* @returns nothing
*
* @throws {Error} If the function is called outside of an OpenFin environment
* @throws {Error} If the function is called outside of an OpenFin View context
* @throws {Error} If the function has been unable to look up or launch the content
* @throws {Error} If the function is unable to find content with the provided id.
*/
declare function launchContent(id: string, options: LaunchContentOptions): Promise<void>;
/**
* A function allowing the easy launching of Supertabs
* @param id The id of supertab
* @returns nothing
*
* @throws {Error} If the function is called outside of an OpenFin environment
* @throws {Error} If the function is called outside of an OpenFin View context
* @throws {Error} If the function has been unable to look up or launch the supertab
* @throws {Error} If the function is unable to find supertab with the provided id.
*/
declare function launchSupertab(id: string): Promise<void>;
/**
* A function allowing the easy launching of Workspaces
* @param id The id of workspace
* @returns nothing
*
* @throws {Error} If the function is called outside of an OpenFin environment
* @throws {Error} If the function is called outside of an OpenFin View context
* @throws {Error} If the function has been unable to look up or launch the workspace
* @throws {Error} If the function is unable to find workspace with the provided id.
*/
declare function launchWorkspace(id: string): Promise<void>;
export { type AppPermissions, 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, setAppUserSettings };
/**
* 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.
*
* @param action The action that was triggered.
* @param result The search result that the action was triggered on.
*
* @returns Result that includes the URL that Here™ should navigate to, or `undefined` if no navigation is required.
*/
type OnActionListener = (action: SearchAction, result: SearchResult) => SearchResultActionResponse | Promise<SearchResultActionResponse>;
/**
* Function that is called when the Search Agent receives a query from Here™’s search UI
*
* @param request Search request data that includes the query.
*
* @returns Search response data that includes the search results.
*/
type OnSearchListener = (request: SearchListenerRequest) => SearchResponse | Promise<SearchResponse>;
/**
* An action that can be triggered by a user on a search result returned by a Search Agent.
*
* 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.
*/
type SearchAction = {
/**
* URL or data URI of an icon that will be displayed within the action button when Here™ is in Light mode.
*/
darkIcon?: string;
/**
* A fuller description of the action that will be displayed in Here™’s search UI when the user hovers over the action button.
*/
description?: string;
/**
* URL or data URI of an icon that will be displayed within the action button when Here™ is in Dark mode.
*/
lightIcon?: string;
/**
* Internal identifier for the action which is used to identify the action in the {@link OnActionListener}.
*/
name: string;
/**
* Compact title of the action displayed within the action button.
*/
title?: string;
};
/**
* 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.
*/
type SearchAgent = {
/**
* The Search Agent’s custom configuration data configured via the Admin Console.
*/
readonly customData: unknown;
/**
* Sets whether or not the Search Agent is ready to provide search results.
*
* When a Search Agent is first registered, it will not receive search queries until it is set as ready by calling this function.
*
* @param ready Whether the Search Agent is ready to provide search results (defaults to `true`).
*/
isReady: (ready?: boolean) => Promise<void>;
};
/**
* Configuration provided when registering a Search Agent.
*/
type SearchAgentRegistrationConfig = {
/**
* 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.
*
* The listener returns a response back to Here™ that includes a URL to navigate to.
*/
onAction: OnActionListener;
/**
* This listener is called when the Search Agent receives a query from Here™’s search UI and returns relevant search results.
*
* Note: When the Search Agent is not ready this listener will not be called.
*/
onSearch: OnSearchListener;
};
/**
* Search request data provided to the {@link OnSearchListener}.
*/
type SearchListenerRequest = {
/**
* Provides additional context for the search request.
*/
context: SearchRequestContext;
/**
* The query entered by the user in Here™’s search UI.
*/
query: string;
/**
* 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.
*/
signal: AbortSignal;
};
/**
* Context data included with a search request.
*/
type SearchRequestContext = {
/**
* The page number of the search results to return.
*/
pageNumber: number;
/**
* The number of search results to return per page.
*/
pageSize: number;
};
/**
* Return type of the {@link OnSearchListener}.
*/
type SearchResponse = {
/**
* The search results to display in Here™’s search UI.
*/
results: SearchResult[];
};
/**
* A search result returned by a Search Agent in response to a search request.
*/
type SearchResult = {
/**
* Actions that can be triggered by the user against the search result.
*/
actions: SearchAction[];
/**
* Additional data that can be used by the {@link OnActionListener} when an action is triggered.
*/
data?: Record<string, unknown>;
/**
* URL or data URI of an icon that will be displayed with the search result in Here™’s search UI.
*/
icon?: string;
/**
* Unique identifier for the search result.
*/
key: string;
/**
* Secondary text that will be displayed with the search result in Here™’s search UI.
*/
label?: string;
/**
* Primary text that will be displayed with the search result in Here™’s search UI.
*/
title: string;
};
/**
* Return type of the {@link OnActionListener}.
*/
type SearchResultActionResponse = {
/**
* URL that Here™ should navigate to.
*/
url: string;
} | undefined;
/**
* 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.
*
* @param config The configuration for the Search Agent.
*
* @returns A promise that resolves with the Search Agent.
*
* @example Registering a basic Search Agent:
* ```ts
* // Handle incoming action and return a response that includes the URL to navigate to
* const onAction: Search.OnActionListener = (action, result) => {
* const { name } = action;
* const { data, key } = result;
* const { owner, searchResultHostUrl } = data as { owner: { id: string, name: string }, searchResultHostUrl: string };
* const { id: ownerId } = owner;
* console.log(`Action "${name}" triggered on search result with key "${key}"`);
* switch (name) {
* case "view-owner":
* return { url: `${searchResultHostUrl}/people/${ownerId}` };
* case "view-result":
* return { url: `${searchResultHostUrl}/record/${key}` };
* default:
* console.warn(`Unknown action: ${name}`);
* }
* };
*
* // Handle incoming search request and return relevant search results
* const onSearch: Search.OnSearchListener = ({ context, query, signal }) => {
* const { pageNumber, pageSize } = context;
* try {
* let results: Search.SearchResult[] = [];
* const url = `https://my-web-app.com/search?q=${query}&page=${pageNumber}&limit=${pageSize}`;
* const response = await fetch(url, { signal });
* if (!response.ok) {
* throw new Error(`Request failed: ${response.status}`);
* }
* const { searchResults } = await response.json();
* results = searchResults.map((result) => {
* const { iconUrl, id: key, owner, subTitle, title } = result;
* const { name: ownerName } = owner as { id: string, name: string };
* return {
* actions: [
* {
* name: "view-result",
* description: `Go to ${title} in My Web App`,
* },
* {
* name: "view-owner",
* description: `Go to ${ownerName} in My Web App`,
* title: "View Owner",
* },
* ],
* data: {
* owner,
* searchResultHostUrl: `https://my-web-app.com`,
* },
* icon: iconUrl,
* key,
* label: subTitle,
* title,
* };
* });
* console.log("Returning results", results);
* return { results };
* } catch (err) {
* if ((err as Error).name === "AbortError") {
* // Ignore errors for cancelled requests
* return { results: [] };
* }
* throw err;
* }
* };
*
* // Register the search agent
* const searchAgent = await Search.register({ onAction, onSearch });
*
* // Set the Search Agent as ready to receive search requests
* await searchAgent.isReady();
* ```
*/
declare function register(config: SearchAgentRegistrationConfig): Promise<SearchAgent>;
type index_OnActionListener = OnActionListener;
type index_OnSearchListener = OnSearchListener;
type index_SearchAction = SearchAction;
type index_SearchAgent = SearchAgent;
type index_SearchAgentRegistrationConfig = SearchAgentRegistrationConfig;
type index_SearchListenerRequest = SearchListenerRequest;
type index_SearchRequestContext = SearchRequestContext;
type index_SearchResponse = SearchResponse;
type index_SearchResult = SearchResult;
type index_SearchResultActionResponse = SearchResultActionResponse;
declare const index_register: typeof register;
declare namespace index {
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 };
}
declare global {
interface Window {
fin: typeof OpenFin.fin;
}
}
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 };

2

dist/index.js

@@ -1,2 +0,2 @@

var t="@openfin/cloud-api";async function a(){try{return await window.fin.View.getCurrentSync().getInfo(),!0}catch{return!1}}function u(e){if(e.name.startsWith("internal-generated"))throw new Error("Cannot extract app UUID from identity");return/\/[\d,a-z-]{36}$/.test(e.name)?e.name.split("/")[0]||"":e.name}var s="@openfin/cloud-api";function d(){return`${window.fin.me.uuid}-cloud-api-notifications`}var l=null;async function g(){return l||(l=w()),l}async function w(){if(!window.fin)throw new Error(`\`${s}\`: \`getNotificationsClient\` cannot be used in a non-OpenFin environment`);if(await a()===!1)throw new Error(`${s}: \`getNotificationsClient\` cannot be used in a non-OpenFin environment`);u(window.fin.me);let e=await m();console.log(e),e.register("openfin-cloud-event",n=>{for(let i of o.get(n.type)??[])typeof n.payload.timestamp=="string"&&(n.payload.timestamp=new Date(n.payload.timestamp)),i(n.payload)});let o=new Map;return{addEventListener:(n,i)=>{let r=o.get(n)||new Set;r.add(i),o.set(n,r)},removeEventListener:(n,i)=>{let r=o.get(n);if(!r){console.warn(`\`${s}\`: Listener was not found for event. Did you pass a function directly instead of a reference or forget to add the listener?`,n);return}r.delete(i)===!1&&console.warn(`\`${s}\`: Listener was not found for event. Did you pass a function directly instead of a reference?`,n)},update:async n=>(await e.dispatch("openfin-cloud-update-notification",{version:1,payload:{notification:n}})).payload.response,clear:async n=>(await e.dispatch("openfin-cloud-clear-notification",{version:1,payload:{notificationId:n}})).payload.response,createNotification:async n=>(n.id&&console.warn(`\`${s}\`: 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 e.dispatch("openfin-cloud-create-notification",{version:1,payload:{notification:{...n,id:void 0}}})).payload.response)}}var p=null;async function m(){return p||(p=y()),p}async function y(){let e=await window.fin.InterApplicationBus.Channel.connect(d());return e.onDisconnection(o=>{console.warn(`\`${s}\`: Channel Disconnected from`,o,"Reconnecting..."),p=null}),e}var f;function N(){return`${window.fin.me.uuid}-client-api`}async function c(){return f||(f=window.fin.InterApplicationBus.Channel.connect(N())),f}async function E(){if(!window.fin)throw new Error(`\`${t}\`: \`getAppSettings\` cannot be used in a non-OpenFin environment`);if(await a()===!1)throw new Error(`${t}: \`getAppSettings\` cannot be used in a non-OpenFin environment`);return(await c()).dispatch("get-settings")}async function P(){if(!window.fin)throw new Error(`\`${t}\`: \`getAppUserSettings\` cannot be used in a non-OpenFin environment`);if(await a()===!1)throw new Error(`${t}: \`getAppUserSettings\` cannot be used in a non-OpenFin environment`);return(await c()).dispatch("get-user-settings")}async function v(e){if(!window.fin)throw new Error(`\`${t}\`: \`setAppUserSettings\` cannot be used in a non-OpenFin environment`);if(await a()===!1)throw new Error(`${t}: \`setAppUserSettings\` cannot be used in a non-OpenFin environment`);return(await c()).dispatch("set-user-settings",e)}async function T(){if(!window.fin)throw new Error(`\`${t}\`: \`getAppUserPermissions\` cannot be used in a non-OpenFin environment`);if(await a()===!1)throw new Error(`${t}: \`getAppUserPermissions\` cannot be used in a non-OpenFin environment`);return(await c()).dispatch("get-user-permissions")}export{E as getAppSettings,T as getAppUserPermissions,P as getAppUserSettings,g as getNotificationsClient,v as setAppUserSettings};
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};
//# sourceMappingURL=index.js.map
{
"name": "@openfin/cloud-api",
"version": "0.0.1-alpha.78bf5df",
"version": "0.0.1-alpha.78c94f6",
"sideEffects": false,

@@ -17,4 +17,8 @@ "description": "",

"build": "tsup --config ./tsup.config.ts",
"build:watch": "tsup --watch --config ./tsup.config.ts",
"lint": "eslint . --ext .ts,.tsx --max-warnings 0"
"dev": "tsup --watch --config ./tsup.config.ts",
"typecheck": "tsc --noEmit",
"test": "echo \"Error: no test specified\" && exit 1",
"lint": "eslint . --max-warnings 0",
"lint:fix": "eslint . --fix --max-warnings 0",
"docs": "typedoc --treatWarningsAsErrors"
},

@@ -24,19 +28,19 @@ "files": [

],
"dependencies": {
"@openfin/core": "^34.78.80",
"openfin-notifications": "^2.3.2"
},
"devDependencies": {
"@openfin/core": "40.101.1",
"@openfin/search-api": "^2.0.0",
"@openfin/typedoc-theme": "^2.0.0",
"@openfin/workspace": "20.2.4",
"@typescript-eslint/eslint-plugin": "^7.5.0",
"@typescript-eslint/parser": "^7.5.0",
"@typescript-eslint/parser": "^7.15.0",
"eslint": "^8.57.0",
"eslint-config-next": "^14.1.4",
"eslint-config-prettier": "^9.1.0",
"eslint-plugin-check-file": "^2.6.2",
"eslint-plugin-prettier": "^5.1.3",
"eslint-plugin-simple-import-sort": "^12.0.0",
"eslint-plugin-unicorn": "^51.0.1",
"prettier": "^3.2.5",
"tsup": "^8.0.1",
"typescript": "^5.4.3"
"eslint-plugin-check-file": "^2.8.0",
"eslint-plugin-prettier": "^5.2.1",
"eslint-plugin-simple-import-sort": "^12.1.1",
"eslint-plugin-unicorn": "^55.0.0",
"prettier": "^3.3.3",
"tsup": "^8.3.0",
"typedoc": "^0.26.11",
"typescript": "^5.6.3"
},

@@ -185,5 +189,3 @@ "eslintConfig": {

],
"@typescript-eslint/no-explicit-any": [
"warn"
]
"@typescript-eslint/no-explicit-any": 1
},

@@ -190,0 +192,0 @@ "ignorePatterns": [

Sorry, the diff of this file is not supported yet

Sorry, the diff of this file is not supported yet

Sorry, the diff of this file is not supported yet

Sorry, the diff of this file is not supported yet

SocketSocket SOC 2 Logo

Product

  • Package Alerts
  • Integrations
  • Docs
  • Pricing
  • FAQ
  • Roadmap
  • Changelog

Packages

npm

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc