@openfin/bloomberg
Advanced tools
Comparing version 0.1.0 to 0.1.1
@@ -1,2 +0,1 @@ | ||
"use strict"; | ||
Object.defineProperty(exports, "__esModule", { value: true }); | ||
"use strict";Object.defineProperty(exports,"__esModule",{value:!0}); |
@@ -1,46 +0,1 @@ | ||
"use strict"; | ||
Object.defineProperty(exports, "__esModule", { value: true }); | ||
exports.removeConnection = exports.getConnectionById = exports.addConnection = void 0; | ||
/** | ||
* Stores active connections. | ||
*/ | ||
const apiConnections = []; | ||
/** | ||
* Adds a new API connection. | ||
* @param windowContextListener Function executed when window context is changed. | ||
* @param bloombergGroupSubscriptionId Connected Bloomberg Launchpad group subscription ID. | ||
*/ | ||
const addConnection = (windowContextListener, bloombergGroupSubscriptionId) => { | ||
const id = getUniqueId(); | ||
const connection = { | ||
windowContextListener, | ||
id, | ||
}; | ||
if ((bloombergGroupSubscriptionId !== null && bloombergGroupSubscriptionId !== void 0 ? bloombergGroupSubscriptionId : undefined) !== undefined) { | ||
connection.bbgSubId = bloombergGroupSubscriptionId; | ||
} | ||
apiConnections.push(connection); | ||
return id; | ||
}; | ||
exports.addConnection = addConnection; | ||
/** | ||
* Generate a unique, short alphanumeric ID string using the Web Crypto API. | ||
*/ | ||
const getUniqueId = () => { | ||
return window.crypto.getRandomValues(new Uint32Array(1))[0].toString(36); | ||
}; | ||
/** | ||
* Gets the API connection with the given ID. | ||
* @param id ID for identifying the connection. | ||
*/ | ||
const getConnectionById = (id) => apiConnections.find((connection) => connection.id === id); | ||
exports.getConnectionById = getConnectionById; | ||
/** | ||
* Removes the API connection with the given ID. | ||
* @param id ID for identifying the connection. | ||
*/ | ||
const removeConnection = (id) => { | ||
const index = apiConnections.findIndex((connection) => connection.id === id); | ||
apiConnections.splice(index, 1); | ||
}; | ||
exports.removeConnection = removeConnection; | ||
"use strict";Object.defineProperty(exports,"__esModule",{value:!0}),exports.removeConnection=exports.getConnectionById=exports.addConnection=void 0;const apiConnections=[],addConnection=(n,o)=>{var e=getUniqueId();const t={windowContextListener:n,id:e};return void 0!==(null!=o?o:void 0)&&(t.bbgSubId=o),apiConnections.push(t),e};exports.addConnection=addConnection;const getUniqueId=()=>window.crypto.getRandomValues(new Uint32Array(1))[0].toString(36),getConnectionById=o=>apiConnections.find(n=>n.id===o);exports.getConnectionById=getConnectionById;const removeConnection=o=>{var n=apiConnections.findIndex(n=>n.id===o);apiConnections.splice(n,1)};exports.removeConnection=removeConnection; |
@@ -1,86 +0,1 @@ | ||
"use strict"; | ||
var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) { | ||
function adopt(value) { return value instanceof P ? value : new P(function (resolve) { resolve(value); }); } | ||
return new (P || (P = Promise))(function (resolve, reject) { | ||
function fulfilled(value) { try { step(generator.next(value)); } catch (e) { reject(e); } } | ||
function rejected(value) { try { step(generator["throw"](value)); } catch (e) { reject(e); } } | ||
function step(result) { result.done ? resolve(result.value) : adopt(result.value).then(fulfilled, rejected); } | ||
step((generator = generator.apply(thisArg, _arguments || [])).next()); | ||
}); | ||
}; | ||
Object.defineProperty(exports, "__esModule", { value: true }); | ||
exports.connect = void 0; | ||
const connection_manager_1 = require("../connection-manager/connection-manager"); | ||
const logger_1 = require("../logger/logger"); | ||
const window_1 = require("../window/window"); | ||
const SOURCE_NAME = 'DIRECT'; | ||
/** | ||
* Connect to Bloomberg Terminal panels and Launchpad groups. | ||
* | ||
* Ensure that connection is cleaned up by calling `close` when finished. | ||
* | ||
* ```ts | ||
* // Create a two way connection with Launchpad group 'A' | ||
* const connection = await connect( | ||
* 'Group-A', | ||
* 'Group-A', | ||
* (context) => console.log('Change detected', context), | ||
* console.error | ||
* ); | ||
* | ||
* // Update the security for group 'A' to 'TSLA US Equity' | ||
* await connection.setSecurity('TSLA US Equity'); | ||
* | ||
* // Close the connection | ||
* await connection.close(); | ||
* ``` | ||
* @param source The Bloomberg Launchpad group that triggers the `onSecurityChanged` callback whenever the group security is changed. Set all groups | ||
* by passing '*'. | ||
* @param target The Bloomberg Terminal panel or Launchpad group whose security will be updated by calling `setSecurity`. Update | ||
* all groups by passing '*'. | ||
* @param onChange Callback that is run whenever `setSecurity` is called or a source group security is changed. | ||
* @param onError Callback that is run if an error occurs. | ||
*/ | ||
const connect = (source, target, onChange, onError) => __awaiter(void 0, void 0, void 0, function* () { | ||
const connection = (yield window_1.connectWindowContext(SOURCE_NAME, source, target, onChange, onChange, onError)); | ||
connection.close = () => disconnect(connection.id); | ||
connection.setSecurity = getSecurityChangeHandler(connection.id); | ||
if ((source !== null && source !== void 0 ? source : undefined) !== undefined) { | ||
connection.source = source; | ||
} | ||
if ((target !== null && target !== void 0 ? target : undefined) !== undefined) { | ||
connection.target = target; | ||
} | ||
logger_1.logInfo(`Connection created (${connection.id})`); | ||
return connection; | ||
}); | ||
exports.connect = connect; | ||
/** | ||
* Closes an existing connection. | ||
* @param id ID for identifying the connection to close. | ||
*/ | ||
const disconnect = (id) => __awaiter(void 0, void 0, void 0, function* () { | ||
const connection = connection_manager_1.getConnectionById(id); | ||
if ((connection !== null && connection !== void 0 ? connection : undefined) === undefined) { | ||
return; | ||
} | ||
try { | ||
yield window_1.disconnectWindowContext(id); | ||
logger_1.logInfo(`Connection closed (${id})`); | ||
} | ||
catch (err) { | ||
logger_1.logWarning(`Unable to close connection: ${err.message} (${id})`); | ||
throw err; | ||
} | ||
}); | ||
/** | ||
* Gets a function that will update window context when a security is received. | ||
* @param id ID for identifying the connection. | ||
*/ | ||
const getSecurityChangeHandler = (id) => (security) => __awaiter(void 0, void 0, void 0, function* () { | ||
if (!security) { | ||
return; | ||
} | ||
logger_1.logInfo(`Received security '${security}' (${id})`); | ||
yield window_1.updateWindowContext(security, SOURCE_NAME); | ||
}); | ||
"use strict";var __awaiter=this&&this.__awaiter||function(n,r,d,a){return new(d=d||Promise)(function(o,e){function t(n){try{c(a.next(n))}catch(n){e(n)}}function i(n){try{c(a.throw(n))}catch(n){e(n)}}function c(n){var e;n.done?o(n.value):((e=n.value)instanceof d?e:new d(function(n){n(e)})).then(t,i)}c((a=a.apply(n,r||[])).next())})};Object.defineProperty(exports,"__esModule",{value:!0}),exports.connect=void 0;const connection_manager_1=require("../connection-manager/connection-manager"),logger_1=require("../logger/logger"),window_1=require("../window/window"),SOURCE_NAME="DIRECT",connect=(e,o,t,i)=>__awaiter(void 0,void 0,void 0,function*(){const n=yield window_1.connectWindowContext(SOURCE_NAME,e,o,t,t,i);return n.close=()=>disconnect(n.id),n.setSecurity=getSecurityChangeHandler(n.id),void 0!==(null!=e?e:void 0)&&(n.source=e),void 0!==(null!=o?o:void 0)&&(n.target=o),logger_1.logInfo(`Connection created (${n.id})`),n});exports.connect=connect;const disconnect=e=>__awaiter(void 0,void 0,void 0,function*(){var n=connection_manager_1.getConnectionById(e);if(void 0!==(null!=n?n:void 0))try{yield window_1.disconnectWindowContext(e),logger_1.logInfo(`Connection closed (${e})`)}catch(n){throw logger_1.logWarning(`Unable to close connection: ${n.message} (${e})`),n}}),getSecurityChangeHandler=e=>n=>__awaiter(void 0,void 0,void 0,function*(){n&&(logger_1.logInfo(`Received security '${n}' (${e})`),yield window_1.updateWindowContext(n,SOURCE_NAME))}); |
@@ -1,72 +0,1 @@ | ||
"use strict"; | ||
/* eslint-disable max-classes-per-file */ | ||
Object.defineProperty(exports, "__esModule", { value: true }); | ||
exports.TerminalConnectionError = exports.BloombergSecurityError = exports.AppNotAuthorizedError = exports.BloombergApiError = exports.getApiErrorFromError = void 0; | ||
/** | ||
* Gets the relevant API error for a given Terminal Connect API error. | ||
* @param error Error generated by Terminal Connect API. | ||
* | ||
* @internal | ||
*/ | ||
const getApiErrorFromError = (error) => { | ||
var _a, _b, _c; | ||
if (error instanceof BloombergApiError) { | ||
return error; | ||
} | ||
switch (true) { | ||
case ((_a = error === null || error === void 0 ? void 0 : error.message) === null || _a === void 0 ? void 0 : _a.indexOf('APPLICATION_VALIDATION')) >= 0: | ||
return new AppNotAuthorizedError(); | ||
case ((_b = error === null || error === void 0 ? void 0 : error.message) === null || _b === void 0 ? void 0 : _b.indexOf('INVALID_COMMAND')) >= 0: | ||
case ((_c = error === null || error === void 0 ? void 0 : error.message) === null || _c === void 0 ? void 0 : _c.indexOf('INVALID_GROUP_VALUE')) >= 0: | ||
return new BloombergSecurityError(); | ||
case (error === null || error === void 0 ? void 0 : error.message) === '[object Object]': | ||
return new TerminalConnectionError(); | ||
default: | ||
return new BloombergApiError(error); | ||
} | ||
}; | ||
exports.getApiErrorFromError = getApiErrorFromError; | ||
/** | ||
* Base class for Bloomberg API errors. | ||
*/ | ||
class BloombergApiError extends Error { | ||
constructor(error, message = 'An unexpected error has occurred', title = 'Bloomberg Integration Error', description = 'An unexpected error has occurred.') { | ||
var _a, _b; | ||
super((_a = error === null || error === void 0 ? void 0 : error.message) !== null && _a !== void 0 ? _a : message); | ||
this.title = title; | ||
this.description = description; | ||
// Use error param stacktrace if provided and add error class name | ||
if (error === null || error === void 0 ? void 0 : error.stack) { | ||
this.stack = error.stack; | ||
} | ||
this.stack = (_b = this.stack) === null || _b === void 0 ? void 0 : _b.replace(/^(Error)/, `$1 (${this.constructor.name})`); | ||
} | ||
} | ||
exports.BloombergApiError = BloombergApiError; | ||
/** | ||
* Error class used when the calling app has not been registered with Bloomberg to use the Terminal Connect API. | ||
*/ | ||
class AppNotAuthorizedError extends BloombergApiError { | ||
constructor(error, message = 'App not authorized to use Terminal Connect API', title = 'Unauthorized App', description = 'This app is not authorized to use the Bloomberg Terminal Connect API. Contact the Bloomberg App Portal team for support.') { | ||
super(error, message, title, description); | ||
} | ||
} | ||
exports.AppNotAuthorizedError = AppNotAuthorizedError; | ||
/** | ||
* Error class used when attempting to set a group security in Bloomberg results in an error. | ||
*/ | ||
class BloombergSecurityError extends BloombergApiError { | ||
constructor(error, message = 'The processed security is invalid', title = 'Invalid Security', description = 'An instrument context was received that contained an invalid security.') { | ||
super(error, message, title, description); | ||
} | ||
} | ||
exports.BloombergSecurityError = BloombergSecurityError; | ||
/** | ||
* Error class used when unable to communicate with the local Bloomberg Terminal instance. | ||
*/ | ||
class TerminalConnectionError extends BloombergApiError { | ||
constructor(error, message = 'Unable to connect to local terminal service', title = 'Bloomberg Connection Error', description = 'Ensure Bloomberg is running locally and that you are logged in.') { | ||
super(error, message, title, description); | ||
} | ||
} | ||
exports.TerminalConnectionError = TerminalConnectionError; | ||
"use strict";Object.defineProperty(exports,"__esModule",{value:!0}),exports.TerminalConnectionError=exports.BloombergSecurityError=exports.AppNotAuthorizedError=exports.BloombergApiError=exports.getApiErrorFromError=void 0;const getApiErrorFromError=r=>{var o;if(r instanceof BloombergApiError)return r;switch(!0){case 0<=(null===(o=null==r?void 0:r.message)||void 0===o?void 0:o.indexOf("APPLICATION_VALIDATION")):return new AppNotAuthorizedError;case 0<=(null===(o=null==r?void 0:r.message)||void 0===o?void 0:o.indexOf("INVALID_COMMAND")):case 0<=(null===(o=null==r?void 0:r.message)||void 0===o?void 0:o.indexOf("INVALID_GROUP_VALUE")):return new BloombergSecurityError;case"[object Object]"===(null==r?void 0:r.message):return new TerminalConnectionError;default:return new BloombergApiError(r)}};exports.getApiErrorFromError=getApiErrorFromError;class BloombergApiError extends Error{constructor(r,o="An unexpected error has occurred",e="Bloomberg Integration Error",t="An unexpected error has occurred."){var n;super(null!==(n=null==r?void 0:r.message)&&void 0!==n?n:o),this.title=e,this.description=t,null!=r&&r.stack&&(this.stack=r.stack),this.stack=null===(r=this.stack)||void 0===r?void 0:r.replace(/^(Error)/,`$1 (${this.constructor.name})`)}}exports.BloombergApiError=BloombergApiError;class AppNotAuthorizedError extends BloombergApiError{constructor(r,o="App not authorized to use Terminal Connect API",e="Unauthorized App",t="This app is not authorized to use the Bloomberg Terminal Connect API. Contact the Bloomberg App Portal team for support."){super(r,o,e,t)}}exports.AppNotAuthorizedError=AppNotAuthorizedError;class BloombergSecurityError extends BloombergApiError{constructor(r,o="The processed security is invalid",e="Invalid Security",t="An instrument context was received that contained an invalid security."){super(r,o,e,t)}}exports.BloombergSecurityError=BloombergSecurityError;class TerminalConnectionError extends BloombergApiError{constructor(r,o="Unable to connect to local terminal service",e="Bloomberg Connection Error",t="Ensure Bloomberg is running locally and that you are logged in."){super(r,o,e,t)}}exports.TerminalConnectionError=TerminalConnectionError; |
142
fdc3/fdc3.js
@@ -1,141 +0,1 @@ | ||
"use strict"; | ||
var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) { | ||
if (k2 === undefined) k2 = k; | ||
Object.defineProperty(o, k2, { enumerable: true, get: function() { return m[k]; } }); | ||
}) : (function(o, m, k, k2) { | ||
if (k2 === undefined) k2 = k; | ||
o[k2] = m[k]; | ||
})); | ||
var __setModuleDefault = (this && this.__setModuleDefault) || (Object.create ? (function(o, v) { | ||
Object.defineProperty(o, "default", { enumerable: true, value: v }); | ||
}) : function(o, v) { | ||
o["default"] = v; | ||
}); | ||
var __importStar = (this && this.__importStar) || function (mod) { | ||
if (mod && mod.__esModule) return mod; | ||
var result = {}; | ||
if (mod != null) for (var k in mod) if (k !== "default" && Object.prototype.hasOwnProperty.call(mod, k)) __createBinding(result, mod, k); | ||
__setModuleDefault(result, mod); | ||
return result; | ||
}; | ||
var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) { | ||
function adopt(value) { return value instanceof P ? value : new P(function (resolve) { resolve(value); }); } | ||
return new (P || (P = Promise))(function (resolve, reject) { | ||
function fulfilled(value) { try { step(generator.next(value)); } catch (e) { reject(e); } } | ||
function rejected(value) { try { step(generator["throw"](value)); } catch (e) { reject(e); } } | ||
function step(result) { result.done ? resolve(result.value) : adopt(result.value).then(fulfilled, rejected); } | ||
step((generator = generator.apply(thisArg, _arguments || [])).next()); | ||
}); | ||
}; | ||
Object.defineProperty(exports, "__esModule", { value: true }); | ||
exports.connectFdc3 = void 0; | ||
const fdc3 = __importStar(require("openfin-fdc3")); | ||
const connection_manager_1 = require("../connection-manager/connection-manager"); | ||
const logger_1 = require("../logger/logger"); | ||
const utils_1 = require("../utils/utils"); | ||
const window_1 = require("../window/window"); | ||
const SOURCE_NAME = 'FDC3'; | ||
/** | ||
* Connects Bloomberg Terminal panels and Launchpad groups with [FDC3](https://developers.openfin.co/docs/fdc3-1) context. | ||
* | ||
* Ensure that connection is cleaned up by calling `close` when finished. | ||
* | ||
* ```ts | ||
* // Create an FDC3 connection with Launchpad group 'A' on the default channel | ||
* const connection = await connectFdc3( | ||
* fdc3.defaultChannel, | ||
* 'Group-A', | ||
* 'Group-A', | ||
* (context) => console.log('Change detected', context), | ||
* console.error | ||
* ); | ||
* | ||
* // Close the connection | ||
* await connection.close(); | ||
* ``` | ||
* @param contextChannel The FDC3 [context channel](https://cdn.openfin.co/docs/services/fdc3/stable/api/modules/contextchannels.html) to create the connection on. Default channel used if none specified. | ||
* @param source The Bloomberg Launchpad group that triggers FDC3 broadcast whenever the group security is changed. Set all groups | ||
* by passing '*'. | ||
* @param target The Bloomberg Terminal panel or Launchpad group whose security will be updated whenever context is received over FDC3. Update | ||
* all groups by passing '*'. | ||
* @param onChange Callback that is run whenever context is received over FDC3 or a source group security is changed. | ||
* @param onError Callback that is run if an error occurs. | ||
*/ | ||
const connectFdc3 = (contextChannel = fdc3.defaultChannel, source, target, onChange, onError) => __awaiter(void 0, void 0, void 0, function* () { | ||
const connection = (yield window_1.connectWindowContext(SOURCE_NAME, source, target, getGroupEventHandler(contextChannel, onChange, onError), onChange, onError)); | ||
const fdc3Listener = contextChannel.addContextListener(getFdc3ContextListener(contextChannel, connection.id)); | ||
connection.close = () => disconnectFdc3(connection.id); | ||
connection.contextChannel = contextChannel; | ||
connection.fdc3ContextListener = fdc3Listener; | ||
if ((source !== null && source !== void 0 ? source : undefined) !== undefined) { | ||
connection.source = source; | ||
} | ||
if ((target !== null && target !== void 0 ? target : undefined) !== undefined) { | ||
connection.target = target; | ||
} | ||
logger_1.logInfo(`FDC3 connection created on ${contextChannel.id} channel (${connection.id})`); | ||
return connection; | ||
}); | ||
exports.connectFdc3 = connectFdc3; | ||
/** | ||
* Closes an existing connection between Bloomberg and FDC3 context. | ||
* @param id ID for identifying the connection to close. | ||
*/ | ||
const disconnectFdc3 = (id) => __awaiter(void 0, void 0, void 0, function* () { | ||
const connection = connection_manager_1.getConnectionById(id); | ||
if ((connection !== null && connection !== void 0 ? connection : undefined) === undefined) { | ||
return; | ||
} | ||
try { | ||
connection.fdc3ContextListener.unsubscribe(); | ||
yield window_1.disconnectWindowContext(id); | ||
logger_1.logInfo(`FDC3 connection closed (${id})`); | ||
} | ||
catch (err) { | ||
logger_1.logWarning(`Unable to close FDC3 connection: ${err.message} (${id})`); | ||
throw err; | ||
} | ||
}); | ||
/** | ||
* Gets a function that will update window context whenever FDC3 context changes. | ||
* @param contextChannel The FDC3 channel being listened to. | ||
* @param id ID for identifying the connection. | ||
*/ | ||
const getFdc3ContextListener = (contextChannel, id) => (context) => __awaiter(void 0, void 0, void 0, function* () { | ||
var _a, _b; | ||
logger_1.logInfo(`Received context via FDC3 on ${contextChannel.id} channel (${id})`, context); | ||
if (!utils_1.isInstrumentContext(context)) { | ||
logger_1.logInfo('Context data is not an FDC3 instrument, ignoring'); | ||
return; | ||
} | ||
const instrument = context; | ||
// Get the security from the BBG id code | ||
let security = (_a = instrument.id) === null || _a === void 0 ? void 0 : _a.BBG; | ||
if (!security) { | ||
// If BBG not provided, get the ticker and assume this is a US equity | ||
const ticker = (_b = instrument.id) === null || _b === void 0 ? void 0 : _b.ticker; | ||
security = utils_1.getSecurityStringFromParts(ticker, 'US'); | ||
} | ||
if (!security) { | ||
// Instrument context has no recognisable codes, ignore | ||
return; | ||
} | ||
yield window_1.updateWindowContext(security, SOURCE_NAME); | ||
}); | ||
/** | ||
* Returns a Bloomberg Launchpad group event handler function that broadcasts FDC3 context whenever a group security is changed. | ||
* @param contextChannel The FDC3 channel on which to broadcast. | ||
* @param onGroupEvent Callback that is run whenever a group security changed. | ||
* @param onError Callback that is run if an error occurs. | ||
*/ | ||
const getGroupEventHandler = (contextChannel, onGroupEvent, onError) => (security) => __awaiter(void 0, void 0, void 0, function* () { | ||
const context = utils_1.getInstrumentContextFromSecurity(security); | ||
logger_1.logInfo(`Broadcasting FDC3 context on ${contextChannel.id} channel`, context); | ||
try { | ||
yield contextChannel.broadcast(context); | ||
onGroupEvent === null || onGroupEvent === void 0 ? void 0 : onGroupEvent(security); | ||
} | ||
catch (err) { | ||
onError === null || onError === void 0 ? void 0 : onError(err); | ||
} | ||
}); | ||
"use strict";var __createBinding=this&&this.__createBinding||(Object.create?function(e,n,t,o){void 0===o&&(o=t),Object.defineProperty(e,o,{enumerable:!0,get:function(){return n[t]}})}:function(e,n,t,o){e[o=void 0===o?t:o]=n[t]}),__setModuleDefault=this&&this.__setModuleDefault||(Object.create?function(e,n){Object.defineProperty(e,"default",{enumerable:!0,value:n})}:function(e,n){e.default=n}),__importStar=this&&this.__importStar||function(e){if(e&&e.__esModule)return e;var n={};if(null!=e)for(var t in e)"default"!==t&&Object.prototype.hasOwnProperty.call(e,t)&&__createBinding(n,e,t);return __setModuleDefault(n,e),n},__awaiter=this&&this.__awaiter||function(e,c,d,a){return new(d=d||Promise)(function(t,n){function o(e){try{r(a.next(e))}catch(e){n(e)}}function i(e){try{r(a.throw(e))}catch(e){n(e)}}function r(e){var n;e.done?t(e.value):((n=e.value)instanceof d?n:new d(function(e){e(n)})).then(o,i)}r((a=a.apply(e,c||[])).next())})};Object.defineProperty(exports,"__esModule",{value:!0}),exports.connectFdc3=void 0;const fdc3=__importStar(require("openfin-fdc3")),connection_manager_1=require("../connection-manager/connection-manager"),logger_1=require("../logger/logger"),utils_1=require("../utils/utils"),window_1=require("../window/window"),SOURCE_NAME="FDC3",connectFdc3=(t=fdc3.defaultChannel,o,i,r,c)=>__awaiter(void 0,void 0,void 0,function*(){const e=yield window_1.connectWindowContext(SOURCE_NAME,o,i,getGroupEventHandler(t,r,c),r,c);var n=t.addContextListener(getFdc3ContextListener(t,e.id));return e.close=()=>disconnectFdc3(e.id),e.contextChannel=t,e.fdc3ContextListener=n,void 0!==(null!=o?o:void 0)&&(e.source=o),void 0!==(null!=i?i:void 0)&&(e.target=i),logger_1.logInfo(`FDC3 connection created on ${t.id} channel (${e.id})`),e});exports.connectFdc3=connectFdc3;const disconnectFdc3=n=>__awaiter(void 0,void 0,void 0,function*(){const e=connection_manager_1.getConnectionById(n);if(void 0!==(null!==e&&void 0!==e?e:void 0))try{e.fdc3ContextListener.unsubscribe(),yield window_1.disconnectWindowContext(n),logger_1.logInfo(`FDC3 connection closed (${n})`)}catch(e){throw logger_1.logWarning(`Unable to close FDC3 connection: ${e.message} (${n})`),e}}),getFdc3ContextListener=(e,o)=>t=>__awaiter(void 0,void 0,void 0,function*(){var n;if(logger_1.logInfo(`Received context via FDC3 on ${e.id} channel (${o})`,t),utils_1.isInstrumentContext(t)){let e=null===(n=t.id)||void 0===n?void 0:n.BBG;e||(n=null===(n=t.id)||void 0===n?void 0:n.ticker,e=utils_1.getSecurityStringFromParts(n,"US")),e&&(yield window_1.updateWindowContext(e,SOURCE_NAME))}else logger_1.logInfo("Context data is not an FDC3 instrument, ignoring")}),getGroupEventHandler=(t,o,i)=>n=>__awaiter(void 0,void 0,void 0,function*(){var e=utils_1.getInstrumentContextFromSecurity(n);logger_1.logInfo(`Broadcasting FDC3 context on ${t.id} channel`,e);try{yield t.broadcast(e),null!=o&&o(n)}catch(e){null!=i&&i(e)}}); |
121
iab/iab.js
@@ -1,120 +0,1 @@ | ||
"use strict"; | ||
var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) { | ||
function adopt(value) { return value instanceof P ? value : new P(function (resolve) { resolve(value); }); } | ||
return new (P || (P = Promise))(function (resolve, reject) { | ||
function fulfilled(value) { try { step(generator.next(value)); } catch (e) { reject(e); } } | ||
function rejected(value) { try { step(generator["throw"](value)); } catch (e) { reject(e); } } | ||
function step(result) { result.done ? resolve(result.value) : adopt(result.value).then(fulfilled, rejected); } | ||
step((generator = generator.apply(thisArg, _arguments || [])).next()); | ||
}); | ||
}; | ||
Object.defineProperty(exports, "__esModule", { value: true }); | ||
exports.connectInterApplicationBus = void 0; | ||
const connection_manager_1 = require("../connection-manager/connection-manager"); | ||
const logger_1 = require("../logger/logger"); | ||
const window_1 = require("../window/window"); | ||
const SOURCE_NAME = 'IAB'; | ||
/** | ||
* Connects Bloomberg Terminal panels and Launchpad groups with the [InterApplicationBus](https://developers.openfin.co/docs/channels-api-and-interapp-bus#section-inter-application-bus-overview). | ||
* | ||
* Ensure that connection is cleaned up by calling `close` when finished. | ||
* | ||
* ```ts | ||
* // Create an IAB connection with Launchpad group 'A' on topic 'bbg-security' to all applications | ||
* const connection = await connectInterApplicationBus( | ||
* 'bbg-security', | ||
* '*', | ||
* 'Group-A', | ||
* 'Group-A', | ||
* (context) => console.log('Change detected', context), | ||
* console.error | ||
* ); | ||
* | ||
* // Close the connection | ||
* await connection.close(); | ||
* ``` | ||
* @param topic The topic on which messages will be sent and received. | ||
* @param applicationId UUID of the application where messages will be sent to and received from. | ||
* @param source Bloomberg Launchpad group that triggers IAB messages to be sent whenever the group security is changed. | ||
* Specify all groups by passing '*'. | ||
* @param target Bloomberg Terminal panel or Launchpad group whose security will be updated whenever context is received over IAB. | ||
* Update all groups by passing '*'. | ||
* @param onChange Callback that is run whenever a message is received over IAB or a source group security is changed. | ||
* @param onError Callback that is run if an error occurs. | ||
*/ | ||
const connectInterApplicationBus = (topic, applicationId = '*', source, target, onChange, onError) => __awaiter(void 0, void 0, void 0, function* () { | ||
const connection = (yield window_1.connectWindowContext(SOURCE_NAME, source, target, getGroupEventHandler(topic, applicationId, onChange, onError), onChange, onError)); | ||
const iabListener = getInterApplicationBusListener(topic, connection.id); | ||
try { | ||
yield fin.InterApplicationBus.subscribe({ uuid: applicationId }, topic, iabListener); | ||
connection.applicationId = applicationId; | ||
connection.close = () => disconnectInterApplicationBus(connection.id); | ||
connection.iabListener = iabListener; | ||
connection.topic = topic; | ||
if ((source !== null && source !== void 0 ? source : undefined) !== undefined) { | ||
connection.source = source; | ||
} | ||
if ((target !== null && target !== void 0 ? target : undefined) !== undefined) { | ||
connection.target = target; | ||
} | ||
logger_1.logInfo(`IAB connection created on topic '${topic}' to ${applicationId === '*' ? 'all applications' : `application '${applicationId}'`} (${connection.id})`); | ||
return connection; | ||
} | ||
catch (err) { | ||
logger_1.logWarning(`Unable to create IAB connection created for topic '${topic}' with application '${applicationId}' (${connection.id})`); | ||
yield window_1.disconnectWindowContext(connection.id); | ||
onError === null || onError === void 0 ? void 0 : onError(err); | ||
} | ||
}); | ||
exports.connectInterApplicationBus = connectInterApplicationBus; | ||
/** | ||
* Closes an existing connection between Bloomberg and IAB. | ||
* @param id ID for identifying the connection to close. | ||
*/ | ||
const disconnectInterApplicationBus = (id) => __awaiter(void 0, void 0, void 0, function* () { | ||
const connection = connection_manager_1.getConnectionById(id); | ||
if ((connection !== null && connection !== void 0 ? connection : undefined) === undefined) { | ||
return; | ||
} | ||
try { | ||
yield fin.InterApplicationBus.unsubscribe({ uuid: connection.applicationId }, connection.topic, connection.iabListener); | ||
yield window_1.disconnectWindowContext(id); | ||
logger_1.logInfo(`IAB connection closed (${id})`); | ||
} | ||
catch (err) { | ||
logger_1.logWarning(`Unable to close IAB connection: ${err.message} (${id})`); | ||
throw err; | ||
} | ||
}); | ||
/** | ||
* Gets a function that will update window context whenever IAB message received. | ||
* @param topic The IAB topic being listened to. | ||
* @param id ID for identifying the connection. | ||
*/ | ||
const getInterApplicationBusListener = (topic, id) => (security, source) => __awaiter(void 0, void 0, void 0, function* () { | ||
if (!security || source.uuid === fin.me.uuid) { | ||
// Ignore empty messages or messages sent from self | ||
return; | ||
} | ||
logger_1.logInfo(`Received security '${security}' via IAB on topic '${topic}' from application '${source.uuid}' (${id})`); | ||
yield window_1.updateWindowContext(security, SOURCE_NAME); | ||
}); | ||
/** | ||
* Returns a Bloomberg Launchpad group event handler function that sends an IAB message whenever a group security changed. | ||
* @param topic The topic on which messages will be sent. | ||
* @param applicationId UUID of the application to which messages will be sent. | ||
* @param onGroupEvent Callback that is run whenever a group security changed. | ||
* @param onError Callback that is run if an error occurs. | ||
*/ | ||
const getGroupEventHandler = (topic, applicationId, onGroupEvent, onError) => (security) => __awaiter(void 0, void 0, void 0, function* () { | ||
logger_1.logInfo(`Sending IAB message '${security}' on topic '${topic}' to ${applicationId === '*' ? 'all applications' : `application '${applicationId}'`}`); | ||
try { | ||
yield (applicationId === '*' | ||
? fin.InterApplicationBus.publish(topic, security) | ||
: fin.InterApplicationBus.send({ uuid: applicationId }, topic, security)); | ||
onGroupEvent === null || onGroupEvent === void 0 ? void 0 : onGroupEvent(security); | ||
} | ||
catch (err) { | ||
onError === null || onError === void 0 ? void 0 : onError(err); | ||
} | ||
}); | ||
"use strict";var __awaiter=this&&this.__awaiter||function(n,a,r,l){return new(r=r||Promise)(function(o,i){function e(n){try{c(l.next(n))}catch(n){i(n)}}function t(n){try{c(l.throw(n))}catch(n){i(n)}}function c(n){var i;n.done?o(n.value):((i=n.value)instanceof r?i:new r(function(n){n(i)})).then(e,t)}c((l=l.apply(n,a||[])).next())})};Object.defineProperty(exports,"__esModule",{value:!0}),exports.connectInterApplicationBus=void 0;const connection_manager_1=require("../connection-manager/connection-manager"),logger_1=require("../logger/logger"),window_1=require("../window/window"),SOURCE_NAME="IAB",connectInterApplicationBus=(o,e="*",t,c,a,r)=>__awaiter(void 0,void 0,void 0,function*(){const i=yield window_1.connectWindowContext(SOURCE_NAME,t,c,getGroupEventHandler(o,e,a,r),a,r);var n=getInterApplicationBusListener(o,i.id);try{return yield fin.InterApplicationBus.subscribe({uuid:e},o,n),i.applicationId=e,i.close=()=>disconnectInterApplicationBus(i.id),i.iabListener=n,i.topic=o,void 0!==(null!=t?t:void 0)&&(i.source=t),void 0!==(null!=c?c:void 0)&&(i.target=c),logger_1.logInfo(`IAB connection created on topic '${o}' to ${"*"===e?"all applications":`application '${e}'`} (${i.id})`),i}catch(n){logger_1.logWarning(`Unable to create IAB connection created for topic '${o}' with application '${e}' (${i.id})`),yield window_1.disconnectWindowContext(i.id),null!=r&&r(n)}});exports.connectInterApplicationBus=connectInterApplicationBus;const disconnectInterApplicationBus=i=>__awaiter(void 0,void 0,void 0,function*(){var n=connection_manager_1.getConnectionById(i);if(void 0!==(null!=n?n:void 0))try{yield fin.InterApplicationBus.unsubscribe({uuid:n.applicationId},n.topic,n.iabListener),yield window_1.disconnectWindowContext(i),logger_1.logInfo(`IAB connection closed (${i})`)}catch(n){throw logger_1.logWarning(`Unable to close IAB connection: ${n.message} (${i})`),n}}),getInterApplicationBusListener=(o,e)=>(n,i)=>__awaiter(void 0,void 0,void 0,function*(){n&&i.uuid!==fin.me.uuid&&(logger_1.logInfo(`Received security '${n}' via IAB on topic '${o}' from application '${i.uuid}' (${e})`),yield window_1.updateWindowContext(n,SOURCE_NAME))}),getGroupEventHandler=(i,o,e,t)=>n=>__awaiter(void 0,void 0,void 0,function*(){logger_1.logInfo(`Sending IAB message '${n}' on topic '${i}' to ${"*"===o?"all applications":`application '${o}'`}`);try{yield"*"===o?fin.InterApplicationBus.publish(i,n):fin.InterApplicationBus.send({uuid:o},i,n),null!=e&&e(n)}catch(n){null!=t&&t(n)}}); |
24
index.js
@@ -1,23 +0,1 @@ | ||
"use strict"; | ||
/** | ||
* OpenFin Bloomberg Integration | ||
* | ||
* @module | ||
*/ | ||
var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) { | ||
if (k2 === undefined) k2 = k; | ||
Object.defineProperty(o, k2, { enumerable: true, get: function() { return m[k]; } }); | ||
}) : (function(o, m, k, k2) { | ||
if (k2 === undefined) k2 = k; | ||
o[k2] = m[k]; | ||
})); | ||
var __exportStar = (this && this.__exportStar) || function(m, exports) { | ||
for (var p in m) if (p !== "default" && !Object.prototype.hasOwnProperty.call(exports, p)) __createBinding(exports, m, p); | ||
}; | ||
Object.defineProperty(exports, "__esModule", { value: true }); | ||
__exportStar(require("./common/types"), exports); | ||
__exportStar(require("./connection/connection"), exports); | ||
__exportStar(require("./errors/errors"), exports); | ||
__exportStar(require("./fdc3/fdc3"), exports); | ||
__exportStar(require("./iab/iab"), exports); | ||
__exportStar(require("./utils/utils"), exports); | ||
"use strict";var __createBinding=this&&this.__createBinding||(Object.create?function(e,r,t,o){void 0===o&&(o=t),Object.defineProperty(e,o,{enumerable:!0,get:function(){return r[t]}})}:function(e,r,t,o){e[o=void 0===o?t:o]=r[t]}),__exportStar=this&&this.__exportStar||function(e,r){for(var t in e)"default"===t||Object.prototype.hasOwnProperty.call(r,t)||__createBinding(r,e,t)};Object.defineProperty(exports,"__esModule",{value:!0}),__exportStar(require("./common/types"),exports),__exportStar(require("./connection/connection"),exports),__exportStar(require("./errors/errors"),exports),__exportStar(require("./fdc3/fdc3"),exports),__exportStar(require("./iab/iab"),exports),__exportStar(require("./utils/utils"),exports); |
@@ -1,19 +0,1 @@ | ||
"use strict"; | ||
/* eslint-disable no-console */ | ||
Object.defineProperty(exports, "__esModule", { value: true }); | ||
exports.logWarning = exports.logInfo = void 0; | ||
const logPrefix = '[OpenFin BBG API]'; | ||
/** | ||
* Writes a log message to console. | ||
* @param message Message to write to console. | ||
* @param optionalParams Optional parameters to pass to console.log. | ||
*/ | ||
const logInfo = (message, ...optionalParams) => console.log(`${logPrefix} ${message}`, ...optionalParams); | ||
exports.logInfo = logInfo; | ||
/** | ||
* Writes a warning message to console. | ||
* @param message Message to write to console. | ||
* @param optionalParams Optional parameters to pass to console.warn. | ||
*/ | ||
const logWarning = (message, ...optionalParams) => console.warn(`${logPrefix} ${message}`, ...optionalParams); | ||
exports.logWarning = logWarning; | ||
"use strict";Object.defineProperty(exports,"__esModule",{value:!0}),exports.logWarning=exports.logInfo=void 0;const logPrefix="[OpenFin BBG API]",logInfo=(o,...n)=>console.log(`${logPrefix} ${o}`,...n);exports.logInfo=logInfo;const logWarning=(o,...n)=>console.warn(`${logPrefix} ${o}`,...n);exports.logWarning=logWarning; |
@@ -5,3 +5,3 @@ { | ||
"author": "OpenFin Inc.", | ||
"version": "0.1.0", | ||
"version": "0.1.1", | ||
"license": "MIT", | ||
@@ -8,0 +8,0 @@ "main": "index.js", |
@@ -233,3 +233,3 @@ # OpenFin Bloomberg Integration | ||
```js | ||
import { terminal } from '@openfin/bloomberg'; | ||
import { terminal } from '@openfin/bloomberg/terminal'; | ||
@@ -236,0 +236,0 @@ // Update Terminal panel 1 to DIS 7 sell ticket 2mm @ 102 |
@@ -0,0 +0,0 @@ /** |
@@ -1,13 +0,1 @@ | ||
"use strict"; | ||
var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) { | ||
if (k2 === undefined) k2 = k; | ||
Object.defineProperty(o, k2, { enumerable: true, get: function() { return m[k]; } }); | ||
}) : (function(o, m, k, k2) { | ||
if (k2 === undefined) k2 = k; | ||
o[k2] = m[k]; | ||
})); | ||
var __exportStar = (this && this.__exportStar) || function(m, exports) { | ||
for (var p in m) if (p !== "default" && !Object.prototype.hasOwnProperty.call(exports, p)) __createBinding(exports, m, p); | ||
}; | ||
Object.defineProperty(exports, "__esModule", { value: true }); | ||
__exportStar(require("./bb-apps-terminal"), exports); | ||
"use strict";var __createBinding=this&&this.__createBinding||(Object.create?function(e,t,r,i){void 0===i&&(i=r),Object.defineProperty(e,i,{enumerable:!0,get:function(){return t[r]}})}:function(e,t,r,i){e[i=void 0===i?r:i]=t[r]}),__exportStar=this&&this.__exportStar||function(e,t){for(var r in e)"default"===r||Object.prototype.hasOwnProperty.call(t,r)||__createBinding(t,e,r)};Object.defineProperty(exports,"__esModule",{value:!0}),__exportStar(require("./bb-apps-terminal"),exports); |
@@ -1,197 +0,1 @@ | ||
"use strict"; | ||
var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) { | ||
function adopt(value) { return value instanceof P ? value : new P(function (resolve) { resolve(value); }); } | ||
return new (P || (P = Promise))(function (resolve, reject) { | ||
function fulfilled(value) { try { step(generator.next(value)); } catch (e) { reject(e); } } | ||
function rejected(value) { try { step(generator["throw"](value)); } catch (e) { reject(e); } } | ||
function step(result) { result.done ? resolve(result.value) : adopt(result.value).then(fulfilled, rejected); } | ||
step((generator = generator.apply(thisArg, _arguments || [])).next()); | ||
}); | ||
}; | ||
Object.defineProperty(exports, "__esModule", { value: true }); | ||
exports.isIsin = exports.isInstrumentContext = exports.isFigi = exports.isEquity = exports.isCusip = exports.isBloombergTerminalReady = exports.getSecurityStringFromParts = exports.getInstrumentContextFromSecurity = exports.getInstrumentCodeFromSecurity = void 0; | ||
const errors_1 = require("../errors/errors"); | ||
const logger_1 = require("../logger/logger"); | ||
const bb_apps_terminal_1 = require("../terminal/bb-apps-terminal"); | ||
/** | ||
* Gets the instrument code portion of a Bloomberg security. | ||
* | ||
* ```ts | ||
* // Returns '25468PBW5' | ||
* getInstrumentCodeFromSecurity('25468PBW5 Corp'); | ||
* ``` | ||
* @param security Bloomberg security to extract instrument code from. | ||
*/ | ||
const getInstrumentCodeFromSecurity = (security) => { | ||
var _a; | ||
if (!security) { | ||
return; | ||
} | ||
return ((_a = security.match(/^\w+/)) !== null && _a !== void 0 ? _a : [])[0]; | ||
}; | ||
exports.getInstrumentCodeFromSecurity = getInstrumentCodeFromSecurity; | ||
/** | ||
* Gets an [FDC3 instrument context](https://cdn.openfin.co/docs/services/fdc3/stable/api/interfaces/contexts.instrumentcontext.html) | ||
* object from a Bloomberg security string. | ||
* | ||
* ```ts | ||
* // Returns an instrument context object with BBG and CUSIP codes | ||
* getInstrumentContextFromSecurity('25468PBW5 Corp'); | ||
* ``` | ||
* @param security Bloomberg security string to get a context object from. | ||
*/ | ||
const getInstrumentContextFromSecurity = (security) => { | ||
const context = { | ||
type: 'fdc3.instrument', | ||
id: { | ||
BBG: security, | ||
}, | ||
}; | ||
const code = exports.getInstrumentCodeFromSecurity(security); | ||
switch (true) { | ||
case exports.isCusip(code): | ||
context.id.CUSIP = code; | ||
break; | ||
case exports.isFigi(code): | ||
context.id.FIGI = code; | ||
break; | ||
case exports.isIsin(code): | ||
context.id.ISIN = code; | ||
break; | ||
case exports.isEquity(security): | ||
context.id.ticker = code; | ||
break; | ||
default: | ||
} | ||
return context; | ||
}; | ||
exports.getInstrumentContextFromSecurity = getInstrumentContextFromSecurity; | ||
/** | ||
* Creates a Bloomberg security string from it's constituent parts. | ||
* | ||
* ```ts | ||
* // Returns 'TSLA US Equity' | ||
* getSecurityStringFromParts('TSLA', 'US'); | ||
* | ||
* // Returns 'GBPUSD Curncy' | ||
* getSecurityStringFromParts('GBPUSD', null, 'Curncy'); | ||
* ``` | ||
* @param instrumentCode Instrument code/ticker of security. | ||
* @param exchangeCode Exchange code of security. Defaults to 'US'. | ||
* @param sector Sector of security. Defaults to 'Equity'. | ||
*/ | ||
const getSecurityStringFromParts = (instrumentCode, exchangeCode, sector = 'Equity') => { | ||
if ((instrumentCode !== null && instrumentCode !== void 0 ? instrumentCode : undefined) === undefined) { | ||
return; | ||
} | ||
return !exchangeCode ? `${instrumentCode} ${sector}` : `${instrumentCode} ${exchangeCode} ${sector}`; | ||
}; | ||
exports.getSecurityStringFromParts = getSecurityStringFromParts; | ||
/** | ||
* Determines if the local Bloomberg Terminal service is ready for API calls. | ||
*/ | ||
const isBloombergTerminalReady = () => __awaiter(void 0, void 0, void 0, function* () { | ||
try { | ||
yield bb_apps_terminal_1.terminal.getAllGroups(); | ||
return true; | ||
} | ||
catch (err) { | ||
const error = errors_1.getApiErrorFromError(err); | ||
logger_1.logWarning(`Bloomberg Terminal not ready: ${error === null || error === void 0 ? void 0 : error.message}`); | ||
return false; | ||
} | ||
}); | ||
exports.isBloombergTerminalReady = isBloombergTerminalReady; | ||
/** | ||
* Determines if the provided text is a [CUSIP](https://www.cusip.com/cusip/index.htm). | ||
* | ||
* ```ts | ||
* // Returns true | ||
* isCusip('25468PBW5'); | ||
* | ||
* // Returns false | ||
* isCusip('BBG00005J747'); | ||
* ``` | ||
* @param text String to check. | ||
*/ | ||
const isCusip = (text) => { | ||
return !text ? false : /^([A-Z0-9]{5})([A-Z0-9*@#]{3})(\d)$/i.test(text); | ||
}; | ||
exports.isCusip = isCusip; | ||
/** | ||
* Determines if a Bloomberg security is an equity. | ||
* | ||
* ```ts | ||
* // Returns true | ||
* isEquity('TSLA US Equity'); | ||
* | ||
* // Returns false | ||
* isEquity('GBPUSD Curncy'); | ||
* ``` | ||
* @param security Bloomberg security to check. | ||
*/ | ||
const isEquity = (security) => { | ||
return !security ? false : /\b(EQUITY)$/i.test(security); | ||
}; | ||
exports.isEquity = isEquity; | ||
/** | ||
* Determines if the provided text is a [FIGI](https://www.openfigi.com/about/figi). | ||
* | ||
* ```ts | ||
* // Returns true | ||
* isFigi('BBG00005J747'); | ||
* | ||
* // Returns false | ||
* isFigi('US25468PBW59'); | ||
* ``` | ||
* @param text String to check. | ||
*/ | ||
const isFigi = (text) => { | ||
return !text ? false : /^(?!B[SM]|G[GBH]|KY|VG)([A-Z]{2})(G)(((?![AEIOU_])\w){8})(\d)$/i.test(text); | ||
}; | ||
exports.isFigi = isFigi; | ||
/** | ||
* Confirms whether or not an FDC3 context object is an instrument context. | ||
* | ||
* ```ts | ||
* const context1 = { | ||
* type: 'fdc3.instrument', | ||
* id: { | ||
* ticker: 'TSLA', | ||
* }, | ||
* }; | ||
* // Returns true | ||
* isInstrumentContext(context1); | ||
* | ||
* const context2 = { | ||
* type: 'fdc3.contact', | ||
* name: 'Jane Doe', | ||
* id: { | ||
* email: 'jane@doe.com', | ||
* }, | ||
* }; | ||
* // Returns false | ||
* isInstrumentContext(context2); | ||
* ``` | ||
* @param context FDC3 context object to check. | ||
*/ | ||
const isInstrumentContext = (context) => { | ||
return (context === null || context === void 0 ? void 0 : context.type) === 'fdc3.instrument'; | ||
}; | ||
exports.isInstrumentContext = isInstrumentContext; | ||
/** | ||
* Determines if the provided text is an [ISIN](https://www.isin.org/isin/). | ||
* | ||
* ```ts | ||
* // Returns true | ||
* isIsin('US25468PBW59'); | ||
* | ||
* // Returns false | ||
* isIsin('BBG00005J747'); | ||
* ``` | ||
* @param text String to check. | ||
*/ | ||
const isIsin = (text) => { | ||
return !text ? false : /^([A-Z]{2})([A-Z0-9]{9})(\d)$/i.test(text); | ||
}; | ||
exports.isIsin = isIsin; | ||
"use strict";var __awaiter=this&&this.__awaiter||function(t,n,u,a){return new(u=u||Promise)(function(r,e){function i(t){try{o(a.next(t))}catch(t){e(t)}}function s(t){try{o(a.throw(t))}catch(t){e(t)}}function o(t){var e;t.done?r(t.value):((e=t.value)instanceof u?e:new u(function(t){t(e)})).then(i,s)}o((a=a.apply(t,n||[])).next())})};Object.defineProperty(exports,"__esModule",{value:!0}),exports.isIsin=exports.isInstrumentContext=exports.isFigi=exports.isEquity=exports.isCusip=exports.isBloombergTerminalReady=exports.getSecurityStringFromParts=exports.getInstrumentContextFromSecurity=exports.getInstrumentCodeFromSecurity=void 0;const errors_1=require("../errors/errors"),logger_1=require("../logger/logger"),bb_apps_terminal_1=require("../terminal/bb-apps-terminal"),getInstrumentCodeFromSecurity=t=>{if(t)return(null!==(t=t.match(/^\w+/))&&void 0!==t?t:[])[0]};exports.getInstrumentCodeFromSecurity=getInstrumentCodeFromSecurity;const getInstrumentContextFromSecurity=t=>{const e={type:"fdc3.instrument",id:{BBG:t}};var r=exports.getInstrumentCodeFromSecurity(t);switch(!0){case exports.isCusip(r):e.id.CUSIP=r;break;case exports.isFigi(r):e.id.FIGI=r;break;case exports.isIsin(r):e.id.ISIN=r;break;case exports.isEquity(t):e.id.ticker=r}return e};exports.getInstrumentContextFromSecurity=getInstrumentContextFromSecurity;const getSecurityStringFromParts=(t,e,r="Equity")=>{if(void 0!==(null!=t?t:void 0))return e?`${t} ${e} ${r}`:`${t} ${r}`};exports.getSecurityStringFromParts=getSecurityStringFromParts;const isBloombergTerminalReady=()=>__awaiter(void 0,void 0,void 0,function*(){try{return yield bb_apps_terminal_1.terminal.getAllGroups(),!0}catch(t){var e=errors_1.getApiErrorFromError(t);return logger_1.logWarning(`Bloomberg Terminal not ready: ${null==e?void 0:e.message}`),!1}});exports.isBloombergTerminalReady=isBloombergTerminalReady;const isCusip=t=>!!t&&/^([A-Z0-9]{5})([A-Z0-9*@#]{3})(\d)$/i.test(t);exports.isCusip=isCusip;const isEquity=t=>!!t&&/\b(EQUITY)$/i.test(t);exports.isEquity=isEquity;const isFigi=t=>!!t&&/^(?!B[SM]|G[GBH]|KY|VG)([A-Z]{2})(G)(((?![AEIOU_])\w){8})(\d)$/i.test(t);exports.isFigi=isFigi;const isInstrumentContext=t=>"fdc3.instrument"===(null==t?void 0:t.type);exports.isInstrumentContext=isInstrumentContext;const isIsin=t=>!!t&&/^([A-Z]{2})([A-Z0-9]{9})(\d)$/i.test(t);exports.isIsin=isIsin; |
@@ -1,1 +0,1 @@ | ||
0.1.0 | ||
0.1.1 |
@@ -1,170 +0,1 @@ | ||
"use strict"; | ||
var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) { | ||
function adopt(value) { return value instanceof P ? value : new P(function (resolve) { resolve(value); }); } | ||
return new (P || (P = Promise))(function (resolve, reject) { | ||
function fulfilled(value) { try { step(generator.next(value)); } catch (e) { reject(e); } } | ||
function rejected(value) { try { step(generator["throw"](value)); } catch (e) { reject(e); } } | ||
function step(result) { result.done ? resolve(result.value) : adopt(result.value).then(fulfilled, rejected); } | ||
step((generator = generator.apply(thisArg, _arguments || [])).next()); | ||
}); | ||
}; | ||
Object.defineProperty(exports, "__esModule", { value: true }); | ||
exports.updateWindowContext = exports.disconnectWindowContext = exports.connectWindowContext = exports.BLOOMBERG_GROUP_EVENT_MARKER = void 0; | ||
const connection_manager_1 = require("../connection-manager/connection-manager"); | ||
const errors_1 = require("../errors/errors"); | ||
const logger_1 = require("../logger/logger"); | ||
const bb_apps_terminal_1 = require("../terminal/bb-apps-terminal"); | ||
const utils_1 = require("../utils/utils"); | ||
exports.BLOOMBERG_GROUP_EVENT_MARKER = 'OF_BBG_API'; | ||
/** | ||
* Connects Bloomberg Terminal panels and Launchpad groups with OpenFin window context. | ||
* | ||
* Ensure that listeners are cleaned up by calling {@link disconnectWindowContext}. | ||
* @param type Type of connection. | ||
* @param source Bloomberg Launchpad group that triggers window context to be updated whenever the group security is changed. | ||
* Specify all groups by passing '*'. | ||
* @param target Bloomberg Terminal panel or Launchpad group whose security will be updated whenever window context is changed. Update | ||
* all groups by passing '*'. | ||
* @param onGroupEvent Callback that is run whenever group specified in source is updated. | ||
* @param onContextChanged Callback that is run whenever window context changes. | ||
* @param onError Callback that is run if an error occurs. | ||
*/ | ||
const connectWindowContext = (type, source, target, onGroupEvent, onContextChanged, onError) => __awaiter(void 0, void 0, void 0, function* () { | ||
// Check if terminal is ready before creating the connection | ||
const terminalReady = yield utils_1.isBloombergTerminalReady(); | ||
if (!terminalReady) { | ||
throw new errors_1.TerminalConnectionError(); | ||
} | ||
let groupSubscriptionId; | ||
if ((source !== null && source !== void 0 ? source : undefined) !== undefined && (onGroupEvent !== null && onGroupEvent !== void 0 ? onGroupEvent : undefined) !== undefined) { | ||
groupSubscriptionId = yield bb_apps_terminal_1.terminal.subscribeGroupEvents(getBloombergGroupEventHander(source, onGroupEvent, onError)); | ||
} | ||
const currentWindow = yield fin.Window.getCurrent(); | ||
const contextListener = getWindowContextListener(type, target, onContextChanged, onError); | ||
yield currentWindow.addListener('context-changed', contextListener); | ||
const connectionId = connection_manager_1.addConnection(contextListener, groupSubscriptionId); | ||
return connection_manager_1.getConnectionById(connectionId); | ||
}); | ||
exports.connectWindowContext = connectWindowContext; | ||
/** | ||
* Closes an existing connection between Bloomberg and window context. | ||
* @param id ID for identifying the connection to disconnect. | ||
*/ | ||
const disconnectWindowContext = (id) => __awaiter(void 0, void 0, void 0, function* () { | ||
const connection = connection_manager_1.getConnectionById(id); | ||
if ((connection !== null && connection !== void 0 ? connection : undefined) === undefined) { | ||
return; | ||
} | ||
if (connection.bbgSubId !== undefined) { | ||
yield bb_apps_terminal_1.terminal.unsubscribeGroupEvents(connection.bbgSubId); | ||
} | ||
const currentWindow = yield fin.Window.getCurrent(); | ||
yield currentWindow.removeListener('context-changed', connection.windowContextListener); | ||
connection_manager_1.removeConnection(id); | ||
}); | ||
exports.disconnectWindowContext = disconnectWindowContext; | ||
/** | ||
* Gets an event handler that will be run whenever a Bloomberg Launchpad group's security is changed. | ||
* @param bloombergGroup Name of the Bloomberg Launchpad group that will trigger the event handler. | ||
* @param onGroupEvent Callback that is run whenever the target Bloomberg Launchpad group's security is | ||
* changed. | ||
* @param onError Callback that is run if an error occurs. | ||
*/ | ||
const getBloombergGroupEventHander = (bloombergGroup, onGroupEvent, onError) => (group, cookie) => __awaiter(void 0, void 0, void 0, function* () { | ||
var _a; | ||
if (((_a = group === null || group === void 0 ? void 0 : group.name) !== null && _a !== void 0 ? _a : undefined) === undefined) { | ||
onError === null || onError === void 0 ? void 0 : onError(new errors_1.BloombergApiError(undefined, 'Group event source is undefined')); | ||
return; | ||
} | ||
if ((bloombergGroup !== '*' && group.name !== bloombergGroup) || cookie === exports.BLOOMBERG_GROUP_EVENT_MARKER) { | ||
return; | ||
} | ||
try { | ||
const security = yield group.getCachedSecurity(); | ||
logger_1.logInfo(`Received security '${security}' from group ${group.name}`); | ||
yield exports.updateWindowContext(security, 'BBG'); | ||
onGroupEvent === null || onGroupEvent === void 0 ? void 0 : onGroupEvent(security); | ||
} | ||
catch (err) { | ||
const error = errors_1.getApiErrorFromError(err); | ||
onError === null || onError === void 0 ? void 0 : onError(error); | ||
} | ||
}); | ||
/** | ||
* Gets a window context listener that will be run whenever window context changes. | ||
* @param target Bloomberg Terminal panel or Launchpad group whose security will be updated when window context is | ||
* updated. | ||
* @param type Type of connection. | ||
* @param onContextChanged Callback that is run whenever window context changes. | ||
* @param onError Callback that is run if an error occurs. | ||
*/ | ||
const getWindowContextListener = (type, target, onContextChanged, onError) => (data) => __awaiter(void 0, void 0, void 0, function* () { | ||
var _b; | ||
const context = (_b = data === null || data === void 0 ? void 0 : data.context) === null || _b === void 0 ? void 0 : _b.bbgContext; | ||
if ((context !== null && context !== void 0 ? context : undefined) === undefined) { | ||
// No context data found | ||
return; | ||
} | ||
if ((context === null || context === void 0 ? void 0 : context.source) !== type) { | ||
// Not this connection type | ||
return; | ||
} | ||
const security = context.security; | ||
if (!security) { | ||
logger_1.logInfo('Security not set, ignoring'); | ||
return; | ||
} | ||
try { | ||
if ((target !== null && target !== void 0 ? target : undefined) !== undefined) { | ||
yield updateTargetSecurityInBloomberg(security, target); | ||
} | ||
onContextChanged === null || onContextChanged === void 0 ? void 0 : onContextChanged(security); | ||
} | ||
catch (err) { | ||
const error = errors_1.getApiErrorFromError(err); | ||
onError === null || onError === void 0 ? void 0 : onError(error); | ||
} | ||
}); | ||
/** | ||
* Updates the security for a Bloomberg Terminal panel or Launchpad group. | ||
* @param security The Bloomberg security string to update target with. | ||
* @param target The Bloomberg Terminal panel or Launchpad group to update. | ||
*/ | ||
const updateTargetSecurityInBloomberg = (security, target) => __awaiter(void 0, void 0, void 0, function* () { | ||
if (!security) { | ||
return; | ||
} | ||
logger_1.logInfo(`Setting ${typeof target === 'string' ? (target === '*' ? 'every group' : `group ${target}`) : `panel ${target}`} security to '${security}'`); | ||
if (typeof target === 'string') { | ||
if (target === '*') { | ||
const groups = yield bb_apps_terminal_1.terminal.getAllGroups(); | ||
yield Promise.all(groups.map((group) => group.setSecurity(security, exports.BLOOMBERG_GROUP_EVENT_MARKER))); | ||
} | ||
else { | ||
const group = yield bb_apps_terminal_1.terminal.getGroup(target); | ||
yield group.setSecurity(security, exports.BLOOMBERG_GROUP_EVENT_MARKER); | ||
} | ||
} | ||
else { | ||
yield bb_apps_terminal_1.terminal.runFunction('DES', target, security); | ||
} | ||
}); | ||
/** | ||
* Updates window context with the provided security. | ||
* @param security The Bloomberg security string to update context to. | ||
* @param source The connection type making the update. | ||
*/ | ||
const updateWindowContext = (security, source) => __awaiter(void 0, void 0, void 0, function* () { | ||
if (!security) { | ||
return; | ||
} | ||
const platform = yield fin.Platform.getCurrent(); | ||
const newWindowContext = { | ||
bbgContext: { | ||
security, | ||
source, | ||
}, | ||
}; | ||
yield platform.setWindowContext(newWindowContext); | ||
}); | ||
exports.updateWindowContext = updateWindowContext; | ||
"use strict";var __awaiter=this&&this.__awaiter||function(e,d,l,a){return new(l=l||Promise)(function(o,n){function t(e){try{r(a.next(e))}catch(e){n(e)}}function i(e){try{r(a.throw(e))}catch(e){n(e)}}function r(e){var n;e.done?o(e.value):((n=e.value)instanceof l?n:new l(function(e){e(n)})).then(t,i)}r((a=a.apply(e,d||[])).next())})};Object.defineProperty(exports,"__esModule",{value:!0}),exports.updateWindowContext=exports.disconnectWindowContext=exports.connectWindowContext=exports.BLOOMBERG_GROUP_EVENT_MARKER=void 0;const connection_manager_1=require("../connection-manager/connection-manager"),errors_1=require("../errors/errors"),logger_1=require("../logger/logger"),bb_apps_terminal_1=require("../terminal/bb-apps-terminal"),utils_1=require("../utils/utils");exports.BLOOMBERG_GROUP_EVENT_MARKER="OF_BBG_API";const connectWindowContext=(t,i,r,d,l,a)=>__awaiter(void 0,void 0,void 0,function*(){if(!(yield utils_1.isBloombergTerminalReady()))throw new errors_1.TerminalConnectionError;let e;void 0!==(null!=i?i:void 0)&&void 0!==(null!=d?d:void 0)&&(e=yield bb_apps_terminal_1.terminal.subscribeGroupEvents(getBloombergGroupEventHander(i,d,a)));const n=yield fin.Window.getCurrent();var o=getWindowContextListener(t,r,l,a);yield n.addListener("context-changed",o);o=connection_manager_1.addConnection(o,e);return connection_manager_1.getConnectionById(o)});exports.connectWindowContext=connectWindowContext;const disconnectWindowContext=o=>__awaiter(void 0,void 0,void 0,function*(){var e=connection_manager_1.getConnectionById(o);if(void 0!==(null!=e?e:void 0)){void 0!==e.bbgSubId&&(yield bb_apps_terminal_1.terminal.unsubscribeGroupEvents(e.bbgSubId));const n=yield fin.Window.getCurrent();yield n.removeListener("context-changed",e.windowContextListener),connection_manager_1.removeConnection(o)}});exports.disconnectWindowContext=disconnectWindowContext;const getBloombergGroupEventHander=(i,r,d)=>(o,t)=>__awaiter(void 0,void 0,void 0,function*(){var e;if(void 0!==(null!==(e=null==o?void 0:o.name)&&void 0!==e?e:void 0)){if(("*"===i||o.name===i)&&t!==exports.BLOOMBERG_GROUP_EVENT_MARKER)try{var n=yield o.getCachedSecurity();logger_1.logInfo(`Received security '${n}' from group ${o.name}`),yield exports.updateWindowContext(n,"BBG"),null!=r&&r(n)}catch(e){n=errors_1.getApiErrorFromError(e);null!=d&&d(n)}}else null!=d&&d(new errors_1.BloombergApiError(void 0,"Group event source is undefined"))}),getWindowContextListener=(o,t,i,r)=>e=>__awaiter(void 0,void 0,void 0,function*(){var n=null===(n=null==e?void 0:e.context)||void 0===n?void 0:n.bbgContext;if(void 0!==(null!=n?n:void 0)&&(null==n?void 0:n.source)===o){n=n.security;if(n)try{void 0!==(null!=t?t:void 0)&&(yield updateTargetSecurityInBloomberg(n,t)),null!=i&&i(n)}catch(e){n=errors_1.getApiErrorFromError(e);null!=r&&r(n)}else logger_1.logInfo("Security not set, ignoring")}}),updateTargetSecurityInBloomberg=(o,t)=>__awaiter(void 0,void 0,void 0,function*(){if(o)if(logger_1.logInfo(`Setting ${"string"==typeof t?"*"===t?"every group":`group ${t}`:`panel ${t}`} security to '${o}'`),"string"==typeof t)if("*"===t){const e=yield bb_apps_terminal_1.terminal.getAllGroups();yield Promise.all(e.map(e=>e.setSecurity(o,exports.BLOOMBERG_GROUP_EVENT_MARKER)))}else{const n=yield bb_apps_terminal_1.terminal.getGroup(t);yield n.setSecurity(o,exports.BLOOMBERG_GROUP_EVENT_MARKER)}else yield bb_apps_terminal_1.terminal.runFunction("DES",t,o)}),updateWindowContext=(n,o)=>__awaiter(void 0,void 0,void 0,function*(){if(n){const e=yield fin.Platform.getCurrent();yield e.setWindowContext({bbgContext:{security:n,source:o}})}});exports.updateWindowContext=updateWindowContext; |
New author
Supply chain riskA new npm collaborator published a version of the package for the first time. New collaborators are usually benign additions to a project, but do indicate a change to the security surface area of a package.
Found 1 instance in 1 package
Minified code
QualityThis package contains minified code. This may be harmless in some cases where minified code is included in packaged libraries, however packages on npm should not minify code.
Found 1 instance in 1 package
75452
1048
9
1