Skip to content

feat(sdk): connect rpc client export #545

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

Open
wants to merge 7 commits into
base: main
Choose a base branch
from

Conversation

eugenioenko
Copy link
Contributor

@eugenioenko eugenioenko commented Apr 15, 2025

Description
Generates and exports connectrpc service definitions.

PR Changes

  • Updated connect client generation
  • Re-exported generated client rpc services
  • Added connectrpc framework as dependency
  • Re-exported connectrpc framework lib
  • Updated platform.sh script to generate client
  • added make generate-platform to run the generator
  • Added example component in web-app

Consumer Usage Example
This is an example of how the generated client can be used:

import { wellknown, platformConnect, platformConnectWeb } from '@opentdf/sdk/platform';

const transport = platformConnectWeb.createConnectTransport({
  baseUrl: '/api',
});

const wellknownClient = platformConnect.createClient(wellknown.WellKnownService, transport);


interface ConnectRpcExampleProps {
  accessToken?: string;
}

const handleWellknown = async () => {
  const response = await wellknownClient.getWellKnownConfiguration({});
};

Generating
To generate the service definition run:

make generate-platform

This will clone the platform into the repository and execute the generators based on the exported protos in the platform services

Details
To allow proto buf genrators to work, the platform needs to be cloned into lib/src/platform diretory. The script scripts/platform.sh handles that.

lib/buf.gen.yaml is the configuration for the generator. To execute the generator manually

cd lib
npx buf generate ../platform/service

This will generate lib/src/platform exports for each of the service.
Finally, lib/src/platform.ts re-exports those services and the connect rpc framework

Follow up

  • update the sdk to use internally the generated rpc services
  • updated web-app to use the exported rpc services

Copy link

If these changes look good, signoff on them with:

git pull && git commit --amend --signoff && git push --force-with-lease origin

If they aren't any good, please remove them with:

git pull && git reset --hard HEAD~1 && git push --force-with-lease origin

@opentdf opentdf deleted a comment from github-actions bot Apr 16, 2025
@@ -72,13 +77,17 @@
"watch": "(trap 'kill 0' SIGINT; npm run build && (npm run build:watch & npm run test -- --watch))"
},
"dependencies": {
"@connectrpc/connect": "^2.0.2",
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

These have been added as dependencies and are re-exported in lib/src/platform.ts. This way we can ensure that the generated client services will work with the connectrpc web framework.

One alternative I've considered here is to declare them as peerDependencies and actually not re-export them. When someone consumes @opentdf/sdk they will get a warning that @connectrcp needs to be added to their package.json.
I would have pushed for this option if the bundle size increased, but it has not. I think we are good with re-export

@eugenioenko eugenioenko marked this pull request as ready for review April 21, 2025 17:23
@eugenioenko eugenioenko requested review from a team as code owners April 21, 2025 17:23
@eugenioenko eugenioenko force-pushed the feat/connect-rpc-client-to-javascript-sdk branch from ab1257d to 0f028e0 Compare April 21, 2025 17:50
Copy link
Member

@dmihalcik-virtru dmihalcik-virtru left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Overall, this seems like a good consolidation over the previous work.

Have you actually managed to make these work? If you want to test them, you'll probably want to add code to the integration test packages (in the cli and web-app folders).

@eugenioenko
Copy link
Contributor Author

Have you actually managed to make these work? If you want to test them, you'll probably want to add code to the integration test packages (in the cli and web-app folders).

I've tested the wellknownconfig endpoint with the local build to make sure it was exported and functional. (Thats how I got the example for the PR description)

As a follow up I do have to update the web-app to use the generated endpoints. If needed, I can do it as part of this PR

@dmihalcik-virtru
For the integration test packages, which integrations test do you want to see updated/added for this PR to be mergeable?

@dmihalcik-virtru
Copy link
Member

Given that this is a refactor of existing code, I'm okay approving without a working integration test. However, it does actually expose the feature (I think? how do you initialize the client?), so we should get a test working before the next release to NPM.

For me, I'd like some code that shows how it works, something the integration test would perforce include

@dmihalcik-virtru
Copy link
Member

oh sorry I see now in the PR description. We maybe still want to add it to the readme (maybe after doing the integration test), and I think the sample code in the description still needs auth configured

@dmihalcik-virtru dmihalcik-virtru self-requested a review April 22, 2025 13:31
Copy link

If these changes look good, signoff on them with:

git pull && git commit --amend --signoff && git push --force-with-lease origin

If they aren't any good, please remove them with:

git pull && git reset --hard HEAD~1 && git push --force-with-lease origin

@eugenioenko eugenioenko marked this pull request as ready for review April 22, 2025 20:07
@eugenioenko eugenioenko force-pushed the feat/connect-rpc-client-to-javascript-sdk branch from 23716d8 to c007567 Compare April 22, 2025 20:18
Copy link

Quality Gate Failed Quality Gate failed

Failed conditions
0.0% Coverage on New Code (required ≥ 80%)

See analysis details on SonarQube Cloud

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants