Skip to content
Permalink

Comparing changes

Choose two branches to see what’s changed or to start a new pull request. If you need to, you can also or learn more about diff comparisons.

Open a pull request

Create a new pull request by comparing changes across two branches. If you need to, you can also . Learn more about diff comparisons here.
base repository: cozy/cozy-libs
Failed to load repositories. Confirm that selected base ref is valid, then try again.
Loading
base: cozy-intent@1.16.1
Choose a base ref
...
head repository: cozy/cozy-libs
Failed to load repositories. Confirm that selected head ref is valid, then try again.
Loading
compare: cozy-intent@1.17.1
Choose a head ref

Commits on Apr 25, 2022

  1. refactor: Normalize the usage of icons

    The app needs to use the `Sprite` component,
    due to the dynamic loading of some icons,
    it should not import icons (via JS)
    
    The `Sprite` component injects all icons into the html,
    importing icons into JS duplicates those icons.
    Merkur39 committed Apr 25, 2022
    Copy the full SHA
    9761d40 View commit details
  2. Copy the full SHA
    5247d41 View commit details
  3. [skip ci] Publish

     - cozy-mespapiers-lib@0.5.14
    Cozy Bot committed Apr 25, 2022
    Copy the full SHA
    17a5d2c View commit details
  4. feat: Add prop to config for redirect to Store

    Add a property in the configuration file
    to be redirected to the Store pre-filtered on taxes
    Merkur39 committed Apr 25, 2022
    Copy the full SHA
    b7e6aaa View commit details
  5. [skip ci] Publish

     - cozy-mespapiers-lib@0.6.0
    Cozy Bot committed Apr 25, 2022
    Copy the full SHA
    7ad3d10 View commit details

