Comparing version 4.2.5 to 4.3.0
{ | ||
"name": "pubnub", | ||
"version": "4.2.5", | ||
"version": "4.3.0", | ||
"main": "dist/web/pubnub.min.js", | ||
@@ -5,0 +5,0 @@ "license": "https://github.com/pubnub/javascript/blob/master/LICENSE", |
## [v4.3.0](https://github.com/pubnub/javascript/tree/v4.3.0) | ||
[Full Changelog](https://github.com/pubnub/javascript/compare/v4.2.5...v4.3.0) | ||
- ⭐bulk history exposed via pubnub.fetchMessages | ||
- ⭐publish supports custom ttl interval | ||
- ⭐v2 for audit and grant; no consumer facing changes. | ||
- ⭐fixes for param validation on usage of promises | ||
## [v4.2.5](https://github.com/pubnub/javascript/tree/v4.2.5) | ||
@@ -3,0 +25,0 @@ |
@@ -9,6 +9,6 @@ 'use strict'; | ||
var networking = modules.networking, | ||
config = modules.config, | ||
crypto = modules.crypto; | ||
config = modules.config; | ||
var callback = null; | ||
var promiseComponent = null; | ||
var incomingParams = {}; | ||
@@ -23,6 +23,15 @@ | ||
if (typeof Promise !== 'undefined' && !callback) { | ||
promiseComponent = _utils2.default.createPromise(); | ||
} | ||
var validationResult = endpoint.validateParams(modules, incomingParams); | ||
if (validationResult) { | ||
callback(createValidationError(validationResult)); | ||
if (callback) { | ||
return callback(createValidationError(validationResult)); | ||
} else if (promiseComponent) { | ||
promiseComponent.reject(new PubNubError('Validation failed, check status for details', createValidationError(validationResult))); | ||
return promiseComponent.promise; | ||
} | ||
return; | ||
@@ -55,28 +64,5 @@ } | ||
if (config.secretKey) { | ||
outgoingParams.timestamp = Math.floor(new Date().getTime() / 1000); | ||
var signInput = config.subscribeKey + '\n' + config.publishKey + '\n'; | ||
if (endpoint.getOperation() === _operations2.default.PNAccessManagerGrant) { | ||
signInput += 'grant\n'; | ||
} else if (endpoint.getOperation() === _operations2.default.PNAccessManagerAudit) { | ||
signInput += 'audit\n'; | ||
} else { | ||
signInput += url + '\n'; | ||
} | ||
signInput += _utils2.default.signPamFromParams(outgoingParams); | ||
var signature = crypto.HMACSHA256(signInput); | ||
signature = signature.replace(/\+/g, '-'); | ||
signature = signature.replace(/\//g, '_'); | ||
outgoingParams.signature = signature; | ||
signRequest(modules, url, outgoingParams); | ||
} | ||
var promiseComponent = null; | ||
if (typeof Promise !== 'undefined' && !callback) { | ||
promiseComponent = _utils2.default.createPromise(); | ||
} | ||
var onResponse = function onResponse(status, payload) { | ||
@@ -189,3 +175,19 @@ if (status.error) { | ||
function signRequest(modules, url, outgoingParams) { | ||
var config = modules.config, | ||
crypto = modules.crypto; | ||
outgoingParams.timestamp = Math.floor(new Date().getTime() / 1000); | ||
var signInput = config.subscribeKey + '\n' + config.publishKey + '\n' + url + '\n'; | ||
signInput += _utils2.default.signPamFromParams(outgoingParams); | ||
var signature = crypto.HMACSHA256(signInput); | ||
signature = signature.replace(/\+/g, '-'); | ||
signature = signature.replace(/\//g, '_'); | ||
outgoingParams.signature = signature; | ||
} | ||
module.exports = exports['default']; | ||
//# sourceMappingURL=endpoint.js.map |
@@ -10,2 +10,3 @@ 'use strict'; | ||
PNHistoryOperation: 'PNHistoryOperation', | ||
PNFetchMessagesOperation: 'PNFetchMessagesOperation', | ||
@@ -12,0 +13,0 @@ PNSubscribeOperation: 'PNSubscribeOperation', |
@@ -36,3 +36,3 @@ 'use strict'; | ||
return '/v1/auth/audit/sub-key/' + config.subscribeKey; | ||
return '/v2/auth/audit/sub-key/' + config.subscribeKey; | ||
} | ||
@@ -39,0 +39,0 @@ |
@@ -36,3 +36,3 @@ 'use strict'; | ||
return '/v1/auth/grant/sub-key/' + config.subscribeKey; | ||
return '/v2/auth/grant/sub-key/' + config.subscribeKey; | ||
} | ||
@@ -39,0 +39,0 @@ |
@@ -104,3 +104,4 @@ 'use strict'; | ||
replicate = _incomingParams$repli === undefined ? true : _incomingParams$repli, | ||
storeInHistory = incomingParams.storeInHistory; | ||
storeInHistory = incomingParams.storeInHistory, | ||
ttl = incomingParams.ttl; | ||
@@ -117,2 +118,6 @@ var params = {}; | ||
if (ttl) { | ||
params.ttl = ttl; | ||
} | ||
if (replicate === false) { | ||
@@ -119,0 +124,0 @@ params.norep = 'true'; |
@@ -113,2 +113,6 @@ 'use strict'; | ||
var _fetch_messages = require('./endpoints/fetch_messages'); | ||
var fetchMessagesEndpointConfig = _interopRequireWildcard(_fetch_messages); | ||
var _time = require('./endpoints/time'); | ||
@@ -213,2 +217,3 @@ | ||
this.history = _endpoint2.default.bind(this, modules, historyEndpointConfig); | ||
this.fetchMessages = _endpoint2.default.bind(this, modules, fetchMessagesEndpointConfig); | ||
@@ -215,0 +220,0 @@ this.time = timeEndpoint; |
{ | ||
"name": "pubnub", | ||
"version": "4.2.5", | ||
"version": "4.3.0", | ||
"author": "PubNub <support@pubnub.com>", | ||
@@ -45,6 +45,6 @@ "description": "Publish & Subscribe Real-time Messaging with PubNub", | ||
"eslint-plugin-flowtype": "^2.19.0", | ||
"eslint-plugin-import": "^1.16.0", | ||
"eslint-plugin-import": "^2.2.0", | ||
"eslint-plugin-mocha": "^4.6.0", | ||
"eslint-plugin-react": "^6.3.0", | ||
"flow-bin": "^0.34.0", | ||
"flow-bin": "^0.35.0", | ||
"gulp": "^3.9.1", | ||
@@ -60,3 +60,3 @@ "gulp-babel": "^6.1.2", | ||
"gulp-rename": "^1.2.2", | ||
"gulp-sourcemaps": "^1.6.0", | ||
"gulp-sourcemaps": "^2.2.0", | ||
"gulp-uglify": "^2.0.0", | ||
@@ -76,3 +76,3 @@ "imports-loader": "^0.6.5", | ||
"phantomjs-prebuilt": "^2.1.12", | ||
"remap-istanbul": "^0.6.4", | ||
"remap-istanbul": "^0.7.0", | ||
"run-sequence": "^1.2.2", | ||
@@ -79,0 +79,0 @@ "sinon": "^1.17.6", |
@@ -21,3 +21,3 @@ # PubNub JavaScript SDK (V4) | ||
## CDN Links | ||
* https://cdn.pubnub.com/sdk/javascript/pubnub.4.2.5.min.js | ||
* https://cdn.pubnub.com/sdk/javascript/pubnub.4.2.5.js | ||
* https://cdn.pubnub.com/sdk/javascript/pubnub.4.3.0.min.js | ||
* https://cdn.pubnub.com/sdk/javascript/pubnub.4.3.0.js |
@@ -46,5 +46,20 @@ import uuidGenerator from 'uuid'; | ||
function signRequest(modules, url, outgoingParams) { | ||
let { config, crypto } = modules; | ||
outgoingParams.timestamp = Math.floor(new Date().getTime() / 1000); | ||
let signInput = config.subscribeKey + '\n' + config.publishKey + '\n' + url + '\n'; | ||
signInput += utils.signPamFromParams(outgoingParams); | ||
let signature = crypto.HMACSHA256(signInput); | ||
signature = signature.replace(/\+/g, '-'); | ||
signature = signature.replace(/\//g, '_'); | ||
outgoingParams.signature = signature; | ||
} | ||
export default function (modules, endpoint, ...args) { | ||
let { networking, config, crypto } = modules; | ||
let { networking, config } = modules; | ||
let callback = null; | ||
let promiseComponent = null; | ||
let incomingParams = {}; | ||
@@ -59,6 +74,16 @@ | ||
// bridge in Promise support. | ||
if (typeof Promise !== 'undefined' && !callback) { | ||
promiseComponent = utils.createPromise(); | ||
} | ||
let validationResult = endpoint.validateParams(modules, incomingParams); | ||
if (validationResult) { | ||
callback(createValidationError(validationResult)); | ||
if (callback) { | ||
return callback(createValidationError(validationResult)); | ||
} else if (promiseComponent) { | ||
promiseComponent.reject(new PubNubError('Validation failed, check status for details', createValidationError(validationResult))); | ||
return promiseComponent.promise; | ||
} | ||
return; | ||
@@ -91,29 +116,5 @@ } | ||
if (config.secretKey) { | ||
outgoingParams.timestamp = Math.floor(new Date().getTime() / 1000); | ||
let signInput = config.subscribeKey + '\n' + config.publishKey + '\n'; | ||
if (endpoint.getOperation() === operationConstants.PNAccessManagerGrant) { | ||
signInput += 'grant\n'; | ||
} else if (endpoint.getOperation() === operationConstants.PNAccessManagerAudit) { | ||
signInput += 'audit\n'; | ||
} else { | ||
signInput += url + '\n'; | ||
} | ||
signInput += utils.signPamFromParams(outgoingParams); | ||
let signature = crypto.HMACSHA256(signInput); | ||
signature = signature.replace(/\+/g, '-'); | ||
signature = signature.replace(/\//g, '_'); | ||
outgoingParams.signature = signature; | ||
signRequest(modules, url, outgoingParams); | ||
} | ||
let promiseComponent = null; | ||
// bridge in Promise support. | ||
if (typeof Promise !== 'undefined' && !callback) { | ||
promiseComponent = utils.createPromise(); | ||
} | ||
let onResponse = (status: StatusAnnouncement, payload: Object) => { | ||
@@ -120,0 +121,0 @@ if (status.error) { |
@@ -6,4 +6,5 @@ /* @flow */ | ||
PNHistoryOperation: 'PNHistoryOperation', | ||
PNFetchMessagesOperation: 'PNFetchMessagesOperation', | ||
// pubsuv | ||
// pubsub | ||
PNSubscribeOperation: 'PNSubscribeOperation', | ||
@@ -10,0 +11,0 @@ PNUnsubscribeOperation: 'PNUnsubscribeOperation', |
@@ -18,3 +18,3 @@ /* @flow */ | ||
let { config } = modules; | ||
return '/v1/auth/audit/sub-key/' + config.subscribeKey; | ||
return '/v2/auth/audit/sub-key/' + config.subscribeKey; | ||
} | ||
@@ -21,0 +21,0 @@ |
@@ -18,3 +18,3 @@ /* @flow */ | ||
let { config } = modules; | ||
return '/v1/auth/grant/sub-key/' + config.subscribeKey; | ||
return '/v2/auth/grant/sub-key/' + config.subscribeKey; | ||
} | ||
@@ -21,0 +21,0 @@ |
@@ -63,3 +63,3 @@ /* @flow */ | ||
export function prepareParams(modules: ModulesInject, incomingParams: PublishArguments): Object { | ||
const { meta, replicate = true, storeInHistory } = incomingParams; | ||
const { meta, replicate = true, storeInHistory, ttl } = incomingParams; | ||
const params = {}; | ||
@@ -75,2 +75,6 @@ | ||
if (ttl) { | ||
params.ttl = ttl; | ||
} | ||
if (replicate === false) { | ||
@@ -77,0 +81,0 @@ params.norep = 'true'; |
@@ -135,3 +135,3 @@ /* eslint no-unused-vars: 0 */ | ||
timetoken: number, | ||
timetoken: number | string, | ||
userMetadata: Object, | ||
@@ -161,8 +161,6 @@ publisher: string | ||
// history | ||
type FetchHistoryArguments = { | ||
channel: string, // fetch history from a channel | ||
channelGroup: string, // fetch history from channel groups | ||
start: number | string, // start timetoken for history fetching | ||
end: number | string, // end timetoken for history feting | ||
end: number | string, // end timetoken for history fetching | ||
includeTimetoken: boolean, // include time token for each history call | ||
@@ -173,2 +171,9 @@ reverse: boolean, | ||
type FetchMessagesArguments = { | ||
channels: string, // fetch history from a channel | ||
start: number | string, // start timetoken for history fetching | ||
end: number | string, // end timetoken for history fetching | ||
count: number | ||
} | ||
type HistoryItem = { | ||
@@ -185,2 +190,6 @@ timetoken: number | string | null, | ||
type HistoryV3Response = { | ||
channels: Object | ||
} | ||
// CG endpoints | ||
@@ -187,0 +196,0 @@ |
@@ -36,2 +36,3 @@ /* @flow */ | ||
import * as historyEndpointConfig from './endpoints/history'; | ||
import * as fetchMessagesEndpointConfig from './endpoints/fetch_messages'; | ||
import * as timeEndpointConfig from './endpoints/time'; | ||
@@ -55,3 +56,6 @@ import * as subscribeEndpointConfig from './endpoints/subscribe'; | ||
fire: Function; | ||
history: Function; | ||
fetchMessages: Function; | ||
// | ||
@@ -164,2 +168,3 @@ channelGroups: Object; | ||
this.history = endpointCreator.bind(this, modules, historyEndpointConfig); | ||
this.fetchMessages = endpointCreator.bind(this, modules, fetchMessagesEndpointConfig); | ||
@@ -166,0 +171,0 @@ this.time = timeEndpoint; |
@@ -33,4 +33,4 @@ /* global describe, beforeEach, it, before, afterEach, after */ | ||
it('issues the correct RESTful request for channels', (done) => { | ||
const scope = utils.createNock().get('/v1/auth/audit/sub-key/mySubscribeKey') | ||
.query({ timestamp: 1317427200, channel: 'ch1', uuid: 'myUUID', pnsdk: 'PubNub-JS-Nodejs/suchJavascript', signature: '4EgDD2LM2BO9GqEwlHDeSBbCM0muLh-Y1s1FY3FrRQI=' }) | ||
const scope = utils.createNock().get('/v2/auth/audit/sub-key/mySubscribeKey') | ||
.query({ timestamp: 1317427200, channel: 'ch1', uuid: 'myUUID', pnsdk: 'PubNub-JS-Nodejs/suchJavascript', signature: 'T7d76LD7SJJdhaljs8yku5cY04TvynsCVBs2D8FMF8Y=' }) | ||
.reply(200, '{"message":"Success","payload":{"level":"channel-group+auth","subscribe_key":"sub-c-82ab2196-b64f-11e5-8622-0619f8945a4f","channel-group":"cg2","auths":{"key1":{"r":1,"m":1,"w":1}}},"service":"Access Manager","status":200}'); | ||
@@ -58,4 +58,4 @@ | ||
it('issues the correct RESTful request for channel groups', (done) => { | ||
const scope = utils.createNock().get('/v1/auth/audit/sub-key/mySubscribeKey') | ||
.query({ timestamp: 1317427200, 'channel-group': 'cg1', uuid: 'myUUID', pnsdk: 'PubNub-JS-Nodejs/suchJavascript', signature: 'J9kaoNajCy6eMCGmL4Fs6LjePhhgkwL6UNW5lry2c4A=' }) | ||
const scope = utils.createNock().get('/v2/auth/audit/sub-key/mySubscribeKey') | ||
.query({ timestamp: 1317427200, 'channel-group': 'cg1', uuid: 'myUUID', pnsdk: 'PubNub-JS-Nodejs/suchJavascript', signature: 'P3xBKue_zoj23Kc0JcTDmeLO751R_bYtr74LFEyfwZM=' }) | ||
.reply(200, '{"message":"Success","payload":{"level":"channel-group+auth","subscribe_key":"sub-c-82ab2196-b64f-11e5-8622-0619f8945a4f","channel-group":"cg2","auths":{"key1":{"r":1,"m":1,"w":1}}},"service":"Access Manager","status":200}'); | ||
@@ -83,4 +83,4 @@ | ||
it('issues the correct RESTful request for keys', (done) => { | ||
const scope = utils.createNock().get('/v1/auth/audit/sub-key/mySubscribeKey') | ||
.query({ timestamp: 1317427200, auth: 'key1,key2', uuid: 'myUUID', pnsdk: 'PubNub-JS-Nodejs/suchJavascript', signature: 'jax2fEP-dRB6kV-pYQGIOEYQJZ3rugoZuYDH-rxPyk4=' }) | ||
const scope = utils.createNock().get('/v2/auth/audit/sub-key/mySubscribeKey') | ||
.query({ timestamp: 1317427200, auth: 'key1,key2', uuid: 'myUUID', pnsdk: 'PubNub-JS-Nodejs/suchJavascript', signature: 'OlwW-JbL2_pnp9qLaCnQwc2oWAoybQYi4wqLOegc1Kg=' }) | ||
.reply(200, '{"message":"Success","payload":{"level":"channel-group+auth","subscribe_key":"sub-c-82ab2196-b64f-11e5-8622-0619f8945a4f","channel-group":"cg2","auths":{"key1":{"r":1,"m":1,"w":1}}},"service":"Access Manager","status":200}'); | ||
@@ -110,3 +110,3 @@ | ||
it('issues the correct RESTful request for channels', (done) => { | ||
const scope = utils.createNock().get('/v1/auth/grant/sub-key/mySubscribeKey') | ||
const scope = utils.createNock().get('/v2/auth/grant/sub-key/mySubscribeKey') | ||
.query({ | ||
@@ -118,3 +118,3 @@ timestamp: 1317427200, | ||
pnsdk: 'PubNub-JS-Nodejs/suchJavascript', | ||
signature: 'GorjdSX4ct8sUbAAbMqq0ighKvVud8L5CpD2Z-RDnSQ=', | ||
signature: 'eHfy2MycQdZySF95iavsSftLDD0oG5umBKgTxHbMFwg=', | ||
r: 0, | ||
@@ -134,3 +134,3 @@ w: 0, | ||
it('issues the correct RESTful request for channels groups', (done) => { | ||
const scope = utils.createNock().get('/v1/auth/grant/sub-key/mySubscribeKey') | ||
const scope = utils.createNock().get('/v2/auth/grant/sub-key/mySubscribeKey') | ||
.query({ | ||
@@ -142,3 +142,3 @@ timestamp: 1317427200, | ||
pnsdk: 'PubNub-JS-Nodejs/suchJavascript', | ||
signature: 'MiYApTnEe6n67rqlMgFiU4csLnu-XJWIB8aAHWuKLhY=', | ||
signature: 'B4QZ4K5nd_eI0AT6JAw4Ubk57x87-Ze7jsihw-vV--A=', | ||
r: 1, | ||
@@ -158,3 +158,3 @@ w: 1, | ||
it('issues the correct RESTful request for channels groups w/ ttl', (done) => { | ||
const scope = utils.createNock().get('/v1/auth/grant/sub-key/mySubscribeKey') | ||
const scope = utils.createNock().get('/v2/auth/grant/sub-key/mySubscribeKey') | ||
.query({ | ||
@@ -166,3 +166,3 @@ timestamp: 1317427200, | ||
pnsdk: 'PubNub-JS-Nodejs/suchJavascript', | ||
signature: 'i4U3Cg3Sa5pCXAYOCGcqndwk_DZ1qyQc6J6xqT42uEc=', | ||
signature: 'CAPs9l4jliNPnle-Tx7PjZCLTYQYg9CU9YKaiAYTuRQ=', | ||
r: 1, | ||
@@ -169,0 +169,0 @@ w: 1, |
@@ -25,2 +25,15 @@ /* global describe, beforeEach, it, before, afterEach, after */ | ||
describe('##validation', () => { | ||
it('fails if channel is missing', (done) => { | ||
const scope = utils.createNock().get('/publish/*') | ||
.reply(200, '[1,"Sent","14647523059145592"]'); | ||
pubnub.publish({ message: { such: 'object' } }).catch((err) => { | ||
assert.equal(scope.isDone(), false); | ||
assert.equal(err.status.message, 'Missing Channel'); | ||
done(); | ||
}); | ||
}); | ||
}); | ||
it('publishes a complex object via GET', (done) => { | ||
@@ -67,2 +80,46 @@ const scope = utils.createNock().get('/publish/myPublishKey/mySubKey/0/ch1/0/%7B%22such%22%3A%22object%22%7D') | ||
it('supports ttl param', (done) => { | ||
const scope = utils.createNock().get('/publish/myPublishKey/mySubKey/0/ch1/0/%22toDEeIZkmIyoiLpSojGu7n3%2B2t1rn7%2FDsrEZ1r8JKR4%3D%22') | ||
.query({ pnsdk: 'PubNub-JS-Nodejs/' + pubnub.getVersion(), uuid: 'myUUID', auth: 'myAuthKey', ttl: '10' }) | ||
.reply(200, '[1,"Sent","14647523059145592"]'); | ||
pubnub.setCipherKey('myCipherKey'); | ||
pubnub.publish({ message: { such: 'object' }, channel: 'ch1', ttl: 10 }, (status, response) => { | ||
assert.equal(status.error, false); | ||
assert.deepEqual(response.timetoken, 14647523059145592); | ||
assert.equal(scope.isDone(), true); | ||
done(); | ||
}); | ||
}); | ||
it('supports storeInHistory=0', (done) => { | ||
const scope = utils.createNock().get('/publish/myPublishKey/mySubKey/0/ch1/0/%22toDEeIZkmIyoiLpSojGu7n3%2B2t1rn7%2FDsrEZ1r8JKR4%3D%22') | ||
.query({ pnsdk: 'PubNub-JS-Nodejs/' + pubnub.getVersion(), uuid: 'myUUID', auth: 'myAuthKey', store: '0' }) | ||
.reply(200, '[1,"Sent","14647523059145592"]'); | ||
pubnub.setCipherKey('myCipherKey'); | ||
pubnub.publish({ message: { such: 'object' }, channel: 'ch1', storeInHistory: false }, (status, response) => { | ||
assert.equal(status.error, false); | ||
assert.deepEqual(response.timetoken, 14647523059145592); | ||
assert.equal(scope.isDone(), true); | ||
done(); | ||
}); | ||
}); | ||
it('supports storeInHistory=1', (done) => { | ||
const scope = utils.createNock().get('/publish/myPublishKey/mySubKey/0/ch1/0/%22toDEeIZkmIyoiLpSojGu7n3%2B2t1rn7%2FDsrEZ1r8JKR4%3D%22') | ||
.query({ pnsdk: 'PubNub-JS-Nodejs/' + pubnub.getVersion(), uuid: 'myUUID', auth: 'myAuthKey', store: '1' }) | ||
.reply(200, '[1,"Sent","14647523059145592"]'); | ||
pubnub.setCipherKey('myCipherKey'); | ||
pubnub.publish({ message: { such: 'object' }, channel: 'ch1', storeInHistory: true }, (status, response) => { | ||
assert.equal(status.error, false); | ||
assert.deepEqual(response.timetoken, 14647523059145592); | ||
assert.equal(scope.isDone(), true); | ||
done(); | ||
}); | ||
}); | ||
it('publishes a complex object via POST', (done) => { | ||
@@ -69,0 +126,0 @@ const scope = utils.createNock().post('/publish/myPublishKey/mySubKey/0/ch1/0', '{"such":"object"}') |
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is too big to display
Sorry, the diff of this file is too big to display
Sorry, the diff of this file is 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
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
1562611
147
12930