New Case Study:See how Anthropic automated 95% of dependency reviews with Socket.Learn More
Socket
Sign inDemoInstall
Socket

@openfin/cloud-api

Package Overview
Dependencies
Maintainers
60
Versions
409
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.7cd9387 to 0.0.1-alpha.7dd233b

307

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;
}
}
/**

@@ -257,2 +252,17 @@ * @returns A client for interacting with the OpenFin Notifications service

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;
});
/**

@@ -268,4 +278,285 @@ * A function allowing the easy launching of content

*/
declare function launchContent(id: string): Promise<void>;
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, launchContent, 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(n){if(n.name.startsWith("internal-generated"))throw new Error("Cannot extract app UUID from identity");return/\/[\d,a-z-]{36}$/.test(n.name)?n.name.split("/")[0]||"":n.name}var r="@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(`\`${r}\`: \`getNotificationsClient\` cannot be used in a non-OpenFin environment`);if(await a()===!1)throw new Error(`${r}: \`getNotificationsClient\` cannot be used in a non-OpenFin environment`);u(window.fin.me);let n=await h();console.log(n),n.register("openfin-cloud-event",e=>{for(let o of i.get(e.type)??[])typeof e.payload.timestamp=="string"&&(e.payload.timestamp=new Date(e.payload.timestamp)),o(e.payload)});let i=new Map;return{addEventListener:(e,o)=>{let s=i.get(e)||new Set;s.add(o),i.set(e,s)},removeEventListener:(e,o)=>{let s=i.get(e);if(!s){console.warn(`\`${r}\`: Listener was not found for event. Did you pass a function directly instead of a reference or forget to add the listener?`,e);return}s.delete(o)===!1&&console.warn(`\`${r}\`: Listener was not found for event. Did you pass a function directly instead of a reference?`,e)},update:async e=>(await n.dispatch("openfin-cloud-update-notification",{version:1,payload:{notification:e}})).payload.response,clear:async e=>(await n.dispatch("openfin-cloud-clear-notification",{version:1,payload:{notificationId:e}})).payload.response,createNotification:async e=>(e.id&&console.warn(`\`${r}\`: 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 n.dispatch("openfin-cloud-create-notification",{version:1,payload:{notification:{...e,id:void 0}}})).payload.response)}}var p=null;async function h(){return p||(p=m()),p}async function m(){let n=await window.fin.InterApplicationBus.Channel.connect(d());return n.onDisconnection(i=>{console.warn(`\`${r}\`: Channel Disconnected from`,i,"Reconnecting..."),p=null}),n}var f;function y(){return`${window.fin.me.uuid}-client-api`}async function c(){return f||(f=window.fin.InterApplicationBus.Channel.connect(y())),f}async function A(){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 v(){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 P(n){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",n)}async function $(){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")}async function T(n){if(!window.fin)throw new Error(`\`${t}\`: \`launchContent\` cannot be used in a non-OpenFin environment`);if(await a()===!1)throw new Error(`${t}: \`launchContent\` cannot be used in a outside of an OpenFin View context`);let i=await c();try{await i.dispatch("launch-content",{id:n})}catch(e){switch(e instanceof Error?e.message:String(e)){case"UnableToLookup":throw new Error(`${t}: \`launchContent\` was unable to lookup content with id: ${n}`);case"UnableToLaunch":throw new Error(`${t}: \`launchContent\` was unable to launch content with id: ${n}`);case"NoContentFound":throw new Error(`${t}: \`launchContent\` did not find content with id: ${n}`);default:throw new Error(`${t}: \`launchContent\` was unable to look up or launch content with id: ${n} or the content did not exist.`)}}}export{A as getAppSettings,$ as getAppUserPermissions,v as getAppUserSettings,g as getNotificationsClient,T as launchContent,P as setAppUserSettings};
var We=Object.create;var mn=Object.defineProperty;var Ve=Object.getOwnPropertyDescriptor;var qe=Object.getOwnPropertyNames;var He=Object.getPrototypeOf,Ke=Object.prototype.hasOwnProperty;var Ge=(o,l)=>()=>(l||o((l={exports:{}}).exports,l),l.exports),je=(o,l)=>{for(var a in l)mn(o,a,{get:l[a],enumerable:!0})},Xe=(o,l,a,d)=>{if(l&&typeof l=="object"||typeof l=="function")for(let p of qe(l))!Ke.call(o,p)&&p!==a&&mn(o,p,{get:()=>l[p],enumerable:!(d=Ve(l,p))||d.enumerable});return o};var ze=(o,l,a)=>(a=o!=null?We(He(o)):{},Xe(l||!o||!o.__esModule?mn(a,"default",{value:o,enumerable:!0}):a,o));var Hn=Ge((At,qn)=>{"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})}},l={};o.r(l),o.d(l,{SearchTagBackground:()=>on,create:()=>Un,defaultTopic:()=>Bn,subscribe:()=>Dn});var a={};o.r(a),o.d(a,{B:()=>ue});var d={};o.r(d),o.d(d,{v:()=>Ue});let p="deregistered or does not exist",y=new Error(`provider ${p}`),O=new Error("provider with name already exists"),S=new Error("bad payload"),b=new Error("subscription rejected"),P=new Error(`channel ${p}`),R;function I(){if(R)return R;throw P}function K(){return R}function Sn(n){R=n}var v,x,tn,on;(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"}(tn||(tn={})),function(n){n.Active="active",n.Default="default"}(on||(on={}));let G="0",Rn="1",En="2",bn="3",Pn="4",j="5",X="6",zn=()=>{},rn=new Set;function Jn(n){rn.add(n)}function Qn(n){rn.delete(n)}let sn=new Set;function Yn(n){sn.add(n)}function Zn(n){sn.delete(n)}let q=new Map;async function an(n){q.set(n.id,n);let e=[...rn].map(t=>t());await Promise.all(e)}async function z(n){q.delete(n);let e=[...sn].map(t=>t());await Promise.all(e)}function cn(){return[...q.values()]}function On(){q.clear()}function L(n){return q.get(n)}function An(n,e,t){return{...n,action:t||{...n.actions[0],trigger:tn.UserAction},dispatcherIdentity:e}}function ln(n,e,t="ascending"){let i=n||[];if(!e?.length)return i;let r=[],s=new Map;e.forEach(u=>{if(u.key)return s.set(u.key,u);r.push(u)});let c=i.map(u=>{let{key:h}=u;if(h&&s.has(h)){let C=s.get(h);return s.delete(h),C}return u});return c.push(...s.values(),...r),c=t==="ascending"?c.sort((u,h)=>(u?.score??1/0)-(h?.score??1/0)):c.sort((u,h)=>(h?.score??1/0)-(u?.score??1/0)),c}function In(n){let e={},t=[],i=[],r=null,s=v.Initial;e.getStatus=()=>s,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=zn;let c={};return e.res=c,c.close=()=>{s!==v.Close&&(s=v.Close,e.onChange())},c.open=()=>{s!==v.Open&&(s=v.Open,e.onChange())},c.respond=u=>{let h=ln(e.getResultBuffer(),u,n);e.setResultBuffer(h)},c.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]))},c.updateContext=u=>{e.setUpdatedContext(u)},e}function Ln(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 J(){return{name:fin.me.name,uuid:fin.me.uuid}}let Nn=50,ne=1e3,ee=new Map;function un(){return ee}let te=100;function oe(){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=un(),s=r.get(n.id);s||(s=Ln(e,n),r.set(n.id,s));let c=In(),u=()=>{let f=c.getResultBuffer();c.setResultBuffer([]);let g=c.getRevokedBuffer();c.setRevokedBuffer([]);let N=c.getUpdatedContext();c.setUpdatedContext(null);let T=c.getStatus();(async function(D){(await I()).dispatch(G,D)})({id:e,providerId:t,results:f,revoked:g,status:T,context:N})},h=!0,C=!1;c.onChange=()=>{if(h)return h=!1,void u();C||(C=!0,setTimeout(()=>{C=!1,u()},te))};try{let{results:f,context:g}=await i.onUserInput(s.req,c.res),N=c.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 Fn(n,e){let t=e||await I(),i=J(),r={...n,identity:i,onResultDispatch:void 0},s=await t.dispatch(En,r);return await an({identity:i,...n}),s}async function ie(n){return await(await I()).dispatch(bn,n),z(n)}async function re(n,e,t,i){let r=An(e,i??J(),t),s=L(n);if(s){let{onResultDispatch:u}=s;return u?u(r):void 0}let c={providerId:n,result:r};return(await I()).dispatch(j,c)}async function se(n){let e={...n,context:n?.context||{}},t={},i=async function*(s,{setState:c}){let u=await I();for(;;){let h=await u.dispatch(Rn,s),C=h.error;if(C)throw new Error(C);let f=h;if(s.id=f.id,c(f.state),f.done)return f.value;yield f.value}}(e,{setState:s=>{t.state=s}}),r=await i.next();return t.id=e.id||"",t.close=()=>{(async function(s){(await I()).dispatch(X,{id:s})})(t.id)},t.next=()=>{if(r){let s=r;return r=void 0,s}return i.next()},t}async function ae(){return(await I()).dispatch(Pn,null)}async function ce(){let n=await I();R=void 0,On(),await n.disconnect()}let le=async n=>{let e=await $n(n);for(let t of cn())await Fn(t,e);return e};async function $n(n){let e=await async function(t){for(let i=0;i<Nn;i++)try{return await fin.InterApplicationBus.Channel.connect(t,{wait:!1})}catch(r){if(i===Nn-1)throw r;await new Promise(s=>setTimeout(s,ne))}}(n);return e.register(G,oe()),e.register(X,t=>{let i=un(),r=i.get(t.id);r&&(r.close(),i.delete(t.id))}),e.register(j,async(t,i)=>{if(!t||!t.providerId||!t.result)return void console.error(S);let r=L(t.providerId);if(!r)return void console.error(y);let{onResultDispatch:s}=r;return s?(t.result.dispatcherIdentity=t.result.dispatcherIdentity??i,s(t.result)):void 0}),e.onDisconnection(function(t){return async()=>{if(!K())return;let i=un();for(let{req:r,close:s}of i.values())s(),i.delete(r.id);Sn(le(t))}}(n)),e}async function ue(n){let e=K();e||(e=$n(n),Sn(e));let t=await e;return{getAllProviders:ae.bind(null),register:Fn.bind(null),search:se.bind(null),deregister:ie.bind(null),dispatch:re.bind(null),disconnect:ce.bind(null),channel:t}}let H;function Q(){if(H)return H;throw P}function de(){return H}function pe(n){H=n}function fe(){H=void 0}let dn=new Set;function he(n){dn.add(n)}function we(n){dn.delete(n)}var k;(function(n){n.Local="local",n.Dev="dev",n.Staging="staging",n.Prod="prod"})(k||(k={}));let pn=typeof window<"u"&&typeof fin<"u",ge=(typeof process>"u"||process.env,typeof window<"u"),ye=ge?window.origin:k.Local,Y=(pn&&fin.me.uuid,pn&&fin.me.name,pn&&fin.me.entityType,k.Local,k.Dev,k.Staging,k.Prod,n=>n.startsWith("http://")||n.startsWith("https://")?n:ye+n),xn=(Y("http://localhost:4002"),Y("http://localhost:4002"),typeof WORKSPACE_DOCS_PLATFORM_URL<"u"&&Y(WORKSPACE_DOCS_PLATFORM_URL),typeof WORKSPACE_DOCS_CLIENT_URL<"u"&&Y(WORKSPACE_DOCS_CLIENT_URL),"20.3.6");typeof WORKSPACE_BUILD_SHA<"u"&&WORKSPACE_BUILD_SHA;async function kn(){return[...cn()].map(n=>({...n,onUserInput:void 0,onResultDispatch:void 0}))}async function me(n){if(L(n.id))throw new Error("provider with name already exists");let e=J();return await an({identity:e,...n}),{workspaceVersion:xn||"",clientAPIVersion:n.clientAPIVersion||""}}async function Ce(n){await z(n)}async function ve(n,e,t,i){let r=L(n);if(!r)throw y;let{onResultDispatch:s}=r;if(s)return s(An(e,i??J(),t))}async function*Se(n,e){let t=function(g,N){let T=[],D=[],B=[],E=[];for(let m of g){let F=In(m.scoreOrder),$={results:[],provider:{id:m.id,identity:m.identity,title:m.title,scoreOrder:m.scoreOrder,icon:m.icon,dispatchFocusEvents:m.dispatchFocusEvents}};T.push($),D.push(F);let M=(async()=>{try{let{results:W,context:nn}=await m.onUserInput(N,F.res);$.results=ln($.results||[],W,m.scoreOrder),$.context={...$.context,...nn}}catch(W){$.error=W}})();M.finally(()=>{M.done=!0}),E.push(M),B.push(B.length)}return{providerResponses:T,listenerResponses:D,openListenerResponses:B,initialResponsePromises:E}}(n.targets?n.targets.map(g=>L(g)).filter(g=>!!g):[...cn().filter(g=>!g.hidden)],n),{providerResponses:i,listenerResponses:r}=t,{openListenerResponses:s,initialResponsePromises:c}=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(c.length){let E=[];for(let m of c)m.done?g=!0:E.push(m);c=E,c.length||(h(x.Fetched),g=!0)}let N,T=!1,D=()=>{T=!0,N&&N()},B=[];for(let E of s){let m=r[E],F=i[E],$=m.getStatus();($===v.Open||u===x.Fetching&&$===v.Initial)&&(B.push(E),m.onChange=D);let M=m.getResultBuffer();M.length&&(m.setResultBuffer([]),F.results=ln(F.results||[],M),g=!0);let W=m.getRevokedBuffer();if(W.length){m.setRevokedBuffer([]);let Be=new Set(W);F.results=(F.results||[]).filter(({key:Me})=>!Be.has(Me)),g=!0}let nn=m.getUpdatedContext();nn&&(m.setUpdatedContext(null),F.context={...F.context,...nn},g=!0)}if(s=B,g&&(yield i),f)break;T||(s.length||c.length)&&await Promise.race([...c,new Promise(E=>{N=E}),new Promise(E=>{C=E})])}while(s.length||c.length);return h(x.Complete),i}let fn=0;async function Tn(n){fn+=1;let e=Ln(fn.toString(),n),t=Se(e.req,{setState:i=>{t.state=i}});return t.id=fn.toString(),t.close=e.close,t.state=x.Fetching,t}let Z=new Map,Re=1e4;function Ee(){return async n=>{if(!n)return console.error(S),{error:S.message};let e;if(n.id)e=n.id;else{let r=await Tn(n);e=r.id,n.id=r.id,Z.set(e,{generator:r})}let t=Z.get(e);clearTimeout(t.timeout);let i=await t.generator.next();return t.timeout=function(r){return window.setTimeout(()=>{Z.delete(r)},Re)}(e),{...i,id:n.id,state:t.generator.state}}}function be(n,e){return Q().dispatch(n,X,{id:e})}function Pe(){return n=>function(e){let t=Z.get(e);t&&t.generator.close()}(n.id)}async function Oe(n,{id:e,query:t,context:i,targets:r=[]}){let s=Q(),c={id:e,query:t,context:i,targets:r,providerId:n.id},u=await s.dispatch(n.identity,G,c),h=u.error;if(h)throw new Error(h);return u}let hn=new Map;function Ae(n,e){return`${n.name}:${n.uuid}:${e}`}let wn=new Map;function _n(n,e){return`${n}:${e}`}function Ie(n){let e=Ae.bind(null,n.identity),t=be.bind(null,n.identity),i=Oe.bind(null,n);return async(r,s)=>{let c=e(r.id);if(!hn.has(c)){let f=()=>{t(r.id),hn.delete(c)};hn.set(c,f),r.onClose(f)}let u=_n(n.id,r.id),h=()=>{wn.delete(u),s.close()};r.onClose(h),wn.set(u,f=>{f.results?.length&&s.respond(f.results),f.revoked?.length&&s.revoke(...f.revoked),f.context&&s.updateContext(f.context),f.status===v.Open&&s.open(),f.status===v.Close&&h()});let C=await i(r);return C.status===v.Open&&s.open(),C.status!==v.Close&&C.status!==v.Initial||h(),C}}function Le(n){return async e=>{let t=Q(),i={providerId:n.id,result:e};return t.dispatch(n.identity,j,i)}}let U=new Map;function gn(n){return`${n.name}-${n.uuid}`}function Ne(){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 O;return n.identity=e,await async function(t){let i=gn(t.identity);U.has(i)||U.set(i,[]),U.get(i).push(t.id),await an({...t,onUserInput:Ie(t),onResultDispatch:Le(t)})}(n),{workspaceVersion:xn||"",clientAPIVersion:n.clientAPIVersion||""}}}function Fe(){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 s=gn(r.identity),c=U.get(s);if(c){let u=c.findIndex(h=>h===t);u!==-1&&(c.splice(u,1),z(t))}}(n,e):console.error(S)}}let yn=new Set;function $e(n){yn.add(n)}function xe(n){yn.delete(n)}function ke(){return async n=>{(function(e){let t=gn(e),i=U.get(t);if(i){for(let r of i)z(r);U.delete(t)}})(n),yn.forEach(e=>e(n))}}async function Te(n){let e=await(t=n,fin.InterApplicationBus.Channel.create(t));var t;return e.onConnection(async i=>{for(let r of dn)if(!await r(i))throw b}),e.onDisconnection(ke()),e.register(X,Pe()),e.register(G,i=>{let r=_n(i.providerId,i.id),s=wn.get(r);s&&s(i)}),e.register(En,Ne()),e.register(bn,Fe()),e.register(Pn,async()=>kn()),e.register(Rn,Ee()),e.register(j,async(i,r)=>{if(!i||!i.providerId||!i.result)return void console.error(S);let s=L(i.providerId);if(!s)throw y;let{onResultDispatch:c}=s;return c?(i.result.dispatcherIdentity=i.result.dispatcherIdentity??r,c(i.result)):void 0}),e}async function _e(){let n=Q();fe(),await n.destroy(),On()}async function Ue(n){let e=de();e||(e=await Te(n),pe(e));let t=we.bind(null),i=xe.bind(null),r=Qn.bind(null),s=Zn.bind(null);return{getAllProviders:kn.bind(null),search:Tn.bind(null),register:me.bind(null),deregister:Ce.bind(null),onSubscription:he.bind(null),onDisconnect:$e.bind(null),onRegister:Jn.bind(null),onDeregister:Yn.bind(null),dispatch:ve.bind(null),disconnect:_e.bind(null),removeListener:c=>{t(c),i(c),r(c),s(c)},channel:e}}let{v:Un}=d,{B:Dn}=a,Bn="all",De={create:Un,subscribe:Dn,defaultTopic:Bn},Mn=()=>{window.search=De},Wn=n=>{let e=()=>{Mn(),window.removeEventListener(n,e)};return e};if(typeof window<"u"){Mn();let n="load",e=Wn(n);window.addEventListener(n,e);let t="DOMContentLoaded",i=Wn(t);window.addEventListener(t,i)}qn.exports=l})()});var w="@openfin/cloud-api";async function A(){try{return await window.fin.View.getCurrentSync().getInfo(),!0}catch{return!1}}function Vn(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 Je(){return`${window.fin.me.uuid}-cloud-api-notifications`}var Cn=null;async function gt(){return Cn||(Cn=Qe()),Cn}async function Qe(){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`);Vn(window.fin.me);let o=await Ye();console.log(o),o.register("openfin-cloud-event",a=>{for(let d of l.get(a.type)??[])typeof a.payload.timestamp=="string"&&(a.payload.timestamp=new Date(a.payload.timestamp)),d(a.payload)});let l=new Map;return{addEventListener:(a,d)=>{let p=l.get(a)||new Set;p.add(d),l.set(a,p)},removeEventListener:(a,d)=>{let p=l.get(a);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?`,a);return}p.delete(d)===!1&&console.warn(`\`${V}\`: Listener was not found for event. Did you pass a function directly instead of a reference?`,a)},update:async a=>(await o.dispatch("openfin-cloud-update-notification",{version:1,payload:{notification:a}})).payload.response,clear:async a=>(await o.dispatch("openfin-cloud-clear-notification",{version:1,payload:{notificationId:a}})).payload.response,createNotification:async a=>(a.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:{...a,id:void 0}}})).payload.response)}}var en=null;async function Ye(){return en||(en=Ze()),en}async function Ze(){let o=await window.fin.InterApplicationBus.Channel.connect(Je());return o.onDisconnection(l=>{console.warn(`\`${V}\`: Channel Disconnected from`,l,"Reconnecting..."),en=null}),o}var vn;function nt(){return`${window.fin.me.uuid}-client-api`}async function _(){return vn||(vn=window.fin.InterApplicationBus.Channel.connect(nt())),vn}async function Ct(){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 _()).dispatch("get-settings")}async function vt(){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 _()).dispatch("get-user-settings")}async function St(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 _()).dispatch("set-user-settings",o)}async function Rt(){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 _()).dispatch("get-user-permissions")}async function Et(o,l){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 a=await _();try{await a.dispatch("launch-content",{id:o,options:l})}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 bt(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 l=await _();try{await l.dispatch("launch-supertab",{id:o})}catch(a){switch(a instanceof Error?a.message:String(a)){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 Pt(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 l=await _();try{await l.dispatch("launch-workspace",{id:o})}catch(a){switch(a instanceof Error?a.message:String(a)){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 Xn={};je(Xn,{register:()=>jn});var Gn=ze(Hn(),1),et="log-message-",tt="open-url",ot="provider-status-",it="registered-",rt="1.0";function st(o,l){let{data:a,...d}=o;return{...d,data:{customData:a,providerId:l,resultType:"app"}}}function Kn(o){return{...o,data:o.data.customData}}function at(){return`${window.fin.me.identity.uuid}-cloud-api-search`}async function ct(o,l,a,d=!0){await l("info",`Setting status as ${d?"ready":"not ready"}`);try{await o.dispatch(`${ot}${a}`,{isReady:d})}catch(p){let y=["Error setting provider status",p];console.error(...y),l("error",...y)}}async function lt(o,l,a,...d){try{await o.dispatch(`${et}${l}`,{level:a,message:d})}catch(p){console.error("Error logging message",p)}}async function ut(o,l,a,d,p){let{action:y,dispatcherIdentity:O,...S}=p;await a("info","Handling action",{action:y,dispatcherIdentity:O,result:S});let b;try{let R=Kn(p).actions?.find(({name:K})=>K===y.name);if(!R)throw new Error("Original action not found in search result");b=(await d(R,Kn(p)))?.url}catch(P){throw await a("error","Error handling dispatch",P),P}if(!b){await a("warn","OnActionListener did not return a URL");return}await pt(o,a,l.id,b,O)}async function dt(o,l,a,d){await l("info","Getting search results",{request:d});try{let p=new AbortController;d.onClose(()=>p.abort());let{context:y,query:O}=d,{results:S}=await a({context:y,query:O,signal:p.signal}),b=S.map(P=>st(P,o.id));return await l("info","Returning results",b),{results:b}}catch(p){let y=["Error handling search",p];throw console.error(...y),l("error",...y),p}}async function pt(o,l,a,d,p){await l("info","Opening URL",{url:d,targetIdentity:p});try{await o.dispatch(tt,{url:d,targetIdentity:p,providerId:a})}catch(y){let O=["Error opening URL",y];console.error(...O),l("error",...O)}}async function jn(o){let a=(await window.fin.me.getOptions()).customData,{configData:d,id:p,title:y}=a,{onAction:O,onSearch:S}=o,b=await Gn.subscribe(at()),P=b.channel,R=lt.bind(null,P,p);return await b.register({icon:"",id:p,onResultDispatch:ut.bind(null,P,a,R,O),onUserInput:dt.bind(null,a,R,S),title:y}),await b.channel.dispatch(`${it}${p}`,{version:rt}),R("info","Registered search topic",{id:p,title:y}),{customData:d,isReady:ct.bind(null,P,R,p)}}export{Xn as Search,Ct as getAppSettings,Rt as getAppUserPermissions,vt as getAppUserSettings,gt as getNotificationsClient,Et as launchContent,bt as launchSupertab,Pt as launchWorkspace,St as setAppUserSettings};
//# sourceMappingURL=index.js.map
{
"name": "@openfin/cloud-api",
"version": "0.0.1-alpha.7cd9387",
"version": "0.0.1-alpha.7dd233b",
"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": {
"@typescript-eslint/eslint-plugin": "^7.5.0",
"@typescript-eslint/parser": "^7.5.0",
"@openfin/core": "^40.102.1",
"@openfin/search-api": "^2.0.1",
"@openfin/typedoc-theme": "^2.0.0",
"@openfin/workspace": "^20.3.11",
"@typescript-eslint/eslint-plugin": "^8.20.0",
"@typescript-eslint/parser": "^8.20.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"
},

@@ -43,0 +47,0 @@ "eslintConfig": {

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