Repository navigation
Develop #154
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Merged
Develop #154
Changes from all commits
Commits
Show all changes
3 commits
Select commit
Hold shift + click to select a range
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,7 @@ | ||
| { | ||
| "webcredentials": { | ||
| "apps": [ | ||
| "QKQVAJMTCN.com.wavetech.Resgrid" | ||
| ] | ||
| } | ||
| } |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,14 @@ | ||
| [ | ||
| { | ||
| "relation": [ | ||
| "delegate_permission/common.get_login_creds" | ||
| ], | ||
| "target": { | ||
| "namespace": "android_app", | ||
| "package_name": "wtdt.resgrid.andriod", | ||
| "sha256_cert_fingerprints": [ | ||
| "FF:56:FC:B4:6B:4F:07:41:20:92:00:08:AA:D0:46:E3:C8:7A:B8:95:F1:CF:A6:68:46:F0:D2:55:42:1C:77:2D" | ||
| ] | ||
| } | ||
| } | ||
| ] |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,113 @@ | ||
| /* eslint-disable no-undef */ | ||
| /** | ||
| * Service worker for Resgrid Responder web push. | ||
| * | ||
| * The page mints its FCM web token against this registration (services/web-push.web.ts), but | ||
| * Firebase is not loaded here: every push is shown below. Core sends the fields in the FCM webpush | ||
| * block (NovuProvider.SendNotification): data carries title, message, eventCode, type and category. | ||
| * | ||
| * The app does the routing. A click focuses an open window and posts NOTIFICATION_CLICK to it; with no | ||
| * window open, the new one is handed the push after it says CLIENT_READY. Every push is also posted as | ||
| * PUSH_RECEIVED so a window the person is looking at can show its in-app alert. | ||
| */ | ||
|
|
||
| const DEFAULT_TITLE = 'Resgrid'; | ||
|
|
||
| // Clicks waiting for the window they opened to finish loading, by client id. | ||
| const pendingClicks = new Map(); | ||
|
|
||
| function readPush(event) { | ||
| let payload = {}; | ||
| if (event.data) { | ||
| try { | ||
| payload = event.data.json() || {}; | ||
| } catch { | ||
| payload = { notification: { body: event.data.text() } }; | ||
| } | ||
| } | ||
|
|
||
| const notification = payload.notification || {}; | ||
| const data = payload.data || {}; | ||
|
|
||
| return { | ||
| title: data.title || notification.title || payload.title || DEFAULT_TITLE, | ||
| body: data.message || notification.body || data.body || payload.body || payload.message || '', | ||
| eventCode: data.eventCode || payload.eventCode || '', | ||
| type: data.type || '', | ||
| category: data.category || '', | ||
| }; | ||
| } | ||
|
|
||
| function isCall(push) { | ||
| return push.category === 'calls' || /^c(?!t)/i.test(push.eventCode); | ||
| } | ||
|
|
||
| self.addEventListener('push', (event) => { | ||
| const push = readPush(event); | ||
|
|
||
| event.waitUntil( | ||
| Promise.all([ | ||
| self.registration.showNotification(push.title, { | ||
| body: push.body, | ||
| icon: '/favicon.ico', | ||
| tag: push.eventCode || undefined, | ||
| renotify: !!push.eventCode, | ||
| requireInteraction: isCall(push), | ||
| data: push, | ||
| }), | ||
| self.clients.matchAll({ type: 'window', includeUncontrolled: true }).then((windows) => { | ||
| windows.forEach((client) => client.postMessage({ type: 'PUSH_RECEIVED', data: push })); | ||
| }), | ||
| ]) | ||
| ); | ||
| }); | ||
|
|
||
| self.addEventListener('notificationclick', (event) => { | ||
| event.notification.close(); | ||
| const data = event.notification.data || {}; | ||
|
|
||
| event.waitUntil( | ||
| self.clients.matchAll({ type: 'window', includeUncontrolled: true }).then((windows) => { | ||
| const client = windows.find((candidate) => 'focus' in candidate); | ||
| if (client) { | ||
| return client.focus().then((focused) => (focused || client).postMessage({ type: 'NOTIFICATION_CLICK', data })); | ||
| } | ||
|
|
||
| if (!self.clients.openWindow) { | ||
| return undefined; | ||
| } | ||
|
|
||
| return self.clients.openWindow('/').then((opened) => { | ||
| if (opened) { | ||
| pendingClicks.set(opened.id, data); | ||
| } | ||
| }); | ||
| }) | ||
| ); | ||
| }); | ||
|
|
||
| self.addEventListener('install', () => { | ||
| self.skipWaiting(); | ||
| }); | ||
|
|
||
| self.addEventListener('activate', (event) => { | ||
| event.waitUntil(self.clients.claim()); | ||
| }); | ||
|
|
||
| self.addEventListener('message', (event) => { | ||
| if (!event.data || !event.source) { | ||
| return; | ||
| } | ||
|
|
||
| if (event.data.type === 'SKIP_WAITING') { | ||
| self.skipWaiting(); | ||
| return; | ||
| } | ||
|
|
||
| // A window this worker opened has loaded: hand it the click that opened it. | ||
| if (event.data.type === 'CLIENT_READY' && pendingClicks.has(event.source.id)) { | ||
| const data = pendingClicks.get(event.source.id); | ||
| pendingClicks.delete(event.source.id); | ||
| event.source.postMessage({ type: 'NOTIFICATION_CLICK', data }); | ||
| } | ||
| }); |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,42 @@ | ||
| import { createApiEndpoint } from '../../common/client'; | ||
| import { getCallLocationHistory } from '../callLocationHistory'; | ||
|
|
||
| jest.mock('../../common/client', () => { | ||
| const get = jest.fn(); | ||
| return { | ||
| createApiEndpoint: jest.fn(() => ({ get })), | ||
| __mockGet: get, | ||
| }; | ||
| }); | ||
|
|
||
| const { __mockGet: mockGet } = jest.requireMock('../../common/client') as { __mockGet: jest.Mock }; | ||
|
|
||
| // Endpoints are created at module load; capture them before beforeEach clears the mock. | ||
| const registeredPaths = (createApiEndpoint as jest.Mock).mock.calls.map((c) => c[0]); | ||
|
|
||
| describe('callLocationHistory api', () => { | ||
| beforeEach(() => { | ||
| jest.clearAllMocks(); | ||
| }); | ||
|
|
||
| it('targets Calls/GetCallLocationHistory', () => { | ||
| expect(registeredPaths).toEqual(['/Calls/GetCallLocationHistory']); | ||
| }); | ||
|
|
||
| it('passes callId as a query parameter and returns the body', async () => { | ||
| const payload = { Data: { AddressMatchingAvailable: true, IndexComplete: true, HasMore: false, IsProtected: false, Calls: [] } }; | ||
| mockGet.mockResolvedValueOnce({ data: payload }); | ||
|
|
||
| await expect(getCallLocationHistory('42')).resolves.toBe(payload); | ||
| expect(mockGet).toHaveBeenCalledWith({ callId: '42' }, undefined); | ||
| }); | ||
|
|
||
| it('forwards the abort signal', async () => { | ||
| const controller = new AbortController(); | ||
| mockGet.mockResolvedValueOnce({ data: { Data: null } }); | ||
|
|
||
| await getCallLocationHistory('42', controller.signal); | ||
|
|
||
| expect(mockGet).toHaveBeenCalledWith({ callId: '42' }, controller.signal); | ||
| }); | ||
| }); |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,15 @@ | ||
| import { type LocationHistoryResult } from '@/models/v4/calls/locationHistoryResult'; | ||
|
|
||
| import { createApiEndpoint } from '../common/client'; | ||
|
|
||
| // v4 Calls/GetCallLocationHistory: other calls at this call's location (address however it was typed, or nearby when one | ||
| // side has no street address) and calls linked to the same contacts, newest first with their notes. Needs Call_View and is | ||
| // limited to the calls the user may see. The client attaches the Protected Data Grant header automatically; without one, | ||
| // a protected department's call text and notes come back REDACTED. | ||
|
|
||
| const getCallLocationHistoryApi = createApiEndpoint('/Calls/GetCallLocationHistory'); | ||
|
|
||
| export const getCallLocationHistory = async (callId: string, signal?: AbortSignal) => { | ||
| const response = await getCallLocationHistoryApi.get<LocationHistoryResult>({ callId }, signal); | ||
| return response.data; | ||
| }; |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,33 @@ | ||
| import { createApiEndpoint } from '../../common/client'; | ||
| import { getContactCallHistory } from '../contactCallHistory'; | ||
|
|
||
| jest.mock('../../common/client', () => { | ||
| const get = jest.fn(); | ||
| return { | ||
| createApiEndpoint: jest.fn(() => ({ get })), | ||
| __mockGet: get, | ||
| }; | ||
| }); | ||
|
|
||
| const { __mockGet: mockGet } = jest.requireMock('../../common/client') as { __mockGet: jest.Mock }; | ||
|
|
||
| // Endpoints are created at module load; capture them before beforeEach clears the mock. | ||
| const registeredPaths = (createApiEndpoint as jest.Mock).mock.calls.map((c) => c[0]); | ||
|
|
||
| describe('contactCallHistory api', () => { | ||
| beforeEach(() => { | ||
| jest.clearAllMocks(); | ||
| }); | ||
|
|
||
| it('targets Contacts/GetContactCallHistory', () => { | ||
| expect(registeredPaths).toEqual(['/Contacts/GetContactCallHistory']); | ||
| }); | ||
|
|
||
| it('passes contactId as a query parameter and returns the body', async () => { | ||
| const payload = { Data: { AddressMatchingAvailable: true, IndexComplete: true, HasMore: false, IsProtected: false, Calls: [] } }; | ||
| mockGet.mockResolvedValueOnce({ data: payload }); | ||
|
|
||
| await expect(getContactCallHistory('c1')).resolves.toBe(payload); | ||
| expect(mockGet).toHaveBeenCalledWith({ contactId: 'c1' }, undefined); | ||
| }); | ||
| }); |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,14 @@ | ||
| import { type LocationHistoryResult } from '@/models/v4/calls/locationHistoryResult'; | ||
|
|
||
| import { createApiEndpoint } from '../common/client'; | ||
|
|
||
| // v4 Contacts/GetContactCallHistory: calls linked to a contact plus calls at every occupancy it is linked to (one contact can | ||
| // have several, such as a business with more than one location), newest first with their notes. Needs Contacts_View and is | ||
| // limited to the calls the user may see. | ||
|
|
||
| const getContactCallHistoryApi = createApiEndpoint('/Contacts/GetContactCallHistory'); | ||
|
|
||
| export const getContactCallHistory = async (contactId: string, signal?: AbortSignal) => { | ||
| const response = await getContactCallHistoryApi.get<LocationHistoryResult>({ contactId }, signal); | ||
| return response.data; | ||
| }; | ||
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Unhandled external API failures from
getContactCallHistoryApi.getomit thecontactIdcontext insrc/api/contacts/contactCallHistory.ts; wrap the call intry/catchand map or rethrow the error with that identifier. Apply the same handling insrc/api/calls/callLocationHistory.ts:13-13,src/api/devices/push.ts:27-27, andsrc/services/__tests__/service-worker.test.ts:12-12.Kody rule violation: Add try-catch blocks for external calls
Prompt for LLM
Talk to Kody by mentioning @kody
Was this suggestion helpful? React with 👍 or 👎 to help Kody learn from this interaction.