@flink-app/firebase-messaging-plugin 0.2.0-beta.15 → 0.2.0-beta.18

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.
@@ -1,4 +1,4 @@
1
- // Generated Thu Oct 28 2021 13:03:35 GMT+0200 (Central European Summer Time)
1
+ // Generated Fri Apr 11 2025 17:48:26 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
 
@@ -1,4 +1,4 @@
1
- // Generated Thu Oct 28 2021 13:03:35 GMT+0200 (Central European Summer Time)
1
+ // Generated Fri Apr 11 2025 17:48:26 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 Thu Oct 28 2021 13:03:36 GMT+0200 (Central European Summer Time)
4
+ // Generated Fri Apr 11 2025 17:48:26 GMT+0200 (Central European Summer Time)
5
5
  export interface PostMessage_17_ReqSchema extends Message {}
6
6
 
7
7
  export interface PostMessage_17_ResSchema extends SendResult {}
package/.flink/start.ts CHANGED
@@ -1,4 +1,4 @@
1
- // Generated Thu Oct 28 2021 13:03:35 GMT+0200 (Central European Summer Time)
1
+ // Generated Fri Apr 11 2025 17:48:26 GMT+0200 (Central European Summer Time)
2
2
  import "./generatedHandlers";
3
3
  import "./generatedRepos";
4
4
  import "../src/index";
@@ -20,7 +20,7 @@ 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 Thu Oct 28 2021 13:03:35 GMT+0200 (Central European Summer Time)
23
+ // Generated Fri Apr 11 2025 17:48:26 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
26
  exports.handlers = [{ handler: PostMessage_0, assumedHttpMethod: flink_1.HttpMethod.post }];
@@ -0,0 +1 @@
1
+ export declare const jobs: never[];
@@ -0,0 +1,7 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.jobs = void 0;
4
+ // Generated Sat Mar 29 2025 08:03:21 GMT+0100 (Central European Standard Time)
5
+ var flink_1 = require("@flink-app/flink");
6
+ exports.jobs = [];
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 Thu Oct 28 2021 13:03:35 GMT+0200 (Central European Summer Time)
4
+ // Generated Fri Apr 11 2025 17:48:26 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);
@@ -1,6 +1,6 @@
1
1
  "use strict";
2
2
  Object.defineProperty(exports, "__esModule", { value: true });
3
- // Generated Thu Oct 28 2021 13:03:35 GMT+0200 (Central European Summer Time)
3
+ // Generated Fri Apr 11 2025 17:48:26 GMT+0200 (Central European Summer Time)
4
4
  require("./generatedHandlers");
5
5
  require("./generatedRepos");
6
6
  require("../src/index");
