@openfin/cloud-api
Advanced tools
Comparing version 0.0.1-alpha.e7132ff to 0.0.1-alpha.e7138f8
@@ -465,53 +465,71 @@ import * as OpenFin from '@openfin/core'; | ||
* ```ts | ||
* import { Search } from "@openfin/cloud-api"; | ||
* // 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}`); | ||
* } | ||
* }; | ||
* | ||
* const searchAgent = await Search.register({ | ||
* onAction: async (action, result) => { | ||
* const { name } = action; | ||
* const { data, key } = result; | ||
* const { searchResultHostUrl } = data as { searchResultHostUrl: string }; | ||
* console.log(`Action "${name}" triggered on search result with key "${key}"`); | ||
* return { url: `${searchResultHostUrl}/${key}` }; | ||
* }, | ||
* onSearch: async ({ 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, subTitle, title } = result; | ||
* return { | ||
* actions: [ | ||
* { | ||
* name: "view-result", | ||
* description: `Go to ${title} in My Web App`, | ||
* } | ||
* ], | ||
* data: { | ||
* searchResultHostUrl: `https://my-web-app.com/record` | ||
* }, | ||
* icon: iconUrl, | ||
* key, | ||
* label: subTitle, | ||
* title, | ||
* }; | ||
* }); | ||
* console.log('Returning results', results) | ||
* return({ results }); | ||
* } catch (err) { | ||
* if ((err as Error).name === 'AbortError') { | ||
* return { results: [] }; | ||
* } | ||
* throw err; | ||
* } | ||
* }, | ||
* }); | ||
* // 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; | ||
* } | ||
* }; | ||
* | ||
* // Set the Search Agent as ready to receive search requests | ||
* await searchAgent.isReady(); | ||
* // Register the search agent | ||
* const searchAgent = await Search.register({ onAction, onSearch }); | ||
* | ||
* // Set the Search Agent as ready to receive search requests | ||
* await searchAgent.isReady(); | ||
* ``` | ||
@@ -518,0 +536,0 @@ */ |
@@ -1,2 +0,2 @@ | ||
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:()=>Mn,defaultTopic:()=>Vn,subscribe:()=>Bn});var s={};o.r(s),o.d(s,{subscribe:()=>we});var d={};o.r(d),o.d(d,{create:()=>Me});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.0.0");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 M=(async()=>{try{let{results:B,context:en}=await m.onUserInput(N,F.res);k.results=dn(k.results||[],B,m.scoreOrder),k.context={...k.context,...en}}catch(B){k.error=B}})();M.finally(()=>{M.done=!0}),E.push(M),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 M=m.getResultBuffer();M.length&&(m.setResultBuffer([]),F.results=dn(F.results||[],M),g=!0);let B=m.getRevokedBuffer();if(B.length){m.setRevokedBuffer([]);let Ve=new Set(B);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 Me(){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{create:Mn}=d,{subscribe:Bn}=s,Vn="all",Be={create:Mn,subscribe:Bn,defaultTopic:Vn},qn=()=>{window.search=Be},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}; | ||
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.e7132ff", | ||
"version": "0.0.1-alpha.e7138f8", | ||
"sideEffects": false, | ||
@@ -21,3 +21,4 @@ "description": "", | ||
"lint": "eslint . --max-warnings 0", | ||
"lint:fix": "eslint . --fix --max-warnings 0" | ||
"lint:fix": "eslint . --fix --max-warnings 0", | ||
"docs": "typedoc --treatWarningsAsErrors" | ||
}, | ||
@@ -28,5 +29,6 @@ "files": [ | ||
"devDependencies": { | ||
"@openfin/core": "40.100.7", | ||
"@openfin/search-api": "^2.0.0-alpha.7", | ||
"@openfin/workspace": "20.0.5", | ||
"@openfin/core": "40.101.1", | ||
"@openfin/search-api": "^2.0.0", | ||
"@openfin/typedoc-theme": "^2.0.0", | ||
"@openfin/workspace": "20.3.0", | ||
"@typescript-eslint/eslint-plugin": "^7.5.0", | ||
@@ -42,2 +44,3 @@ "@typescript-eslint/parser": "^7.15.0", | ||
"tsup": "^8.3.0", | ||
"typedoc": "^0.26.11", | ||
"typescript": "^5.6.3" | ||
@@ -44,0 +47,0 @@ }, |
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
186779
729
16