Commits on Apr 26, 2022

  1. feat: Rework error handling flow

    - This will handle scenarios that were unknown to this day (url casing)
    - Updated tests
    - Updated typings
    - Replaced throw statements with debug statements
    - Added more typeguards
    - Removed unused strings
    acezard authored and trollepierre committed Apr 26, 2022
    Copy the full SHA
    ad860bd View commit details
  2. chore(deps): Bump tmpl from 1.0.4 to 1.0.5

    Bumps [tmpl](https://github.com/daaku/nodejs-tmpl) from 1.0.4 to 1.0.5.
    - [Release notes](https://github.com/daaku/nodejs-tmpl/releases)
    - [Commits](https://github.com/daaku/nodejs-tmpl/commits/v1.0.5)
    
    ---
    updated-dependencies:
    - dependency-name: tmpl
      dependency-type: indirect
    ...
    
    Signed-off-by: dependabot[bot] <support@github.com>
    dependabot[bot] authored and trollepierre committed Apr 26, 2022
    Copy the full SHA
    89b4ce0 View commit details
  3. chore(deps): Bump y18n from 3.2.1 to 3.2.2

    Bumps [y18n](https://github.com/yargs/y18n) from 3.2.1 to 3.2.2.
    - [Release notes](https://github.com/yargs/y18n/releases)
    - [Changelog](https://github.com/yargs/y18n/blob/master/CHANGELOG.md)
    - [Commits](https://github.com/yargs/y18n/commits)
    
    Signed-off-by: dependabot[bot] <support@github.com>
    dependabot[bot] authored and trollepierre committed Apr 26, 2022
    Copy the full SHA
    f1c79e5 View commit details
  4. [skip ci] Publish

     - cozy-intent@1.17.0
     - cozy-mespapiers-lib@0.6.1
    Cozy Bot committed Apr 26, 2022
    Copy the full SHA
    8d6102a View commit details
  5. chore(deps): bump lodash-es in /packages/cozy-realtime/examples/chat

    Bumps [lodash-es](https://github.com/lodash/lodash) from 4.17.15 to 4.17.21.
    - [Release notes](https://github.com/lodash/lodash/releases)
    - [Commits](lodash/lodash@4.17.15...4.17.21)
    
    ---
    updated-dependencies:
    - dependency-name: lodash-es
      dependency-type: indirect
    ...
    
    Signed-off-by: dependabot[bot] <support@github.com>
    dependabot[bot] authored and trollepierre committed Apr 26, 2022
    Copy the full SHA
    538a25e View commit details
  6. Copy the full SHA
    779af97 View commit details
  7. [skip ci] Publish

     - cozy-harvest-lib@8.4.2
     - cozy-mespapiers-lib@0.6.2
     - cozy-realtime@4.0.7
     - cozy-playgrounds@1.18.63
    Cozy Bot committed Apr 26, 2022
    Copy the full SHA
    b60562a View commit details
  8. feat: Hide useless featured placeholders

    The featured placeholders must have the property "placeholderIndex"
    in addition to "acquisitionSteps" or "connectorCriteria" to be displayed
    Merkur39 committed Apr 26, 2022
    Copy the full SHA
    eb16941 View commit details
  9. fix: Disable Placeholder correctly in list

    Refactor for more clarity
    Merkur39 committed Apr 26, 2022
    Copy the full SHA
    fa1d324 View commit details
  10. chore: Remove useless key in PapersDefinitions

    Only the keys `category` & `name`
    currently exist in the `connectorCriteria` object
    Merkur39 committed Apr 26, 2022
    Copy the full SHA
    afb6a43 View commit details
  11. Copy the full SHA
    510f151 View commit details
  12. feat: Bypass choices before paper creation

    In case there is no possibility to go through a connector,
    we want to bypass the ActionMenu and go directly to the creation modal
    Merkur39 committed Apr 26, 2022
    Copy the full SHA
    59e7815 View commit details
  13. refactor: Remove useless code

    Now, as we don't display this component
    when there is no choice of connector,
    the conditions on the presence or not
    of the latter are no longer relevant
    Merkur39 committed Apr 26, 2022
    Copy the full SHA
    17310ca View commit details
  14. feat: On mobile, add download action in paper line option

    In the options (...) of each line of Paper,
    on mobile, we want to add the Download action
    Merkur39 committed Apr 26, 2022
    Copy the full SHA
    6023cb0 View commit details
  15. [skip ci] Publish

     - cozy-mespapiers-lib@0.7.0
    Cozy Bot committed Apr 26, 2022
    Copy the full SHA
    a7e7eba View commit details
  16. fix: Next button position on contact and information paper creation step

    Use same approach than AcquisitionResult
    JF-Cozy committed Apr 26, 2022
    Copy the full SHA
    b340dd5 View commit details
  17. [skip ci] Publish

     - cozy-mespapiers-lib@0.7.1
    Cozy Bot committed Apr 26, 2022
    Copy the full SHA
    07f1624 View commit details
  18. feat: Update cozy-client and cozy-ui libs

    BREAKING CHANGE: The following packages
    must be installed on the applications:
    ```
      "cozy-ui": ">=64.0.0",
      "cozy-client": ">=28.2.1"
    ```
    Merkur39 committed Apr 26, 2022
    Copy the full SHA
    f929d97 View commit details
  19. feat: Move all cozy packages to devDeps & peerDeps

    BREAKING CHANGE: The following packages
    must be installed on the applications:
    ```
      "cozy-device-helper": ">=1.18.0",
      "cozy-doctypes": ">=1.83.3",
      "cozy-harvest-lib": ">=8.4.2",
      "cozy-sharing": ">=4.1.6"
    ```
    Merkur39 committed Apr 26, 2022
    Copy the full SHA
    8f37e7e View commit details
  20. [skip ci] Publish

     - cozy-mespapiers-lib@0.8.0
    Cozy Bot committed Apr 26, 2022
    Copy the full SHA
    7c3e970 View commit details

Commits on Apr 27, 2022

  1. feat: Update cozy-ui package

    To get the fix on the Forward button on the Viewer
    Merkur39 committed Apr 27, 2022
    Copy the full SHA
    21f0008 View commit details
  2. [skip ci] Publish

     - cozy-mespapiers-lib@0.9.0
    Cozy Bot committed Apr 27, 2022
    Copy the full SHA
    52b6604 View commit details
  3. Copy the full SHA
    e84f24e View commit details

Commits on Apr 28, 2022

  1. fix: FlagshipMetadata is now a getter

    BREAKING CHANGE: flagshipMetadata reference has been replaced with
    getFlagshipMetadata().
    It returns the same information but adds safety at file init
    acezard committed Apr 28, 2022
    Copy the full SHA
    11948ad View commit details
  2. [skip ci] Publish

     - cozy-authentication@2.8.5
     - cozy-device-helper@2.0.0
     - cozy-harvest-lib@8.4.3
     - cozy-intent@1.17.1
     - cozy-mespapiers-lib@0.9.1
     - cozy-realtime@4.0.8
     - cozy-scanner@2.1.4
     - cozy-sharing@4.1.7
     - cozy-playgrounds@1.18.64
    Cozy Bot committed Apr 28, 2022
    Copy the full SHA
    cf4a264 View commit details
Showing with 1,036 additions and 449 deletions.
  1. +16 −0 CODEOWNERS
  2. +8 −0 packages/cozy-authentication/CHANGELOG.md
  3. +2 −2 packages/cozy-authentication/package.json
  4. +18 −0 packages/cozy-device-helper/CHANGELOG.md
  5. +1 −1 packages/cozy-device-helper/package.json
  6. +2 −1 packages/cozy-device-helper/src/flagship.ts
  7. +1 −1 packages/cozy-device-helper/src/index.ts
  8. +19 −0 packages/cozy-harvest-lib/CHANGELOG.md
  9. +4 −4 packages/cozy-harvest-lib/package.json
  10. +19 −0 packages/cozy-intent/CHANGELOG.md
  11. +2 −2 packages/cozy-intent/package.json
  12. +3 −9 packages/cozy-intent/src/api/constants/strings.ts
  13. +3 −1 packages/cozy-intent/src/api/models/messengers.ts
  14. +18 −4 packages/cozy-intent/src/api/services/NativeMessenger.spec.ts
  15. +3 −3 packages/cozy-intent/src/api/services/NativeMessenger.ts
  16. +48 −26 packages/cozy-intent/src/api/services/NativeService.spec.ts
  17. +31 −14 packages/cozy-intent/src/api/services/NativeService.ts
  18. +5 −0 packages/cozy-intent/src/utils/index.ts
  19. +0 −1 packages/cozy-intent/src/view/components/WebviewIntentProvider.tsx
  20. +1 −7 packages/cozy-intent/src/view/hooks/useNativeIntent.spec.tsx
  21. +3 −8 packages/cozy-intent/src/view/hooks/useNativeIntent.ts
  22. +113 −0 packages/cozy-mespapiers-lib/CHANGELOG.md
  23. +15 −11 packages/cozy-mespapiers-lib/package.json
  24. +5 −10 packages/cozy-mespapiers-lib/src/components/Actions/Actions.jsx
  25. +5 −0 packages/cozy-mespapiers-lib/src/components/Actions/utils.js
  26. +18 −0 packages/cozy-mespapiers-lib/src/components/Actions/utils.spec.js
  27. +8 −33 packages/cozy-mespapiers-lib/src/components/ImportDropdown/ImportDropdown.jsx
  28. +1 −2 packages/cozy-mespapiers-lib/src/components/ImportDropdown/ImportDropdown.spec.jsx
  29. +3 −6 packages/cozy-mespapiers-lib/src/components/ModelSteps/AcquisitionResult.jsx
  30. +12 −4 packages/cozy-mespapiers-lib/src/components/ModelSteps/Contact.jsx
  31. +9 −1 packages/cozy-mespapiers-lib/src/components/ModelSteps/Information.jsx
  32. +2 −4 packages/cozy-mespapiers-lib/src/components/ModelSteps/ScanDesktopActions.jsx
  33. +3 −6 packages/cozy-mespapiers-lib/src/components/ModelSteps/ScanMobileActions.jsx
  34. +2 −4 packages/cozy-mespapiers-lib/src/components/Papers/PaperGroup.jsx
  35. +3 −6 packages/cozy-mespapiers-lib/src/components/Papers/PaperLine.jsx
  36. +4 −10 packages/cozy-mespapiers-lib/src/components/Papers/PapersList.jsx
  37. +1 −2 packages/cozy-mespapiers-lib/src/components/Papers/PapersListWrapper.jsx
  38. +1 −2 packages/cozy-mespapiers-lib/src/components/PapersFab/PapersFab.jsx
  39. +21 −14 packages/cozy-mespapiers-lib/src/components/Placeholders/FeaturedPlaceholdersList.jsx
  40. +60 −48 packages/cozy-mespapiers-lib/src/components/Placeholders/FeaturedPlaceholdersList.spec.jsx
  41. +8 −5 packages/cozy-mespapiers-lib/src/components/Placeholders/Placeholder.jsx
  42. +68 −22 packages/cozy-mespapiers-lib/src/components/Placeholders/Placeholder.spec.jsx
  43. +2 −4 packages/cozy-mespapiers-lib/src/components/Placeholders/PlaceholderThemesList.jsx
  44. +24 −24 packages/cozy-mespapiers-lib/src/components/Placeholders/PlaceholdersList.jsx
  45. +30 −9 packages/cozy-mespapiers-lib/src/components/Placeholders/PlaceholdersList.spec.jsx
  46. +5 −5 packages/cozy-mespapiers-lib/src/constants/papersDefinitions.json
  47. +0 −7 packages/cozy-mespapiers-lib/src/helpers/findIconByLabel.js
  48. +0 −17 packages/cozy-mespapiers-lib/src/helpers/findIconByLabel.spec.js
  49. +15 −10 packages/cozy-mespapiers-lib/src/helpers/findPlaceholders.js
  50. +36 −16 packages/cozy-mespapiers-lib/src/helpers/findPlaceholders.spec.js
  51. +94 −0 packages/cozy-mespapiers-lib/test/mockPaperDefinitions.js
  52. +16 −0 packages/cozy-realtime/CHANGELOG.md
  53. +142 −47 packages/cozy-realtime/examples/chat/yarn.lock
  54. +2 −2 packages/cozy-realtime/package.json
  55. +8 −0 packages/cozy-scanner/CHANGELOG.md
  56. +2 −2 packages/cozy-scanner/package.json
  57. +8 −0 packages/cozy-sharing/CHANGELOG.md
  58. +2 −2 packages/cozy-sharing/package.json
  59. +16 −0 packages/playgrounds/CHANGELOG.md
  60. +5 −5 packages/playgrounds/package.json
  61. +60 −25 yarn.lock
16 changes: 16 additions & 0 deletions CODEOWNERS
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
# General code owners
* @trollepierre @acezard

# Based on the Paper of the Technical maintainers of 2022
packages/cozy-harvest-lib @doubleface @trollepierre
packages/cozy-doctypes/ @doubleface @trollepierre
packages/cozy-flags/ @acezard @trollepierre @Ldoppea
packages/cozy-app-publish/ @acezard @doubleface @trollepierre @sblaisot
packages/cozy-interapp/ @Ldoppea @acezard @trollepierre
packages/cozy-intent/ @Ldoppea @acezard
packages/cozy-realtime/ @Ldoppea @trollepierre
packages/eslint-config-cozy-app/ @acezard @trollepierre
packages/renovate-config-cozy/ @doubleface @trollepierre
packages/renovate-config-cozy-libs/ @doubleface @trollepierre
packages/cozy-sharing/ @Ldoppea @acezard @trollepierre
packages/cozy-mespapiers-lib/ @Merkur39 @JF-Cozy
8 changes: 8 additions & 0 deletions packages/cozy-authentication/CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -3,6 +3,14 @@
All notable changes to this project will be documented in this file.
See [Conventional Commits](https://conventionalcommits.org) for commit guidelines.

## [2.8.5](https://github.com/cozy/cozy-libs/compare/cozy-authentication@2.8.4...cozy-authentication@2.8.5) (2022-04-28)

**Note:** Version bump only for package cozy-authentication





## [2.8.4](https://github.com/cozy/cozy-libs/compare/cozy-authentication@2.8.3...cozy-authentication@2.8.4) (2022-04-25)

**Note:** Version bump only for package cozy-authentication
4 changes: 2 additions & 2 deletions packages/cozy-authentication/package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "cozy-authentication",
"version": "2.8.4",
"version": "2.8.5",
"description": "Component providing login to a Cozy",
"main": "dist/index.js",
"files": [
@@ -38,7 +38,7 @@
"react-router": "6.3.0"
},
"dependencies": {
"cozy-device-helper": "^1.18.0",
"cozy-device-helper": "^2.0.0",
"localforage": "1.7.3",
"prop-types": "15.7.2",
"snarkdown": "1.2.2",
18 changes: 18 additions & 0 deletions packages/cozy-device-helper/CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -3,6 +3,24 @@
All notable changes to this project will be documented in this file.
See [Conventional Commits](https://conventionalcommits.org) for commit guidelines.

# [2.0.0](https://github.com/cozy/cozy-libs/compare/cozy-device-helper@1.18.0...cozy-device-helper@2.0.0) (2022-04-28)


### Bug Fixes

* FlagshipMetadata is now a getter ([11948ad](https://github.com/cozy/cozy-libs/commit/11948ad9b554996800c6b8d08cf0f30e43043084))


### BREAKING CHANGES

* flagshipMetadata reference has been replaced with
getFlagshipMetadata().
It returns the same information but adds safety at file init





# 1.18.0 (2022-04-25)


2 changes: 1 addition & 1 deletion packages/cozy-device-helper/package.json
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
{
"name": "cozy-device-helper",
"description": "To know more information about the device platform",
"version": "1.18.0",
"version": "2.0.0",
"author": "Cozy",
"bugs": {
"url": "https://github.com/cozy/cozy-libs/issues"
3 changes: 2 additions & 1 deletion packages/cozy-device-helper/src/flagship.ts
Original file line number Diff line number Diff line change
@@ -17,6 +17,7 @@ export interface FlagshipMetadata {
version?: string
}

export const flagshipMetadata = window.cozy?.flagship || {}
export const getFlagshipMetadata = (): FlagshipMetadata =>
window.cozy?.flagship || {}

export const isFlagshipApp = (): boolean => window.cozy?.flagship !== undefined
2 changes: 1 addition & 1 deletion packages/cozy-device-helper/src/index.ts
Original file line number Diff line number Diff line change
@@ -21,4 +21,4 @@ export { isCordova } from './cordova'
export { nativeLinkOpen } from './link'
export { openDeeplinkOrRedirect } from './deeplink'

export { isFlagshipApp, flagshipMetadata } from './flagship'
export { isFlagshipApp, getFlagshipMetadata } from './flagship'
19 changes: 19 additions & 0 deletions packages/cozy-harvest-lib/CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -3,6 +3,25 @@
All notable changes to this project will be documented in this file.
See [Conventional Commits](https://conventionalcommits.org) for commit guidelines.

## [8.4.3](https://github.com/cozy/cozy-libs/compare/cozy-harvest-lib@8.4.2...cozy-harvest-lib@8.4.3) (2022-04-28)

**Note:** Version bump only for package cozy-harvest-lib





## [8.4.2](https://github.com/cozy/cozy-libs/compare/cozy-harvest-lib@8.4.1...cozy-harvest-lib@8.4.2) (2022-04-26)


### Bug Fixes

* **deps:** update dependency @testing-library/jest-dom to v5.16.4 ([779af97](https://github.com/cozy/cozy-libs/commit/779af972e7821ae0043215f0f6f24b4823ca087b))





## [8.4.1](https://github.com/cozy/cozy-libs/compare/cozy-harvest-lib@8.4.0...cozy-harvest-lib@8.4.1) (2022-04-25)

**Note:** Version bump only for package cozy-harvest-lib
8 changes: 4 additions & 4 deletions packages/cozy-harvest-lib/package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "cozy-harvest-lib",
"version": "8.4.1",
"version": "8.4.3",
"description": "Provides logic, modules and components for Cozy's harvest applications.",
"main": "dist/index.js",
"author": "Cozy",
@@ -47,16 +47,16 @@
"@cozy/cli-tree": "^0.5.0",
"@material-ui/core": "4.11.3",
"@material-ui/lab": "4.0.0-alpha.60",
"@testing-library/jest-dom": "5.16.2",
"@testing-library/jest-dom": "5.16.4",
"@testing-library/react": "10.4.9",
"babel-jest": "26.6.3",
"babel-plugin-inline-react-svg": "1.1.2",
"babel-preset-cozy-app": "^2.0.2",
"cozy-client": "27.17.0",
"cozy-device-helper": "^1.18.0",
"cozy-device-helper": "^2.0.0",
"cozy-flags": "^2.8.7",
"cozy-keys-lib": "3.8.0",
"cozy-realtime": "^4.0.6",
"cozy-realtime": "^4.0.8",
"cozy-ui": "60.6.0",
"enzyme": "3.11.0",
"enzyme-adapter-react-16": "1.15.6",
19 changes: 19 additions & 0 deletions packages/cozy-intent/CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -3,6 +3,25 @@
All notable changes to this project will be documented in this file.
See [Conventional Commits](https://conventionalcommits.org) for commit guidelines.

## [1.17.1](https://github.com/cozy/cozy-libs/compare/cozy-intent@1.17.0...cozy-intent@1.17.1) (2022-04-28)

**Note:** Version bump only for package cozy-intent





# [1.17.0](https://github.com/cozy/cozy-libs/compare/cozy-intent@1.16.1...cozy-intent@1.17.0) (2022-04-26)


### Features

* Rework error handling flow ([ad860bd](https://github.com/cozy/cozy-libs/commit/ad860bd5ee57ba686a865b6e4973c48685fc849c))





## [1.16.1](https://github.com/cozy/cozy-libs/compare/cozy-intent@1.16.0...cozy-intent@1.16.1) (2022-04-25)

**Note:** Version bump only for package cozy-intent
4 changes: 2 additions & 2 deletions packages/cozy-intent/package.json
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
{
"name": "cozy-intent",
"description": "Event-based library allowing interactions between React-Native and React applications",
"version": "1.16.1",
"version": "1.17.1",
"author": {
"name": "Cozy Cloud",
"url": "https://github.com/cozy"
@@ -17,7 +17,7 @@
"@testing-library/react": "10.4.9",
"@testing-library/react-hooks": "7.0.2",
"babel-preset-cozy-app": "^2.0.2",
"cozy-device-helper": "^1.18.0",
"cozy-device-helper": "^2.0.0",
"cozy-logger": "^1.9.0",
"jest": "26.6.3",
"mutationobserver-shim": "0.3.7",
12 changes: 3 additions & 9 deletions packages/cozy-intent/src/api/constants/strings.ts
Original file line number Diff line number Diff line change
@@ -1,18 +1,10 @@
export const strings = {
flagshipButNoRNAPI:
'<WebviewIntentProvider /> can not instantiate its service. The application was detected as running in a Flagship webview but has no access to `window.ReactNativeWebView`, which is contradictory.',
nativeNoProviderFound:
'Your component must be in a <NativeIntentProvider /> in order to call useNativeIntent',
noListenerFound:
'Could not handle event, this `NativeMessenger` instance does not have a listener.',
noRNAPIFound:
'You tried to send a synchronous message to a React Native listener, but no React Native API was found in the DOM. Are you in a webview?',
postMeSignature: '@post-me',
remoteHandleNotFound:
'Remote handle returned undefined, could not call method',
webviewIsRendered: 'webviewIsRendered',
webviewNoProviderFound:
'Your component must be in a <WebviewIntentProvider /> in order to call useWebviewIntent',
errorRegisterWebview:
'Cannot register webview. A webview is already registered into cozy-intent with the uri: ${uri}',
errorUnregisterWebview:
@@ -24,5 +16,7 @@ export const strings = {
errorCozyBarAPIMissing:
'Cozy-bar was detected by WebviewIntentProvider but the required setWebviewContext() API was not found. Cozy-bar webview intents will not work. Your cozy-bar version is most likely outdated.',
errorParentHandshake:
'Handshake failed for uri: "${uri}". ConcreteConnection will not be available for this uri\'s messenger, but messages should still work.'
'Handshake failed for uri: "${uri}". ConcreteConnection will not be available for this uri\'s messenger, but messages should still work. Error was: "${errorMessage}".',
errorNoMessengerToInit:
'Could not initialise messenger for uri: "${uri}. No WebView has been registered from react-native with this uri. Please use NativeService.registerWebview(WebviewRef).'
}
4 changes: 3 additions & 1 deletion packages/cozy-intent/src/api/models/messengers.ts
Original file line number Diff line number Diff line change
@@ -4,7 +4,9 @@ import { NativeMessenger } from '../../api'

export interface MessengerRegister {
id: { connection: Connection; messenger: NativeMessenger }
[key: string]: { connection?: Connection; messenger: NativeMessenger }
[key: string]:
| { connection?: Connection; messenger: NativeMessenger }
| undefined
}

export type MessageListener = (event: MessageEvent) => void
22 changes: 18 additions & 4 deletions packages/cozy-intent/src/api/services/NativeMessenger.spec.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,16 @@
import { NativeMessenger, PostMeMessage, strings } from '../../api'
import { NativeMessenger, PostMeMessage } from '../../api'
import { mockWebviewRef } from '../../../tests'

const mockDebug = jest.fn()

jest.mock('post-me', () => ({
...jest.requireActual('post-me'),
debug:
(nameSpace = 'NativeService') =>
(): unknown =>
mockDebug(nameSpace)
}))

describe('NativeMessenger', () => {
afterEach(() => {
mockWebviewRef.injectJavaScript.mockClear()
@@ -44,7 +54,7 @@ describe('NativeMessenger', () => {
)
})

it('Should throw if no listener is injected', () => {
it('Should bail out and log if no listener is injected', () => {
const nativeMessenger = new NativeMessenger(mockWebviewRef)

expect(() =>
@@ -58,7 +68,9 @@ describe('NativeMessenger', () => {
type: 'string',
uri: 'string'
})
).toThrowError(strings.noListenerFound)
).not.toThrow()

expect(mockDebug).toHaveBeenCalled()
})

it('Should remove listener', () => {
@@ -79,6 +91,8 @@ describe('NativeMessenger', () => {
type: 'string',
uri: 'string'
})
).toThrowError(strings.noListenerFound)
).not.toThrow()

expect(mockDebug).toHaveBeenCalled()
})
})
6 changes: 3 additions & 3 deletions packages/cozy-intent/src/api/services/NativeMessenger.ts
Original file line number Diff line number Diff line change
@@ -8,6 +8,8 @@ import {
strings
} from '../../api'

const log = debug('NativeMessenger')

export class NativeMessenger implements Messenger {
private injectJavaScript?: (data: string) => void
private listener?: MessageListener
@@ -30,7 +32,7 @@ export class NativeMessenger implements Messenger {
}

public onMessage = (data: PostMeMessage): void => {
if (!this.listener) throw new Error(strings.noListenerFound)
if (!this.listener) return log(strings.noListenerFound)

this.listener({ data } as MessageEvent)
}
@@ -39,8 +41,6 @@ export class NativeMessenger implements Messenger {
export const DebugNativeMessenger = (
messenger: NativeMessenger
): NativeMessenger => {
const log = debug('NativeMessenger')

return {
postMessage: (message: Record<string, unknown>): void => {
message.action !== 'response' && log('- OUT', message)
Loading