kinvey-flex-sdk
Advanced tools
Comparing version 3.0.0-beta.2 to 3.0.0
## Changelog | ||
### 3.0.0 | ||
* See README for migration guide | ||
* BREAKING CHANGE: email and push modules now require a callback or promise handlers. They can no longer be executed as "fire and forget". | ||
@@ -5,0 +6,0 @@ * FLEX-206 Added Promise support to Asynchronous flex-sdk modules |
@@ -22,4 +22,19 @@ /** | ||
if (!to || !from || !subject || !textBody) { | ||
throw new Error("To send an email, you must specify the 'to', 'from', " + | ||
"'subject' and 'body' parameters"); | ||
// find the callback function, if it exists | ||
if (!callback || (callback && typeof callback !== 'function')) { | ||
if (typeof bcc === 'function') callback = bcc; | ||
else if (typeof cc === 'function') callback = cc; | ||
else if (typeof htmlBody === 'function') callback = htmlBody; | ||
else if (typeof replyTo === 'function') callback = replyTo; | ||
else if (typeof textBody === 'function') callback = textBody; | ||
else if (typeof subject === 'function') callback = subject; | ||
else if (typeof to === 'function') callback = to; | ||
else if (typeof from === 'function') callback = from; | ||
else callback = undefined; | ||
} | ||
const err = new Error('EmailError'); | ||
err.description = 'Invalid Arguments'; | ||
err.debug = "To send an email, you must specify the 'to', 'from', 'subject' and 'body' parameters"; | ||
return callback ? setImmediate(() => callback(err)) : Promise.reject(err); | ||
} | ||
@@ -26,0 +41,0 @@ |
@@ -28,4 +28,14 @@ /** | ||
function sendMessage(userEntities, message, callback) { | ||
if (userEntities == null) throw new TypeError(MISSING_USER_PARAM_ERROR); | ||
if (message == null) throw new TypeError(MISSING_MESSAGE_PARAM_ERROR); | ||
if (userEntities == null) { | ||
if (!callback && typeof message === 'function') callback = message; | ||
const err = new TypeError(MISSING_USER_PARAM_ERROR); | ||
return callback ? setImmediate(() => callback(err)) : Promise.reject(err); | ||
} | ||
if (message == null) { | ||
if (!callback && typeof userEntities === 'function') callback = userEntities; | ||
const err = new TypeError(MISSING_MESSAGE_PARAM_ERROR); | ||
return callback ? setImmediate(() => callback(err)) : Promise.reject(err); | ||
} | ||
if (userEntities.constructor !== Array && typeof userEntities === 'object') userEntities = [userEntities]; | ||
@@ -55,3 +65,4 @@ | ||
if (message == null) { | ||
throw new TypeError(MISSING_MESSAGE_PARAM_ERROR); | ||
const err = new TypeError(MISSING_MESSAGE_PARAM_ERROR); | ||
return callback ? setImmediate(() => callback(err)) : Promise.reject(err); | ||
} | ||
@@ -58,0 +69,0 @@ |
@@ -213,2 +213,9 @@ /** | ||
if (Array.isArray(userId) || Array.isArray(roleId)) { | ||
const err = new Error('UserStoreError'); | ||
err.description = 'Bad Request'; | ||
err.debug = 'Bulk role assignment is not currently supported.'; | ||
return callback ? setImmediate(() => callback(err)) : Promise.reject(err); | ||
} | ||
const requestOptions = this._buildUserRequest(); | ||
@@ -241,2 +248,9 @@ | ||
if (Array.isArray(userId) || Array.isArray(roleId)) { | ||
const err = new Error('UserStoreError'); | ||
err.description = 'Bad Request'; | ||
err.debug = 'Bulk role revocation is not currently supported.'; | ||
return callback ? setImmediate(() => callback(err)) : Promise.reject(err); | ||
} | ||
const requestOptions = this._buildUserRequest(); | ||
@@ -243,0 +257,0 @@ |
{ | ||
"name": "kinvey-flex-sdk", | ||
"version": "3.0.0-beta.2", | ||
"version": "3.0.0", | ||
"description": "SDK for creating Kinvey Flex Services", | ||
@@ -5,0 +5,0 @@ "engines": { |
@@ -5,2 +5,11 @@ # Kinvey Flex SDK (beta) | ||
## Upgrading from 2.x to 3.x | ||
Flex-sdk 3.x contains several breaking changes as well as new features. To upgrade your service from Flex-sdk 2.x to 3.x: | ||
* All email and push methods now return a promise. It is now required that you either handle the promise, or pass a callback. | ||
* For all stores (e.g. dataStore, userStore, etc), the deprecated options `skipBl` and `useMasterSecret` have been removed and no longer function. Use `useBl` and `useUserContext` instead. | ||
* All asynchonous modules (dataStore, groupStore, roleStore, endpointRunner, userStore, email, and push) now return a promise or accept a callback. | ||
* For more information on what's new, see the [Changelog](CHANGELOG.md). | ||
## [Official documentation](#docs) | ||
@@ -19,7 +28,2 @@ * [Kinvey FlexServices guide](http://devcenter.kinvey.com/nodejs/guides/flex-services) | ||
Or install it with `yarn`: | ||
``` | ||
yarn add kinvey-flex-sdk | ||
``` | ||
To use this module, require it in your project as such: | ||
@@ -130,2 +134,2 @@ ``` | ||
## Support | ||
Please contact Kinvey for further information or questions | ||
Please contact Kinvey for further information or questions |
@@ -85,10 +85,10 @@ /** | ||
it('throws if \'from\', \'to\', \'subject\' and \'textBody\' are not all specified', (done) => { | ||
(() => emailInstance.send()).should.throw(); | ||
(() => emailInstance.send('from')).should.throw(); | ||
(() => emailInstance.send('from', 'to')).should.throw(); | ||
(() => emailInstance.send('from', 'to', 'subject')).should.throw(); | ||
(() => emailInstance.send(null, 'to', 'subject', 'textBody')).should.throw(); | ||
(() => emailInstance.send('from', null, 'subject', 'textBody')).should.throw(); | ||
(() => emailInstance.send('from', 'to', null, 'textBody')).should.throw(); | ||
it('rejects if \'from\', \'to\', \'subject\' and \'textBody\' are not all specified', (done) => { | ||
(emailInstance.send()).should.be.rejected(); | ||
(emailInstance.send('from')).should.be.rejected(); | ||
(emailInstance.send('from', 'to')).should.be.rejected(); | ||
(emailInstance.send('from', 'to', 'subject')).should.be.rejected(); | ||
(emailInstance.send(null, 'to', 'subject', 'textBody')).should.be.rejected(); | ||
(emailInstance.send('from', null, 'subject', 'textBody')).should.be.rejected(); | ||
(emailInstance.send('from', 'to', null, 'textBody')).should.be.rejected(); | ||
return done(); | ||
@@ -95,0 +95,0 @@ }); |
@@ -163,12 +163,12 @@ /** | ||
it('throws an error if no receipents are specified', (done) => { | ||
it('rejects if no receipents are specified', (done) => { | ||
requestStub.post.callsArgWith(1, {}); | ||
(() => pushInstance.send(null, 'hello')).should.throw(/.*users.*/); | ||
(() => pushInstance.send()).should.throw(/.*users.*/); | ||
(pushInstance.send(null, 'hello')).should.be.rejected(/.*users.*/); | ||
(pushInstance.send()).should.be.rejected(/.*users.*/); | ||
return done(); | ||
}); | ||
it('throws an error if no message is specified', (done) => { | ||
it('rejects if no message is specified', (done) => { | ||
requestStub.post.callsArgWith(1, {}); | ||
(() => pushInstance.send(recipients, null)).should.throw(/.*message.*/); | ||
(pushInstance.send(recipients, null)).should.be.rejected(/.*message.*/); | ||
return done(); | ||
@@ -272,6 +272,6 @@ }); | ||
it('throws an error if no message is specified', (done) => { | ||
it('rejects if no message is specified', (done) => { | ||
requestStub.post.callsArgWith(1, {}); | ||
(() => pushInstance.broadcast()).should.throw(/.*message.*/); | ||
(() => pushInstance.broadcast(null)).should.throw(/.*message.*/); | ||
(pushInstance.broadcast()).should.be.rejected(/.*message.*/); | ||
(pushInstance.broadcast(null)).should.be.rejected(/.*message.*/); | ||
return done(); | ||
@@ -370,6 +370,6 @@ }); | ||
it('throws an error if no receipents are specified', (done) => { | ||
it('rejects if no receipents are specified', (done) => { | ||
requestStub.post.callsArgWith(1, {}); | ||
(() => pushInstance.sendPayload(null, iOSAps, iOSExtras, androidPayload)).should.throw(/.*users.*/); | ||
(() => pushInstance.sendPayload()).should.throw(/.*users.*/); | ||
(pushInstance.sendPayload(null, iOSAps, iOSExtras, androidPayload)).should.be.rejected(/.*users.*/); | ||
(pushInstance.sendPayload()).should.be.rejected(/.*users.*/); | ||
return done(); | ||
@@ -376,0 +376,0 @@ }); |
Sorry, the diff of this file is too big to display
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
No v1
QualityPackage is not semver >=1. This means it is not stable and does not support ^ ranges.
Found 1 instance in 1 package
645169
14560
1
133