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: providers package #3308

Merged
merged 5 commits into from
Jan 16, 2025
Merged
Show file tree
Hide file tree
Changes from 3 commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
10 changes: 6 additions & 4 deletions .github/workflows/cli-verification.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -51,11 +51,12 @@ jobs:
fi
}

check_and_publish packages/node-client
check_and_publish packages/shared
check_and_publish packages/frontend
check_and_publish packages/types
check_and_publish packages/nango-yaml
check_and_publish packages/providers
check_and_publish packages/node-client
check_and_publish packages/frontend

- id: publish_step
name: Publish npm packages to the github registry
env:
Expand All @@ -66,6 +67,7 @@ jobs:
GIT_HASH=$(git rev-parse HEAD)
echo "hash=${GIT_HASH}" >> "$GITHUB_OUTPUT"
bash ./scripts/publish.sh 0.0.1-$GIT_HASH

- name: Publish the cli privately under the correct scope
working-directory: packages/cli
env:
Expand All @@ -85,7 +87,7 @@ jobs:
steps:
- uses: actions/setup-node@v4
with:
node-version: '20.12.2'
node-version: '20.18.1'
registry-url: 'https://npm.pkg.github.com'
scope: '@nangohq'
always-auth: true
Expand Down
1 change: 1 addition & 0 deletions Dockerfile
Original file line number Diff line number Diff line change
Expand Up @@ -38,6 +38,7 @@ COPY packages/utils/package.json ./packages/utils/package.json
COPY packages/webapp/package.json ./packages/webapp/package.json
COPY packages/webhooks/package.json ./packages/webhooks/package.json
COPY packages/fleet/package.json ./packages/fleet/package.json
COPY packages/providers/package.json ./packages/providers/package.json
COPY package*.json ./

# Install every dependencies
Expand Down
23 changes: 14 additions & 9 deletions package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

58 changes: 58 additions & 0 deletions packages/providers/lib/index.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,58 @@
import { fileURLToPath } from 'node:url';
import path from 'node:path';
import fs from 'node:fs';
import yaml from 'js-yaml';
import type { Provider, ProviderAlias } from '@nangohq/types';

const __filename = fileURLToPath(import.meta.url);
const pkgRoot = path.join(__filename, '../../');

let providers: Record<string, Provider> | undefined = undefined;

export function updateProviderCache(update: Record<string, Provider>) {
providers = update;
}

export function getProviders() {
if (!providers) {
providers = loadProvidersYaml();
}

return providers;
}

export function getProvider(providerName: string): Provider | null {
const providers = getProviders();
return providers?.[providerName] ?? null;
}

function loadProvidersYaml(): Record<string, Provider> | undefined {
try {
const providersYamlPath = path.join(pkgRoot, 'providers.yaml');
const fileEntries = yaml.load(fs.readFileSync(providersYamlPath).toString()) as Record<string, Provider | ProviderAlias>;

if (fileEntries == null) {
throw new Error('provider_template_loading_failed');
}

for (const key in fileEntries) {
const entry = fileEntries[key];

if (entry && 'alias' in entry) {
if (Object.keys(entry).length <= 0) {
console.error('Failed to find alias', entry.alias);
continue;
}

const { alias, ...overrides } = entry;
const aliasData = fileEntries[entry.alias] as Provider;
fileEntries[key] = { ...aliasData, ...overrides };
}
}

return fileEntries as Record<string, Provider>;
} catch (err) {
console.error('Failed to load providers.yaml', err);
}
return;
}
21 changes: 21 additions & 0 deletions packages/providers/package.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
{
"name": "@nangohq/providers",
"version": "0.48.3",
"description": "Nango's shared components.",
bodinsamuel marked this conversation as resolved.
Show resolved Hide resolved
"type": "module",
"main": "./dist/index.js",
"typings": "./dist/index.d.ts",
"private": false,
"scripts": {},
"dependencies": {
"js-yaml": "4.1.0"
},
"devDependencies": {
"@nangohq/types": "0.48.3",
"vitest": "2.1.8"
},
"files": [
"dist/**/*",
"providers.yaml"
]
}
Loading
Loading