@digipair/skill-web-push-notification 0.43.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/index.cjs.d.ts ADDED
@@ -0,0 +1 @@
1
+ export * from "./src/index";
package/index.cjs.js ADDED
@@ -0,0 +1,52 @@
1
+ 'use strict';
2
+
3
+ Object.defineProperty(exports, '__esModule', { value: true });
4
+
5
+ // import { PinsSettings } from '@digipair/engine';
6
+ let WebHttpNotificationService = class WebHttpNotificationService {
7
+ async registerServiceWorker() {
8
+ if (!('serviceWorker' in navigator)) {
9
+ console.log('Service Worker not supported in this browser');
10
+ return null;
11
+ }
12
+ try {
13
+ const registration = await navigator.serviceWorker.register('/public/push-notification.worker.js');
14
+ return registration;
15
+ } catch (error) {
16
+ console.error('Error when registering the Service Worker', error);
17
+ return null;
18
+ }
19
+ }
20
+ async subscribeToPushNotifications(registration, vapidPublicKey) {
21
+ if (!('PushManager' in window)) {
22
+ console.log('Push Manager not supported in this browser');
23
+ return null;
24
+ }
25
+ try {
26
+ const permission = await Notification.requestPermission();
27
+ if (permission !== 'granted') {
28
+ console.log('Notification permission not granted');
29
+ return null;
30
+ }
31
+ const subscription = await registration.pushManager.subscribe({
32
+ userVisibleOnly: true,
33
+ applicationServerKey: vapidPublicKey
34
+ });
35
+ return subscription;
36
+ } catch (error) {
37
+ console.error('Error when subscribing to push notifications', error);
38
+ return null;
39
+ }
40
+ }
41
+ async initialize(params, _pinsSettingsList, context) {
42
+ const { publicKey = context.variables.PUSH_NOTIFICATION_PUBLIC_KEY } = params;
43
+ const registration = await this.registerServiceWorker();
44
+ if (registration) {
45
+ return await this.subscribeToPushNotifications(registration, publicKey);
46
+ }
47
+ return null;
48
+ }
49
+ };
50
+ const initialize = (params, pinsSettingsList, context)=>new WebHttpNotificationService().initialize(params, pinsSettingsList, context);
51
+
52
+ exports.initialize = initialize;
package/index.d.ts ADDED
@@ -0,0 +1 @@
1
+ export * from './libs/skill-web-push-notification/src/index';
package/index.esm.js ADDED
@@ -0,0 +1,48 @@
1
+ // import { PinsSettings } from '@digipair/engine';
2
+ let WebHttpNotificationService = class WebHttpNotificationService {
3
+ async registerServiceWorker() {
4
+ if (!('serviceWorker' in navigator)) {
5
+ console.log('Service Worker not supported in this browser');
6
+ return null;
7
+ }
8
+ try {
9
+ const registration = await navigator.serviceWorker.register('/public/push-notification.worker.js');
10
+ return registration;
11
+ } catch (error) {
12
+ console.error('Error when registering the Service Worker', error);
13
+ return null;
14
+ }
15
+ }
16
+ async subscribeToPushNotifications(registration, vapidPublicKey) {
17
+ if (!('PushManager' in window)) {
18
+ console.log('Push Manager not supported in this browser');
19
+ return null;
20
+ }
21
+ try {
22
+ const permission = await Notification.requestPermission();
23
+ if (permission !== 'granted') {
24
+ console.log('Notification permission not granted');
25
+ return null;
26
+ }
27
+ const subscription = await registration.pushManager.subscribe({
28
+ userVisibleOnly: true,
29
+ applicationServerKey: vapidPublicKey
30
+ });
31
+ return subscription;
32
+ } catch (error) {
33
+ console.error('Error when subscribing to push notifications', error);
34
+ return null;
35
+ }
36
+ }
37
+ async initialize(params, _pinsSettingsList, context) {
38
+ const { publicKey = context.variables.PUSH_NOTIFICATION_PUBLIC_KEY } = params;
39
+ const registration = await this.registerServiceWorker();
40
+ if (registration) {
41
+ return await this.subscribeToPushNotifications(registration, publicKey);
42
+ }
43
+ return null;
44
+ }
45
+ };
46
+ const initialize = (params, pinsSettingsList, context)=>new WebHttpNotificationService().initialize(params, pinsSettingsList, context);
47
+
48
+ export { initialize };
@@ -0,0 +1 @@
1
+ export * from './lib/skill-web-push-notification';
@@ -0,0 +1,3 @@
1
+ type PinsSettings = any;
2
+ export declare const initialize: (params: any, pinsSettingsList: PinsSettings[], context: any) => Promise<any>;
3
+ export {};
package/package.json ADDED
@@ -0,0 +1,7 @@
1
+ {
2
+ "name": "@digipair/skill-web-push-notification",
3
+ "version": "0.43.0",
4
+ "dependencies": {},
5
+ "main": "./index.cjs.js",
6
+ "module": "./index.esm.js"
7
+ }
package/schema.fr.json ADDED
@@ -0,0 +1,34 @@
1
+ {
2
+ "openapi": "3.0.0",
3
+ "info": {
4
+ "title": "@digipair/skill-web-push-notification",
5
+ "summary": "Enregistre l'utilisateur aux notifications push",
6
+ "description": "Cette compétence permet aux utilisateurs de s'enregistrer pour recevoir des notifications push.",
7
+ "version": "0.1.0",
8
+ "x-icon": "đź“•"
9
+ },
10
+ "paths": {
11
+ "/initialize": {
12
+ "post": {
13
+ "tags": ["web", "spatial"],
14
+ "summary": "Enregistre l'utilisateur aux notifications push",
15
+ "description": "Enregistre l'utilisateur pour recevoir des notifications push en temps réel.",
16
+ "parameters": [
17
+ {
18
+ "name": "publicKey",
19
+ "summary": "Clé publique VAPID",
20
+ "required": false,
21
+ "description": "Clé publique VAPID utilisée pour autoriser les notifications.",
22
+ "schema": {
23
+ "type": "string"
24
+ }
25
+ }
26
+ ],
27
+ "x-events": []
28
+ }
29
+ }
30
+ },
31
+ "components": {
32
+ "schemas": {}
33
+ }
34
+ }
package/schema.json ADDED
@@ -0,0 +1,34 @@
1
+ {
2
+ "openapi": "3.0.0",
3
+ "info": {
4
+ "title": "@digipair/skill-web-push-notification",
5
+ "summary": "Allow user to get push notifications",
6
+ "description": "This skill allow user to get notifications from WebPush",
7
+ "version": "0.1.0",
8
+ "x-icon": "đź“•"
9
+ },
10
+ "paths": {
11
+ "/initialize": {
12
+ "post": {
13
+ "tags": ["web", "spatial"],
14
+ "summary": "Register the user for push notifications.",
15
+ "description": "Register the user to receive push notifications for real-time updates.",
16
+ "parameters": [
17
+ {
18
+ "name": "publicKey",
19
+ "summary": "VAPID public key",
20
+ "required": false,
21
+ "description": "VAPID public key used to enable push subscription.",
22
+ "schema": {
23
+ "type": "string"
24
+ }
25
+ }
26
+ ],
27
+ "x-events": []
28
+ }
29
+ }
30
+ },
31
+ "components": {
32
+ "schemas": {}
33
+ }
34
+ }