@rocketmakers/orbit-notify-firebase 2.0.0-beta.2 → 2.0.0-beta.5
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/README.md +8 -7
- package/package.json +17 -18
- package/lib/_tests_/manualTest/index.test.d.ts +0 -2
- package/lib/_tests_/manualTest/index.test.d.ts.map +0 -1
- package/lib/_tests_/manualTest/index.test.js +0 -7
- package/lib/_tests_/manualTest/index.test.js.map +0 -1
- package/lib/_tests_/manualTest/sendNotification.d.ts +0 -2
- package/lib/_tests_/manualTest/sendNotification.d.ts.map +0 -1
- package/lib/_tests_/manualTest/sendNotification.js +0 -51
- package/lib/_tests_/manualTest/sendNotification.js.map +0 -1
- package/lib/_tests_/manualTest/serviceInstance.d.ts +0 -9
- package/lib/_tests_/manualTest/serviceInstance.d.ts.map +0 -1
- package/lib/_tests_/manualTest/serviceInstance.js +0 -25
- package/lib/_tests_/manualTest/serviceInstance.js.map +0 -1
- package/lib/_tests_/unit/validation/index.test.d.ts +0 -2
- package/lib/_tests_/unit/validation/index.test.d.ts.map +0 -1
- package/lib/_tests_/unit/validation/index.test.js +0 -7
- package/lib/_tests_/unit/validation/index.test.js.map +0 -1
- package/lib/_tests_/unit/validation/mockedService.d.ts +0 -13
- package/lib/_tests_/unit/validation/mockedService.d.ts.map +0 -1
- package/lib/_tests_/unit/validation/mockedService.js +0 -20
- package/lib/_tests_/unit/validation/mockedService.js.map +0 -1
- package/lib/_tests_/unit/validation/sendNotification.d.ts +0 -2
- package/lib/_tests_/unit/validation/sendNotification.d.ts.map +0 -1
- package/lib/_tests_/unit/validation/sendNotification.js +0 -40
- package/lib/_tests_/unit/validation/sendNotification.js.map +0 -1
- package/lib/src/config/environment.generated.d.ts +0 -7
- package/lib/src/config/environment.generated.d.ts.map +0 -1
- package/lib/src/config/environment.generated.js +0 -28
- package/lib/src/config/environment.generated.js.map +0 -1
- package/lib/src/config/index.d.ts +0 -7
- package/lib/src/config/index.d.ts.map +0 -1
- package/lib/src/config/index.js +0 -5
- package/lib/src/config/index.js.map +0 -1
- package/lib/src/index.d.ts +0 -5
- package/lib/src/index.d.ts.map +0 -1
- package/lib/src/index.js +0 -8
- package/lib/src/index.js.map +0 -1
- package/lib/src/ioc/container.d.ts +0 -13
- package/lib/src/ioc/container.d.ts.map +0 -1
- package/lib/src/ioc/container.js +0 -7
- package/lib/src/ioc/container.js.map +0 -1
- package/lib/src/ioc/index.d.ts +0 -3
- package/lib/src/ioc/index.d.ts.map +0 -1
- package/lib/src/ioc/index.js +0 -6
- package/lib/src/ioc/index.js.map +0 -1
- package/lib/src/ioc/register.d.ts +0 -3
- package/lib/src/ioc/register.d.ts.map +0 -1
- package/lib/src/ioc/register.js +0 -27
- package/lib/src/ioc/register.js.map +0 -1
- package/lib/src/ioc/types.d.ts +0 -10
- package/lib/src/ioc/types.d.ts.map +0 -1
- package/lib/src/ioc/types.js +0 -3
- package/lib/src/ioc/types.js.map +0 -1
- package/lib/src/services/firebaseService.d.ts +0 -29
- package/lib/src/services/firebaseService.d.ts.map +0 -1
- package/lib/src/services/firebaseService.js +0 -78
- package/lib/src/services/firebaseService.js.map +0 -1
- package/lib/src/services/index.d.ts +0 -2
- package/lib/src/services/index.d.ts.map +0 -1
- package/lib/src/services/index.js +0 -5
- package/lib/src/services/index.js.map +0 -1
- package/lib/src/validation/index.d.ts +0 -15
- package/lib/src/validation/index.d.ts.map +0 -1
- package/lib/src/validation/index.js +0 -24
- package/lib/src/validation/index.js.map +0 -1
- package/lib/tsconfig.tsbuildinfo +0 -13271
|
@@ -1,78 +0,0 @@
|
|
|
1
|
-
"use strict";
|
|
2
|
-
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
-
exports.FirebaseService = void 0;
|
|
4
|
-
const tslib_1 = require("tslib");
|
|
5
|
-
const orbit_core_1 = require("@rocketmakers/orbit-core");
|
|
6
|
-
const FirebaseAdmin = require("firebase-admin");
|
|
7
|
-
const __1 = require("..");
|
|
8
|
-
class FirebaseService {
|
|
9
|
-
constructor(templateService, serviceAccount, logger) {
|
|
10
|
-
this.templateService = templateService;
|
|
11
|
-
this.serviceAccount = serviceAccount;
|
|
12
|
-
this.logger = logger;
|
|
13
|
-
this.app = FirebaseAdmin.initializeApp({
|
|
14
|
-
credential: FirebaseAdmin.credential.cert({
|
|
15
|
-
clientEmail: this.serviceAccount.client_email,
|
|
16
|
-
privateKey: this.serviceAccount.private_key,
|
|
17
|
-
projectId: this.serviceAccount.project_id,
|
|
18
|
-
}),
|
|
19
|
-
});
|
|
20
|
-
}
|
|
21
|
-
sendNotification(params) {
|
|
22
|
-
var _a;
|
|
23
|
-
return tslib_1.__awaiter(this, void 0, void 0, function* () {
|
|
24
|
-
const { firebaseDeviceToken, layoutId, templateName, payload } = params;
|
|
25
|
-
const { validatedDeviceToken, validatedLayoutId, validatedTemplateName, validatedPayload, } = yield __1.Validation.sendNotification(firebaseDeviceToken, layoutId, templateName, payload);
|
|
26
|
-
const layouts = yield this.templateService.renderLayoutTemplates(validatedLayoutId, validatedPayload.data);
|
|
27
|
-
const txtNotification = (_a = layouts.find(layout => layout.name === validatedTemplateName)) === null || _a === void 0 ? void 0 : _a.compiled;
|
|
28
|
-
if (!txtNotification) {
|
|
29
|
-
throw new orbit_core_1.NotFoundError(`Failed to find Firebase txt template for layout: ${layoutId}`);
|
|
30
|
-
}
|
|
31
|
-
const notification = {
|
|
32
|
-
title: validatedPayload.title,
|
|
33
|
-
body: txtNotification,
|
|
34
|
-
imageUrl: validatedPayload.imageUrl,
|
|
35
|
-
};
|
|
36
|
-
let firebaseMessaging;
|
|
37
|
-
try {
|
|
38
|
-
firebaseMessaging = this.app.messaging();
|
|
39
|
-
const result = yield firebaseMessaging.sendAll([
|
|
40
|
-
{
|
|
41
|
-
token: validatedDeviceToken,
|
|
42
|
-
notification,
|
|
43
|
-
data: {
|
|
44
|
-
event: JSON.stringify(notification),
|
|
45
|
-
payload: JSON.stringify(validatedPayload),
|
|
46
|
-
},
|
|
47
|
-
},
|
|
48
|
-
]);
|
|
49
|
-
const errors = [];
|
|
50
|
-
if (result.responses) {
|
|
51
|
-
for (let i = 0; i < result.responses.length; i += 1) {
|
|
52
|
-
const response = result.responses[i];
|
|
53
|
-
if (!response.success) {
|
|
54
|
-
if (response.error &&
|
|
55
|
-
(response.error.code === 'messaging/invalid-registration-token' ||
|
|
56
|
-
response.error.code === 'messaging/registration-token-not-registered' ||
|
|
57
|
-
response.error.code === 'messaging/mismatched-credential')) {
|
|
58
|
-
this.logger.info('Removed contact device token');
|
|
59
|
-
}
|
|
60
|
-
errors.push(`${validatedDeviceToken}: ${JSON.stringify(response.error)}`);
|
|
61
|
-
}
|
|
62
|
-
}
|
|
63
|
-
}
|
|
64
|
-
if (errors && errors.length > 0) {
|
|
65
|
-
throw new Error(JSON.stringify(errors));
|
|
66
|
-
}
|
|
67
|
-
return true;
|
|
68
|
-
}
|
|
69
|
-
finally {
|
|
70
|
-
if (firebaseMessaging) {
|
|
71
|
-
yield firebaseMessaging.app.delete();
|
|
72
|
-
}
|
|
73
|
-
}
|
|
74
|
-
});
|
|
75
|
-
}
|
|
76
|
-
}
|
|
77
|
-
exports.FirebaseService = FirebaseService;
|
|
78
|
-
//# sourceMappingURL=firebaseService.js.map
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"firebaseService.js","sourceRoot":"","sources":["../../../src/services/firebaseService.ts"],"names":[],"mappings":";;;;AAEA,yDAAyD;AAGzD,gDAAgD;AAChD,0BAAuD;AA0BvD,MAAa,eAAe;IAG1B,YACU,eAAgC,EAChC,cAAqC,EACrC,MAAc;QAFd,oBAAe,GAAf,eAAe,CAAiB;QAChC,mBAAc,GAAd,cAAc,CAAuB;QACrC,WAAM,GAAN,MAAM,CAAQ;QAEtB,IAAI,CAAC,GAAG,GAAG,aAAa,CAAC,aAAa,CAAC;YACrC,UAAU,EAAE,aAAa,CAAC,UAAU,CAAC,IAAI,CAAC;gBACxC,WAAW,EAAE,IA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AA,cAAc,mBAAmB,CAAC"}
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"index.js","sourceRoot":"","sources":["../../../src/services/index.ts"],"names":[],"mappings":";;;AAAA,4DAAkC"}
|
|
@@ -1,15 +0,0 @@
|
|
|
1
|
-
import { LayoutId } from '@rocketmakers/orbit-template-core';
|
|
2
|
-
import { IFirebasePayload } from '../services';
|
|
3
|
-
export declare namespace Validation {
|
|
4
|
-
function sendNotification<TPayload>(firebaseDeviceToken: string, layoutId: LayoutId, templateName: string, payload: IFirebasePayload<TPayload>): Promise<{
|
|
5
|
-
validatedDeviceToken: string;
|
|
6
|
-
validatedLayoutId: string;
|
|
7
|
-
validatedTemplateName: string;
|
|
8
|
-
validatedPayload: {
|
|
9
|
-
data: any;
|
|
10
|
-
title: string;
|
|
11
|
-
imageUrl: string;
|
|
12
|
-
};
|
|
13
|
-
}>;
|
|
14
|
-
}
|
|
15
|
-
//# sourceMappingURL=index.d.ts.map
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../../src/validation/index.ts"],"names":[],"mappings":"AACA,OAAO,EAAE,QAAQ,EAAE,MAAM,mCAAmC,CAAC;AAC7D,OAAO,EAAE,gBAAgB,EAAE,MAAM,aAAa,CAAC;AAE/C,yBAAiB,UAAU,CAAC;IAC1B,SAAsB,gBAAgB,CAAC,QAAQ,EAC7C,mBAAmB,EAAE,MAAM,EAC3B,QAAQ,EAAE,QAAQ,EAClB,YAAY,EAAE,MAAM,EACpB,OAAO,EAAE,gBAAgB,CAAC,QAAQ,CAAC;;;;;;;;;OAepC;CACF"}
|
|
@@ -1,24 +0,0 @@
|
|
|
1
|
-
"use strict";
|
|
2
|
-
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
-
exports.Validation = void 0;
|
|
4
|
-
const tslib_1 = require("tslib");
|
|
5
|
-
const orbit_core_1 = require("@rocketmakers/orbit-core");
|
|
6
|
-
var Validation;
|
|
7
|
-
(function (Validation) {
|
|
8
|
-
function sendNotification(firebaseDeviceToken, layoutId, templateName, payload) {
|
|
9
|
-
return tslib_1.__awaiter(this, void 0, void 0, function* () {
|
|
10
|
-
return {
|
|
11
|
-
validatedDeviceToken: yield orbit_core_1.validate(orbit_core_1.CommonValidators.string(true).minLength(1).build(), firebaseDeviceToken),
|
|
12
|
-
validatedLayoutId: yield orbit_core_1.validate(orbit_core_1.CommonValidators.opaque(true).minLength(1).build(), layoutId),
|
|
13
|
-
validatedTemplateName: yield orbit_core_1.validate(orbit_core_1.CommonValidators.string(true).minLength(1).build(), templateName),
|
|
14
|
-
validatedPayload: yield orbit_core_1.validate(orbit_core_1.CommonValidators.objectMandatory({
|
|
15
|
-
data: orbit_core_1.CommonValidators.any(true),
|
|
16
|
-
title: orbit_core_1.CommonValidators.string(false),
|
|
17
|
-
imageUrl: orbit_core_1.CommonValidators.string(false),
|
|
18
|
-
}).build(), payload),
|
|
19
|
-
};
|
|
20
|
-
});
|
|
21
|
-
}
|
|
22
|
-
Validation.sendNotification = sendNotification;
|
|
23
|
-
})(Validation = exports.Validation || (exports.Validation = {}));
|
|
24
|
-
//# sourceMappingURL=index.js.map
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"index.js","sourceRoot":"","sources":["../../../src/validation/index.ts"],"names":[],"mappings":";;;;AAAA,yDAAsE;AAItE,IAAiB,UAAU,CAqB1B;AArBD,WAAiB,UAAU;IACzB,SAAsB,gBAAgB,CACpC,mBAA2B,EAC3B,QAAkB,EAClB,YAAoB,EACpB,OAAmC;;YAEnC,OAAO;gBACL,oBAAoB,EAAE,MAAM,qBAAQ,CAAC,6BAAgB,CAAC,MAAM,CAAC,IAAI,CAAC,CAAC,SAAS,CAAC,CAAC,CAAC,CAAC,KAAK,EAAE,EAAE,mBAAmB,CAAC;gBAC7G,iBAAiB,EAAE,MAAM,qBAAQ,CAAC,6BAAgB,CAAC,MAAM,CAAW,IAAI,CAAC,CAAC,SAAS,CAAC,CAAC,CAAC,CAAC,KAAK,EAAE,EAAE,QAAQ,CAAC;gBACzG,qBAAqB,EAAE,MAAM,qBAAQ,CAAC,6BAAgB,CAAC,MAAM,CAAC,IAAI,CAAC,CAAC,SAAS,CAAC,CAAC,CAAC,CAAC,KAAK,EAAE,EAAE,YAAY,CAAC;gBACvG,gBAAgB,EAAE,MAAM,qBAAQ,CAC9B,6BAAgB,CAAC,eAAe,CAAC;oBAC/B,IAAI,EAAE,6BAAgB,CAAC,GAAG,CAAC,IAAI,CAAC;oBAChC,KAAK,EAAE,6BAAgB,CAAC,MAAM,CAAC,KAAK,CAAC;oBACrC,QAAQ,EAAE,6BAAgB,CAAC,MAAM,CAAC,KAAK,CAAC;iBACzC,CAAC,CAAC,KAAK,EAAE,EACV,OAAO,CACR;aACF,CAAC;QACJ,CAAC;KAAA;IAnBqB,2BAAgB,mBAmBrC,CAAA;AACH,CAAC,EArBgB,UAAU,GAAV,kBAAU,KAAV,kBAAU,QAqB1B"}
|