@nu-art/push-pub-sub-frontend 0.401.8 → 0.500.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.
@@ -1,6 +1,5 @@
1
1
  import { Module } from '@nu-art/ts-common';
2
- import { ApiDefCaller } from '@nu-art/thunderstorm-shared';
3
- import { ApiStruct_PushMessages } from '@nu-art/push-pub-sub-shared';
2
+ import { API_PushMessages, BaseSubscriptionData } from '@nu-art/push-pub-sub-shared';
4
3
  export declare const Command_SwToApp = "SwToApp";
5
4
  type FirebaseConfig = {
6
5
  apiKey: string;
@@ -16,15 +15,25 @@ export type PushPubSubConfig = {
16
15
  registerOnInit?: boolean;
17
16
  };
18
17
  export declare const pushSessionIdKey = "x-push-session-id";
19
- export declare class ModuleFE_PushPubSub_Class extends Module<PushPubSubConfig> implements ApiDefCaller<ApiStruct_PushMessages> {
18
+ export declare class ModuleFE_PushPubSub_Class extends Module<PushPubSubConfig> {
20
19
  private subscriptions;
21
20
  private firebaseToken?;
22
21
  private messaging;
23
22
  private dispatch_pushMessage;
24
- readonly v1: ApiDefCaller<ApiStruct_PushMessages>['v1'];
25
23
  private readonly pushSessionId;
26
24
  protected timeout: number;
27
25
  constructor();
26
+ subscribe(subscription: BaseSubscriptionData): {
27
+ executeSync: () => Promise<API_PushMessages['register']['Response']>;
28
+ };
29
+ unsubscribe(subscription: BaseSubscriptionData): {
30
+ executeSync: () => Promise<API_PushMessages['register']['Response']>;
31
+ };
32
+ subscribeAll(subscriptions: BaseSubscriptionData[]): {
33
+ executeSync: () => Promise<API_PushMessages['register']['Response']>;
34
+ };
35
+ test(body: API_PushMessages['test']['Body']): Promise<API_PushMessages['test']['Response']>;
36
+ register(body: API_PushMessages['register']['Body']): Promise<API_PushMessages['register']['Response']>;
28
37
  private composeRegisterRequest;
29
38
  init(): void;
30
39
  getPushSessionId(): string;
@@ -15,143 +15,196 @@
15
15
  * See the License for the specific language governing permissions and
16
16
  * limitations under the License.
17
17
  */
18
+ var __runInitializers = (this && this.__runInitializers) || function (thisArg, initializers, value) {
19
+ var useValue = arguments.length > 2;
20
+ for (var i = 0; i < initializers.length; i++) {
21
+ value = useValue ? initializers[i].call(thisArg, value) : initializers[i].call(thisArg);
22
+ }
23
+ return useValue ? value : void 0;
24
+ };
25
+ var __esDecorate = (this && this.__esDecorate) || function (ctor, descriptorIn, decorators, contextIn, initializers, extraInitializers) {
26
+ function accept(f) { if (f !== void 0 && typeof f !== "function") throw new TypeError("Function expected"); return f; }
27
+ var kind = contextIn.kind, key = kind === "getter" ? "get" : kind === "setter" ? "set" : "value";
28
+ var target = !descriptorIn && ctor ? contextIn["static"] ? ctor : ctor.prototype : null;
29
+ var descriptor = descriptorIn || (target ? Object.getOwnPropertyDescriptor(target, contextIn.name) : {});
30
+ var _, done = false;
31
+ for (var i = decorators.length - 1; i >= 0; i--) {
32
+ var context = {};
33
+ for (var p in contextIn) context[p] = p === "access" ? {} : contextIn[p];
34
+ for (var p in contextIn.access) context.access[p] = contextIn.access[p];
35
+ context.addInitializer = function (f) { if (done) throw new TypeError("Cannot add initializers after decoration has completed"); extraInitializers.push(accept(f || null)); };
36
+ var result = (0, decorators[i])(kind === "accessor" ? { get: descriptor.get, set: descriptor.set } : descriptor[key], context);
37
+ if (kind === "accessor") {
38
+ if (result === void 0) continue;
39
+ if (result === null || typeof result !== "object") throw new TypeError("Object expected");
40
+ if (_ = accept(result.get)) descriptor.get = _;
41
+ if (_ = accept(result.set)) descriptor.set = _;
42
+ if (_ = accept(result.init)) initializers.unshift(_);
43
+ }
44
+ else if (_ = accept(result)) {
45
+ if (kind === "field") initializers.unshift(_);
46
+ else descriptor[key] = _;
47
+ }
48
+ }
49
+ if (target) Object.defineProperty(target, contextIn.name, descriptor);
50
+ done = true;
51
+ };
18
52
  import { addItemToArray, compare, generateHex, ImplementationMissingException, Module, removeFromArray, ThisShouldNotHappenException } from '@nu-art/ts-common';
19
- import { apiWithBody, StorageKey, ThunderDispatcher } from '@nu-art/thunderstorm-frontend/index';
20
- import { ApiDef_PushMessages } from '@nu-art/push-pub-sub-shared';
53
+ import { ApiCaller } from '@nu-art/http-client';
54
+ import { StorageKey, ThunderDispatcher } from '@nu-art/thunder-core';
55
+ import { ApiDef_PushMessages, } from '@nu-art/push-pub-sub-shared';
21
56
  export const Command_SwToApp = 'SwToApp';
22
57
  export const pushSessionIdKey = 'x-push-session-id';
23
58
  const pushSessionId = new StorageKey(pushSessionIdKey, false);
24
- export class ModuleFE_PushPubSub_Class extends Module {
25
- subscriptions = [];
26
- firebaseToken;
27
- messaging;
28
- dispatch_pushMessage = new ThunderDispatcher('__onMessageReceived');
29
- v1;
30
- pushSessionId;
31
- timeout = 800;
32
- constructor() {
33
- super();
34
- window.name = window.name || generateHex(32);
35
- this.pushSessionId = pushSessionId.set(window.name);
36
- const register = apiWithBody(ApiDef_PushMessages.v1.register);
37
- this.v1 = {
38
- test: apiWithBody(ApiDef_PushMessages.v1.test),
39
- register: (subscription) => {
40
- this.subscribeImpl(subscription);
41
- return register(this.composeRegisterRequest());
42
- },
43
- unregister: (subscription) => {
44
- removeFromArray(this.subscriptions, d => d.topic === subscription.topic && compare(subscription.filter, d.filter));
45
- return register(this.composeRegisterRequest());
46
- },
47
- registerAll: (subscriptions) => {
48
- subscriptions.forEach(subscription => this.subscribeImpl(subscription));
49
- return register(this.composeRegisterRequest());
50
- }
51
- };
52
- }
53
- composeRegisterRequest() {
54
- if (!this.firebaseToken)
55
- throw new ThisShouldNotHappenException('Firebase token not found');
56
- const body = {
57
- firebaseToken: this.firebaseToken,
58
- pushSessionId: this.getPushSessionId(),
59
- subscriptions: this.subscriptions.map(({ topic, filter }) => ({ topic, filter }))
60
- };
61
- return body;
62
- }
63
- init() {
64
- if (this.config?.registerOnInit === false)
65
- return;
66
- if (!this.config?.publicKeyBase64)
67
- throw new ImplementationMissingException(`ModuleFE_PushPubSub config is missing the publicKeyBase64`);
68
- // this.initApp();
69
- }
70
- getPushSessionId() {
71
- return this.pushSessionId;
72
- }
73
- // @ts-ignore
74
- registerServiceWorker = async () => {
75
- if (!('serviceWorker' in navigator)) {
76
- this.logWarning('serviceWorker property is missing in navigator');
59
+ let ModuleFE_PushPubSub_Class = (() => {
60
+ let _classSuper = Module;
61
+ let _instanceExtraInitializers = [];
62
+ let _test_decorators;
63
+ let _register_decorators;
64
+ return class ModuleFE_PushPubSub_Class extends _classSuper {
65
+ static {
66
+ const _metadata = typeof Symbol === "function" && Symbol.metadata ? Object.create(_classSuper[Symbol.metadata] ?? null) : void 0;
67
+ _test_decorators = [ApiCaller(ApiDef_PushMessages.test)];
68
+ _register_decorators = [ApiCaller(ApiDef_PushMessages.register)];
69
+ __esDecorate(this, null, _test_decorators, { kind: "method", name: "test", static: false, private: false, access: { has: obj => "test" in obj, get: obj => obj.test }, metadata: _metadata }, null, _instanceExtraInitializers);
70
+ __esDecorate(this, null, _register_decorators, { kind: "method", name: "register", static: false, private: false, access: { has: obj => "register" in obj, get: obj => obj.register }, metadata: _metadata }, null, _instanceExtraInitializers);
71
+ if (_metadata) Object.defineProperty(this, Symbol.metadata, { enumerable: true, configurable: true, writable: true, value: _metadata });
72
+ }
73
+ subscriptions = (__runInitializers(this, _instanceExtraInitializers), []);
74
+ firebaseToken;
75
+ messaging;
76
+ dispatch_pushMessage = new ThunderDispatcher('__onMessageReceived');
77
+ pushSessionId;
78
+ timeout = 800;
79
+ constructor() {
80
+ super();
81
+ window.name = window.name || generateHex(32);
82
+ this.pushSessionId = pushSessionId.set(window.name);
83
+ }
84
+ subscribe(subscription) {
85
+ this.subscribeImpl(subscription);
86
+ return { executeSync: () => this.register(this.composeRegisterRequest()) };
87
+ }
88
+ unsubscribe(subscription) {
89
+ removeFromArray(this.subscriptions, d => d.topic === subscription.topic && compare(subscription.filter, d.filter));
90
+ return { executeSync: () => this.register(this.composeRegisterRequest()) };
91
+ }
92
+ subscribeAll(subscriptions) {
93
+ subscriptions.forEach(subscription => this.subscribeImpl(subscription));
94
+ return { executeSync: () => this.register(this.composeRegisterRequest()) };
95
+ }
96
+ async test(body) {
97
+ void body;
77
98
  return undefined;
78
99
  }
79
- // const registration = await navigator.serviceWorker.register(`/${this.config.swFileName || 'pubsub-sw.js'}`);
80
- // await registration.update();
81
- // navigator.serviceWorker.oncontrollerchange = () => {
82
- // this.logDebug('This page is now controlled by:', this.getControllingServiceWorker());
83
- // };
100
+ async register(body) {
101
+ void body;
102
+ return undefined;
103
+ }
104
+ composeRegisterRequest() {
105
+ if (!this.firebaseToken)
106
+ throw new ThisShouldNotHappenException('Firebase token not found');
107
+ const body = {
108
+ firebaseToken: this.firebaseToken,
109
+ pushSessionId: this.getPushSessionId(),
110
+ subscriptions: this.subscriptions.map(({ topic, filter }) => ({ topic, filter }))
111
+ };
112
+ return body;
113
+ }
114
+ init() {
115
+ if (this.config?.registerOnInit === false)
116
+ return;
117
+ if (!this.config?.publicKeyBase64)
118
+ throw new ImplementationMissingException(`ModuleFE_PushPubSub config is missing the publicKeyBase64`);
119
+ // this.initApp();
120
+ }
121
+ getPushSessionId() {
122
+ return this.pushSessionId;
123
+ }
124
+ // @ts-ignore
125
+ registerServiceWorker = async () => {
126
+ if (!('serviceWorker' in navigator)) {
127
+ this.logWarning('serviceWorker property is missing in navigator');
128
+ return undefined;
129
+ }
130
+ // const registration = await navigator.serviceWorker.register(`/${this.config.swFileName || 'pubsub-sw.js'}`);
131
+ // await registration.update();
132
+ // navigator.serviceWorker.oncontrollerchange = () => {
133
+ // this.logDebug('This page is now controlled by:', this.getControllingServiceWorker());
134
+ // };
135
+ //
136
+ // navigator.serviceWorker.onmessage = (event: MessageEvent) => {
137
+ // this.processMessageFromSw(event.data);
138
+ // };
139
+ // return registration;
140
+ };
141
+ // initApp = () => {
142
+ // this.runAsync('Initializing Firebase SDK and registering SW', async () => {
143
+ // const registration = await this.registerServiceWorker();
144
+ // const session = await ModuleFE_Firebase.createSession();
145
+ //
146
+ // this.messaging = session.getMessaging();
147
+ // this.messaging.onMessage((payload) => {
148
+ // if (!payload.data)
149
+ // return this.logInfo('No data passed to the message handler, I got this', payload);
84
150
  //
85
- // navigator.serviceWorker.onmessage = (event: MessageEvent) => {
86
- // this.processMessageFromSw(event.data);
151
+ // this.processMessage(payload.data as PushMessage_PayloadWrapper);
152
+ // });
153
+ //
154
+ // this.logDebug('Getting new Token');
155
+ // await this.getToken({vapidKey: this.config?.publicKeyBase64, serviceWorkerRegistration: registration});
156
+ // this.logDebug('GOT new Token');
157
+ //
158
+ // if (this.getControllingServiceWorker()) {
159
+ // this.logDebug(`This page is currently controlled by: `, this.getControllingServiceWorker());
160
+ // }
161
+ // });
87
162
  // };
88
- // return registration;
89
- };
90
- // initApp = () => {
91
- // this.runAsync('Initializing Firebase SDK and registering SW', async () => {
92
- // const registration = await this.registerServiceWorker();
93
- // const session = await ModuleFE_Firebase.createSession();
94
- //
95
- // this.messaging = session.getMessaging();
96
- // this.messaging.onMessage((payload) => {
97
- // if (!payload.data)
98
- // return this.logInfo('No data passed to the message handler, I got this', payload);
99
- //
100
- // this.processMessage(payload.data as PushMessage_PayloadWrapper);
101
- // });
102
- //
103
- // this.logDebug('Getting new Token');
104
- // await this.getToken({vapidKey: this.config?.publicKeyBase64, serviceWorkerRegistration: registration});
105
- // this.logDebug('GOT new Token');
106
- //
107
- // if (this.getControllingServiceWorker()) {
108
- // this.logDebug(`This page is currently controlled by: `, this.getControllingServiceWorker());
109
- // }
110
- // });
111
- // };
112
- // @ts-ignore
113
- getControllingServiceWorker() {
114
- return navigator.serviceWorker.controller;
115
- }
116
- deleteToken() {
117
- return this.messaging.deleteToken();
118
- }
119
- isNotificationEnabled() {
120
- return Notification.permission === 'granted';
121
- }
122
- requestPermissions = async () => {
123
- if (this.isNotificationEnabled())
124
- return this.logVerbose('Notification already allowed');
125
- const permission = await Notification.requestPermission();
126
- if (permission !== 'granted')
127
- return this.logWarning('Notification was NOT granted');
128
- return this.logVerbose('Notification WAS granted');
129
- };
130
- getToken = async (options) => {
131
- if (!this.isNotificationEnabled())
132
- return;
133
- this.firebaseToken = await this.messaging.getToken(options);
134
- this.logVerbose('new token received: ' + this.firebaseToken);
135
- };
136
- hasToken = () => !!this.firebaseToken;
137
- // @ts-ignore
138
- processMessageFromSw = (data) => {
139
- this.logDebug('Got message from service worker: ', data);
140
- if (!data.command || !data.message || data.command !== Command_SwToApp)
141
- return;
142
- this.processMessage(data.message);
143
- };
144
- processMessage = (data) => {
145
- if (data.sessionId !== this.pushSessionId)
146
- return;
147
- this.logInfo('process message', data);
148
- const payload = JSON.parse(data.payload);
149
- this.dispatch_pushMessage.dispatchAll(payload);
163
+ // @ts-ignore
164
+ getControllingServiceWorker() {
165
+ return navigator.serviceWorker.controller;
166
+ }
167
+ deleteToken() {
168
+ return this.messaging.deleteToken();
169
+ }
170
+ isNotificationEnabled() {
171
+ return Notification.permission === 'granted';
172
+ }
173
+ requestPermissions = async () => {
174
+ if (this.isNotificationEnabled())
175
+ return this.logVerbose('Notification already allowed');
176
+ const permission = await Notification.requestPermission();
177
+ if (permission !== 'granted')
178
+ return this.logWarning('Notification was NOT granted');
179
+ return this.logVerbose('Notification WAS granted');
180
+ };
181
+ getToken = async (options) => {
182
+ if (!this.isNotificationEnabled())
183
+ return;
184
+ this.firebaseToken = await this.messaging.getToken(options);
185
+ this.logVerbose('new token received: ' + this.firebaseToken);
186
+ };
187
+ hasToken = () => !!this.firebaseToken;
188
+ // @ts-ignore
189
+ processMessageFromSw = (data) => {
190
+ this.logDebug('Got message from service worker: ', data);
191
+ if (!data.command || !data.message || data.command !== Command_SwToApp)
192
+ return;
193
+ this.processMessage(data.message);
194
+ };
195
+ processMessage = (data) => {
196
+ if (data.sessionId !== this.pushSessionId)
197
+ return;
198
+ this.logInfo('process message', data);
199
+ const payload = JSON.parse(data.payload);
200
+ this.dispatch_pushMessage.dispatchAll(payload);
201
+ };
202
+ subscribeImpl(subscription) {
203
+ if (this.subscriptions.find(d => d.topic === subscription.topic && compare(subscription.filter, d.filter)))
204
+ return;
205
+ addItemToArray(this.subscriptions, subscription);
206
+ }
150
207
  };
151
- subscribeImpl(subscription) {
152
- if (this.subscriptions.find(d => d.topic === subscription.topic && compare(subscription.filter, d.filter)))
153
- return;
154
- addItemToArray(this.subscriptions, subscription);
155
- }
156
- }
208
+ })();
209
+ export { ModuleFE_PushPubSub_Class };
157
210
  export const ModuleFE_PushPubSub = new ModuleFE_PushPubSub_Class();
@@ -1,8 +1,14 @@
1
- import { ModuleFE_BaseApi } from '@nu-art/thunderstorm-frontend/index';
2
- import { DispatcherDef, ThunderDispatcherV3 } from '@nu-art/thunderstorm-frontend/core/db-api-gen/types';
3
- import { DBProto_PushSubscription } from '@nu-art/push-pub-sub-shared/push-subscription/index';
4
- export declare const dispatch_onSubscriptionChanged: ThunderDispatcherV3<DispatcherDef<DBProto_PushSubscription, "__onSubscriptionUpdated">>;
5
- export declare class ModuleFE_PushSubscription_Class extends ModuleFE_BaseApi<DBProto_PushSubscription> {
1
+ import type { DB_Prototype } from '@nu-art/db-api-shared';
2
+ import type { ApiCallerEventType } from '@nu-art/db-api-shared';
3
+ import { ModuleFE_BaseApi } from '@nu-art/db-api-frontend';
4
+ import { DatabaseDef_PushSubscription } from '@nu-art/push-pub-sub-shared/push-subscription/index';
5
+ import { ThunderDispatcher } from '@nu-art/thunder-core';
6
+ /** Event type for subscription updates. Uses any for DB type to bridge ts-common DB_PushSubscription with db-api DB_Object. */
7
+ export interface OnSubscriptionUpdated {
8
+ __onSubscriptionUpdated(...params: ApiCallerEventType<any>): void;
9
+ }
10
+ export declare const dispatch_onSubscriptionChanged: ThunderDispatcher<OnSubscriptionUpdated, "__onSubscriptionUpdated", ApiCallerEventType<any>, void>;
11
+ export declare class ModuleFE_PushSubscription_Class extends ModuleFE_BaseApi<DatabaseDef_PushSubscription & DB_Prototype> {
6
12
  constructor();
7
13
  }
8
14
  export declare const ModuleFE_PushSubscription: ModuleFE_PushSubscription_Class;
@@ -1,10 +1,15 @@
1
- import { ModuleFE_BaseApi } from '@nu-art/thunderstorm-frontend/index';
2
- import { ThunderDispatcherV3 } from '@nu-art/thunderstorm-frontend/core/db-api-gen/types';
1
+ import { CrudApiDef } from '@nu-art/db-api-shared';
2
+ import { buildConfigFromDBDef, ModuleFE_BaseApi } from '@nu-art/db-api-frontend';
3
3
  import { DBDef_PushSubscription } from '@nu-art/push-pub-sub-shared/push-subscription/index';
4
- export const dispatch_onSubscriptionChanged = new ThunderDispatcherV3('__onSubscriptionUpdated');
4
+ import { ThunderDispatcher } from '@nu-art/thunder-core';
5
+ export const dispatch_onSubscriptionChanged = new ThunderDispatcher('__onSubscriptionUpdated');
5
6
  export class ModuleFE_PushSubscription_Class extends ModuleFE_BaseApi {
6
7
  constructor() {
7
- super(DBDef_PushSubscription, dispatch_onSubscriptionChanged);
8
+ super({
9
+ config: buildConfigFromDBDef(DBDef_PushSubscription),
10
+ crudApiDef: CrudApiDef(DBDef_PushSubscription.dbKey),
11
+ dispatcher: (...params) => dispatch_onSubscriptionChanged.dispatchAll(...params)
12
+ });
8
13
  }
9
14
  }
10
15
  export const ModuleFE_PushSubscription = new ModuleFE_PushSubscription_Class();
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@nu-art/push-pub-sub-frontend",
3
- "version": "0.401.8",
3
+ "version": "0.500.0",
4
4
  "description": "push-pub-sub Frontend",
5
5
  "keywords": [
6
6
  "TacB0sS",
@@ -21,21 +21,23 @@
21
21
  },
22
22
  "license": "Apache-2.0",
23
23
  "author": "TacB0sS",
24
- "scripts": {
25
- "build": "tsc -b -f"
26
- },
24
+ "scripts": {},
27
25
  "dependencies": {
28
- "@nu-art/push-pub-sub-shared": "0.401.8",
29
- "@nu-art/firebase-frontend": "0.401.8",
30
- "@nu-art/firebase-shared": "0.401.8",
31
- "@nu-art/permissions-frontend": "0.401.8",
32
- "@nu-art/permissions-shared": "0.401.8",
33
- "@nu-art/thunderstorm-frontend": "0.401.8",
34
- "@nu-art/thunderstorm-shared": "0.401.8",
35
- "@nu-art/ts-common": "0.401.8",
36
- "@nu-art/ts-styles": "0.401.8",
37
- "@nu-art/user-account-frontend": "0.401.8",
38
- "@nu-art/user-account-shared": "0.401.8",
26
+ "@nu-art/push-pub-sub-shared": "0.500.0",
27
+ "@nu-art/firebase-frontend": "0.500.0",
28
+ "@nu-art/firebase-shared": "0.500.0",
29
+ "@nu-art/permissions-frontend": "0.500.0",
30
+ "@nu-art/permissions-shared": "0.500.0",
31
+ "@nu-art/db-api-frontend": "0.500.0",
32
+ "@nu-art/db-api-shared": "0.500.0",
33
+ "@nu-art/http-client": "{{THUNDERSTORM_VERSION}}",
34
+ "@nu-art/thunder-core": "{{THUNDERSTORM_VERSION}}",
35
+ "@nu-art/thunder-ui-modules": "{{THUNDERSTORM_VERSION}}",
36
+ "@nu-art/thunder-widgets": "{{THUNDERSTORM_VERSION}}",
37
+ "@nu-art/ts-common": "0.500.0",
38
+ "@nu-art/ts-styles": "0.500.0",
39
+ "@nu-art/user-account-frontend": "0.500.0",
40
+ "@nu-art/user-account-shared": "0.500.0",
39
41
  "firebase": "^11.9.0",
40
42
  "firebase-admin": "13.4.0",
41
43
  "moment": "^2.29.4",
@@ -1,9 +1,9 @@
1
1
  import * as React from 'react';
2
- import { AppToolsScreen, ComponentSync } from '@nu-art/thunderstorm-frontend/index';
2
+ import type { ApiCallerEventType } from '@nu-art/db-api-shared';
3
+ import { AppToolsScreen } from '@nu-art/thunder-ui-modules';
4
+ import { ComponentSync } from '@nu-art/thunder-widgets';
3
5
  import { OnPushMessageReceived, PushMessage_Payload } from '@nu-art/push-pub-sub-shared';
4
6
  import './ATS_PushPubSub.scss';
5
- import { ApiCallerEventType } from '@nu-art/thunderstorm-frontend/core/db-api-gen/types';
6
- import { DBProto_PushSubscription } from '@nu-art/push-pub-sub-shared/push-subscription/index';
7
7
  type ObjProps = {
8
8
  key: string;
9
9
  value: string;
@@ -18,7 +18,7 @@ type State = {
18
18
  type Props = {};
19
19
  export declare class ATS_PushPubSub extends ComponentSync<Props, State> implements OnPushMessageReceived {
20
20
  static screen: AppToolsScreen;
21
- __onSubscriptionUpdated(...params: ApiCallerEventType<DBProto_PushSubscription>): void;
21
+ __onSubscriptionUpdated(...params: ApiCallerEventType<any>): void;
22
22
  __onMessageReceived(payload: PushMessage_Payload): void;
23
23
  protected deriveStateFromProps(nextProps: Props, _state: (Partial<State>) | undefined): State;
24
24
  private composeFilter;
@@ -1,10 +1,11 @@
1
1
  import { jsxs as _jsxs, jsx as _jsx } from "react/jsx-runtime";
2
- import { _className, ATS_Fullstack, Button, ComponentSync, LL_H_C, LL_H_T, LL_V_L, ModuleFE_Toaster, TS_Input, TS_PropRenderer, TS_Table } from '@nu-art/thunderstorm-frontend/index';
2
+ import { _className } from '@nu-art/thunder-core';
3
+ import { ATS_Fullstack } from '@nu-art/thunder-ui-modules';
4
+ import { Button, ComponentSync, LL_H_C, LL_H_T, LL_V_L, ModuleFE_Toaster, TS_Input, TS_PropRenderer, TS_Table } from '@nu-art/thunder-widgets';
3
5
  import { __stringify, DateTimeFormat_yyyyMMDDTHHmmss, groupArrayBy, removeFromArrayByIndex, } from '@nu-art/ts-common';
4
6
  import { TS_Icons } from '@nu-art/ts-styles';
5
7
  import { ModuleFE_PushPubSub } from '../../modules/ModuleFE_PushPubSub.js';
6
8
  import './ATS_PushPubSub.scss';
7
- import { TS_InputV2 } from '@nu-art/thunderstorm-frontend/components/TS_V2_Input/index';
8
9
  import { ModuleFE_PushSubscription } from '../../modules/ModuleFE_PushSubscription.js';
9
10
  function createNewInstance(key = '', value = '') {
10
11
  return { key, value };
@@ -19,14 +20,12 @@ const ConfigPreset_1 = {
19
20
  }
20
21
  };
21
22
  export class ATS_PushPubSub extends ComponentSync {
22
- // ######################## Static ########################
23
23
  static screen = {
24
24
  name: `Push Messages`,
25
25
  renderer: this,
26
26
  group: ATS_Fullstack,
27
27
  modulesToAwait: [ModuleFE_PushSubscription]
28
28
  };
29
- // ######################## Lifecycle ########################
30
29
  __onSubscriptionUpdated(...params) {
31
30
  this.forceUpdate();
32
31
  }
@@ -38,7 +37,6 @@ export class ATS_PushPubSub extends ComponentSync {
38
37
  const state = _state ?? {};
39
38
  return { ...state, ...ConfigPreset_1.config, receivedPushPayloads: [] };
40
39
  }
41
- // ######################## Logic ########################
42
40
  composeFilter(objProps) {
43
41
  return objProps.reduce((toRet, item) => {
44
42
  if (!!item.key && item.key !== '')
@@ -53,17 +51,16 @@ export class ATS_PushPubSub extends ComponentSync {
53
51
  const data = { 'a': 'aaa' };
54
52
  const message = { topic: this.state.triggerKey, filter, data };
55
53
  this.logInfo(`triggering push: ${__stringify(message, true)}`);
56
- await ModuleFE_PushPubSub.v1.test({ message }).executeSync();
54
+ await ModuleFE_PushPubSub.test({ message });
57
55
  };
58
56
  subscribe = async () => {
59
57
  if (!ModuleFE_PushPubSub.hasToken())
60
58
  return ModuleFE_Toaster.toastError('No push token generated');
61
- await ModuleFE_PushPubSub.v1.register({
59
+ await ModuleFE_PushPubSub.subscribe({
62
60
  topic: this.state.registerKey,
63
61
  filter: this.composeFilter(this.state.registerFilter)
64
62
  }).executeSync();
65
63
  };
66
- // ######################## Render ########################
67
64
  render() {
68
65
  const className = _className('notification-icon', ModuleFE_PushPubSub.isNotificationEnabled() ? 'notification-enabled' : 'notification-disabled');
69
66
  const mySubscription = ModuleFE_PushSubscription.cache.all()
@@ -74,7 +71,7 @@ export class ATS_PushPubSub extends ComponentSync {
74
71
  await ModuleFE_PushPubSub.requestPermissions();
75
72
  }
76
73
  }) }), _jsx(Button, { onClick: ModuleFE_PushPubSub.deleteToken, children: "Delete Token" }), _jsx(Button, { onClick: async () => await ModuleFE_PushPubSub.getToken(), children: "Generate Token" })] }), _jsxs(LL_H_T, { className: "panels-container h-gap__n match_width", children: [this.renderPanel('Register', this.state.registerFilter, 'registerKey', this.subscribe), this.renderPanel('Trigger', this.state.triggerFilter, 'triggerKey', this.trigger)] }), _jsxs(LL_H_T, { className: "panels-container h-gap__n match_width", children: [_jsx(LL_V_L, { className: "panel v-gap__l", children: groupArrayBy(mySubscription, (subscription) => subscription.topic)
77
- .map((subscription, index) => _jsxs(LL_H_C, { children: [_jsx(LL_H_C, { style: { width: 100 }, children: subscription.key }), _jsx(LL_V_L, { children: subscription.values.map((value, index) => _jsxs(LL_H_C, { children: [_jsx(TS_Icons.bin.component, { onClick: () => ModuleFE_PushSubscription.v1.delete({ _id: value._id }).executeSync() }), JSON.stringify(value.filter)] }, index)) })] }, index)) }), _jsx(LL_V_L, { className: "panel", children: this.state.receivedPushPayloads.map(payload => _jsxs(LL_H_C, { children: [_jsx("span", { style: { width: 200 }, children: DateTimeFormat_yyyyMMDDTHHmmss.format(payload.timestamp) }), JSON.stringify(payload.message)] })) })] })] });
74
+ .map((subscription, index) => _jsxs(LL_H_C, { children: [_jsx(LL_H_C, { style: { width: 100 }, children: subscription.key }), _jsx(LL_V_L, { children: subscription.values.map((value, index) => _jsxs(LL_H_C, { children: [_jsx(TS_Icons.bin.component, { onClick: () => void ModuleFE_PushSubscription.deleteUnique({ _id: value._id }) }), JSON.stringify(value.filter)] }, index)) })] }, index)) }), _jsx(LL_V_L, { className: "panel", children: this.state.receivedPushPayloads.map(payload => _jsxs(LL_H_C, { children: [_jsx("span", { style: { width: 200 }, children: DateTimeFormat_yyyyMMDDTHHmmss.format(payload.timestamp) }), JSON.stringify(payload.message)] })) })] })] });
78
75
  }
