@garbarino/gb-jscommons
Advanced tools
Comparing version 1.2.0 to 1.3.0
@@ -63,20 +63,14 @@ (function webpackUniversalModuleDefinition(root, factory) { | ||
function sendSubscriptionToBackEnd(subscription, brand) { | ||
return fetch('/api/save-subscription/', { | ||
function sendSubscriptionToBackEnd(subscription, platform) { | ||
return fetch('/normandia/services/push_tokens', { | ||
method: 'POST', | ||
headers: { | ||
'Content-Type': 'application/json', | ||
'x-api-key': '32223507-c36c-42c2-b52d-b3f1d65fa5ae' | ||
'Content-Type': 'application/json' | ||
}, | ||
body: JSON.stringify(subscription) | ||
}).then(function (response) { | ||
if (!response.ok) { | ||
throw new Error('Bad status code from server.'); | ||
} | ||
return response.json(); | ||
}).then(function (responseData) { | ||
if (!(responseData.data && responseData.data.success)) { | ||
throw new Error('Bad response from server.'); | ||
} | ||
body: { | ||
"registration_token": subscription.registration_token, | ||
"platform": platform || "", | ||
"keys": subscription.keys | ||
}, | ||
credentials: "same-origin" | ||
}); | ||
@@ -83,0 +77,0 @@ } |
@@ -1,1 +0,1 @@ | ||
!function(e,n){"object"==typeof exports&&"object"==typeof module?module.exports=n():"function"==typeof define&&define.amd?define([],n):"object"==typeof exports?exports["push-notifications"]=n():(e.gbJsCommons=e.gbJsCommons||{},e.gbJsCommons["push-notifications"]=n())}("undefined"!=typeof self?self:this,function(){return function(e){function n(r){if(t[r])return t[r].exports;var o=t[r]={i:r,l:!1,exports:{}};return e[r].call(o.exports,o,o.exports,n),o.l=!0,o.exports}var t={};return n.m=e,n.c=t,n.d=function(e,t,r){n.o(e,t)||Object.defineProperty(e,t,{configurable:!1,enumerable:!0,get:r})},n.n=function(e){var t=e&&e.__esModule?function(){return e.default}:function(){return e};return n.d(t,"a",t),t},n.o=function(e,n){return Object.prototype.hasOwnProperty.call(e,n)},n.p="",n(n.s=0)}([function(e,n,t){"use strict";function r(){return"serviceWorker"in navigator&&"PushManager"in window}Object.defineProperty(n,"__esModule",{value:!0}),n.isCompatible=r,n.canAskForPermission=function(){return r()&&"denied"!==Notification.permission},n.subscribeUserToPush=function(){return r()?navigator.serviceWorker.getRegistration().then(function(e){var n={userVisibleOnly:!0,applicationServerKey:o};return e.pushManager.subscribe(n)}).then(function(e){return console.log("Received PushSubscription: ",JSON.stringify(e)),e}):Promise.reject("Push notifications not compatible")},n.getSubscription=function(){return r()?navigator.serviceWorker.getRegistration().then(function(e){return e.pushManager.getSubscription()}):Promise.reject("Push notifications not compatible")},n.sendSubscriptionToBackEnd=function(e,n){return fetch("/api/save-subscription/",{method:"POST",headers:{"Content-Type":"application/json","x-api-key":"32223507-c36c-42c2-b52d-b3f1d65fa5ae"},body:JSON.stringify(e)}).then(function(e){if(!e.ok)throw new Error("Bad status code from server.");return e.json()}).then(function(e){if(!e.data||!e.data.success)throw new Error("Bad response from server.")})};var o=function(e){for(var n=(e+"=".repeat((4-e.length%4)%4)).replace(/\-/g,"+").replace(/_/g,"/"),t="undefined"!=typeof window?window.atob(n):"",r=new Uint8Array(t.length),o=0;o<t.length;++o)r[o]=t.charCodeAt(o);return r}("BEl62iUYgUivxIkv69yViEuiBIa-Ib9-SkvMeAtA3LFgDzkrxZJjSgSnfckjBJuBkr3qBUYIHBQFLXYp5Nksh8U")}])}); | ||
!function(e,n){"object"==typeof exports&&"object"==typeof module?module.exports=n():"function"==typeof define&&define.amd?define([],n):"object"==typeof exports?exports["push-notifications"]=n():(e.gbJsCommons=e.gbJsCommons||{},e.gbJsCommons["push-notifications"]=n())}("undefined"!=typeof self?self:this,function(){return function(e){function n(o){if(t[o])return t[o].exports;var r=t[o]={i:o,l:!1,exports:{}};return e[o].call(r.exports,r,r.exports,n),r.l=!0,r.exports}var t={};return n.m=e,n.c=t,n.d=function(e,t,o){n.o(e,t)||Object.defineProperty(e,t,{configurable:!1,enumerable:!0,get:o})},n.n=function(e){var t=e&&e.__esModule?function(){return e.default}:function(){return e};return n.d(t,"a",t),t},n.o=function(e,n){return Object.prototype.hasOwnProperty.call(e,n)},n.p="",n(n.s=0)}([function(e,n,t){"use strict";function o(){return"serviceWorker"in navigator&&"PushManager"in window}Object.defineProperty(n,"__esModule",{value:!0}),n.isCompatible=o,n.canAskForPermission=function(){return o()&&"denied"!==Notification.permission},n.subscribeUserToPush=function(){return o()?navigator.serviceWorker.getRegistration().then(function(e){var n={userVisibleOnly:!0,applicationServerKey:r};return e.pushManager.subscribe(n)}).then(function(e){return console.log("Received PushSubscription: ",JSON.stringify(e)),e}):Promise.reject("Push notifications not compatible")},n.getSubscription=function(){return o()?navigator.serviceWorker.getRegistration().then(function(e){return e.pushManager.getSubscription()}):Promise.reject("Push notifications not compatible")},n.sendSubscriptionToBackEnd=function(e,n){return fetch("/normandia/services/push_tokens",{method:"POST",headers:{"Content-Type":"application/json"},body:{registration_token:e.registration_token,platform:n||"",keys:e.keys},credentials:"same-origin"})};var r=function(e){for(var n=(e+"=".repeat((4-e.length%4)%4)).replace(/\-/g,"+").replace(/_/g,"/"),t="undefined"!=typeof window?window.atob(n):"",o=new Uint8Array(t.length),r=0;r<t.length;++r)o[r]=t.charCodeAt(r);return o}("BEl62iUYgUivxIkv69yViEuiBIa-Ib9-SkvMeAtA3LFgDzkrxZJjSgSnfckjBJuBkr3qBUYIHBQFLXYp5Nksh8U")}])}); |
@@ -42,23 +42,15 @@ const APPLICATIONSERVERKEY = urlB64ToUint8Array('BEl62iUYgUivxIkv69yViEuiBIa-Ib9-SkvMeAtA3LFgDzkrxZJjSgSnfckjBJuBkr3qBUYIHBQFLXYp5Nksh8U'); | ||
export function sendSubscriptionToBackEnd(subscription, brand) { | ||
return fetch('/api/save-subscription/', { | ||
export function sendSubscriptionToBackEnd(subscription, platform) { | ||
return fetch('/normandia/services/push_tokens', { | ||
method: 'POST', | ||
headers: { | ||
'Content-Type': 'application/json', | ||
'x-api-key': '32223507-c36c-42c2-b52d-b3f1d65fa5ae' | ||
'Content-Type': 'application/json' | ||
}, | ||
body: JSON.stringify(subscription) | ||
}) | ||
.then(function(response) { | ||
if (!response.ok) { | ||
throw new Error('Bad status code from server.'); | ||
} | ||
return response.json(); | ||
}) | ||
.then(function(responseData) { | ||
if (!(responseData.data && responseData.data.success)) { | ||
throw new Error('Bad response from server.'); | ||
} | ||
}); | ||
body: { | ||
"registration_token": subscription.registration_token, | ||
"platform": platform || "", | ||
"keys": subscription.keys | ||
}, | ||
credentials: "same-origin" | ||
}); | ||
} | ||
@@ -65,0 +57,0 @@ |
{ | ||
"name": "@garbarino/gb-jscommons", | ||
"version": "1.2.0", | ||
"version": "1.3.0", | ||
"description": "A package of common functions used in our JavaScript applications.", | ||
@@ -5,0 +5,0 @@ "main": "index.js", |
19795
386