Skip to content

Commit

Permalink
Send notification body to fallback to
Browse files Browse the repository at this point in the history
  • Loading branch information
kaladivo committed May 16, 2024
1 parent be93996 commit a32dbee
Show file tree
Hide file tree
Showing 12 changed files with 69 additions and 32 deletions.
Binary file not shown.
2 changes: 1 addition & 1 deletion apps/location-service/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,7 @@
"@vexl-next/rest-api": "0.0.0",
"@vexl-next/server-utils": "0.0.0",
"axios": "^1.6.0",
"dotenv": "^16.0.3",
"dotenv": "^16.4.5",
"dynamic-import-polyfill": "^0.1.1",
"effect": "^3.0.1",
"fast-check": "^3.17.1"
Expand Down
2 changes: 1 addition & 1 deletion apps/mobile/app.config.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
// import {SemverString} from '@vexl-next/domain/src/utility/SmeverString.brand'

const VERSION_CODE = 200
const VERSION_CODE = 203
const VERSION = '1.17.0'
const ENV_PRESET = process.env.ENV_PRESET
const COMMIT_HASH = process.env.EAS_BUILD_GIT_COMMIT_HASH ?? 'local'
Expand Down
12 changes: 12 additions & 0 deletions apps/mobile/src/components/DebugScreen/index.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -276,6 +276,7 @@ function DebugScreen(): JSX.Element {
})
}
await notifee.displayNotification({
id: 'nnn',
title: `title ${Date.now()}`,
subtitle: 'some notification',
ios: {
Expand All @@ -300,6 +301,17 @@ function DebugScreen(): JSX.Element {
})()
}}
/>
<Button
variant="primary"
size="small"
text="print all not"
onPress={() => {
void (async () => {
const nots = await notifee.getDisplayedNotifications()
console.log(JSON.stringify(nots, null, 2))
})()
}}
/>
<Button
variant="primary"
size="small"
Expand Down
3 changes: 2 additions & 1 deletion apps/notification-service/package.json
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
{
"name": "notification-service",
"name": "@vexl-next/notification-service",
"version": "0.0.0",
"main": "index.js",
"type": "module",
Expand Down Expand Up @@ -41,6 +41,7 @@
"@vexl-next/cryptography": "0.0.0",
"@vexl-next/rest-api": "0.0.0",
"@vexl-next/server-utils": "0.0.0",
"dotenv": "^16.4.5",
"effect": "^3.0.1",
"fast-check": "^3.17.1",
"firebase-admin": "^12.1.0"
Expand Down
3 changes: 3 additions & 0 deletions apps/notification-service/src/EnvironmentLayer.ts
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,9 @@ const EnvironmentData = S.Struct({
FCM_TOKEN_PRIVATE_KEY: PrivateKeyPemBase64E,
SIGNATURE_PUBLIC_KEY: PublicKeyPemBase64E,
FIREBASE_CREDENTIALS: S.parseJson({}),
IOS_APP_BUNDLE_ID: S.String.pipe(
S.optional({default: () => 'it.vexl.nextstaging'})
),
})

export interface EnvironmentData
Expand Down
23 changes: 18 additions & 5 deletions apps/notification-service/src/FirebaseMessagingLayer.ts
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ import {SendingNotificationError} from '@vexl-next/rest-api/src/services/notific
import {Effect, Layer} from 'effect'
import {cert, initializeApp, type ServiceAccount} from 'firebase-admin/app'
import {getMessaging, type Message} from 'firebase-admin/messaging'
import {EnvironmentConstants} from './EnvironmentLayer'
import {EnvironmentConstants, type Environment} from './EnvironmentLayer'

export class FirebaseMessagingError extends Schema.TaggedError<FirebaseMessagingError>(
'FirebaseMessagingError'
Expand All @@ -16,16 +16,28 @@ export function sendFirebaseMessage({
}: Message & {
token: FcmToken
data: Record<string, string>
}): Effect.Effect<string, SendingNotificationError, FirebaseMessagingLayer> {
return FirebaseMessagingLayer.pipe(
Effect.flatMap((messaging) =>
}): Effect.Effect<
string,
SendingNotificationError,
FirebaseMessagingLayer | Environment
> {
return Effect.gen(function* (_) {
const messaging = yield* _(FirebaseMessagingLayer)
const topic = yield* _(EnvironmentConstants.IOS_APP_BUNDLE_ID)

return yield* _(
Effect.tryPromise({
try: async () =>
await messaging.send({
token,
data,
android: {priority: 'high'},
apns: {
headers: {
'apns-priority': '10',
'apns-push-type': 'alert',
'apns-topic': topic,
},
payload: {
aps: {
contentAvailable: true,
Expand All @@ -35,7 +47,8 @@ export function sendFirebaseMessage({
}),
catch: () => new SendingNotificationError({tokenInvalid: false}),
})
),
)
}).pipe(
Effect.tapError((e) => Effect.logInfo('Error while sending message', e))
)
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@ const IssueNotificationRouteLive = Http.router.post(
const fcmToken = yield* _(decodeFcmCypher(data.fcmCypher))

const encryptedNotificationData = new EncryptedNotificationData({
id: EncryptedNotificationData.id(),
payload: data.messagePayload,
targetCypher: data.fcmCypher,
})
Expand Down
12 changes: 11 additions & 1 deletion packages/domain/src/general/notifications.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@ import {type AST} from '@effect/schema'
import * as S from '@effect/schema/Schema'
import {type PublicKeyPemBase64} from '@vexl-next/cryptography/src/KeyHolder'
import {PublicKeyPemBase64E} from '@vexl-next/cryptography/src/KeyHolder/brands'
import {randomUUID} from 'crypto'
import {Brand} from 'effect'
import {z} from 'zod'

Expand Down Expand Up @@ -84,9 +85,18 @@ export const EncryptedNotificationPayloadSchema = S.String.pipe(
S.fromBrand(EncryptedNotificationPayload)
)

export const EncryptedNotificationDataId = S.UUID.pipe(
S.brand('EncryptedNotificationDataId')
)

export class EncryptedNotificationData extends S.TaggedClass<EncryptedNotificationData>(
'EncryptedNotificationData'
)('EncryptedNotificationData', {
id: EncryptedNotificationDataId,
payload: EncryptedNotificationPayloadSchema,
targetCypher: FcmCypherE,
}) {}
}) {
static id = (): S.Schema.Type<typeof EncryptedNotificationDataId> => {
return S.decodeSync(EncryptedNotificationDataId)(randomUUID())
}
}
12 changes: 10 additions & 2 deletions packages/domain/src/utility/Uuid.brand.ts
Original file line number Diff line number Diff line change
@@ -1,8 +1,16 @@
import {Schema} from '@effect/schema'
import {Brand} from 'effect'
import {randomUUID} from 'node:crypto'
import {z} from 'zod'

export const Uuid = z.string().uuid().brand<'Uuid'>()
export type Uuid = z.TypeOf<typeof Uuid>
export const Uuid = z
.string()
.uuid()
.transform((v) => Brand.nominal<typeof v & Brand.Brand<'Uuid'>>()(v))

export const UuidE = Schema.UUID.pipe(Schema.brand('Uuid'))

export type Uuid = Schema.Schema.Type<typeof UuidE>

export function generateUuid(): Uuid {
return Uuid.parse(randomUUID())
Expand Down
1 change: 0 additions & 1 deletion packages/ecdh-platform-native-utils/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,6 @@
},
"devDependencies": {
"@commitlint/config-conventional": "^17.0.2",
"@evilmartians/lefthook": "^1.2.2",
"@react-native-community/eslint-config": "^3.0.2",
"@release-it/conventional-changelog": "^5.0.0",
"@types/jest": "^29.4.0",
Expand Down
30 changes: 10 additions & 20 deletions yarn.lock
Original file line number Diff line number Diff line change
Expand Up @@ -4261,16 +4261,6 @@ __metadata:
languageName: node
linkType: hard

"@evilmartians/lefthook@npm:^1.2.2":
version: 1.3.12
resolution: "@evilmartians/lefthook@npm:1.3.12"
bin:
lefthook: bin/index.js
checksum: 12982387edf7a92fa59dbfc9863044ef3e6eb6c8513297b136c9500c3bc5cea0b1a2559232f7b19a4315320ff9e4c70aae6ee625b815604d37e2248b4c65d843
conditions: (os=darwin | os=linux | os=win32) & (cpu=x64 | cpu=arm64 | cpu=ia32)
languageName: node
linkType: hard

"@expo/bunyan@npm:^4.0.0":
version: 4.0.0
resolution: "@expo/bunyan@npm:4.0.0"
Expand Down Expand Up @@ -10575,7 +10565,7 @@ __metadata:
"@vexl-next/server-utils": 0.0.0
"@vexl-next/tsconfig": 0.0.0
axios: ^1.6.0
dotenv: ^16.0.3
dotenv: ^16.4.5
dynamic-import-polyfill: ^0.1.1
effect: ^3.0.1
esbuild: ^0.17.16
Expand Down Expand Up @@ -10763,6 +10753,7 @@ __metadata:
"@vexl-next/rest-api": 0.0.0
"@vexl-next/server-utils": 0.0.0
"@vexl-next/tsconfig": 0.0.0
dotenv: ^16.4.5
effect: ^3.0.1
esbuild: ^0.17.16
eslint: ^8.50.0
Expand All @@ -10789,7 +10780,6 @@ __metadata:
resolution: "@vexl-next/react-native-ecdh-platform-native-utils@workspace:packages/ecdh-platform-native-utils"
dependencies:
"@commitlint/config-conventional": ^17.0.2
"@evilmartians/lefthook": ^1.2.2
"@react-native-community/eslint-config": ^3.0.2
"@release-it/conventional-changelog": ^5.0.0
"@types/jest": ^29.4.0
Expand Down Expand Up @@ -14626,27 +14616,27 @@ __metadata:
languageName: node
linkType: hard

"dotenv@npm:^16.0.0":
"dotenv@npm:^16.0.0, dotenv@npm:^16.4.5":
version: 16.4.5
resolution: "dotenv@npm:16.4.5"
checksum: 301a12c3d44fd49888b74eb9ccf9f07a1f5df43f489e7fcb89647a2edcd84c42d6bc349dc8df099cd18f07c35c7b04685c1a4f3e6a6a9e6b30f8d48c15b7f49c
languageName: node
linkType: hard

"dotenv@npm:^16.0.3, dotenv@npm:~16.0.3":
version: 16.0.3
resolution: "dotenv@npm:16.0.3"
checksum: afcf03f373d7a6d62c7e9afea6328e62851d627a4e73f2e12d0a8deae1cd375892004f3021883f8aec85932cd2834b091f568ced92b4774625b321db83b827f8
languageName: node
linkType: hard

"dotenv@npm:^16.3.1":
version: 16.3.1
resolution: "dotenv@npm:16.3.1"
checksum: 15d75e7279018f4bafd0ee9706593dd14455ddb71b3bcba9c52574460b7ccaf67d5cf8b2c08a5af1a9da6db36c956a04a1192b101ee102a3e0cf8817bbcf3dfd
languageName: node
linkType: hard

"dotenv@npm:~16.0.3":
version: 16.0.3
resolution: "dotenv@npm:16.0.3"
checksum: afcf03f373d7a6d62c7e9afea6328e62851d627a4e73f2e12d0a8deae1cd375892004f3021883f8aec85932cd2834b091f568ced92b4774625b321db83b827f8
languageName: node
linkType: hard

"duplexer3@npm:^0.1.4":
version: 0.1.5
resolution: "duplexer3@npm:0.1.5"
Expand Down

0 comments on commit a32dbee

Please sign in to comment.