Page MenuHomePhabricator

D6717.id22670.diff
No OneTemporary

D6717.id22670.diff

diff --git a/keyserver/src/push/providers.js b/keyserver/src/push/providers.js
--- a/keyserver/src/push/providers.js
+++ b/keyserver/src/push/providers.js
@@ -80,6 +80,14 @@
return codeVersion && codeVersion >= 87 ? 'app.comm' : 'org.squadcal.app';
}
+type WebPushConfig = { +publicKey: string, +privateKey: string };
+async function getWebPushConfig(): Promise<?WebPushConfig> {
+ return await importJSON<WebPushConfig>({
+ folder: 'secrets',
+ name: 'web_push_config',
+ });
+}
+
export {
getAPNPushProfileForCodeVersion,
getFCMPushProfileForCodeVersion,
@@ -88,4 +96,5 @@
endFirebase,
endAPNs,
getAPNsNotificationTopic,
+ getWebPushConfig,
};
diff --git a/keyserver/src/responders/website-responders.js b/keyserver/src/responders/website-responders.js
--- a/keyserver/src/responders/website-responders.js
+++ b/keyserver/src/responders/website-responders.js
@@ -3,6 +3,7 @@
import html from 'common-tags/lib/html/index.js';
import type { $Response, $Request } from 'express';
import fs from 'fs';
+import invariant from 'invariant';
import _keyBy from 'lodash/fp/keyBy.js';
import * as React from 'react';
// eslint-disable-next-line import/extensions
@@ -40,6 +41,7 @@
fetchCurrentUserInfo,
fetchKnownUserInfos,
} from '../fetchers/user-fetchers.js';
+import { getWebPushConfig } from '../push/providers.js';
import { setNewSession } from '../session/cookies.js';
import { Viewer } from '../session/viewer.js';
import { streamJSON, waitForStream } from '../utils/json-stream.js';
@@ -301,6 +303,21 @@
return hasNotAcknowledgedPolicies ? 0 : initialTime;
})();
+ const pushApiPublicKeyPromise = (async () => {
+ const pushConfig = await getWebPushConfig();
+ if (!pushConfig && process.env.NODE_ENV === 'development') {
+ console.log(
+ 'no keyserver/secrets/web_push_config.json so skipping sending public key',
+ );
+ return null;
+ }
+ invariant(
+ pushConfig,
+ 'keyserver/secrets/web_push_config.json should exist',
+ );
+ return pushConfig.publicKey;
+ })();
+
const { jsURL, fontsURL, cssInclude } = await assetInfoPromise;
// prettier-ignore
@@ -386,6 +403,7 @@
windowActive: true,
userPolicies: {},
primaryIdentityPublicKey: null,
+ pushApiPublicKey: pushApiPublicKeyPromise,
_persist: null,
});
const jsonStream = streamJSON(res, initialReduxState);
diff --git a/lib/types/redux-types.js b/lib/types/redux-types.js
--- a/lib/types/redux-types.js
+++ b/lib/types/redux-types.js
@@ -121,6 +121,7 @@
deviceToken?: void,
cookie?: void,
primaryIdentityPublicKey: ?string,
+ pushApiPublicKey: ?string,
...
};
export type AppState = NativeAppState | WebAppState;
diff --git a/web/redux/redux-setup.js b/web/redux/redux-setup.js
--- a/web/redux/redux-setup.js
+++ b/web/redux/redux-setup.js
@@ -81,6 +81,7 @@
windowActive: boolean,
userPolicies: UserPolicies,
primaryIdentityPublicKey: ?string,
+ pushApiPublicKey: ?string,
_persist: ?PersistState,
};

File Metadata

Mime Type
text/plain
Expires
Sun, Dec 22, 6:49 PM (18 h, 25 m)
Storage Engine
blob
Storage Format
Raw Data
Storage Handle
2692148
Default Alt Text
D6717.id22670.diff (2 KB)

Event Timeline