@rocketmakers/orbit-notify-firebase 2.0.0-beta.1 → 2.0.0-beta.10

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 (94) hide show
  1. package/README.md +8 -7
  2. package/lib/_tests_/manualTest/index.test.d.ts.map +1 -1
  3. package/lib/_tests_/manualTest/index.test.js +1 -1
  4. package/lib/_tests_/manualTest/index.test.js.map +1 -1
  5. package/lib/_tests_/manualTest/sendNotification.d.ts.map +1 -1
  6. package/lib/_tests_/manualTest/sendNotification.js +2 -6
  7. package/lib/_tests_/manualTest/sendNotification.js.map +1 -1
  8. package/lib/_tests_/manualTest/serviceInstance.d.ts +3 -3
  9. package/lib/_tests_/manualTest/serviceInstance.d.ts.map +1 -1
  10. package/lib/_tests_/manualTest/serviceInstance.js +7 -6
  11. package/lib/_tests_/manualTest/serviceInstance.js.map +1 -1
  12. package/lib/_tests_/unit/validation/index.test.d.ts.map +1 -1
  13. package/lib/_tests_/unit/validation/index.test.js +1 -1
  14. package/lib/_tests_/unit/validation/index.test.js.map +1 -1
  15. package/lib/_tests_/unit/validation/mockedService.d.ts +1 -1
  16. package/lib/_tests_/unit/validation/mockedService.d.ts.map +1 -1
  17. package/lib/_tests_/unit/validation/mockedService.js +3 -3
  18. package/lib/_tests_/unit/validation/mockedService.js.map +1 -1
  19. package/lib/_tests_/unit/validation/sendNotification.d.ts.map +1 -1
  20. package/lib/_tests_/unit/validation/sendNotification.js +8 -9
  21. package/lib/_tests_/unit/validation/sendNotification.js.map +1 -1
  22. package/lib/_tests_/validation/index.test.d.ts +2 -0
  23. package/lib/_tests_/validation/index.test.d.ts.map +1 -0
  24. package/lib/_tests_/validation/index.test.js +7 -0
  25. package/lib/_tests_/validation/index.test.js.map +1 -0
  26. package/lib/_tests_/validation/mockedService.d.ts +14 -0
  27. package/lib/_tests_/validation/mockedService.d.ts.map +1 -0
  28. package/lib/_tests_/validation/mockedService.js +20 -0
  29. package/lib/_tests_/validation/mockedService.js.map +1 -0
  30. package/lib/_tests_/validation/sendNotification.d.ts +2 -0
  31. package/lib/_tests_/validation/sendNotification.d.ts.map +1 -0
  32. package/lib/_tests_/validation/sendNotification.js +39 -0
  33. package/lib/_tests_/validation/sendNotification.js.map +1 -0
  34. package/lib/{src/config → config}/environment.generated.d.ts +1 -1
  35. package/lib/config/environment.generated.d.ts.map +1 -0
  36. package/lib/{src/config → config}/environment.generated.js +8 -11
  37. package/lib/config/environment.generated.js.map +1 -0
  38. package/lib/{src/config → config}/index.d.ts +0 -0
  39. package/lib/config/index.d.ts.map +1 -0
  40. package/lib/{src/config → config}/index.js +0 -0
  41. package/lib/config/index.js.map +1 -0
  42. package/lib/{src/index.d.ts → index.d.ts} +0 -0
  43. package/lib/index.d.ts.map +1 -0
  44. package/lib/{src/index.js → index.js} +0 -0
  45. package/lib/index.js.map +1 -0
  46. package/lib/{src/ioc → ioc}/index.d.ts +0 -0
  47. package/lib/ioc/index.d.ts.map +1 -0
  48. package/lib/{src/ioc → ioc}/index.js +0 -0
  49. package/lib/ioc/index.js.map +1 -0
  50. package/lib/ioc/register.d.ts +8 -0
  51. package/lib/ioc/register.d.ts.map +1 -0
  52. package/lib/ioc/register.js +31 -0
  53. package/lib/ioc/register.js.map +1 -0
  54. package/lib/{src/ioc → ioc}/types.d.ts +0 -3
  55. package/lib/ioc/types.d.ts.map +1 -0
  56. package/lib/{src/ioc → ioc}/types.js +0 -0
  57. package/lib/{src/ioc → ioc}/types.js.map +1 -1
  58. package/lib/{src/services → services}/firebaseService.d.ts +6 -3
  59. package/lib/services/firebaseService.d.ts.map +1 -0
  60. package/lib/{src/services → services}/firebaseService.js +28 -13
  61. package/lib/services/firebaseService.js.map +1 -0
  62. package/lib/{src/services → services}/index.d.ts +0 -0
  63. package/lib/services/index.d.ts.map +1 -0
  64. package/lib/{src/services → services}/index.js +0 -0
  65. package/lib/services/index.js.map +1 -0
  66. package/lib/tsconfig.tsbuildinfo +1 -11730
  67. package/lib/{src/validation → validation}/index.d.ts +1 -1
  68. package/lib/validation/index.d.ts.map +1 -0
  69. package/lib/{src/validation → validation}/index.js +4 -4
  70. package/lib/validation/index.js.map +1 -0
  71. package/package.json +17 -18
  72. package/lib/src/config/environment.generated.d.ts.map +0 -1
  73. package/lib/src/config/environment.generated.js.map +0 -1
  74. package/lib/src/config/index.d.ts.map +0 -1
  75. package/lib/src/config/index.js.map +0 -1
  76. package/lib/src/index.d.ts.map +0 -1
  77. package/lib/src/index.js.map +0 -1
  78. package/lib/src/ioc/container.d.ts +0 -13
  79. package/lib/src/ioc/container.d.ts.map +0 -1
  80. package/lib/src/ioc/container.js +0 -7
  81. package/lib/src/ioc/container.js.map +0 -1
  82. package/lib/src/ioc/index.d.ts.map +0 -1
  83. package/lib/src/ioc/index.js.map +0 -1
  84. package/lib/src/ioc/register.d.ts +0 -3
  85. package/lib/src/ioc/register.d.ts.map +0 -1
  86. package/lib/src/ioc/register.js +0 -27
  87. package/lib/src/ioc/register.js.map +0 -1
  88. package/lib/src/ioc/types.d.ts.map +0 -1
  89. package/lib/src/services/firebaseService.d.ts.map +0 -1
  90. package/lib/src/services/firebaseService.js.map +0 -1
  91. package/lib/src/services/index.d.ts.map +0 -1
  92. package/lib/src/services/index.js.map +0 -1
  93. package/lib/src/validation/index.d.ts.map +0 -1
  94. package/lib/src/validation/index.js.map +0 -1
