Skip to content
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

feat(sdk): standalone package #3297

Draft
wants to merge 22 commits into
base: master
Choose a base branch
from
Draft

Conversation

bodinsamuel
Copy link
Collaborator

@bodinsamuel bodinsamuel commented Jan 13, 2025

Context

We need to stop using shared in the CLI because it contains a lot (e.g: unrelated database models, internal packages, unrelated npm packages, etc.). We imported shared because it contains the runner SDK which is used in the CLI and in the runner + providers.yaml.
The goal of this project is stop importing shared but still be able to share some code between CLI and Runner.

Changes

Untitled-2024-02-19-1625 excalidraw

  • New package @nangohq/runner-sdk
    It contains the shared SDK, data validation, and paginate service. The SDK is now an abstract class. It includes the common logic, but if a method is different between the CLI and Runner, it is not implemented.
    The code is mostly similar, except for:

    • Replaced NangoError by SDKError
    • Removed all the backend logic (e.g: proxy, pagination, instrumentation, persist, etc.)
  • New package @nangohq/shared-public
    This package contains logic shared between the CLI, Runner SDK and Backend. And also providers.yaml!
    It's relatively small for now, the goal is to limit this as much as we can, so it doesn't end up like shared.
    I could not find a good name. I often use core or common but there would be no difference with utils which could create some confusion. Happy to change if needed.

  • CLI and Runner now implement their own SDK
    Using the new package, they implement the custom part (what was inside sync.ts). The footprint of duplicated code is small right now so I feel like it works but happy to discuss this choice.

  • Simplify npm publish
    Since we don't need to pack things up anymore, it's faster and simpler (but still takes a bit of time)


Todo

  • Make SDK works in Runner
  • Fix/inject logger
  • Build models.ts
  • Re-up integrations tests
  • Move monitor providers
  • Publish

bodinsamuel added a commit that referenced this pull request Jan 14, 2025
## Changes

Contributes to
https://linear.app/nango/issue/NAN-2265/remove-shared-from-cli

- Copy SDK types to `@nangohq/types` 
It's to prepare the field when I introduce a dedicated package for the
SDK, so we can reuse types across the codebase. Those types are not used
at the moment. (see #3297 for full PR)

- Fix types for pagination 
It wasn't using a discriminated object which makes type narrowing
impossible

- Fix types for response saver
bodinsamuel added a commit that referenced this pull request Jan 14, 2025
## Changes

Contributes to
https://linear.app/nango/issue/NAN-2265/remove-shared-from-cli
Split of #3297 

- NangoProps use DBSyncConfig
In order to stop using shared I need to stop using the types from
shared, so instead of copying an invalid type I took the time to use the
proper one across the board.
Copy link
Collaborator Author

Choose a reason for hiding this comment

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

This is a temporary fix, until we find a way to inline all types inside a d.ts or better, get rid of models.ts altogether
That means if you modify the SDK you need to manually change this file for the next few weeks.

@@ -151,50 +145,44 @@ describe('Pagination', () => {
token_url: '',
docs: ''
};
(await import('@nangohq/node')).Nango.prototype.getIntegration = vi.fn().mockReturnValue({ config: { provider: 'github' } });
vi.spyOn(providerService, 'getProvider').mockImplementation(() => provider);
vi.spyOn(await import('@nangohq/shared-public'), 'getProvider').mockImplementation(() => provider);
Copy link
Collaborator Author

Choose a reason for hiding this comment

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

Since dryRun is no longer available in the backend, I had to change the mocking strategy, thankfully it was not too bad

@@ -0,0 +1,55 @@
import path from 'node:path';
Copy link
Collaborator Author

Choose a reason for hiding this comment

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

This is more or less, providers.ts that was in shared

bodinsamuel added a commit that referenced this pull request Jan 16, 2025
## Changes

Contributes to
https://linear.app/nango/issue/NAN-2265/remove-shared-from-cli
Split of #3297 

- New package `@nangohq/providers`
Only contains providers.yaml. Compiled and included in tooling but not
used in code yet
bodinsamuel added a commit that referenced this pull request Jan 16, 2025
## Changes 

Contributes to
https://linear.app/nango/issue/NAN-2265/remove-shared-from-cli
Split of #3297 

- **New package `@nangohq/runner-sdk`**
It contains the shared SDK, data validation, and paginate service. The
SDK is now an abstract class. It includes the common logic, but if a
method is different between the CLI and Runner, it is not implemented.
The code is mostly similar, except for:

  - Replaced NangoError by SDKError
- Removed all the backend logic (e.g: proxy, instrumentation, persist,
etc.)

- Hardcoded `models.ts` 
It can't be computed like it used to (it wasn't really working anyway),
it's hardcoded and delivered as-is for the CLI, so it needs to be
maintained manually. We will change that in the coming weeks.
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.

1 participant