@openfin/cloud-api 0.0.1-alpha.fb41cf7 → 0.0.1-alpha.fb5ba58

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/dist/index.cjs CHANGED
@@ -1,2 +1,2 @@
1
- "use strict";Object.defineProperty(exports, "__esModule", {value: true}); function _nullishCoalesce(lhs, rhsFn) { if (lhs != null) { return lhs; } else { return rhsFn(); } }var o="@openfin/cloud-api";function l(){return`${window.fin.me.uuid}-cloud-api-notifications`}async function c(){try{return await window.fin.View.getCurrentSync().getInfo(),!0}catch (e2){return!1}}function f(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 r=null;async function y(){return r||(r=p()),r}async function p(){if(!window.fin)throw new Error(`\`${o}\`: \`getNotificationsClient\` cannot be used in a non-OpenFin environment`);if(await c()===!1)throw new Error(`${o}: \`getNotificationsClient\` cannot be used in a non-OpenFin environment`);f(window.fin.me);let e=await d();console.log(e),e.register("openfin-cloud-event",n=>{for(let t of _nullishCoalesce(i.get(n.type), () => ([])))typeof n.payload.timestamp=="string"&&(n.payload.timestamp=new Date(n.payload.timestamp)),t(n.payload)});let i=new Map;return{addEventListener:(n,t)=>{let a=i.get(n)||new Set;a.add(t),i.set(n,a)},removeEventListener:(n,t)=>{let a=i.get(n);if(!a){console.warn(`\`${o}\`: Listener was not found for event. Did you pass a function directly instead of a reference or forget to add the listener?`,n);return}a.delete(t)===!1&&console.warn(`\`${o}\`: 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(`\`${o}\`: 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 s=null;async function d(){return s||(s=u()),s}async function u(){let e=await window.fin.InterApplicationBus.Channel.connect(l());return e.onDisconnection(i=>{console.warn(`\`${o}\`: Channel Disconnected from`,i,"Reconnecting..."),s=null}),e}exports.getNotificationsClient = y;
1
+ "use strict";Object.defineProperty(exports, "__esModule", {value: true}); function _nullishCoalesce(lhs, rhsFn) { if (lhs != null) { return lhs; } else { return rhsFn(); } }var t="@openfin/cloud-api";async function a(){try{return await window.fin.View.getCurrentSync().getInfo(),!0}catch (e2){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 _nullishCoalesce(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.`)}}}exports.getAppSettings = A; exports.getAppUserPermissions = $; exports.getAppUserSettings = v; exports.getNotificationsClient = g; exports.launchContent = T; exports.setAppUserSettings = P;
2
2
  //# sourceMappingURL=index.cjs.map
@@ -1 +1 @@
1
- {"version":3,"sources":["../src/index.ts"],"names":["PACKAGE_NAME","getChannelName","isInViewContext","extractAppUuidFromIdentity","identity","notificationsClientPromise","getNotificationsClient","getNotificationsClientInternal","channelPromise","getChannelClient","message","listener","eventListeners","eventName","listeners","options","notificationId","channelClientPromise","getChannelClientInternal","channel"],"mappings":"AAMA,IAAMA,EAAe,qBAmBrB,SAASC,GAAiB,CACtB,MAAO,GAAG,OAAO,IAAI,GAAG,IAAI,0BAChC,CAEA,eAAeC,GAAoC,CAC/C,GAAI,CACA,aAAM,OAAO,IAAI,KAAK,eAAe,EAAE,QAAQ,EACxC,EACX,MAAQ,CACJ,MAAO,EACX,CACJ,CAEA,SAASC,EAA2BC,EAAoC,CACpE,GAAIA,EAAS,KAAK,WAAW,oBAAoB,EAC7C,MAAM,IAAI,MAAM,uCAAuC,EAG3D,MAAI,mBAAmB,KAAKA,EAAS,IAAI,EAC9BA,EAAS,KAAK,MAAM,GAAG,EAAE,CAAC,GAAK,GAGnCA,EAAS,IACpB,CAEA,IAAIC,EAAkE,KAmDtE,eAAeC,GAAuD,CAClE,OAAKD,IACDA,EAA6BE,EAA+B,GAGzDF,CACX,CAEA,eAAeE,GAA+D,CAC1E,GAAI,CAAC,OAAO,IACR,MAAM,IAAI,MAAM,KAAKP,CAAY,4EAA4E,EAGjH,GAAK,MAAME,EAAgB,IAAO,GAC9B,MAAM,IAAI,MAAM,GAAGF,CAAY,0EAA0E,EAG7GG,EAA2B,OAAO,IAAI,EAAE,EAExC,IAAMK,EAAiB,MAAMC,EAAiB,EAC9C,QAAQ,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7CD,CACX,CAEA,eAAeC,GAA0D,CACrE,IAAMC,EAAW,MAAM,OAAO,IAAI,oBAAoB,QAAQ,QAAQlB,EAAe,CAAC,EAEtF,OAAAkB,EAAQ,gBAAiBf,GAAa,CAClC,QAAQ,KAAK,KAAKJ,CAAY,gCAAiCI,EAAU,iBAAiB,EAC1Fa,EAAuB,IAC3B,CAAC,EAEME,CACX","sourcesContent":["// eslint-disable-next-line check-file/no-index\nimport type OpenFin from '@openfin/core';\nimport type * as NotificationsTypes from 'openfin-notifications';\n\nimport type { FlannelChannelClient, NotificationEventsMap, NotificationsClient } from './types';\n\nconst PACKAGE_NAME = '@openfin/cloud-api';\n\nexport type {\n FlannelChannelProvider as __INTERNAL_FlannelChannelProvider,\n FlannelCreateNotificationRequest as __INTERNAL_FlannelCreateNotificationRequest,\n FlannelCreateNotificationResponse as __INTERNAL_FlannelCreateNotificationResponse,\n FlannelUpdateNotificationRequest as __INTERNAL_FlannelUpdateNotificationRequest,\n FlannelUpdateNotificationResponse as __INTERNAL_FlannelUpdateNotificationResponse,\n FlannelClearNotificationRequest as __INTERNAL_FlannelClearNotificationRequest,\n FlannelClearNotificationResponse as __INTERNAL_FlannelClearNotificationResponse,\n} from './types';\n\ndeclare global {\n // eslint-disable-next-line @typescript-eslint/consistent-type-definitions\n interface Window {\n fin: typeof import('@openfin/core').fin;\n }\n}\n\nfunction getChannelName() {\n return `${window.fin.me.uuid}-cloud-api-notifications`;\n}\n\nasync function isInViewContext(): Promise<boolean> {\n try {\n await window.fin.View.getCurrentSync().getInfo();\n return true;\n } catch {\n return false;\n }\n}\n\nfunction extractAppUuidFromIdentity(identity: OpenFin.Identity): string {\n if (identity.name.startsWith('internal-generated')) {\n throw new Error('Cannot extract app UUID from identity');\n }\n // <uuid>/<name>\n if (/\\/[\\d,a-z-]{36}$/.test(identity.name)) {\n return identity.name.split('/')[0] || '';\n }\n\n return identity.name;\n}\n\nlet notificationsClientPromise: Promise<NotificationsClient> | null = null;\n\n/**\n * @returns A client for interacting with the OpenFin Notifications service\n *\n * @throws {Error} If the function is called outside of an OpenFin environment\n * @throws {Error} If the function is called outside of an OpenFin View context\n * @throws {Error} If the app UUID cannot be extracted from the current context\n *\n * @example **Basic Usage** Creating a notification, updating it and then clearing it\n * ```ts\n * const notificationsClient = await getNotificationsClient();\n *\n * const notification = await notificationsClient.createNotification({\n * title: 'Hello, World!',\n * body: 'This is a notification from the OpenFin Cloud API',\n * });\n *\n * // Use the `id` from the returned notification to interact with it\n * console.log(notification.id);\n *\n * // Update the notification\n * await notificationsClient.update({\n * id: notification.id,\n * body: 'This is a notification from the OpenFin Cloud API, that has been updated!',\n * })\n *\n * // Clear the notification\n * await notificationsClient.clear(notification.id);\n * ```\n *\n * @example **Advanced Usage** Listening for events\n * ```ts\n * const notificationsClient = await getNotificationsClient();\n *\n * // create the notification\n * const notification = await notificationsClient.createNotification({\n * title: `${window.fin.me.identity.name} Hello, World!`,\n * body: `This is a notification from the cloud API example created at ${new Date().toLocaleTimeString()}`,\n * buttons: [\n * {\n * title: 'Acknowledge',\n * },\n * ],\n * });\n *\n * notificationsClient.addEventListener('notification-action', (event) => {\n * console.log('Notification action:', event);\n * });\n * ```\n */\nasync function getNotificationsClient(): Promise<NotificationsClient> {\n if (!notificationsClientPromise) {\n notificationsClientPromise = getNotificationsClientInternal();\n }\n\n return notificationsClientPromise;\n}\n\nasync function getNotificationsClientInternal(): Promise<NotificationsClient> {\n if (!window.fin) {\n throw new Error(`\\`${PACKAGE_NAME}\\`: \\`getNotificationsClient\\` cannot be used in a non-OpenFin environment`);\n }\n\n if ((await isInViewContext()) === false) {\n throw new Error(`${PACKAGE_NAME}: \\`getNotificationsClient\\` cannot be used in a non-OpenFin environment`);\n }\n\n extractAppUuidFromIdentity(window.fin.me);\n\n const channelPromise = await getChannelClient();\n console.log(channelPromise);\n\n channelPromise.register('openfin-cloud-event', (message) => {\n for (const listener of eventListeners.get(message.type) ?? []) {\n // `Date` is serialized as a string, so we need to convert it back\n if (typeof message.payload.timestamp === 'string') {\n message.payload.timestamp = new Date(message.payload.timestamp);\n }\n\n listener(message.payload as never);\n }\n });\n\n const eventListeners = new Map<keyof NotificationEventsMap, Set<NotificationEventsMap[keyof NotificationEventsMap]>>();\n\n return {\n addEventListener: <T extends keyof NotificationEventsMap>(eventName: T, listener: NotificationEventsMap[T]) => {\n const listeners = eventListeners.get(eventName) || new Set();\n listeners.add(listener);\n eventListeners.set(eventName, listeners);\n },\n removeEventListener: <T extends keyof NotificationEventsMap>(eventName: T, listener: NotificationEventsMap[T]) => {\n const listeners = eventListeners.get(eventName);\n if (!listeners) {\n console.warn(\n `\\`${PACKAGE_NAME}\\`: Listener was not found for event. Did you pass a function directly instead of a reference or forget to add the listener?`,\n eventName,\n );\n return;\n }\n\n if (listeners.delete(listener as (args: unknown) => void) === false) {\n console.warn(`\\`${PACKAGE_NAME}\\`: Listener was not found for event. Did you pass a function directly instead of a reference?`, eventName);\n }\n },\n update: async (options: Parameters<typeof NotificationsTypes.update>[0]): ReturnType<typeof NotificationsTypes.update> => {\n const response = await channelPromise.dispatch('openfin-cloud-update-notification', {\n version: 1,\n payload: {\n notification: options,\n },\n });\n return response.payload.response;\n },\n clear: async (notificationId: Parameters<typeof NotificationsTypes.clear>[0]): ReturnType<typeof NotificationsTypes.clear> => {\n const response = await channelPromise.dispatch('openfin-cloud-clear-notification', {\n version: 1,\n payload: {\n notificationId,\n },\n });\n return response.payload.response;\n },\n createNotification: async (\n options: NotificationsTypes.NotificationOptions,\n ): Promise<NotificationsTypes.Notification<NotificationsTypes.NotificationOptions>> => {\n if (options.id) {\n console.warn(\n `\\`${PACKAGE_NAME}\\`: 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.`,\n );\n }\n const response = await channelPromise.dispatch('openfin-cloud-create-notification', {\n version: 1,\n payload: {\n notification: { ...options, id: undefined },\n },\n });\n return response.payload.response;\n },\n };\n}\n\nlet channelClientPromise: Promise<FlannelChannelClient> | null = null;\n\nasync function getChannelClient(): Promise<FlannelChannelClient> {\n if (!channelClientPromise) {\n channelClientPromise = getChannelClientInternal();\n }\n\n return channelClientPromise;\n}\n\nasync function getChannelClientInternal(): Promise<FlannelChannelClient> {\n const channel = (await window.fin.InterApplicationBus.Channel.connect(getChannelName())) as FlannelChannelClient;\n\n channel.onDisconnection((identity) => {\n console.warn(`\\`${PACKAGE_NAME}\\`: Channel Disconnected from`, identity, 'Reconnecting...');\n channelClientPromise = null;\n });\n\n return channel;\n}\n\nexport { getNotificationsClient };\n"]}
1
+ {"version":3,"sources":["../src/utils.ts","../src/notifications.ts","../src/client-api.ts"],"names":["PACKAGE_NAME","isInViewContext","extractAppUuidFromIdentity","identity","getChannelName","notificationsClientPromise","getNotificationsClient","getNotificationsClientInternal","channelPromise","getChannelClient","message","listener","eventListeners","eventName","listeners","options","notificationId","channelClientPromise","getChannelClientInternal","channel","apiChannelClientPromise","getApiChannelName","getApiChannelClient","getAppSettings","getAppUserSettings","setAppUserSettings","settings","getAppUserPermissions","launchContent","id","error"],"mappings":"AAEO,IAAMA,EAAe,qBAE5B,eAAsBC,GAAoC,CACtD,GAAI,CACA,aAAM,OAAO,IAAI,KAAK,eAAe,EAAE,QAAQ,EACxC,EACX,MAAQ,CACJ,MAAO,EACX,CACJ,CAEO,SAASC,EAA2BC,EAAoC,CAC3E,GAAIA,EAAS,KAAK,WAAW,oBAAoB,EAC7C,MAAM,IAAI,MAAM,uCAAuC,EAG3D,MAAI,mBAAmB,KAAKA,EAAS,IAAI,EAC9BA,EAAS,KAAK,MAAM,GAAG,EAAE,CAAC,GAAK,GAGnCA,EAAS,IACpB,CCjBA,IAAMH,EAAe,qBAmBrB,SAASI,GAAiB,CACtB,MAAO,GAAG,OAAO,IAAI,GAAG,IAAI,0BAChC,CAEA,IAAIC,EAAkE,KAmDtE,eAAeC,GAAuD,CAClE,OAAKD,IACDA,EAA6BE,EAA+B,GAGzDF,CACX,CAEA,eAAeE,GAA+D,CAC1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AMC,EAAgB,IAAO,GAC9B,MAAM,IAAI,MAAM,GAAGD,CAAY,sEAAsE,EAKzG,OAFgB,MAAMsB,EAAoB,GAE3B,SAAS,oBAAqBI,CAAQ,CACzD,CAQA,eAAeC,GAAiD,CAC5D,GAAI,CAAC,OAAO,IACR,MAAM,IAAI,MAAM,KAAK3B,CAAY,2EAA2E,EAGhH,GAAK,MAAMC,EAAgB,IAAO,GAC9B,MAAM,IAAI,MAAM,GAAGD,CAAY,yEAAyE,EAK5G,OAFgB,MAAMsB,EAAoB,GAE3B,SAAS,sBAAsB,CAClD,CAYA,eAAeM,EAAcC,EAA2B,CACpD,GAAI,CAAC,OAAO,IACR,MAAM,IAAI,MAAM,KAAK7B,CAAY,mEAAmE,EAGxG,GAAK,MAAMC,EAAgB,IAAO,GAC9B,MAAM,IAAI,MAAM,GAAGD,CAAY,4EAA4E,EAG/G,IAAMmB,EAAU,MAAMG,EAAoB,EAE1C,GAAI,CACA,MAAMH,EAAQ,SAAS,iBAAkB,CAAE,GAAAU,CAAG,CAAC,CACnD,OAASC,EAAO,CAEZ,OADqBA,aAAiB,MAAQA,EAAM,QAAU,OAAOA,CAAK,EACpD,CAClB,IAAK,iBACD,MAAM,IAAI,MAAM,GAAG9B,CAAY,6DAA6D6B,CAAE,EAAE,EAEpG,IAAK,iBACD,MAAM,IAAI,MAAM,GAAG7B,CAAY,6DAA6D6B,CAAE,EAAE,EAEpG,IAAK,iBACD,MAAM,IAAI,MAAM,GAAG7B,CAAY,qDAAqD6B,CAAE,EAAE,EAE5F,QACI,MAAM,IAAI,MAAM,GAAG7B,CAAY,wEAAwE6B,CAAE,gCAAgC,CAEjJ,CACJ,CACJ","sourcesContent":["import type OpenFin from '@openfin/core';\n\nexport const PACKAGE_NAME = '@openfin/cloud-api';\n\nexport async function isInViewContext(): Promise<boolean> {\n try {\n await window.fin.View.getCurrentSync().getInfo();\n return true;\n } catch {\n return false;\n }\n}\n\nexport function extractAppUuidFromIdentity(identity: OpenFin.Identity): string {\n if (identity.name.startsWith('internal-generated')) {\n throw new Error('Cannot extract app UUID from identity');\n }\n // <uuid>/<name>\n if (/\\/[\\d,a-z-]{36}$/.test(identity.name)) {\n return identity.name.split('/')[0] || '';\n }\n\n return identity.name;\n}\n","// eslint-disable-next-line check-file/no-index\nimport type * as NotificationsTypes from 'openfin-notifications';\n\nimport type { FlannelChannelClient, NotificationEventsMap, NotificationsClient } from './types';\nimport { extractAppUuidFromIdentity, isInViewContext } from './utils';\n\nconst PACKAGE_NAME = '@openfin/cloud-api';\n\nexport type {\n FlannelChannelProvider as __INTERNAL_FlannelChannelProvider,\n FlannelCreateNotificationRequest as __INTERNAL_FlannelCreateNotificationRequest,\n FlannelCreateNotificationResponse as __INTERNAL_FlannelCreateNotificationResponse,\n FlannelUpdateNotificationRequest as __INTERNAL_FlannelUpdateNotificationRequest,\n FlannelUpdateNotificationResponse as __INTERNAL_FlannelUpdateNotificationResponse,\n FlannelClearNotificationRequest as __INTERNAL_FlannelClearNotificationRequest,\n FlannelClearNotificationResponse as __INTERNAL_FlannelClearNotificationResponse,\n} from './types';\n\ndeclare global {\n // eslint-disable-next-line @typescript-eslint/consistent-type-definitions\n interface Window {\n fin: typeof import('@openfin/core').fin;\n }\n}\n\nfunction getChannelName() {\n return `${window.fin.me.uuid}-cloud-api-notifications`;\n}\n\nlet notificationsClientPromise: Promise<NotificationsClient> | null = null;\n\n/**\n * @returns A client for interacting with the OpenFin Notifications service\n *\n * @throws {Error} If the function is called outside of an OpenFin environment\n * @throws {Error} If the function is called outside of an OpenFin View context\n * @throws {Error} If the app UUID cannot be extracted from the current context\n *\n * @example **Basic Usage** Creating a notification, updating it and then clearing it\n * ```ts\n * const notificationsClient = await getNotificationsClient();\n *\n * const notification = await notificationsClient.createNotification({\n * title: 'Hello, World!',\n * body: 'This is a notification from the OpenFin Cloud API',\n * });\n *\n * // Use the `id` from the returned notification to interact with it\n * console.log(notification.id);\n *\n * // Update the notification\n * await notificationsClient.update({\n * id: notification.id,\n * body: 'This is a notification from the OpenFin Cloud API, that has been updated!',\n * })\n *\n * // Clear the notification\n * await notificationsClient.clear(notification.id);\n * ```\n *\n * @example **Advanced Usage** Listening for events\n * ```ts\n * const notificationsClient = await getNotificationsClient();\n *\n * // create the notification\n * const notification = await notificationsClient.createNotification({\n * title: `${window.fin.me.identity.name} Hello, World!`,\n * body: `This is a notification from the cloud API example created at ${new Date().toLocaleTimeString()}`,\n * buttons: [\n * {\n * title: 'Acknowledge',\n * },\n * ],\n * });\n *\n * notificationsClient.addEventListener('notification-action', (event) => {\n * console.log('Notification action:', event);\n * });\n * ```\n */\nasync function getNotificationsClient(): Promise<NotificationsClient> {\n if (!notificationsClientPromise) {\n notificationsClientPromise = getNotificationsClientInternal();\n }\n\n return notificationsClientPromise;\n}\n\nasync function getNotificationsClientInternal(): Promise<NotificationsClient> {\n if (!window.fin) {\n throw new Error(`\\`${PACKAGE_NAME}\\`: \\`getNotificationsClient\\` cannot be used in a non-OpenFin environment`);\n }\n\n if ((await isInViewContext()) === false) {\n throw new Error(`${PACKAGE_NAME}: \\`getNotificationsClient\\` cannot be used in a non-OpenFin environment`);\n }\n\n extractAppUuidFromIdentity(window.fin.me);\n\n const channelPromise = await getChannelClient();\n console.log(channelPromise);\n\n channelPromise.register('openfin-cloud-event', (message) => {\n for (const listener of eventListeners.get(message.type) ?? []) {\n // `Date` is serialized as a string, so we need to convert it back\n if (typeof message.payload.timestamp === 'string') {\n message.payload.timestamp = new Date(message.payload.timestamp);\n }\n\n listener(message.payload as never);\n }\n });\n\n const eventListeners = new Map<keyof NotificationEventsMap, Set<NotificationEventsMap[keyof NotificationEventsMap]>>();\n\n return {\n addEventListener: <T extends keyof NotificationEventsMap>(eventName: T, listener: NotificationEventsMap[T]) => {\n const listeners = eventListeners.get(eventName) || new Set();\n listeners.add(listener);\n eventListeners.set(eventName, listeners);\n },\n removeEventListener: <T extends keyof NotificationEventsMap>(eventName: T, listener: NotificationEventsMap[T]) => {\n const listeners = eventListeners.get(eventName);\n if (!listeners) {\n console.warn(\n `\\`${PACKAGE_NAME}\\`: Listener was not found for event. Did you pass a function directly instead of a reference or forget to add the listener?`,\n eventName,\n );\n return;\n }\n\n if (listeners.delete(listener as (args: unknown) => void) === false) {\n console.warn(`\\`${PACKAGE_NAME}\\`: Listener was not found for event. Did you pass a function directly instead of a reference?`, eventName);\n }\n },\n update: async (options: Parameters<typeof NotificationsTypes.update>[0]): ReturnType<typeof NotificationsTypes.update> => {\n const response = await channelPromise.dispatch('openfin-cloud-update-notification', {\n version: 1,\n payload: {\n notification: options,\n },\n });\n return response.payload.response;\n },\n clear: async (notificationId: Parameters<typeof NotificationsTypes.clear>[0]): ReturnType<typeof NotificationsTypes.clear> => {\n const response = await channelPromise.dispatch('openfin-cloud-clear-notification', {\n version: 1,\n payload: {\n notificationId,\n },\n });\n return response.payload.response;\n },\n createNotification: async (\n options: NotificationsTypes.NotificationOptions,\n ): Promise<NotificationsTypes.Notification<NotificationsTypes.NotificationOptions>> => {\n if (options.id) {\n console.warn(\n `\\`${PACKAGE_NAME}\\`: 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.`,\n );\n }\n const response = await channelPromise.dispatch('openfin-cloud-create-notification', {\n version: 1,\n payload: {\n notification: { ...options, id: undefined },\n },\n });\n return response.payload.response;\n },\n };\n}\n\nlet channelClientPromise: Promise<FlannelChannelClient> | null = null;\n\nasync function getChannelClient(): Promise<FlannelChannelClient> {\n if (!channelClientPromise) {\n channelClientPromise = getChannelClientInternal();\n }\n\n return channelClientPromise;\n}\n\nasync function getChannelClientInternal(): Promise<FlannelChannelClient> {\n const channel = (await window.fin.InterApplicationBus.Channel.connect(getChannelName())) as FlannelChannelClient;\n\n channel.onDisconnection((identity) => {\n console.warn(`\\`${PACKAGE_NAME}\\`: Channel Disconnected from`, identity, 'Reconnecting...');\n channelClientPromise = null;\n });\n\n return channel;\n}\n\nexport { getNotificationsClient };\n","import type OpenFin from '@openfin/core';\n\nimport { isInViewContext, PACKAGE_NAME } from './utils';\n\nlet apiChannelClientPromise: Promise<OpenFin.ChannelClient>;\n\n/**\n * Represents a collection of returned app permissions\n */\nexport type AppPermissions = {\n permissions: {\n /**\n * The name of the permission\n */\n name: string;\n /**\n * The ID of the permission\n */\n id: string;\n }[];\n};\n\nfunction getApiChannelName() {\n return `${window.fin.me.uuid}-client-api`;\n}\n\nasync function getApiChannelClient(): Promise<OpenFin.ChannelClient> {\n if (!apiChannelClientPromise) {\n apiChannelClientPromise = window.fin.InterApplicationBus.Channel.connect(getApiChannelName());\n }\n\n return apiChannelClientPromise;\n}\n\n/**\n * @returns The app settings that have been set against the current app\n *\n * @throws {Error} If the function is called outside of an OpenFin environment\n * @throws {Error} If the function is called outside of an OpenFin View context\n */\nasync function getAppSettings(): Promise<unknown> {\n if (!window.fin) {\n throw new Error(`\\`${PACKAGE_NAME}\\`: \\`getAppSettings\\` cannot be used in a non-OpenFin environment`);\n }\n\n if ((await isInViewContext()) === false) {\n throw new Error(`${PACKAGE_NAME}: \\`getAppSettings\\` cannot be used in a non-OpenFin environment`);\n }\n\n const channel = await getApiChannelClient();\n\n return channel.dispatch('get-settings');\n}\n\n/**\n * @returns The app settings that have been set against the current app for the current user\n *\n * @throws {Error} If the function is called outside of an OpenFin environment\n * @throws {Error} If the function is called outside of an OpenFin View context\n */\nasync function getAppUserSettings(): Promise<unknown> {\n if (!window.fin) {\n throw new Error(`\\`${PACKAGE_NAME}\\`: \\`getAppUserSettings\\` cannot be used in a non-OpenFin environment`);\n }\n\n if ((await isInViewContext()) === false) {\n throw new Error(`${PACKAGE_NAME}: \\`getAppUserSettings\\` cannot be used in a non-OpenFin environment`);\n }\n\n const channel = await getApiChannelClient();\n\n return channel.dispatch('get-user-settings');\n}\n\n/**\n * Assigns a set of user specific settings to the current app\n *\n * @returns The app settings that have been set against the current app for the current user\n *\n * @throws {Error} If the function is called outside of an OpenFin environment\n * @throws {Error} If the function is called outside of an OpenFin View context\n */\nasync function setAppUserSettings(settings: unknown): Promise<unknown> {\n if (!window.fin) {\n throw new Error(`\\`${PACKAGE_NAME}\\`: \\`setAppUserSettings\\` cannot be used in a non-OpenFin environment`);\n }\n\n if ((await isInViewContext()) === false) {\n throw new Error(`${PACKAGE_NAME}: \\`setAppUserSettings\\` cannot be used in a non-OpenFin environment`);\n }\n\n const channel = await getApiChannelClient();\n\n return channel.dispatch('set-user-settings', settings);\n}\n\n/**\n * @returns The permissions that have been set against the current app for the current user\n *\n * @throws {Error} If the function is called outside of an OpenFin environment\n * @throws {Error} If the function is called outside of an OpenFin View context\n */\nasync function getAppUserPermissions(): Promise<AppPermissions> {\n if (!window.fin) {\n throw new Error(`\\`${PACKAGE_NAME}\\`: \\`getAppUserPermissions\\` cannot be used in a non-OpenFin environment`);\n }\n\n if ((await isInViewContext()) === false) {\n throw new Error(`${PACKAGE_NAME}: \\`getAppUserPermissions\\` cannot be used in a non-OpenFin environment`);\n }\n\n const channel = await getApiChannelClient();\n\n return channel.dispatch('get-user-permissions');\n}\n\n/**\n * A function allowing the easy launching of content\n * @param id The id of the content to launch\n * @returns nothing\n *\n * @throws {Error} If the function is called outside of an OpenFin environment\n * @throws {Error} If the function is called outside of an OpenFin View context\n * @throws {Error} If the function has been unable to look up or launch the content\n * @throws {Error} If the function is unable to find content with the provided id.\n */\nasync function launchContent(id: string): Promise<void> {\n if (!window.fin) {\n throw new Error(`\\`${PACKAGE_NAME}\\`: \\`launchContent\\` cannot be used in a non-OpenFin environment`);\n }\n\n if ((await isInViewContext()) === false) {\n throw new Error(`${PACKAGE_NAME}: \\`launchContent\\` cannot be used in a outside of an OpenFin View context`);\n }\n\n const channel = await getApiChannelClient();\n\n try {\n await channel.dispatch('launch-content', { id });\n } catch (error) {\n const errorMessage = error instanceof Error ? error.message : String(error);\n switch (errorMessage) {\n case 'UnableToLookup': {\n throw new Error(`${PACKAGE_NAME}: \\`launchContent\\` was unable to lookup content with id: ${id}`);\n }\n case 'UnableToLaunch': {\n throw new Error(`${PACKAGE_NAME}: \\`launchContent\\` was unable to launch content with id: ${id}`);\n }\n case 'NoContentFound': {\n throw new Error(`${PACKAGE_NAME}: \\`launchContent\\` did not find content with id: ${id}`);\n }\n default: {\n throw new Error(`${PACKAGE_NAME}: \\`launchContent\\` was unable to look up or launch content with id: ${id} or the content did not exist.`);\n }\n }\n }\n}\n\nexport { getAppSettings, getAppUserSettings, setAppUserSettings, getAppUserPermissions, launchContent };\n"]}
package/dist/index.d.cts CHANGED
@@ -208,4 +208,61 @@ declare global {
208
208
  */
209
209
  declare function getNotificationsClient(): Promise<NotificationsClient>;
210
210
 
211
- export { 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, getNotificationsClient };
211
+ /**
212
+ * Represents a collection of returned app permissions
213
+ */
214
+ type AppPermissions = {
215
+ permissions: {
216
+ /**
217
+ * The name of the permission
218
+ */
219
+ name: string;
220
+ /**
221
+ * The ID of the permission
222
+ */
223
+ id: string;
224
+ }[];
225
+ };
226
+ /**
227
+ * @returns The app settings that have been set against the current app
228
+ *
229
+ * @throws {Error} If the function is called outside of an OpenFin environment
230
+ * @throws {Error} If the function is called outside of an OpenFin View context
231
+ */
232
+ declare function getAppSettings(): Promise<unknown>;
233
+ /**
234
+ * @returns The app settings that have been set against the current app for the current user
235
+ *
236
+ * @throws {Error} If the function is called outside of an OpenFin environment
237
+ * @throws {Error} If the function is called outside of an OpenFin View context
238
+ */
239
+ declare function getAppUserSettings(): Promise<unknown>;
240
+ /**
241
+ * Assigns a set of user specific settings to the current app
242
+ *
243
+ * @returns The app settings that have been set against the current app for the current user
244
+ *
245
+ * @throws {Error} If the function is called outside of an OpenFin environment
246
+ * @throws {Error} If the function is called outside of an OpenFin View context
247
+ */
248
+ declare function setAppUserSettings(settings: unknown): Promise<unknown>;
249
+ /**
250
+ * @returns The permissions that have been set against the current app for the current user
251
+ *
252
+ * @throws {Error} If the function is called outside of an OpenFin environment
253
+ * @throws {Error} If the function is called outside of an OpenFin View context
254
+ */
255
+ declare function getAppUserPermissions(): Promise<AppPermissions>;
256
+ /**
257
+ * A function allowing the easy launching of content
258
+ * @param id The id of the content to launch
259
+ * @returns nothing
260
+ *
261
+ * @throws {Error} If the function is called outside of an OpenFin environment
262
+ * @throws {Error} If the function is called outside of an OpenFin View context
263
+ * @throws {Error} If the function has been unable to look up or launch the content
264
+ * @throws {Error} If the function is unable to find content with the provided id.
265
+ */
266
+ declare function launchContent(id: string): Promise<void>;
267
+
268
+ 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 };
package/dist/index.d.ts CHANGED
@@ -208,4 +208,61 @@ declare global {
208
208
  */
209
209
  declare function getNotificationsClient(): Promise<NotificationsClient>;
210
210
 
211
- export { 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, getNotificationsClient };
211
+ /**
212
+ * Represents a collection of returned app permissions
213
+ */
214
+ type AppPermissions = {
215
+ permissions: {
216
+ /**
217
+ * The name of the permission
218
+ */
219
+ name: string;
220
+ /**
221
+ * The ID of the permission
222
+ */
223
+ id: string;
224
+ }[];
225
+ };
226
+ /**
227
+ * @returns The app settings that have been set against the current app
228
+ *
229
+ * @throws {Error} If the function is called outside of an OpenFin environment
230
+ * @throws {Error} If the function is called outside of an OpenFin View context
231
+ */
232
+ declare function getAppSettings(): Promise<unknown>;
233
+ /**
234
+ * @returns The app settings that have been set against the current app for the current user
235
+ *
236
+ * @throws {Error} If the function is called outside of an OpenFin environment
237
+ * @throws {Error} If the function is called outside of an OpenFin View context
238
+ */
239
+ declare function getAppUserSettings(): Promise<unknown>;
240
+ /**
241
+ * Assigns a set of user specific settings to the current app
242
+ *
243
+ * @returns The app settings that have been set against the current app for the current user
244
+ *
245
+ * @throws {Error} If the function is called outside of an OpenFin environment
246
+ * @throws {Error} If the function is called outside of an OpenFin View context
247
+ */
248
+ declare function setAppUserSettings(settings: unknown): Promise<unknown>;
249
+ /**
250
+ * @returns The permissions that have been set against the current app for the current user
251
+ *
252
+ * @throws {Error} If the function is called outside of an OpenFin environment
253
+ * @throws {Error} If the function is called outside of an OpenFin View context
254
+ */
255
+ declare function getAppUserPermissions(): Promise<AppPermissions>;
256
+ /**
257
+ * A function allowing the easy launching of content
258
+ * @param id The id of the content to launch
259
+ * @returns nothing
260
+ *
261
+ * @throws {Error} If the function is called outside of an OpenFin environment
262
+ * @throws {Error} If the function is called outside of an OpenFin View context
263
+ * @throws {Error} If the function has been unable to look up or launch the content
264
+ * @throws {Error} If the function is unable to find content with the provided id.
265
+ */
266
+ declare function launchContent(id: string): Promise<void>;
267
+
268
+ 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 };
package/dist/index.js CHANGED
@@ -1,2 +1,2 @@
1
- var o="@openfin/cloud-api";function l(){return`${window.fin.me.uuid}-cloud-api-notifications`}async function c(){try{return await window.fin.View.getCurrentSync().getInfo(),!0}catch{return!1}}function f(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 r=null;async function y(){return r||(r=p()),r}async function p(){if(!window.fin)throw new Error(`\`${o}\`: \`getNotificationsClient\` cannot be used in a non-OpenFin environment`);if(await c()===!1)throw new Error(`${o}: \`getNotificationsClient\` cannot be used in a non-OpenFin environment`);f(window.fin.me);let e=await d();console.log(e),e.register("openfin-cloud-event",n=>{for(let t of i.get(n.type)??[])typeof n.payload.timestamp=="string"&&(n.payload.timestamp=new Date(n.payload.timestamp)),t(n.payload)});let i=new Map;return{addEventListener:(n,t)=>{let a=i.get(n)||new Set;a.add(t),i.set(n,a)},removeEventListener:(n,t)=>{let a=i.get(n);if(!a){console.warn(`\`${o}\`: Listener was not found for event. Did you pass a function directly instead of a reference or forget to add the listener?`,n);return}a.delete(t)===!1&&console.warn(`\`${o}\`: 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(`\`${o}\`: 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 s=null;async function d(){return s||(s=u()),s}async function u(){let e=await window.fin.InterApplicationBus.Channel.connect(l());return e.onDisconnection(i=>{console.warn(`\`${o}\`: Channel Disconnected from`,i,"Reconnecting..."),s=null}),e}export{y as getNotificationsClient};
1
+ 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};
2
2
  //# sourceMappingURL=index.js.map
package/dist/index.js.map CHANGED
@@ -1 +1 @@
1
- {"version":3,"sources":["../src/index.ts"],"sourcesContent":["// eslint-disable-next-line check-file/no-index\nimport type OpenFin from '@openfin/core';\nimport type * as NotificationsTypes from 'openfin-notifications';\n\nimport type { FlannelChannelClient, NotificationEventsMap, NotificationsClient } from './types';\n\nconst PACKAGE_NAME = '@openfin/cloud-api';\n\nexport type {\n FlannelChannelProvider as __INTERNAL_FlannelChannelProvider,\n FlannelCreateNotificationRequest as __INTERNAL_FlannelCreateNotificationRequest,\n FlannelCreateNotificationResponse as __INTERNAL_FlannelCreateNotificationResponse,\n FlannelUpdateNotificationRequest as __INTERNAL_FlannelUpdateNotificationRequest,\n FlannelUpdateNotificationResponse as __INTERNAL_FlannelUpdateNotificationResponse,\n FlannelClearNotificationRequest as __INTERNAL_FlannelClearNotificationRequest,\n FlannelClearNotificationResponse as __INTERNAL_FlannelClearNotificationResponse,\n} from './types';\n\ndeclare global {\n // eslint-disable-next-line @typescript-eslint/consistent-type-definitions\n interface Window {\n fin: typeof import('@openfin/core').fin;\n }\n}\n\nfunction getChannelName() {\n return `${window.fin.me.uuid}-cloud-api-notifications`;\n}\n\nasync function isInViewContext(): Promise<boolean> {\n try {\n await window.fin.View.getCurrentSync().getInfo();\n return true;\n } catch {\n return false;\n }\n}\n\nfunction extractAppUuidFromIdentity(identity: OpenFin.Identity): string {\n if (identity.name.startsWith('internal-generated')) {\n throw new Error('Cannot extract app UUID from identity');\n }\n // <uuid>/<name>\n if (/\\/[\\d,a-z-]{36}$/.test(identity.name)) {\n return identity.name.split('/')[0] || '';\n }\n\n return identity.name;\n}\n\nlet notificationsClientPromise: Promise<NotificationsClient> | null = null;\n\n/**\n * @returns A client for interacting with the OpenFin Notifications service\n *\n * @throws {Error} If the function is called outside of an OpenFin environment\n * @throws {Error} If the function is called outside of an OpenFin View context\n * @throws {Error} If the app UUID cannot be extracted from the current context\n *\n * @example **Basic Usage** Creating a notification, updating it and then clearing it\n * ```ts\n * const notificationsClient = await getNotificationsClient();\n *\n * const notification = await notificationsClient.createNotification({\n * title: 'Hello, World!',\n * body: 'This is a notification from the OpenFin Cloud API',\n * });\n *\n * // Use the `id` from the returned notification to interact with it\n * console.log(notification.id);\n *\n * // Update the notification\n * await notificationsClient.update({\n * id: notification.id,\n * body: 'This is a notification from the OpenFin Cloud API, that has been updated!',\n * })\n *\n * // Clear the notification\n * await notificationsClient.clear(notification.id);\n * ```\n *\n * @example **Advanced Usage** Listening for events\n * ```ts\n * const notificationsClient = await getNotificationsClient();\n *\n * // create the notification\n * const notification = await notificationsClient.createNotification({\n * title: `${window.fin.me.identity.name} Hello, World!`,\n * body: `This is a notification from the cloud API example created at ${new Date().toLocaleTimeString()}`,\n * buttons: [\n * {\n * title: 'Acknowledge',\n * },\n * ],\n * });\n *\n * notificationsClient.addEventListener('notification-action', (event) => {\n * console.log('Notification action:', event);\n * });\n * ```\n */\nasync function getNotificationsClient(): Promise<NotificationsClient> {\n if (!notificationsClientPromise) {\n notificationsClientPromise = getNotificationsClientInternal();\n }\n\n return notificationsClientPromise;\n}\n\nasync function getNotificationsClientInternal(): Promise<NotificationsClient> {\n if (!window.fin) {\n throw new Error(`\\`${PACKAGE_NAME}\\`: \\`getNotificationsClient\\` cannot be used in a non-OpenFin environment`);\n }\n\n if ((await isInViewContext()) === false) {\n throw new Error(`${PACKAGE_NAME}: \\`getNotificationsClient\\` cannot be used in a non-OpenFin environment`);\n }\n\n extractAppUuidFromIdentity(window.fin.me);\n\n const channelPromise = await getChannelClient();\n console.log(channelPromise);\n\n channelPromise.register('openfin-cloud-event', (message) => {\n for (const listener of eventListeners.get(message.type) ?? []) {\n // `Date` is serialized as a string, so we need to convert it back\n if (typeof message.payload.timestamp === 'string') {\n message.payload.timestamp = new Date(message.payload.timestamp);\n }\n\n listener(message.payload as never);\n }\n });\n\n const eventListeners = new Map<keyof NotificationEventsMap, Set<NotificationEventsMap[keyof NotificationEventsMap]>>();\n\n return {\n addEventListener: <T extends keyof NotificationEventsMap>(eventName: T, listener: NotificationEventsMap[T]) => {\n const listeners = eventListeners.get(eventName) || new Set();\n listeners.add(listener);\n eventListeners.set(eventName, listeners);\n },\n removeEventListener: <T extends keyof NotificationEventsMap>(eventName: T, listener: NotificationEventsMap[T]) => {\n const listeners = eventListeners.get(eventName);\n if (!listeners) {\n console.warn(\n `\\`${PACKAGE_NAME}\\`: Listener was not found for event. Did you pass a function directly instead of a reference or forget to add the listener?`,\n eventName,\n );\n return;\n }\n\n if (listeners.delete(listener as (args: unknown) => void) === false) {\n console.warn(`\\`${PACKAGE_NAME}\\`: Listener was not found for event. Did you pass a function directly instead of a reference?`, eventName);\n }\n },\n update: async (options: Parameters<typeof NotificationsTypes.update>[0]): ReturnType<typeof NotificationsTypes.update> => {\n const response = await channelPromise.dispatch('openfin-cloud-update-notification', {\n version: 1,\n payload: {\n notification: options,\n },\n });\n return response.payload.response;\n },\n clear: async (notificationId: Parameters<typeof NotificationsTypes.clear>[0]): ReturnType<typeof NotificationsTypes.clear> => {\n const response = await channelPromise.dispatch('openfin-cloud-clear-notification', {\n version: 1,\n payload: {\n notificationId,\n },\n });\n return response.payload.response;\n },\n createNotification: async (\n options: NotificationsTypes.NotificationOptions,\n ): Promise<NotificationsTypes.Notification<NotificationsTypes.NotificationOptions>> => {\n if (options.id) {\n console.warn(\n `\\`${PACKAGE_NAME}\\`: 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.`,\n );\n }\n const response = await channelPromise.dispatch('openfin-cloud-create-notification', {\n version: 1,\n payload: {\n notification: { ...options, id: undefined },\n },\n });\n return response.payload.response;\n },\n };\n}\n\nlet channelClientPromise: Promise<FlannelChannelClient> | null = null;\n\nasync function getChannelClient(): Promise<FlannelChannelClient> {\n if (!channelClientPromise) {\n channelClientPromise = getChannelClientInternal();\n }\n\n return channelClientPromise;\n}\n\nasync function getChannelClientInternal(): Promise<FlannelChannelClient> {\n const channel = (await window.fin.InterApplicationBus.Channel.connect(getChannelName())) as FlannelChannelClient;\n\n channel.onDisconnection((identity) => {\n console.warn(`\\`${PACKAGE_NAME}\\`: Channel Disconnected from`, identity, 'Reconnecting...');\n channelClientPromise = null;\n });\n\n return channel;\n}\n\nexport { getNotificationsClient };\n"],"mappings":"AAMA,IAAMA,EAAe,qBAmBrB,SAASC,GAAiB,CACtB,MAAO,GAAG,OAAO,IAAI,GAAG,IAAI,0BAChC,CAEA,eAAeC,GAAoC,CAC/C,GAAI,CACA,aAAM,OAAO,IAAI,KAAK,eAAe,EAAE,QAAQ,EACxC,EACX,MAAQ,CACJ,MAAO,EACX,CACJ,CAEA,SAASC,EAA2BC,EAAoC,CACpE,GAAIA,EAAS,KAAK,WAAW,oBAAoB,EAC7C,MAAM,IAAI,MAAM,uCAAuC,EAG3D,MAAI,mBAAmB,KAAKA,EAAS,IAAI,EAC9BA,EAAS,KAAK,MAAM,GAAG,EAAE,CAAC,GAAK,GAGnCA,EAAS,IACpB,CAEA,IAAIC,EAAkE,KAmDtE,eAAeC,GAAuD,CAClE,OAAKD,IACDA,EAA6BE,EAA+B,GAGzDF,CACX,CAEA,eAAeE,GAA+D,CAC1E,GAAI,CAAC,OAAO,IACR,MAAM,IAAI,MAAM,KAAKP,CAAY,4EAA4E,EAGjH,GAAK,MAAME,EAAgB,IAAO,GAC9B,MAAM,IAAI,MAAM,GAAGF,CAAY,0EAA0E,EAG7GG,EAA2B,OAAO,IAAI,EAAE,EAExC,IAAMK,EAAiB,MAAMC,EAAiB,EAC9C,QAAQ,IAAID,CAAc,EAE1BA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eC,GAA0D,CACrE,IAAMC,EAAW,MAAM,OAAO,IAAI,oBAAoB,QAAQ,QAAQlB,EAAe,CAAC,EAEtF,OAAAkB,EAAQ,gBAAiBf,GAAa,CAClC,QAAQ,KAAK,KAAKJ,CAAY,gCAAiCI,EAAU,iBAAiB,EAC1Fa,EAAuB,IAC3B,CAAC,EAEME,CACX","names":["PACKAGE_NAME","getChannelName","isInViewContext","extractAppUuidFromIdentity","identity","notificationsClientPromise","getNotificationsClient","getNotificationsClientInternal","channelPromise","getChannelClient","message","listener","eventListeners","eventName","listeners","options","notificationId","channelClientPromise","getChannelClientInternal","channel"]}
1
+ {"version":3,"sources":["../src/utils.ts","../src/notifications.ts","../src/client-api.ts"],"sourcesContent":["import type OpenFin from '@openfin/core';\n\nexport const PACKAGE_NAME = '@openfin/cloud-api';\n\nexport async function isInViewContext(): Promise<boolean> {\n try {\n await window.fin.View.getCurrentSync().getInfo();\n return true;\n } catch {\n return false;\n }\n}\n\nexport function extractAppUuidFromIdentity(identity: OpenFin.Identity): string {\n if (identity.name.startsWith('internal-generated')) {\n throw new Error('Cannot extract app UUID from identity');\n }\n // <uuid>/<name>\n if (/\\/[\\d,a-z-]{36}$/.test(identity.name)) {\n return identity.name.split('/')[0] || '';\n }\n\n return identity.name;\n}\n","// eslint-disable-next-line check-file/no-index\nimport type * as NotificationsTypes from 'openfin-notifications';\n\nimport type { FlannelChannelClient, NotificationEventsMap, NotificationsClient } from './types';\nimport { extractAppUuidFromIdentity, isInViewContext } from './utils';\n\nconst PACKAGE_NAME = '@openfin/cloud-api';\n\nexport type {\n FlannelChannelProvider as __INTERNAL_FlannelChannelProvider,\n FlannelCreateNotificationRequest as __INTERNAL_FlannelCreateNotificationRequest,\n FlannelCreateNotificationResponse as __INTERNAL_FlannelCreateNotificationResponse,\n FlannelUpdateNotificationRequest as __INTERNAL_FlannelUpdateNotificationRequest,\n FlannelUpdateNotificationResponse as __INTERNAL_FlannelUpdateNotificationResponse,\n FlannelClearNotificationRequest as __INTERNAL_FlannelClearNotificationRequest,\n FlannelClearNotificationResponse as __INTERNAL_FlannelClearNotificationResponse,\n} from './types';\n\ndeclare global {\n // eslint-disable-next-line @typescript-eslint/consistent-type-definitions\n interface Window {\n fin: typeof import('@openfin/core').fin;\n }\n}\n\nfunction getChannelName() {\n return `${window.fin.me.uuid}-cloud-api-notifications`;\n}\n\nlet notificationsClientPromise: Promise<NotificationsClient> | null = null;\n\n/**\n * @returns A client for interacting with the OpenFin Notifications service\n *\n * @throws {Error} If the function is called outside of an OpenFin environment\n * @throws {Error} If the function is called outside of an OpenFin View context\n * @throws {Error} If the app UUID cannot be extracted from the current context\n *\n * @example **Basic Usage** Creating a notification, updating it and then clearing it\n * ```ts\n * const notificationsClient = await getNotificationsClient();\n *\n * const notification = await notificationsClient.createNotification({\n * title: 'Hello, World!',\n * body: 'This is a notification from the OpenFin Cloud API',\n * });\n *\n * // Use the `id` from the returned notification to interact with it\n * console.log(notification.id);\n *\n * // Update the notification\n * await notificationsClient.update({\n * id: notification.id,\n * body: 'This is a notification from the OpenFin Cloud API, that has been updated!',\n * })\n *\n * // Clear the notification\n * await notificationsClient.clear(notification.id);\n * ```\n *\n * @example **Advanced Usage** Listening for events\n * ```ts\n * const notificationsClient = await getNotificationsClient();\n *\n * // create the notification\n * const notification = await notificationsClient.createNotification({\n * title: `${window.fin.me.identity.name} Hello, World!`,\n * body: `This is a notification from the cloud API example created at ${new Date().toLocaleTimeString()}`,\n * buttons: [\n * {\n * title: 'Acknowledge',\n * },\n * ],\n * });\n *\n * notificationsClient.addEventListener('notification-action', (event) => {\n * console.log('Notification action:', event);\n * });\n * ```\n */\nasync function getNotificationsClient(): Promise<NotificationsClient> {\n if (!notificationsClientPromise) {\n notificationsClientPromise = getNotificationsClientInternal();\n }\n\n return notificationsClientPromise;\n}\n\nasync function getNotificationsClientInternal(): Promise<NotificationsClient> {\n if (!window.fin) {\n throw new Error(`\\`${PACKAGE_NAME}\\`: \\`getNotificationsClient\\` cannot be used in a non-OpenFin environment`);\n }\n\n if ((await isInViewContext()) === false) {\n throw new Error(`${PACKAGE_NAME}: \\`getNotificationsClient\\` cannot be used in a non-OpenFin environment`);\n }\n\n extractAppUuidFromIdentity(window.fin.me);\n\n const channelPromise = await getChannelClient();\n console.log(channelPromise);\n\n channelPromise.register('openfin-cloud-event', (message) => {\n for (const listener of eventListeners.get(message.type) ?? []) {\n // `Date` is serialized as a string, so we need to convert it back\n if (typeof message.payload.timestamp === 'string') {\n message.payload.timestamp = new Date(message.payload.timestamp);\n }\n\n listener(message.payload as never);\n }\n });\n\n const eventListeners = new Map<keyof NotificationEventsMap, Set<NotificationEventsMap[keyof NotificationEventsMap]>>();\n\n return {\n addEventListener: <T extends keyof NotificationEventsMap>(eventName: T, listener: NotificationEventsMap[T]) => {\n const listeners = eventListeners.get(eventName) || new Set();\n listeners.add(listener);\n eventListeners.set(eventName, listeners);\n },\n removeEventListener: <T extends keyof NotificationEventsMap>(eventName: T, listener: NotificationEventsMap[T]) => {\n const listeners = eventListeners.get(eventName);\n if (!listeners) {\n console.warn(\n `\\`${PACKAGE_NAME}\\`: Listener was not found for event. Did you pass a function directly instead of a reference or forget to add the listener?`,\n eventName,\n );\n return;\n }\n\n if (listeners.delete(listener as (args: unknown) => void) === false) {\n console.warn(`\\`${PACKAGE_NAME}\\`: Listener was not found for event. Did you pass a function directly instead of a reference?`, eventName);\n }\n },\n update: async (options: Parameters<typeof NotificationsTypes.update>[0]): ReturnType<typeof NotificationsTypes.update> => {\n const response = await channelPromise.dispatch('openfin-cloud-update-notification', {\n version: 1,\n payload: {\n notification: options,\n },\n });\n return response.payload.response;\n },\n clear: async (notificationId: Parameters<typeof NotificationsTypes.clear>[0]): ReturnType<typeof NotificationsTypes.clear> => {\n const response = await channelPromise.dispatch('openfin-cloud-clear-notification', {\n version: 1,\n payload: {\n notificationId,\n },\n });\n return response.payload.response;\n },\n createNotification: async (\n options: NotificationsTypes.NotificationOptions,\n ): Promise<NotificationsTypes.Notification<NotificationsTypes.NotificationOptions>> => {\n if (options.id) {\n console.warn(\n `\\`${PACKAGE_NAME}\\`: 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.`,\n );\n }\n const response = await channelPromise.dispatch('openfin-cloud-create-notification', {\n version: 1,\n payload: {\n notification: { ...options, id: undefined },\n },\n });\n return response.payload.response;\n },\n };\n}\n\nlet channelClientPromise: Promise<FlannelChannelClient> | null = null;\n\nasync function getChannelClient(): Promise<FlannelChannelClient> {\n if (!channelClientPromise) {\n channelClientPromise = getChannelClientInternal();\n }\n\n return channelClientPromise;\n}\n\nasync function getChannelClientInternal(): Promise<FlannelChannelClient> {\n const channel = (await window.fin.InterApplicationBus.Channel.connect(getChannelName())) as FlannelChannelClient;\n\n channel.onDisconnection((identity) => {\n console.warn(`\\`${PACKAGE_NAME}\\`: Channel Disconnected from`, identity, 'Reconnecting...');\n channelClientPromise = null;\n });\n\n return channel;\n}\n\nexport { getNotificationsClient };\n","import type OpenFin from '@openfin/core';\n\nimport { isInViewContext, PACKAGE_NAME } from './utils';\n\nlet apiChannelClientPromise: Promise<OpenFin.ChannelClient>;\n\n/**\n * Represents a collection of returned app permissions\n */\nexport type AppPermissions = {\n permissions: {\n /**\n * The name of the permission\n */\n name: string;\n /**\n * The ID of the permission\n */\n id: string;\n }[];\n};\n\nfunction getApiChannelName() {\n return `${window.fin.me.uuid}-client-api`;\n}\n\nasync function getApiChannelClient(): Promise<OpenFin.ChannelClient> {\n if (!apiChannelClientPromise) {\n apiChannelClientPromise = window.fin.InterApplicationBus.Channel.connect(getApiChannelName());\n }\n\n return apiChannelClientPromise;\n}\n\n/**\n * @returns The app settings that have been set against the current app\n *\n * @throws {Error} If the function is called outside of an OpenFin environment\n * @throws {Error} If the function is called outside of an OpenFin View context\n */\nasync function getAppSettings(): Promise<unknown> {\n if (!window.fin) {\n throw new Error(`\\`${PACKAGE_NAME}\\`: \\`getAppSettings\\` cannot be used in a non-OpenFin environment`);\n }\n\n if ((await isInViewContext()) === false) {\n throw new Error(`${PACKAGE_NAME}: \\`getAppSettings\\` cannot be used in a non-OpenFin environment`);\n }\n\n const channel = await getApiChannelClient();\n\n return channel.dispatch('get-settings');\n}\n\n/**\n * @returns The app settings that have been set against the current app for the current user\n *\n * @throws {Error} If the function is called outside of an OpenFin environment\n * @throws {Error} If the function is called outside of an OpenFin View context\n */\nasync function getAppUserSettings(): Promise<unknown> {\n if (!window.fin) {\n throw new Error(`\\`${PACKAGE_NAME}\\`: \\`getAppUserSettings\\` cannot be used in a non-OpenFin environment`);\n }\n\n if ((await isInViewContext()) === false) {\n throw new Error(`${PACKAGE_NAME}: \\`getAppUserSettings\\` cannot be used in a non-OpenFin environment`);\n }\n\n const channel = await getApiChannelClient();\n\n return channel.dispatch('get-user-settings');\n}\n\n/**\n * Assigns a set of user specific settings to the current app\n *\n * @returns The app settings that have been set against the current app for the current user\n *\n * @throws {Error} If the function is called outside of an OpenFin environment\n * @throws {Error} If the function is called outside of an OpenFin View context\n */\nasync function setAppUserSettings(settings: unknown): Promise<unknown> {\n if (!window.fin) {\n throw new Error(`\\`${PACKAGE_NAME}\\`: \\`setAppUserSettings\\` cannot be used in a non-OpenFin environment`);\n }\n\n if ((await isInViewContext()) === false) {\n throw new Error(`${PACKAGE_NAME}: \\`setAppUserSettings\\` cannot be used in a non-OpenFin environment`);\n }\n\n const channel = await getApiChannelClient();\n\n return channel.dispatch('set-user-settings', settings);\n}\n\n/**\n * @returns The permissions that have been set against the current app for the current user\n *\n * @throws {Error} If the function is called outside of an OpenFin environment\n * @throws {Error} If the function is called outside of an OpenFin View context\n */\nasync function getAppUserPermissions(): Promise<AppPermissions> {\n if (!window.fin) {\n throw new Error(`\\`${PACKAGE_NAME}\\`: \\`getAppUserPermissions\\` cannot be used in a non-OpenFin environment`);\n }\n\n if ((await isInViewContext()) === false) {\n throw new Error(`${PACKAGE_NAME}: \\`getAppUserPermissions\\` cannot be used in a non-OpenFin environment`);\n }\n\n const channel = await getApiChannelClient();\n\n return channel.dispatch('get-user-permissions');\n}\n\n/**\n * A function allowing the easy launching of content\n * @param id The id of the content to launch\n * @returns nothing\n *\n * @throws {Error} If the function is called outside of an OpenFin environment\n * @throws {Error} If the function is called outside of an OpenFin View context\n * @throws {Error} If the function has been unable to look up or launch the content\n * @throws {Error} If the function is unable to find content with the provided id.\n */\nasync function launchContent(id: string): Promise<void> {\n if (!window.fin) {\n throw new Error(`\\`${PACKAGE_NAME}\\`: \\`launchContent\\` cannot be used in a non-OpenFin environment`);\n }\n\n if ((await isInViewContext()) === false) {\n throw new Error(`${PACKAGE_NAME}: \\`launchContent\\` cannot be used in a outside of an OpenFin View context`);\n }\n\n const channel = await getApiChannelClient();\n\n try {\n await channel.dispatch('launch-content', { id });\n } catch (error) {\n const errorMessage = error instanceof Error ? error.message : String(error);\n switch (errorMessage) {\n case 'UnableToLookup': {\n throw new Error(`${PACKAGE_NAME}: \\`launchContent\\` was unable to lookup content with id: ${id}`);\n }\n case 'UnableToLaunch': {\n throw new Error(`${PACKAGE_NAME}: \\`launchContent\\` was unable to launch content with id: ${id}`);\n }\n case 'NoContentFound': {\n throw new Error(`${PACKAGE_NAME}: \\`launchContent\\` did not find content with id: ${id}`);\n }\n default: {\n throw new Error(`${PACKAGE_NAME}: \\`launchContent\\` was unable to look up or launch content with id: ${id} or the content did not exist.`);\n }\n }\n }\n}\n\nexport { getAppSettings, getAppUserSettings, setAppUserSettings, getAppUserPermissions, launchContent };\n"],"mappings":"AAEO,IAAMA,EAAe,qBAE5B,eAAsBC,GAAoC,CACtD,GAAI,CACA,aAAM,OAAO,IAAI,KAAK,eAAe,EAAE,QAAQ,EACxC,EACX,MAAQ,CACJ,MAAO,EACX,CACJ,CAEO,SAASC,EAA2BC,EAAoC,CAC3E,GAAIA,EAAS,KAAK,WAAW,oBAAoB,EAC7C,MAAM,IAAI,MAAM,uCAAuC,EAG3D,MAAI,mBAAmB,KAAKA,EAAS,IAAI,EAC9BA,EAAS,K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AGP,CAAY,wEAAwEO,CAAE,gCAAgC,CAEjJ,CACJ,CACJ","names":["PACKAGE_NAME","isInViewContext","extractAppUuidFromIdentity","identity","PACKAGE_NAME","getChannelName","notificationsClientPromise","getNotificationsClient","getNotificationsClientInternal","isInViewContext","extractAppUuidFromIdentity","channelPromise","getChannelClient","message","listener","eventListeners","eventName","listeners","options","notificationId","channelClientPromise","getChannelClientInternal","channel","identity","apiChannelClientPromise","getApiChannelName","getApiChannelClient","getAppSettings","PACKAGE_NAME","isInViewContext","getAppUserSettings","setAppUserSettings","settings","getAppUserPermissions","launchContent","id","channel","error"]}
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@openfin/cloud-api",
3
- "version": "0.0.1-alpha.fb41cf7",
3
+ "version": "0.0.1-alpha.fb5ba58",
4
4
  "sideEffects": false,
5
5
  "description": "",
6
6
  "exports": {
@@ -14,6 +14,7 @@
14
14
  "module": "./dist/index.js",
15
15
  "scripts": {
16
16
  "build": "tsup --config ./tsup.config.ts",
17
+ "build:watch": "tsup --watch --config ./tsup.config.ts",
17
18
  "lint": "eslint . --ext .ts,.tsx --max-warnings 0"
18
19
  },
19
20
  "files": [
@@ -24,18 +25,18 @@
24
25
  "openfin-notifications": "^2.3.2"
25
26
  },
26
27
  "devDependencies": {
27
- "@typescript-eslint/eslint-plugin": "^6.21.0",
28
- "@typescript-eslint/parser": "^6.21.0",
29
- "eslint": "^8.56.0",
30
- "eslint-config-next": "^14.1.0",
28
+ "@typescript-eslint/eslint-plugin": "^7.5.0",
29
+ "@typescript-eslint/parser": "^7.5.0",
30
+ "eslint": "^8.57.0",
31
+ "eslint-config-next": "^14.1.4",
31
32
  "eslint-config-prettier": "^9.1.0",
32
33
  "eslint-plugin-check-file": "^2.6.2",
33
34
  "eslint-plugin-prettier": "^5.1.3",
34
- "eslint-plugin-simple-import-sort": "^10.0.0",
35
+ "eslint-plugin-simple-import-sort": "^12.0.0",
35
36
  "eslint-plugin-unicorn": "^51.0.1",
36
37
  "prettier": "^3.2.5",
37
38
  "tsup": "^8.0.1",
38
- "typescript": "^5.3.3"
39
+ "typescript": "^5.4.3"
39
40
  },
40
41
  "eslintConfig": {
41
42
  "env": {
@@ -179,9 +180,7 @@
179
180
  "varsIgnorePattern": "^_"
180
181
  }
181
182
  ],
182
- "@typescript-eslint/no-explicit-any": [
183
- "warn"
184
- ]
183
+ "@typescript-eslint/no-explicit-any": 1
185
184
  },
186
185
  "ignorePatterns": [
187
186
  "node_modules",