Comparing version 1.7.7 to 1.7.8
## Changelog | ||
1.7.8: | ||
* Add support for Mutable Content (#413) | ||
1.7.7: | ||
@@ -4,0 +8,0 @@ |
@@ -67,2 +67,14 @@ "use strict"; | ||
get mutableContent() { | ||
return this._mutableContent; | ||
}, | ||
set mutableContent(value) { | ||
this.compiled = false; | ||
if (value === 1 || value === true) { | ||
this._mutableContent = 1; | ||
return; | ||
} | ||
this._mutableContent = undefined; | ||
}, | ||
get newsstandAvailable() { | ||
@@ -125,2 +137,3 @@ return this.contentAvailable; | ||
notification.contentAvailable = this.contentAvailable; | ||
notification.mutableContent = this.mutableContent; | ||
notification.mdm = this.mdm; | ||
@@ -328,2 +341,12 @@ notification.truncateAtWordEnd = this.truncateAtWordEnd; | ||
/** | ||
* Set the 'mutable-content' flag on the payload | ||
* @param {Boolean} [mutableContent] Whether the mutable-content flag should be set or not. | ||
* @since v1.7.8 | ||
*/ | ||
Notification.prototype.setMutableContent = function (mutableContent) { | ||
this.mutableContent = mutableContent; | ||
return this; | ||
}; | ||
/** | ||
* Set the 'mdm' flag on the payload | ||
@@ -409,3 +432,3 @@ * @param {Object} [mdm] The mdm property for the payload. | ||
} | ||
escaped = JSON.stringify(escaped).slice(1, -1); // trim quotes | ||
@@ -459,3 +482,3 @@ length = Buffer.byteLength(escaped, encoding); | ||
var result = new Buffer(string, encoding).toString(encoding, 0, length); | ||
if (this.truncateAtWordEnd === true) { | ||
@@ -494,3 +517,7 @@ var lastSpaceIndexInResult = result.lastIndexOf(" "); | ||
} | ||
if (this.mutableContent) { | ||
aps["mutable-content"] = 1; | ||
} | ||
aps["url-args"] = this.urlArgs || aps["url-args"]; | ||
@@ -509,3 +536,3 @@ aps.category = this.category || aps.category; | ||
} | ||
this.payload.aps = this.apsPayload(); | ||
@@ -512,0 +539,0 @@ |
{ | ||
"name": "apn", | ||
"description": "An interface to the Apple Push Notification service for Node.js", | ||
"version": "1.7.7", | ||
"version": "1.7.8", | ||
"author": "Andrew Naylor <argon@mkbot.net>", | ||
@@ -6,0 +6,0 @@ "contributors": [ |
@@ -271,3 +271,3 @@ var rewire = require("rewire"); | ||
var connection = Connection({ pfx: "myCredentials.pfx" }); | ||
return connection.createSocket().finally(function() { | ||
connection.createSocket().finally(function() { | ||
expect(connection.loadCredentials).to.have.been.calledOnce; | ||
@@ -274,0 +274,0 @@ done(); |
@@ -266,3 +266,3 @@ var rewire = require("rewire"); | ||
var feedback = Feedback({ pfx: "myCredentials.pfx" }); | ||
return feedback.createSocket().finally(function() { | ||
feedback.createSocket().finally(function() { | ||
expect(feedback.loadCredentials).to.have.been.calledOnce; | ||
@@ -269,0 +269,0 @@ done(); |
@@ -175,2 +175,47 @@ var apn = require("../"); | ||
describe("mutable-content property", function() { | ||
it("defaults to undefined", function() { | ||
expect(note.mutableContent).to.be.undefined; | ||
}); | ||
it("can be set to `1` with a boolean value", function() { | ||
note.mutableContent = true; | ||
expect(note.mutableContent).to.equal(1); | ||
}); | ||
it("resets the `compiled` flag when enabled", function() { | ||
note.compiled = true; | ||
note.mutableContent = true; | ||
expect(note.compiled).to.be.false; | ||
}); | ||
it("resets the `compiled` flag when disabled", function() { | ||
note.compiled = true; | ||
note.mutableContent = false; | ||
expect(note.compiled).to.be.false; | ||
}); | ||
it("can be set to undefined", function() { | ||
note.mutableContent = true; | ||
note.mutableContent = undefined; | ||
expect(note.mutableContent).to.be.undefined; | ||
}); | ||
it("can be set to `1`", function() { | ||
note.mutableContent = 1; | ||
expect(typeof note.mutableContent).to.equal("number"); | ||
}); | ||
it("cannot be set to a string", function() { | ||
note.mutableContent = "true"; | ||
expect(note.mutableContent).to.be.undefined; | ||
}); | ||
it("can be disabled", function() { | ||
note.mutableContent = false; | ||
expect(note.mutableContent).to.be.undefined; | ||
}); | ||
}); | ||
describe("mdm property", function() { | ||
@@ -342,3 +387,3 @@ it("defaults to undefined", function() { | ||
}); | ||
it("trims notification alert body to reduce payload to maximum length", function () { | ||
@@ -402,3 +447,3 @@ note.alert = { | ||
}); | ||
it("leaves escaped escape character intact", function() { | ||
@@ -473,3 +518,3 @@ note.alert = "test\\ message"; | ||
}); | ||
it("correctly empties the string", function() { | ||
@@ -635,3 +680,3 @@ note.alert = Buffer([0x3D, 0xD8, 0x03, 0xDE, 0x3D, 0xD8, 0x1E, 0xDE]).toString(note.encoding); | ||
note.contentAvailable = true; | ||
expect(note.toJSON().aps["content-available"]).to.eql(1); | ||
@@ -643,5 +688,5 @@ }); | ||
it("does not set the 'content-available' flag", function() { | ||
note.alert = "message"; | ||
note.alert = "message"; | ||
note.contentAvailable = false; | ||
expect(note.toJSON().aps["content-available"]).to.be.undefined; | ||
@@ -651,2 +696,19 @@ }); | ||
describe("with mutableContent property", function() { | ||
it("sets the 'mutable-content' flag", function() { | ||
note.mutableContent = true; | ||
expect(note.toJSON().aps["mutable-content"]).to.eql(1); | ||
}); | ||
}); | ||
describe("with mutableContent property disabled", function() { | ||
it("does not set the 'mutable-content' flag", function() { | ||
note.alert = "message"; | ||
note.mutableContent = false; | ||
expect(note.toJSON().aps["mutable-content"]).to.be.undefined; | ||
}); | ||
}); | ||
describe("with newsstandAvailable property", function() { | ||
@@ -653,0 +715,0 @@ it("sets the 'content-available' flag", function() { |
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
247898
3904