@@ -0,0 +1,3 @@
1
+ import { ManagementApiModule } from "@flink-app/management-api-plugin";
2
+ import { GetManagementModuleConfig } from "./schemas/ManagementModule";
3
+ export declare const GetManagementModule: (config: GetManagementModuleConfig) => ManagementApiModule;
@@ -0,0 +1,71 @@
1
+ "use strict";
2
+ var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) {
3
+ if (k2 === undefined) k2 = k;
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);
9
+ }) : (function(o, m, k, k2) {
10
+ if (k2 === undefined) k2 = k;
11
+ o[k2] = m[k];
12
+ }));
13
+ var __setModuleDefault = (this && this.__setModuleDefault) || (Object.create ? (function(o, v) {
14
+ Object.defineProperty(o, "default", { enumerable: true, value: v });
15
+ }) : function(o, v) {
16
+ o["default"] = v;
17
+ });
18
+ var __importStar = (this && this.__importStar) || function (mod) {
19
+ if (mod && mod.__esModule) return mod;
20
+ var result = {};
21
+ if (mod != null) for (var k in mod) if (k !== "default" && Object.prototype.hasOwnProperty.call(mod, k)) __createBinding(result, mod, k);
22
+ __setModuleDefault(result, mod);
23
+ return result;
24
+ };
25
+ Object.defineProperty(exports, "__esModule", { value: true });
26
+ exports.GetManagementModule = void 0;
27
+ var flink_1 = require("@flink-app/flink");
28
+ var management_api_plugin_1 = require("@flink-app/management-api-plugin");
29
+ var getManagementPluginHandler = __importStar(require("./managementHandlers/Get"));
30
+ var postMessageHandler = __importStar(require("./managementHandlers/PostMessage"));
31
+ var GetManagementModule = function (config) {
32
+ var _a;
33
+ if (config.pluginId == null)
34
+ config.pluginId = "managementNotificationsApi";
35
+ var endpoints = [];
36
+ endpoints.push({
37
+ routeProps: {
38
+ path: "",
39
+ method: flink_1.HttpMethod.get,
40
+ origin: config.pluginId,
41
+ },
42
+ handler: getManagementPluginHandler,
43
+ });
44
+ endpoints.push({
45
+ routeProps: {
46
+ path: "/message",
47
+ method: flink_1.HttpMethod.post,
48
+ origin: config.pluginId,
49
+ },
50
+ handler: postMessageHandler,
51
+ });
52
+ var features = [];
53
+ var module = {
54
+ id: config.pluginId || "notifications",
55
+ uiSettings: {
56
+ title: ((_a = config.uiSettings) === null || _a === void 0 ? void 0 : _a.title) || "Notifications",
57
+ icon: "",
58
+ features: features,
59
+ },
60
+ ui: config.ui,
61
+ type: management_api_plugin_1.ManagementApiType.notification,
62
+ endpoints: endpoints,
63
+ data: {
64
+ segments: config.segments,
65
+ data: config.data,
66
+ callback: config.messageSentCallback,
67
+ },
68
+ };
69
+ return module;
70
+ };
71
+ exports.GetManagementModule = GetManagementModule;
@@ -0,0 +1,4 @@
1
+ import { FlinkContext, Handler } from "@flink-app/flink";
2
+ import { ManagementGetRequest, ManagementGetResponse } from "../schemas/ManagementGet";
3
+ declare const getManagementPluginHandler: Handler<FlinkContext, ManagementGetRequest, ManagementGetResponse>;
4
+ export default getManagementPluginHandler;
@@ -0,0 +1,64 @@
1
+ "use strict";
2
+ var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) {
3
+ function adopt(value) { return value instanceof P ? value : new P(function (resolve) { resolve(value); }); }
4
+ return new (P || (P = Promise))(function (resolve, reject) {
5
+ function fulfilled(value) { try { step(generator.next(value)); } catch (e) { reject(e); } }
6
+ function rejected(value) { try { step(generator["throw"](value)); } catch (e) { reject(e); } }
7
+ function step(result) { result.done ? resolve(result.value) : adopt(result.value).then(fulfilled, rejected); }
8
+ step((generator = generator.apply(thisArg, _arguments || [])).next());
9
+ });
10
+ };
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 = { next: verb(0), "throw": verb(1), "return": verb(2) }, typeof Symbol === "function" && (g[Symbol.iterator] = function() { return this; }), g;
14
+ function verb(n) { return function (v) { return step([n, v]); }; }
15
+ function step(op) {
16
+ if (f) throw new TypeError("Generator is already executing.");
17
+ while (g && (g = 0, op[0] && (_ = 0)), _) try {
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
+ if (y = 0, t) op = [op[0] & 2, t.value];
20
+ switch (op[0]) {
21
+ case 0: case 1: t = op; break;
22
+ case 4: _.label++; return { value: op[1], done: false };
23
+ case 5: _.label++; y = op[1]; op = [0]; continue;
24
+ case 7: op = _.ops.pop(); _.trys.pop(); continue;
25
+ default:
26
+ if (!(t = _.trys, t = t.length > 0 && t[t.length - 1]) && (op[0] === 6 || op[0] === 2)) { _ = 0; continue; }
27
+ if (op[0] === 3 && (!t || (op[1] > t[0] && op[1] < t[3]))) { _.label = op[1]; break; }
28
+ if (op[0] === 6 && _.label < t[1]) { _.label = t[1]; t = op; break; }
29
+ if (t && _.label < t[2]) { _.label = t[2]; _.ops.push(op); break; }
30
+ if (t[2]) _.ops.pop();
31
+ _.trys.pop(); continue;
32
+ }
33
+ op = body.call(thisArg, _);
34
+ } catch (e) { op = [6, e]; y = 0; } finally { f = t = 0; }
35
+ if (op[0] & 5) throw op[1]; return { value: op[0] ? op[1] : void 0, done: true };
36
+ }
37
+ };
38
+ Object.defineProperty(exports, "__esModule", { value: true });
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
+ }];
62
+ });
63
+ }); };
64
+ exports.default = getManagementPluginHandler;
@@ -0,0 +1,4 @@
1
+ import { FlinkContext, Handler } from "@flink-app/flink";
2
+ import { ManagementPostMessageRequest, ManagementPostMessageResponse } from "../schemas/ManagementPostMessage";
3
+ declare const postMessageHandler: Handler<FlinkContext, ManagementPostMessageRequest, ManagementPostMessageResponse>;
4
+ export default postMessageHandler;
@@ -0,0 +1,81 @@
1
+ "use strict";
2
+ var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) {
3
+ function adopt(value) { return value instanceof P ? value : new P(function (resolve) { resolve(value); }); }
4
+ return new (P || (P = Promise))(function (resolve, reject) {
5
+ function fulfilled(value) { try { step(generator.next(value)); } catch (e) { reject(e); } }
6
+ function rejected(value) { try { step(generator["throw"](value)); } catch (e) { reject(e); } }
7
+ function step(result) { result.done ? resolve(result.value) : adopt(result.value).then(fulfilled, rejected); }
8
+ step((generator = generator.apply(thisArg, _arguments || [])).next());
9
+ });
10
+ };
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 = { next: verb(0), "throw": verb(1), "return": verb(2) }, typeof Symbol === "function" && (g[Symbol.iterator] = function() { return this; }), g;
14
+ function verb(n) { return function (v) { return step([n, v]); }; }
15
+ function step(op) {
16
+ if (f) throw new TypeError("Generator is already executing.");
17
+ while (g && (g = 0, op[0] && (_ = 0)), _) try {
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
+ if (y = 0, t) op = [op[0] & 2, t.value];
20
+ switch (op[0]) {
21
+ case 0: case 1: t = op; break;
22
+ case 4: _.label++; return { value: op[1], done: false };
23
+ case 5: _.label++; y = op[1]; op = [0]; continue;
24
+ case 7: op = _.ops.pop(); _.trys.pop(); continue;
25
+ default:
26
+ if (!(t = _.trys, t = t.length > 0 && t[t.length - 1]) && (op[0] === 6 || op[0] === 2)) { _ = 0; continue; }
27
+ if (op[0] === 3 && (!t || (op[1] > t[0] && op[1] < t[3]))) { _.label = op[1]; break; }
28
+ if (op[0] === 6 && _.label < t[1]) { _.label = t[1]; t = op; break; }
29
+ if (t && _.label < t[2]) { _.label = t[2]; _.ops.push(op); break; }
30
+ if (t[2]) _.ops.pop();
31
+ _.trys.pop(); continue;
32
+ }
33
+ op = body.call(thisArg, _);
34
+ } catch (e) { op = [6, e]; y = 0; } finally { f = t = 0; }
35
+ if (op[0] & 5) throw op[1]; return { value: op[0] ? op[1] : void 0, done: true };
36
+ }
37
+ };
38
+ Object.defineProperty(exports, "__esModule", { value: true });
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) {
50
+ return [2 /*return*/, {
51
+ data: { message: "Segment not found" },
52
+ status: 500,
53
+ }];
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
+ }
79
+ });
80
+ }); };
81
+ exports.default = postMessageHandler;
@@ -0,0 +1,7 @@
1
+ import { MessagingData, MessagingSegmentView } from "./ManagementModule";
2
+ export interface ManagementGetRequest {
3
+ }
4
+ export interface ManagementGetResponse {
5
+ segments: MessagingSegmentView[];
6
+ data: MessagingData[];
7
+ }
@@ -0,0 +1,2 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
@@ -0,0 +1,28 @@
1
+ import { FlinkContext } from "@flink-app/flink";
2
+ import Message from "./Message";
3
+ export interface MessagingSegment {
4
+ id: string;
5
+ description: string;
6
+ handler(ctx: FlinkContext<any>): Promise<MessagingTarget[]>;
7
+ }
8
+ export interface MessagingSegmentView extends Omit<MessagingSegment, "handler"> {
9
+ }
10
+ export interface MessagingTarget {
11
+ userId: string;
12
+ pushToken: string[];
13
+ }
14
+ export interface MessagingData {
15
+ id: string;
16
+ description: string;
17
+ options?: string[];
18
+ }
19
+ export interface GetManagementModuleConfig {
20
+ pluginId?: string;
21
+ ui: boolean;
22
+ uiSettings?: {
23
+ title: string;
24
+ };
25
+ segments: MessagingSegment[];
26
+ data?: MessagingData[];
27
+ messageSentCallback?: (ctx: any, target: MessagingTarget[], message: Message) => void;
28
+ }
@@ -0,0 +1,2 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
@@ -0,0 +1,10 @@
1
+ export interface ManagementPostMessageRequest {
2
+ segment: string;
3
+ subject: string;
4
+ body: string;
5
+ data: {
6
+ [key: string]: string;
7
+ };
8
+ }
9
+ export interface ManagementPostMessageResponse {
10
+ }
@@ -0,0 +1,2 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@flink-app/firebase-messaging-plugin",
3
- "version": "0.2.0-beta.15",
3
+ "version": "0.2.0-beta.18",
4
4
  "description": "Flink plugin to send Firebase cloud messages",
5
5
  "scripts": {
6
6
  "test": "echo \"Error: no test specified\"",
@@ -19,7 +19,7 @@
19
19
  "fcm-push": "^1.1.3"
20
20
  },
21
21
  "devDependencies": {
22
- "@flink-app/flink": "^0.2.0-beta.15",
22
+ "@flink-app/flink": "^0.2.0-beta.18",
23
23
  "@types/express": "^4.17.12",
24
24
  "@types/node": "^15.6.2",
25
25
  "nodemon": "^2.0.7",
@@ -27,5 +27,5 @@
27
27
  "tsc-watch": "^4.2.9",
28
28
  "typescript": "^4.2.4"
29
29
  },
30
- "gitHead": "798ef9a11c291c0b16ed937436dd46986942546c"
30
+ "gitHead": "aaeadba35673b13654a54bf752fef3ecc4c94b52"
31
31
  }
@@ -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
- }