Comparing version 1.0.0 to 2.0.0
@@ -0,8 +1,11 @@ | ||
/// <reference types="ws" /> | ||
import { Filter, News } from "./types"; | ||
import { CloseEvent, ErrorEvent } from "isomorphic-ws"; | ||
import { ErrorEvent, CloseEvent } from "isomorphic-ws"; | ||
export declare class Api { | ||
private apikey; | ||
private host; | ||
private socket?; | ||
constructor(apikey: string, host?: string); | ||
subscribe: (filter: Filter, callback: (news: News) => void, errorCallback?: ((errorEvent: ErrorEvent) => void) | undefined, closeCallback?: ((closeEvent: CloseEvent) => void) | undefined) => void; | ||
subscribe(filter: Filter, callback: (news: News) => void, errorCallback?: (errorEvent: ErrorEvent) => void, openCallback?: () => void, closeCallback?: (closeEvent: CloseEvent) => void): void; | ||
unsubscribe(): void; | ||
} |
"use strict"; | ||
var __importDefault = (this && this.__importDefault) || function (mod) { | ||
return (mod && mod.__esModule) ? mod : { "default": mod }; | ||
}; | ||
Object.defineProperty(exports, "__esModule", { value: true }); | ||
exports.Api = void 0; | ||
const types_1 = require("./types"); | ||
const isomorphic_ws_1 = require("isomorphic-ws"); | ||
const isomorphic_ws_1 = __importDefault(require("isomorphic-ws")); | ||
class Api { | ||
@@ -10,28 +13,45 @@ constructor(apikey, host = types_1.ApiHost.Production) { | ||
this.host = host; | ||
this.subscribe = (filter, callback, errorCallback, closeCallback) => { | ||
const urlParams = new URLSearchParams({ | ||
apikey: this.apikey, | ||
filter: JSON.stringify(filter) | ||
}); | ||
console.log(urlParams); | ||
const socket = new isomorphic_ws_1.WebSocket(`${this.host}/v1/ws/news?${urlParams.toString()}`); | ||
socket.onmessage = (event) => { | ||
callback(JSON.parse(event.data.toString())); | ||
}; | ||
socket.onerror = (event) => { | ||
console.log("Websocket error: ", event); | ||
if (!errorCallback) | ||
return; | ||
else | ||
errorCallback(event); | ||
}; | ||
socket.onclose = (event) => { | ||
console.log("Connection closed"); | ||
if (closeCallback) | ||
closeCallback(event); | ||
}; | ||
} | ||
subscribe(filter, callback, errorCallback, openCallback, closeCallback) { | ||
const urlParams = new URLSearchParams({ | ||
apikey: this.apikey, | ||
filter: JSON.stringify(filter) | ||
}); | ||
this.socket = new isomorphic_ws_1.default(`${this.host}/v1/ws/news?${urlParams.toString()}`); | ||
this.socket.onmessage = (event) => { | ||
var _a; | ||
const response = JSON.parse(event.data.toString()); | ||
if (response.error && ((_a = this.socket) === null || _a === void 0 ? void 0 : _a.onerror)) { | ||
this.socket.onerror({ | ||
error: new Error(response.error.message), | ||
message: response.error.message, | ||
target: this.socket, | ||
type: "error" | ||
}); | ||
} | ||
else | ||
callback(response.data); | ||
}; | ||
this.socket.onerror = (event) => { | ||
var _a; | ||
if ((_a = event.message) === null || _a === void 0 ? void 0 : _a.includes('403')) { | ||
event = Object.assign(Object.assign({}, event), { message: "Not authorized, make sure your api key is correct and active" }); | ||
} | ||
if (errorCallback) | ||
errorCallback(event); | ||
}; | ||
this.socket.onopen = () => { | ||
if (openCallback) | ||
openCallback(); | ||
}; | ||
this.socket.onclose = (event) => { | ||
if (closeCallback) | ||
closeCallback(event); | ||
}; | ||
} | ||
unsubscribe() { | ||
this.socket.close(); | ||
} | ||
} | ||
exports.Api = Api; | ||
//# sourceMappingURL=api.js.map |
@@ -1,3 +0,3 @@ | ||
export { Or, And, Text } from "./queries"; | ||
export { or, and, text } from "./queries"; | ||
export { Api } from "./api"; | ||
export { News, Filter, TextQuery, ApiHost } from "./types"; | ||
export { News, Filter, TextOptions, ApiHost, Source } from "./types"; |
"use strict"; | ||
Object.defineProperty(exports, "__esModule", { value: true }); | ||
exports.ApiHost = exports.Api = exports.Text = exports.And = exports.Or = void 0; | ||
exports.Source = exports.ApiHost = exports.Api = exports.text = exports.and = exports.or = void 0; | ||
var queries_1 = require("./queries"); | ||
Object.defineProperty(exports, "Or", { enumerable: true, get: function () { return queries_1.Or; } }); | ||
Object.defineProperty(exports, "And", { enumerable: true, get: function () { return queries_1.And; } }); | ||
Object.defineProperty(exports, "Text", { enumerable: true, get: function () { return queries_1.Text; } }); | ||
Object.defineProperty(exports, "or", { enumerable: true, get: function () { return queries_1.or; } }); | ||
Object.defineProperty(exports, "and", { enumerable: true, get: function () { return queries_1.and; } }); | ||
Object.defineProperty(exports, "text", { enumerable: true, get: function () { return queries_1.text; } }); | ||
var api_1 = require("./api"); | ||
@@ -12,2 +12,3 @@ Object.defineProperty(exports, "Api", { enumerable: true, get: function () { return api_1.Api; } }); | ||
Object.defineProperty(exports, "ApiHost", { enumerable: true, get: function () { return types_1.ApiHost; } }); | ||
Object.defineProperty(exports, "Source", { enumerable: true, get: function () { return types_1.Source; } }); | ||
//# sourceMappingURL=index.js.map |
@@ -1,16 +0,4 @@ | ||
import { Query, QueryDto, TextQuery } from "./types"; | ||
export declare class And implements Query { | ||
private value; | ||
constructor(value: Query[]); | ||
toJSON(): QueryDto; | ||
} | ||
export declare class Or implements Query { | ||
private value; | ||
constructor(value: Query[]); | ||
toJSON(): QueryDto; | ||
} | ||
export declare class Text implements Query { | ||
private readonly value; | ||
constructor(value: TextQuery); | ||
toJSON(): QueryDto; | ||
} | ||
import { Query, TextOptions } from "./types"; | ||
export declare const and: (...queries: Query[]) => Query; | ||
export declare const or: (...queries: Query[]) => Query; | ||
export declare const text: (text: string, options?: TextOptions) => Query; |
"use strict"; | ||
Object.defineProperty(exports, "__esModule", { value: true }); | ||
exports.Text = exports.Or = exports.And = void 0; | ||
exports.text = exports.or = exports.and = void 0; | ||
const types_1 = require("./types"); | ||
const and = (...queries) => { | ||
return new And(queries); | ||
}; | ||
exports.and = and; | ||
const or = (...queries) => { | ||
return new Or(queries); | ||
}; | ||
exports.or = or; | ||
const text = (text, options) => { | ||
return new Text(Object.assign({ text }, options)); | ||
}; | ||
exports.text = text; | ||
class And { | ||
@@ -16,3 +28,2 @@ constructor(value) { | ||
} | ||
exports.And = And; | ||
class Or { | ||
@@ -29,3 +40,2 @@ constructor(value) { | ||
} | ||
exports.Or = Or; | ||
class Text { | ||
@@ -43,3 +53,2 @@ constructor(value) { | ||
} | ||
exports.Text = Text; | ||
const textQueryDefaults = { | ||
@@ -46,0 +55,0 @@ ignore: false, |
export interface Filter { | ||
query?: Query; | ||
tickers?: string[]; | ||
sources?: Source[]; | ||
} | ||
export interface Response { | ||
error: ResponseError; | ||
data: News; | ||
} | ||
export interface ResponseError { | ||
code: number; | ||
message: string; | ||
} | ||
export interface News { | ||
@@ -15,4 +24,6 @@ id: string; | ||
} | ||
export interface TextQuery { | ||
export interface TextQuery extends TextOptions { | ||
text: string; | ||
} | ||
export interface TextOptions { | ||
searchBody?: boolean; | ||
@@ -42,1 +53,8 @@ searchHeadline?: boolean; | ||
} | ||
export declare enum Source { | ||
DowJones = "DJ", | ||
AccessWire = "AR", | ||
GlobeNewswire = "PZ", | ||
PRNewswire = "PN", | ||
BusinessWire = "BW" | ||
} |
"use strict"; | ||
Object.defineProperty(exports, "__esModule", { value: true }); | ||
exports.ApiHost = exports.QueryType = void 0; | ||
exports.Source = exports.ApiHost = exports.QueryType = void 0; | ||
var QueryType; | ||
@@ -15,2 +15,10 @@ (function (QueryType) { | ||
})(ApiHost || (exports.ApiHost = ApiHost = {})); | ||
var Source; | ||
(function (Source) { | ||
Source["DowJones"] = "DJ"; | ||
Source["AccessWire"] = "AR"; | ||
Source["GlobeNewswire"] = "PZ"; | ||
Source["PRNewswire"] = "PN"; | ||
Source["BusinessWire"] = "BW"; | ||
})(Source || (exports.Source = Source = {})); | ||
//# sourceMappingURL=types.js.map |
{ | ||
"name": "newsware", | ||
"version": "1.0.0", | ||
"version": "2.0.0", | ||
"description": "Typescript client for interacting with the Newsware API", | ||
@@ -40,5 +40,4 @@ "main": "lib/index.js", | ||
"dependencies": { | ||
"isomorphic-ws": "^5.0.0", | ||
"ws": "^8.13.0" | ||
"isomorphic-ws": "^5.0.0" | ||
} | ||
} |
@@ -1,5 +0,7 @@ | ||
import {ApiHost, Filter, News} from "./types"; | ||
import {CloseEvent, ErrorEvent, MessageEvent, WebSocket as IsoWebsocket} from "isomorphic-ws" | ||
import {ApiHost, Filter, News, Response} from "./types"; | ||
import WebSocket, {MessageEvent, ErrorEvent, CloseEvent} from "isomorphic-ws" | ||
export class Api { | ||
private socket?: WebSocket | ||
constructor( | ||
@@ -11,8 +13,9 @@ private apikey: string, | ||
subscribe = ( | ||
subscribe ( | ||
filter: Filter, | ||
callback: (news: News) => void, | ||
errorCallback?: (errorEvent: ErrorEvent) => void, | ||
openCallback?: () => void, | ||
closeCallback?: (closeEvent: CloseEvent) => void | ||
) => { | ||
) { | ||
const urlParams = new URLSearchParams({ | ||
@@ -22,20 +25,37 @@ apikey: this.apikey, | ||
}) | ||
console.log(urlParams) | ||
const socket = new IsoWebsocket(`${this.host}/v1/ws/news?${urlParams.toString()}`) | ||
this.socket = new WebSocket(`${this.host}/v1/ws/news?${urlParams.toString()}`) | ||
socket.onmessage = (event: MessageEvent) => { | ||
callback(JSON.parse(event.data.toString()) as News) | ||
this.socket.onmessage = (event: MessageEvent) => { | ||
const response = JSON.parse(event.data.toString()) as Response | ||
if (response.error && this.socket?.onerror) { | ||
this.socket.onerror({ | ||
error: new Error(response.error.message), | ||
message: response.error.message, | ||
target: this.socket, | ||
type: "error" | ||
}) | ||
} else | ||
callback(response.data) | ||
} | ||
socket.onerror = (event: ErrorEvent) => { | ||
console.log("Websocket error: ", event) | ||
if (!errorCallback) return | ||
else errorCallback(event) | ||
this.socket.onerror = (event: ErrorEvent) => { | ||
if (event.message?.includes('403')) { | ||
event = {... event, message: "Not authorized, make sure your api key is correct and active"} | ||
} | ||
if (errorCallback) errorCallback(event) | ||
} | ||
socket.onclose = (event: CloseEvent) => { | ||
console.log("Connection closed") | ||
this.socket.onopen = () => { | ||
if (openCallback) openCallback() | ||
} | ||
this.socket.onclose = (event: CloseEvent) => { | ||
if (closeCallback) closeCallback(event) | ||
} | ||
} | ||
unsubscribe() { | ||
this.socket!!.close() | ||
} | ||
} |
@@ -1,3 +0,3 @@ | ||
export {Or, And, Text} from "./queries"; | ||
export {or, and, text} from "./queries"; | ||
export {Api} from "./api" | ||
export {News, Filter, TextQuery, ApiHost} from "./types" | ||
export {News, Filter, TextOptions, ApiHost, Source} from "./types" |
@@ -1,4 +0,16 @@ | ||
import {Query, QueryDto, QueryType, TextQuery} from "./types"; | ||
import {Query, QueryDto, QueryType, TextOptions, TextQuery} from "./types"; | ||
export class And implements Query { | ||
export const and = (...queries: Query[]): Query => { | ||
return new And(queries) | ||
} | ||
export const or = (...queries: Query[]): Query => { | ||
return new Or(queries) | ||
} | ||
export const text = (text: string, options?: TextOptions): Query => { | ||
return new Text({text, ...options}) | ||
} | ||
class And implements Query { | ||
constructor( | ||
@@ -17,3 +29,3 @@ private value: Query[] | ||
export class Or implements Query { | ||
class Or implements Query { | ||
constructor(private value: Query[]) { | ||
@@ -30,7 +42,7 @@ } | ||
export class Text implements Query { | ||
class Text implements Query { | ||
constructor( | ||
private readonly value: TextQuery | ||
) { | ||
this.value = {... textQueryDefaults, ... this.value} | ||
this.value = {...textQueryDefaults, ...this.value} | ||
} | ||
@@ -37,0 +49,0 @@ |
export interface Filter { | ||
query?: Query | ||
tickers?: string[] | ||
sources?: Source[] | ||
} | ||
export interface Response { | ||
error: ResponseError; | ||
data: News; | ||
} | ||
export interface ResponseError { | ||
code: number; | ||
message: string; | ||
} | ||
export interface News { | ||
@@ -17,4 +28,7 @@ id: string; | ||
export interface TextQuery { | ||
text: string, | ||
export interface TextQuery extends TextOptions{ | ||
text: string | ||
} | ||
export interface TextOptions { | ||
searchBody?: boolean // defaults to true | ||
@@ -48,2 +62,10 @@ searchHeadline?: boolean // defaults to true | ||
Production = "wss://newswareapi.encypherstudio.com" | ||
} | ||
export enum Source { | ||
DowJones = "DJ", | ||
AccessWire = "AR", | ||
GlobeNewswire = "PZ", | ||
PRNewswire = "PN", | ||
BusinessWire = "BW" | ||
} |
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
18485
1
27
417
- Removedws@^8.13.0