@servicelabsco/slabs-access-manager 0.1.240 → 0.1.242
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,4 +1,4 @@
|
|
|
1
|
-
import { CacheService,
|
|
1
|
+
import { CacheService, PropertyService, RemoteRawResponseDto, RemoteRequestService } from '@servicelabsco/nestjs-utility-services';
|
|
2
2
|
import { FcmNotificationEntity } from '../../accessUtility/entities/fcm.notification.entity';
|
|
3
3
|
import { NotificationPayloadDto } from '../dtos/notification.payload.dto';
|
|
4
4
|
export declare class SendFcmNotification {
|
|
@@ -10,10 +10,10 @@ export declare class SendFcmNotification {
|
|
|
10
10
|
protected token: string;
|
|
11
11
|
constructor(notification: FcmNotificationEntity, propertyService: PropertyService, remoteRequestService: RemoteRequestService, cacheService: CacheService);
|
|
12
12
|
process(payload: NotificationPayloadDto): Promise<void>;
|
|
13
|
-
sendMessage(notification: FcmNotificationEntity, userId: number): Promise<
|
|
13
|
+
sendMessage(notification: FcmNotificationEntity, userId: number): Promise<RemoteRawResponseDto>;
|
|
14
14
|
private getContent;
|
|
15
15
|
getUserToken(user_id: number): Promise<string>;
|
|
16
|
-
sendNotification(data: any, token: string): Promise<
|
|
16
|
+
sendNotification(data: any, token: string): Promise<RemoteRawResponseDto>;
|
|
17
17
|
private logMessage;
|
|
18
18
|
getToken(): Promise<any>;
|
|
19
19
|
getTokenFromCacheService(cacheKey: string): Promise<any>;
|
|
@@ -16,13 +16,15 @@ class SendFcmNotification {
|
|
|
16
16
|
async process(payload) {
|
|
17
17
|
this.payload = payload;
|
|
18
18
|
this.token = await this.getToken();
|
|
19
|
+
if (!this.token)
|
|
20
|
+
return;
|
|
19
21
|
for (const user of this.payload.user_ids)
|
|
20
22
|
await this.sendMessage(this.notification, user);
|
|
21
23
|
}
|
|
22
24
|
async sendMessage(notification, userId) {
|
|
23
25
|
const token = await this.getUserToken(userId);
|
|
24
26
|
if (!token)
|
|
25
|
-
|
|
27
|
+
return;
|
|
26
28
|
const data = await this.getContent(notification.template);
|
|
27
29
|
const response = await this.sendNotification(data, token);
|
|
28
30
|
await this.logMessage(userId, notification, data, response);
|
|
@@ -33,15 +35,18 @@ class SendFcmNotification {
|
|
|
33
35
|
return JSON.parse(nestjs_utility_services_1.PlatformUtility.compileHandlebar(str, this.payload.data));
|
|
34
36
|
}
|
|
35
37
|
async getUserToken(user_id) {
|
|
36
|
-
const token = await fcm_token_entity_1.FcmTokenEntity.findOne({
|
|
38
|
+
const token = await fcm_token_entity_1.FcmTokenEntity.findOne({
|
|
39
|
+
where: { business_id: this.payload.business.id, user_id, active: true },
|
|
40
|
+
order: { updated_at: 'DESC' },
|
|
41
|
+
});
|
|
37
42
|
if (token)
|
|
38
43
|
return token.token;
|
|
39
44
|
return;
|
|
40
45
|
}
|
|
41
46
|
async sendNotification(data, token) {
|
|
42
|
-
const url = this.propertyService.get('fcm.url');
|
|
47
|
+
const url = await this.propertyService.get('fcm.url');
|
|
43
48
|
const options = {
|
|
44
|
-
method: '
|
|
49
|
+
method: 'POST',
|
|
45
50
|
url,
|
|
46
51
|
headers: {
|
|
47
52
|
'Content-Type': 'application/json',
|
|
@@ -49,7 +54,7 @@ class SendFcmNotification {
|
|
|
49
54
|
},
|
|
50
55
|
data: { message: { token, ...data } },
|
|
51
56
|
};
|
|
52
|
-
return this.remoteRequestService.
|
|
57
|
+
return this.remoteRequestService.getRawResponse(options);
|
|
53
58
|
}
|
|
54
59
|
async logMessage(user_id, notification, content, response) {
|
|
55
60
|
const wm = fcm_message_entity_1.FcmMessageEntity.create({
|
|
@@ -58,10 +63,9 @@ class SendFcmNotification {
|
|
|
58
63
|
fcm_notification_id: notification.id,
|
|
59
64
|
type_id: notification_type_enum_1.NotificationTypeEnum.Outward,
|
|
60
65
|
content,
|
|
61
|
-
response,
|
|
62
66
|
source_id: this.payload.source.source_id,
|
|
63
67
|
source_type: this.payload.source.source_type,
|
|
64
|
-
attributes: this.payload?.attributes,
|
|
68
|
+
attributes: { ...this.payload?.attributes, response },
|
|
65
69
|
});
|
|
66
70
|
return wm.save();
|
|
67
71
|
}
|
|
@@ -91,10 +95,10 @@ class SendFcmNotification {
|
|
|
91
95
|
}
|
|
92
96
|
async getTokenFromTheGoogle() {
|
|
93
97
|
const email = await this.propertyService.get('fcm.email');
|
|
94
|
-
const
|
|
98
|
+
const propertyKey = await this.propertyService.get('fcm.api.key');
|
|
95
99
|
const client = new google_auth_library_1.JWT({
|
|
96
100
|
email,
|
|
97
|
-
key
|
|
101
|
+
key: `-----BEGIN PRIVATE KEY-----\n${propertyKey}\n-----END PRIVATE KEY-----`,
|
|
98
102
|
scopes: ['https://www.googleapis.com/auth/cloud-platform'],
|
|
99
103
|
});
|
|
100
104
|
try {
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"send.fcm.notification.js","sourceRoot":"","sources":["../../../src/access/libraries/send.fcm.notification.ts"],"names":[],"mappings":";;;AAAA,
|
|
1
|
+
{"version":3,"file":"send.fcm.notification.js","sourceRoot":"","sources":["../../../src/access/libraries/send.fcm.notification.ts"],"names":[],"mappings":";;;AAAA,oFAAoJ;AACpJ,6DAA0C;AAI1C,uEAAkE;AAClE,mEAA8D;AAC9D,4EAAuE;AAOvE,MAAa,mBAAmB;IAI5B,YACqB,YAAmC,EACnC,eAAgC,EAChC,oBAA0C,EAC1C,YAA0B;QAH1B,iBAAY,GAAZ,YAAY,CAAuB;QACnC,oBAAe,GAAf,eAAe,CAAiB;QAChC,yBAAoB,GAApB,oBAAoB,CAAsB;QAC1C,iBAAY,GAAZ,YAAY,CAAc;IAC5C,CAAC;IAEJ,KAAK,CAAC,OAAO,CAAC,OAA+B;QACzC,IAAI,CAAC,OAAO,GAAG,OAAO,CAAC;QAEvB,IAAI,CAAC,KAAK,GAAG,MAAM,IAAI,CAAC,QAAQ,EAAE,CAAC;QACnC,IAAI,CAAC,IAAI,CAAC,KAAK;YAAE,OAAO;QAExB,KAAK,MAAM,IAAI,IAAI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