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

@pusher/push-notifications-web

Package Overview
Dependencies
Maintainers
4
Versions
19
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

@pusher/push-notifications-web - npm Package Compare versions

Comparing version 2.0.0-beta.1 to 2.0.0-beta.2

284

dist/service-worker.js

@@ -1,6 +0,15 @@

// SDK version: v1.1.0
// Git commit: e0a22afcbdbf8bf554bab556f524825933394093
// SDK version: v2.0.0-beta.2
// Git commit: ad23547e5a32407210d378067c3e90f675a9bc9b
'use strict';
function unwrapExports (x) {
return x && x.__esModule && Object.prototype.hasOwnProperty.call(x, 'default') ? x['default'] : x;
}
function createCommonjsModule(fn, module) {
return module = { exports: {} }, fn(module, module.exports), module.exports;
}
var defineProperty = createCommonjsModule(function (module) {
function _defineProperty(obj, key, value) {

@@ -21,29 +30,51 @@ if (key in obj) {

var defineProperty = _defineProperty;
module.exports = _defineProperty;
module.exports["default"] = module.exports, module.exports.__esModule = true;
});
function _objectSpread(target) {
for (var i = 1; i < arguments.length; i++) {
var source = arguments[i] != null ? arguments[i] : {};
var ownKeys = Object.keys(source);
var _defineProperty = unwrapExports(defineProperty);
if (typeof Object.getOwnPropertySymbols === 'function') {
ownKeys = ownKeys.concat(Object.getOwnPropertySymbols(source).filter(function (sym) {
return Object.getOwnPropertyDescriptor(source, sym).enumerable;
}));
}
var asyncToGenerator = createCommonjsModule(function (module) {
function asyncGeneratorStep(gen, resolve, reject, _next, _throw, key, arg) {
try {
var info = gen[key](arg);
var value = info.value;
} catch (error) {
reject(error);
return;
}
ownKeys.forEach(function (key) {
defineProperty(target, key, source[key]);
});
if (info.done) {
resolve(value);
} else {
Promise.resolve(value).then(_next, _throw);
}
return target;
}
var objectSpread = _objectSpread;
function _asyncToGenerator(fn) {
return function () {
var self = this,
args = arguments;
return new Promise(function (resolve, reject) {
var gen = fn.apply(self, args);
function createCommonjsModule(fn, module) {
return module = { exports: {} }, fn(module, module.exports), module.exports;
function _next(value) {
asyncGeneratorStep(gen, resolve, reject, _next, _throw, "next", value);
}
function _throw(err) {
asyncGeneratorStep(gen, resolve, reject, _next, _throw, "throw", err);
}
_next(undefined);
});
};
}
module.exports = _asyncToGenerator;
module.exports["default"] = module.exports, module.exports.__esModule = true;
});
var _asyncToGenerator = unwrapExports(asyncToGenerator);
var runtime_1 = createCommonjsModule(function (module) {

@@ -67,2 +98,20 @@ /**

function define(obj, key, value) {
Object.defineProperty(obj, key, {
value: value,
enumerable: true,
configurable: true,
writable: true
});
return obj[key];
}
try {
// IE 8 has a broken Object.defineProperty that only works on DOM objects.
define({}, "");
} catch (err) {
define = function(obj, key, value) {
return obj[key] = value;
};
}
function wrap(innerFn, outerFn, self, tryLocsList) {

@@ -120,5 +169,5 @@ // If outerFn provided and outerFn.prototype is a Generator, then outerFn.prototype instanceof Generator.

var IteratorPrototype = {};
IteratorPrototype[iteratorSymbol] = function () {
define(IteratorPrototype, iteratorSymbol, function () {
return this;
};
});

@@ -137,6 +186,10 @@ var getProto = Object.getPrototypeOf;

Generator.prototype = Object.create(IteratorPrototype);
GeneratorFunction.prototype = Gp.constructor = GeneratorFunctionPrototype;
GeneratorFunctionPrototype.constructor = GeneratorFunction;
GeneratorFunctionPrototype[toStringTagSymbol] =
GeneratorFunction.displayName = "GeneratorFunction";
GeneratorFunction.prototype = GeneratorFunctionPrototype;
define(Gp, "constructor", GeneratorFunctionPrototype);
define(GeneratorFunctionPrototype, "constructor", GeneratorFunction);
GeneratorFunction.displayName = define(
GeneratorFunctionPrototype,
toStringTagSymbol,
"GeneratorFunction"
);

@@ -147,5 +200,5 @@ // Helper for defining the .next, .throw, and .return methods of the

["next", "throw", "return"].forEach(function(method) {
prototype[method] = function(arg) {
define(prototype, method, function(arg) {
return this._invoke(method, arg);
};
});
});

@@ -169,5 +222,3 @@ }

genFun.__proto__ = GeneratorFunctionPrototype;
if (!(toStringTagSymbol in genFun)) {
genFun[toStringTagSymbol] = "GeneratorFunction";
}
define(genFun, toStringTagSymbol, "GeneratorFunction");
}

@@ -186,3 +237,3 @@ genFun.prototype = Object.create(Gp);

function AsyncIterator(generator) {
function AsyncIterator(generator, PromiseImpl) {
function invoke(method, arg, resolve, reject) {

@@ -198,3 +249,3 @@ var record = tryCatch(generator[method], generator, arg);

hasOwn.call(value, "__await")) {
return Promise.resolve(value.__await).then(function(value) {
return PromiseImpl.resolve(value.__await).then(function(value) {
invoke("next", value, resolve, reject);

@@ -206,3 +257,3 @@ }, function(err) {

return Promise.resolve(value).then(function(unwrapped) {
return PromiseImpl.resolve(value).then(function(unwrapped) {
// When a yielded Promise is resolved, its final value becomes

@@ -225,3 +276,3 @@ // the .value of the Promise<{value,done}> result for the

function callInvokeWithMethodAndArg() {
return new Promise(function(resolve, reject) {
return new PromiseImpl(function(resolve, reject) {
invoke(method, arg, resolve, reject);

@@ -258,5 +309,5 @@ });

defineIteratorMethods(AsyncIterator.prototype);
AsyncIterator.prototype[asyncIteratorSymbol] = function () {
define(AsyncIterator.prototype, asyncIteratorSymbol, function () {
return this;
};
});
exports.AsyncIterator = AsyncIterator;

@@ -267,5 +318,8 @@

// the final result produced by the iterator.
exports.async = function(innerFn, outerFn, self, tryLocsList) {
exports.async = function(innerFn, outerFn, self, tryLocsList, PromiseImpl) {
if (PromiseImpl === void 0) PromiseImpl = Promise;
var iter = new AsyncIterator(
wrap(innerFn, outerFn, self, tryLocsList)
wrap(innerFn, outerFn, self, tryLocsList),
PromiseImpl
);

@@ -445,3 +499,3 @@

Gp[toStringTagSymbol] = "Generator";
define(Gp, toStringTagSymbol, "Generator");

@@ -453,9 +507,9 @@ // A Generator should always return itself as the iterator object when the

// See https://github.com/facebook/regenerator/issues/274 for more details.
Gp[iteratorSymbol] = function() {
define(Gp, iteratorSymbol, function() {
return this;
};
});
Gp.toString = function() {
define(Gp, "toString", function() {
return "[object Generator]";
};
});

@@ -771,3 +825,3 @@ function pushTryEntry(locs) {

// the regeneratorRuntime variable at the top of this file.
module.exports
module.exports
));

@@ -780,3 +834,4 @@

// assignment should always work unless something is misconfigured. Just
// in case runtime.js accidentally runs in strict mode, we can escape
// in case runtime.js accidentally runs in strict mode, in modern engines
// we can explicitly access globalThis. In older engines we can escape
// strict mode using a global Function call. This could conceivably fail

@@ -788,3 +843,7 @@ // if a Content Security Policy forbids using Function, but in that case

// problems, please detail your unique predicament in a GitHub issue.
Function("r", "regeneratorRuntime = r")(runtime);
if (typeof globalThis === "object") {
globalThis.regeneratorRuntime = runtime;
} else {
Function("r", "regeneratorRuntime = r")(runtime);
}
}

@@ -795,40 +854,6 @@ });

function asyncGeneratorStep(gen, resolve, reject, _next, _throw, key, arg) {
try {
var info = gen[key](arg);
var value = info.value;
} catch (error) {
reject(error);
return;
}
function ownKeys(object, enumerableOnly) { var keys = Object.keys(object); if (Object.getOwnPropertySymbols) { var symbols = Object.getOwnPropertySymbols(object); if (enumerableOnly) { symbols = symbols.filter(function (sym) { return Object.getOwnPropertyDescriptor(object, sym).enumerable; }); } keys.push.apply(keys, symbols); } return keys; }
if (info.done) {
resolve(value);
} else {
Promise.resolve(value).then(_next, _throw);
}
}
function _objectSpread(target) { for (var i = 1; i < arguments.length; i++) { var source = arguments[i] != null ? arguments[i] : {}; if (i % 2) { ownKeys(Object(source), true).forEach(function (key) { _defineProperty(target, key, source[key]); }); } else if (Object.getOwnPropertyDescriptors) { Object.defineProperties(target, Object.getOwnPropertyDescriptors(source)); } else { ownKeys(Object(source)).forEach(function (key) { Object.defineProperty(target, key, Object.getOwnPropertyDescriptor(source, key)); }); } } return target; }
function _asyncToGenerator(fn) {
return function () {
var self = this,
args = arguments;
return new Promise(function (resolve, reject) {
var gen = fn.apply(self, args);
function _next(value) {
asyncGeneratorStep(gen, resolve, reject, _next, _throw, "next", value);
}
function _throw(err) {
asyncGeneratorStep(gen, resolve, reject, _next, _throw, "throw", err);
}
_next(undefined);
});
};
}
var asyncToGenerator = _asyncToGenerator;
function doRequest(_ref) {

@@ -851,3 +876,3 @@ var method = _ref.method,

options.body = JSON.stringify(body);
options.headers = objectSpread({
options.headers = _objectSpread({
'Content-Type': 'application/json'

@@ -857,8 +882,4 @@ }, headers);

return fetch(path, options).then(
/*#__PURE__*/
function () {
var _ref2 = asyncToGenerator(
/*#__PURE__*/
regenerator.mark(function _callee(response) {
return fetch(path, options).then( /*#__PURE__*/function () {
var _ref2 = _asyncToGenerator( /*#__PURE__*/regenerator.mark(function _callee(response) {
return regenerator.wrap(function _callee$(_context) {

@@ -908,6 +929,4 @@ while (1) {

function _handleError() {
_handleError = asyncToGenerator(
/*#__PURE__*/
regenerator.mark(function _callee2(response) {
var errorMessage, _ref3, _ref3$error, error, _ref3$description, description;
_handleError = _asyncToGenerator( /*#__PURE__*/regenerator.mark(function _callee2(response) {
var errorMessage, _yield$response$json, _yield$response$json$, error, _yield$response$json$2, description;

@@ -923,7 +942,7 @@ return regenerator.wrap(function _callee2$(_context2) {

case 3:
_ref3 = _context2.sent;
_ref3$error = _ref3.error;
error = _ref3$error === void 0 ? 'Unknown error' : _ref3$error;
_ref3$description = _ref3.description;
description = _ref3$description === void 0 ? 'No description' : _ref3$description;
_yield$response$json = _context2.sent;
_yield$response$json$ = _yield$response$json.error;
error = _yield$response$json$ === void 0 ? 'Unknown error' : _yield$response$json$;
_yield$response$json$2 = _yield$response$json.description;
description = _yield$response$json$2 === void 0 ? 'No description' : _yield$response$json$2;
errorMessage = "Unexpected status code ".concat(response.status, ": ").concat(error, ", ").concat(description);

@@ -951,2 +970,3 @@ _context2.next = 14;

var classCallCheck = createCommonjsModule(function (module) {
function _classCallCheck(instance, Constructor) {

@@ -958,4 +978,9 @@ if (!(instance instanceof Constructor)) {

var classCallCheck = _classCallCheck;
module.exports = _classCallCheck;
module.exports["default"] = module.exports, module.exports.__esModule = true;
});
var _classCallCheck = unwrapExports(classCallCheck);
var createClass = createCommonjsModule(function (module) {
function _defineProperties(target, props) {

@@ -977,9 +1002,11 @@ for (var i = 0; i < props.length; i++) {

var createClass = _createClass;
module.exports = _createClass;
module.exports["default"] = module.exports, module.exports.__esModule = true;
});
var DeviceStateStore =
/*#__PURE__*/
function () {
var _createClass = unwrapExports(createClass);
var DeviceStateStore = /*#__PURE__*/function () {
function DeviceStateStore(instanceId) {
classCallCheck(this, DeviceStateStore);
_classCallCheck(this, DeviceStateStore);

@@ -990,3 +1017,13 @@ this._instanceId = instanceId;

createClass(DeviceStateStore, [{
_createClass(DeviceStateStore, [{
key: "_dbName",
get: function get() {
return "beams-".concat(this._instanceId);
}
}, {
key: "isConnected",
get: function get() {
return this._dbConn !== null;
}
}, {
key: "connect",

@@ -1061,5 +1098,3 @@ value: function connect() {

value: function () {
var _readProperty2 = asyncToGenerator(
/*#__PURE__*/
regenerator.mark(function _callee(name) {
var _readProperty2 = _asyncToGenerator( /*#__PURE__*/regenerator.mark(function _callee(name) {
var state;

@@ -1124,5 +1159,3 @@ return regenerator.wrap(function _callee$(_context) {

value: function () {
var _writeProperty2 = asyncToGenerator(
/*#__PURE__*/
regenerator.mark(function _callee2(name, value) {
var _writeProperty2 = _asyncToGenerator( /*#__PURE__*/regenerator.mark(function _callee2(name, value) {
var state;

@@ -1206,12 +1239,2 @@ return regenerator.wrap(function _callee2$(_context2) {

}
}, {
key: "_dbName",
get: function get() {
return "beams-".concat(this._instanceId);
}
}, {
key: "isConnected",
get: function get() {
return this._dbConn !== null;
}
}]);

@@ -1222,2 +1245,5 @@

function ownKeys$1(object, enumerableOnly) { var keys = Object.keys(object); if (Object.getOwnPropertySymbols) { var symbols = Object.getOwnPropertySymbols(object); if (enumerableOnly) { symbols = symbols.filter(function (sym) { return Object.getOwnPropertyDescriptor(object, sym).enumerable; }); } keys.push.apply(keys, symbols); } return keys; }
function _objectSpread$1(target) { for (var i = 1; i < arguments.length; i++) { var source = arguments[i] != null ? arguments[i] : {}; if (i % 2) { ownKeys$1(Object(source), true).forEach(function (key) { _defineProperty(target, key, source[key]); }); } else if (Object.getOwnPropertyDescriptors) { Object.defineProperties(target, Object.getOwnPropertyDescriptors(source)); } else { ownKeys$1(Object(source)).forEach(function (key) { Object.defineProperty(target, key, Object.getOwnPropertyDescriptor(source, key)); }); } } return target; }
self.PusherPushNotifications = {

@@ -1260,5 +1286,3 @@ endpointOverride: null,

reportEvent: function () {
var _reportEvent = asyncToGenerator(
/*#__PURE__*/
regenerator.mark(function _callee(_ref) {
var _reportEvent = _asyncToGenerator( /*#__PURE__*/regenerator.mark(function _callee(_ref) {
var eventType, pusherMetadata, instanceId, publishId, hasDisplayableContent, hasData, deviceStateStore, deviceId, userId, appInBackground, path, options;

@@ -1371,3 +1395,3 @@ return regenerator.wrap(function _callee$(_context) {

var customerPayload = objectSpread({}, payload);
var customerPayload = _objectSpread$1({}, payload);

@@ -1383,8 +1407,4 @@ var customerData = {};

var handleNotification =
/*#__PURE__*/
function () {
var _ref2 = asyncToGenerator(
/*#__PURE__*/
regenerator.mark(function _callee2(payloadFromCallback) {
var handleNotification = /*#__PURE__*/function () {
var _ref2 = _asyncToGenerator( /*#__PURE__*/regenerator.mark(function _callee2(payloadFromCallback) {
var hideNotificationIfSiteHasFocus, title, body, icon, options;

@@ -1391,0 +1411,0 @@ return regenerator.wrap(function _callee2$(_context2) {

{
"name": "@pusher/push-notifications-web",
"version": "2.0.0-beta.1",
"version": "2.0.0-beta.2",
"description": "",

@@ -5,0 +5,0 @@ "main": "dist/push-notifications-esm.js",

@@ -7,3 +7,3 @@ import { WebPushClient } from './web-push-client';

function Client(config) {
if ('safari' in window) {
if (isSafari()) {
return new SafariClient(config);

@@ -14,2 +14,9 @@ }

function isSafari() {
return (
window.navigator.userAgent.indexOf('Safari') > -1 &&
window.navigator.userAgent.indexOf('Chrome') === -1
);
}
export { Client, RegistrationState, TokenProvider };

@@ -47,28 +47,2 @@ import * as PusherPushNotifications from './push-notifications';

test('will throw if the SDK is loaded from a context that is not secure', () => {
setUpGlobals({ isSecureContext: false });
const instanceId = 'df3c1965-e870-4bd6-8d75-fea56b26335f';
return expect(
() => new PusherPushNotifications.Client({ instanceId })
).toThrow(
'Pusher Beams relies on Service Workers, which only work in secure contexts'
);
});
test('will throw if ServiceWorkerRegistration not supported', () => {
setUpGlobals({ serviceWorkerSupport: false });
const instanceId = 'df3c1965-e870-4bd6-8d75-fea56b26335f';
return expect(
() => new PusherPushNotifications.Client({ instanceId })
).toThrow('Service Workers not supported');
});
test('will throw if Web Push not supported', () => {
setUpGlobals({ webPushSupport: false });
const instanceId = 'df3c1965-e870-4bd6-8d75-fea56b26335f';
return expect(
() => new PusherPushNotifications.Client({ instanceId })
).toThrow('Web Push not supported');
});
test('will return properly configured instance otherwise', () => {

@@ -688,2 +662,40 @@ const PusherPushNotifications = require('./push-notifications');

describe('.browserIsSupported', () => {
afterEach(() => {
jest.resetModules();
tearDownGlobals();
});
test('will resolve to false if the SDK is loaded from a context that is not secure', () => {
setUpGlobals({ isSecureContext: false });
const instanceId = 'df3c1965-e870-4bd6-8d75-fea56b26335f';
const client = new PusherPushNotifications.Client({ instanceId });
return client.isSupportedBrowser().then(result => {
expect(result).toEqual(false);
expect(client.error).toMatch(
'Pusher Beams relies on Service Workers, which only work in secure contexts'
);
});
});
test('will resolve to false if ServiceWorkerRegistration not supported', () => {
setUpGlobals({ serviceWorkerSupport: false });
const instanceId = 'df3c1965-e870-4bd6-8d75-fea56b26335f';
const client = new PusherPushNotifications.Client({ instanceId });
return client.isSupportedBrowser().then(result => {
expect(result).toEqual(false);
expect(client.error).toMatch('Service Workers not supported');
});
});
test('will resolve to false if Web Push not supported', () => {
setUpGlobals({ webPushSupport: false });
const instanceId = 'df3c1965-e870-4bd6-8d75-fea56b26335f';
const client = new PusherPushNotifications.Client({ instanceId });
return client.isSupportedBrowser().then(result => {
expect(result).toEqual(false);
expect(client.error).toMatch('Web Push not supported');
});
});
});
const setUpGlobals = ({

@@ -690,0 +702,0 @@ indexedDBSupport = true,

@@ -11,14 +11,19 @@ import doRequest from './do-request';

super(config, platform);
this._ready = this._init();
}
async _init() {
this.error = null;
if (!this._isSupportedBrowser()) {
throw new Error(
'Pusher Beams does not support this Safari version (Safari Push Notifications not supported)'
);
this.error = 'Pusher Beams does not support this Safari version';
return;
}
this._ready = this._init();
}
this._websitePushId = await this._fetchWebsitePushId();
if (this._websitePushId === null) {
this.error =
'Safari credentials are not configured for this Pusher Beams instance';
return;
}
async _init() {
let { websitePushId } = await this._fetchWebsitePushId();
this._websitePushId = websitePushId;
this._serviceUrl = `${

@@ -164,3 +169,3 @@ this._baseURL

_fetchWebsitePushId() {
async _fetchWebsitePushId() {
const path = `${this._baseURL}/device_api/v1/instances/${encodeURIComponent(

@@ -171,8 +176,25 @@ this.instanceId

const options = { method: 'GET', path };
return doRequest(options);
try {
let { websitePushId } = await doRequest(options);
return websitePushId;
} catch (err) {
if (err.message.match(/Unexpected status code 404/)) {
return null;
}
throw err;
}
}
_isSupportedBrowser() {
return 'safari' in window && 'pushNotification' in window.safari;
return (
'safari' in window &&
'pushNotification' in window.safari &&
'indexedDB' in window
);
}
async isSupportedBrowser() {
await this._ready;
return this.error === null;
}
}

@@ -179,0 +201,0 @@

@@ -13,18 +13,19 @@ import doRequest from './do-request';

this.error = null;
if (!window.isSecureContext) {
throw new Error(
'Pusher Beams relies on Service Workers, which only work in secure contexts. Check that your page is being served from localhost/over HTTPS'
);
this.error =
'Pusher Beams relies on Service Workers, which only work in secure contexts. Check that your page is being served from localhost/over HTTPS';
return;
}
if (!('serviceWorker' in navigator)) {
throw new Error(
'Pusher Beams does not support this browser version (Service Workers not supported)'
);
this.error =
'Pusher Beams does not support this browser version (Service Workers not supported)';
return;
}
if (!('PushManager' in window)) {
throw new Error(
'Pusher Beams does not support this browser version (Web Push not supported)'
);
this.error =
'Pusher Beams does not support this browser version (Web Push not supported)';
return;
}

@@ -234,2 +235,7 @@

}
async isSupportedBrowser() {
await this._ready;
return this.error === null;
}
}

@@ -236,0 +242,0 @@

Sorry, the diff of this file is too big to display

Sorry, the diff of this file is too big to display

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