@flink-app/firebase-messaging-plugin 0.11.1 → 0.11.4-next.0
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.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/start.js +1 -1
- package/dist/src/ManagementModule.js +5 -1
- package/dist/src/firebaseMessagingPlugin.d.ts +1 -1
- package/dist/src/firebaseMessagingPlugin.js +46 -20
- package/dist/src/handlers/PostMessage.js +15 -17
- package/dist/src/index.js +5 -1
- package/dist/src/managementHandlers/Get.js +27 -29
- package/dist/src/managementHandlers/PostMessage.js +42 -44
- package/package.json +30 -30
- package/src/firebaseMessagingPlugin.ts +14 -3
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
// Generated
|
|
1
|
+
// Generated Mon Dec 09 2024 15:58:03 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
|
|
1
|
+
// Generated Mon Dec 09 2024 15:58:03 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
|
|
1
|
+
// Generated Mon Dec 09 2024 15:58:03 GMT+0100 (Central European Standard Time)
|
|
2
2
|
import { autoRegisteredRepos } from "@flink-app/flink";
|
|
3
3
|
export const repos = [];
|
|
4
4
|
autoRegisteredRepos.push(...repos);
|
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
import Message from "../../src/schemas/Message";
|
|
2
2
|
import SendResult from "../../src/schemas/SendResult";
|
|
3
3
|
|
|
4
|
-
// Generated
|
|
4
|
+
// Generated Mon Dec 09 2024 15:58:03 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
|
|
27
|
+
// Generated Mon Dec 09 2024 15:58:03 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
|
|
4
|
+
// Generated Mon Dec 09 2024 15:58:03 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
|
|
4
|
+
// Generated Mon Dec 09 2024 15:58:03 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);
|
package/dist/.flink/start.js
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
"use strict";
|
|
2
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
-
// Generated
|
|
3
|
+
// Generated Mon Dec 09 2024 15:58:03 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];
|
|
@@ -39,12 +43,12 @@ var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, ge
|
|
|
39
43
|
});
|
|
40
44
|
};
|
|
41
45
|
var __generator = (this && this.__generator) || function (thisArg, body) {
|
|
42
|
-
var _ = { label: 0, sent: function() { if (t[0] & 1) throw t[1]; return t[1]; }, trys: [], ops: [] }, f, y, t, g;
|
|
43
|
-
return g =
|
|
46
|
+
var _ = { label: 0, sent: function() { if (t[0] & 1) throw t[1]; return t[1]; }, trys: [], ops: [] }, f, y, t, g = Object.create((typeof Iterator === "function" ? Iterator : Object).prototype);
|
|
47
|
+
return g.next = verb(0), g["throw"] = verb(1), g["return"] = verb(2), typeof Symbol === "function" && (g[Symbol.iterator] = function() { return this; }), g;
|
|
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]) {
|
|
@@ -111,7 +115,7 @@ exports.firebaseMessagingPlugin = firebaseMessagingPlugin;
|
|
|
111
115
|
*/
|
|
112
116
|
function send(message, adminApp) {
|
|
113
117
|
return __awaiter(this, void 0, void 0, function () {
|
|
114
|
-
var messages,
|
|
118
|
+
var messages, batchSize, _loop_1, i;
|
|
115
119
|
return __generator(this, function (_a) {
|
|
116
120
|
switch (_a.label) {
|
|
117
121
|
case 0:
|
|
@@ -119,26 +123,48 @@ function send(message, adminApp) {
|
|
|
119
123
|
var toArray = message.to, rest = __rest(message, ["to"]);
|
|
120
124
|
return __assign(__assign({}, rest), { token: to });
|
|
121
125
|
});
|
|
122
|
-
|
|
126
|
+
batchSize = 500;
|
|
127
|
+
_loop_1 = function (i) {
|
|
128
|
+
var batch, response, err_1;
|
|
129
|
+
return __generator(this, function (_b) {
|
|
130
|
+
switch (_b.label) {
|
|
131
|
+
case 0:
|
|
132
|
+
batch = messages.slice(i, i + batchSize);
|
|
133
|
+
_b.label = 1;
|
|
134
|
+
case 1:
|
|
135
|
+
_b.trys.push([1, 3, , 4]);
|
|
136
|
+
return [4 /*yield*/, adminApp.messaging().sendEach(batch)];
|
|
137
|
+
case 2:
|
|
138
|
+
response = _b.sent();
|
|
139
|
+
response.responses.forEach(function (res, idx) {
|
|
140
|
+
if (res.success) {
|
|
141
|
+
flink_1.log.debug("[firebaseMessaging] Successfully sent to device ".concat(batch[idx].token));
|
|
142
|
+
}
|
|
143
|
+
else {
|
|
144
|
+
flink_1.log.debug("[firebaseMessaging] Failed sending to device ".concat(batch[idx].token, ": ").concat(res.error));
|
|
145
|
+
}
|
|
146
|
+
});
|
|
147
|
+
return [3 /*break*/, 4];
|
|
148
|
+
case 3:
|
|
149
|
+
err_1 = _b.sent();
|
|
150
|
+
flink_1.log.debug("[firebaseMessaging] Failed sending batch: ".concat(err_1));
|
|
151
|
+
return [3 /*break*/, 4];
|
|
152
|
+
case 4: return [2 /*return*/];
|
|
153
|
+
}
|
|
154
|
+
});
|
|
155
|
+
};
|
|
156
|
+
i = 0;
|
|
123
157
|
_a.label = 1;
|
|
124
158
|
case 1:
|
|
125
|
-
if (!(
|
|
126
|
-
|
|
127
|
-
_a.label = 2;
|
|
159
|
+
if (!(i < messages.length)) return [3 /*break*/, 4];
|
|
160
|
+
return [5 /*yield**/, _loop_1(i)];
|
|
128
161
|
case 2:
|
|
129
|
-
_a.trys.push([2, 4, , 5]);
|
|
130
|
-
return [4 /*yield*/, adminApp.messaging().send(message_1)];
|
|
131
|
-
case 3:
|
|
132
162
|
_a.sent();
|
|
133
|
-
|
|
134
|
-
case
|
|
135
|
-
|
|
136
|
-
flink_1.log.debug("[firebaseMessaging] Failed sending to device " + message_1.token + ": " + err_1);
|
|
137
|
-
return [3 /*break*/, 5];
|
|
138
|
-
case 5:
|
|
139
|
-
_i++;
|
|
163
|
+
_a.label = 3;
|
|
164
|
+
case 3:
|
|
165
|
+
i += batchSize;
|
|
140
166
|
return [3 /*break*/, 1];
|
|
141
|
-
case
|
|
167
|
+
case 4: return [2 /*return*/];
|
|
142
168
|
}
|
|
143
169
|
});
|
|
144
170
|
});
|
|
@@ -9,12 +9,12 @@ var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, ge
|
|
|
9
9
|
});
|
|
10
10
|
};
|
|
11
11
|
var __generator = (this && this.__generator) || function (thisArg, body) {
|
|
12
|
-
var _ = { label: 0, sent: function() { if (t[0] & 1) throw t[1]; return t[1]; }, trys: [], ops: [] }, f, y, t, g;
|
|
13
|
-
return g =
|
|
12
|
+
var _ = { label: 0, sent: function() { if (t[0] & 1) throw t[1]; return t[1]; }, trys: [], ops: [] }, f, y, t, g = Object.create((typeof Iterator === "function" ? Iterator : Object).prototype);
|
|
13
|
+
return g.next = verb(0), g["throw"] = verb(1), g["return"] = verb(2), typeof Symbol === "function" && (g[Symbol.iterator] = function() { return this; }), g;
|
|
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
61
|
exports.__schemas = { reqSchema: { "$schema": "http://json-schema.org/draft-07/schema#", "type": "object", "additionalProperties": false, "properties": { "to": { "type": "array", "items": { "type": "string" }, "description": "Devices to send to" }, "notification": { "type": "object", "properties": { "title": { "type": "string", "description": "Optional push notification title" }, "body": { "type": "string", "description": "Optional body" } }, "additionalProperties": false, "description": "Use `notification` if sending a standard push notification https://firebase.google.com/docs/cloud-messaging/concept-options#notifications" }, "data": { "type": "object", "additionalProperties": { "type": "string" }, "description": "Use `data` to send data messages. https://firebase.google.com/docs/cloud-messaging/concept-options#data_messages" } }, "required": ["data", "to"], "definitions": {} }, resSchema: { "$schema": "http://json-schema.org/draft-07/schema#", "type": "object", "additionalProperties": false, "properties": { "failedDevices": { "type": "array", "items": { "type": "string" }, "description": "Devices to which delivery failed" } }, "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];
|
|
@@ -9,12 +9,12 @@ var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, ge
|
|
|
9
9
|
});
|
|
10
10
|
};
|
|
11
11
|
var __generator = (this && this.__generator) || function (thisArg, body) {
|
|
12
|
-
var _ = { label: 0, sent: function() { if (t[0] & 1) throw t[1]; return t[1]; }, trys: [], ops: [] }, f, y, t, g;
|
|
13
|
-
return g =
|
|
12
|
+
var _ = { label: 0, sent: function() { if (t[0] & 1) throw t[1]; return t[1]; }, trys: [], ops: [] }, f, y, t, g = Object.create((typeof Iterator === "function" ? Iterator : Object).prototype);
|
|
13
|
+
return g.next = verb(0), g["throw"] = verb(1), g["return"] = verb(2), typeof Symbol === "function" && (g[Symbol.iterator] = function() { return this; }), g;
|
|
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;
|
|
@@ -9,12 +9,12 @@ var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, ge
|
|
|
9
9
|
});
|
|
10
10
|
};
|
|
11
11
|
var __generator = (this && this.__generator) || function (thisArg, body) {
|
|
12
|
-
var _ = { label: 0, sent: function() { if (t[0] & 1) throw t[1]; return t[1]; }, trys: [], ops: [] }, f, y, t, g;
|
|
13
|
-
return g =
|
|
12
|
+
var _ = { label: 0, sent: function() { if (t[0] & 1) throw t[1]; return t[1]; }, trys: [], ops: [] }, f, y, t, g = Object.create((typeof Iterator === "function" ? Iterator : Object).prototype);
|
|
13
|
+
return g.next = verb(0), g["throw"] = verb(1), g["return"] = verb(2), typeof Symbol === "function" && (g[Symbol.iterator] = function() { return this; }), g;
|
|
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.11.4-next.0",
|
|
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.11.4-next.0",
|
|
20
|
+
"firebase-admin": "^12.1.1"
|
|
21
|
+
},
|
|
22
|
+
"devDependencies": {
|
|
23
|
+
"@flink-app/flink": "^0.11.4-next.0",
|
|
24
|
+
"@types/express": "^4.17.12",
|
|
25
|
+
"@types/node": "^22.10.1",
|
|
26
|
+
"nodemon": "^2.0.7",
|
|
27
|
+
"ts-node": "^10.9.2",
|
|
28
|
+
"tsc-watch": "^4.2.9",
|
|
29
|
+
"typescript": "5.6.2"
|
|
30
|
+
},
|
|
31
|
+
"gitHead": "6a44df1b6601c86ea3402750b939784d003202c3"
|
|
32
32
|
}
|
|
@@ -50,11 +50,22 @@ async function send(message: Message, adminApp: admin.app.App) {
|
|
|
50
50
|
return { ...rest, token: to };
|
|
51
51
|
});
|
|
52
52
|
|
|
53
|
-
|
|
53
|
+
// Split messages into batches of 500
|
|
54
|
+
const batchSize = 500;
|
|
55
|
+
for (let i = 0; i < messages.length; i += batchSize) {
|
|
56
|
+
const batch = messages.slice(i, i + batchSize);
|
|
57
|
+
|
|
54
58
|
try {
|
|
55
|
-
await adminApp.messaging().
|
|
59
|
+
const response = await adminApp.messaging().sendEach(batch);
|
|
60
|
+
response.responses.forEach((res, idx) => {
|
|
61
|
+
if (res.success) {
|
|
62
|
+
log.debug(`[firebaseMessaging] Successfully sent to device ${batch[idx].token}`);
|
|
63
|
+
} else {
|
|
64
|
+
log.debug(`[firebaseMessaging] Failed sending to device ${batch[idx].token}: ${res.error}`);
|
|
65
|
+
}
|
|
66
|
+
});
|
|
56
67
|
} catch (err: any) {
|
|
57
|
-
log.debug(`[firebaseMessaging] Failed sending
|
|
68
|
+
log.debug(`[firebaseMessaging] Failed sending batch: ${err}`);
|
|
58
69
|
}
|
|
59
70
|
}
|
|
60
71
|
}
|