@@ -6,27 +6,36 @@ const orbit_core_1 = require("@rocketmakers/orbit-core");
6
6
  const FirebaseAdmin = require("firebase-admin");
7
7
  const __1 = require("..");
8
8
  class FirebaseService {
9
- constructor(templateService, serviceAccount, logger) {
9
+ constructor(templateService, serviceAccount, logger, isTestInstance = false) {
10
10
  this.templateService = templateService;
11
11
  this.serviceAccount = serviceAccount;
12
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
- });
13
+ this.isTestInstance = isTestInstance;
14
+ if (!this.isTestInstance) {
15
+ this.app = FirebaseAdmin.initializeApp({
16
+ credential: FirebaseAdmin.credential.cert({
17
+ clientEmail: this.serviceAccount.client_email,
18
+ privateKey: this.serviceAccount.private_key,
19
+ projectId: this.serviceAccount.project_id,
20
+ }),
21
+ });
22
+ }
23
+ else {
24
+ this.app = 'TEST_INIT_APP';
25
+ }
20
26
  }
21
27
  sendNotification(params) {
22
28
  var _a;
23
29
  return tslib_1.__awaiter(this, void 0, void 0, function* () {
24
30
  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;
31
+ const { validatedDeviceToken, validatedLayoutId, validatedTemplateName, validatedPayload } = yield __1.Validation.sendNotification(firebaseDeviceToken, layoutId, templateName, payload);
32
+ const templatesResponse = yield this.templateService.renderLayoutTemplates(validatedLayoutId, validatedPayload.data);
33
+ if (templatesResponse.kind !== 'ok') {
34
+ return templatesResponse;
35
+ }
36
+ const txtNotification = (_a = templatesResponse.result.find(template => template.name === validatedTemplateName)) === null || _a === void 0 ? void 0 : _a.compiled;
28
37
  if (!txtNotification) {
29
- throw new orbit_core_1.NotFoundError(`Failed to find Firebase txt template for layout: ${layoutId}`);
38
+ return (0, orbit_core_1.buildNotFoundResponse)('Template', this.logger, `Failed to find Firebase txt template for layout: ${layoutId}`);
30
39
  }
31
40
  const notification = {
32
41
  title: validatedPayload.title,
@@ -64,7 +73,7 @@ class FirebaseService {
64
73
  if (errors && errors.length > 0) {
65
74
  throw new Error(JSON.stringify(errors));
66
75
  }
67
- return true;
76
+ return { kind: 'ok', result: true };
68
77
  }
69
78
  finally {
70
79
  if (firebaseMessaging) {
@@ -74,5 +83,11 @@ class FirebaseService {
74
83
  });
75
84
  }
76
85
  }
86
+ tslib_1.__decorate([
87
+ orbit_core_1.ensureNoError,
88
+ tslib_1.__metadata("design:type", Function),
89
+ tslib_1.__metadata("design:paramtypes", [Object]),
90
+ tslib_1.__metadata("design:returntype", Object)
91
+ ], FirebaseService.prototype, "sendNotification", null);
77
92
  exports.FirebaseService = FirebaseService;
78
93
  //# sourceMappingURL=firebaseService.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"firebaseService.js","sourceRoot":"","sources":["../../src/services/firebaseService.ts"],"names":[],"mappings":";;;;AAEA,yDAAgG;AAGhG,gDAAgD;AAChD,0BAAuD;AA4BvD,MAAa,eAAe;IAG1B,YACU,eAAgC,EAChC,cAAqC,EACrC,MAAc,EACd,iBAAiB,KAAK;QAHtB,oBAAe,GAAf,eAAe,CAAiB;QAChC,mBAAc,GAAd,cAAc,CAAuB;QACrC,WAAM,GAAN,MAAM,CAAQ;QACd,mBAAc,GAAd,cAAc,CAAQ;QAE9B,IAAI,CAAC,IAAI,CAAC,cAAc,EAAE;YACxB,IAAI,CAAC,GAAG,GAAG,aAAa,CAAC,aAAa,CAAC;gBACrC,UAAU,EAAE,aAAa,CAAC,UAAU,CAAC,IAAI,CAAC;oBACxC,WAAW,EAAE,IAAI,CAAC,cAAc,CAAC,YAAY;oBAC7C,UAAU,EAAE,IAAI,CAAC,cAAc,CAAC,WAAW;oBAC3C,SAAS,EAAE,IAAI,CAAC,cAAc,CAAC,UAAU;iBAC1C,CAAC;aACH,CAAC,CAAC;SACJ;aAAM;YACL,IAAI,CAAC,GAAG,GAAG,eAAsB,CAAC;SACnC;IACH,CAAC;IAQY,gBAAgB,CAC3B,MAA6D;;;YAE7D,MAAM,EAAE,mBAAmB,EAAE,QAAQ,EAAE,YAAY,EAAE,OAAO,EAAE,GAAG,MAAM,CAAC;YACxE,MAAM,EAAE,oBAAoB,EAAE,iBAAiB,E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,IAAI,CAAC,GAAG,CAAC,EAAE,CAAC,GAAG,MAAM,CAAC,SAAS,CAAC,MAAM,EAAE,CAAC,IAAI,CAAC,EAAE;wBACnD,MAAM,QAAQ,GAAG,MAAM,CAAC,SAAS,CAAC,CAAC,CAAC,CAAC;wBAErC,IAAI,CAAC,QAAQ,CAAC,OAAO,EAAE;4BACrB,IACE,QAAQ,CAAC,KAAK;gCACd,CAAC,QAAQ,CAAC,KAAK,CAAC,IAAI,KAAK,sCAAsC;oCAC7D,QAAQ,CAAC,KAAK,CAAC,IAAI,KAAK,6CAA6C;oCACrE,QAAQ,CAAC,KAAK,CAAC,IAAI,KAAK,iCAAiC,CAAC,EAC5D;gCACA,IAAI,CAAC,MAAM,CAAC,IAAI,CAAC,8BAA8B,CAAC,CAAC;6BAClD;4BAED,MAAM,CAAC,IAAI,CAAC,GAAG,oBAAoB,KAAK,IAAI,CAAC,SAAS,CAAC,QAAQ,CAAC,KAAK,CAAC,EAAE,CAAC,CAAC;yBAC3E;qBACF;iBACF;gBAGD,IAAI,MAAM,IAAI,MAAM,CAAC,MAAM,GAAG,CAAC,EAAE;oBAC/B,MAAM,IAAI,KAAK,CAAC,IAAI,CAAC,SAAS,CAAC,MAAM,CAAC,CAAC,CAAC;iBACzC;gBAED,OAAO,EAAE,IAAI,EAAE,IAAI,EAAE,MAAM,EAAE,IAAI,EAAE,CAAC;aACrC;oBAAS;gBAER,IAAI,iBAAiB,EAAE;oBACrB,MAAM,iBAAiB,CAAC,GAAG,CAAC,MAAM,EAAE,CAAC;iBACtC;aACF;;KACF;CACF;AAnFC;IADC,0BAAa;;;;uDAmFb;AA9GH,0CA+GC"}
File without changes
@@ -0,0 +1 @@
1
+ {"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../src/services/index.ts"],"names":[],"mappings":"AAAA,cAAc,mBAAmB,CAAC"}
File without changes
@@ -0,0 +1 @@
1
+ {"version":3,"file":"index.js","sourceRoot":"","sources":["../../src/services/index.ts"],"names":[],"mappings":";;;AAAA,4DAAkC"}