@digipair/skill-web-push-notification 0.91.0-0 → 0.91.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,51 @@
1
+ 'use strict';
2
+
3
+ Object.defineProperty(exports, '__esModule', { value: true });
4
+
5
+ let WebHttpNotificationService = class WebHttpNotificationService {
6
+ async registerServiceWorker() {
7
+ if (!('serviceWorker' in navigator)) {
8
+ console.log('Service Worker not supported in this browser');
9
+ return null;
10
+ }
11
+ try {
12
+ const registration = await navigator.serviceWorker.register('/assets/push-notification.worker.js');
13
+ return registration;
14
+ } catch (error) {
15
+ console.error('Error when registering the Service Worker', error);
16
+ return null;
17
+ }
18
+ }
19
+ async subscribeToPushNotifications(registration, vapidPublicKey) {
20
+ if (!('PushManager' in window)) {
21
+ console.log('Push Manager not supported in this browser');
22
+ return null;
23
+ }
24
+ try {
25
+ const permission = await Notification.requestPermission();
26
+ if (permission !== 'granted') {
27
+ console.log('Notification permission not granted');
28
+ return null;
29
+ }
30
+ const subscription = await registration.pushManager.subscribe({
31
+ userVisibleOnly: true,
32
+ applicationServerKey: vapidPublicKey
33
+ });
34
+ return subscription;
35
+ } catch (error) {
36
+ console.error('Error when subscribing to push notifications', error);
37
+ return null;
38
+ }
39
+ }
40
+ async initialize(params, _pinsSettingsList, context) {
41
+ const { publicKey = context.variables.PUSH_NOTIFICATION_PUBLIC_KEY } = params;
42
+ const registration = await this.registerServiceWorker();
43
+ if (registration) {
44
+ return await this.subscribeToPushNotifications(registration, publicKey);
45
+ }
46
+ return null;
47
+ }
48
+ };
49
+ const initialize = (params, pinsSettingsList, context)=>new WebHttpNotificationService().initialize(params, pinsSettingsList, context);
50
+
51
+ exports.initialize = initialize;
package/index.esm.js ADDED
@@ -0,0 +1,47 @@
1
+ let WebHttpNotificationService = class WebHttpNotificationService {
2
+ async registerServiceWorker() {
3
+ if (!('serviceWorker' in navigator)) {
4
+ console.log('Service Worker not supported in this browser');
5
+ return null;
6
+ }
7
+ try {
8
+ const registration = await navigator.serviceWorker.register('/assets/push-notification.worker.js');
9
+ return registration;
10
+ } catch (error) {
11
+ console.error('Error when registering the Service Worker', error);
12
+ return null;
13
+ }
14
+ }
15
+ async subscribeToPushNotifications(registration, vapidPublicKey) {
16
+ if (!('PushManager' in window)) {
17
+ console.log('Push Manager not supported in this browser');
18
+ return null;
19
+ }
20
+ try {
21
+ const permission = await Notification.requestPermission();
22
+ if (permission !== 'granted') {
23
+ console.log('Notification permission not granted');
24
+ return null;
25
+ }
26
+ const subscription = await registration.pushManager.subscribe({
27
+ userVisibleOnly: true,
28
+ applicationServerKey: vapidPublicKey
29
+ });
30
+ return subscription;
31
+ } catch (error) {
32
+ console.error('Error when subscribing to push notifications', error);
33
+ return null;
34
+ }
35
+ }
36
+ async initialize(params, _pinsSettingsList, context) {
37
+ const { publicKey = context.variables.PUSH_NOTIFICATION_PUBLIC_KEY } = params;
38
+ const registration = await this.registerServiceWorker();
39
+ if (registration) {
40
+ return await this.subscribeToPushNotifications(registration, publicKey);
41
+ }
42
+ return null;
43
+ }
44
+ };
45
+ const initialize = (params, pinsSettingsList, context)=>new WebHttpNotificationService().initialize(params, pinsSettingsList, context);
46
+
47
+ export { initialize };
@@ -0,0 +1,2 @@
1
+ import { PinsSettings } from '@digipair/engine';
2
+ export declare const initialize: (params: any, pinsSettingsList: PinsSettings[], context: any) => Promise<any>;
package/package.json CHANGED
@@ -1,28 +1,12 @@
1
1
  {
2
2
  "name": "@digipair/skill-web-push-notification",
3
- "version": "0.91.0-0",
4
- "type": "module",
5
- "main": "dist/libs/skill-web-push-notification/index.cjs.js",
6
- "module": "dist/libs/skill-web-push-notification/index.esm.js",
7
- "types": "dist/libs/skill-web-push-notification/index.esm.d.ts",
8
- "exports": {
9
- "./package.json": "./libs/skill-web-push-notification/package.json",
10
- ".": {
11
- "development": "./dist/libs/skill-web-push-notification/src/index.ts",
12
- "types": "./dist/libs/skill-web-push-notification/index.esm.d.ts",
13
- "import": "./dist/libs/skill-web-push-notification/index.esm.js",
14
- "default": "./dist/libs/skill-web-push-notification/index.cjs.js"
15
- }
16
- },
3
+ "version": "0.91.0",
17
4
  "keywords": [
18
5
  "digipair",
19
6
  "web",
20
7
  "util"
21
8
  ],
22
- "nx": {
23
- "name": "skill-web-push-notification"
24
- },
25
- "dependencies": {
26
- "@digipair/engine": "0.91.0-0"
27
- }
28
- }
9
+ "dependencies": {},
10
+ "main": "./index.cjs.js",
11
+ "module": "./index.esm.js"
12
+ }
package/.swcrc DELETED
@@ -1,28 +0,0 @@
1
- {
2
- "jsc": {
3
- "target": "es2017",
4
- "parser": {
5
- "syntax": "typescript",
6
- "decorators": true,
7
- "dynamicImport": true
8
- },
9
- "transform": {
10
- "decoratorMetadata": true,
11
- "legacyDecorator": true
12
- },
13
- "keepClassNames": true,
14
- "externalHelpers": true,
15
- "loose": true
16
- },
17
- "module": {
18
- "type": "es6"
19
- },
20
- "sourceMaps": true,
21
- "exclude": [
22
- "jest.config.ts",
23
- ".*\\.spec.tsx?$",
24
- ".*\\.test.tsx?$",
25
- "./src/jest-setup.ts$",
26
- "./**/jest-setup.ts$"
27
- ]
28
- }
package/README.md DELETED
@@ -1,7 +0,0 @@
1
- # mylib
2
-
3
- This library was generated with [Nx](https://nx.dev).
4
-
5
- ## Building
6
-
7
- Run `nx build mylib` to build the library.
package/eslint.config.mjs DELETED
@@ -1,22 +0,0 @@
1
- import baseConfig from '../../eslint.config.mjs';
2
-
3
- export default [
4
- ...baseConfig,
5
- {
6
- files: ['**/*.json'],
7
- rules: {
8
- '@nx/dependency-checks': [
9
- 'error',
10
- {
11
- ignoredFiles: [
12
- '{projectRoot}/eslint.config.{js,cjs,mjs}',
13
- '{projectRoot}/rollup.config.{js,ts,mjs,mts,cjs,cts}',
14
- ],
15
- },
16
- ],
17
- },
18
- languageOptions: {
19
- parser: await import('jsonc-eslint-parser'),
20
- },
21
- },
22
- ];
package/rollup.config.cjs DELETED
@@ -1,28 +0,0 @@
1
- const { withNx } = require('@nx/rollup/with-nx');
2
-
3
- module.exports = withNx(
4
- {
5
- main: 'libs/skill-web-push-notification/src/index.ts',
6
- outputPath: 'dist/libs/skill-web-push-notification',
7
- tsConfig: 'libs/skill-web-push-notification/tsconfig.lib.json',
8
- compiler: 'swc',
9
- format: ['esm', "cjs"],
10
- assets: [
11
- {
12
- input: 'libs/skill-web-push-notification/',
13
- glob: 'package.json',
14
- output: '.'
15
- },
16
- {
17
- input: 'libs/skill-web-push-notification/src/',
18
- glob: '*.json',
19
- output: '.'
20
- }
21
- ]
22
- },
23
- {
24
- // Provide additional rollup configuration here. See: https://rollupjs.org/configuration-options
25
- // e.g.
26
- // output: { sourcemap: true },
27
- }
28
- );
@@ -1,7 +0,0 @@
1
- import { skillWebPushNotification } from './skill-web-push-notification';
2
-
3
- describe('skillWebPushNotification', () => {
4
- it('should work', () => {
5
- expect(skillWebPushNotification()).toEqual('skill-web-push-notification');
6
- });
7
- });
@@ -1,58 +0,0 @@
1
- import { PinsSettings } from '@digipair/engine';
2
-
3
- class WebHttpNotificationService {
4
- private async registerServiceWorker() {
5
- if (!('serviceWorker' in navigator)) {
6
- console.log('Service Worker not supported in this browser');
7
- return null;
8
- }
9
-
10
- try {
11
- const registration = await navigator.serviceWorker.register(
12
- '/assets/push-notification.worker.js',
13
- );
14
- return registration;
15
- } catch (error) {
16
- console.error('Error when registering the Service Worker', error);
17
- return null;
18
- }
19
- }
20
-
21
- private async subscribeToPushNotifications(registration: any, vapidPublicKey: string) {
22
- if (!('PushManager' in window)) {
23
- console.log('Push Manager not supported in this browser');
24
- return null;
25
- }
26
-
27
- try {
28
- const permission = await Notification.requestPermission();
29
- if (permission !== 'granted') {
30
- console.log('Notification permission not granted');
31
- return null;
32
- }
33
-
34
- const subscription = await registration.pushManager.subscribe({
35
- userVisibleOnly: true,
36
- applicationServerKey: vapidPublicKey,
37
- });
38
-
39
- return subscription;
40
- } catch (error) {
41
- console.error('Error when subscribing to push notifications', error);
42
- return null;
43
- }
44
- }
45
-
46
- async initialize(params: any, _pinsSettingsList: PinsSettings[], context: any) {
47
- const { publicKey = context.variables.PUSH_NOTIFICATION_PUBLIC_KEY } = params;
48
- const registration = await this.registerServiceWorker();
49
-
50
- if (registration) {
51
- return await this.subscribeToPushNotifications(registration, publicKey);
52
- }
53
- return null;
54
- }
55
- }
56
-
57
- export const initialize = (params: any, pinsSettingsList: PinsSettings[], context: any) =>
58
- new WebHttpNotificationService().initialize(params, pinsSettingsList, context);
package/tsconfig.json DELETED
@@ -1,13 +0,0 @@
1
- {
2
- "extends": "../../tsconfig.base.json",
3
- "files": [],
4
- "include": [],
5
- "references": [
6
- {
7
- "path": "../engine"
8
- },
9
- {
10
- "path": "./tsconfig.lib.json"
11
- }
12
- ]
13
- }
package/tsconfig.lib.json DELETED
@@ -1,19 +0,0 @@
1
- {
2
- "extends": "../../tsconfig.base.json",
3
- "compilerOptions": {
4
- "rootDir": "src",
5
- "outDir": "dist",
6
- "tsBuildInfoFile": "dist/tsconfig.lib.tsbuildinfo",
7
- "emitDeclarationOnly": true,
8
- "module": "esnext",
9
- "moduleResolution": "node",
10
- "forceConsistentCasingInFileNames": true,
11
- "types": ["node"]
12
- },
13
- "include": ["src/**/*.ts"],
14
- "references": [
15
- {
16
- "path": "../engine/tsconfig.lib.json"
17
- }
18
- ]
19
- }
File without changes
File without changes
File without changes