@openfin/cloud-api 0.0.1-alpha.01a0640

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/README.md ADDED
@@ -0,0 +1,59 @@
1
+ # @openfin/cloud-api
2
+
3
+ Client library for interacting with notifications when used as part of the OpenFin Cloud Platform.
4
+
5
+ <!-- High-level description of what this package is useful for. Include specific use case/s whenever possible. -->
6
+
7
+ <!-- Depending on package, explain why this package vs a different one, and link to other options. -->
8
+
9
+ Related packages:
10
+
11
+ - [@openfin/workspace](https://www.npmjs.com/package/@openfin/workspace)
12
+ - [@openfin/workspace-platform](https://www.npmjs.com/package/@openfin/workspace-platform)
13
+
14
+ <!-- For more information about how to work with this package, see [{the relevant docs}]({relevant_docs_link}). -->
15
+
16
+ ## Prerequisites
17
+
18
+ None.
19
+
20
+ ## Installation
21
+
22
+ With npm:
23
+
24
+ > npm -i @openfin/cloud-api
25
+
26
+ With pnpm:
27
+
28
+ > pnpm add @openfin/cloud-api
29
+
30
+ With bun:
31
+
32
+ > bun add @openfin/cloud-api
33
+
34
+ With yarn:
35
+
36
+ > yarn global add @openfin/cloud-api
37
+
38
+ ## Usage
39
+
40
+ <!-- If this is a command-line tool, this is some basic usage info. -->
41
+
42
+ <!-- If it is a library, link to the specific section of the developer guide or api refdoc. (This might mean repeating links already -->
43
+ <!-- provided in the first section of the readme. This is FINE.) -->
44
+
45
+ <!-- ## For more information -->
46
+
47
+ <!-- - [{Developer guide}]({relevant_docs_link}). -->
48
+ <!-- - [{API reference}]({relevant_docs_link}). -->
49
+ <!-- - See the [workspace-starter]() project for example code.-->
50
+
51
+ ## License
52
+
53
+ Copyright 2024-2024 OpenFin
54
+
55
+ The code in this package is distributed under the {relevant license}.
56
+
57
+ However, if you run this code, it may call on the OpenFin RVM or OpenFin Runtime, which are covered by OpenFin's Developer, Community, and Enterprise licenses. You can learn more about OpenFin licensing at the link listed below or email us at support@openfin.co with questions.
58
+
59
+ - [Developer license](https://openfin.co/developer-agreement/)
package/dist/index.cjs ADDED
@@ -0,0 +1,2 @@
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(e){if(e.name.startsWith("internal-generated"))throw new Error("Cannot extract app UUID from identity");return/\/[\d,a-z-]{36}$/.test(e.name)?e.name.split("/")[0]||"":e.name}var s="@openfin/cloud-api";function d(){return`${window.fin.me.uuid}-cloud-api-notifications`}var l=null;async function g(){return l||(l=w()),l}async function w(){if(!window.fin)throw new Error(`\`${s}\`: \`getNotificationsClient\` cannot be used in a non-OpenFin environment`);if(await a()===!1)throw new Error(`${s}: \`getNotificationsClient\` cannot be used in a non-OpenFin environment`);u(window.fin.me);let e=await m();console.log(e),e.register("openfin-cloud-event",n=>{for(let i of _nullishCoalesce(o.get(n.type), () => ([])))typeof n.payload.timestamp=="string"&&(n.payload.timestamp=new Date(n.payload.timestamp)),i(n.payload)});let o=new Map;return{addEventListener:(n,i)=>{let r=o.get(n)||new Set;r.add(i),o.set(n,r)},removeEventListener:(n,i)=>{let r=o.get(n);if(!r){console.warn(`\`${s}\`: Listener was not found for event. Did you pass a function directly instead of a reference or forget to add the listener?`,n);return}r.delete(i)===!1&&console.warn(`\`${s}\`: Listener was not found for event. Did you pass a function directly instead of a reference?`,n)},update:async n=>(await e.dispatch("openfin-cloud-update-notification",{version:1,payload:{notification:n}})).payload.response,clear:async n=>(await e.dispatch("openfin-cloud-clear-notification",{version:1,payload:{notificationId:n}})).payload.response,createNotification:async n=>(n.id&&console.warn(`\`${s}\`: The \`id\` property is not supported and will be ignored. If you need to use the \`id\` property, you should use the \`id\` property of the returned notification object.`),(await e.dispatch("openfin-cloud-create-notification",{version:1,payload:{notification:{...n,id:void 0}}})).payload.response)}}var p=null;async function m(){return p||(p=y()),p}async function y(){let e=await window.fin.InterApplicationBus.Channel.connect(d());return e.onDisconnection(o=>{console.warn(`\`${s}\`: Channel Disconnected from`,o,"Reconnecting..."),p=null}),e}var f;function N(){return`${window.fin.me.uuid}-client-api`}async function c(){return f||(f=window.fin.InterApplicationBus.Channel.connect(N())),f}async function E(){if(!window.fin)throw new Error(`\`${t}\`: \`getAppSettings\` cannot be used in a non-OpenFin environment`);if(await a()===!1)throw new Error(`${t}: \`getAppSettings\` cannot be used in a non-OpenFin environment`);return(await c()).dispatch("get-settings")}async function P(){if(!window.fin)throw new Error(`\`${t}\`: \`getAppUserSettings\` cannot be used in a non-OpenFin environment`);if(await a()===!1)throw new Error(`${t}: \`getAppUserSettings\` cannot be used in a non-OpenFin environment`);return(await c()).dispatch("get-user-settings")}async function v(e){if(!window.fin)throw new Error(`\`${t}\`: \`setAppUserSettings\` cannot be used in a non-OpenFin environment`);if(await a()===!1)throw new Error(`${t}: \`setAppUserSettings\` cannot be used in a non-OpenFin environment`);return(await c()).dispatch("set-user-settings",e)}async function T(){if(!window.fin)throw new Error(`\`${t}\`: \`getAppUserPermissions\` cannot be used in a non-OpenFin environment`);if(await a()===!1)throw new Error(`${t}: \`getAppUserPermissions\` cannot be used in a non-OpenFin environment`);return(await c()).dispatch("get-user-permissions")}exports.getAppSettings = E; exports.getAppUserPermissions = T; exports.getAppUserSettings = P; exports.getNotificationsClient = g; exports.setAppUserSettings = v;
2
+ //# sourceMappingURL=index.cjs.map
@@ -0,0 +1 @@
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"],"mappings":"AAEO,IAAMA,E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,CAC9C,GAAI,CAAC,OAAO,IACR,MAAM,IAAI,MAAM,KAAKvB,CAAY,oEAAoE,EAGzG,GAAK,MAAMC,EAAgB,IAAO,GAC9B,MAAM,IAAI,MAAM,GAAGD,CAAY,kEAAkE,EAKrG,OAFgB,MAAMsB,EAAoB,GAE3B,SAAS,cAAc,CAC1C,CAQA,eAAeE,GAAuC,CAClD,GAAI,CAAC,OAAO,IACR,MAAM,IAAI,MAAM,KAAKxB,CAAY,wEAAwE,EAG7G,GAAK,MAAMC,EAAgB,IAAO,GAC9B,MAAM,IAAI,MAAM,GAAGD,CAAY,sEAAsE,EAKzG,OAFgB,MAAMsB,EAAoB,GAE3B,SAAS,mBAAmB,CAC/C,CAUA,eAAeG,EAAmBC,EAAqC,CACnE,GAAI,CAAC,OAAO,IACR,MAAM,IAAI,MAAM,KAAK1B,CAAY,wEAAwE,EAG7G,GAAK,MAAMC,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","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\nexport { getAppSettings, getAppUserSettings, setAppUserSettings, getAppUserPermissions };\n"]}
@@ -0,0 +1,257 @@
1
+ import * as OpenFin from '@openfin/core';
2
+ import OpenFin__default from '@openfin/core';
3
+ import * as NotificationsTypes from 'openfin-notifications';
4
+
5
+ /**
6
+ * NotificationsClient is a client for accessing and interacting with the Notifications your application has created.
7
+ */
8
+ type NotificationsClient = {
9
+ /**
10
+ * Adds an event listener to the Notifications service.
11
+ *
12
+ * @param event the event name to listen for
13
+ * @param callback the callback to be invoked when the event is emitted
14
+ */
15
+ addEventListener<T extends keyof NotificationEventsMap>(event: T, callback: NotificationEventsMap[T]): void;
16
+ /**
17
+ * Removes an event listener from the Notifications service.
18
+ *
19
+ * @see {NotificationsClient.addEventListener}
20
+ *
21
+ * @remarks If the listener is not found, a warning will be logged to the console.
22
+ */
23
+ removeEventListener<T extends keyof NotificationEventsMap>(event: T, callback: NotificationEventsMap[T]): void;
24
+ /**
25
+ * Creates a new Notification.
26
+ *
27
+ * @remarks `id` should __not__ be provided. Instead, use the id property of the returned notification object. If you supply and `id` property, it will be ignored, with a warning logged to the console.
28
+ *
29
+ * @param args
30
+ */
31
+ createNotification(...args: Parameters<typeof NotificationsTypes.create>): ReturnType<typeof NotificationsTypes.create>;
32
+ /**
33
+ * Updates an existing Notification.
34
+ */
35
+ update(...args: Parameters<typeof NotificationsTypes.update>): ReturnType<typeof NotificationsTypes.update>;
36
+ /**
37
+ * Clears a Notification with the specified id.
38
+ */
39
+ clear(...args: Parameters<typeof NotificationsTypes.clear>): ReturnType<typeof NotificationsTypes.clear>;
40
+ };
41
+ /**
42
+ * @internal
43
+ */
44
+ type FlannelCreateNotificationRequest = {
45
+ version: 1;
46
+ payload: {
47
+ notification: NotificationsTypes.NotificationOptions;
48
+ };
49
+ };
50
+ /**
51
+ * @internal
52
+ */
53
+ type FlannelCreateNotificationResponse = {
54
+ version: 1;
55
+ payload: {
56
+ response: NotificationsTypes.Notification<NotificationsTypes.NotificationOptions>;
57
+ };
58
+ };
59
+ /**
60
+ * @internal
61
+ */
62
+ type FlannelUpdateNotificationRequest = {
63
+ version: 1;
64
+ payload: {
65
+ notification: NotificationsTypes.UpdatableNotificationOptions;
66
+ };
67
+ };
68
+ /**
69
+ * @internal
70
+ */
71
+ type FlannelUpdateNotificationResponse = {
72
+ version: 1;
73
+ payload: {
74
+ response: NotificationsTypes.Notification;
75
+ };
76
+ };
77
+ /**
78
+ * @internal
79
+ */
80
+ type FlannelClearNotificationRequest = {
81
+ version: 1;
82
+ payload: {
83
+ notificationId: string;
84
+ };
85
+ };
86
+ /**
87
+ * @internal
88
+ */
89
+ type FlannelClearNotificationResponse = {
90
+ version: 1;
91
+ payload: {
92
+ response: boolean;
93
+ };
94
+ };
95
+ /**
96
+ * @internal
97
+ */
98
+ type FlannelProvider = {
99
+ 'openfin-cloud-create-notification': (arg0: FlannelCreateNotificationRequest) => Promise<FlannelCreateNotificationResponse>;
100
+ 'openfin-cloud-update-notification': (arg0: FlannelUpdateNotificationRequest) => Promise<FlannelUpdateNotificationResponse>;
101
+ 'openfin-cloud-clear-notification': (arg0: FlannelClearNotificationRequest) => Promise<FlannelClearNotificationResponse>;
102
+ };
103
+ type NotificationEventsMap = {
104
+ 'notification-form-values-changed': (event: NotificationsTypes.NotificationFormValuesChangedEvent & {
105
+ timestamp: Date;
106
+ }) => void;
107
+ 'notification-form-submitted': (event: NotificationsTypes.NotificationFormSubmittedEvent & {
108
+ timestamp: Date;
109
+ }) => void;
110
+ 'notification-action': (event: NotificationsTypes.NotificationActionEvent & {
111
+ timestamp: Date;
112
+ }) => void;
113
+ 'notification-created': (event: NotificationsTypes.NotificationCreatedEvent & {
114
+ timestamp: Date;
115
+ }) => void;
116
+ 'notification-toast-dismissed': (event: NotificationsTypes.NotificationToastDismissedEvent & {
117
+ timestamp: Date;
118
+ }) => void;
119
+ 'notification-closed': (event: NotificationsTypes.NotificationClosedEvent & {
120
+ timestamp: Date;
121
+ }) => void;
122
+ 'notifications-count-changed': (event: NotificationsTypes.NotificationsCountChanged & {
123
+ timestamp: Date;
124
+ }) => void;
125
+ 'notification-reminder-created': (event: NotificationsTypes.NotificationReminderCreatedEvent & {
126
+ timestamp: Date;
127
+ }) => void;
128
+ 'notification-reminder-removed': (event: NotificationsTypes.NotificationReminderRemovedEvent & {
129
+ timestamp: Date;
130
+ }) => void;
131
+ };
132
+ /**
133
+ * @internal
134
+ */
135
+ type FlannelClient = {
136
+ 'openfin-cloud-event': <T extends keyof NotificationEventsMap>(arg0: {
137
+ type: T;
138
+ payload: Parameters<NotificationEventsMap[T]>[0];
139
+ }) => void;
140
+ };
141
+ /**
142
+ * @internal
143
+ */
144
+ type FlannelChannelProvider = {
145
+ /**
146
+ * @internal
147
+ */
148
+ dispatch: <T extends keyof FlannelClient>(to: OpenFin__default.ClientIdentity | OpenFin__default.Identity, action: T, payload: Parameters<FlannelClient[T]>[0]) => Promise<Awaited<ReturnType<FlannelClient[T]>>>;
149
+ /**
150
+ * @internal
151
+ */
152
+ register: <T extends keyof FlannelProvider>(action: T, handler: (payload: Parameters<FlannelProvider[T]>[0], id: OpenFin__default.ProviderIdentity | OpenFin__default.ClientIdentity) => ReturnType<FlannelProvider[T]>) => boolean;
153
+ } & Omit<OpenFin__default.ChannelProvider, 'dispatch' | 'register'>;
154
+
155
+ declare global {
156
+ interface Window {
157
+ fin: typeof OpenFin.fin;
158
+ }
159
+ }
160
+ /**
161
+ * @returns A client for interacting with the OpenFin Notifications service
162
+ *
163
+ * @throws {Error} If the function is called outside of an OpenFin environment
164
+ * @throws {Error} If the function is called outside of an OpenFin View context
165
+ * @throws {Error} If the app UUID cannot be extracted from the current context
166
+ *
167
+ * @example **Basic Usage** Creating a notification, updating it and then clearing it
168
+ * ```ts
169
+ * const notificationsClient = await getNotificationsClient();
170
+ *
171
+ * const notification = await notificationsClient.createNotification({
172
+ * title: 'Hello, World!',
173
+ * body: 'This is a notification from the OpenFin Cloud API',
174
+ * });
175
+ *
176
+ * // Use the `id` from the returned notification to interact with it
177
+ * console.log(notification.id);
178
+ *
179
+ * // Update the notification
180
+ * await notificationsClient.update({
181
+ * id: notification.id,
182
+ * body: 'This is a notification from the OpenFin Cloud API, that has been updated!',
183
+ * })
184
+ *
185
+ * // Clear the notification
186
+ * await notificationsClient.clear(notification.id);
187
+ * ```
188
+ *
189
+ * @example **Advanced Usage** Listening for events
190
+ * ```ts
191
+ * const notificationsClient = await getNotificationsClient();
192
+ *
193
+ * // create the notification
194
+ * const notification = await notificationsClient.createNotification({
195
+ * title: `${window.fin.me.identity.name} Hello, World!`,
196
+ * body: `This is a notification from the cloud API example created at ${new Date().toLocaleTimeString()}`,
197
+ * buttons: [
198
+ * {
199
+ * title: 'Acknowledge',
200
+ * },
201
+ * ],
202
+ * });
203
+ *
204
+ * notificationsClient.addEventListener('notification-action', (event) => {
205
+ * console.log('Notification action:', event);
206
+ * });
207
+ * ```
208
+ */
209
+ declare function getNotificationsClient(): Promise<NotificationsClient>;
210
+
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
+ export { type AppPermissions, type FlannelChannelProvider as __INTERNAL_FlannelChannelProvider, type FlannelClearNotificationRequest as __INTERNAL_FlannelClearNotificationRequest, type FlannelClearNotificationResponse as __INTERNAL_FlannelClearNotificationResponse, type FlannelCreateNotificationRequest as __INTERNAL_FlannelCreateNotificationRequest, type FlannelCreateNotificationResponse as __INTERNAL_FlannelCreateNotificationResponse, type FlannelUpdateNotificationRequest as __INTERNAL_FlannelUpdateNotificationRequest, type FlannelUpdateNotificationResponse as __INTERNAL_FlannelUpdateNotificationResponse, getAppSettings, getAppUserPermissions, getAppUserSettings, getNotificationsClient, setAppUserSettings };
@@ -0,0 +1,257 @@
1
+ import * as OpenFin from '@openfin/core';
2
+ import OpenFin__default from '@openfin/core';
3
+ import * as NotificationsTypes from 'openfin-notifications';
4
+
5
+ /**
6
+ * NotificationsClient is a client for accessing and interacting with the Notifications your application has created.
7
+ */
8
+ type NotificationsClient = {
9
+ /**
10
+ * Adds an event listener to the Notifications service.
11
+ *
12
+ * @param event the event name to listen for
13
+ * @param callback the callback to be invoked when the event is emitted
14
+ */
15
+ addEventListener<T extends keyof NotificationEventsMap>(event: T, callback: NotificationEventsMap[T]): void;
16
+ /**
17
+ * Removes an event listener from the Notifications service.
18
+ *
19
+ * @see {NotificationsClient.addEventListener}
20
+ *
21
+ * @remarks If the listener is not found, a warning will be logged to the console.
22
+ */
23
+ removeEventListener<T extends keyof NotificationEventsMap>(event: T, callback: NotificationEventsMap[T]): void;
24
+ /**
25
+ * Creates a new Notification.
26
+ *
27
+ * @remarks `id` should __not__ be provided. Instead, use the id property of the returned notification object. If you supply and `id` property, it will be ignored, with a warning logged to the console.
28
+ *
29
+ * @param args
30
+ */
31
+ createNotification(...args: Parameters<typeof NotificationsTypes.create>): ReturnType<typeof NotificationsTypes.create>;
32
+ /**
33
+ * Updates an existing Notification.
34
+ */
35
+ update(...args: Parameters<typeof NotificationsTypes.update>): ReturnType<typeof NotificationsTypes.update>;
36
+ /**
37
+ * Clears a Notification with the specified id.
38
+ */
39
+ clear(...args: Parameters<typeof NotificationsTypes.clear>): ReturnType<typeof NotificationsTypes.clear>;
40
+ };
41
+ /**
42
+ * @internal
43
+ */
44
+ type FlannelCreateNotificationRequest = {
45
+ version: 1;
46
+ payload: {
47
+ notification: NotificationsTypes.NotificationOptions;
48
+ };
49
+ };
50
+ /**
51
+ * @internal
52
+ */
53
+ type FlannelCreateNotificationResponse = {
54
+ version: 1;
55
+ payload: {
56
+ response: NotificationsTypes.Notification<NotificationsTypes.NotificationOptions>;
57
+ };
58
+ };
59
+ /**
60
+ * @internal
61
+ */
62
+ type FlannelUpdateNotificationRequest = {
63
+ version: 1;
64
+ payload: {
65
+ notification: NotificationsTypes.UpdatableNotificationOptions;
66
+ };
67
+ };
68
+ /**
69
+ * @internal
70
+ */
71
+ type FlannelUpdateNotificationResponse = {
72
+ version: 1;
73
+ payload: {
74
+ response: NotificationsTypes.Notification;
75
+ };
76
+ };
77
+ /**
78
+ * @internal
79
+ */
80
+ type FlannelClearNotificationRequest = {
81
+ version: 1;
82
+ payload: {
83
+ notificationId: string;
84
+ };
85
+ };
86
+ /**
87
+ * @internal
88
+ */
89
+ type FlannelClearNotificationResponse = {
90
+ version: 1;
91
+ payload: {
92
+ response: boolean;
93
+ };
94
+ };
95
+ /**
96
+ * @internal
97
+ */
98
+ type FlannelProvider = {
99
+ 'openfin-cloud-create-notification': (arg0: FlannelCreateNotificationRequest) => Promise<FlannelCreateNotificationResponse>;
100
+ 'openfin-cloud-update-notification': (arg0: FlannelUpdateNotificationRequest) => Promise<FlannelUpdateNotificationResponse>;
101
+ 'openfin-cloud-clear-notification': (arg0: FlannelClearNotificationRequest) => Promise<FlannelClearNotificationResponse>;
102
+ };
103
+ type NotificationEventsMap = {
104
+ 'notification-form-values-changed': (event: NotificationsTypes.NotificationFormValuesChangedEvent & {
105
+ timestamp: Date;
106
+ }) => void;
107
+ 'notification-form-submitted': (event: NotificationsTypes.NotificationFormSubmittedEvent & {
108
+ timestamp: Date;
109
+ }) => void;
110
+ 'notification-action': (event: NotificationsTypes.NotificationActionEvent & {
111
+ timestamp: Date;
112
+ }) => void;
113
+ 'notification-created': (event: NotificationsTypes.NotificationCreatedEvent & {
114
+ timestamp: Date;
115
+ }) => void;
116
+ 'notification-toast-dismissed': (event: NotificationsTypes.NotificationToastDismissedEvent & {
117
+ timestamp: Date;
118
+ }) => void;
119
+ 'notification-closed': (event: NotificationsTypes.NotificationClosedEvent & {
120
+ timestamp: Date;
121
+ }) => void;
122
+ 'notifications-count-changed': (event: NotificationsTypes.NotificationsCountChanged & {
123
+ timestamp: Date;
124
+ }) => void;
125
+ 'notification-reminder-created': (event: NotificationsTypes.NotificationReminderCreatedEvent & {
126
+ timestamp: Date;
127
+ }) => void;
128
+ 'notification-reminder-removed': (event: NotificationsTypes.NotificationReminderRemovedEvent & {
129
+ timestamp: Date;
130
+ }) => void;
131
+ };
132
+ /**
133
+ * @internal
134
+ */
135
+ type FlannelClient = {
136
+ 'openfin-cloud-event': <T extends keyof NotificationEventsMap>(arg0: {
137
+ type: T;
138
+ payload: Parameters<NotificationEventsMap[T]>[0];
139
+ }) => void;
140
+ };
141
+ /**
142
+ * @internal
143
+ */
144
+ type FlannelChannelProvider = {
145
+ /**
146
+ * @internal
147
+ */
148
+ dispatch: <T extends keyof FlannelClient>(to: OpenFin__default.ClientIdentity | OpenFin__default.Identity, action: T, payload: Parameters<FlannelClient[T]>[0]) => Promise<Awaited<ReturnType<FlannelClient[T]>>>;
149
+ /**
150
+ * @internal
151
+ */
152
+ register: <T extends keyof FlannelProvider>(action: T, handler: (payload: Parameters<FlannelProvider[T]>[0], id: OpenFin__default.ProviderIdentity | OpenFin__default.ClientIdentity) => ReturnType<FlannelProvider[T]>) => boolean;
153
+ } & Omit<OpenFin__default.ChannelProvider, 'dispatch' | 'register'>;
154
+
155
+ declare global {
156
+ interface Window {
157
+ fin: typeof OpenFin.fin;
158
+ }
159
+ }
160
+ /**
161
+ * @returns A client for interacting with the OpenFin Notifications service
162
+ *
163
+ * @throws {Error} If the function is called outside of an OpenFin environment
164
+ * @throws {Error} If the function is called outside of an OpenFin View context
165
+ * @throws {Error} If the app UUID cannot be extracted from the current context
166
+ *
167
+ * @example **Basic Usage** Creating a notification, updating it and then clearing it
168
+ * ```ts
169
+ * const notificationsClient = await getNotificationsClient();
170
+ *
171
+ * const notification = await notificationsClient.createNotification({
172
+ * title: 'Hello, World!',
173
+ * body: 'This is a notification from the OpenFin Cloud API',
174
+ * });
175
+ *
176
+ * // Use the `id` from the returned notification to interact with it
177
+ * console.log(notification.id);
178
+ *
179
+ * // Update the notification
180
+ * await notificationsClient.update({
181
+ * id: notification.id,
182
+ * body: 'This is a notification from the OpenFin Cloud API, that has been updated!',
183
+ * })
184
+ *
185
+ * // Clear the notification
186
+ * await notificationsClient.clear(notification.id);
187
+ * ```
188
+ *
189
+ * @example **Advanced Usage** Listening for events
190
+ * ```ts
191
+ * const notificationsClient = await getNotificationsClient();
192
+ *
193
+ * // create the notification
194
+ * const notification = await notificationsClient.createNotification({
195
+ * title: `${window.fin.me.identity.name} Hello, World!`,
196
+ * body: `This is a notification from the cloud API example created at ${new Date().toLocaleTimeString()}`,
197
+ * buttons: [
198
+ * {
199
+ * title: 'Acknowledge',
200
+ * },
201
+ * ],
202
+ * });
203
+ *
204
+ * notificationsClient.addEventListener('notification-action', (event) => {
205
+ * console.log('Notification action:', event);
206
+ * });
207
+ * ```
208
+ */
209
+ declare function getNotificationsClient(): Promise<NotificationsClient>;
210
+
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
+ export { type AppPermissions, type FlannelChannelProvider as __INTERNAL_FlannelChannelProvider, type FlannelClearNotificationRequest as __INTERNAL_FlannelClearNotificationRequest, type FlannelClearNotificationResponse as __INTERNAL_FlannelClearNotificationResponse, type FlannelCreateNotificationRequest as __INTERNAL_FlannelCreateNotificationRequest, type FlannelCreateNotificationResponse as __INTERNAL_FlannelCreateNotificationResponse, type FlannelUpdateNotificationRequest as __INTERNAL_FlannelUpdateNotificationRequest, type FlannelUpdateNotificationResponse as __INTERNAL_FlannelUpdateNotificationResponse, getAppSettings, getAppUserPermissions, getAppUserSettings, getNotificationsClient, setAppUserSettings };
package/dist/index.js ADDED
@@ -0,0 +1,2 @@
1
+ var t="@openfin/cloud-api";async function a(){try{return await window.fin.View.getCurrentSync().getInfo(),!0}catch{return!1}}function u(e){if(e.name.startsWith("internal-generated"))throw new Error("Cannot extract app UUID from identity");return/\/[\d,a-z-]{36}$/.test(e.name)?e.name.split("/")[0]||"":e.name}var s="@openfin/cloud-api";function d(){return`${window.fin.me.uuid}-cloud-api-notifications`}var l=null;async function g(){return l||(l=w()),l}async function w(){if(!window.fin)throw new Error(`\`${s}\`: \`getNotificationsClient\` cannot be used in a non-OpenFin environment`);if(await a()===!1)throw new Error(`${s}: \`getNotificationsClient\` cannot be used in a non-OpenFin environment`);u(window.fin.me);let e=await m();console.log(e),e.register("openfin-cloud-event",n=>{for(let i of o.get(n.type)??[])typeof n.payload.timestamp=="string"&&(n.payload.timestamp=new Date(n.payload.timestamp)),i(n.payload)});let o=new Map;return{addEventListener:(n,i)=>{let r=o.get(n)||new Set;r.add(i),o.set(n,r)},removeEventListener:(n,i)=>{let r=o.get(n);if(!r){console.warn(`\`${s}\`: Listener was not found for event. Did you pass a function directly instead of a reference or forget to add the listener?`,n);return}r.delete(i)===!1&&console.warn(`\`${s}\`: Listener was not found for event. Did you pass a function directly instead of a reference?`,n)},update:async n=>(await e.dispatch("openfin-cloud-update-notification",{version:1,payload:{notification:n}})).payload.response,clear:async n=>(await e.dispatch("openfin-cloud-clear-notification",{version:1,payload:{notificationId:n}})).payload.response,createNotification:async n=>(n.id&&console.warn(`\`${s}\`: The \`id\` property is not supported and will be ignored. If you need to use the \`id\` property, you should use the \`id\` property of the returned notification object.`),(await e.dispatch("openfin-cloud-create-notification",{version:1,payload:{notification:{...n,id:void 0}}})).payload.response)}}var p=null;async function m(){return p||(p=y()),p}async function y(){let e=await window.fin.InterApplicationBus.Channel.connect(d());return e.onDisconnection(o=>{console.warn(`\`${s}\`: Channel Disconnected from`,o,"Reconnecting..."),p=null}),e}var f;function N(){return`${window.fin.me.uuid}-client-api`}async function c(){return f||(f=window.fin.InterApplicationBus.Channel.connect(N())),f}async function E(){if(!window.fin)throw new Error(`\`${t}\`: \`getAppSettings\` cannot be used in a non-OpenFin environment`);if(await a()===!1)throw new Error(`${t}: \`getAppSettings\` cannot be used in a non-OpenFin environment`);return(await c()).dispatch("get-settings")}async function P(){if(!window.fin)throw new Error(`\`${t}\`: \`getAppUserSettings\` cannot be used in a non-OpenFin environment`);if(await a()===!1)throw new Error(`${t}: \`getAppUserSettings\` cannot be used in a non-OpenFin environment`);return(await c()).dispatch("get-user-settings")}async function v(e){if(!window.fin)throw new Error(`\`${t}\`: \`setAppUserSettings\` cannot be used in a non-OpenFin environment`);if(await a()===!1)throw new Error(`${t}: \`setAppUserSettings\` cannot be used in a non-OpenFin environment`);return(await c()).dispatch("set-user-settings",e)}async function T(){if(!window.fin)throw new Error(`\`${t}\`: \`getAppUserPermissions\` cannot be used in a non-OpenFin environment`);if(await a()===!1)throw new Error(`${t}: \`getAppUserPermissions\` cannot be used in a non-OpenFin environment`);return(await c()).dispatch("get-user-permissions")}export{E as getAppSettings,T as getAppUserPermissions,P as getAppUserSettings,g as getNotificationsClient,v as setAppUserSettings};
2
+ //# sourceMappingURL=index.js.map
@@ -0,0 +1 @@
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\nexport { getAppSettings, getAppUserSettings, setAppUserSettings, getAppUserPermissions };\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,KAAK,MAAM,GAAG,EAAE,CAAC,GAAK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gB,IAAO,GAC9B,MAAM,IAAI,MAAM,GAAGD,CAAY,sEAAsE,EAKzG,OAFgB,MAAMF,EAAoB,GAE3B,SAAS,mBAAmB,CAC/C,CAUA,eAAeK,EAAmBC,EAAqC,CACnE,GAAI,CAAC,OAAO,IACR,MAAM,IAAI,MAAM,KAAKJ,CAAY,wEAAwE,EAG7G,GAAK,MAAMC,EAAgB,IAAO,GAC9B,MAAM,IAAI,MAAM,GAAGD,CAAY,sEAAsE,EAKzG,OAFgB,MAAMF,EAAoB,GAE3B,SAAS,oBAAqBM,CAAQ,CACzD,CAQA,eAAeC,GAAiD,CAC5D,GAAI,CAAC,OAAO,IACR,MAAM,IAAI,MAAM,KAAKL,CAAY,2EAA2E,EAGhH,GAAK,MAAMC,EAAgB,IAAO,GAC9B,MAAM,IAAI,MAAM,GAAGD,CAAY,yEAAyE,EAK5G,OAFgB,MAAMF,EAAoB,GAE3B,SAAS,sBAAsB,CAClD","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"]}
package/package.json ADDED
@@ -0,0 +1,193 @@
1
+ {
2
+ "name": "@openfin/cloud-api",
3
+ "version": "0.0.1-alpha.01a0640",
4
+ "sideEffects": false,
5
+ "description": "",
6
+ "exports": {
7
+ ".": {
8
+ "import": "./dist/index.js",
9
+ "require": "./dist/index.cjs"
10
+ }
11
+ },
12
+ "type": "module",
13
+ "main": "./dist/index.cjs",
14
+ "module": "./dist/index.js",
15
+ "scripts": {
16
+ "build": "tsup --config ./tsup.config.ts",
17
+ "build:watch": "tsup --watch --config ./tsup.config.ts",
18
+ "lint": "eslint . --ext .ts,.tsx --max-warnings 0"
19
+ },
20
+ "files": [
21
+ "dist"
22
+ ],
23
+ "dependencies": {
24
+ "@openfin/core": "^34.78.80",
25
+ "openfin-notifications": "^2.3.2"
26
+ },
27
+ "devDependencies": {
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",
32
+ "eslint-config-prettier": "^9.1.0",
33
+ "eslint-plugin-check-file": "^2.6.2",
34
+ "eslint-plugin-prettier": "^5.1.3",
35
+ "eslint-plugin-simple-import-sort": "^12.0.0",
36
+ "eslint-plugin-unicorn": "^51.0.1",
37
+ "prettier": "^3.2.5",
38
+ "tsup": "^8.0.1",
39
+ "typescript": "^5.4.3"
40
+ },
41
+ "eslintConfig": {
42
+ "env": {
43
+ "browser": true,
44
+ "node": true
45
+ },
46
+ "parser": "@typescript-eslint/parser",
47
+ "parserOptions": {
48
+ "ecmaVersion": "latest",
49
+ "sourceType": "module",
50
+ "project": true
51
+ },
52
+ "extends": [
53
+ "eslint:recommended",
54
+ "plugin:prettier/recommended",
55
+ "plugin:@typescript-eslint/recommended",
56
+ "plugin:@typescript-eslint/strict",
57
+ "plugin:unicorn/recommended"
58
+ ],
59
+ "plugins": [
60
+ "simple-import-sort",
61
+ "prettier",
62
+ "check-file"
63
+ ],
64
+ "rules": {
65
+ "unicorn/prevent-abbreviations": [
66
+ "error",
67
+ {
68
+ "replacements": {
69
+ "props": false,
70
+ "prop": false,
71
+ "ref": false,
72
+ "args": false,
73
+ "arg": false,
74
+ "src": false,
75
+ "dev": false,
76
+ "str": false
77
+ }
78
+ }
79
+ ],
80
+ "@typescript-eslint/no-non-null-assertion": "error",
81
+ "unicorn/no-nested-ternary": "off",
82
+ "unicorn/no-array-for-each": "off",
83
+ "unicorn/no-useless-undefined": "off",
84
+ "unicorn/no-null": "off",
85
+ "eqeqeq": [
86
+ "error",
87
+ "always"
88
+ ],
89
+ "no-alert": "error",
90
+ "no-eval": "error",
91
+ "prettier/prettier": "warn",
92
+ "simple-import-sort/imports": [
93
+ "error",
94
+ {
95
+ "groups": [
96
+ [
97
+ "^react$"
98
+ ],
99
+ [
100
+ "^react"
101
+ ],
102
+ [
103
+ "^next"
104
+ ],
105
+ [
106
+ "^zod"
107
+ ],
108
+ [
109
+ "^@radix-ui/"
110
+ ],
111
+ [
112
+ "^[^.]"
113
+ ],
114
+ [
115
+ "@/components/ui/.*"
116
+ ],
117
+ [
118
+ "@/components/.*"
119
+ ],
120
+ [
121
+ "@/config/.*"
122
+ ],
123
+ [
124
+ "@/lib/.*"
125
+ ],
126
+ [
127
+ "^\\.\\.(?!/?$)",
128
+ "^\\.\\./?$"
129
+ ],
130
+ [
131
+ "^\\./(?=.*/)(?!/?$)",
132
+ "^\\.(?!/?$)",
133
+ "^\\./?$"
134
+ ],
135
+ [
136
+ "^.+\\.s?css$"
137
+ ]
138
+ ]
139
+ }
140
+ ],
141
+ "check-file/no-index": "error",
142
+ "check-file/filename-naming-convention": [
143
+ "error",
144
+ {
145
+ "**/*.{jsx,tsx}": "KEBAB_CASE",
146
+ "**/*.{js,ts}": "KEBAB_CASE"
147
+ },
148
+ {
149
+ "ignoreMiddleExtensions": true
150
+ }
151
+ ],
152
+ "check-file/filename-blocklist": [
153
+ "error",
154
+ {
155
+ "**/*.spec.js": "*.test.js",
156
+ "**/*.spec.jsx": "*.test.jsx",
157
+ "**/*.spec.ts": "*.test.ts",
158
+ "**/*.spec.tsx": "*.test.tsx"
159
+ }
160
+ ],
161
+ "no-restricted-syntax": [
162
+ "error",
163
+ {
164
+ "selector": "TSEnumDeclaration",
165
+ "message": "Prefer string unions to enums."
166
+ }
167
+ ],
168
+ "curly": [
169
+ "error",
170
+ "multi-line"
171
+ ],
172
+ "@typescript-eslint/consistent-type-definitions": [
173
+ "error",
174
+ "type"
175
+ ],
176
+ "@typescript-eslint/no-unused-vars": [
177
+ "warn",
178
+ {
179
+ "argsIgnorePattern": "^_",
180
+ "varsIgnorePattern": "^_"
181
+ }
182
+ ],
183
+ "@typescript-eslint/no-explicit-any": 1
184
+ },
185
+ "ignorePatterns": [
186
+ "node_modules",
187
+ "out",
188
+ "build",
189
+ "dist/",
190
+ ".next"
191
+ ]
192
+ }
193
+ }