@notifi-network/notifi-graphql
Advanced tools
Comparing version 2.2.1-alpha.14 to 2.2.1-alpha.15
@@ -27,3 +27,3 @@ import { Client as WebSocketClient } from 'graphql-ws'; | ||
type NotifiSubscriptionEvents = { | ||
export type NotifiSubscriptionEvents = { | ||
tenantActiveAlertChanged: [TenantActiveAlertChangeEvent]; | ||
@@ -30,0 +30,0 @@ stateChanged: [StateChangedEvent]; |
@@ -7,8 +7,8 @@ import { | ||
import { Observable, Subscription } from 'relay-runtime'; | ||
import { NotifiEventEmitter, NotifiEmitterEvents } from './NotifiEventEmitter'; | ||
import { | ||
NotifiEventEmitter, | ||
NotifiEmitterEvents, | ||
NotifiSubscriptionEvents, | ||
} from './NotifiEventEmitter'; | ||
import { stateChangedSubscriptionQuery } from './gql'; | ||
import { | ||
StateChangedEvent, | ||
TenantActiveAlertChangeEvent, | ||
} from './gql/generated'; | ||
import { tenantActiveAlertChangedSubscriptionQuery } from './gql/subscriptions/tenantActiveAlertChanged.gql'; | ||
@@ -143,8 +143,19 @@ | ||
case stateChangedSubscriptionQuery: | ||
this.eventEmitter.emit('stateChanged', data as StateChangedEvent); | ||
const stateChangedData = getSubscriptionData('stateChanged', data); | ||
if (!stateChangedData) { | ||
throw new Error('Invalid stateChanged event data'); | ||
} | ||
this.eventEmitter.emit('stateChanged', stateChangedData); | ||
break; | ||
case tenantActiveAlertChangedSubscriptionQuery: | ||
const tenantActiveAlertChangedData = getSubscriptionData( | ||
'tenantActiveAlertChanged', | ||
data, | ||
); | ||
if (!tenantActiveAlertChangedData) { | ||
throw new Error('Invalid tenantActiveAlertChanged event data'); | ||
} | ||
this.eventEmitter.emit( | ||
'tenantActiveAlertChanged', | ||
data as TenantActiveAlertChangeEvent, | ||
tenantActiveAlertChangedData, | ||
); | ||
@@ -219,1 +230,23 @@ break; | ||
} | ||
// Utils | ||
const getSubscriptionData = <T extends keyof NotifiSubscriptionEvents>( | ||
subscriptionEvent: T, | ||
data: unknown, | ||
) => { | ||
// NOTE: The raw data from the subscription is in the format { data: { subscriptionEvent: T } } | ||
if (typeof data !== 'object' || data === null) return null; | ||
if (!('data' in data)) return null; | ||
const subscriptionData = data.data; | ||
if ( | ||
typeof subscriptionData === 'object' && | ||
subscriptionData !== null && | ||
subscriptionEvent in subscriptionData | ||
) { | ||
return (subscriptionData as Record<keyof NotifiSubscriptionEvents, any>)[ | ||
subscriptionEvent | ||
] as NotifiSubscriptionEvents[T][0]; | ||
} | ||
return null; | ||
}; |
{ | ||
"name": "@notifi-network/notifi-graphql", | ||
"version": "2.2.1-alpha.14+8de158d1", | ||
"version": "2.2.1-alpha.15+ef3fed3b", | ||
"description": "The GraphQL API for Notifi", | ||
@@ -49,3 +49,3 @@ "main": "./dist/index.js", | ||
}, | ||
"gitHead": "8de158d1077066c906350c8ba7d49e7785b9f68d" | ||
"gitHead": "ef3fed3bf7163352c537cfcef1829b30e805e973" | ||
} |
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is too big to display
Sorry, the diff of this file is too big to display
Sorry, the diff of this file is not supported yet
Manifest confusion
Supply chain riskThis package has inconsistent metadata. This could be malicious or caused by an error when publishing the package.
Found 1 instance in 1 package
Manifest confusion
Supply chain riskThis package has inconsistent metadata. This could be malicious or caused by an error when publishing the package.
Found 1 instance in 1 package
1315494
17824