@openfin/cloud-api 0.0.1-alpha.0857dfe

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 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;
2
+ //# sourceMappingURL=index.cjs.map
@@ -0,0 +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,IAAID,CAAc,EAE1BA,EAAe,SAAS,sBAAwBE,GAAY,CACxD,QAAWC,KAAYC,EAAe,IAAIF,EAAQ,IAAI,GAAK,CAAC,EAEpD,OAAOA,EAAQ,QAAQ,WAAc,WACrCA,EAAQ,QAAQ,UAAY,IAAI,KAAKA,EAAQ,QAAQ,SAAS,GAGlEC,EAASD,EAAQ,OAAgB,CAEzC,CAAC,EAED,IAAME,EAAiB,IAAI,IAE3B,MAAO,CACH,iBAAkB,CAAwCC,EAAcF,IAAuC,CAC3G,IAAMG,EAAYF,EAAe,IAAIC,CAAS,GAAK,IAAI,IACvDC,EAAU,IAAIH,CAAQ,EACtBC,EAAe,IAAIC,EAAWC,CAAS,CAC3C,EACA,oBAAqB,CAAwCD,EAAcF,IAAuC,CAC9G,IAAMG,EAAYF,EAAe,IAAIC,CAAS,EAC9C,GAAI,CAACC,EAAW,CACZ,QAAQ,KACJ,KAAKd,CAAY,+HACjBa,CACJ,EACA,MACJ,CAEIC,EAAU,OAAOH,CAAmC,IAAM,IAC1D,QAAQ,KAAK,KAAKX,CAAY,iGAAkGa,CAAS,CAEjJ,EACA,OAAQ,MAAOE,IACM,MAAMP,EAAe,SAAS,oCAAqC,CAChF,QAAS,EACT,QAAS,CACL,aAAcO,CAClB,CACJ,CAAC,GACe,QAAQ,SAE5B,MAAO,MAAOC,IACO,MAAMR,EAAe,SAAS,mCAAoC,CAC/E,QAAS,EACT,QAAS,CACL,eAAAQ,CACJ,CACJ,CAAC,GACe,QAAQ,SAE5B,mBAAoB,MAChBD,IAEIA,EAAQ,IACR,QAAQ,KACJ,KAAKf,CAAY,+KACrB,GAEa,MAAMQ,EAAe,SAAS,oCAAqC,CAChF,QAAS,EACT,QAAS,CACL,aAAc,CAAE,GAAGO,EAAS,GAAI,MAAU,CAC9C,CACJ,CAAC,GACe,QAAQ,SAEhC,CACJ,CAEA,IAAIE,EAA6D,KAEjE,eAAeR,GAAkD,CAC7D,OAAKQ,IACDA,EAAuBC,EAAyB,GAG7CD,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"]}
@@ -0,0 +1,211 @@
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
+ 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 };
@@ -0,0 +1,211 @@
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
+ 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 };
package/dist/index.js ADDED
@@ -0,0 +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};
2
+ //# sourceMappingURL=index.js.map
@@ -0,0 +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,EAAe,SAAS,sBAAwBE,GAAY,CACxD,QAAWC,KAAYC,EAAe,IAAIF,EAAQ,IAAI,GAAK,CAAC,EAEpD,OAAOA,EAAQ,QAAQ,WAAc,WACrCA,EAAQ,QAAQ,UAAY,IAAI,KAAKA,EAAQ,QAAQ,SAAS,GAGlEC,EAASD,EAAQ,OAAgB,CAEzC,CAAC,EAED,IAAME,EAAiB,IAAI,IAE3B,MAAO,CACH,iBAAkB,CAAwCC,EAAcF,IAAuC,CAC3G,IAAMG,EAAYF,EAAe,IAAIC,CAAS,GAAK,IAAI,IACvDC,EAAU,IAAIH,CAAQ,EACtBC,EAAe,IAAIC,EAAWC,CAAS,CAC3C,EACA,oBAAqB,CAAwCD,EAAcF,IAAuC,CAC9G,IAAMG,EAAYF,EAAe,IAAIC,CAAS,EAC9C,GAAI,CAACC,EAAW,CACZ,QAAQ,KACJ,KAAKd,CAAY,+HACjBa,CACJ,EACA,MACJ,CAEIC,EAAU,OAAOH,CAAmC,IAAM,IAC1D,QAAQ,KAAK,KAAKX,CAAY,iGAAkGa,CAAS,CAEjJ,EACA,OAAQ,MAAOE,IACM,MAAMP,EAAe,SAAS,oCAAqC,CAChF,QAAS,EACT,QAAS,CACL,aAAcO,CAClB,CACJ,CAAC,GACe,QAAQ,SAE5B,MAAO,MAAOC,IACO,MAAMR,EAAe,SAAS,mCAAoC,CAC/E,QAAS,EACT,QAAS,CACL,eAAAQ,CACJ,CACJ,CAAC,GACe,QAAQ,SAE5B,mBAAoB,MAChBD,IAEIA,EAAQ,IACR,QAAQ,KACJ,KAAKf,CAAY,+KACrB,GAEa,MAAMQ,EAAe,SAAS,oCAAqC,CAChF,QAAS,EACT,QAAS,CACL,aAAc,CAAE,GAAGO,EAAS,GAAI,MAAU,CAC9C,CACJ,CAAC,GACe,QAAQ,SAEhC,CACJ,CAEA,IAAIE,EAA6D,KAEjE,eAAeR,GAAkD,CAC7D,OAAKQ,IACDA,EAAuBC,EAAyB,GAG7CD,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","names":["PACKAGE_NAME","getChannelName","isInViewContext","extractAppUuidFromIdentity","identity","notificationsClientPromise","getNotificationsClient","getNotificationsClientInternal","channelPromise","getChannelClient","message","listener","eventListeners","eventName","listeners","options","notificationId","channelClientPromise","getChannelClientInternal","channel"]}
package/package.json ADDED
@@ -0,0 +1,194 @@
1
+ {
2
+ "name": "@openfin/cloud-api",
3
+ "version": "0.0.1-alpha.0857dfe",
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
+ "lint": "eslint . --ext .ts,.tsx --max-warnings 0"
18
+ },
19
+ "files": [
20
+ "dist"
21
+ ],
22
+ "dependencies": {
23
+ "@openfin/core": "^34.78.80",
24
+ "openfin-notifications": "^2.3.2"
25
+ },
26
+ "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",
31
+ "eslint-config-prettier": "^9.1.0",
32
+ "eslint-plugin-check-file": "^2.6.2",
33
+ "eslint-plugin-prettier": "^5.1.3",
34
+ "eslint-plugin-simple-import-sort": "^10.0.0",
35
+ "eslint-plugin-unicorn": "^51.0.1",
36
+ "prettier": "^3.2.5",
37
+ "tsup": "^8.0.1",
38
+ "typescript": "^5.3.3"
39
+ },
40
+ "eslintConfig": {
41
+ "env": {
42
+ "browser": true,
43
+ "node": true
44
+ },
45
+ "parser": "@typescript-eslint/parser",
46
+ "parserOptions": {
47
+ "ecmaVersion": "latest",
48
+ "sourceType": "module",
49
+ "project": true
50
+ },
51
+ "extends": [
52
+ "eslint:recommended",
53
+ "plugin:prettier/recommended",
54
+ "plugin:@typescript-eslint/recommended",
55
+ "plugin:@typescript-eslint/strict",
56
+ "plugin:unicorn/recommended"
57
+ ],
58
+ "plugins": [
59
+ "simple-import-sort",
60
+ "prettier",
61
+ "check-file"
62
+ ],
63
+ "rules": {
64
+ "unicorn/prevent-abbreviations": [
65
+ "error",
66
+ {
67
+ "replacements": {
68
+ "props": false,
69
+ "prop": false,
70
+ "ref": false,
71
+ "args": false,
72
+ "arg": false,
73
+ "src": false,
74
+ "dev": false,
75
+ "str": false
76
+ }
77
+ }
78
+ ],
79
+ "@typescript-eslint/no-non-null-assertion": "error",
80
+ "unicorn/no-nested-ternary": "off",
81
+ "unicorn/no-array-for-each": "off",
82
+ "unicorn/no-useless-undefined": "off",
83
+ "unicorn/no-null": "off",
84
+ "eqeqeq": [
85
+ "error",
86
+ "always"
87
+ ],
88
+ "no-alert": "error",
89
+ "no-eval": "error",
90
+ "prettier/prettier": "warn",
91
+ "simple-import-sort/imports": [
92
+ "error",
93
+ {
94
+ "groups": [
95
+ [
96
+ "^react$"
97
+ ],
98
+ [
99
+ "^react"
100
+ ],
101
+ [
102
+ "^next"
103
+ ],
104
+ [
105
+ "^zod"
106
+ ],
107
+ [
108
+ "^@radix-ui/"
109
+ ],
110
+ [
111
+ "^[^.]"
112
+ ],
113
+ [
114
+ "@/components/ui/.*"
115
+ ],
116
+ [
117
+ "@/components/.*"
118
+ ],
119
+ [
120
+ "@/config/.*"
121
+ ],
122
+ [
123
+ "@/lib/.*"
124
+ ],
125
+ [
126
+ "^\\.\\.(?!/?$)",
127
+ "^\\.\\./?$"
128
+ ],
129
+ [
130
+ "^\\./(?=.*/)(?!/?$)",
131
+ "^\\.(?!/?$)",
132
+ "^\\./?$"
133
+ ],
134
+ [
135
+ "^.+\\.s?css$"
136
+ ]
137
+ ]
138
+ }
139
+ ],
140
+ "check-file/no-index": "error",
141
+ "check-file/filename-naming-convention": [
142
+ "error",
143
+ {
144
+ "**/*.{jsx,tsx}": "KEBAB_CASE",
145
+ "**/*.{js,ts}": "KEBAB_CASE"
146
+ },
147
+ {
148
+ "ignoreMiddleExtensions": true
149
+ }
150
+ ],
151
+ "check-file/filename-blocklist": [
152
+ "error",
153
+ {
154
+ "**/*.spec.js": "*.test.js",
155
+ "**/*.spec.jsx": "*.test.jsx",
156
+ "**/*.spec.ts": "*.test.ts",
157
+ "**/*.spec.tsx": "*.test.tsx"
158
+ }
159
+ ],
160
+ "no-restricted-syntax": [
161
+ "error",
162
+ {
163
+ "selector": "TSEnumDeclaration",
164
+ "message": "Prefer string unions to enums."
165
+ }
166
+ ],
167
+ "curly": [
168
+ "error",
169
+ "multi-line"
170
+ ],
171
+ "@typescript-eslint/consistent-type-definitions": [
172
+ "error",
173
+ "type"
174
+ ],
175
+ "@typescript-eslint/no-unused-vars": [
176
+ "warn",
177
+ {
178
+ "argsIgnorePattern": "^_",
179
+ "varsIgnorePattern": "^_"
180
+ }
181
+ ],
182
+ "@typescript-eslint/no-explicit-any": [
183
+ "warn"
184
+ ]
185
+ },
186
+ "ignorePatterns": [
187
+ "node_modules",
188
+ "out",
189
+ "build",
190
+ "dist/",
191
+ ".next"
192
+ ]
193
+ }
194
+ }