79
76
  renderPanel(title, rows, key, action) {
80
77
  const cellRenderer = (prop, item, index) => {
@@ -92,7 +89,7 @@ export class ATS_PushPubSub extends ComponentSync {
92
89
  rows[rows.length] = createNewInstance();
93
90
  this.forceUpdate();
94
91
  };
95
- return _jsxs(LL_V_L, { className: "panel", children: [_jsxs(LL_H_C, { className: "panel-header match_width flex__justify-center", children: [title, _jsx(Button, { variant: 'secondary', onClick: addNewRow, children: "Add" }), _jsx(Button, { variant: 'primary', onClick: action, children: "Send" })] }), _jsxs(LL_V_L, { className: "panel-content v-gap__n", children: [_jsx(TS_PropRenderer.Vertical, { label: 'Key', children: _jsx(TS_InputV2, { onChange: (value) => this.setState({ [key]: value }), type: "text", id: key, value: this.state[key] }) }), _jsx(TS_Table, { id: key, table: { className: 'match_width' }, header: ['key', 'value', { header: 'delete', widthPx: 30 }], rows: rows, headerRenderer: columnKey => _jsx("div", { children: columnKey === 'delete' ? '' : columnKey }), cellRenderer: cellRenderer, tr: { style: { padding: '5px' } } })] })] });
92
+ return _jsxs(LL_V_L, { className: "panel", children: [_jsxs(LL_H_C, { className: "panel-header match_width flex__justify-center", children: [title, _jsx(Button, { variant: 'secondary', onClick: addNewRow, children: "Add" }), _jsx(Button, { variant: 'primary', onClick: action, children: "Send" })] }), _jsxs(LL_V_L, { className: "panel-content v-gap__n", children: [_jsx(TS_PropRenderer.Vertical, { label: 'Key', children: _jsx(TS_Input, { onChange: (value) => this.setState({ [key]: value }), type: "text", id: key, value: this.state[key] }) }), _jsx(TS_Table, { id: key, table: { className: 'match_width' }, header: ['key', 'value', { header: 'delete', widthPx: 30 }], rows: rows, headerRenderer: columnKey => _jsx("div", { children: columnKey === 'delete' ? '' : columnKey }), cellRenderer: cellRenderer, tr: { style: { padding: '5px' } } })] })] });
96
93
  }
97
94
  title(title) {
98
95
  return _jsx("div", { children: title });