Skip to content

Commit 560c432

Browse files
committed
prepare push notification for ios
add addToken graphql mutation
1 parent 949505f commit 560c432

File tree

7 files changed

+77
-3
lines changed

7 files changed

+77
-3
lines changed

.gitignore

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
11
node_modules/
22
*.env
33
*.log
4-
/dist/*
4+
/dist/*
5+
AuthKey_*.p8

package.json

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,7 @@
1313
"serve": "node dist/index.js"
1414
},
1515
"dependencies": {
16+
"apn": "^2.2.0",
1617
"apollo-cache-inmemory": "^1.1.7",
1718
"apollo-client": "^2.2.3",
1819
"apollo-engine": "^0.8.8",

src/graphql/resolvers/Notification.js

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,13 @@
1+
/* eslint no-underscore-dangle: ["error", { "allow": ["_id"] }] */
2+
3+
export default {
4+
Query: {},
5+
6+
Mutation: {
7+
addToken: async (parent, { token, os }, { user }) => {
8+
console.log('x');
9+
console.log(` ### addToken ### , Token: "${token}, os: "${os}"`);
10+
console.log('y');
11+
},
12+
},
13+
};

src/graphql/schemas/Notification.js

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,11 @@
1+
export default `
2+
3+
type TokenResult {
4+
succeeded: Boolean
5+
}
6+
7+
type Mutation {
8+
addToken(token: String!, os: String!): TokenResult
9+
}
10+
11+
`;

src/index.js

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,7 @@ import webhook from './scripts/webhook';
1616
// import importAll from './scripts/importAll';
1717

1818
import auth from './express/auth';
19+
import './services/notifications/apn';
1920

2021
// Models
2122
import ProcedureModel from './models/Procedure';

src/services/notifications/apn.js

Lines changed: 29 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,29 @@
1+
import apn from 'apn';
2+
3+
const options = {
4+
token: {
5+
key: process.env.APPLE_APN_KEY,
6+
keyId: process.env.APPLE_APN_KEY_ID,
7+
teamId: process.env.APPLE_TEAMID,
8+
},
9+
production: false,
10+
};
11+
12+
const apnProvider = new apn.Provider(options);
13+
14+
const deviceToken = 'c6a966484866d2d274d4660e9e593ccbc35636894eb08e2b1fb4070396bcaad5';
15+
16+
const note = new apn.Notification();
17+
18+
note.expiry = Math.floor(Date.now() / 1000) + 3600; // Expires 1 hour from now.
19+
note.badge = 3;
20+
note.sound = 'ping.aiff';
21+
note.alert = '\uD83D\uDCE7 \u2709 You have a new message';
22+
note.payload = { messageFrom: 'John Appleseed' };
23+
note.topic = 'de.democracy-deutschland.clientapp';
24+
25+
export default apnProvider;
26+
27+
apnProvider.send(note, deviceToken).then((result) => {
28+
console.log('apnProvider.send', result);
29+
});

yarn.lock

Lines changed: 20 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -97,6 +97,16 @@ anymatch@^2.0.0:
9797
micromatch "^3.1.4"
9898
normalize-path "^2.1.1"
9999

100+
apn@^2.2.0:
101+
version "2.2.0"
102+
resolved "https://registry.yarnpkg.com/apn/-/apn-2.2.0.tgz#211ae4adf31b115a033342376b7ce23a5d18c393"
103+
dependencies:
104+
debug "^3.1.0"
105+
http2 "https://github.com/node-apn/node-http2/archive/apn-2.1.4.tar.gz"
106+
jsonwebtoken "^8.1.0"
107+
node-forge "^0.7.1"
108+
verror "^1.10.0"
109+
100110
apollo-cache-control@^0.0.x:
101111
version "0.0.9"
102112
resolved "https://registry.yarnpkg.com/apollo-cache-control/-/apollo-cache-control-0.0.9.tgz#77100f456fb19526d33b7f595c8ab1a2980dcbb4"
@@ -2295,6 +2305,10 @@ http-signature@~1.2.0:
22952305
jsprim "^1.2.2"
22962306
sshpk "^1.7.0"
22972307

2308+
"http2@https://github.com/node-apn/node-http2/archive/apn-2.1.4.tar.gz":
2309+
version "3.3.6"
2310+
resolved "https://github.com/node-apn/node-http2/archive/apn-2.1.4.tar.gz#8333dee2d6e0089152cefad30f41ced502f9c366"
2311+
22982312
[email protected], iconv-lite@^0.4.17, iconv-lite@~0.4.13:
22992313
version "0.4.19"
23002314
resolved "https://registry.yarnpkg.com/iconv-lite/-/iconv-lite-0.4.19.tgz#f7468f60135f5e5dad3399c0a81be9a1603a082b"
@@ -2684,7 +2698,7 @@ jsonify@~0.0.0:
26842698
version "0.0.0"
26852699
resolved "https://registry.yarnpkg.com/jsonify/-/jsonify-0.0.0.tgz#2c74b6ee41d93ca51b7b5aaee8f503631d252a73"
26862700

2687-
jsonwebtoken@^8.2.0:
2701+
jsonwebtoken@^8.1.0, jsonwebtoken@^8.2.0:
26882702
version "8.2.0"
26892703
resolved "https://registry.yarnpkg.com/jsonwebtoken/-/jsonwebtoken-8.2.0.tgz#690ec3a9e7e95e2884347ce3e9eb9d389aa598b3"
26902704
dependencies:
@@ -3088,6 +3102,10 @@ node-fetch@^2.0.0:
30883102
version "2.0.0"
30893103
resolved "https://registry.yarnpkg.com/node-fetch/-/node-fetch-2.0.0.tgz#982bba43ecd4f2922a29cc186a6bbb0bb73fcba6"
30903104

3105+
node-forge@^0.7.1:
3106+
version "0.7.4"
3107+
resolved "https://registry.yarnpkg.com/node-forge/-/node-forge-0.7.4.tgz#8e6e9f563a1e32213aa7508cded22aa791dbf986"
3108+
30913109
node-pre-gyp@^0.6.39:
30923110
version "0.6.39"
30933111
resolved "https://registry.yarnpkg.com/node-pre-gyp/-/node-pre-gyp-0.6.39.tgz#c00e96860b23c0e1420ac7befc5044e1d78d8649"
@@ -4377,7 +4395,7 @@ vary@~1.1.2:
43774395
version "1.1.2"
43784396
resolved "https://registry.yarnpkg.com/vary/-/vary-1.1.2.tgz#2299f02c6ded30d4a5961b0b9f74524a18f634fc"
43794397

4380-
4398+
[email protected], verror@^1.10.0:
43814399
version "1.10.0"
43824400
resolved "https://registry.yarnpkg.com/verror/-/verror-1.10.0.tgz#3a105ca17053af55d6e270c1f8288682e18da400"
43834401
dependencies:

0 commit comments

Comments
 (0)