@fanoutio/grip
Advanced tools
Comparing version 3.0.0-beta.5 to 3.0.0-beta.6
@@ -1,4 +0,4 @@ | ||
import IAuth from "./IAuth"; | ||
import IAuth from './IAuth'; | ||
export default abstract class Base implements IAuth { | ||
abstract buildHeader(): string; | ||
} |
@@ -34,3 +34,4 @@ "use strict"; | ||
var data = this.user + ":" + this.pass; | ||
return "Basic " + buffer_1.Buffer.from(data).toString('base64'); | ||
var dataBase64 = buffer_1.Buffer.from(data).toString('base64'); | ||
return "Basic " + dataBase64; | ||
}; | ||
@@ -37,0 +38,0 @@ return Basic; |
import Base from './Base'; | ||
import Basic from './Basic'; | ||
import Jwt from './Jwt'; | ||
export { Base, Basic, Jwt, }; | ||
export { Base, Basic, Jwt }; |
/// <reference types="node" /> | ||
import Base from "./Base"; | ||
import Base from './Base'; | ||
export default class Jwt extends Base { | ||
@@ -4,0 +4,0 @@ token?: string; |
@@ -15,2 +15,21 @@ "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.hasOwnProperty.call(mod, k)) __createBinding(result, mod, k); | ||
__setModuleDefault(result, mod); | ||
return result; | ||
}; | ||
var __importDefault = (this && this.__importDefault) || function (mod) { | ||
@@ -21,3 +40,3 @@ return (mod && mod.__esModule) ? mod : { "default": mod }; | ||
var buffer_1 = require("buffer"); | ||
var jwt_simple_1 = require("jwt-simple"); | ||
var jwt = __importStar(require("jsonwebtoken")); | ||
var Base_1 = __importDefault(require("./Base")); | ||
@@ -45,3 +64,3 @@ // JWT authentication class used for building auth headers containing | ||
_this.claim = args[0]; | ||
_this.key = args[1] instanceof buffer_1.Buffer ? args[1] : buffer_1.Buffer.from(String(args[1]), "utf8"); | ||
_this.key = args[1] instanceof buffer_1.Buffer ? args[1] : buffer_1.Buffer.from(String(args[1]), 'utf8'); | ||
} | ||
@@ -57,9 +76,3 @@ return _this; | ||
else { | ||
var claim = this.claim != null && "exp" in this.claim ? | ||
this.claim : | ||
Object.assign({}, this.claim, { | ||
exp: Math.floor(new Date().getTime() / 1000) + 600 | ||
}); | ||
// @ts-ignore | ||
token = jwt_simple_1.encode(claim, this.key); | ||
token = jwt.sign(this.claim, this.key, { expiresIn: '10m' }); | ||
} | ||
@@ -66,0 +79,0 @@ return "Bearer " + token; |
@@ -1,2 +0,2 @@ | ||
import IExportedChannel from "./IExportedChannel"; | ||
import IExportedChannel from './IExportedChannel'; | ||
export default class Channel { | ||
@@ -3,0 +3,0 @@ name?: string; |
@@ -1,3 +0,3 @@ | ||
import IFormat from "./IFormat"; | ||
import IFormatExport from "./IFormatExport"; | ||
import IFormat from './IFormat'; | ||
import IFormatExport from './IFormatExport'; | ||
export default abstract class Format implements IFormat { | ||
@@ -4,0 +4,0 @@ abstract name(): string; |
/// <reference types="node" /> | ||
import Channel from "./Channel"; | ||
import Channel from './Channel'; | ||
export default class GripInstruct { | ||
@@ -4,0 +4,0 @@ status?: number; |
@@ -28,3 +28,5 @@ "use strict"; | ||
// The name used when publishing this format. | ||
HttpResponseFormat.prototype.name = function () { return 'http-response'; }; | ||
HttpResponseFormat.prototype.name = function () { | ||
return 'http-response'; | ||
}; | ||
return HttpResponseFormat; | ||
@@ -31,0 +33,0 @@ }(Response_1.default)); |
/// <reference types="node" /> | ||
import IFormat from '../IFormat'; | ||
import IFormatExport from "../IFormatExport"; | ||
import IFormatExport from '../IFormatExport'; | ||
export default class HttpStreamFormat implements IFormat { | ||
@@ -5,0 +5,0 @@ content: string | Buffer | null; |
@@ -20,3 +20,5 @@ "use strict"; | ||
// The name used when publishing this format. | ||
HttpStreamFormat.prototype.name = function () { return 'http-stream'; }; | ||
HttpStreamFormat.prototype.name = function () { | ||
return 'http-stream'; | ||
}; | ||
// Exports the message in the required format depending on whether the | ||
@@ -23,0 +25,0 @@ // message content is binary or not, or whether the connection should |
@@ -1,2 +0,2 @@ | ||
import IFormatExport from "./IFormatExport"; | ||
import IFormatExport from './IFormatExport'; | ||
export default interface IFormat { | ||
@@ -3,0 +3,0 @@ name(): string; |
@@ -1,4 +0,4 @@ | ||
import IItemExport from "./IItemExport"; | ||
import IItemExport from './IItemExport'; | ||
export default interface IItem { | ||
export(): IItemExport; | ||
} |
export default interface IItemExport { | ||
channel?: string; | ||
id?: string; | ||
"prev-id"?: string; | ||
'prev-id'?: string; | ||
[format: string]: any; | ||
} |
@@ -1,4 +0,4 @@ | ||
import IFormat from "./IFormat"; | ||
import IItem from "./IItem"; | ||
import IItemExport from "./IItemExport"; | ||
import IFormat from './IFormat'; | ||
import IItem from './IItem'; | ||
import IItemExport from './IItemExport'; | ||
export default class Item implements IItem { | ||
@@ -5,0 +5,0 @@ formats: IFormat[]; |
/// <reference types="node" /> | ||
import IWebSocketEvent from "./IWebSocketEvent"; | ||
import IWebSocketEvent from './IWebSocketEvent'; | ||
export default class WebSocketContext { | ||
@@ -4,0 +4,0 @@ id: string; |
@@ -34,5 +34,3 @@ "use strict"; | ||
WebSocketContext.prototype.isOpening = function () { | ||
return Array.isArray(this.inEvents) && | ||
this.inEvents.length > 0 && | ||
this.inEvents[0].type === 'OPEN'; | ||
return Array.isArray(this.inEvents) && this.inEvents.length > 0 && this.inEvents[0].type === 'OPEN'; | ||
}; | ||
@@ -109,6 +107,6 @@ WebSocketContext.prototype.accept = function () { | ||
WebSocketContext.prototype.subscribe = function (channel) { | ||
this.sendControl(webSocketEvents_1.createWebSocketControlMessage('subscribe', { 'channel': this.prefix + channel })); | ||
this.sendControl(webSocketEvents_1.createWebSocketControlMessage('subscribe', { channel: this.prefix + channel })); | ||
}; | ||
WebSocketContext.prototype.unsubscribe = function (channel) { | ||
this.sendControl(webSocketEvents_1.createWebSocketControlMessage('unsubscribe', { 'channel': this.prefix + channel })); | ||
this.sendControl(webSocketEvents_1.createWebSocketControlMessage('unsubscribe', { channel: this.prefix + channel })); | ||
}; | ||
@@ -139,13 +137,11 @@ WebSocketContext.prototype.detach = function () { | ||
// in wsContext.meta | ||
var metaToRemove = Object.keys(this.origMeta) | ||
.filter(function (k) { return Object.keys(_this.meta) | ||
.every(function (nk) { return nk.toLowerCase() !== k; }); }); | ||
var metaToRemove = Object.keys(this.origMeta).filter(function (k) { | ||
return Object.keys(_this.meta).every(function (nk) { return nk.toLowerCase() !== k; }); | ||
}); | ||
// Find all items in wsContext.meta whose keys and values don't match | ||
// any in wsContext.origMeta | ||
var metaToSet = Object.entries(this.meta) | ||
.reduce(function (acc, _a) { | ||
var metaToSet = Object.entries(this.meta).reduce(function (acc, _a) { | ||
var nk = _a[0], nv = _a[1]; | ||
var lname = nk.toLowerCase(); | ||
if (Object.entries(_this.origMeta) | ||
.every(function (_a) { | ||
if (Object.entries(_this.origMeta).every(function (_a) { | ||
var k = _a[0], v = _a[1]; | ||
@@ -152,0 +148,0 @@ return lname !== k || nv !== v; |
/// <reference types="node" /> | ||
import IWebSocketEvent from "./IWebSocketEvent"; | ||
import IWebSocketEvent from './IWebSocketEvent'; | ||
export default class WebSocketEvent implements IWebSocketEvent { | ||
@@ -4,0 +4,0 @@ type: string; |
/// <reference types="node" /> | ||
import IFormat from '../IFormat'; | ||
import IFormatExport from "../IFormatExport"; | ||
import IFormatExport from '../IFormatExport'; | ||
export default class WebSocketMessageFormat implements IFormat { | ||
@@ -5,0 +5,0 @@ content: string | Buffer | null; |
@@ -21,3 +21,5 @@ "use strict"; | ||
// The name used when publishing this format. | ||
WebSocketMessageFormat.prototype.name = function () { return 'ws-message'; }; | ||
WebSocketMessageFormat.prototype.name = function () { | ||
return 'ws-message'; | ||
}; | ||
// Exports the message in the required format depending on whether the | ||
@@ -24,0 +26,0 @@ // message content is a buffer or not, or whether the connection should |
import IFormat from '../data/IFormat'; | ||
import HttpStreamFormat from '../data/http/HttpStreamFormat'; | ||
import HttpResponseFormat from '../data/http/HttpResponseFormat'; | ||
import IGripConfig from "./IGripConfig"; | ||
import PublisherClient from "./PublisherClient"; | ||
import IItem from "../data/IItem"; | ||
import IGripConfig from './IGripConfig'; | ||
import PublisherClient from './PublisherClient'; | ||
import IItem from '../data/IItem'; | ||
export default class Publisher { | ||
@@ -8,0 +8,0 @@ clients: PublisherClient[]; |
/// <reference types="node" /> | ||
import 'isomorphic-fetch'; | ||
import HttpAgent, { HttpsAgent } from 'agentkeepalive'; | ||
import IAuth from "../auth/IAuth"; | ||
import IItem from "../data/IItem"; | ||
import IItemExport from "../data/IItemExport"; | ||
import IAuth from '../auth/IAuth'; | ||
import IItem from '../data/IItem'; | ||
import IItemExport from '../data/IItemExport'; | ||
interface IReqHeaders { | ||
@@ -8,0 +8,0 @@ [name: string]: string; |
@@ -81,3 +81,3 @@ "use strict"; | ||
// Initialize this class with a URL representing the publishing endpoint. | ||
this.uri = uri.replace(/\/$/, ""); | ||
this.uri = uri.replace(/\/$/, ''); | ||
} | ||
@@ -127,12 +127,12 @@ // Call this method and pass a username and password to use basic | ||
headers = { | ||
"Content-Type": "application/json", | ||
"Content-Length": "" + buffer_1.Buffer.byteLength(content, "utf8"), | ||
'Content-Type': 'application/json', | ||
'Content-Length': String(buffer_1.Buffer.byteLength(content, 'utf8')), | ||
}; | ||
if (authHeader != null) { | ||
headers["Authorization"] = authHeader; | ||
headers['Authorization'] = authHeader; | ||
} | ||
publishUri = uri + "/publish/"; | ||
publishUri = uri + '/publish/'; | ||
parsed = new URL(publishUri); | ||
reqParams = { | ||
method: "POST", | ||
method: 'POST', | ||
headers: headers, | ||
@@ -144,4 +144,4 @@ body: content, | ||
switch (_a) { | ||
case "http:": return [3 /*break*/, 1]; | ||
case "https:": return [3 /*break*/, 2]; | ||
case 'http:': return [3 /*break*/, 1]; | ||
case 'https:': return [3 /*break*/, 2]; | ||
} | ||
@@ -194,3 +194,3 @@ return [3 /*break*/, 3]; | ||
_a.trys.push([5, 7, , 8]); | ||
mode = "end"; | ||
mode = 'end'; | ||
return [4 /*yield*/, res.text()]; | ||
@@ -202,3 +202,3 @@ case 6: | ||
err_2 = _a.sent(); | ||
mode = "close"; | ||
mode = 'close'; | ||
data = err_2; | ||
@@ -217,3 +217,3 @@ return [3 /*break*/, 8]; | ||
context.httpBody = httpData; | ||
if (mode === "end") { | ||
if (mode === 'end') { | ||
if (context.statusCode < 200 || context.statusCode >= 300) { | ||
@@ -223,3 +223,3 @@ throw new PublishException_1.default(JSON.stringify(context.httpBody), context); | ||
} | ||
else if (mode === "close") { | ||
else if (mode === 'close') { | ||
throw new PublishException_1.default('Connection closed unexpectedly', context); | ||
@@ -231,3 +231,2 @@ } | ||
exports.default = PublisherClient; | ||
; | ||
//# sourceMappingURL=PublisherClient.js.map |
@@ -22,4 +22,4 @@ export { default as Publisher } from './engine/Publisher'; | ||
export type { default as IItemExport } from './data/IItemExport'; | ||
export { createGripChannelHeader, parseGripUri, } from './utilities/grip'; | ||
export { createGripChannelHeader, parseGripUri } from './utilities/grip'; | ||
export { encodeWebSocketEvents, decodeWebSocketEvents, createWebSocketControlMessage, } from './utilities/webSocketEvents'; | ||
export { validateSig, } from './utilities/jwt'; | ||
export { validateSig } from './utilities/jwt'; |
@@ -1,5 +0,5 @@ | ||
import IGripConfig from "../engine/IGripConfig"; | ||
import Channel from "../data/Channel"; | ||
import IGripConfig from '../engine/IGripConfig'; | ||
import Channel from '../data/Channel'; | ||
export declare function parseChannels(inChannels: Channel | Channel[] | string | string[]): Channel[]; | ||
export declare function parseGripUri(uri: string): IGripConfig; | ||
export declare function createGripChannelHeader(channels: Channel | Channel[] | string | string[]): string; |
@@ -37,3 +37,3 @@ "use strict"; | ||
var channels = !Array.isArray(inChannels) ? [inChannels] : inChannels; | ||
return channels.map(function (channel) { return string_1.isString(channel) ? new Channel_1.default(channel) : channel; }); | ||
return channels.map(function (channel) { return (string_1.isString(channel) ? new Channel_1.default(channel) : channel); }); | ||
} | ||
@@ -71,3 +71,3 @@ exports.parseChannels = parseChannels; | ||
} | ||
var out = { 'control_uri': controlUri }; | ||
var out = { control_uri: controlUri }; | ||
if (iss != null) { | ||
@@ -74,0 +74,0 @@ out['control_iss'] = iss; |
@@ -1,1 +0,2 @@ | ||
export declare function validateSig(token: string, key: any): boolean; | ||
/// <reference types="node" /> | ||
export declare function validateSig(token: string, key: string | Buffer): boolean; |
@@ -23,4 +23,3 @@ "use strict"; | ||
exports.validateSig = void 0; | ||
var jwt = __importStar(require("jwt-simple")); | ||
var buffer_1 = require("./buffer"); | ||
var jwt = __importStar(require("jsonwebtoken")); | ||
// Validate the specified JWT token and key. This method is used to validate | ||
@@ -30,8 +29,5 @@ // the GRIP-SIG header coming from GRIP proxies such as Pushpin or Fanout.io. | ||
function validateSig(token, key) { | ||
var keyBuffer = buffer_1.toBuffer(key); | ||
var claim; | ||
try { | ||
// HACK: jwt-simple's d.ts says decode takes a string, but | ||
// it works fine with buffer. | ||
claim = jwt.decode(token, keyBuffer); | ||
claim = jwt.verify(token, key); | ||
} | ||
@@ -41,9 +37,8 @@ catch (e) { | ||
} | ||
if (!('exp' in claim)) { | ||
if (claim == null) { | ||
return false; | ||
} | ||
var exp = claim.exp; | ||
return new Date().getTime() / 1000 <= exp; | ||
return true; | ||
} | ||
exports.validateSig = validateSig; | ||
//# sourceMappingURL=jwt.js.map |
/// <reference types="node" /> | ||
import IWebSocketEvent from "../data/websocket/IWebSocketEvent"; | ||
import IWebSocketEvent from '../data/websocket/IWebSocketEvent'; | ||
export declare function encodeWebSocketEvents(events: IWebSocketEvent[]): Buffer; | ||
export declare function decodeWebSocketEvents(body: Buffer | string): IWebSocketEvent[]; | ||
export declare function createWebSocketControlMessage(type: string, args?: object | null): string; |
@@ -28,9 +28,14 @@ "use strict"; | ||
} | ||
out = buffer_1.Buffer.concat([out, buffer_1.Buffer.from(e.getType()), buffer_1.Buffer.from(' '), | ||
out = buffer_1.Buffer.concat([ | ||
out, | ||
buffer_1.Buffer.from(e.getType()), | ||
buffer_1.Buffer.from(' '), | ||
buffer_1.Buffer.from(content.length.toString(16)), | ||
bufferNewLine, content, bufferNewLine]); | ||
bufferNewLine, | ||
content, | ||
bufferNewLine, | ||
]); | ||
} | ||
else { | ||
out = buffer_1.Buffer.concat([out, buffer_1.Buffer.from(e.getType()), | ||
bufferNewLine]); | ||
out = buffer_1.Buffer.concat([out, buffer_1.Buffer.from(e.getType()), bufferNewLine]); | ||
} | ||
@@ -37,0 +42,0 @@ } |
{ | ||
"name": "@fanoutio/grip", | ||
"version": "3.0.0-beta.5", | ||
"version": "3.0.0-beta.6", | ||
"author": "Fanout, Inc. <info@fanout.io>", | ||
@@ -29,3 +29,3 @@ "description": "GRIP Interface Library", | ||
"build-commonjs:build": "tsc --outDir build", | ||
"format": "prettier --write \"src/**/*.ts\" \"src/**/*.js\"", | ||
"format": "prettier --write \"src/**/*.{js,ts}\"", | ||
"build-browser": "npm run build-browser:clean && npm run build-browser:build", | ||
@@ -36,3 +36,3 @@ "build-browser:clean": "rimraf browser", | ||
"lint:tslint": "tslint -p tsconfig.json", | ||
"test": "jest --config jestconfig.json" | ||
"test": "jest --config jestconfig.json --verbose" | ||
}, | ||
@@ -58,6 +58,5 @@ "repository": { | ||
"@rollup/plugin-node-resolve": "^9.0.0", | ||
"@rollup/plugin-replace": "^2.3.3", | ||
"@rollup/plugin-typescript": "^5.0.2", | ||
"@types/jest": "^26.0.10", | ||
"@types/jwt-simple": "^0.5.33", | ||
"@types/jsonwebtoken": "^8.5.0", | ||
"@types/node": "^14.6.0", | ||
@@ -68,4 +67,3 @@ "jest": "^26.4.0", | ||
"rollup": "^2.26.4", | ||
"rollup-plugin-node-builtins": "^2.1.2", | ||
"rollup-plugin-node-globals": "^1.4.0", | ||
"rollup-plugin-node-polyfills": "^0.2.1", | ||
"ts-jest": "^26.2.0", | ||
@@ -79,5 +77,5 @@ "tslint": "^6.1.3", | ||
"isomorphic-fetch": "^2.2.1", | ||
"jspack": "0.0.4", | ||
"jwt-simple": "^0.5.6" | ||
"jsonwebtoken": "^8.5.1", | ||
"jspack": "0.0.4" | ||
} | ||
} |
Sorry, the diff of this file is too big to display
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
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
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
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
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Major refactor
Supply chain riskPackage has recently undergone a major refactor. It may be unstable or indicate significant internal changes. Use caution when updating to versions that include significant changes.
Found 1 instance in 1 package
16
13287
2
537177
+ Addedjsonwebtoken@^8.5.1
+ Addedbuffer-equal-constant-time@1.0.1(transitive)
+ Addedecdsa-sig-formatter@1.0.11(transitive)
+ Addedjsonwebtoken@8.5.1(transitive)
+ Addedjwa@1.4.1(transitive)
+ Addedjws@3.2.2(transitive)
+ Addedlodash.includes@4.3.0(transitive)
+ Addedlodash.isboolean@3.0.3(transitive)
+ Addedlodash.isinteger@4.0.4(transitive)
+ Addedlodash.isnumber@3.0.3(transitive)
+ Addedlodash.isplainobject@4.0.6(transitive)
+ Addedlodash.isstring@4.0.1(transitive)
+ Addedlodash.once@4.1.1(transitive)
+ Addedsafe-buffer@5.2.1(transitive)
+ Addedsemver@5.7.2(transitive)
- Removedjwt-simple@^0.5.6
- Removedjwt-simple@0.5.6(transitive)