@flink-app/firebase-messaging-plugin 0.12.1-alpha.0 → 0.12.1-alpha.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/.flink/generatedHandlers.ts +1 -1
- package/.flink/generatedJobs.ts +1 -1
- package/.flink/generatedRepos.ts +1 -1
- package/.flink/schemas/schemas.json +6 -12
- package/.flink/schemas/schemas.ts +1 -1
- package/.flink/start.ts +1 -1
- package/dist/.flink/generatedHandlers.js +6 -2
- package/dist/.flink/generatedJobs.js +1 -1
- package/dist/.flink/generatedRepos.js +1 -1
- package/dist/.flink/schemas/schemas.json +6 -12
- package/dist/.flink/start.js +1 -1
- package/dist/src/ManagementModule.js +5 -1
- package/dist/src/firebaseMessagingPlugin.d.ts +1 -1
- package/dist/src/firebaseMessagingPlugin.js +9 -5
- package/dist/src/handlers/PostMessage.js +14 -16
- package/dist/src/index.js +5 -1
- package/dist/src/managementHandlers/Get.js +25 -27
- package/dist/src/managementHandlers/PostMessage.js +40 -42
- package/package.json +30 -30
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
// Generated Wed Mar 19 2025
|
|
1
|
+
// Generated Wed Mar 19 2025 22:58:42 GMT+0100 (Central European Standard Time)
|
|
2
2
|
import { autoRegisteredHandlers, HttpMethod } from "@flink-app/flink";
|
|
3
3
|
import * as PostMessage_0 from "../src/handlers/PostMessage";
|
|
4
4
|
|
package/.flink/generatedJobs.ts
CHANGED
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
// Generated Wed Mar 19 2025
|
|
1
|
+
// Generated Wed Mar 19 2025 22:58:42 GMT+0100 (Central European Standard Time)
|
|
2
2
|
import { autoRegisteredJobs } from "@flink-app/flink";
|
|
3
3
|
export const jobs = [];
|
|
4
4
|
autoRegisteredJobs.push(...jobs);
|
package/.flink/generatedRepos.ts
CHANGED
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
// Generated Wed Mar 19 2025
|
|
1
|
+
// Generated Wed Mar 19 2025 22:58:42 GMT+0100 (Central European Standard Time)
|
|
2
2
|
import { autoRegisteredRepos } from "@flink-app/flink";
|
|
3
3
|
export const repos = [];
|
|
4
4
|
autoRegisteredRepos.push(...repos);
|
|
@@ -11,30 +11,25 @@
|
|
|
11
11
|
"type": "array",
|
|
12
12
|
"items": {
|
|
13
13
|
"type": "string"
|
|
14
|
-
}
|
|
15
|
-
"description": "Devices to send to"
|
|
14
|
+
}
|
|
16
15
|
},
|
|
17
16
|
"notification": {
|
|
18
17
|
"type": "object",
|
|
19
18
|
"properties": {
|
|
20
19
|
"title": {
|
|
21
|
-
"type": "string"
|
|
22
|
-
"description": "Optional push notification title"
|
|
20
|
+
"type": "string"
|
|
23
21
|
},
|
|
24
22
|
"body": {
|
|
25
|
-
"type": "string"
|
|
26
|
-
"description": "Optional body"
|
|
23
|
+
"type": "string"
|
|
27
24
|
}
|
|
28
25
|
},
|
|
29
|
-
"additionalProperties": false
|
|
30
|
-
"description": "Use `notification` if sending a standard push notification https://firebase.google.com/docs/cloud-messaging/concept-options#notifications"
|
|
26
|
+
"additionalProperties": false
|
|
31
27
|
},
|
|
32
28
|
"data": {
|
|
33
29
|
"type": "object",
|
|
34
30
|
"additionalProperties": {
|
|
35
31
|
"type": "string"
|
|
36
|
-
}
|
|
37
|
-
"description": "Use `data` to send data messages. https://firebase.google.com/docs/cloud-messaging/concept-options#data_messages"
|
|
32
|
+
}
|
|
38
33
|
}
|
|
39
34
|
},
|
|
40
35
|
"required": [
|
|
@@ -52,8 +47,7 @@
|
|
|
52
47
|
"type": "array",
|
|
53
48
|
"items": {
|
|
54
49
|
"type": "string"
|
|
55
|
-
}
|
|
56
|
-
"description": "Devices to which delivery failed"
|
|
50
|
+
}
|
|
57
51
|
}
|
|
58
52
|
},
|
|
59
53
|
"required": [
|
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
import Message from "../../src/schemas/Message";
|
|
2
2
|
import SendResult from "../../src/schemas/SendResult";
|
|
3
3
|
|
|
4
|
-
// Generated Wed Mar 19 2025
|
|
4
|
+
// Generated Wed Mar 19 2025 22:58:42 GMT+0100 (Central European Standard Time)
|
|
5
5
|
export interface PostMessage_12_ReqSchema extends Message {}
|
|
6
6
|
|
|
7
7
|
export interface PostMessage_12_ResSchema extends SendResult {}
|
package/.flink/start.ts
CHANGED
|
@@ -1,7 +1,11 @@
|
|
|
1
1
|
"use strict";
|
|
2
2
|
var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) {
|
|
3
3
|
if (k2 === undefined) k2 = k;
|
|
4
|
-
Object.
|
|
4
|
+
var desc = Object.getOwnPropertyDescriptor(m, k);
|
|
5
|
+
if (!desc || ("get" in desc ? !m.__esModule : desc.writable || desc.configurable)) {
|
|
6
|
+
desc = { enumerable: true, get: function() { return m[k]; } };
|
|
7
|
+
}
|
|
8
|
+
Object.defineProperty(o, k2, desc);
|
|
5
9
|
}) : (function(o, m, k, k2) {
|
|
6
10
|
if (k2 === undefined) k2 = k;
|
|
7
11
|
o[k2] = m[k];
|
|
@@ -20,7 +24,7 @@ var __importStar = (this && this.__importStar) || function (mod) {
|
|
|
20
24
|
};
|
|
21
25
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
22
26
|
exports.handlers = void 0;
|
|
23
|
-
// Generated Wed Mar 19 2025
|
|
27
|
+
// Generated Wed Mar 19 2025 22:58:42 GMT+0100 (Central European Standard Time)
|
|
24
28
|
var flink_1 = require("@flink-app/flink");
|
|
25
29
|
var PostMessage_0 = __importStar(require("../src/handlers/PostMessage"));
|
|
26
30
|
exports.handlers = [{ handler: PostMessage_0, assumedHttpMethod: flink_1.HttpMethod.post }];
|
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
"use strict";
|
|
2
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
3
|
exports.jobs = void 0;
|
|
4
|
-
// Generated Wed Mar 19 2025
|
|
4
|
+
// Generated Wed Mar 19 2025 22:58:42 GMT+0100 (Central European Standard Time)
|
|
5
5
|
var flink_1 = require("@flink-app/flink");
|
|
6
6
|
exports.jobs = [];
|
|
7
7
|
flink_1.autoRegisteredJobs.push.apply(flink_1.autoRegisteredJobs, exports.jobs);
|
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
"use strict";
|
|
2
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
3
|
exports.repos = void 0;
|
|
4
|
-
// Generated Wed Mar 19 2025
|
|
4
|
+
// Generated Wed Mar 19 2025 22:58:42 GMT+0100 (Central European Standard Time)
|
|
5
5
|
var flink_1 = require("@flink-app/flink");
|
|
6
6
|
exports.repos = [];
|
|
7
7
|
flink_1.autoRegisteredRepos.push.apply(flink_1.autoRegisteredRepos, exports.repos);
|
|
@@ -11,30 +11,25 @@
|
|
|
11
11
|
"type": "array",
|
|
12
12
|
"items": {
|
|
13
13
|
"type": "string"
|
|
14
|
-
}
|
|
15
|
-
"description": "Devices to send to"
|
|
14
|
+
}
|
|
16
15
|
},
|
|
17
16
|
"notification": {
|
|
18
17
|
"type": "object",
|
|
19
18
|
"properties": {
|
|
20
19
|
"title": {
|
|
21
|
-
"type": "string"
|
|
22
|
-
"description": "Optional push notification title"
|
|
20
|
+
"type": "string"
|
|
23
21
|
},
|
|
24
22
|
"body": {
|
|
25
|
-
"type": "string"
|
|
26
|
-
"description": "Optional body"
|
|
23
|
+
"type": "string"
|
|
27
24
|
}
|
|
28
25
|
},
|
|
29
|
-
"additionalProperties": false
|
|
30
|
-
"description": "Use `notification` if sending a standard push notification https://firebase.google.com/docs/cloud-messaging/concept-options#notifications"
|
|
26
|
+
"additionalProperties": false
|
|
31
27
|
},
|
|
32
28
|
"data": {
|
|
33
29
|
"type": "object",
|
|
34
30
|
"additionalProperties": {
|
|
35
31
|
"type": "string"
|
|
36
|
-
}
|
|
37
|
-
"description": "Use `data` to send data messages. https://firebase.google.com/docs/cloud-messaging/concept-options#data_messages"
|
|
32
|
+
}
|
|
38
33
|
}
|
|
39
34
|
},
|
|
40
35
|
"required": [
|
|
@@ -52,8 +47,7 @@
|
|
|
52
47
|
"type": "array",
|
|
53
48
|
"items": {
|
|
54
49
|
"type": "string"
|
|
55
|
-
}
|
|
56
|
-
"description": "Devices to which delivery failed"
|
|
50
|
+
}
|
|
57
51
|
}
|
|
58
52
|
},
|
|
59
53
|
"required": [
|
package/dist/.flink/start.js
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
"use strict";
|
|
2
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
-
// Generated Wed Mar 19 2025
|
|
3
|
+
// Generated Wed Mar 19 2025 22:58:42 GMT+0100 (Central European Standard Time)
|
|
4
4
|
require("./generatedHandlers");
|
|
5
5
|
require("./generatedRepos");
|
|
6
6
|
require("./generatedJobs");
|
|
@@ -1,7 +1,11 @@
|
|
|
1
1
|
"use strict";
|
|
2
2
|
var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) {
|
|
3
3
|
if (k2 === undefined) k2 = k;
|
|
4
|
-
Object.
|
|
4
|
+
var desc = Object.getOwnPropertyDescriptor(m, k);
|
|
5
|
+
if (!desc || ("get" in desc ? !m.__esModule : desc.writable || desc.configurable)) {
|
|
6
|
+
desc = { enumerable: true, get: function() { return m[k]; } };
|
|
7
|
+
}
|
|
8
|
+
Object.defineProperty(o, k2, desc);
|
|
5
9
|
}) : (function(o, m, k, k2) {
|
|
6
10
|
if (k2 === undefined) k2 = k;
|
|
7
11
|
o[k2] = m[k];
|
|
@@ -12,7 +12,11 @@ var __assign = (this && this.__assign) || function () {
|
|
|
12
12
|
};
|
|
13
13
|
var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) {
|
|
14
14
|
if (k2 === undefined) k2 = k;
|
|
15
|
-
Object.
|
|
15
|
+
var desc = Object.getOwnPropertyDescriptor(m, k);
|
|
16
|
+
if (!desc || ("get" in desc ? !m.__esModule : desc.writable || desc.configurable)) {
|
|
17
|
+
desc = { enumerable: true, get: function() { return m[k]; } };
|
|
18
|
+
}
|
|
19
|
+
Object.defineProperty(o, k2, desc);
|
|
16
20
|
}) : (function(o, m, k, k2) {
|
|
17
21
|
if (k2 === undefined) k2 = k;
|
|
18
22
|
o[k2] = m[k];
|
|
@@ -44,7 +48,7 @@ var __generator = (this && this.__generator) || function (thisArg, body) {
|
|
|
44
48
|
function verb(n) { return function (v) { return step([n, v]); }; }
|
|
45
49
|
function step(op) {
|
|
46
50
|
if (f) throw new TypeError("Generator is already executing.");
|
|
47
|
-
while (_) try {
|
|
51
|
+
while (g && (g = 0, op[0] && (_ = 0)), _) try {
|
|
48
52
|
if (f = 1, y && (t = op[0] & 2 ? y["return"] : op[0] ? y["throw"] || ((t = y["return"]) && t.call(y), 0) : y.next) && !(t = t.call(y, op[1])).done) return t;
|
|
49
53
|
if (y = 0, t) op = [op[0] & 2, t.value];
|
|
50
54
|
switch (op[0]) {
|
|
@@ -134,16 +138,16 @@ function send(message, adminApp) {
|
|
|
134
138
|
response = _b.sent();
|
|
135
139
|
response.responses.forEach(function (res, idx) {
|
|
136
140
|
if (res.success) {
|
|
137
|
-
flink_1.log.debug("[firebaseMessaging] Successfully sent to device "
|
|
141
|
+
flink_1.log.debug("[firebaseMessaging] Successfully sent to device ".concat(batch[idx].token));
|
|
138
142
|
}
|
|
139
143
|
else {
|
|
140
|
-
flink_1.log.debug("[firebaseMessaging] Failed sending to device "
|
|
144
|
+
flink_1.log.debug("[firebaseMessaging] Failed sending to device ".concat(batch[idx].token, ": ").concat(res.error));
|
|
141
145
|
}
|
|
142
146
|
});
|
|
143
147
|
return [3 /*break*/, 4];
|
|
144
148
|
case 3:
|
|
145
149
|
err_1 = _b.sent();
|
|
146
|
-
flink_1.log.debug("[firebaseMessaging] Failed sending batch: "
|
|
150
|
+
flink_1.log.debug("[firebaseMessaging] Failed sending batch: ".concat(err_1));
|
|
147
151
|
return [3 /*break*/, 4];
|
|
148
152
|
case 4: return [2 /*return*/];
|
|
149
153
|
}
|
|
@@ -14,7 +14,7 @@ var __generator = (this && this.__generator) || function (thisArg, body) {
|
|
|
14
14
|
function verb(n) { return function (v) { return step([n, v]); }; }
|
|
15
15
|
function step(op) {
|
|
16
16
|
if (f) throw new TypeError("Generator is already executing.");
|
|
17
|
-
while (_) try {
|
|
17
|
+
while (g && (g = 0, op[0] && (_ = 0)), _) try {
|
|
18
18
|
if (f = 1, y && (t = op[0] & 2 ? y["return"] : op[0] ? y["throw"] || ((t = y["return"]) && t.call(y), 0) : y.next) && !(t = t.call(y, op[1])).done) return t;
|
|
19
19
|
if (y = 0, t) op = [op[0] & 2, t.value];
|
|
20
20
|
switch (op[0]) {
|
|
@@ -43,21 +43,19 @@ exports.Route = {
|
|
|
43
43
|
path: "/send-message",
|
|
44
44
|
docs: "Publishes push notification to one or multiple devices",
|
|
45
45
|
};
|
|
46
|
-
var PostMessage = function (_a) {
|
|
47
|
-
var ctx =
|
|
48
|
-
return
|
|
49
|
-
|
|
50
|
-
|
|
51
|
-
|
|
52
|
-
|
|
53
|
-
|
|
54
|
-
|
|
55
|
-
|
|
56
|
-
|
|
57
|
-
}
|
|
58
|
-
});
|
|
46
|
+
var PostMessage = function (_a) { return __awaiter(void 0, [_a], void 0, function (_b) {
|
|
47
|
+
var ctx = _b.ctx, req = _b.req;
|
|
48
|
+
return __generator(this, function (_c) {
|
|
49
|
+
switch (_c.label) {
|
|
50
|
+
case 0: return [4 /*yield*/, ctx.plugins.firebaseMessaging.send(req.body)];
|
|
51
|
+
case 1:
|
|
52
|
+
_c.sent();
|
|
53
|
+
return [2 /*return*/, {
|
|
54
|
+
data: { failedDevices: [] }, // TODO
|
|
55
|
+
}];
|
|
56
|
+
}
|
|
59
57
|
});
|
|
60
|
-
};
|
|
58
|
+
}); };
|
|
61
59
|
exports.default = PostMessage;
|
|
62
60
|
exports.__assumedHttpMethod = "post", exports.__file = "PostMessage.ts", exports.__query = [], exports.__params = [];
|
|
63
|
-
exports.__schemas = { reqSchema: { "$schema": "http://json-schema.org/draft-07/schema#", "type": "object", "additionalProperties": false, "properties": { "to": { "type": "array", "items": { "type": "string" }
|
|
61
|
+
exports.__schemas = { reqSchema: { "$schema": "http://json-schema.org/draft-07/schema#", "type": "object", "additionalProperties": false, "properties": { "to": { "type": "array", "items": { "type": "string" } }, "notification": { "type": "object", "properties": { "title": { "type": "string" }, "body": { "type": "string" } }, "additionalProperties": false }, "data": { "type": "object", "additionalProperties": { "type": "string" } } }, "required": ["data", "to"], "definitions": {} }, resSchema: { "$schema": "http://json-schema.org/draft-07/schema#", "type": "object", "additionalProperties": false, "properties": { "failedDevices": { "type": "array", "items": { "type": "string" } } }, "required": ["failedDevices"], "definitions": {} } };
|
package/dist/src/index.js
CHANGED
|
@@ -1,7 +1,11 @@
|
|
|
1
1
|
"use strict";
|
|
2
2
|
var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) {
|
|
3
3
|
if (k2 === undefined) k2 = k;
|
|
4
|
-
Object.
|
|
4
|
+
var desc = Object.getOwnPropertyDescriptor(m, k);
|
|
5
|
+
if (!desc || ("get" in desc ? !m.__esModule : desc.writable || desc.configurable)) {
|
|
6
|
+
desc = { enumerable: true, get: function() { return m[k]; } };
|
|
7
|
+
}
|
|
8
|
+
Object.defineProperty(o, k2, desc);
|
|
5
9
|
}) : (function(o, m, k, k2) {
|
|
6
10
|
if (k2 === undefined) k2 = k;
|
|
7
11
|
o[k2] = m[k];
|
|
@@ -14,7 +14,7 @@ var __generator = (this && this.__generator) || function (thisArg, body) {
|
|
|
14
14
|
function verb(n) { return function (v) { return step([n, v]); }; }
|
|
15
15
|
function step(op) {
|
|
16
16
|
if (f) throw new TypeError("Generator is already executing.");
|
|
17
|
-
while (_) try {
|
|
17
|
+
while (g && (g = 0, op[0] && (_ = 0)), _) try {
|
|
18
18
|
if (f = 1, y && (t = op[0] & 2 ? y["return"] : op[0] ? y["throw"] || ((t = y["return"]) && t.call(y), 0) : y.next) && !(t = t.call(y, op[1])).done) return t;
|
|
19
19
|
if (y = 0, t) op = [op[0] & 2, t.value];
|
|
20
20
|
switch (op[0]) {
|
|
@@ -36,31 +36,29 @@ var __generator = (this && this.__generator) || function (thisArg, body) {
|
|
|
36
36
|
}
|
|
37
37
|
};
|
|
38
38
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
39
|
-
var getManagementPluginHandler = function (_a) {
|
|
40
|
-
var
|
|
41
|
-
|
|
42
|
-
|
|
43
|
-
|
|
44
|
-
|
|
45
|
-
|
|
46
|
-
|
|
47
|
-
|
|
48
|
-
|
|
49
|
-
|
|
50
|
-
|
|
51
|
-
|
|
52
|
-
|
|
53
|
-
|
|
54
|
-
|
|
55
|
-
|
|
56
|
-
|
|
57
|
-
|
|
58
|
-
|
|
59
|
-
|
|
60
|
-
|
|
61
|
-
|
|
62
|
-
}];
|
|
63
|
-
});
|
|
39
|
+
var getManagementPluginHandler = function (_a) { return __awaiter(void 0, [_a], void 0, function (_b) {
|
|
40
|
+
var modules, module, segments, messageingData, data;
|
|
41
|
+
var _c, _d;
|
|
42
|
+
var ctx = _b.ctx, req = _b.req, origin = _b.origin;
|
|
43
|
+
return __generator(this, function (_e) {
|
|
44
|
+
modules = ctx.plugins.managementApi.moduleList.modules;
|
|
45
|
+
module = modules.find(function (p) { return p.id == origin; });
|
|
46
|
+
segments = (_c = module.data) === null || _c === void 0 ? void 0 : _c.segments;
|
|
47
|
+
messageingData = ((_d = module.data) === null || _d === void 0 ? void 0 : _d.data) || [];
|
|
48
|
+
data = {
|
|
49
|
+
segments: segments.map(function (s) {
|
|
50
|
+
var sv = {
|
|
51
|
+
id: s.id,
|
|
52
|
+
description: s.description,
|
|
53
|
+
};
|
|
54
|
+
return sv;
|
|
55
|
+
}),
|
|
56
|
+
data: messageingData,
|
|
57
|
+
};
|
|
58
|
+
return [2 /*return*/, {
|
|
59
|
+
data: data,
|
|
60
|
+
status: 200,
|
|
61
|
+
}];
|
|
64
62
|
});
|
|
65
|
-
};
|
|
63
|
+
}); };
|
|
66
64
|
exports.default = getManagementPluginHandler;
|
|
@@ -14,7 +14,7 @@ var __generator = (this && this.__generator) || function (thisArg, body) {
|
|
|
14
14
|
function verb(n) { return function (v) { return step([n, v]); }; }
|
|
15
15
|
function step(op) {
|
|
16
16
|
if (f) throw new TypeError("Generator is already executing.");
|
|
17
|
-
while (_) try {
|
|
17
|
+
while (g && (g = 0, op[0] && (_ = 0)), _) try {
|
|
18
18
|
if (f = 1, y && (t = op[0] & 2 ? y["return"] : op[0] ? y["throw"] || ((t = y["return"]) && t.call(y), 0) : y.next) && !(t = t.call(y, op[1])).done) return t;
|
|
19
19
|
if (y = 0, t) op = [op[0] & 2, t.value];
|
|
20
20
|
switch (op[0]) {
|
|
@@ -36,48 +36,46 @@ var __generator = (this && this.__generator) || function (thisArg, body) {
|
|
|
36
36
|
}
|
|
37
37
|
};
|
|
38
38
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
39
|
-
var postMessageHandler = function (_a) {
|
|
40
|
-
var
|
|
41
|
-
|
|
42
|
-
|
|
43
|
-
|
|
44
|
-
|
|
45
|
-
|
|
46
|
-
|
|
47
|
-
|
|
48
|
-
|
|
49
|
-
|
|
50
|
-
if (!segment) {
|
|
51
|
-
return [2 /*return*/, {
|
|
52
|
-
data: { message: "Segment not found" },
|
|
53
|
-
status: 500,
|
|
54
|
-
}];
|
|
55
|
-
}
|
|
56
|
-
return [4 /*yield*/, segment.handler(ctx)];
|
|
57
|
-
case 1:
|
|
58
|
-
targets = _e.sent();
|
|
59
|
-
tokens = targets.map(function (t) { return t.pushToken; }).flat();
|
|
60
|
-
message = {
|
|
61
|
-
to: tokens,
|
|
62
|
-
notification: {
|
|
63
|
-
title: req.body.subject,
|
|
64
|
-
body: req.body.body,
|
|
65
|
-
},
|
|
66
|
-
data: req.body.data,
|
|
67
|
-
};
|
|
68
|
-
return [4 /*yield*/, ctx.plugins["firebaseMessaging"].send(message)];
|
|
69
|
-
case 2:
|
|
70
|
-
_e.sent();
|
|
71
|
-
callback = (_d = module === null || module === void 0 ? void 0 : module.data) === null || _d === void 0 ? void 0 : _d.callback;
|
|
72
|
-
if (callback) {
|
|
73
|
-
callback(ctx, targets, message);
|
|
74
|
-
}
|
|
39
|
+
var postMessageHandler = function (_a) { return __awaiter(void 0, [_a], void 0, function (_b) {
|
|
40
|
+
var modules, module, segment, targets, tokens, message, callback;
|
|
41
|
+
var _c, _d, _e;
|
|
42
|
+
var ctx = _b.ctx, req = _b.req, origin = _b.origin;
|
|
43
|
+
return __generator(this, function (_f) {
|
|
44
|
+
switch (_f.label) {
|
|
45
|
+
case 0:
|
|
46
|
+
modules = ctx.plugins.managementApi.moduleList.modules;
|
|
47
|
+
module = modules.find(function (p) { return p.id == origin; });
|
|
48
|
+
segment = (_d = (_c = module === null || module === void 0 ? void 0 : module.data) === null || _c === void 0 ? void 0 : _c.segments) === null || _d === void 0 ? void 0 : _d.find(function (p) { return p.id === req.body.segment; });
|
|
49
|
+
if (!segment) {
|
|
75
50
|
return [2 /*return*/, {
|
|
76
|
-
data: {},
|
|
77
|
-
status:
|
|
51
|
+
data: { message: "Segment not found" },
|
|
52
|
+
status: 500,
|
|
78
53
|
}];
|
|
79
|
-
|
|
80
|
-
|
|
54
|
+
}
|
|
55
|
+
return [4 /*yield*/, segment.handler(ctx)];
|
|
56
|
+
case 1:
|
|
57
|
+
targets = _f.sent();
|
|
58
|
+
tokens = targets.map(function (t) { return t.pushToken; }).flat();
|
|
59
|
+
message = {
|
|
60
|
+
to: tokens,
|
|
61
|
+
notification: {
|
|
62
|
+
title: req.body.subject,
|
|
63
|
+
body: req.body.body,
|
|
64
|
+
},
|
|
65
|
+
data: req.body.data,
|
|
66
|
+
};
|
|
67
|
+
return [4 /*yield*/, ctx.plugins["firebaseMessaging"].send(message)];
|
|
68
|
+
case 2:
|
|
69
|
+
_f.sent();
|
|
70
|
+
callback = (_e = module === null || module === void 0 ? void 0 : module.data) === null || _e === void 0 ? void 0 : _e.callback;
|
|
71
|
+
if (callback) {
|
|
72
|
+
callback(ctx, targets, message);
|
|
73
|
+
}
|
|
74
|
+
return [2 /*return*/, {
|
|
75
|
+
data: {},
|
|
76
|
+
status: 200,
|
|
77
|
+
}];
|
|
78
|
+
}
|
|
81
79
|
});
|
|
82
|
-
};
|
|
80
|
+
}); };
|
|
83
81
|
exports.default = postMessageHandler;
|
package/package.json
CHANGED
|
@@ -1,32 +1,32 @@
|
|
|
1
1
|
{
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
|
|
2
|
+
"name": "@flink-app/firebase-messaging-plugin",
|
|
3
|
+
"version": "0.12.1-alpha.1",
|
|
4
|
+
"description": "Flink plugin to send Firebase cloud messages",
|
|
5
|
+
"scripts": {
|
|
6
|
+
"test": "echo \"Error: no test specified\"",
|
|
7
|
+
"build": "flink build",
|
|
8
|
+
"prepublish": "npm run build",
|
|
9
|
+
"watch": "nodemon --exec \"flink build\""
|
|
10
|
+
},
|
|
11
|
+
"author": "joel@frost.se",
|
|
12
|
+
"license": "MIT",
|
|
13
|
+
"types": "dist/src/index.d.ts",
|
|
14
|
+
"main": "dist/src/index.js",
|
|
15
|
+
"publishConfig": {
|
|
16
|
+
"access": "public"
|
|
17
|
+
},
|
|
18
|
+
"dependencies": {
|
|
19
|
+
"@flink-app/management-api-plugin": "^0.12.1-alpha.1",
|
|
20
|
+
"firebase-admin": "^12.1.1"
|
|
21
|
+
},
|
|
22
|
+
"devDependencies": {
|
|
23
|
+
"@flink-app/flink": "^0.12.1-alpha.1",
|
|
24
|
+
"@types/express": "^4.17.12",
|
|
25
|
+
"@types/node": "22.13.10",
|
|
26
|
+
"nodemon": "^2.0.7",
|
|
27
|
+
"ts-node": "^9.1.1",
|
|
28
|
+
"tsc-watch": "^4.2.9",
|
|
29
|
+
"typescript": "5.4.5"
|
|
30
|
+
},
|
|
31
|
+
"gitHead": "040e670be372c0cc47d9c7106bed55780910cf39"
|
|
32
32
|
}
|