capacitor-push-signal 0.0.1

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.
Files changed (38) hide show
  1. package/CapacitorPushSignal.podspec +19 -0
  2. package/Package.swift +36 -0
  3. package/README.md +271 -0
  4. package/android/build.gradle +66 -0
  5. package/android/src/main/AndroidManifest.xml +19 -0
  6. package/android/src/main/java/com/antonseagull/cap/push/signal/PushModels.kt +15 -0
  7. package/android/src/main/java/com/antonseagull/cap/push/signal/PushSignalCenter.kt +397 -0
  8. package/android/src/main/java/com/antonseagull/cap/push/signal/PushSignalInitProvider.kt +34 -0
  9. package/android/src/main/java/com/antonseagull/cap/push/signal/PushSignalMessagingService.kt +20 -0
  10. package/android/src/main/java/com/antonseagull/cap/push/signal/PushSignalPlugin.kt +85 -0
  11. package/android/src/main/res/.gitkeep +0 -0
  12. package/dist/docs.json +275 -0
  13. package/dist/esm/definitions.d.ts +19 -0
  14. package/dist/esm/definitions.js +2 -0
  15. package/dist/esm/definitions.js.map +1 -0
  16. package/dist/esm/index.d.ts +2 -0
  17. package/dist/esm/index.js +2 -0
  18. package/dist/esm/index.js.map +1 -0
  19. package/dist/esm/pushSignal.d.ts +8 -0
  20. package/dist/esm/pushSignal.js +76 -0
  21. package/dist/esm/pushSignal.js.map +1 -0
  22. package/dist/esm/types.d.ts +20 -0
  23. package/dist/esm/types.js +2 -0
  24. package/dist/esm/types.js.map +1 -0
  25. package/dist/esm/web.d.ts +8 -0
  26. package/dist/esm/web.js +13 -0
  27. package/dist/esm/web.js.map +1 -0
  28. package/dist/plugin.cjs.js +100 -0
  29. package/dist/plugin.cjs.js.map +1 -0
  30. package/dist/plugin.js +103 -0
  31. package/dist/plugin.js.map +1 -0
  32. package/ios/Sources/PushSignalCore/PushSignalCenter.m +583 -0
  33. package/ios/Sources/PushSignalCore/PushSignalLaunchStore.m +38 -0
  34. package/ios/Sources/PushSignalCore/include/PushSignalCenter.h +26 -0
  35. package/ios/Sources/PushSignalCore/include/PushSignalLaunchStore.h +21 -0
  36. package/ios/Sources/PushSignalPlugin/PushSignalPlugin.swift +66 -0
  37. package/ios/Tests/PushSignalPluginTests/PushSignalTests.swift +9 -0
  38. package/package.json +80 -0
