@flink-app/apn-plugin 0.11.11
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 +5 -0
- package/.flink/generatedJobs.ts +5 -0
- package/.flink/generatedRepos.ts +5 -0
- package/.flink/schemas/schemas.json +5 -0
- package/.flink/schemas/schemas.ts +1 -0
- package/.flink/start.ts +5 -0
- package/LICENSE +21 -0
- package/dist/.flink/generatedHandlers.d.ts +1 -0
- package/dist/.flink/generatedHandlers.js +7 -0
- package/dist/.flink/generatedJobs.d.ts +1 -0
- package/dist/.flink/generatedJobs.js +7 -0
- package/dist/.flink/generatedRepos.d.ts +1 -0
- package/dist/.flink/generatedRepos.js +7 -0
- package/dist/.flink/schemas/schemas.d.ts +0 -0
- package/dist/.flink/schemas/schemas.js +2 -0
- package/dist/.flink/schemas/schemas.json +5 -0
- package/dist/.flink/start.d.ts +4 -0
- package/dist/.flink/start.js +7 -0
- package/dist/src/ApnPluginContext.d.ts +6 -0
- package/dist/src/ApnPluginContext.js +2 -0
- package/dist/src/apnPlugin.d.ts +29 -0
- package/dist/src/apnPlugin.js +114 -0
- package/dist/src/index.d.ts +2 -0
- package/dist/src/index.js +14 -0
- package/dist/src/schemas/ApnMessage.d.ts +14 -0
- package/dist/src/schemas/ApnMessage.js +2 -0
- package/dist/src/schemas/Message.d.ts +13 -0
- package/dist/src/schemas/Message.js +2 -0
- package/dist/src/schemas/SendResult.d.ts +6 -0
- package/dist/src/schemas/SendResult.js +2 -0
- package/nodemon.json +7 -0
- package/package.json +29 -0
- package/readme.md +52 -0
- package/src/ApnPluginContext.ts +7 -0
- package/src/apnPlugin.ts +103 -0
- package/src/index.ts +2 -0
- package/src/schemas/ApnMessage.ts +18 -0
- package/tsconfig.json +23 -0
|
@@ -0,0 +1 @@
|
|
|
1
|
+
// Generated Thu Feb 13 2025 14:49:54 GMT+0100 (Central European Standard Time)
|
package/.flink/start.ts
ADDED
package/LICENSE
ADDED
|
@@ -0,0 +1,21 @@
|
|
|
1
|
+
The MIT License
|
|
2
|
+
|
|
3
|
+
Copyright (c) Frost Experience AB https://www.frost.se
|
|
4
|
+
|
|
5
|
+
Permission is hereby granted, free of charge, to any person obtaining a copy
|
|
6
|
+
of this software and associated documentation files (the "Software"), to deal
|
|
7
|
+
in the Software without restriction, including without limitation the rights
|
|
8
|
+
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
|
9
|
+
copies of the Software, and to permit persons to whom the Software is
|
|
10
|
+
furnished to do so, subject to the following conditions:
|
|
11
|
+
|
|
12
|
+
The above copyright notice and this permission notice shall be included in
|
|
13
|
+
all copies or substantial portions of the Software.
|
|
14
|
+
|
|
15
|
+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
|
16
|
+
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
|
17
|
+
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
|
18
|
+
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
|
19
|
+
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
|
20
|
+
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
|
|
21
|
+
THE SOFTWARE.
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export declare const handlers: never[];
|
|
@@ -0,0 +1,7 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.handlers = void 0;
|
|
4
|
+
// Generated Thu Feb 13 2025 14:49:54 GMT+0100 (Central European Standard Time)
|
|
5
|
+
var flink_1 = require("@flink-app/flink");
|
|
6
|
+
exports.handlers = [];
|
|
7
|
+
flink_1.autoRegisteredHandlers.push.apply(flink_1.autoRegisteredHandlers, exports.handlers);
|
|
@@ -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 Thu Feb 13 2025 14:49:54 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);
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export declare const repos: never[];
|
|
@@ -0,0 +1,7 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.repos = void 0;
|
|
4
|
+
// Generated Thu Feb 13 2025 14:49:54 GMT+0100 (Central European Standard Time)
|
|
5
|
+
var flink_1 = require("@flink-app/flink");
|
|
6
|
+
exports.repos = [];
|
|
7
|
+
flink_1.autoRegisteredRepos.push.apply(flink_1.autoRegisteredRepos, exports.repos);
|
|
File without changes
|
|
@@ -0,0 +1,7 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
// Generated Thu Feb 13 2025 14:49:54 GMT+0100 (Central European Standard Time)
|
|
4
|
+
require("./generatedHandlers");
|
|
5
|
+
require("./generatedRepos");
|
|
6
|
+
require("./generatedJobs");
|
|
7
|
+
require("../src/index");
|
|
@@ -0,0 +1,29 @@
|
|
|
1
|
+
import { FlinkPlugin } from "@flink-app/flink";
|
|
2
|
+
export declare type ApnPluginOptions = {
|
|
3
|
+
certificate: {
|
|
4
|
+
/**
|
|
5
|
+
* Base64 encoded string for your APNs certificate (in PEM format).
|
|
6
|
+
*/
|
|
7
|
+
cert: string;
|
|
8
|
+
/**
|
|
9
|
+
* Base64 encoded string for your APNs private key (in PEM format).
|
|
10
|
+
*/
|
|
11
|
+
key: string;
|
|
12
|
+
/**
|
|
13
|
+
* Optional passphrase for the private key, if needed.
|
|
14
|
+
*/
|
|
15
|
+
passphrase?: string;
|
|
16
|
+
};
|
|
17
|
+
production: boolean;
|
|
18
|
+
/**
|
|
19
|
+
* Default topic for your APNs notifications.
|
|
20
|
+
* For VoIP pushes this is typically your app's bundle id with a `.voip` suffix,
|
|
21
|
+
* e.g. "com.example.myapp.voip".
|
|
22
|
+
*/
|
|
23
|
+
topic: string;
|
|
24
|
+
/**
|
|
25
|
+
* Default priority for your APNs notifications.
|
|
26
|
+
*/
|
|
27
|
+
defaultPriority?: number;
|
|
28
|
+
};
|
|
29
|
+
export declare const apnPlugin: (options: ApnPluginOptions) => FlinkPlugin;
|
|
@@ -0,0 +1,114 @@
|
|
|
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 (_) 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
|
+
var __importDefault = (this && this.__importDefault) || function (mod) {
|
|
39
|
+
return (mod && mod.__esModule) ? mod : { "default": mod };
|
|
40
|
+
};
|
|
41
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
42
|
+
exports.apnPlugin = void 0;
|
|
43
|
+
var node_apn_1 = __importDefault(require("@parse/node-apn"));
|
|
44
|
+
var apnPlugin = function (options) {
|
|
45
|
+
// Decode the base64 encoded certificate and key.
|
|
46
|
+
var decodedCert = Buffer.from(options.certificate.cert, "base64").toString("utf8");
|
|
47
|
+
var decodedKey = Buffer.from(options.certificate.key, "base64").toString("utf8");
|
|
48
|
+
// Initialize the APNs provider using certificate-based authentication.
|
|
49
|
+
var provider = new node_apn_1.default.Provider({
|
|
50
|
+
cert: decodedCert,
|
|
51
|
+
key: decodedKey,
|
|
52
|
+
passphrase: options.certificate.passphrase,
|
|
53
|
+
production: options.production,
|
|
54
|
+
});
|
|
55
|
+
return {
|
|
56
|
+
id: "apn",
|
|
57
|
+
ctx: {
|
|
58
|
+
/**
|
|
59
|
+
* Sends a VoIP push notification.
|
|
60
|
+
* @param message - The message to be sent. Expected to include:
|
|
61
|
+
* - `to`: an array of device tokens,
|
|
62
|
+
* - `alert`: (optional) text to display,
|
|
63
|
+
* - `payload`: (optional) any extra data,
|
|
64
|
+
* - `topic`: (optional) override the default APNs topic.
|
|
65
|
+
*/
|
|
66
|
+
send: function (message) { return __awaiter(void 0, void 0, void 0, function () {
|
|
67
|
+
var notification, result, err_1;
|
|
68
|
+
return __generator(this, function (_a) {
|
|
69
|
+
switch (_a.label) {
|
|
70
|
+
case 0:
|
|
71
|
+
if (!message.to || message.to.length === 0) {
|
|
72
|
+
throw new Error("No device tokens provided in message.to");
|
|
73
|
+
}
|
|
74
|
+
notification = new node_apn_1.default.Notification();
|
|
75
|
+
notification.pushType = message.pushType || "alert";
|
|
76
|
+
// Set the priority to the default or the provided value.
|
|
77
|
+
notification.priority = message.priority || options.defaultPriority || 10;
|
|
78
|
+
// Use the topic provided in the message or fall back to the plugin's default.
|
|
79
|
+
notification.topic = message.topic || options.topic;
|
|
80
|
+
if (!notification.topic) {
|
|
81
|
+
throw new Error("APNs topic must be provided either in the message or in plugin options");
|
|
82
|
+
}
|
|
83
|
+
// Set any provided alert and payload properties.
|
|
84
|
+
if (message.alert) {
|
|
85
|
+
notification.alert = message.alert;
|
|
86
|
+
}
|
|
87
|
+
if (message.payload) {
|
|
88
|
+
notification.payload = message.payload;
|
|
89
|
+
}
|
|
90
|
+
_a.label = 1;
|
|
91
|
+
case 1:
|
|
92
|
+
_a.trys.push([1, 3, , 4]);
|
|
93
|
+
return [4 /*yield*/, provider.send(notification, message.to)];
|
|
94
|
+
case 2:
|
|
95
|
+
result = _a.sent();
|
|
96
|
+
console.log("APNs push result:", result);
|
|
97
|
+
return [2 /*return*/, result];
|
|
98
|
+
case 3:
|
|
99
|
+
err_1 = _a.sent();
|
|
100
|
+
console.error("Error sending APNs push:", err_1);
|
|
101
|
+
throw err_1;
|
|
102
|
+
case 4: return [2 /*return*/];
|
|
103
|
+
}
|
|
104
|
+
});
|
|
105
|
+
}); },
|
|
106
|
+
},
|
|
107
|
+
init: function (app) { return __awaiter(void 0, void 0, void 0, function () {
|
|
108
|
+
return __generator(this, function (_a) {
|
|
109
|
+
return [2 /*return*/];
|
|
110
|
+
});
|
|
111
|
+
}); },
|
|
112
|
+
};
|
|
113
|
+
};
|
|
114
|
+
exports.apnPlugin = apnPlugin;
|
|
@@ -0,0 +1,14 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) {
|
|
3
|
+
if (k2 === undefined) k2 = k;
|
|
4
|
+
Object.defineProperty(o, k2, { enumerable: true, get: function() { return m[k]; } });
|
|
5
|
+
}) : (function(o, m, k, k2) {
|
|
6
|
+
if (k2 === undefined) k2 = k;
|
|
7
|
+
o[k2] = m[k];
|
|
8
|
+
}));
|
|
9
|
+
var __exportStar = (this && this.__exportStar) || function(m, exports) {
|
|
10
|
+
for (var p in m) if (p !== "default" && !Object.prototype.hasOwnProperty.call(exports, p)) __createBinding(exports, m, p);
|
|
11
|
+
};
|
|
12
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
13
|
+
__exportStar(require("./apnPlugin"), exports);
|
|
14
|
+
__exportStar(require("./ApnPluginContext"), exports);
|
|
@@ -0,0 +1,14 @@
|
|
|
1
|
+
import { NotificationPushType } from "@parse/node-apn";
|
|
2
|
+
export default interface ApnMessage {
|
|
3
|
+
/**
|
|
4
|
+
* Devices to send to
|
|
5
|
+
*/
|
|
6
|
+
to: string[];
|
|
7
|
+
alert?: string;
|
|
8
|
+
payload: {
|
|
9
|
+
[x: string]: string;
|
|
10
|
+
};
|
|
11
|
+
topic?: string;
|
|
12
|
+
pushType?: NotificationPushType;
|
|
13
|
+
priority?: number;
|
|
14
|
+
}
|
|
@@ -0,0 +1,13 @@
|
|
|
1
|
+
import { NotificationPushType } from "@parse/node-apn";
|
|
2
|
+
export default interface Message {
|
|
3
|
+
/**
|
|
4
|
+
* Devices to send to
|
|
5
|
+
*/
|
|
6
|
+
to: string[];
|
|
7
|
+
alert?: string;
|
|
8
|
+
payload: {
|
|
9
|
+
[x: string]: string;
|
|
10
|
+
};
|
|
11
|
+
topic?: string;
|
|
12
|
+
pushType?: NotificationPushType;
|
|
13
|
+
}
|
package/nodemon.json
ADDED
package/package.json
ADDED
|
@@ -0,0 +1,29 @@
|
|
|
1
|
+
{
|
|
2
|
+
"name": "@flink-app/apn-plugin",
|
|
3
|
+
"version": "0.11.11",
|
|
4
|
+
"description": "Flink plugin to send push notifications to APN",
|
|
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
|
+
"@parse/node-apn": "6.4.3"
|
|
20
|
+
},
|
|
21
|
+
"devDependencies": {
|
|
22
|
+
"@flink-app/flink": "^0.11.9",
|
|
23
|
+
"@types/node": "^15.6.2",
|
|
24
|
+
"nodemon": "^2.0.7",
|
|
25
|
+
"ts-node": "^9.1.1",
|
|
26
|
+
"typescript": "4.2.3"
|
|
27
|
+
},
|
|
28
|
+
"gitHead": "0eb9b8d88342ba6c868ba70eed1dddb818d1f6dc"
|
|
29
|
+
}
|
package/readme.md
ADDED
|
@@ -0,0 +1,52 @@
|
|
|
1
|
+
# APN Plugin
|
|
2
|
+
|
|
3
|
+
A FLINK plugin used for sending push notifications using APN (Apple Push Notification) service.
|
|
4
|
+
|
|
5
|
+
## Usage
|
|
6
|
+
|
|
7
|
+
Install plugin to your flink app project:
|
|
8
|
+
|
|
9
|
+
```
|
|
10
|
+
npm i -S @flink-app/apn-plugin
|
|
11
|
+
```
|
|
12
|
+
|
|
13
|
+
Add and configure plugin in your app startup:
|
|
14
|
+
|
|
15
|
+
```typescript
|
|
16
|
+
import { apnPlugin } from "@flink-app/apn-plugin";
|
|
17
|
+
|
|
18
|
+
function start() {
|
|
19
|
+
new FlinkApp<AppContext>({
|
|
20
|
+
name: "My app",
|
|
21
|
+
plugins: [
|
|
22
|
+
apnPlugin({
|
|
23
|
+
token: {
|
|
24
|
+
key: "./path/to/AuthKey_XXXXXXXXXX.p8", // Absolute or relative path to your .p8 file
|
|
25
|
+
keyId: "XXXXXXXXXX", // Your APNs Auth Key ID
|
|
26
|
+
teamId: "YYYYYYYYYY", // Your Apple Developer Team ID
|
|
27
|
+
},
|
|
28
|
+
production: false, // Set to true if you want to use the production APNs server
|
|
29
|
+
}),
|
|
30
|
+
],
|
|
31
|
+
}).start();
|
|
32
|
+
}
|
|
33
|
+
```
|
|
34
|
+
|
|
35
|
+
Add it to your app context (normally `Ctx.ts` in the root folder of your project)
|
|
36
|
+
|
|
37
|
+
```
|
|
38
|
+
import { ApnPluginContext } from "@flink-app/apn-plugin";
|
|
39
|
+
|
|
40
|
+
export interface Ctx extends FlinkContext<ApnPluginContext> {
|
|
41
|
+
// your context here
|
|
42
|
+
}
|
|
43
|
+
|
|
44
|
+
```
|
|
45
|
+
|
|
46
|
+
## Configuration
|
|
47
|
+
|
|
48
|
+
- `token` - APNs Auth Key configuration
|
|
49
|
+
- `key` - Absolute or relative path to your .p8 file
|
|
50
|
+
- `keyId` - Your APNs Auth Key ID
|
|
51
|
+
- `teamId` - Your Apple Developer Team ID
|
|
52
|
+
- `production` - Set to true if you want to use the production APNs server
|
package/src/apnPlugin.ts
ADDED
|
@@ -0,0 +1,103 @@
|
|
|
1
|
+
import { FlinkPlugin } from "@flink-app/flink";
|
|
2
|
+
import apn from "@parse/node-apn";
|
|
3
|
+
|
|
4
|
+
import ApnMessage from "./schemas/ApnMessage";
|
|
5
|
+
|
|
6
|
+
export type ApnPluginOptions = {
|
|
7
|
+
certificate: {
|
|
8
|
+
/**
|
|
9
|
+
* Base64 encoded string for your APNs certificate (in PEM format).
|
|
10
|
+
*/
|
|
11
|
+
cert: string;
|
|
12
|
+
/**
|
|
13
|
+
* Base64 encoded string for your APNs private key (in PEM format).
|
|
14
|
+
*/
|
|
15
|
+
key: string;
|
|
16
|
+
/**
|
|
17
|
+
* Optional passphrase for the private key, if needed.
|
|
18
|
+
*/
|
|
19
|
+
passphrase?: string;
|
|
20
|
+
};
|
|
21
|
+
production: boolean;
|
|
22
|
+
/**
|
|
23
|
+
* Default topic for your APNs notifications.
|
|
24
|
+
* For VoIP pushes this is typically your app's bundle id with a `.voip` suffix,
|
|
25
|
+
* e.g. "com.example.myapp.voip".
|
|
26
|
+
*/
|
|
27
|
+
topic: string;
|
|
28
|
+
/**
|
|
29
|
+
* Default priority for your APNs notifications.
|
|
30
|
+
*/
|
|
31
|
+
defaultPriority?: number;
|
|
32
|
+
};
|
|
33
|
+
|
|
34
|
+
export const apnPlugin = (options: ApnPluginOptions): FlinkPlugin => {
|
|
35
|
+
// Decode the base64 encoded certificate and key.
|
|
36
|
+
const decodedCert = Buffer.from(options.certificate.cert, "base64").toString("utf8");
|
|
37
|
+
const decodedKey = Buffer.from(options.certificate.key, "base64").toString("utf8");
|
|
38
|
+
|
|
39
|
+
// Initialize the APNs provider using certificate-based authentication.
|
|
40
|
+
const provider = new apn.Provider({
|
|
41
|
+
cert: decodedCert,
|
|
42
|
+
key: decodedKey,
|
|
43
|
+
passphrase: options.certificate.passphrase,
|
|
44
|
+
production: options.production,
|
|
45
|
+
});
|
|
46
|
+
|
|
47
|
+
return {
|
|
48
|
+
id: "apn",
|
|
49
|
+
ctx: {
|
|
50
|
+
/**
|
|
51
|
+
* Sends a VoIP push notification.
|
|
52
|
+
* @param message - The message to be sent. Expected to include:
|
|
53
|
+
* - `to`: an array of device tokens,
|
|
54
|
+
* - `alert`: (optional) text to display,
|
|
55
|
+
* - `payload`: (optional) any extra data,
|
|
56
|
+
* - `topic`: (optional) override the default APNs topic.
|
|
57
|
+
*/
|
|
58
|
+
send: async (message: ApnMessage) => {
|
|
59
|
+
if (!message.to || message.to.length === 0) {
|
|
60
|
+
throw new Error("No device tokens provided in message.to");
|
|
61
|
+
}
|
|
62
|
+
|
|
63
|
+
const notification = new apn.Notification();
|
|
64
|
+
|
|
65
|
+
notification.pushType = message.pushType || "alert";
|
|
66
|
+
|
|
67
|
+
// Set the priority to the default or the provided value.
|
|
68
|
+
notification.priority = message.priority || options.defaultPriority || 10;
|
|
69
|
+
|
|
70
|
+
// Use the topic provided in the message or fall back to the plugin's default.
|
|
71
|
+
notification.topic = message.topic || options.topic;
|
|
72
|
+
if (!notification.topic) {
|
|
73
|
+
throw new Error("APNs topic must be provided either in the message or in plugin options");
|
|
74
|
+
}
|
|
75
|
+
|
|
76
|
+
// Set any provided alert and payload properties.
|
|
77
|
+
if (message.alert) {
|
|
78
|
+
notification.alert = message.alert;
|
|
79
|
+
}
|
|
80
|
+
if (message.payload) {
|
|
81
|
+
notification.payload = message.payload;
|
|
82
|
+
}
|
|
83
|
+
|
|
84
|
+
try {
|
|
85
|
+
const result = await provider.send(notification, message.to);
|
|
86
|
+
console.log("APNs push result:", result);
|
|
87
|
+
return result;
|
|
88
|
+
} catch (err) {
|
|
89
|
+
console.error("Error sending APNs push:", err);
|
|
90
|
+
throw err;
|
|
91
|
+
}
|
|
92
|
+
},
|
|
93
|
+
},
|
|
94
|
+
init: async (app) => {
|
|
95
|
+
// Optionally, add a message handler to your framework.
|
|
96
|
+
// Adjust permissions or handler names as required by your app.
|
|
97
|
+
// Example:
|
|
98
|
+
// app.addHandler("PostMessage", {
|
|
99
|
+
// permissions: [options.permissions?.send || "apn:send"],
|
|
100
|
+
// });
|
|
101
|
+
},
|
|
102
|
+
};
|
|
103
|
+
};
|
package/src/index.ts
ADDED
|
@@ -0,0 +1,18 @@
|
|
|
1
|
+
import { NotificationPushType } from "@parse/node-apn";
|
|
2
|
+
|
|
3
|
+
export default interface ApnMessage {
|
|
4
|
+
/**
|
|
5
|
+
* Devices to send to
|
|
6
|
+
*/
|
|
7
|
+
to: string[];
|
|
8
|
+
|
|
9
|
+
alert?: string;
|
|
10
|
+
|
|
11
|
+
payload: { [x: string]: string };
|
|
12
|
+
|
|
13
|
+
topic?: string;
|
|
14
|
+
|
|
15
|
+
pushType?: NotificationPushType;
|
|
16
|
+
|
|
17
|
+
priority?: number;
|
|
18
|
+
}
|
package/tsconfig.json
ADDED
|
@@ -0,0 +1,23 @@
|
|
|
1
|
+
{
|
|
2
|
+
"compilerOptions": {
|
|
3
|
+
"target": "es5",
|
|
4
|
+
"lib": ["esnext", "es2016"],
|
|
5
|
+
"allowJs": true,
|
|
6
|
+
"skipLibCheck": true,
|
|
7
|
+
"esModuleInterop": true,
|
|
8
|
+
"allowSyntheticDefaultImports": true,
|
|
9
|
+
"strict": true,
|
|
10
|
+
"forceConsistentCasingInFileNames": true,
|
|
11
|
+
"module": "commonjs",
|
|
12
|
+
"moduleResolution": "node",
|
|
13
|
+
"resolveJsonModule": true,
|
|
14
|
+
"isolatedModules": true,
|
|
15
|
+
"noEmit": false,
|
|
16
|
+
"declaration": true,
|
|
17
|
+
"experimentalDecorators": true,
|
|
18
|
+
"checkJs": true,
|
|
19
|
+
"outDir": "dist"
|
|
20
|
+
},
|
|
21
|
+
"include": ["./src/**/*.ts", "./.flink/**/*"],
|
|
22
|
+
"exclude": ["./node_modules/*"]
|
|
23
|
+
}
|