@flink-app/firebase-messaging-plugin 0.7.0-alpha.0 → 0.11.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 +2 -2
- 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.d.ts +1 -67
- package/dist/.flink/generatedHandlers.js +2 -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/firebaseMessagingPlugin.d.ts +1 -1
- package/dist/src/firebaseMessagingPlugin.js +23 -9
- package/dist/src/handlers/PostMessage.d.ts +2 -0
- package/dist/src/handlers/PostMessage.js +3 -1
- package/package.json +5 -5
- package/readme.md +2 -0
- package/src/firebaseMessagingPlugin.ts +25 -12
- package/dist/.flink/schemas.json +0 -57
|
@@ -1,7 +1,7 @@
|
|
|
1
|
-
// Generated
|
|
1
|
+
// Generated Tue Jun 18 2024 09:50:53 GMT+0200 (Central European Summer Time)
|
|
2
2
|
import { autoRegisteredHandlers, HttpMethod } from "@flink-app/flink";
|
|
3
3
|
import * as PostMessage_0 from "../src/handlers/PostMessage";
|
|
4
4
|
|
|
5
|
-
export const handlers = [{
|
|
5
|
+
export const handlers = [{handler: PostMessage_0, assumedHttpMethod: HttpMethod.post}];
|
|
6
6
|
autoRegisteredHandlers.push(...handlers);
|
|
7
7
|
|
package/.flink/generatedJobs.ts
CHANGED
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
// Generated
|
|
1
|
+
// Generated Tue Jun 18 2024 09:50:53 GMT+0200 (Central European Summer 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 Tue Jun 18 2024 09:50:53 GMT+0200 (Central European Summer 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 Tue Jun 18 2024 09:50:53 GMT+0200 (Central European Summer 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,72 +1,6 @@
|
|
|
1
1
|
import { HttpMethod } from "@flink-app/flink";
|
|
2
2
|
import * as PostMessage_0 from "../src/handlers/PostMessage";
|
|
3
3
|
export declare const handlers: {
|
|
4
|
-
importName: string;
|
|
5
|
-
moduleSpecifier: string;
|
|
6
|
-
schemasToGenerate: {
|
|
7
|
-
reqSchemaType: string;
|
|
8
|
-
resSchemaType: string;
|
|
9
|
-
};
|
|
10
|
-
__file: string;
|
|
11
|
-
__query: never[];
|
|
12
|
-
__params: never[];
|
|
13
|
-
__schemas: {
|
|
14
|
-
reqSchema: {
|
|
15
|
-
$schema: string;
|
|
16
|
-
type: string;
|
|
17
|
-
additionalProperties: boolean;
|
|
18
|
-
properties: {
|
|
19
|
-
to: {
|
|
20
|
-
type: string;
|
|
21
|
-
items: {
|
|
22
|
-
type: string;
|
|
23
|
-
};
|
|
24
|
-
description: string;
|
|
25
|
-
};
|
|
26
|
-
notification: {
|
|
27
|
-
type: string;
|
|
28
|
-
properties: {
|
|
29
|
-
title: {
|
|
30
|
-
type: string;
|
|
31
|
-
description: string;
|
|
32
|
-
};
|
|
33
|
-
body: {
|
|
34
|
-
type: string;
|
|
35
|
-
description: string;
|
|
36
|
-
};
|
|
37
|
-
};
|
|
38
|
-
additionalProperties: boolean;
|
|
39
|
-
description: string;
|
|
40
|
-
};
|
|
41
|
-
data: {
|
|
42
|
-
type: string;
|
|
43
|
-
additionalProperties: {
|
|
44
|
-
type: string;
|
|
45
|
-
};
|
|
46
|
-
description: string;
|
|
47
|
-
};
|
|
48
|
-
};
|
|
49
|
-
required: string[];
|
|
50
|
-
definitions: {};
|
|
51
|
-
};
|
|
52
|
-
resSchema: {
|
|
53
|
-
$schema: string;
|
|
54
|
-
type: string;
|
|
55
|
-
additionalProperties: boolean;
|
|
56
|
-
properties: {
|
|
57
|
-
failedDevices: {
|
|
58
|
-
type: string;
|
|
59
|
-
items: {
|
|
60
|
-
type: string;
|
|
61
|
-
};
|
|
62
|
-
description: string;
|
|
63
|
-
};
|
|
64
|
-
};
|
|
65
|
-
required: string[];
|
|
66
|
-
definitions: {};
|
|
67
|
-
};
|
|
68
|
-
};
|
|
69
|
-
assumedHttpMethod: HttpMethod;
|
|
70
4
|
handler: typeof PostMessage_0;
|
|
71
|
-
|
|
5
|
+
assumedHttpMethod: HttpMethod;
|
|
72
6
|
}[];
|
|
@@ -20,8 +20,8 @@ var __importStar = (this && this.__importStar) || function (mod) {
|
|
|
20
20
|
};
|
|
21
21
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
22
22
|
exports.handlers = void 0;
|
|
23
|
-
// Generated
|
|
23
|
+
// Generated Tue Jun 18 2024 09:50:53 GMT+0200 (Central European Summer Time)
|
|
24
24
|
var flink_1 = require("@flink-app/flink");
|
|
25
25
|
var PostMessage_0 = __importStar(require("../src/handlers/PostMessage"));
|
|
26
|
-
exports.handlers = [{
|
|
26
|
+
exports.handlers = [{ handler: PostMessage_0, assumedHttpMethod: flink_1.HttpMethod.post }];
|
|
27
27
|
flink_1.autoRegisteredHandlers.push.apply(flink_1.autoRegisteredHandlers, exports.handlers);
|
|
@@ -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 Tue Jun 18 2024 09:50:53 GMT+0200 (Central European Summer 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 Tue Jun 18 2024 09:50:53 GMT+0200 (Central European Summer 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 Tue Jun 18 2024 09:50:53 GMT+0200 (Central European Summer Time)
|
|
4
4
|
require("./generatedHandlers");
|
|
5
5
|
require("./generatedRepos");
|
|
6
6
|
require("./generatedJobs");
|
|
@@ -65,21 +65,34 @@ var __generator = (this && this.__generator) || function (thisArg, body) {
|
|
|
65
65
|
if (op[0] & 5) throw op[1]; return { value: op[0] ? op[1] : void 0, done: true };
|
|
66
66
|
}
|
|
67
67
|
};
|
|
68
|
+
var __rest = (this && this.__rest) || function (s, e) {
|
|
69
|
+
var t = {};
|
|
70
|
+
for (var p in s) if (Object.prototype.hasOwnProperty.call(s, p) && e.indexOf(p) < 0)
|
|
71
|
+
t[p] = s[p];
|
|
72
|
+
if (s != null && typeof Object.getOwnPropertySymbols === "function")
|
|
73
|
+
for (var i = 0, p = Object.getOwnPropertySymbols(s); i < p.length; i++) {
|
|
74
|
+
if (e.indexOf(p[i]) < 0 && Object.prototype.propertyIsEnumerable.call(s, p[i]))
|
|
75
|
+
t[p[i]] = s[p[i]];
|
|
76
|
+
}
|
|
77
|
+
return t;
|
|
78
|
+
};
|
|
68
79
|
var __importDefault = (this && this.__importDefault) || function (mod) {
|
|
69
80
|
return (mod && mod.__esModule) ? mod : { "default": mod };
|
|
70
81
|
};
|
|
71
82
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
72
83
|
exports.firebaseMessagingPlugin = void 0;
|
|
73
84
|
var flink_1 = require("@flink-app/flink");
|
|
74
|
-
var fcm_push_1 = __importDefault(require("fcm-push"));
|
|
75
85
|
var PostMessage = __importStar(require("./handlers/PostMessage"));
|
|
86
|
+
var firebase_admin_1 = __importDefault(require("firebase-admin"));
|
|
76
87
|
var firebaseMessagingPlugin = function (options) {
|
|
77
|
-
var
|
|
88
|
+
var decodedKey = Buffer.from(options.serviceAccountKey, "base64").toString("utf-8");
|
|
89
|
+
var adminAdpp = firebase_admin_1.default.initializeApp({
|
|
90
|
+
credential: firebase_admin_1.default.credential.cert(JSON.parse(decodedKey))
|
|
91
|
+
});
|
|
78
92
|
return {
|
|
79
93
|
id: "firebaseMessaging",
|
|
80
94
|
ctx: {
|
|
81
|
-
|
|
82
|
-
send: function (message) { return send(message, fcmClient); },
|
|
95
|
+
send: function (message) { return send(message, adminAdpp); },
|
|
83
96
|
},
|
|
84
97
|
init: function (app) { return __awaiter(void 0, void 0, void 0, function () {
|
|
85
98
|
var _a;
|
|
@@ -96,15 +109,16 @@ exports.firebaseMessagingPlugin = firebaseMessagingPlugin;
|
|
|
96
109
|
/**
|
|
97
110
|
* Send push notification.
|
|
98
111
|
*/
|
|
99
|
-
function send(message,
|
|
112
|
+
function send(message, adminApp) {
|
|
100
113
|
var messages = message.to.map(function (to) {
|
|
101
|
-
|
|
114
|
+
var toArray = message.to, rest = __rest(message, ["to"]);
|
|
115
|
+
return __assign(__assign({}, rest), { token: to });
|
|
102
116
|
});
|
|
103
117
|
return Promise.all(messages.map(function (m) {
|
|
104
|
-
|
|
105
|
-
.send(m)
|
|
118
|
+
adminApp
|
|
119
|
+
.messaging().send(m)
|
|
106
120
|
.catch(function (err) {
|
|
107
|
-
return flink_1.log.debug("[firebaseMessaging] Failed sending to device " + m.
|
|
121
|
+
return flink_1.log.debug("[firebaseMessaging] Failed sending to device " + m.token + ": " + err);
|
|
108
122
|
});
|
|
109
123
|
}));
|
|
110
124
|
}
|
|
@@ -5,3 +5,5 @@ import SendResult from "../schemas/SendResult";
|
|
|
5
5
|
export declare const Route: RouteProps;
|
|
6
6
|
declare const PostMessage: Handler<FlinkContext<FirebaseMessagingContext>, Message, SendResult>;
|
|
7
7
|
export default PostMessage;
|
|
8
|
+
export declare const __assumedHttpMethod = "post", __file = "PostMessage.ts", __query: never[], __params: never[];
|
|
9
|
+
export declare const __schemas: any;
|
|
@@ -36,7 +36,7 @@ var __generator = (this && this.__generator) || function (thisArg, body) {
|
|
|
36
36
|
}
|
|
37
37
|
};
|
|
38
38
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
39
|
-
exports.Route = void 0;
|
|
39
|
+
exports.__schemas = exports.__params = exports.__query = exports.__file = exports.__assumedHttpMethod = exports.Route = void 0;
|
|
40
40
|
var flink_1 = require("@flink-app/flink");
|
|
41
41
|
exports.Route = {
|
|
42
42
|
method: flink_1.HttpMethod.post,
|
|
@@ -59,3 +59,5 @@ var PostMessage = function (_a) {
|
|
|
59
59
|
});
|
|
60
60
|
};
|
|
61
61
|
exports.default = PostMessage;
|
|
62
|
+
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" }, "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/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@flink-app/firebase-messaging-plugin",
|
|
3
|
-
"version": "0.
|
|
3
|
+
"version": "0.11.0",
|
|
4
4
|
"description": "Flink plugin to send Firebase cloud messages",
|
|
5
5
|
"scripts": {
|
|
6
6
|
"test": "echo \"Error: no test specified\"",
|
|
@@ -16,11 +16,11 @@
|
|
|
16
16
|
"access": "public"
|
|
17
17
|
},
|
|
18
18
|
"dependencies": {
|
|
19
|
-
"@flink-app/management-api-plugin": "^0.
|
|
20
|
-
"
|
|
19
|
+
"@flink-app/management-api-plugin": "^0.11.0",
|
|
20
|
+
"firebase-admin": "^12.1.1"
|
|
21
21
|
},
|
|
22
22
|
"devDependencies": {
|
|
23
|
-
"@flink-app/flink": "^0.
|
|
23
|
+
"@flink-app/flink": "^0.11.0",
|
|
24
24
|
"@types/express": "^4.17.12",
|
|
25
25
|
"@types/node": "^15.6.2",
|
|
26
26
|
"nodemon": "^2.0.7",
|
|
@@ -28,5 +28,5 @@
|
|
|
28
28
|
"tsc-watch": "^4.2.9",
|
|
29
29
|
"typescript": "^4.2.4"
|
|
30
30
|
},
|
|
31
|
-
"gitHead": "
|
|
31
|
+
"gitHead": "3869def3e7e7e7105373ad31bc23a8ed68108015"
|
|
32
32
|
}
|
package/readme.md
CHANGED
|
@@ -1,13 +1,15 @@
|
|
|
1
1
|
import { FlinkPlugin, log } from "@flink-app/flink";
|
|
2
|
-
|
|
2
|
+
|
|
3
3
|
import * as PostMessage from "./handlers/PostMessage";
|
|
4
4
|
import Message from "./schemas/Message";
|
|
5
|
+
import admin from "firebase-admin"
|
|
5
6
|
|
|
6
7
|
export type FirebaseMessagingPluginOptions = {
|
|
7
8
|
/**
|
|
8
9
|
* Firebase server key
|
|
9
10
|
*/
|
|
10
|
-
|
|
11
|
+
|
|
12
|
+
serviceAccountKey: string
|
|
11
13
|
|
|
12
14
|
/**
|
|
13
15
|
* If to expose endpoints for sending push notification.
|
|
@@ -22,13 +24,18 @@ export type FirebaseMessagingPluginOptions = {
|
|
|
22
24
|
export const firebaseMessagingPlugin = (
|
|
23
25
|
options: FirebaseMessagingPluginOptions
|
|
24
26
|
): FlinkPlugin => {
|
|
25
|
-
|
|
27
|
+
|
|
28
|
+
const decodedKey = Buffer.from(options.serviceAccountKey, "base64").toString("utf-8");
|
|
29
|
+
|
|
30
|
+
const adminAdpp = admin.initializeApp({
|
|
31
|
+
credential: admin.credential.cert(JSON.parse(decodedKey))
|
|
32
|
+
});
|
|
33
|
+
|
|
26
34
|
|
|
27
35
|
return {
|
|
28
36
|
id: "firebaseMessaging",
|
|
29
37
|
ctx: {
|
|
30
|
-
|
|
31
|
-
send: (message: Message) => send(message, fcmClient),
|
|
38
|
+
send: (message: Message) => send(message, adminAdpp),
|
|
32
39
|
},
|
|
33
40
|
init: async (app) => {
|
|
34
41
|
app.addHandler(PostMessage, {
|
|
@@ -41,20 +48,26 @@ export const firebaseMessagingPlugin = (
|
|
|
41
48
|
/**
|
|
42
49
|
* Send push notification.
|
|
43
50
|
*/
|
|
44
|
-
function send(message: Message,
|
|
51
|
+
function send(message: Message, adminApp: admin.app.App) {
|
|
45
52
|
const messages = message.to.map((to) => {
|
|
46
|
-
|
|
53
|
+
const { to : toArray, ...rest} = message;
|
|
54
|
+
return { ...rest, token : to };
|
|
47
55
|
});
|
|
48
56
|
|
|
49
57
|
return Promise.all(
|
|
50
|
-
messages.map((m) =>
|
|
51
|
-
|
|
52
|
-
|
|
58
|
+
messages.map((m) => {
|
|
59
|
+
|
|
60
|
+
adminApp
|
|
61
|
+
.messaging().send(m)
|
|
53
62
|
.catch((err: any) =>
|
|
54
63
|
log.debug(
|
|
55
|
-
`[firebaseMessaging] Failed sending to device ${m.
|
|
64
|
+
`[firebaseMessaging] Failed sending to device ${m.token}: ${err}`
|
|
56
65
|
)
|
|
57
66
|
)
|
|
58
|
-
|
|
67
|
+
|
|
68
|
+
|
|
69
|
+
|
|
70
|
+
})
|
|
71
|
+
|
|
59
72
|
);
|
|
60
73
|
}
|
package/dist/.flink/schemas.json
DELETED
|
@@ -1,57 +0,0 @@
|
|
|
1
|
-
{
|
|
2
|
-
"Message": {
|
|
3
|
-
"type": "object",
|
|
4
|
-
"properties": {
|
|
5
|
-
"to": {
|
|
6
|
-
"description": "Devices to send to",
|
|
7
|
-
"type": "array",
|
|
8
|
-
"items": {
|
|
9
|
-
"type": "string"
|
|
10
|
-
}
|
|
11
|
-
},
|
|
12
|
-
"notification": {
|
|
13
|
-
"description": "Use `notification` if sending a standard push notification\nhttps://firebase.google.com/docs/cloud-messaging/concept-options#notifications",
|
|
14
|
-
"type": "object",
|
|
15
|
-
"properties": {
|
|
16
|
-
"title": {
|
|
17
|
-
"description": "Optional push notification title",
|
|
18
|
-
"type": "string"
|
|
19
|
-
},
|
|
20
|
-
"body": {
|
|
21
|
-
"description": "Optional body",
|
|
22
|
-
"type": "string"
|
|
23
|
-
}
|
|
24
|
-
},
|
|
25
|
-
"additionalProperties": false
|
|
26
|
-
},
|
|
27
|
-
"data": {
|
|
28
|
-
"description": "Use `data` to send data messages.\nhttps://firebase.google.com/docs/cloud-messaging/concept-options#data_messages",
|
|
29
|
-
"type": "object",
|
|
30
|
-
"additionalProperties": {
|
|
31
|
-
"type": "string"
|
|
32
|
-
}
|
|
33
|
-
}
|
|
34
|
-
},
|
|
35
|
-
"additionalProperties": false,
|
|
36
|
-
"required": [
|
|
37
|
-
"data",
|
|
38
|
-
"to"
|
|
39
|
-
]
|
|
40
|
-
},
|
|
41
|
-
"SendResult": {
|
|
42
|
-
"type": "object",
|
|
43
|
-
"properties": {
|
|
44
|
-
"failedDevices": {
|
|
45
|
-
"description": "Devices to which delivery failed",
|
|
46
|
-
"type": "array",
|
|
47
|
-
"items": {
|
|
48
|
-
"type": "string"
|
|
49
|
-
}
|
|
50
|
-
}
|
|
51
|
-
},
|
|
52
|
-
"additionalProperties": false,
|
|
53
|
-
"required": [
|
|
54
|
-
"failedDevices"
|
|
55
|
-
]
|
|
56
|
-
}
|
|
57
|
-
}
|