package/dist/docs.json ADDED
@@ -0,0 +1,275 @@
1
+ {
2
+ "api": {
3
+ "name": "PushSignalPlugin",
4
+ "slug": "pushsignalplugin",
5
+ "docs": "",
6
+ "tags": [],
7
+ "methods": [
8
+ {
9
+ "name": "initialize",
10
+ "signature": "(config?: AndroidFirebaseConfig | undefined) => Promise<void>",
11
+ "parameters": [
12
+ {
13
+ "name": "config",
14
+ "docs": "",
15
+ "type": "AndroidFirebaseConfig | undefined"
16
+ }
17
+ ],
18
+ "returns": "Promise<void>",
19
+ "tags": [],
20
+ "docs": "Bootstrap Android Firebase from client fields (no-op on iOS / incomplete config).",
21
+ "complexTypes": [
22
+ "AndroidFirebaseConfig"
23
+ ],
24
+ "slug": "initialize"
25
+ },
26
+ {
27
+ "name": "getCredentials",
28
+ "signature": "() => Promise<PushCredentials>",
29
+ "parameters": [],
30
+ "returns": "Promise<PushCredentials>",
31
+ "tags": [],
32
+ "docs": "Returns APNs (iOS) or FCM (Android) credentials for your server.",
33
+ "complexTypes": [
34
+ "PushCredentials"
35
+ ],
36
+ "slug": "getcredentials"
37
+ },
38
+ {
39
+ "name": "startListening",
40
+ "signature": "() => Promise<void>",
41
+ "parameters": [],
42
+ "returns": "Promise<void>",
43
+ "tags": [],
44
+ "docs": "Start delivering native message / press events to JS listeners.",
45
+ "complexTypes": [],
46
+ "slug": "startlistening"
47
+ },
48
+ {
49
+ "name": "addListener",
50
+ "signature": "(eventName: 'onMessage', listenerFunc: (message: PushMessage) => void) => Promise<PluginListenerHandle>",
51
+ "parameters": [
52
+ {
53
+ "name": "eventName",
54
+ "docs": "",
55
+ "type": "'onMessage'"
56
+ },
57
+ {
58
+ "name": "listenerFunc",
59
+ "docs": "",
60
+ "type": "(message: PushMessage) => void"
61
+ }
62
+ ],
63
+ "returns": "Promise<PluginListenerHandle>",
64
+ "tags": [],
65
+ "docs": "",
66
+ "complexTypes": [
67
+ "PluginListenerHandle",
68
+ "PushMessage"
69
+ ],
70
+ "slug": "addlisteneronmessage-"
71
+ },
72
+ {
73
+ "name": "addListener",
74
+ "signature": "(eventName: 'onNotificationPress', listenerFunc: (message: PushMessage) => void) => Promise<PluginListenerHandle>",
75
+ "parameters": [
76
+ {
77
+ "name": "eventName",
78
+ "docs": "",
79
+ "type": "'onNotificationPress'"
80
+ },
81
+ {
82
+ "name": "listenerFunc",
83
+ "docs": "",
84
+ "type": "(message: PushMessage) => void"
85
+ }
86
+ ],
87
+ "returns": "Promise<PluginListenerHandle>",
88
+ "tags": [],
89
+ "docs": "",
90
+ "complexTypes": [
91
+ "PluginListenerHandle",
92
+ "PushMessage"
93
+ ],
94
+ "slug": "addlisteneronnotificationpress-"
95
+ }
96
+ ],
97
+ "properties": []
98
+ },
99
+ "interfaces": [
100
+ {
101
+ "name": "AndroidFirebaseConfig",
102
+ "slug": "androidfirebaseconfig",
103
+ "docs": "",
104
+ "tags": [],
105
+ "methods": [],
106
+ "properties": [
107
+ {
108
+ "name": "project_id",
109
+ "tags": [],
110
+ "docs": "",
111
+ "complexTypes": [],
112
+ "type": "string | undefined"
113
+ },
114
+ {
115
+ "name": "mobilesdk_app_id",
116
+ "tags": [],
117
+ "docs": "",
118
+ "complexTypes": [],
119
+ "type": "string | undefined"
120
+ },
121
+ {
122
+ "name": "current_key",
123
+ "tags": [],
124
+ "docs": "",
125
+ "complexTypes": [],
126
+ "type": "string | undefined"
127
+ },
128
+ {
129
+ "name": "project_number",
130
+ "tags": [],
131
+ "docs": "",
132
+ "complexTypes": [],
133
+ "type": "string | undefined"
134
+ }
135
+ ]
136
+ },
137
+ {
138
+ "name": "PushCredentials",
139
+ "slug": "pushcredentials",
140
+ "docs": "",
141
+ "tags": [],
142
+ "methods": [],
143
+ "properties": [
144
+ {
145
+ "name": "platform",
146
+ "tags": [],
147
+ "docs": "",
148
+ "complexTypes": [
149
+ "PushPlatform"
150
+ ],
151
+ "type": "PushPlatform"
152
+ },
153
+ {
154
+ "name": "token",
155
+ "tags": [],
156
+ "docs": "",
157
+ "complexTypes": [],
158
+ "type": "string"
159
+ },
160
+ {
161
+ "name": "environment",
162
+ "tags": [],
163
+ "docs": "",
164
+ "complexTypes": [
165
+ "PushEnvironment"
166
+ ],
167
+ "type": "PushEnvironment"
168
+ }
169
+ ]
170
+ },
171
+ {
172
+ "name": "PluginListenerHandle",
173
+ "slug": "pluginlistenerhandle",
174
+ "docs": "",
175
+ "tags": [],
176
+ "methods": [],
177
+ "properties": [
178
+ {
179
+ "name": "remove",
180
+ "tags": [],
181
+ "docs": "",
182
+ "complexTypes": [],
183
+ "type": "() => Promise<void>"
184
+ }
185
+ ]
186
+ },
187
+ {
188
+ "name": "PushMessage",
189
+ "slug": "pushmessage",
190
+ "docs": "",
191
+ "tags": [],
192
+ "methods": [],
193
+ "properties": [
194
+ {
195
+ "name": "id",
196
+ "tags": [],
197
+ "docs": "",
198
+ "complexTypes": [],
199
+ "type": "string | undefined"
200
+ },
201
+ {
202
+ "name": "title",
203
+ "tags": [],
204
+ "docs": "",
205
+ "complexTypes": [],
206
+ "type": "string | undefined"
207
+ },
208
+ {
209
+ "name": "body",
210
+ "tags": [],
211
+ "docs": "",
212
+ "complexTypes": [],
213
+ "type": "string | undefined"
214
+ },
215
+ {
216
+ "name": "data",
217
+ "tags": [],
218
+ "docs": "",
219
+ "complexTypes": [
220
+ "Record"
221
+ ],
222
+ "type": "Record<string, string>"
223
+ }
224
+ ]
225
+ }
226
+ ],
227
+ "enums": [],
228
+ "typeAliases": [
229
+ {
230
+ "name": "PushPlatform",
231
+ "slug": "pushplatform",
232
+ "docs": "",
233
+ "types": [
234
+ {
235
+ "text": "'ios'",
236
+ "complexTypes": []
237
+ },
238
+ {
239
+ "text": "'android'",
240
+ "complexTypes": []
241
+ }
242
+ ]
243
+ },
244
+ {
245
+ "name": "PushEnvironment",
246
+ "slug": "pushenvironment",
247
+ "docs": "",
248
+ "types": [
249
+ {
250
+ "text": "'sandbox'",
251
+ "complexTypes": []
252
+ },
253
+ {
254
+ "text": "'production'",
255
+ "complexTypes": []
256
+ }
257
+ ]
258
+ },
259
+ {
260
+ "name": "Record",
261
+ "slug": "record",
262
+ "docs": "Construct a type with a set of properties K of type T",
263
+ "types": [
264
+ {
265
+ "text": "{\r\n [P in K]: T;\r\n}",
266
+ "complexTypes": [
267
+ "K",
268
+ "T"
269
+ ]
270
+ }
271
+ ]
272
+ }
273
+ ],
274
+ "pluginConfigs": []
275
+ }
@@ -0,0 +1,19 @@
1
+ import type { PluginListenerHandle } from '@capacitor/core';
2
+ import type { AndroidFirebaseConfig, PushCredentials, PushMessage } from './types';
3
+ export type { AndroidFirebaseConfig, OnMessageListener, PushCredentials, PushEnvironment, PushMessage, PushPlatform, } from './types';
4
+ export interface PushSignalPlugin {
5
+ /**
6
+ * Bootstrap Android Firebase from client fields (no-op on iOS / incomplete config).
7
+ */
8
+ initialize(config?: AndroidFirebaseConfig): Promise<void>;
9
+ /**
10
+ * Returns APNs (iOS) or FCM (Android) credentials for your server.
11
+ */
12
+ getCredentials(): Promise<PushCredentials>;
13
+ /**
14
+ * Start delivering native message / press events to JS listeners.
15
+ */
16
+ startListening(): Promise<void>;
17
+ addListener(eventName: 'onMessage', listenerFunc: (message: PushMessage) => void): Promise<PluginListenerHandle>;
18
+ addListener(eventName: 'onNotificationPress', listenerFunc: (message: PushMessage) => void): Promise<PluginListenerHandle>;
19
+ }
@@ -0,0 +1,2 @@
1
+ export {};
2
+ //# sourceMappingURL=definitions.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"definitions.js","sourceRoot":"","sources":["../../src/definitions.ts"],"names":[],"mappings":"","sourcesContent":["import type { PluginListenerHandle } from '@capacitor/core';\n\nimport type { AndroidFirebaseConfig, PushCredentials, PushMessage } from './types';\n\nexport type {\n AndroidFirebaseConfig,\n OnMessageListener,\n PushCredentials,\n PushEnvironment,\n PushMessage,\n PushPlatform,\n} from './types';\n\nexport interface PushSignalPlugin {\n /**\n * Bootstrap Android Firebase from client fields (no-op on iOS / incomplete config).\n */\n initialize(config?: AndroidFirebaseConfig): Promise<void>;\n\n /**\n * Returns APNs (iOS) or FCM (Android) credentials for your server.\n */\n getCredentials(): Promise<PushCredentials>;\n\n /**\n * Start delivering native message / press events to JS listeners.\n */\n startListening(): Promise<void>;\n\n addListener(\n eventName: 'onMessage',\n listenerFunc: (message: PushMessage) => void,\n ): Promise<PluginListenerHandle>;\n\n addListener(\n eventName: 'onNotificationPress',\n listenerFunc: (message: PushMessage) => void,\n ): Promise<PluginListenerHandle>;\n}\n"]}
@@ -0,0 +1,2 @@
1
+ export type { AndroidFirebaseConfig, OnMessageListener, PushCredentials, PushEnvironment, PushMessage, PushPlatform, PushSignalPlugin, } from './definitions';
2
+ export { getCredentials, initialize, onMessage, onNotificationPress, PushSignal } from './pushSignal';
@@ -0,0 +1,2 @@
1
+ export { getCredentials, initialize, onMessage, onNotificationPress, PushSignal } from './pushSignal';
2
+ //# sourceMappingURL=index.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"index.js","sourceRoot":"","sources":["../../src/index.ts"],"names":[],"mappings":"AASA,OAAO,EAAE,cAAc,EAAE,UAAU,EAAE,SAAS,EAAE,mBAAmB,EAAE,UAAU,EAAE,MAAM,cAAc,CAAC","sourcesContent":["export type {\n AndroidFirebaseConfig,\n OnMessageListener,\n PushCredentials,\n PushEnvironment,\n PushMessage,\n PushPlatform,\n PushSignalPlugin,\n} from './definitions';\nexport { getCredentials, initialize, onMessage, onNotificationPress, PushSignal } from './pushSignal';\n"]}
@@ -0,0 +1,8 @@
1
+ import type { PushSignalPlugin } from './definitions';
2
+ import type { AndroidFirebaseConfig, OnMessageListener, PushCredentials, PushMessage } from './types';
3
+ declare const PushSignal: PushSignalPlugin;
4
+ export declare function initialize(config?: AndroidFirebaseConfig): Promise<void>;
5
+ export declare function getCredentials(): Promise<PushCredentials>;
6
+ export declare function onMessage(listener: OnMessageListener): () => void;
7
+ export declare function onNotificationPress(listener: (message: PushMessage) => void): () => void;
8
+ export { PushSignal };
@@ -0,0 +1,76 @@
1
+ import { registerPlugin } from '@capacitor/core';
2
+ const PushSignal = registerPlugin('PushSignal', {
3
+ web: () => import('./web').then((m) => new m.PushSignalWeb()),
4
+ });
5
+ const messageListeners = new Set();
6
+ const pressListeners = new Set();
7
+ let nativeCallbacksBound = false;
8
+ function normalizeMessage(raw) {
9
+ const data = {};
10
+ if (raw.data && typeof raw.data === 'object') {
11
+ for (const [key, value] of Object.entries(raw.data)) {
12
+ if (value == null) {
13
+ continue;
14
+ }
15
+ data[key] = typeof value === 'string' ? value : String(value);
16
+ }
17
+ }
18
+ return {
19
+ id: raw.id,
20
+ title: raw.title,
21
+ body: raw.body,
22
+ data,
23
+ };
24
+ }
25
+ function normalizeCredentials(raw) {
26
+ return {
27
+ platform: raw.platform,
28
+ token: raw.token,
29
+ environment: raw.environment,
30
+ };
31
+ }
32
+ function bindNativeCallbacks() {
33
+ if (nativeCallbacksBound) {
34
+ return;
35
+ }
36
+ nativeCallbacksBound = true;
37
+ void PushSignal.addListener('onMessage', (raw) => {
38
+ const message = normalizeMessage(raw);
39
+ for (const listener of [...messageListeners]) {
40
+ try {
41
+ Promise.resolve(listener(message)).then(() => undefined, () => undefined);
42
+ }
43
+ catch (_a) {
44
+ // Ignore listener failures so one bad subscriber cannot break delivery.
45
+ }
46
+ }
47
+ });
48
+ void PushSignal.addListener('onNotificationPress', (raw) => {
49
+ const message = normalizeMessage(raw);
50
+ pressListeners.forEach((listener) => listener(message));
51
+ });
52
+ void PushSignal.startListening();
53
+ }
54
+ export function initialize(config = {}) {
55
+ return PushSignal.initialize(config);
56
+ }
57
+ export function getCredentials() {
58
+ return PushSignal.getCredentials().then(normalizeCredentials);
59
+ }
60
+ export function onMessage(listener) {
61
+ bindNativeCallbacks();
62
+ messageListeners.add(listener);
63
+ return () => {
64
+ messageListeners.delete(listener);
65
+ };
66
+ }
67
+ export function onNotificationPress(listener) {
68
+ bindNativeCallbacks();
69
+ pressListeners.add(listener);
70
+ return () => {
71
+ pressListeners.delete(listener);
72
+ };
73
+ }
74
+ bindNativeCallbacks();
75
+ export { PushSignal };
76
+ //# sourceMappingURL=pushSignal.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"pushSignal.js","sourceRoot":"","sources":["../../src/pushSignal.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,cAAc,EAAE,MAAM,iBAAiB,CAAC;AAYjD,MAAM,UAAU,GAAG,cAAc,CAAmB,YAAY,EAAE;IAChE,GAAG,EAAE,GAAG,EAAE,CAAC,MAAM,CAAC,OAAO,CAAC,CAAC,IAAI,CAAC,CAAC,CAAC,EAAE,EAAE,CAAC,IAAI,CAAC,CAAC,aAAa,EAAE,CAAC;CAC9D,CAAC,CAAC;AAEH,MAAM,gBAAgB,GAAG,IAAI,GAAG,EAAqB,CAAC;AACtD,MAAM,cAAc,GAAG,IAAI,GAAG,EAAkC,CAAC;AACjE,IAAI,oBAAoB,GAAG,KAAK,CAAC;AAEjC,SAAS,gBAAgB,CAAC,GAKzB;IACC,MAAM,IAAI,GAA2B,EAAE,CAAC;IACxC,IAAI,GAAG,CAAC,IAAI,IAAI,OAAO,GAAG,CAAC,IAAI,KAAK,QAAQ,EAAE,CAAC;QAC7C,KAAK,MAAM,CAAC,GAAG,EAAE,KAAK,CAAC,IAAI,MAAM,CAAC,OAAO,CAAC,GAAG,CAAC,IAA+B,CAAC,EAAE,CAAC;YAC/E,IAAI,KAAK,IAAI,IAAI,EAAE,CAAC;gBAClB,SAAS;YACX,CAAC;YACD,IAAI,CAAC,GAAG,CAAC,GAAG,OAAO,KAAK,KAAK,QAAQ,CAAC,CAAC,CAAC,KAAK,CAAC,CAAC,CAAC,MAAM,CAAC,KAAK,CAAC,CAAC;QAChE,CAAC;IACH,CAAC;IAED,OAAO;QACL,EAAE,EAA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UAAU,CAAC,UAAU,CAAC,MAAM,CAAC,CAAC;AACvC,CAAC;AAED,MAAM,UAAU,cAAc;IAC5B,OAAO,UAAU,CAAC,cAAc,EAAE,CAAC,IAAI,CAAC,oBAAoB,CAAC,CAAC;AAChE,CAAC;AAED,MAAM,UAAU,SAAS,CAAC,QAA2B;IACnD,mBAAmB,EAAE,CAAC;IACtB,gBAAgB,CAAC,GAAG,CAAC,QAAQ,CAAC,CAAC;IAC/B,OAAO,GAAG,EAAE;QACV,gBAAgB,CAAC,MAAM,CAAC,QAAQ,CAAC,CAAC;IACpC,CAAC,CAAC;AACJ,CAAC;AAED,MAAM,UAAU,mBAAmB,CAAC,QAAwC;IAC1E,mBAAmB,EAAE,CAAC;IACtB,cAAc,CAAC,GAAG,CAAC,QAAQ,CAAC,CAAC;IAC7B,OAAO,GAAG,EAAE;QACV,cAAc,CAAC,MAAM,CAAC,QAAQ,CAAC,CAAC;IAClC,CAAC,CAAC;AACJ,CAAC;AAED,mBAAmB,EAAE,CAAC;AAEtB,OAAO,EAAE,UAAU,EAAE,CAAC","sourcesContent":["import { registerPlugin } from '@capacitor/core';\n\nimport type { PushSignalPlugin } from './definitions';\nimport type {\n AndroidFirebaseConfig,\n OnMessageListener,\n PushCredentials,\n PushEnvironment,\n PushMessage,\n PushPlatform,\n} from './types';\n\nconst PushSignal = registerPlugin<PushSignalPlugin>('PushSignal', {\n web: () => import('./web').then((m) => new m.PushSignalWeb()),\n});\n\nconst messageListeners = new Set<OnMessageListener>();\nconst pressListeners = new Set<(message: PushMessage) => void>();\nlet nativeCallbacksBound = false;\n\nfunction normalizeMessage(raw: {\n id?: string;\n title?: string;\n body?: string;\n data?: Record<string, unknown> | object;\n}): PushMessage {\n const data: Record<string, string> = {};\n if (raw.data && typeof raw.data === 'object') {\n for (const [key, value] of Object.entries(raw.data as Record<string, unknown>)) {\n if (value == null) {\n continue;\n }\n data[key] = typeof value === 'string' ? value : String(value);\n }\n }\n\n return {\n id: raw.id,\n title: raw.title,\n body: raw.body,\n data,\n };\n}\n\nfunction normalizeCredentials(raw: {\n platform: string;\n token: string;\n environment?: string;\n}): PushCredentials {\n return {\n platform: raw.platform as PushPlatform,\n token: raw.token,\n environment: raw.environment as PushEnvironment | undefined,\n };\n}\n\nfunction bindNativeCallbacks(): void {\n if (nativeCallbacksBound) {\n return;\n }\n\n nativeCallbacksBound = true;\n\n void PushSignal.addListener('onMessage', (raw) => {\n const message = normalizeMessage(raw);\n for (const listener of [...messageListeners]) {\n try {\n Promise.resolve(listener(message)).then(\n () => undefined,\n () => undefined,\n );\n } catch {\n // Ignore listener failures so one bad subscriber cannot break delivery.\n }\n }\n });\n\n void PushSignal.addListener('onNotificationPress', (raw) => {\n const message = normalizeMessage(raw);\n pressListeners.forEach((listener) => listener(message));\n });\n\n void PushSignal.startListening();\n}\n\nexport function initialize(config: AndroidFirebaseConfig = {}): Promise<void> {\n return PushSignal.initialize(config);\n}\n\nexport function getCredentials(): Promise<PushCredentials> {\n return PushSignal.getCredentials().then(normalizeCredentials);\n}\n\nexport function onMessage(listener: OnMessageListener): () => void {\n bindNativeCallbacks();\n messageListeners.add(listener);\n return () => {\n messageListeners.delete(listener);\n };\n}\n\nexport function onNotificationPress(listener: (message: PushMessage) => void): () => void {\n bindNativeCallbacks();\n pressListeners.add(listener);\n return () => {\n pressListeners.delete(listener);\n };\n}\n\nbindNativeCallbacks();\n\nexport { PushSignal };\n"]}
@@ -0,0 +1,20 @@
1
+ export type PushPlatform = 'ios' | 'android';
2
+ export type PushEnvironment = 'sandbox' | 'production';
3
+ export interface PushCredentials {
4
+ platform: PushPlatform;
5
+ token: string;
6
+ environment?: PushEnvironment;
7
+ }
8
+ export interface PushMessage {
9
+ id?: string;
10
+ title?: string;
11
+ body?: string;
12
+ data: Record<string, string>;
13
+ }
14
+ export type OnMessageListener = (message: PushMessage) => void | Promise<void>;
15
+ export interface AndroidFirebaseConfig {
16
+ project_id?: string;
17
+ mobilesdk_app_id?: string;
18
+ current_key?: string;
19
+ project_number?: string;
20
+ }
@@ -0,0 +1,2 @@
1
+ export {};
2
+ //# sourceMappingURL=types.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"types.js","sourceRoot":"","sources":["../../src/types.ts"],"names":[],"mappings":"","sourcesContent":["export type PushPlatform = 'ios' | 'android';\nexport type PushEnvironment = 'sandbox' | 'production';\n\nexport interface PushCredentials {\n platform: PushPlatform;\n token: string;\n environment?: PushEnvironment;\n}\n\nexport interface PushMessage {\n id?: string;\n title?: string;\n body?: string;\n data: Record<string, string>;\n}\n\nexport type OnMessageListener = (message: PushMessage) => void | Promise<void>;\n\nexport interface AndroidFirebaseConfig {\n project_id?: string;\n mobilesdk_app_id?: string;\n current_key?: string;\n project_number?: string;\n}\n"]}
@@ -0,0 +1,8 @@
1
+ import { WebPlugin } from '@capacitor/core';
2
+ import type { PushSignalPlugin } from './definitions';
3
+ import type { AndroidFirebaseConfig, PushCredentials } from './types';
4
+ export declare class PushSignalWeb extends WebPlugin implements PushSignalPlugin {
5
+ initialize(config?: AndroidFirebaseConfig): Promise<void>;
6
+ getCredentials(): Promise<PushCredentials>;
7
+ startListening(): Promise<void>;
8
+ }
@@ -0,0 +1,13 @@
1
+ import { WebPlugin } from '@capacitor/core';
2
+ export class PushSignalWeb extends WebPlugin {
3
+ async initialize(config) {
4
+ void config;
5
+ }
6
+ async getCredentials() {
7
+ throw this.unimplemented('Push credentials are not supported on web');
8
+ }
9
+ async startListening() {
10
+ return;
11
+ }
12
+ }
13
+ //# sourceMappingURL=web.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"web.js","sourceRoot":"","sources":["../../src/web.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,SAAS,EAAE,MAAM,iBAAiB,CAAC;AAK5C,MAAM,OAAO,aAAc,SAAQ,SAAS;IAC1C,KAAK,CAAC,UAAU,CAAC,MAA8B;QAC7C,KAAK,MAAM,CAAC;IACd,CAAC;IAED,KAAK,CAAC,cAAc;QAClB,MAAM,IAAI,CAAC,aAAa,CAAC,2CAA2C,CAAC,CAAC;IACxE,CAAC;IAED,KAAK,CAAC,cAAc;QAClB,OAAO;IACT,CAAC;CACF","sourcesContent":["import { WebPlugin } from '@capacitor/core';\n\nimport type { PushSignalPlugin } from './definitions';\nimport type { AndroidFirebaseConfig, PushCredentials } from './types';\n\nexport class PushSignalWeb extends WebPlugin implements PushSignalPlugin {\n async initialize(config?: AndroidFirebaseConfig): Promise<void> {\n void config;\n }\n\n async getCredentials(): Promise<PushCredentials> {\n throw this.unimplemented('Push credentials are not supported on web');\n }\n\n async startListening(): Promise<void> {\n return;\n }\n}\n"]}
@@ -0,0 +1,100 @@
1
+ 'use strict';
2
+
3
+ var core = require('@capacitor/core');
4
+
5
+ const PushSignal = core.registerPlugin('PushSignal', {
6
+ web: () => Promise.resolve().then(function () { return web; }).then((m) => new m.PushSignalWeb()),
7
+ });
8
+ const messageListeners = new Set();
9
+ const pressListeners = new Set();
10
+ let nativeCallbacksBound = false;
11
+ function normalizeMessage(raw) {
12
+ const data = {};
13
+ if (raw.data && typeof raw.data === 'object') {
14
+ for (const [key, value] of Object.entries(raw.data)) {
15
+ if (value == null) {
16
+ continue;
17
+ }
18
+ data[key] = typeof value === 'string' ? value : String(value);
19
+ }
20
+ }
21
+ return {
22
+ id: raw.id,
23
+ title: raw.title,
24
+ body: raw.body,
25
+ data,
26
+ };
27
+ }
28
+ function normalizeCredentials(raw) {
29
+ return {
30
+ platform: raw.platform,
31
+ token: raw.token,
32
+ environment: raw.environment,
33
+ };
34
+ }
35
+ function bindNativeCallbacks() {
36
+ if (nativeCallbacksBound) {
37
+ return;
38
+ }
39
+ nativeCallbacksBound = true;
40
+ void PushSignal.addListener('onMessage', (raw) => {
41
+ const message = normalizeMessage(raw);
42
+ for (const listener of [...messageListeners]) {
43
+ try {
44
+ Promise.resolve(listener(message)).then(() => undefined, () => undefined);
45
+ }
46
+ catch (_a) {
47
+ // Ignore listener failures so one bad subscriber cannot break delivery.
48
+ }
49
+ }
50
+ });
51
+ void PushSignal.addListener('onNotificationPress', (raw) => {
52
+ const message = normalizeMessage(raw);
53
+ pressListeners.forEach((listener) => listener(message));
54
+ });
55
+ void PushSignal.startListening();
56
+ }
57
+ function initialize(config = {}) {
58
+ return PushSignal.initialize(config);
59
+ }
60
+ function getCredentials() {
61
+ return PushSignal.getCredentials().then(normalizeCredentials);
62
+ }
63
+ function onMessage(listener) {
64
+ bindNativeCallbacks();
65
+ messageListeners.add(listener);
66
+ return () => {
67
+ messageListeners.delete(listener);
68
+ };
69
+ }
70
+ function onNotificationPress(listener) {
71
+ bindNativeCallbacks();
72
+ pressListeners.add(listener);
73
+ return () => {
74
+ pressListeners.delete(listener);
75
+ };
76
+ }
77
+ bindNativeCallbacks();
78
+
79
+ class PushSignalWeb extends core.WebPlugin {
80
+ async initialize(config) {
81
+ }
82
+ async getCredentials() {
83
+ throw this.unimplemented('Push credentials are not supported on web');
84
+ }
85
+ async startListening() {
86
+ return;
87
+ }
88
+ }
89
+
90
+ var web = /*#__PURE__*/Object.freeze({
91
+ __proto__: null,
92
+ PushSignalWeb: PushSignalWeb
93
+ });
94
+
95
+ exports.PushSignal = PushSignal;
96
+ exports.getCredentials = getCredentials;
97
+ exports.initialize = initialize;
98
+ exports.onMessage = onMessage;
99
+ exports.onNotificationPress = onNotificationPress;
100
+ //# sourceMappingURL=plugin.cjs.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"plugin.cjs.js","sources":["esm/pushSignal.js","esm/web.js"],"sourcesContent":["import { registerPlugin } from '@capacitor/core';\nconst PushSignal = registerPlugin('PushSignal', {\n web: () => import('./web').then((m) => new m.PushSignalWeb()),\n});\nconst messageListeners = new Set();\nconst pressListeners = new Set();\nlet nativeCallbacksBound = false;\nfunction normalizeMessage(raw) {\n const data = {};\n if (raw.data && typeof raw.data === 'object') {\n for (const [key, value] of Object.entries(raw.data)) {\n if (value == null) {\n continue;\n }\n data[key] = typeof value === 'string' ? value : String(value);\n }\n }\n return {\n id: raw.id,\n title: raw.title,\n body: raw.body,\n data,\n };\n}\nfunction normalizeCredentials(raw) {\n return {\n platform: raw.platform,\n token: raw.token,\n environment: raw.environment,\n };\n}\nfunction bindNativeCallbacks() {\n if (nativeCallbacksBound) {\n return;\n }\n nativeCallbacksBound = true;\n void PushSignal.addListener('onMessage', (raw) => {\n const message = normalizeMessage(raw);\n for (const listener of [...messageListeners]) {\n try {\n Promise.resolve(listener(message)).then(() => undefined, () => undefined);\n }\n catch (_a) {\n // Ignore listener failures so one bad subscriber cannot break delivery.\n }\n }\n });\n void PushSignal.addListener('onNotificationPress', (raw) => {\n const message = normalizeMessage(raw);\n pressListeners.forEach((listener) => listener(message));\n });\n void PushSignal.startListening();\n}\nexport function initialize(config = {}) {\n return PushSignal.initialize(config);\n}\nexport function getCredentials() {\n return PushSignal.getCredentials().then(normalizeCredentials);\n}\nexport function onMessage(listener) {\n bindNativeCallbacks();\n messageListeners.add(listener);\n return () => {\n messageListeners.delete(listener);\n };\n}\nexport function onNotificationPress(listener) {\n bindNativeCallbacks();\n pressListeners.add(listener);\n return () => {\n pressListeners.delete(listener);\n };\n}\nbindNativeCallbacks();\nexport { PushSignal };\n//# sourceMappingURL=pushSignal.js.map","import { WebPlugin } from '@capacitor/core';\nexport class PushSignalWeb extends WebPlugin {\n async initialize(config) {\n void config;\n }\n async getCredentials() {\n throw this.unimplemented('Push credentials are not supported on web');\n }\n async startListening() {\n return;\n }\n}\n//# sourceMappingURL=web.js.map"],"names":["registerPlugin","WebPlugin"],"mappings":";;;;AACK,MAAC,UAAU,GAAGA,mBAAc,CAAC,YAAY,EAAE;AAChD,IAAI,GAAG,EAAE,MAAM,mDAAe,CAAC,IAAI,CAAC,CAAC,CAAC,KAAK,IAAI,CAAC,CAAC,aAAa,EAAE,CAAC;AACjE,CAAC;AACD,MAAM,gBAAgB,GAAG,IAAI,GAAG,EAAE;AAClC,MAAM,cAAc,GAAG,IAAI,GAAG,EAAE;AAChC,IAAI,oBAAoB,GAAG,KA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