@credo-ts/didcomm-push-notifications 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.
- package/LICENSE +202 -0
- package/README.md +23 -0
- package/build/fcm/DidCommPushNotificationsFcmApi.d.ts +40 -0
- package/build/fcm/DidCommPushNotificationsFcmApi.js +75 -0
- package/build/fcm/DidCommPushNotificationsFcmApi.js.map +1 -0
- package/build/fcm/DidCommPushNotificationsFcmModule.d.ts +10 -0
- package/build/fcm/DidCommPushNotificationsFcmModule.js +31 -0
- package/build/fcm/DidCommPushNotificationsFcmModule.js.map +1 -0
- package/build/fcm/PushNotificationsFcmApi.d.ts +40 -0
- package/build/fcm/PushNotificationsFcmApi.js +75 -0
- package/build/fcm/PushNotificationsFcmApi.js.map +1 -0
- package/build/fcm/PushNotificationsFcmModule.d.ts +10 -0
- package/build/fcm/PushNotificationsFcmModule.js +31 -0
- package/build/fcm/PushNotificationsFcmModule.js.map +1 -0
- package/build/fcm/errors/DidCommPushNotificationsFcmProblemReportError.d.ts +19 -0
- package/build/fcm/errors/DidCommPushNotificationsFcmProblemReportError.js +18 -0
- package/build/fcm/errors/DidCommPushNotificationsFcmProblemReportError.js.map +1 -0
- package/build/fcm/errors/DidCommPushNotificationsFcmProblemReportReason.d.ts +11 -0
- package/build/fcm/errors/DidCommPushNotificationsFcmProblemReportReason.js +13 -0
- package/build/fcm/errors/DidCommPushNotificationsFcmProblemReportReason.js.map +1 -0
- package/build/fcm/errors/PushNotificationsFcmProblemReportError.d.ts +19 -0
- package/build/fcm/errors/PushNotificationsFcmProblemReportError.js +18 -0
- package/build/fcm/errors/PushNotificationsFcmProblemReportError.js.map +1 -0
- package/build/fcm/errors/PushNotificationsFcmProblemReportReason.d.ts +11 -0
- package/build/fcm/errors/PushNotificationsFcmProblemReportReason.js +13 -0
- package/build/fcm/errors/PushNotificationsFcmProblemReportReason.js.map +1 -0
- package/build/fcm/errors/index.d.ts +2 -0
- package/build/fcm/errors/index.js +3 -0
- package/build/fcm/errors/index.js.map +1 -0
- package/build/fcm/handlers/DidCommPushNotificationsFcmDeviceInfoHandler.d.ts +13 -0
- package/build/fcm/handlers/DidCommPushNotificationsFcmDeviceInfoHandler.js +18 -0
- package/build/fcm/handlers/DidCommPushNotificationsFcmDeviceInfoHandler.js.map +1 -0
- package/build/fcm/handlers/DidCommPushNotificationsFcmProblemReportHandler.d.ts +13 -0
- package/build/fcm/handlers/DidCommPushNotificationsFcmProblemReportHandler.js +18 -0
- package/build/fcm/handlers/DidCommPushNotificationsFcmProblemReportHandler.js.map +1 -0
- package/build/fcm/handlers/DidCommPushNotificationsFcmSetDeviceInfoHandler.d.ts +17 -0
- package/build/fcm/handlers/DidCommPushNotificationsFcmSetDeviceInfoHandler.js +20 -0
- package/build/fcm/handlers/DidCommPushNotificationsFcmSetDeviceInfoHandler.js.map +1 -0
- package/build/fcm/handlers/PushNotificationsFcmDeviceInfoHandler.d.ts +13 -0
- package/build/fcm/handlers/PushNotificationsFcmDeviceInfoHandler.js +18 -0
- package/build/fcm/handlers/PushNotificationsFcmDeviceInfoHandler.js.map +1 -0
- package/build/fcm/handlers/PushNotificationsFcmProblemReportHandler.d.ts +13 -0
- package/build/fcm/handlers/PushNotificationsFcmProblemReportHandler.js +18 -0
- package/build/fcm/handlers/PushNotificationsFcmProblemReportHandler.js.map +1 -0
- package/build/fcm/handlers/PushNotificationsFcmSetDeviceInfoHandler.d.ts +17 -0
- package/build/fcm/handlers/PushNotificationsFcmSetDeviceInfoHandler.js +20 -0
- package/build/fcm/handlers/PushNotificationsFcmSetDeviceInfoHandler.js.map +1 -0
- package/build/fcm/handlers/index.d.ts +3 -0
- package/build/fcm/handlers/index.js +4 -0
- package/build/fcm/handlers/index.js.map +1 -0
- package/build/fcm/index.d.ts +5 -0
- package/build/fcm/index.js +6 -0
- package/build/fcm/index.js.map +1 -0
- package/build/fcm/messages/DidCommPushNotificationsFcmDeviceInfoMessage.d.ts +20 -0
- package/build/fcm/messages/DidCommPushNotificationsFcmDeviceInfoMessage.js +48 -0
- package/build/fcm/messages/DidCommPushNotificationsFcmDeviceInfoMessage.js.map +1 -0
- package/build/fcm/messages/DidCommPushNotificationsFcmGetDeviceInfoMessage.d.ts +15 -0
- package/build/fcm/messages/DidCommPushNotificationsFcmGetDeviceInfoMessage.js +30 -0
- package/build/fcm/messages/DidCommPushNotificationsFcmGetDeviceInfoMessage.js.map +1 -0
- package/build/fcm/messages/DidCommPushNotificationsFcmProblemReportMessage.d.ts +11 -0
- package/build/fcm/messages/DidCommPushNotificationsFcmProblemReportMessage.js +26 -0
- package/build/fcm/messages/DidCommPushNotificationsFcmProblemReportMessage.js.map +1 -0
- package/build/fcm/messages/DidCommPushNotificationsFcmSetDeviceInfoMessage.d.ts +18 -0
- package/build/fcm/messages/DidCommPushNotificationsFcmSetDeviceInfoMessage.js +46 -0
- package/build/fcm/messages/DidCommPushNotificationsFcmSetDeviceInfoMessage.js.map +1 -0
- package/build/fcm/messages/PushNotificationsFcmDeviceInfoMessage.d.ts +20 -0
- package/build/fcm/messages/PushNotificationsFcmDeviceInfoMessage.js +48 -0
- package/build/fcm/messages/PushNotificationsFcmDeviceInfoMessage.js.map +1 -0
- package/build/fcm/messages/PushNotificationsFcmGetDeviceInfoMessage.d.ts +15 -0
- package/build/fcm/messages/PushNotificationsFcmGetDeviceInfoMessage.js +30 -0
- package/build/fcm/messages/PushNotificationsFcmGetDeviceInfoMessage.js.map +1 -0
- package/build/fcm/messages/PushNotificationsFcmProblemReportMessage.d.ts +11 -0
- package/build/fcm/messages/PushNotificationsFcmProblemReportMessage.js +26 -0
- package/build/fcm/messages/PushNotificationsFcmProblemReportMessage.js.map +1 -0
- package/build/fcm/messages/PushNotificationsFcmSetDeviceInfoMessage.d.ts +18 -0
- package/build/fcm/messages/PushNotificationsFcmSetDeviceInfoMessage.js +46 -0
- package/build/fcm/messages/PushNotificationsFcmSetDeviceInfoMessage.js.map +1 -0
- package/build/fcm/messages/index.d.ts +4 -0
- package/build/fcm/messages/index.js +5 -0
- package/build/fcm/messages/index.js.map +1 -0
- package/build/fcm/models/DidCommFcmDeviceInfo.d.ts +4 -0
- package/build/fcm/models/DidCommFcmDeviceInfo.js +2 -0
- package/build/fcm/models/DidCommFcmDeviceInfo.js.map +1 -0
- package/build/fcm/models/DidCommPushNotificationsFcmRole.d.ts +10 -0
- package/build/fcm/models/DidCommPushNotificationsFcmRole.js +12 -0
- package/build/fcm/models/DidCommPushNotificationsFcmRole.js.map +1 -0
- package/build/fcm/models/FcmDeviceInfo.d.ts +4 -0
- package/build/fcm/models/FcmDeviceInfo.js +2 -0
- package/build/fcm/models/FcmDeviceInfo.js.map +1 -0
- package/build/fcm/models/PushNotificationsFcmRole.d.ts +10 -0
- package/build/fcm/models/PushNotificationsFcmRole.js +12 -0
- package/build/fcm/models/PushNotificationsFcmRole.js.map +1 -0
- package/build/fcm/models/index.d.ts +2 -0
- package/build/fcm/models/index.js +3 -0
- package/build/fcm/models/index.js.map +1 -0
- package/build/fcm/repository/DidCommPushNotificationsFcmRecord.d.ts +26 -0
- package/build/fcm/repository/DidCommPushNotificationsFcmRecord.js +23 -0
- package/build/fcm/repository/DidCommPushNotificationsFcmRecord.js.map +1 -0
- package/build/fcm/repository/DidCommPushNotificationsFcmRepository.d.ts +5 -0
- package/build/fcm/repository/DidCommPushNotificationsFcmRepository.js +26 -0
- package/build/fcm/repository/DidCommPushNotificationsFcmRepository.js.map +1 -0
- package/build/fcm/repository/PushNotificationsFcmRecord.d.ts +26 -0
- package/build/fcm/repository/PushNotificationsFcmRecord.js +23 -0
- package/build/fcm/repository/PushNotificationsFcmRecord.js.map +1 -0
- package/build/fcm/repository/PushNotificationsFcmRepository.d.ts +5 -0
- package/build/fcm/repository/PushNotificationsFcmRepository.js +26 -0
- package/build/fcm/repository/PushNotificationsFcmRepository.js.map +1 -0
- package/build/fcm/repository/index.d.ts +2 -0
- package/build/fcm/repository/index.js +3 -0
- package/build/fcm/repository/index.js.map +1 -0
- package/build/fcm/services/DidCommPushNotificationsFcmService.d.ts +19 -0
- package/build/fcm/services/DidCommPushNotificationsFcmService.js +93 -0
- package/build/fcm/services/DidCommPushNotificationsFcmService.js.map +1 -0
- package/build/fcm/services/PushNotificationsFcmService.d.ts +19 -0
- package/build/fcm/services/PushNotificationsFcmService.js +93 -0
- package/build/fcm/services/PushNotificationsFcmService.js.map +1 -0
- package/build/fcm/services/index.d.ts +1 -0
- package/build/fcm/services/index.js +2 -0
- package/build/fcm/services/index.js.map +1 -0
- package/build/index.d.ts +1 -0
- package/build/index.js +2 -0
- package/build/index.js.map +1 -0
- package/package.json +39 -0
|
@@ -0,0 +1,93 @@
|
|
|
1
|
+
var __decorate = (this && this.__decorate) || function (decorators, target, key, desc) {
|
|
2
|
+
var c = arguments.length, r = c < 3 ? target : desc === null ? desc = Object.getOwnPropertyDescriptor(target, key) : desc, d;
|
|
3
|
+
if (typeof Reflect === "object" && typeof Reflect.decorate === "function") r = Reflect.decorate(decorators, target, key, desc);
|
|
4
|
+
else for (var i = decorators.length - 1; i >= 0; i--) if (d = decorators[i]) r = (c < 3 ? d(r) : c > 3 ? d(target, key, r) : d(target, key)) || r;
|
|
5
|
+
return c > 3 && r && Object.defineProperty(target, key, r), r;
|
|
6
|
+
};
|
|
7
|
+
var __metadata = (this && this.__metadata) || function (k, v) {
|
|
8
|
+
if (typeof Reflect === "object" && typeof Reflect.metadata === "function") return Reflect.metadata(k, v);
|
|
9
|
+
};
|
|
10
|
+
var __param = (this && this.__param) || function (paramIndex, decorator) {
|
|
11
|
+
return function (target, key) { decorator(target, key, paramIndex); }
|
|
12
|
+
};
|
|
13
|
+
import { CredoError, InjectionSymbols, inject, injectable } from '@credo-ts/core';
|
|
14
|
+
import { DidCommPushNotificationsFcmProblemReportReason, PushNotificationsFcmProblemReportError, } from '../errors/index.js';
|
|
15
|
+
import { DidCommPushNotificationsFcmDeviceInfoMessage, DidCommPushNotificationsFcmGetDeviceInfoMessage, DidCommPushNotificationsFcmSetDeviceInfoMessage, } from '../messages/index.js';
|
|
16
|
+
import { DidCommPushNotificationsFcmRecord, DidCommPushNotificationsFcmRepository } from '../repository/index.js';
|
|
17
|
+
let DidCommPushNotificationsFcmService = class DidCommPushNotificationsFcmService {
|
|
18
|
+
constructor(pushNotificationsFcmRepository, logger) {
|
|
19
|
+
this.pushNotificationsFcmRepository = pushNotificationsFcmRepository;
|
|
20
|
+
this.logger = logger;
|
|
21
|
+
}
|
|
22
|
+
createSetDeviceInfo(deviceInfo) {
|
|
23
|
+
if ((deviceInfo.deviceToken === null && deviceInfo.devicePlatform !== null) ||
|
|
24
|
+
(deviceInfo.deviceToken !== null && deviceInfo.devicePlatform === null))
|
|
25
|
+
throw new CredoError('Both or none of deviceToken and devicePlatform must be null');
|
|
26
|
+
return new DidCommPushNotificationsFcmSetDeviceInfoMessage(deviceInfo);
|
|
27
|
+
}
|
|
28
|
+
createGetDeviceInfo() {
|
|
29
|
+
return new DidCommPushNotificationsFcmGetDeviceInfoMessage({});
|
|
30
|
+
}
|
|
31
|
+
createDeviceInfo(options) {
|
|
32
|
+
const { threadId, deviceInfo } = options;
|
|
33
|
+
if ((deviceInfo.deviceToken === null && deviceInfo.devicePlatform !== null) ||
|
|
34
|
+
(deviceInfo.deviceToken !== null && deviceInfo.devicePlatform === null))
|
|
35
|
+
throw new CredoError('Both or none of deviceToken and devicePlatform must be null');
|
|
36
|
+
return new DidCommPushNotificationsFcmDeviceInfoMessage({
|
|
37
|
+
threadId,
|
|
38
|
+
deviceToken: deviceInfo.deviceToken,
|
|
39
|
+
devicePlatform: deviceInfo.devicePlatform,
|
|
40
|
+
});
|
|
41
|
+
}
|
|
42
|
+
async processSetDeviceInfo(messageContext) {
|
|
43
|
+
const { message, agentContext } = messageContext;
|
|
44
|
+
if ((message.deviceToken === null && message.devicePlatform !== null) ||
|
|
45
|
+
(message.deviceToken !== null && message.devicePlatform === null)) {
|
|
46
|
+
throw new PushNotificationsFcmProblemReportError('Both or none of deviceToken and devicePlatform must be null', {
|
|
47
|
+
problemCode: DidCommPushNotificationsFcmProblemReportReason.MissingValue,
|
|
48
|
+
});
|
|
49
|
+
}
|
|
50
|
+
const connection = messageContext.assertReadyConnection();
|
|
51
|
+
let pushNotificationsFcmRecord = await this.pushNotificationsFcmRepository.findSingleByQuery(agentContext, {
|
|
52
|
+
connectionId: connection.id,
|
|
53
|
+
});
|
|
54
|
+
if (pushNotificationsFcmRecord) {
|
|
55
|
+
if (pushNotificationsFcmRecord.deviceToken === message.deviceToken) {
|
|
56
|
+
this.logger.debug(`Device token is same for connection ${connection.id}. So skipping update`);
|
|
57
|
+
return;
|
|
58
|
+
}
|
|
59
|
+
// Update the record with new device token
|
|
60
|
+
pushNotificationsFcmRecord.deviceToken = message.deviceToken;
|
|
61
|
+
// Reset project in case the firebase project might have changed
|
|
62
|
+
pushNotificationsFcmRecord.firebaseProjectId = undefined;
|
|
63
|
+
this.logger.debug(`Device token changed for connection ${connection.id}. Updating record`);
|
|
64
|
+
await this.pushNotificationsFcmRepository.update(agentContext, pushNotificationsFcmRecord);
|
|
65
|
+
}
|
|
66
|
+
else {
|
|
67
|
+
this.logger.debug(`No device info found for connection ${connection.id}. So creating new record`);
|
|
68
|
+
pushNotificationsFcmRecord = new DidCommPushNotificationsFcmRecord({
|
|
69
|
+
connectionId: connection.id,
|
|
70
|
+
deviceToken: message.deviceToken,
|
|
71
|
+
devicePlatform: message.devicePlatform,
|
|
72
|
+
});
|
|
73
|
+
await this.pushNotificationsFcmRepository.save(agentContext, pushNotificationsFcmRecord);
|
|
74
|
+
}
|
|
75
|
+
}
|
|
76
|
+
async getPushNotificationRecordByConnectionId(agentContext, connectionId) {
|
|
77
|
+
return await this.pushNotificationsFcmRepository.getSingleByQuery(agentContext, {
|
|
78
|
+
connectionId,
|
|
79
|
+
});
|
|
80
|
+
}
|
|
81
|
+
async findPushNotificationRecordByConnectionId(agentContext, connectionId) {
|
|
82
|
+
return await this.pushNotificationsFcmRepository.findSingleByQuery(agentContext, {
|
|
83
|
+
connectionId,
|
|
84
|
+
});
|
|
85
|
+
}
|
|
86
|
+
};
|
|
87
|
+
DidCommPushNotificationsFcmService = __decorate([
|
|
88
|
+
injectable(),
|
|
89
|
+
__param(1, inject(InjectionSymbols.Logger)),
|
|
90
|
+
__metadata("design:paramtypes", [DidCommPushNotificationsFcmRepository, Object])
|
|
91
|
+
], DidCommPushNotificationsFcmService);
|
|
92
|
+
export { DidCommPushNotificationsFcmService };
|
|
93
|
+
//# sourceMappingURL=DidCommPushNotificationsFcmService.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"DidCommPushNotificationsFcmService.js","sourceRoot":"","sources":["../../../src/fcm/services/DidCommPushNotificationsFcmService.ts"],"names":[],"mappings":";;;;;;;;;;;;AACA,OAAO,EAAE,UAAU,EAAE,gBAAgB,EAAE,MAAM,EAAE,UAAU,EAAE,MAAM,gBAAgB,CAAA;AAEjF,OAAO,EACL,8CAA8C,EAC9C,sCAAsC,GACvC,MAAM,oBAAoB,CAAA;AAC3B,OAAO,EACL,4CAA4C,EAC5C,+CAA+C,EAC/C,+CAA+C,GAChD,MAAM,sBAAsB,CAAA;AAE7B,OAAO,EAAE,iCAAiC,EAAE,qCAAqC,EAAE,MAAM,wBAAwB,CAAA;AAG1G,IAAM,kCAAkC,GAAxC,MAAM,kCAAkC;IAI7C,YACE,8BAAqE,EACpC,MAAc;QAE/C,IAAI,CAAC,8BAA8B,GAAG,8BAA8B,CAAA;QACpE,IAAI,CAAC,MAAM,GAAG,MAAM,CAAA;IACtB,CAAC;IAEM,mBAAmB,CAAC,UAAgC;QACzD,IACE,CAAC,UAAU,CAAC,WAAW,KAAK,IAAI,IAAI,UAAU,CAAC,cAAc,KAAK,IAAI,CAAC;YACvE,CAAC,UAAU,CAAC,WAAW,KAAK,IAAI,IAAI,UAAU,CAAC,cAAc,KAAK,IAAI,CAAC;YAEvE,MAAM,IAAI,UAAU,CAAC,6DAA6D,CAAC,CAAA;Q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;AApGY,kCAAkC;IAD9C,UAAU,EAAE;IAOR,WAAA,MAAM,CAAC,gBAAgB,CAAC,MAAM,CAAC,CAAA;qCADA,qCAAqC;GAL5D,kCAAkC,CAoG9C"}
|
|
@@ -0,0 +1,19 @@
|
|
|
1
|
+
import type { AgentContext, Logger } from '@credo-ts/core';
|
|
2
|
+
import { DidCommInboundMessageContext } from '@credo-ts/didcomm';
|
|
3
|
+
import { PushNotificationsFcmDeviceInfoMessage, PushNotificationsFcmGetDeviceInfoMessage, PushNotificationsFcmSetDeviceInfoMessage } from '../messages/index.js';
|
|
4
|
+
import type { FcmDeviceInfo } from '../models/FcmDeviceInfo.js';
|
|
5
|
+
import { PushNotificationsFcmRecord, PushNotificationsFcmRepository } from '../repository/index.js';
|
|
6
|
+
export declare class PushNotificationsFcmService {
|
|
7
|
+
private pushNotificationsFcmRepository;
|
|
8
|
+
private logger;
|
|
9
|
+
constructor(pushNotificationsFcmRepository: PushNotificationsFcmRepository, logger: Logger);
|
|
10
|
+
createSetDeviceInfo(deviceInfo: FcmDeviceInfo): PushNotificationsFcmSetDeviceInfoMessage;
|
|
11
|
+
createGetDeviceInfo(): PushNotificationsFcmGetDeviceInfoMessage;
|
|
12
|
+
createDeviceInfo(options: {
|
|
13
|
+
threadId: string;
|
|
14
|
+
deviceInfo: FcmDeviceInfo;
|
|
15
|
+
}): PushNotificationsFcmDeviceInfoMessage;
|
|
16
|
+
processSetDeviceInfo(messageContext: DidCommInboundMessageContext<PushNotificationsFcmSetDeviceInfoMessage>): Promise<void>;
|
|
17
|
+
getPushNotificationRecordByConnectionId(agentContext: AgentContext, connectionId: string): Promise<PushNotificationsFcmRecord>;
|
|
18
|
+
findPushNotificationRecordByConnectionId(agentContext: AgentContext, connectionId: string): Promise<PushNotificationsFcmRecord | null>;
|
|
19
|
+
}
|
|
@@ -0,0 +1,93 @@
|
|
|
1
|
+
var __decorate = (this && this.__decorate) || function (decorators, target, key, desc) {
|
|
2
|
+
var c = arguments.length, r = c < 3 ? target : desc === null ? desc = Object.getOwnPropertyDescriptor(target, key) : desc, d;
|
|
3
|
+
if (typeof Reflect === "object" && typeof Reflect.decorate === "function") r = Reflect.decorate(decorators, target, key, desc);
|
|
4
|
+
else for (var i = decorators.length - 1; i >= 0; i--) if (d = decorators[i]) r = (c < 3 ? d(r) : c > 3 ? d(target, key, r) : d(target, key)) || r;
|
|
5
|
+
return c > 3 && r && Object.defineProperty(target, key, r), r;
|
|
6
|
+
};
|
|
7
|
+
var __metadata = (this && this.__metadata) || function (k, v) {
|
|
8
|
+
if (typeof Reflect === "object" && typeof Reflect.metadata === "function") return Reflect.metadata(k, v);
|
|
9
|
+
};
|
|
10
|
+
var __param = (this && this.__param) || function (paramIndex, decorator) {
|
|
11
|
+
return function (target, key) { decorator(target, key, paramIndex); }
|
|
12
|
+
};
|
|
13
|
+
import { CredoError, InjectionSymbols, inject, injectable } from '@credo-ts/core';
|
|
14
|
+
import { PushNotificationsFcmProblemReportError, PushNotificationsFcmProblemReportReason } from '../errors/index.js';
|
|
15
|
+
import { PushNotificationsFcmDeviceInfoMessage, PushNotificationsFcmGetDeviceInfoMessage, PushNotificationsFcmSetDeviceInfoMessage } from '../messages/index.js';
|
|
16
|
+
import { PushNotificationsFcmRecord, PushNotificationsFcmRepository } from '../repository/index.js';
|
|
17
|
+
let PushNotificationsFcmService = class PushNotificationsFcmService {
|
|
18
|
+
constructor(pushNotificationsFcmRepository, logger) {
|
|
19
|
+
this.pushNotificationsFcmRepository = pushNotificationsFcmRepository;
|
|
20
|
+
this.logger = logger;
|
|
21
|
+
}
|
|
22
|
+
createSetDeviceInfo(deviceInfo) {
|
|
23
|
+
if ((deviceInfo.deviceToken === null && deviceInfo.devicePlatform !== null) ||
|
|
24
|
+
(deviceInfo.deviceToken !== null && deviceInfo.devicePlatform === null))
|
|
25
|
+
throw new CredoError('Both or none of deviceToken and devicePlatform must be null');
|
|
26
|
+
return new PushNotificationsFcmSetDeviceInfoMessage(deviceInfo);
|
|
27
|
+
}
|
|
28
|
+
createGetDeviceInfo() {
|
|
29
|
+
return new PushNotificationsFcmGetDeviceInfoMessage({});
|
|
30
|
+
}
|
|
31
|
+
createDeviceInfo(options) {
|
|
32
|
+
const { threadId, deviceInfo } = options;
|
|
33
|
+
if ((deviceInfo.deviceToken === null && deviceInfo.devicePlatform !== null) ||
|
|
34
|
+
(deviceInfo.deviceToken !== null && deviceInfo.devicePlatform === null))
|
|
35
|
+
throw new CredoError('Both or none of deviceToken and devicePlatform must be null');
|
|
36
|
+
return new PushNotificationsFcmDeviceInfoMessage({
|
|
37
|
+
threadId,
|
|
38
|
+
deviceToken: deviceInfo.deviceToken,
|
|
39
|
+
devicePlatform: deviceInfo.devicePlatform,
|
|
40
|
+
});
|
|
41
|
+
}
|
|
42
|
+
async processSetDeviceInfo(messageContext) {
|
|
43
|
+
const { message, agentContext } = messageContext;
|
|
44
|
+
if ((message.deviceToken === null && message.devicePlatform !== null) ||
|
|
45
|
+
(message.deviceToken !== null && message.devicePlatform === null)) {
|
|
46
|
+
throw new PushNotificationsFcmProblemReportError('Both or none of deviceToken and devicePlatform must be null', {
|
|
47
|
+
problemCode: PushNotificationsFcmProblemReportReason.MissingValue,
|
|
48
|
+
});
|
|
49
|
+
}
|
|
50
|
+
const connection = messageContext.assertReadyConnection();
|
|
51
|
+
let pushNotificationsFcmRecord = await this.pushNotificationsFcmRepository.findSingleByQuery(agentContext, {
|
|
52
|
+
connectionId: connection.id,
|
|
53
|
+
});
|
|
54
|
+
if (pushNotificationsFcmRecord) {
|
|
55
|
+
if (pushNotificationsFcmRecord.deviceToken === message.deviceToken) {
|
|
56
|
+
this.logger.debug(`Device token is same for connection ${connection.id}. So skipping update`);
|
|
57
|
+
return;
|
|
58
|
+
}
|
|
59
|
+
// Update the record with new device token
|
|
60
|
+
pushNotificationsFcmRecord.deviceToken = message.deviceToken;
|
|
61
|
+
// Reset project in case the firebase project might have changed
|
|
62
|
+
pushNotificationsFcmRecord.firebaseProjectId = undefined;
|
|
63
|
+
this.logger.debug(`Device token changed for connection ${connection.id}. Updating record`);
|
|
64
|
+
await this.pushNotificationsFcmRepository.update(agentContext, pushNotificationsFcmRecord);
|
|
65
|
+
}
|
|
66
|
+
else {
|
|
67
|
+
this.logger.debug(`No device info found for connection ${connection.id}. So creating new record`);
|
|
68
|
+
pushNotificationsFcmRecord = new PushNotificationsFcmRecord({
|
|
69
|
+
connectionId: connection.id,
|
|
70
|
+
deviceToken: message.deviceToken,
|
|
71
|
+
devicePlatform: message.devicePlatform,
|
|
72
|
+
});
|
|
73
|
+
await this.pushNotificationsFcmRepository.save(agentContext, pushNotificationsFcmRecord);
|
|
74
|
+
}
|
|
75
|
+
}
|
|
76
|
+
async getPushNotificationRecordByConnectionId(agentContext, connectionId) {
|
|
77
|
+
return await this.pushNotificationsFcmRepository.getSingleByQuery(agentContext, {
|
|
78
|
+
connectionId,
|
|
79
|
+
});
|
|
80
|
+
}
|
|
81
|
+
async findPushNotificationRecordByConnectionId(agentContext, connectionId) {
|
|
82
|
+
return await this.pushNotificationsFcmRepository.findSingleByQuery(agentContext, {
|
|
83
|
+
connectionId,
|
|
84
|
+
});
|
|
85
|
+
}
|
|
86
|
+
};
|
|
87
|
+
PushNotificationsFcmService = __decorate([
|
|
88
|
+
injectable(),
|
|
89
|
+
__param(1, inject(InjectionSymbols.Logger)),
|
|
90
|
+
__metadata("design:paramtypes", [PushNotificationsFcmRepository, Object])
|
|
91
|
+
], PushNotificationsFcmService);
|
|
92
|
+
export { PushNotificationsFcmService };
|
|
93
|
+
//# sourceMappingURL=PushNotificationsFcmService.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"PushNotificationsFcmService.js","sourceRoot":"","sources":["../../../src/fcm/services/PushNotificationsFcmService.ts"],"names":[],"mappings":";;;;;;;;;;;;AACA,OAAO,EAAE,UAAU,EAAE,gBAAgB,EAAE,MAAM,EAAE,UAAU,EAAE,MAAM,gBAAgB,CAAA;AAEjF,OAAO,EAAE,s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C,CAAA;YAEjG,0BAA0B,GAAG,IAAI,0BAA0B,CAAC;gBAC1D,YAAY,EAAE,UAAU,CAAC,EAAE;gBAC3B,WAAW,EAAE,OAAO,CAAC,WAAW;gBAChC,cAAc,EAAE,OAAO,CAAC,cAAc;aACvC,CAAC,CAAA;YAEF,MAAM,IAAI,CAAC,8BAA8B,CAAC,IAAI,CAAC,YAAY,EAAE,0BAA0B,CAAC,CAAA;QAC1F,CAAC;IACH,CAAC;IAEM,KAAK,CAAC,uCAAuC,CAClD,YAA0B,EAC1B,YAAoB;QAEpB,OAAO,MAAM,IAAI,CAAC,8BAA8B,CAAC,gBAAgB,CAAC,YAAY,EAAE;YAC9E,YAAY;SACb,CAAC,CAAA;IACJ,CAAC;IAEM,KAAK,CAAC,wCAAwC,CAAC,YAA0B,EAAE,YAAoB;QACpG,OAAO,MAAM,IAAI,CAAC,8BAA8B,CAAC,iBAAiB,CAAC,YAAY,EAAE;YAC/E,YAAY;SACb,CAAC,CAAA;IACJ,CAAC;CACF,CAAA;AApGY,2BAA2B;IADvC,UAAU,EAAE;IAOR,WAAA,MAAM,CAAC,gBAAgB,CAAC,MAAM,CAAC,CAAA;qCADA,8BAA8B;GALrD,2BAA2B,CAoGvC"}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export * from './DidCommPushNotificationsFcmService.js';
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"index.js","sourceRoot":"","sources":["../../../src/fcm/services/index.ts"],"names":[],"mappings":"AAAA,cAAc,yCAAyC,CAAA"}
|
package/build/index.d.ts
ADDED
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export * from './fcm/index.js';
|
package/build/index.js
ADDED
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"index.js","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AAAA,cAAc,gBAAgB,CAAA"}
|
package/package.json
ADDED
|
@@ -0,0 +1,39 @@
|
|
|
1
|
+
{
|
|
2
|
+
"name": "@credo-ts/didcomm-push-notifications",
|
|
3
|
+
"main": "build/index.js",
|
|
4
|
+
"types": "build/index.d.ts",
|
|
5
|
+
"version": "0.0.1",
|
|
6
|
+
"files": [
|
|
7
|
+
"build"
|
|
8
|
+
],
|
|
9
|
+
"type": "module",
|
|
10
|
+
"publishConfig": {
|
|
11
|
+
"access": "public"
|
|
12
|
+
},
|
|
13
|
+
"description": "Credo DIDComm Push Notifications module",
|
|
14
|
+
"license": "Apache-2.0",
|
|
15
|
+
"homepage": "https://github.com/openwallet-foundation/didcomm-mediator-credo/tree/main/packages/push-notifications",
|
|
16
|
+
"repository": {
|
|
17
|
+
"type": "git",
|
|
18
|
+
"url": "https://github.com/openwallet-foundation/didcomm-mediator-credo",
|
|
19
|
+
"directory": "packages/push-notifications"
|
|
20
|
+
},
|
|
21
|
+
"dependencies": {
|
|
22
|
+
"class-transformer": "^0.5.1",
|
|
23
|
+
"class-validator": "^0.14.2"
|
|
24
|
+
},
|
|
25
|
+
"devDependencies": {
|
|
26
|
+
"@credo-ts/askar": "^0.6.0",
|
|
27
|
+
"@credo-ts/core": "^0.6.0",
|
|
28
|
+
"@credo-ts/didcomm": "^0.6.0",
|
|
29
|
+
"@types/node": "^22.15.17",
|
|
30
|
+
"typescript": "^5.6.3"
|
|
31
|
+
},
|
|
32
|
+
"peerDependencies": {
|
|
33
|
+
"@credo-ts/core": "^0.6.0",
|
|
34
|
+
"@credo-ts/didcomm": "^0.6.0"
|
|
35
|
+
},
|
|
36
|
+
"scripts": {
|
|
37
|
+
"build": "tsc -p tsconfig.build.json"
|
|
38
|
+
}
|
|
39
|
+
}
|