@xbg.solutions/utils-push-notifications-connector 1.0.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/lib/index.d.ts +11 -0
- package/lib/index.d.ts.map +1 -0
- package/lib/index.js +56 -0
- package/lib/index.js.map +1 -0
- package/lib/providers/fcm-provider.d.ts +40 -0
- package/lib/providers/fcm-provider.d.ts.map +1 -0
- package/lib/providers/fcm-provider.js +250 -0
- package/lib/providers/fcm-provider.js.map +1 -0
- package/lib/push-notifications-connector.d.ts +58 -0
- package/lib/push-notifications-connector.d.ts.map +1 -0
- package/lib/push-notifications-connector.js +129 -0
- package/lib/push-notifications-connector.js.map +1 -0
- package/lib/types.d.ts +74 -0
- package/lib/types.d.ts.map +1 -0
- package/lib/types.js +6 -0
- package/lib/types.js.map +1 -0
- package/package.json +30 -0
package/lib/index.d.ts
ADDED
|
@@ -0,0 +1,11 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Push Notifications Connector Barrel Export
|
|
3
|
+
*/
|
|
4
|
+
export * from './types';
|
|
5
|
+
export * from './push-notifications-connector';
|
|
6
|
+
export * from './providers/fcm-provider';
|
|
7
|
+
import { PushNotificationsConnector } from './push-notifications-connector';
|
|
8
|
+
export declare function initializePushNotificationsConnector(config: any): void;
|
|
9
|
+
export declare function createPushNotificationsConnector(): PushNotificationsConnector | null;
|
|
10
|
+
export declare function getPushNotificationsConnector(): PushNotificationsConnector | null;
|
|
11
|
+
//# sourceMappingURL=index.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AAAA;;GAEG;AAEH,cAAc,SAAS,CAAC;AACxB,cAAc,gCAAgC,CAAC;AAC/C,cAAc,0BAA0B,CAAC;AAEzC,OAAO,EAAE,0BAA0B,EAAE,MAAM,gCAAgC,CAAC;AAM5E,wBAAgB,oCAAoC,CAAC,MAAM,EAAE,GAAG,GAAG,IAAI,CAItE;AAED,wBAAgB,gCAAgC,IAAI,0BAA0B,GAAG,IAAI,CAiBpF;AAID,wBAAgB,6BAA6B,IAAI,0BAA0B,GAAG,IAAI,CAKjF"}
|
package/lib/index.js
ADDED
|
@@ -0,0 +1,56 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
/**
|
|
3
|
+
* Push Notifications Connector Barrel Export
|
|
4
|
+
*/
|
|
5
|
+
var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) {
|
|
6
|
+
if (k2 === undefined) k2 = k;
|
|
7
|
+
var desc = Object.getOwnPropertyDescriptor(m, k);
|
|
8
|
+
if (!desc || ("get" in desc ? !m.__esModule : desc.writable || desc.configurable)) {
|
|
9
|
+
desc = { enumerable: true, get: function() { return m[k]; } };
|
|
10
|
+
}
|
|
11
|
+
Object.defineProperty(o, k2, desc);
|
|
12
|
+
}) : (function(o, m, k, k2) {
|
|
13
|
+
if (k2 === undefined) k2 = k;
|
|
14
|
+
o[k2] = m[k];
|
|
15
|
+
}));
|
|
16
|
+
var __exportStar = (this && this.__exportStar) || function(m, exports) {
|
|
17
|
+
for (var p in m) if (p !== "default" && !Object.prototype.hasOwnProperty.call(exports, p)) __createBinding(exports, m, p);
|
|
18
|
+
};
|
|
19
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
20
|
+
exports.initializePushNotificationsConnector = initializePushNotificationsConnector;
|
|
21
|
+
exports.createPushNotificationsConnector = createPushNotificationsConnector;
|
|
22
|
+
exports.getPushNotificationsConnector = getPushNotificationsConnector;
|
|
23
|
+
__exportStar(require("./types"), exports);
|
|
24
|
+
__exportStar(require("./push-notifications-connector"), exports);
|
|
25
|
+
__exportStar(require("./providers/fcm-provider"), exports);
|
|
26
|
+
const push_notifications_connector_1 = require("./push-notifications-connector");
|
|
27
|
+
const fcm_provider_1 = require("./providers/fcm-provider");
|
|
28
|
+
// Config is provided via initializePushNotificationsConnector() at app startup
|
|
29
|
+
let connectorConfig = null;
|
|
30
|
+
function initializePushNotificationsConnector(config) {
|
|
31
|
+
connectorConfig = config;
|
|
32
|
+
// Reset singleton so it gets re-created with new config
|
|
33
|
+
pushNotificationsConnectorInstance = undefined;
|
|
34
|
+
}
|
|
35
|
+
function createPushNotificationsConnector() {
|
|
36
|
+
if (!connectorConfig) {
|
|
37
|
+
throw new Error('Push notifications connector not initialized. Call initializePushNotificationsConnector() first.');
|
|
38
|
+
}
|
|
39
|
+
if (!connectorConfig.pushNotifications.enabled) {
|
|
40
|
+
return null;
|
|
41
|
+
}
|
|
42
|
+
const provider = connectorConfig.pushNotifications.provider;
|
|
43
|
+
if (provider === 'fcm') {
|
|
44
|
+
const config = connectorConfig.pushNotifications.providers.fcm;
|
|
45
|
+
return new push_notifications_connector_1.PushNotificationsConnector(new fcm_provider_1.FCMProvider(config));
|
|
46
|
+
}
|
|
47
|
+
throw new Error(`Unsupported push notifications provider: ${provider}`);
|
|
48
|
+
}
|
|
49
|
+
let pushNotificationsConnectorInstance;
|
|
50
|
+
function getPushNotificationsConnector() {
|
|
51
|
+
if (pushNotificationsConnectorInstance === undefined) {
|
|
52
|
+
pushNotificationsConnectorInstance = createPushNotificationsConnector();
|
|
53
|
+
}
|
|
54
|
+
return pushNotificationsConnectorInstance;
|
|
55
|
+
}
|
|
56
|
+
//# sourceMappingURL=index.js.map
|
package/lib/index.js.map
ADDED
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"index.js","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":";AAAA;;GAEG;;;;;;;;;;;;;;;;AAYH,oFAIC;AAED,4EAiBC;AAID,sEAKC;AA1CD,0CAAwB;AACxB,iEAA+C;AAC/C,2DAAyC;AAEzC,iFAA4E;AAC5E,2DAAuD;AAEvD,+EAA+E;AAC/E,IAAI,eAAe,GAAQ,IAAI,CAAC;AAEhC,SAAgB,oCAAoC,CAAC,MAAW;IAC9D,eAAe,GAAG,MAAM,CAAC;IACzB,wDAAwD;IACxD,kCAAkC,GAAG,SAAS,CAAC;AACjD,CAAC;AAED,SAAgB,gCAAgC;IAC9C,IAAI,CAAC,eAAe,EAAE,CAAC;QACrB,MAAM,IAAI,KAAK,CAAC,kGAAkG,CAAC,CAAC;IACtH,CAAC;IAED,IAAI,CAAC,eAAe,CAAC,iBAAiB,CAAC,OAAO,EAAE,CAAC;QAC/C,OAAO,IAAI,CAAC;IACd,CAAC;IAED,MAAM,QAAQ,GAAG,eAAe,CAAC,iBAAiB,CAAC,QAAQ,CAAC;IAE5D,IAAI,QAAQ,KAAK,KAAK,EAAE,CAAC;QACvB,MAAM,MAAM,GAAG,eAAe,CAAC,iBAAiB,CAAC,SAAS,CAAC,GAAG,CAAC;QAC/D,OAAO,IAAI,yDAA0B,CAAC,IAAI,0BAAW,CAAC,MAAM,CAAC,CAAC,CAAC;IACjE,CAAC;IAED,MAAM,IAAI,KAAK,CAAC,4CAA4C,QAAQ,EAAE,CAAC,CAAC;AAC1E,CAAC;AAED,IAAI,kCAAiF,CAAC;AAEtF,SAAgB,6BAA6B;IAC3C,IAAI,kCAAkC,KAAK,SAAS,EAAE,CAAC;QACrD,kCAAkC,GAAG,gCAAgC,EAAE,CAAC;IAC1E,CAAC;IACD,OAAO,kCAAkC,CAAC;AAC5C,CAAC"}
|
|
@@ -0,0 +1,40 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Firebase Cloud Messaging (FCM) Provider
|
|
3
|
+
*/
|
|
4
|
+
import { PushNotificationsProvider } from '../push-notifications-connector';
|
|
5
|
+
import { SendNotificationRequest, SendNotificationResponse, TopicSubscriptionRequest, TopicSubscriptionResponse } from '../types';
|
|
6
|
+
export interface FCMProviderConfig {
|
|
7
|
+
}
|
|
8
|
+
export declare class FCMProvider implements PushNotificationsProvider {
|
|
9
|
+
private messaging;
|
|
10
|
+
constructor(config?: FCMProviderConfig);
|
|
11
|
+
/**
|
|
12
|
+
* Send notification to single target (token, topic, or condition)
|
|
13
|
+
*/
|
|
14
|
+
send(request: SendNotificationRequest): Promise<SendNotificationResponse>;
|
|
15
|
+
/**
|
|
16
|
+
* Send notification to multiple devices
|
|
17
|
+
*/
|
|
18
|
+
sendMulticast(request: SendNotificationRequest): Promise<SendNotificationResponse>;
|
|
19
|
+
/**
|
|
20
|
+
* Subscribe tokens to a topic
|
|
21
|
+
*/
|
|
22
|
+
subscribeToTopic(request: TopicSubscriptionRequest): Promise<TopicSubscriptionResponse>;
|
|
23
|
+
/**
|
|
24
|
+
* Unsubscribe tokens from a topic
|
|
25
|
+
*/
|
|
26
|
+
unsubscribeFromTopic(request: TopicSubscriptionRequest): Promise<TopicSubscriptionResponse>;
|
|
27
|
+
/**
|
|
28
|
+
* Validate device token by attempting a dry run send
|
|
29
|
+
*/
|
|
30
|
+
validateToken(token: string): Promise<boolean>;
|
|
31
|
+
/**
|
|
32
|
+
* Build FCM message for single target
|
|
33
|
+
*/
|
|
34
|
+
private buildMessage;
|
|
35
|
+
/**
|
|
36
|
+
* Build FCM multicast message
|
|
37
|
+
*/
|
|
38
|
+
private buildMulticastMessage;
|
|
39
|
+
}
|
|
40
|
+
//# sourceMappingURL=fcm-provider.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"fcm-provider.d.ts","sourceRoot":"","sources":["../../src/providers/fcm-provider.ts"],"names":[],"mappings":"AAAA;;GAEG;AAGH,OAAO,EAAE,yBAAyB,EAAE,MAAM,iCAAiC,CAAC;AAC5E,OAAO,EACL,uBAAuB,EACvB,wBAAwB,EACxB,wBAAwB,EACxB,yBAAyB,EAC1B,MAAM,UAAU,CAAC;AAElB,MAAM,WAAW,iBAAiB;CAGjC;AAED,qBAAa,WAAY,YAAW,yBAAyB;IAC3D,OAAO,CAAC,SAAS,CAA4B;gBAEjC,MAAM,CAAC,EAAE,iBAAiB;IAItC;;OAEG;IACG,IAAI,CAAC,OAAO,EAAE,uBAAuB,GAAG,OAAO,CAAC,wBAAwB,CAAC;IAwB/E;;OAEG;IACG,aAAa,CAAC,OAAO,EAAE,uBAAuB,GAAG,OAAO,CAAC,wBAAwB,CAAC;IAwCxF;;OAEG;IACG,gBAAgB,CAAC,OAAO,EAAE,wBAAwB,GAAG,OAAO,CAAC,yBAAyB,CAAC;IA6B7F;;OAEG;IACG,oBAAoB,CAAC,OAAO,EAAE,wBAAwB,GAAG,OAAO,CAAC,yBAAyB,CAAC;IA6BjG;;OAEG;IACG,aAAa,CAAC,KAAK,EAAE,MAAM,GAAG,OAAO,CAAC,OAAO,CAAC;IAkBpD;;OAEG;IACH,OAAO,CAAC,YAAY;IAgEpB;;OAEG;IACH,OAAO,CAAC,qBAAqB;CAQ9B"}
|
|
@@ -0,0 +1,250 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
/**
|
|
3
|
+
* Firebase Cloud Messaging (FCM) Provider
|
|
4
|
+
*/
|
|
5
|
+
var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) {
|
|
6
|
+
if (k2 === undefined) k2 = k;
|
|
7
|
+
var desc = Object.getOwnPropertyDescriptor(m, k);
|
|
8
|
+
if (!desc || ("get" in desc ? !m.__esModule : desc.writable || desc.configurable)) {
|
|
9
|
+
desc = { enumerable: true, get: function() { return m[k]; } };
|
|
10
|
+
}
|
|
11
|
+
Object.defineProperty(o, k2, desc);
|
|
12
|
+
}) : (function(o, m, k, k2) {
|
|
13
|
+
if (k2 === undefined) k2 = k;
|
|
14
|
+
o[k2] = m[k];
|
|
15
|
+
}));
|
|
16
|
+
var __setModuleDefault = (this && this.__setModuleDefault) || (Object.create ? (function(o, v) {
|
|
17
|
+
Object.defineProperty(o, "default", { enumerable: true, value: v });
|
|
18
|
+
}) : function(o, v) {
|
|
19
|
+
o["default"] = v;
|
|
20
|
+
});
|
|
21
|
+
var __importStar = (this && this.__importStar) || (function () {
|
|
22
|
+
var ownKeys = function(o) {
|
|
23
|
+
ownKeys = Object.getOwnPropertyNames || function (o) {
|
|
24
|
+
var ar = [];
|
|
25
|
+
for (var k in o) if (Object.prototype.hasOwnProperty.call(o, k)) ar[ar.length] = k;
|
|
26
|
+
return ar;
|
|
27
|
+
};
|
|
28
|
+
return ownKeys(o);
|
|
29
|
+
};
|
|
30
|
+
return function (mod) {
|
|
31
|
+
if (mod && mod.__esModule) return mod;
|
|
32
|
+
var result = {};
|
|
33
|
+
if (mod != null) for (var k = ownKeys(mod), i = 0; i < k.length; i++) if (k[i] !== "default") __createBinding(result, mod, k[i]);
|
|
34
|
+
__setModuleDefault(result, mod);
|
|
35
|
+
return result;
|
|
36
|
+
};
|
|
37
|
+
})();
|
|
38
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
39
|
+
exports.FCMProvider = void 0;
|
|
40
|
+
const admin = __importStar(require("firebase-admin"));
|
|
41
|
+
class FCMProvider {
|
|
42
|
+
constructor(config) {
|
|
43
|
+
this.messaging = admin.messaging();
|
|
44
|
+
}
|
|
45
|
+
/**
|
|
46
|
+
* Send notification to single target (token, topic, or condition)
|
|
47
|
+
*/
|
|
48
|
+
async send(request) {
|
|
49
|
+
try {
|
|
50
|
+
const message = this.buildMessage(request);
|
|
51
|
+
const messageId = await this.messaging.send(message);
|
|
52
|
+
return {
|
|
53
|
+
success: true,
|
|
54
|
+
messageId,
|
|
55
|
+
successCount: 1,
|
|
56
|
+
failureCount: 0,
|
|
57
|
+
};
|
|
58
|
+
}
|
|
59
|
+
catch (error) {
|
|
60
|
+
return {
|
|
61
|
+
success: false,
|
|
62
|
+
successCount: 0,
|
|
63
|
+
failureCount: 1,
|
|
64
|
+
errors: [{
|
|
65
|
+
error: error instanceof Error ? error.message : String(error),
|
|
66
|
+
}],
|
|
67
|
+
};
|
|
68
|
+
}
|
|
69
|
+
}
|
|
70
|
+
/**
|
|
71
|
+
* Send notification to multiple devices
|
|
72
|
+
*/
|
|
73
|
+
async sendMulticast(request) {
|
|
74
|
+
if (!request.target.tokens || request.target.tokens.length === 0) {
|
|
75
|
+
return {
|
|
76
|
+
success: false,
|
|
77
|
+
successCount: 0,
|
|
78
|
+
failureCount: 0,
|
|
79
|
+
errors: [{ error: 'No tokens provided' }],
|
|
80
|
+
};
|
|
81
|
+
}
|
|
82
|
+
try {
|
|
83
|
+
const message = this.buildMulticastMessage(request);
|
|
84
|
+
const response = await this.messaging.sendEachForMulticast(message);
|
|
85
|
+
const errors = response.responses
|
|
86
|
+
.map((resp, idx) => {
|
|
87
|
+
var _a;
|
|
88
|
+
return ({
|
|
89
|
+
token: request.target.tokens[idx],
|
|
90
|
+
error: ((_a = resp.error) === null || _a === void 0 ? void 0 : _a.message) || '',
|
|
91
|
+
});
|
|
92
|
+
})
|
|
93
|
+
.filter(item => item.error);
|
|
94
|
+
return {
|
|
95
|
+
success: response.successCount > 0,
|
|
96
|
+
successCount: response.successCount,
|
|
97
|
+
failureCount: response.failureCount,
|
|
98
|
+
errors: errors.length > 0 ? errors : undefined,
|
|
99
|
+
};
|
|
100
|
+
}
|
|
101
|
+
catch (error) {
|
|
102
|
+
return {
|
|
103
|
+
success: false,
|
|
104
|
+
successCount: 0,
|
|
105
|
+
failureCount: request.target.tokens.length,
|
|
106
|
+
errors: [{
|
|
107
|
+
error: error instanceof Error ? error.message : String(error),
|
|
108
|
+
}],
|
|
109
|
+
};
|
|
110
|
+
}
|
|
111
|
+
}
|
|
112
|
+
/**
|
|
113
|
+
* Subscribe tokens to a topic
|
|
114
|
+
*/
|
|
115
|
+
async subscribeToTopic(request) {
|
|
116
|
+
try {
|
|
117
|
+
const response = await this.messaging.subscribeToTopic(request.tokens, request.topic);
|
|
118
|
+
const errors = response.errors.map((error, idx) => ({
|
|
119
|
+
token: request.tokens[idx],
|
|
120
|
+
error: error.error.message,
|
|
121
|
+
}));
|
|
122
|
+
return {
|
|
123
|
+
successCount: response.successCount,
|
|
124
|
+
failureCount: response.failureCount,
|
|
125
|
+
errors: errors.length > 0 ? errors : undefined,
|
|
126
|
+
};
|
|
127
|
+
}
|
|
128
|
+
catch (error) {
|
|
129
|
+
return {
|
|
130
|
+
successCount: 0,
|
|
131
|
+
failureCount: request.tokens.length,
|
|
132
|
+
errors: [{
|
|
133
|
+
token: '',
|
|
134
|
+
error: error instanceof Error ? error.message : String(error),
|
|
135
|
+
}],
|
|
136
|
+
};
|
|
137
|
+
}
|
|
138
|
+
}
|
|
139
|
+
/**
|
|
140
|
+
* Unsubscribe tokens from a topic
|
|
141
|
+
*/
|
|
142
|
+
async unsubscribeFromTopic(request) {
|
|
143
|
+
try {
|
|
144
|
+
const response = await this.messaging.unsubscribeFromTopic(request.tokens, request.topic);
|
|
145
|
+
const errors = response.errors.map((error, idx) => ({
|
|
146
|
+
token: request.tokens[idx],
|
|
147
|
+
error: error.error.message,
|
|
148
|
+
}));
|
|
149
|
+
return {
|
|
150
|
+
successCount: response.successCount,
|
|
151
|
+
failureCount: response.failureCount,
|
|
152
|
+
errors: errors.length > 0 ? errors : undefined,
|
|
153
|
+
};
|
|
154
|
+
}
|
|
155
|
+
catch (error) {
|
|
156
|
+
return {
|
|
157
|
+
successCount: 0,
|
|
158
|
+
failureCount: request.tokens.length,
|
|
159
|
+
errors: [{
|
|
160
|
+
token: '',
|
|
161
|
+
error: error instanceof Error ? error.message : String(error),
|
|
162
|
+
}],
|
|
163
|
+
};
|
|
164
|
+
}
|
|
165
|
+
}
|
|
166
|
+
/**
|
|
167
|
+
* Validate device token by attempting a dry run send
|
|
168
|
+
*/
|
|
169
|
+
async validateToken(token) {
|
|
170
|
+
try {
|
|
171
|
+
// FCM doesn't have a direct validation method
|
|
172
|
+
// We can try a dry run send to check token validity
|
|
173
|
+
await this.messaging.send({
|
|
174
|
+
token,
|
|
175
|
+
notification: {
|
|
176
|
+
title: 'Test',
|
|
177
|
+
body: 'Validation test',
|
|
178
|
+
},
|
|
179
|
+
}, true); // dry run
|
|
180
|
+
return true;
|
|
181
|
+
}
|
|
182
|
+
catch (error) {
|
|
183
|
+
return false;
|
|
184
|
+
}
|
|
185
|
+
}
|
|
186
|
+
/**
|
|
187
|
+
* Build FCM message for single target
|
|
188
|
+
*/
|
|
189
|
+
buildMessage(request) {
|
|
190
|
+
const basePayload = {
|
|
191
|
+
notification: {
|
|
192
|
+
title: request.notification.title,
|
|
193
|
+
body: request.notification.body,
|
|
194
|
+
imageUrl: request.notification.imageUrl,
|
|
195
|
+
},
|
|
196
|
+
data: request.notification.data,
|
|
197
|
+
};
|
|
198
|
+
// Build message with proper type based on target
|
|
199
|
+
let message;
|
|
200
|
+
if (request.target.token) {
|
|
201
|
+
message = Object.assign(Object.assign({}, basePayload), { token: request.target.token });
|
|
202
|
+
}
|
|
203
|
+
else if (request.target.topic) {
|
|
204
|
+
message = Object.assign(Object.assign({}, basePayload), { topic: request.target.topic });
|
|
205
|
+
}
|
|
206
|
+
else if (request.target.condition) {
|
|
207
|
+
message = Object.assign(Object.assign({}, basePayload), { condition: request.target.condition });
|
|
208
|
+
}
|
|
209
|
+
else {
|
|
210
|
+
throw new Error('Message must have either token, topic, or condition');
|
|
211
|
+
}
|
|
212
|
+
// Add Android-specific options
|
|
213
|
+
if (request.options) {
|
|
214
|
+
message.android = {
|
|
215
|
+
priority: request.options.priority === 'high' ? 'high' : 'normal',
|
|
216
|
+
ttl: request.options.ttl ? request.options.ttl * 1000 : undefined,
|
|
217
|
+
collapseKey: request.options.collapseKey,
|
|
218
|
+
};
|
|
219
|
+
// Add iOS-specific options
|
|
220
|
+
message.apns = {
|
|
221
|
+
payload: {
|
|
222
|
+
aps: {
|
|
223
|
+
badge: request.notification.badge,
|
|
224
|
+
sound: request.notification.sound || 'default',
|
|
225
|
+
contentAvailable: request.options.contentAvailable,
|
|
226
|
+
mutableContent: request.options.mutableContent,
|
|
227
|
+
},
|
|
228
|
+
},
|
|
229
|
+
};
|
|
230
|
+
}
|
|
231
|
+
// Add web push options
|
|
232
|
+
if (request.notification.clickAction) {
|
|
233
|
+
message.webpush = {
|
|
234
|
+
fcmOptions: {
|
|
235
|
+
link: request.notification.clickAction,
|
|
236
|
+
},
|
|
237
|
+
};
|
|
238
|
+
}
|
|
239
|
+
return message;
|
|
240
|
+
}
|
|
241
|
+
/**
|
|
242
|
+
* Build FCM multicast message
|
|
243
|
+
*/
|
|
244
|
+
buildMulticastMessage(request) {
|
|
245
|
+
const baseMessage = this.buildMessage(request);
|
|
246
|
+
return Object.assign(Object.assign({}, baseMessage), { tokens: request.target.tokens });
|
|
247
|
+
}
|
|
248
|
+
}
|
|
249
|
+
exports.FCMProvider = FCMProvider;
|
|
250
|
+
//# sourceMappingURL=fcm-provider.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"fcm-provider.js","sourceRoot":"","sources":["../../src/providers/fcm-provider.ts"],"names":[],"mappings":";AAAA;;GAEG;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;AAEH,sDAAwC;AAcxC,MAAa,WAAW;IAGtB,YAAY,MAA0B;QACpC,IAAI,CAAC,SAAS,GAAG,KAAK,CAAC,SAAS,EAAE,CAAC;IACrC,CAAC;IAED;;OAEG;IACH,KAAK,CAAC,IAAI,CAAC,OAAgC;QACzC,IAAI,CAAC;YACH,MAAM,OAAO,GAAG,IAAI,CAAC,YAAY,CAAC,OAAO,CAAC,CAAC;YAE3C,MAAM,SAAS,GAAG,MAAM,IAAI,CAAC,SAAS,CAAC,IAAI,CAAC,OAAO,CAAC,CAAC;YAErD,OAAO;gBACL,OAAO,EAAE,IAAI;gBACb,SAAS;gBACT,YAAY,EAAE,CAAC;gBACf,YAAY,EAAE,CAAC;aAChB,CAAC;QACJ,CAAC;QAAC,OAAO,KAAK,EAAE,CAAC;YACf,OAAO;gBACL,OAAO,EAAE,KAAK;gBACd,YAAY,EAAE,CAAC;gBACf,YAAY,EAAE,CAAC;gBACf,MAAM,EAAE,CAAC;wBACP,KAAK,EAAE,KAAK,YAAY,KAAK,CAAC,CAAC,CAAC,KAAK,CAAC,OAAO,CAAC,CAAC,CAAC,MAAM,CAAC,KAAK,CAAC;qBAC9D,CAAC;aACH,CAAC;QACJ,CAAC;IACH,CAAC;IAED;;OAEG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AO,CAAC,GAAG,GAAG,IAAI,CAAC,CAAC,CAAC,SAAS;gBACjE,WAAW,EAAE,OAAO,CAAC,OAAO,CAAC,WAAW;aACzC,CAAC;YAEF,2BAA2B;YAC3B,OAAO,CAAC,IAAI,GAAG;gBACb,OAAO,EAAE;oBACP,GAAG,EAAE;wBACH,KAAK,EAAE,OAAO,CAAC,YAAY,CAAC,KAAK;wBACjC,KAAK,EAAE,OAAO,CAAC,YAAY,CAAC,KAAK,IAAI,SAAS;wBAC9C,gBAAgB,EAAE,OAAO,CAAC,OAAO,CAAC,gBAAgB;wBAClD,cAAc,EAAE,OAAO,CAAC,OAAO,CAAC,cAAc;qBAC/C;iBACF;aACF,CAAC;QACJ,CAAC;QAED,uBAAuB;QACvB,IAAI,OAAO,CAAC,YAAY,CAAC,WAAW,EAAE,CAAC;YACrC,OAAO,CAAC,OAAO,GAAG;gBAChB,UAAU,EAAE;oBACV,IAAI,EAAE,OAAO,CAAC,YAAY,CAAC,WAAW;iBACvC;aACF,CAAC;QACJ,CAAC;QAED,OAAO,OAAO,CAAC;IACjB,CAAC;IAED;;OAEG;IACK,qBAAqB,CAAC,OAAgC;QAC5D,MAAM,WAAW,GAAG,IAAI,CAAC,YAAY,CAAC,OAAO,CAAC,CAAC;QAE/C,uCACK,WAAW,KACd,MAAM,EAAE,OAAO,CAAC,MAAM,CAAC,MAAO,IAC9B;IACJ,CAAC;CACF;AAhPD,kCAgPC"}
|
|
@@ -0,0 +1,58 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Push Notifications Connector
|
|
3
|
+
*/
|
|
4
|
+
import { SendNotificationRequest, SendNotificationResponse, TopicSubscriptionRequest, TopicSubscriptionResponse } from './types';
|
|
5
|
+
/**
|
|
6
|
+
* Push Notifications Provider Interface
|
|
7
|
+
*/
|
|
8
|
+
export interface PushNotificationsProvider {
|
|
9
|
+
/**
|
|
10
|
+
* Send push notification
|
|
11
|
+
*/
|
|
12
|
+
send(request: SendNotificationRequest): Promise<SendNotificationResponse>;
|
|
13
|
+
/**
|
|
14
|
+
* Send notification to multiple devices
|
|
15
|
+
*/
|
|
16
|
+
sendMulticast(request: SendNotificationRequest): Promise<SendNotificationResponse>;
|
|
17
|
+
/**
|
|
18
|
+
* Subscribe tokens to a topic
|
|
19
|
+
*/
|
|
20
|
+
subscribeToTopic(request: TopicSubscriptionRequest): Promise<TopicSubscriptionResponse>;
|
|
21
|
+
/**
|
|
22
|
+
* Unsubscribe tokens from a topic
|
|
23
|
+
*/
|
|
24
|
+
unsubscribeFromTopic(request: TopicSubscriptionRequest): Promise<TopicSubscriptionResponse>;
|
|
25
|
+
/**
|
|
26
|
+
* Validate device token
|
|
27
|
+
*/
|
|
28
|
+
validateToken(token: string): Promise<boolean>;
|
|
29
|
+
}
|
|
30
|
+
/**
|
|
31
|
+
* Push Notifications Connector
|
|
32
|
+
* Provides unified interface for sending push notifications
|
|
33
|
+
*/
|
|
34
|
+
export declare class PushNotificationsConnector {
|
|
35
|
+
private provider;
|
|
36
|
+
constructor(provider: PushNotificationsProvider);
|
|
37
|
+
/**
|
|
38
|
+
* Send push notification to single device, topic, or condition
|
|
39
|
+
*/
|
|
40
|
+
send(request: SendNotificationRequest): Promise<SendNotificationResponse>;
|
|
41
|
+
/**
|
|
42
|
+
* Send push notification to multiple devices
|
|
43
|
+
*/
|
|
44
|
+
sendMulticast(request: SendNotificationRequest): Promise<SendNotificationResponse>;
|
|
45
|
+
/**
|
|
46
|
+
* Subscribe device tokens to a topic
|
|
47
|
+
*/
|
|
48
|
+
subscribeToTopic(request: TopicSubscriptionRequest): Promise<TopicSubscriptionResponse>;
|
|
49
|
+
/**
|
|
50
|
+
* Unsubscribe device tokens from a topic
|
|
51
|
+
*/
|
|
52
|
+
unsubscribeFromTopic(request: TopicSubscriptionRequest): Promise<TopicSubscriptionResponse>;
|
|
53
|
+
/**
|
|
54
|
+
* Validate if a device token is valid
|
|
55
|
+
*/
|
|
56
|
+
validateToken(token: string): Promise<boolean>;
|
|
57
|
+
}
|
|
58
|
+
//# sourceMappingURL=push-notifications-connector.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"push-notifications-connector.d.ts","sourceRoot":"","sources":["../src/push-notifications-connector.ts"],"names":[],"mappings":"AAAA;;GAEG;AAEH,OAAO,EACL,uBAAuB,EACvB,wBAAwB,EACxB,wBAAwB,EACxB,yBAAyB,EAC1B,MAAM,SAAS,CAAC;AAGjB;;GAEG;AACH,MAAM,WAAW,yBAAyB;IACxC;;OAEG;IACH,IAAI,CAAC,OAAO,EAAE,uBAAuB,GAAG,OAAO,CAAC,wBAAwB,CAAC,CAAC;IAE1E;;OAEG;IACH,aAAa,CAAC,OAAO,EAAE,uBAAuB,GAAG,OAAO,CAAC,wBAAwB,CAAC,CAAC;IAEnF;;OAEG;IACH,gBAAgB,CAAC,OAAO,EAAE,wBAAwB,GAAG,OAAO,CAAC,yBAAyB,CAAC,CAAC;IAExF;;OAEG;IACH,oBAAoB,CAAC,OAAO,EAAE,wBAAwB,GAAG,OAAO,CAAC,yBAAyB,CAAC,CAAC;IAE5F;;OAEG;IACH,aAAa,CAAC,KAAK,EAAE,MAAM,GAAG,OAAO,CAAC,OAAO,CAAC,CAAC;CAChD;AAED;;;GAGG;AACH,qBAAa,0BAA0B;IACrC,OAAO,CAAC,QAAQ,CAA4B;gBAEhC,QAAQ,EAAE,yBAAyB;IAI/C;;OAEG;IACG,IAAI,CAAC,OAAO,EAAE,uBAAuB,GAAG,OAAO,CAAC,wBAAwB,CAAC;IA0B/E;;OAEG;IACG,aAAa,CAAC,OAAO,EAAE,uBAAuB,GAAG,OAAO,CAAC,wBAAwB,CAAC;IAyBxF;;OAEG;IACG,gBAAgB,CAAC,OAAO,EAAE,wBAAwB,GAAG,OAAO,CAAC,yBAAyB,CAAC;IAwB7F;;OAEG;IACG,oBAAoB,CAAC,OAAO,EAAE,wBAAwB,GAAG,OAAO,CAAC,yBAAyB,CAAC;IAwBjG;;OAEG;IACG,aAAa,CAAC,KAAK,EAAE,MAAM,GAAG,OAAO,CAAC,OAAO,CAAC;CAQrD"}
|
|
@@ -0,0 +1,129 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
/**
|
|
3
|
+
* Push Notifications Connector
|
|
4
|
+
*/
|
|
5
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
6
|
+
exports.PushNotificationsConnector = void 0;
|
|
7
|
+
const utils_logger_1 = require("@xbg/utils-logger");
|
|
8
|
+
/**
|
|
9
|
+
* Push Notifications Connector
|
|
10
|
+
* Provides unified interface for sending push notifications
|
|
11
|
+
*/
|
|
12
|
+
class PushNotificationsConnector {
|
|
13
|
+
constructor(provider) {
|
|
14
|
+
this.provider = provider;
|
|
15
|
+
}
|
|
16
|
+
/**
|
|
17
|
+
* Send push notification to single device, topic, or condition
|
|
18
|
+
*/
|
|
19
|
+
async send(request) {
|
|
20
|
+
utils_logger_1.logger.info('Sending push notification', {
|
|
21
|
+
target: request.target,
|
|
22
|
+
title: request.notification.title,
|
|
23
|
+
});
|
|
24
|
+
try {
|
|
25
|
+
const response = await this.provider.send(request);
|
|
26
|
+
if (response.success) {
|
|
27
|
+
utils_logger_1.logger.info('Push notification sent successfully', {
|
|
28
|
+
messageId: response.messageId,
|
|
29
|
+
});
|
|
30
|
+
}
|
|
31
|
+
else {
|
|
32
|
+
utils_logger_1.logger.warn('Push notification failed', {
|
|
33
|
+
errors: response.errors,
|
|
34
|
+
});
|
|
35
|
+
}
|
|
36
|
+
return response;
|
|
37
|
+
}
|
|
38
|
+
catch (error) {
|
|
39
|
+
utils_logger_1.logger.error('Failed to send push notification', error instanceof Error ? error : new Error('Unknown error'));
|
|
40
|
+
throw error;
|
|
41
|
+
}
|
|
42
|
+
}
|
|
43
|
+
/**
|
|
44
|
+
* Send push notification to multiple devices
|
|
45
|
+
*/
|
|
46
|
+
async sendMulticast(request) {
|
|
47
|
+
if (!request.target.tokens || request.target.tokens.length === 0) {
|
|
48
|
+
throw new Error('Multicast requires at least one device token');
|
|
49
|
+
}
|
|
50
|
+
utils_logger_1.logger.info('Sending multicast push notification', {
|
|
51
|
+
tokenCount: request.target.tokens.length,
|
|
52
|
+
title: request.notification.title,
|
|
53
|
+
});
|
|
54
|
+
try {
|
|
55
|
+
const response = await this.provider.sendMulticast(request);
|
|
56
|
+
utils_logger_1.logger.info('Multicast notification sent', {
|
|
57
|
+
successCount: response.successCount,
|
|
58
|
+
failureCount: response.failureCount,
|
|
59
|
+
});
|
|
60
|
+
return response;
|
|
61
|
+
}
|
|
62
|
+
catch (error) {
|
|
63
|
+
utils_logger_1.logger.error('Failed to send multicast notification', error instanceof Error ? error : new Error('Unknown error'));
|
|
64
|
+
throw error;
|
|
65
|
+
}
|
|
66
|
+
}
|
|
67
|
+
/**
|
|
68
|
+
* Subscribe device tokens to a topic
|
|
69
|
+
*/
|
|
70
|
+
async subscribeToTopic(request) {
|
|
71
|
+
utils_logger_1.logger.info('Subscribing tokens to topic', {
|
|
72
|
+
topic: request.topic,
|
|
73
|
+
tokenCount: request.tokens.length,
|
|
74
|
+
});
|
|
75
|
+
try {
|
|
76
|
+
const response = await this.provider.subscribeToTopic(request);
|
|
77
|
+
utils_logger_1.logger.info('Topic subscription completed', {
|
|
78
|
+
topic: request.topic,
|
|
79
|
+
successCount: response.successCount,
|
|
80
|
+
failureCount: response.failureCount,
|
|
81
|
+
});
|
|
82
|
+
return response;
|
|
83
|
+
}
|
|
84
|
+
catch (error) {
|
|
85
|
+
utils_logger_1.logger.error('Failed to subscribe to topic', error instanceof Error ? error : new Error('Unknown error'), {
|
|
86
|
+
topic: request.topic,
|
|
87
|
+
});
|
|
88
|
+
throw error;
|
|
89
|
+
}
|
|
90
|
+
}
|
|
91
|
+
/**
|
|
92
|
+
* Unsubscribe device tokens from a topic
|
|
93
|
+
*/
|
|
94
|
+
async unsubscribeFromTopic(request) {
|
|
95
|
+
utils_logger_1.logger.info('Unsubscribing tokens from topic', {
|
|
96
|
+
topic: request.topic,
|
|
97
|
+
tokenCount: request.tokens.length,
|
|
98
|
+
});
|
|
99
|
+
try {
|
|
100
|
+
const response = await this.provider.unsubscribeFromTopic(request);
|
|
101
|
+
utils_logger_1.logger.info('Topic unsubscription completed', {
|
|
102
|
+
topic: request.topic,
|
|
103
|
+
successCount: response.successCount,
|
|
104
|
+
failureCount: response.failureCount,
|
|
105
|
+
});
|
|
106
|
+
return response;
|
|
107
|
+
}
|
|
108
|
+
catch (error) {
|
|
109
|
+
utils_logger_1.logger.error('Failed to unsubscribe from topic', error instanceof Error ? error : new Error('Unknown error'), {
|
|
110
|
+
topic: request.topic,
|
|
111
|
+
});
|
|
112
|
+
throw error;
|
|
113
|
+
}
|
|
114
|
+
}
|
|
115
|
+
/**
|
|
116
|
+
* Validate if a device token is valid
|
|
117
|
+
*/
|
|
118
|
+
async validateToken(token) {
|
|
119
|
+
try {
|
|
120
|
+
return await this.provider.validateToken(token);
|
|
121
|
+
}
|
|
122
|
+
catch (error) {
|
|
123
|
+
utils_logger_1.logger.error('Failed to validate token', error instanceof Error ? error : new Error('Unknown error'));
|
|
124
|
+
return false;
|
|
125
|
+
}
|
|
126
|
+
}
|
|
127
|
+
}
|
|
128
|
+
exports.PushNotificationsConnector = PushNotificationsConnector;
|
|
129
|
+
//# sourceMappingURL=push-notifications-connector.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"push-notifications-connector.js","sourceRoot":"","sources":["../src/push-notifications-connector.ts"],"names":[],"mappings":";AAAA;;GAEG;;;AAQH,oDAA2C;AAgC3C;;;GAGG;AACH,MAAa,0BAA0B;IAGrC,YAAY,QAAmC;QAC7C,IAAI,CAAC,QAAQ,GAAG,QAAQ,CAAC;IAC3B,CAAC;IAED;;OAEG;IACH,KAAK,CAAC,IAAI,CAAC,OAAgC;QACzC,qBAAM,CAAC,IAAI,CAAC,2BAA2B,EAAE;YACvC,MAAM,EAAE,OAAO,CAAC,MAAM;YACtB,KAAK,EAAE,OAAO,CAAC,YAAY,CAAC,KAAK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notification message structure
|
|
6
|
+
*/
|
|
7
|
+
export interface PushNotificationMessage {
|
|
8
|
+
title: string;
|
|
9
|
+
body: string;
|
|
10
|
+
imageUrl?: string;
|
|
11
|
+
data?: Record<string, string>;
|
|
12
|
+
badge?: number;
|
|
13
|
+
sound?: string;
|
|
14
|
+
clickAction?: string;
|
|
15
|
+
}
|
|
16
|
+
/**
|
|
17
|
+
* Notification target options
|
|
18
|
+
*/
|
|
19
|
+
export interface NotificationTarget {
|
|
20
|
+
token?: string;
|
|
21
|
+
tokens?: string[];
|
|
22
|
+
topic?: string;
|
|
23
|
+
condition?: string;
|
|
24
|
+
}
|
|
25
|
+
/**
|
|
26
|
+
* Notification options
|
|
27
|
+
*/
|
|
28
|
+
export interface NotificationOptions {
|
|
29
|
+
priority?: 'high' | 'normal';
|
|
30
|
+
ttl?: number;
|
|
31
|
+
collapseKey?: string;
|
|
32
|
+
mutableContent?: boolean;
|
|
33
|
+
contentAvailable?: boolean;
|
|
34
|
+
}
|
|
35
|
+
/**
|
|
36
|
+
* Send notification request
|
|
37
|
+
*/
|
|
38
|
+
export interface SendNotificationRequest {
|
|
39
|
+
target: NotificationTarget;
|
|
40
|
+
notification: PushNotificationMessage;
|
|
41
|
+
options?: NotificationOptions;
|
|
42
|
+
}
|
|
43
|
+
/**
|
|
44
|
+
* Send notification response
|
|
45
|
+
*/
|
|
46
|
+
export interface SendNotificationResponse {
|
|
47
|
+
success: boolean;
|
|
48
|
+
messageId?: string;
|
|
49
|
+
failureCount?: number;
|
|
50
|
+
successCount?: number;
|
|
51
|
+
errors?: Array<{
|
|
52
|
+
token?: string;
|
|
53
|
+
error: string;
|
|
54
|
+
}>;
|
|
55
|
+
}
|
|
56
|
+
/**
|
|
57
|
+
* Topic subscription request
|
|
58
|
+
*/
|
|
59
|
+
export interface TopicSubscriptionRequest {
|
|
60
|
+
tokens: string[];
|
|
61
|
+
topic: string;
|
|
62
|
+
}
|
|
63
|
+
/**
|
|
64
|
+
* Topic subscription response
|
|
65
|
+
*/
|
|
66
|
+
export interface TopicSubscriptionResponse {
|
|
67
|
+
successCount: number;
|
|
68
|
+
failureCount: number;
|
|
69
|
+
errors?: Array<{
|
|
70
|
+
token: string;
|
|
71
|
+
error: string;
|
|
72
|
+
}>;
|
|
73
|
+
}
|
|
74
|
+
//# sourceMappingURL=types.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"types.d.ts","sourceRoot":"","sources":["../src/types.ts"],"names":[],"mappings":"AAAA;;GAEG;AAEH;;GAEG;AACH,MAAM,WAAW,uBAAuB;IACtC,KAAK,EAAE,MAAM,CAAC;IACd,IAAI,EAAE,MAAM,CAAC;IACb,QAAQ,CAAC,EAAE,MAAM,CAAC;IAClB,IAAI,CAAC,EAAE,MAAM,CAAC,MAAM,EAAE,MAAM,CAAC,CAAC;IAC9B,KAAK,CAAC,EAAE,MAAM,CAAC;IACf,KAAK,CAAC,EAAE,MAAM,CAAC;IACf,WAAW,CAAC,EAAE,MAAM,CAAC;CACtB;AAED;;GAEG;AACH,MAAM,WAAW,kBAAkB;IACjC,KAAK,CAAC,EAAE,MAAM,CAAC;IACf,MAAM,CAAC,EAAE,MAAM,EAAE,CAAC;IAClB,KAAK,CAAC,EAAE,MAAM,CAAC;IACf,SAAS,CAAC,EAAE,MAAM,CAAC;CACpB;AAED;;GAEG;AACH,MAAM,WAAW,mBAAmB;IAClC,QAAQ,CAAC,EAAE,MAAM,GAAG,QAAQ,CAAC;IAC7B,GAAG,CAAC,EAAE,MAAM,CAAC;IACb,WAAW,CAAC,EAAE,MAAM,CAAC;IACrB,cAAc,CAAC,EAAE,OAAO,CAAC;IACzB,gBAAgB,CAAC,EAAE,OAAO,CAAC;CAC5B;AAED;;GAEG;AACH,MAAM,WAAW,uBAAuB;IACtC,MAAM,EAAE,kBAAkB,CAAC;IAC3B,YAAY,EAAE,uBAAuB,CAAC;IACtC,OAAO,CAAC,EAAE,mBAAmB,CAAC;CAC/B;AAED;;GAEG;AACH,MAAM,WAAW,wBAAwB;IACvC,OAAO,EAAE,OAAO,CAAC;IACjB,SAAS,CAAC,EAAE,MAAM,CAAC;IACnB,YAAY,CAAC,EAAE,MAAM,CAAC;IACtB,YAAY,CAAC,EAAE,MAAM,CAAC;IACtB,MAAM,CAAC,EAAE,KAAK,CAAC;QACb,KAAK,CAAC,EAAE,MAAM,CAAC;QACf,KAAK,EAAE,MAAM,CAAC;KACf,CAAC,CAAC;CACJ;AAED;;GAEG;AACH,MAAM,WAAW,wBAAwB;IACvC,MAAM,EAAE,MAAM,EAAE,CAAC;IACjB,KAAK,EAAE,MAAM,CAAC;CACf;AAED;;GAEG;AACH,MAAM,WAAW,yBAAyB;IACxC,YAAY,EAAE,MAAM,CAAC;IACrB,YAAY,EAAE,MAAM,CAAC;IACrB,MAAM,CAAC,EAAE,KAAK,CAAC;QACb,KAAK,EAAE,MAAM,CAAC;QACd,KAAK,EAAE,MAAM,CAAC;KACf,CAAC,CAAC;CACJ"}
|
package/lib/types.js
ADDED
package/lib/types.js.map
ADDED
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"types.js","sourceRoot":"","sources":["../src/types.ts"],"names":[],"mappings":";AAAA;;GAEG"}
|
package/package.json
ADDED
|
@@ -0,0 +1,30 @@
|
|
|
1
|
+
{
|
|
2
|
+
"name": "@xbg.solutions/utils-push-notifications-connector",
|
|
3
|
+
"version": "1.0.0",
|
|
4
|
+
"description": "Push notifications via FCM",
|
|
5
|
+
"main": "lib/index.js",
|
|
6
|
+
"types": "lib/index.d.ts",
|
|
7
|
+
"files": [
|
|
8
|
+
"lib"
|
|
9
|
+
],
|
|
10
|
+
"scripts": {
|
|
11
|
+
"build": "tsc",
|
|
12
|
+
"build:watch": "tsc --watch",
|
|
13
|
+
"clean": "rm -rf lib",
|
|
14
|
+
"prepublishOnly": "npm run build"
|
|
15
|
+
},
|
|
16
|
+
"dependencies": {
|
|
17
|
+
"@xbg/utils-logger": "^1.0.0",
|
|
18
|
+
"firebase-admin": "^12.0.0"
|
|
19
|
+
},
|
|
20
|
+
"devDependencies": {
|
|
21
|
+
"@types/node": "^20.11.0",
|
|
22
|
+
"typescript": "^5.3.3"
|
|
23
|
+
},
|
|
24
|
+
"engines": {
|
|
25
|
+
"node": "22"
|
|
26
|
+
},
|
|
27
|
+
"publishConfig": {
|
|
28
|
+
"access": "public"
|
|
29
|
+
}
|
|
30
|
+
}
|