-
Notifications
You must be signed in to change notification settings - Fork 1
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat: Implement FlagshipLinkRequest interface through localMethods
In previous commits we configured the application's cozy-client to use CozyPouchLink This link is configured for all react-native side queries, but not for cozy-app queries as they are served inside of WebViews and use a different cozy-client instance We want cozy-apps to benefits from the CozyPouchLink by redirecting their queries to the react-native side using the new FlagshipLink interface With this interface, all cozy-apps queries can be redirected to the react-native side using cozy-intent/post-me In order to intercept them, then we should declare `FlagshipLinkRequest()` method `localMethods` Related PR: cozy/cozy-client#1505
- Loading branch information
Showing
3 changed files
with
48 additions
and
2 deletions.
There are no files selected for viewing
This file contains 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 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 CozyClient, { QueryDefinition } from 'cozy-client' | ||
import type { QueryResult } from 'cozy-client/types/types' | ||
import Minilog from 'cozy-minilog' | ||
|
||
import { getErrorMessage } from '/libs/functions/getErrorMessage' | ||
|
||
const log = Minilog('⛳🔗 flagshipLink') | ||
|
||
export const flagshipLinkRequest = async ( | ||
operation: QueryDefinition, | ||
client: CozyClient | undefined | ||
): Promise<QueryResult> => { | ||
try { | ||
if (!client) { | ||
throw new Error( | ||
'FlagshipLinkRequest should not be called with undefined client' | ||
) | ||
} | ||
|
||
// eslint-disable-next-line @typescript-eslint/no-unsafe-assignment | ||
const result = await client.query(operation) | ||
|
||
// eslint-disable-next-line @typescript-eslint/no-unsafe-return | ||
return result | ||
} catch (error) { | ||
const errorMessage = getErrorMessage(error) | ||
log.error( | ||
`Something when wrong while processing FlagshipLinkRequest: ${errorMessage}`, | ||
operation | ||
) | ||
throw error | ||
} | ||
} |
This file contains 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