odoo / mail-client-extensions

Other
27 stars 54 forks source link

[FIX] gmail: broken imports #36

Closed reth-odoo closed 1 year ago

reth-odoo commented 1 year ago

Currently following the steps of the README file results in an unusable addon because of weird importing behavior in typescript compilation, coupled with App Scripts not supporting ES6 imports at all.

To get rid of these issues we remove circular imports and start using roll-up as a compilation step so as to avoid any trouble with importing on Google's side.

This also updates the README and fixes some typescript typing issues so that we can compile locally.

task-3329768

reth-odoo commented 1 year ago

I had to add some diffs in the code itself to make rollup inline things in the right order. -> it uses the standard ES/6 order, which is to 'execute' imports first. So circular imports are problematic. As noted, there are some circular depencies left in views but there isn't a clean way to fix these without adding some kind of shared global variable (because of Google actions...) which isn't super neat. And I don't think they pose any issue, from testing.

I also replaced strings with references to function names to prevent "tree-shaking" of functions that are called in eval (or by google Actions). We could use treeshake: false as a config parameter for rollup but then we get a lot of useless stuff in the result. And I think it's nice to be able to debug it live inside google's editor without having to sift through compilation symbols :D

reth-odoo commented 1 year ago

@std-odoo blip bloup want to give this one another look whenever you have time? (Not super urgent, just making sure it's not forgotten :p)

std-odoo commented 1 year ago

@thiryr Sure, I'll check when it reach review / validation :)

reth-odoo commented 1 year ago

Oh right I thought we already were in validation, my bad :man_facepalming:

Abridbus commented 1 year ago

internal opw-3329768

customer opw-3232745

kirca commented 1 year ago

Hello @thiryr , I am trying to test this by following the readme but it fails at the compile step

$ npx rollup -c

./src/main.ts → ./build...
[!] (plugin typescript) RollupError: @rollup/plugin-typescript TS2339: Property 'ImageCropType' does not exist on type 'CardService'.
src/views/company.ts (70:33)

70                     CardService.ImageCropType.CIRCLE,
                                   ~~~~~~~~~~~~~

    at error (/home/kiril/projects/archeti_projects/mail-client-extensions/gmail/node_modules/rollup/dist/shared/rollup.js:284:30)
    at Object.error (/home/kiril/projects/archeti_projects/mail-client-extensions/gmail/node_modules/rollup/dist/shared/rollup.js:24958:20)
    at emitDiagnostic (file:///home/kiril/projects/archeti_projects/mail-client-extensions/gmail/node_modules/@rollup/plugin-typescript/dist/es/index.js:514:17)
    at reportDiagnostics (file:///home/kiril/projects/archeti_projects/mail-client-extensions/gmail/node_modules/@rollup/plugin-typescript/dist/es/index.js:522:9)
    at Array.forEach (<anonymous>)
    at emitFilesAndReportErrors (/home/kiril/projects/archeti_projects/mail-client-extensions/gmail/node_modules/typescript/lib/typescript.js:123038:17)
    at result.afterProgramCreate (/home/kiril/projects/archeti_projects/mail-client-extensions/gmail/node_modules/typescript/lib/typescript.js:123196:7)
    at Object.afterProgramCreate (file:///home/kiril/projects/archeti_projects/mail-client-extensions/gmail/node_modules/@rollup/plugin-typescript/dist/es/index.js:679:29)
    at synchronizeProgram (/home/kiril/projects/archeti_projects/mail-client-extensions/gmail/node_modules/typescript/lib/typescript.js:123563:14)
    at Object.createWatchProgram (/home/kiril/projects/archeti_projects/mail-client-extensions/gmail/node_modules/typescript/lib/typescript.js:123466:5)

Additionally I had to install tslib as well, without it there was another error

[!] (plugin typescript) RollupError: @rollup/plugin-typescript: Could not find module 'tslib', which is required by this plugin. Is it installed

$ npm --version
9.3.1

$ node --version
v18.14.1

OS: NixOS 22.11
reth-odoo commented 1 year ago

@kirca Hey :wave:

Indeed I remember encountering that, after a full reset it seems to be an issue. We need to update to the new minor version for google script type bindings to fix your second issue, and I've added tslib as a dev dependency too.

-> After pulling this latest change, you should now be able get past the error and compile by just updating your packages with npm i (and/or npm i --dev for some configurations)

Thank you for the report! Let me know if you encounter any other issue.

kirca commented 1 year ago

Hello @thiryr ,

Thanks for the feedback!

Compiling now works and I managed to upload to Apps Script (manually and using clasp).

After this I encounter 2 different issues:

  1. The Test Deployments doesn't open just hangs or gives a message that there is an error and to try again Screenshot from 2023-06-07 18-53-18

  2. At one point it did open and I managed to install it. But after that trying to test with some email and after entering the host it shows the message Screenshot from 2023-06-07 19-03-48

The mail_plugin module is installed on the server though and I can that see in the logs there is no request being sent from gmail. So it looks like it is doing nothing.

reth-odoo commented 1 year ago

@kirca hi again :wave: .

The way gmail plugins work means the request will be sent by google when you click the button. You should see it submits a form to a google URL when you click the button. At the point google will issue a request to the database you link at the /mail_plugin/auth/access_token route. If google cannot establish a connection, or if your server otherwise returns anything outside of the HTTP response 200-299 (success), you will get this error message.

You should make sure 'mail plugin' is enabled in the settings of your database, that visiting /mail_plugin/auth/access_token at least gives you 405 (method disallowed) locally and that the URL is reachable from the outside by at least google. Google makes the list of IPs you should allow available here as of now if you want to explicitly only allow them. Also make sure you allowed the right address in the URL whitelist of appscript.json.

Also make sure that if you have multiple databases, the one you're using is directly accessible without having to select which one to use manually. If multiple databases are on the same base URL the server won't know to respond. You can use --db-filter to ensure the db is directly reachable if needed.

Note that if you are still using an older version of Odoo (< 14.3), you should change all urls from /mail_plugin to /mail_client_extension in both the appscript.json and the app itself. But even then, 14.0 is not well supported for the plugin so I'm not sure it will work quite well :/

I'm hoping you're not using 14.0 but let me know ^^'


For the first issue, I'm not sure what it could be. The script shouldn't play any role in that though. As long as you don't get something like error at line x it should be able to deploy the script for testing.


Globally these should be more of a sysadmin issues as far as I know, I can only help so much with that if it's the case. But feel free to come back with more data on how we might be able to reproduce your issues reliably :)

kirca commented 1 year ago

Hello @thiryr ,

Thank you for the detailed explanation!

The odoo server is v15, single database, and the mail_plugin module is installed . I updated appscript.json to whitelist the server routes, I don't know how I could've missed that :) but probably it would be good to add this info in the readme. Even after this I didn't see any request coming to the server. I will check with our sysadmin if there is maybe a firewall or something that could block the traffic.

Thanks again for your help so far!

kirca commented 1 year ago

@thiryr nevermind the last comment, it is working well. The appscript.json didn't save because of miss formatting :man_facepalming:

Thank you!

reth-odoo commented 1 year ago

@kirca glad to hear it! Hope all goes well from here on out :D