New Case Study:See how Anthropic automated 95% of dependency reviews with Socket.Learn More
Socket
Sign inDemoInstall
Socket

newsware

Package Overview
Dependencies
Maintainers
1
Versions
73
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

newsware - npm Package Compare versions

Comparing version 4.1.1 to 5.0.0-beta.0

lib/src/enums.d.ts

8

lib/src/api.d.ts

@@ -1,13 +0,11 @@

import { HistoricalFilter, News, SubscribeOptions, EndpointDescription } from "./types";
import { ConnectOptions, EndpointDescription, HistoricalFilter, News } from "./types";
import { WsClient } from "./wsclient";
export declare class Api {
private apikey;
private socket?;
private subscribed;
websocketEndpoint: string;
restEndpoint: string;
constructor(apikey: string, endpoint?: EndpointDescription);
subscribe(options: SubscribeOptions): void;
unsubscribe(): void;
getWsClient(options: ConnectOptions): WsClient;
search(filter: HistoricalFilter): Promise<News[]>;
post<T, Z>(path: string, body: T): Promise<Z>;
}

@@ -16,57 +16,17 @@ "use strict";

exports.Api = void 0;
const types_1 = require("./types");
const enums_1 = require("./enums");
const isomorphic_ws_1 = __importDefault(require("isomorphic-ws"));
const wsclient_1 = require("./wsclient");
class Api {
constructor(apikey, endpoint = types_1.Endpoint.Production) {
constructor(apikey, endpoint = enums_1.Endpoint.PRODUCTION) {
this.apikey = apikey;
this.subscribed = false;
this.websocketEndpoint = endpoint.websocketProtocol + "://" + endpoint.host;
this.restEndpoint = endpoint.restProtocol + "://" + endpoint.host;
}
subscribe(options) {
if (options.automaticReconnect == undefined)
options.automaticReconnect = true;
getWsClient(options) {
const urlParams = new URLSearchParams({
apikey: this.apikey,
filter: JSON.stringify(options.filter)
});
this.socket = new isomorphic_ws_1.default(`${this.websocketEndpoint}/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
options.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 (options.errorCallback)
options.errorCallback(event);
};
this.socket.onopen = () => {
this.subscribed = true;
if (options.openCallback)
options.openCallback();
};
this.socket.onclose = (event) => {
if (options.closeCallback)
options.closeCallback(event);
if (this.subscribed && options.automaticReconnect)
setTimeout(() => this.subscribe(options), 1000);
};
return new wsclient_1.WsClient(new isomorphic_ws_1.default(`${this.websocketEndpoint}/v2/ws?${urlParams.toString()}`), options);
}
unsubscribe() {
this.subscribed = false;
this.socket.close();
}
search(filter) {

@@ -73,0 +33,0 @@ return __awaiter(this, void 0, void 0, function* () {

@@ -13,3 +13,3 @@ "use strict";

const api_1 = require("./api");
const types_1 = require("./types");
const enums_1 = require("./enums");
const chai_1 = require("chai");

@@ -24,3 +24,3 @@ describe("Api historical search", () => {

it("paginate", () => __awaiter(void 0, void 0, void 0, function* () {
const api = new api_1.Api(context.config.apikey, types_1.Endpoint.Localhost);
const api = new api_1.Api(context.config.apikey, enums_1.Endpoint.Localhost);
let actualNews = yield api.search({

@@ -49,3 +49,3 @@ pagination: {

it("published after", () => __awaiter(void 0, void 0, void 0, function* () {
const api = new api_1.Api(context.config.apikey, types_1.Endpoint.Localhost);
const api = new api_1.Api(context.config.apikey, enums_1.Endpoint.Localhost);
let actualNews = yield api.search({

@@ -65,3 +65,3 @@ publishedAfter: 3000

it("published before", () => __awaiter(void 0, void 0, void 0, function* () {
const api = new api_1.Api(context.config.apikey, types_1.Endpoint.Localhost);
const api = new api_1.Api(context.config.apikey, enums_1.Endpoint.Localhost);
let actualNews = yield api.search({

@@ -81,3 +81,3 @@ publishedBefore: 1000

it("published between", () => __awaiter(void 0, void 0, void 0, function* () {
const api = new api_1.Api(context.config.apikey, types_1.Endpoint.Localhost);
const api = new api_1.Api(context.config.apikey, enums_1.Endpoint.Localhost);
let actualNews = yield api.search({

@@ -105,3 +105,3 @@ publishedAfter: 1000,

it("by body", () => __awaiter(void 0, void 0, void 0, function* () {
const api = new api_1.Api(context.config.apikey, types_1.Endpoint.Localhost);
const api = new api_1.Api(context.config.apikey, enums_1.Endpoint.Localhost);
let actualNews = yield api.search({

@@ -136,3 +136,3 @@ query: {

it("by headline", () => __awaiter(void 0, void 0, void 0, function* () {
const api = new api_1.Api(context.config.apikey, types_1.Endpoint.Localhost);
const api = new api_1.Api(context.config.apikey, enums_1.Endpoint.Localhost);
let actualNews = yield api.search({

@@ -139,0 +139,0 @@ query: {

export { or, and, text } from "./queries";
export { Api } from "./api";
export { News, Filter, TextOptions, Endpoint, EndpointDescription, Source } from "./types";
export { WsClient } from "./wsclient";
export { News, Filter, TextOptions, EndpointDescription, WebsocketResponse, WebsocketRequest, WebsocketErrorResponse } from "./types";
export { Source, WebsocketMethod, WebsocketResponseType, QueryType, Endpoint } from "./enums";
"use strict";
Object.defineProperty(exports, "__esModule", { value: true });
exports.Source = exports.Endpoint = exports.Api = exports.text = exports.and = exports.or = void 0;
exports.Endpoint = exports.QueryType = exports.WebsocketResponseType = exports.WebsocketMethod = exports.Source = exports.WsClient = exports.Api = exports.text = exports.and = exports.or = void 0;
var queries_1 = require("./queries");

@@ -10,5 +10,10 @@ Object.defineProperty(exports, "or", { enumerable: true, get: function () { return queries_1.or; } });

Object.defineProperty(exports, "Api", { enumerable: true, get: function () { return api_1.Api; } });
var types_1 = require("./types");
Object.defineProperty(exports, "Endpoint", { enumerable: true, get: function () { return types_1.Endpoint; } });
Object.defineProperty(exports, "Source", { enumerable: true, get: function () { return types_1.Source; } });
var wsclient_1 = require("./wsclient");
Object.defineProperty(exports, "WsClient", { enumerable: true, get: function () { return wsclient_1.WsClient; } });
var enums_1 = require("./enums");
Object.defineProperty(exports, "Source", { enumerable: true, get: function () { return enums_1.Source; } });
Object.defineProperty(exports, "WebsocketMethod", { enumerable: true, get: function () { return enums_1.WebsocketMethod; } });
Object.defineProperty(exports, "WebsocketResponseType", { enumerable: true, get: function () { return enums_1.WebsocketResponseType; } });
Object.defineProperty(exports, "QueryType", { enumerable: true, get: function () { return enums_1.QueryType; } });
Object.defineProperty(exports, "Endpoint", { enumerable: true, get: function () { return enums_1.Endpoint; } });
//# sourceMappingURL=index.js.map

@@ -25,4 +25,5 @@ "use strict";

searchBody: true,
searchHeadline: true
searchHeadline: true,
exactMatch: false
};
//# sourceMappingURL=queries.js.map
/// <reference types="ws" />
import { CloseEvent, ErrorEvent } from "isomorphic-ws";
import { CloseEvent } from "isomorphic-ws";
import { Source, WebsocketMethod, WebsocketResponseType } from "./enums";
export interface Filter {

@@ -9,3 +10,3 @@ query?: Query;

}
export interface ApiResponse {
export interface RestResponse {
error: ApiResponseError;

@@ -35,13 +36,11 @@ data: News[];

ignore?: boolean;
exactMatch?: boolean;
}
export interface Query {
and?: Query[];
or?: Query[];
text?: TextQuery;
}
export declare enum QueryType {
And = "and",
Or = "or",
Text = "text"
}
export type Query = {
and: Query[];
} | {
or: Query[];
} | {
text: TextQuery;
};
export interface EndpointDescription {

@@ -52,20 +51,12 @@ host: string;

}
export declare const Endpoint: {
[key: string]: EndpointDescription;
};
export declare enum Source {
DowJones = "DJ",
AccessWire = "AR",
GlobeNewswire = "PZ",
PRNewswire = "PN",
BusinessWire = "BW",
SEC = "SEC"
export interface ConnectOptions {
automaticReconnect?: boolean;
callback: (response: WebsocketResponse) => void;
errorCallback?: (error: WebsocketErrorResponse) => void;
openCallback?: () => void;
closeCallback?: (closeEvent: CloseEvent) => void;
}
export interface SubscribeOptions {
subscriptionId: string;
filter: Filter;
callback: (news: News[]) => void;
errorCallback?: (errorEvent: ErrorEvent) => void;
openCallback?: () => void;
closeCallback?: (closeEvent: CloseEvent) => void;
automaticReconnect?: boolean;
}

@@ -81,1 +72,34 @@ export interface HistoricalFilter extends Filter {

}
export type WebsocketRequest = {
method: WebsocketMethod.SUBSCRIBE;
id: string;
payload: Filter;
} | {
method: WebsocketMethod.UNSUBSCRIBE;
id: string;
payload: {
all: boolean;
} | {
subscriptionId: string;
};
};
export type ErrorPayload = {
message: string;
};
export type WebsocketErrorResponse = {
method: WebsocketMethod;
id?: string;
payload: ErrorPayload;
type: WebsocketResponseType.ERROR;
};
export type WebsocketResponse = {
method: WebsocketMethod.SUBSCRIBE;
id: string;
payload: News[];
type: WebsocketResponseType.DATA;
} | WebsocketErrorResponse | {
method: WebsocketMethod;
id?: string;
payload: undefined;
type: WebsocketResponseType.OK;
};
"use strict";
Object.defineProperty(exports, "__esModule", { value: true });
exports.Source = exports.Endpoint = exports.QueryType = void 0;
var QueryType;
(function (QueryType) {
QueryType["And"] = "and";
QueryType["Or"] = "or";
QueryType["Text"] = "text";
})(QueryType || (exports.QueryType = QueryType = {}));
exports.Endpoint = {
Localhost: {
host: "localhost:8080",
websocketProtocol: "ws",
restProtocol: "http"
},
Production: {
host: "newswareapi.encypherstudio.com",
websocketProtocol: "wss",
restProtocol: "https"
},
};
var Source;
(function (Source) {
Source["DowJones"] = "DJ";
Source["AccessWire"] = "AR";
Source["GlobeNewswire"] = "PZ";
Source["PRNewswire"] = "PN";
Source["BusinessWire"] = "BW";
Source["SEC"] = "SEC";
})(Source || (exports.Source = Source = {}));
//# sourceMappingURL=types.js.map
{
"name": "newsware",
"version": "4.1.1",
"version": "5.0.0-beta.0",
"description": "Typescript client for interacting with the Newsware API",

@@ -5,0 +5,0 @@ "main": "lib/src/index.js",

import {Api} from "./api";
import {Endpoint} from "./types";
import {Endpoint} from "./enums";
import {expect} from "chai"

@@ -4,0 +4,0 @@ import {TestsContext} from "../test/setup";

@@ -1,7 +0,7 @@

import {Endpoint, HistoricalFilter, News, ApiResponse, SubscribeOptions, EndpointDescription} from "./types";
import WebSocket, {MessageEvent, ErrorEvent, CloseEvent} from "isomorphic-ws"
import {ConnectOptions, EndpointDescription, HistoricalFilter, News, RestResponse} from "./types"
import {Endpoint} from "./enums"
import WebSocket from "isomorphic-ws"
import {WsClient} from "./wsclient"
export class Api {
private socket?: WebSocket
private subscribed = false
websocketEndpoint: string

@@ -12,3 +12,3 @@ restEndpoint: string

private apikey: string,
endpoint: EndpointDescription = Endpoint.Production
endpoint: EndpointDescription = Endpoint.PRODUCTION
) {

@@ -19,53 +19,10 @@ this.websocketEndpoint = endpoint.websocketProtocol + "://" + endpoint.host

subscribe(options: SubscribeOptions) {
if (options.automaticReconnect == undefined)
options.automaticReconnect = true
getWsClient(options: ConnectOptions): WsClient {
const urlParams = new URLSearchParams({
apikey: this.apikey,
filter: JSON.stringify(options.filter)
})
this.socket = new WebSocket(`${this.websocketEndpoint}/v1/ws/news?${urlParams.toString()}`)
this.socket.onmessage = (event: MessageEvent) => {
const response = JSON.parse(event.data.toString()) as ApiResponse
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
options.callback(response.data)
}
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 (options.errorCallback)
options.errorCallback(event)
}
this.socket.onopen = () => {
this.subscribed = true
if (options.openCallback)
options.openCallback()
}
this.socket.onclose = (event: CloseEvent) => {
if (options.closeCallback)
options.closeCallback(event)
if (this.subscribed && options.automaticReconnect)
setTimeout(() => this.subscribe(options), 1000)
}
return new WsClient(new WebSocket(`${this.websocketEndpoint}/v2/ws?${urlParams.toString()}`), options)
}
unsubscribe() {
this.subscribed = false
this.socket!!.close()
}
async search(filter: HistoricalFilter): Promise<News[]> {

@@ -86,3 +43,3 @@ return await this.post<HistoricalFilter, News[]>('/v1/api/news', filter)

const apiResponse = await res.json() as ApiResponse
const apiResponse = await res.json() as RestResponse

@@ -89,0 +46,0 @@ if (res.status < 200 || res.status > 299 || apiResponse.error) {

export {or, and, text} from "./queries";
export {Api} from "./api"
export {News, Filter, TextOptions, Endpoint, EndpointDescription, Source} from "./types"
export {WsClient} from "./wsclient"
export {
News, Filter, TextOptions, EndpointDescription, WebsocketResponse, WebsocketRequest, WebsocketErrorResponse
} from "./types"
export {Source, WebsocketMethod, WebsocketResponseType, QueryType, Endpoint} from "./enums"

@@ -28,3 +28,4 @@ import {Query, TextOptions} from "./types";

searchBody: true,
searchHeadline: true
searchHeadline: true,
exactMatch: false
}

@@ -1,2 +0,3 @@

import {CloseEvent, ErrorEvent} from "isomorphic-ws";
import {CloseEvent} from "isomorphic-ws";
import {Source, WebsocketMethod, WebsocketResponseType} from "./enums";

@@ -10,5 +11,5 @@ export interface Filter {

export interface ApiResponse {
error: ApiResponseError;
data: News[];
export interface RestResponse {
error: ApiResponseError
data: News[]
}

@@ -32,3 +33,3 @@

export interface TextQuery extends TextOptions{
export interface TextQuery extends TextOptions {
text: string

@@ -41,16 +42,13 @@ }

ignore?: boolean // defaults to false
exactMatch?: boolean // defaults to false
}
export interface Query {
and?: Query[]
or?: Query[]
text?: TextQuery
export type Query = {
and: Query[]
} | {
or: Query[]
} | {
text: TextQuery
}
export enum QueryType {
And = "and",
Or = "or",
Text = "text"
}
export interface EndpointDescription {

@@ -62,31 +60,13 @@ host: string

export const Endpoint: {[key: string]: EndpointDescription} = {
Localhost: {
host: "localhost:8080",
websocketProtocol: "ws",
restProtocol: "http"
},
Production: {
host: "newswareapi.encypherstudio.com",
websocketProtocol: "wss",
restProtocol: "https"
},
export interface ConnectOptions {
automaticReconnect?: boolean
callback: (response: WebsocketResponse) => void,
errorCallback?: (error: WebsocketErrorResponse) => void,
openCallback?: () => void,
closeCallback?: (closeEvent: CloseEvent) => void,
}
export enum Source {
DowJones = "DJ",
AccessWire = "AR",
GlobeNewswire = "PZ",
PRNewswire = "PN",
BusinessWire = "BW",
SEC = "SEC"
}
export interface SubscribeOptions {
subscriptionId: string,
filter: Filter,
callback: (news: News[]) => void,
errorCallback?: (errorEvent: ErrorEvent) => void,
openCallback?: () => void,
closeCallback?: (closeEvent: CloseEvent) => void,
automaticReconnect?: boolean
}

@@ -103,2 +83,39 @@

page?: number
}
export type WebsocketRequest = {
method: WebsocketMethod.SUBSCRIBE
id: string
payload: Filter
} | {
method: WebsocketMethod.UNSUBSCRIBE
id: string
payload: {
all: boolean
} | {
subscriptionId: string
}
}
export type ErrorPayload = {
message: string
}
export type WebsocketErrorResponse = {
method: WebsocketMethod
id?: string
payload: ErrorPayload
type: WebsocketResponseType.ERROR
}
export type WebsocketResponse = {
method: WebsocketMethod.SUBSCRIBE
id: string
payload: News[]
type: WebsocketResponseType.DATA
} | WebsocketErrorResponse | {
method: WebsocketMethod
id?: string
payload: undefined
type: WebsocketResponseType.OK
}

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

SocketSocket SOC 2 Logo

Product

  • Package Alerts
  • Integrations
  • Docs
  • Pricing
  • FAQ
  • Roadmap
  • Changelog

Packages

npm

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc