Skip to content

feat(api): add NANGO_ADMIN_PROD_ENV env var #3828

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

Closed
wants to merge 2 commits into from
Closed
Show file tree
Hide file tree
Changes from all 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
5 changes: 5 additions & 0 deletions .env.example
Original file line number Diff line number Diff line change
Expand Up @@ -109,6 +109,11 @@ PUBLIC_LOGODEV_KEY=

# ---- Connect UI
NANGO_PUBLIC_CONNECT_URL=

# Only relevant for self-hosted
NANGO_CONNECT_UI_PORT=3009
FLAG_SERVE_CONNECT_UI=true
# Slack Notification
NANGO_SLACK_INTEGRATION_KEY=
NANGO_ADMIN_UUID=
NANGO_ADMIN_PROD_ENV=prod
20 changes: 11 additions & 9 deletions packages/server/lib/controllers/connection.controller.ts
Original file line number Diff line number Diff line change
@@ -1,19 +1,21 @@
import type { Request, Response, NextFunction } from 'express';
import type { OAuth2Credentials, AuthCredentials, ConnectionUpsertResponse } from '@nangohq/shared';
import db from '@nangohq/database';
import type { TbaCredentials, ApiKeyCredentials, BasicApiCredentials, ConnectionConfig, OAuth1Credentials, OAuth2ClientCredentials } from '@nangohq/types';
import { configService, connectionService, errorManager, NangoError, accountService, getProvider } from '@nangohq/shared';
import { NANGO_ADMIN_UUID } from './account.controller.js';
import { logContextGetter } from '@nangohq/logs';
import type { RequestLocals } from '../utils/express.js';
import { NangoError, accountService, configService, connectionService, errorManager, getProvider } from '@nangohq/shared';

import { NANGO_ADMIN_UUID } from './account.controller.js';
import { preConnectionDeletion } from '../hooks/connection/on/connection-deleted.js';
import {
connectionCreated as connectionCreatedHook,
connectionCreationStartCapCheck as connectionCreationStartCapCheckHook,
connectionRefreshSuccess
} from '../hooks/hooks.js';
import { getOrchestrator } from '../utils/utils.js';
import { preConnectionDeletion } from '../hooks/connection/on/connection-deleted.js';
import { slackService } from '../services/slack.js';
import { getOrchestrator } from '../utils/utils.js';

import type { RequestLocals } from '../utils/express.js';
import type { AuthCredentials, ConnectionUpsertResponse, OAuth2Credentials } from '@nangohq/shared';
import type { ApiKeyCredentials, BasicApiCredentials, ConnectionConfig, OAuth1Credentials, OAuth2ClientCredentials, TbaCredentials } from '@nangohq/types';
import type { NextFunction, Request, Response } from 'express';

const orchestrator = getOrchestrator();

Expand All @@ -30,7 +32,7 @@ class ConnectionController {

const integration_key = process.env['NANGO_SLACK_INTEGRATION_KEY'] || 'slack';
const nangoAdminUUID = NANGO_ADMIN_UUID;
const env = 'prod';
const env = process.env['NANGO_ADMIN_PROD_ENV'] || 'prod';

Copy link
Collaborator

Choose a reason for hiding this comment

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

we now prefer to use the validated and type safed parsedEnvs. Example:

initSentry({ dsn: envs.SENTRY_DSN, applicationName: envs.NANGO_DB_APPLICATION_NAME, hash: envs.GIT_HASH });

Copy link
Collaborator

Choose a reason for hiding this comment

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

yes, and that way you can put a default value too

const info = await accountService.getAccountAndEnvironmentIdByUUID(nangoAdminUUID as string, env);
const {
Expand Down
2 changes: 1 addition & 1 deletion packages/server/lib/controllers/environment.controller.ts
Original file line number Diff line number Diff line change
Expand Up @@ -43,7 +43,7 @@ class EnvironmentController {

const integration_key = process.env['NANGO_SLACK_INTEGRATION_KEY'] || 'slack';
const nangoAdminUUID = NANGO_ADMIN_UUID;
const env = 'prod';
const env = process.env['NANGO_ADMIN_PROD_ENV'] || 'prod';
const info = await accountService.getAccountAndEnvironmentIdByUUID(nangoAdminUUID as string, env);

if (!info) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -47,7 +47,7 @@ export const getEnvironment = asyncWrapper<GetEnvironment>(async (req, res) => {
const connectionId = generateSlackConnectionId(account.uuid, environment.name);
const integration_key = process.env['NANGO_SLACK_INTEGRATION_KEY'] || 'slack';
const nangoAdminUUID = NANGO_ADMIN_UUID;
const env = 'prod';
const env = process.env['NANGO_ADMIN_PROD_ENV'] || 'prod';
const info = await accountService.getAccountAndEnvironmentIdByUUID(nangoAdminUUID as string, env);
if (info) {
const connectionConfig = await connectionService.getConnectionConfig({
Expand Down
22 changes: 12 additions & 10 deletions packages/shared/lib/services/notification/slack.service.ts
Original file line number Diff line number Diff line change
@@ -1,18 +1,20 @@
import db, { schema, dbNamespace } from '@nangohq/database';
import type { ServiceResponse } from '../../models/Generic.js';
import environmentService from '../environment.service.js';
import type { Result } from '@nangohq/utils';
import { basePublicUrl, Err, getLogger, Ok, stringToHash, truncateJson } from '@nangohq/utils';
import db, { dbNamespace, schema } from '@nangohq/database';
import { Err, Ok, basePublicUrl, getLogger, stringToHash, truncateJson } from '@nangohq/utils';

import configService from '../config.service.js';
import connectionService from '../connection.service.js';
import type { LogContextGetter } from '@nangohq/logs';
import type { ConnectionJobs, DBConnection, DBConnectionDecrypted, DBEnvironment, DBSlackNotification, DBTeam } from '@nangohq/types';
import type { NangoError } from '../../utils/error.js';
import { refreshOrTestCredentials } from '../connections/credentials/refresh.js';
import configService from '../config.service.js';
import environmentService from '../environment.service.js';
import { ProxyRequest } from '../proxy/request.js';
import { getProxyConfiguration } from '../proxy/utils.js';

import type { ServiceResponse } from '../../models/Generic.js';
import type { Config } from '../../models/Provider.js';
import type { NangoError } from '../../utils/error.js';
import type { FeatureFlags } from '@nangohq/kvstore';
import type { LogContextGetter } from '@nangohq/logs';
import type { ConnectionJobs, DBConnection, DBConnectionDecrypted, DBEnvironment, DBSlackNotification, DBTeam } from '@nangohq/types';
import type { Result } from '@nangohq/utils';

const logger = getLogger('SlackService');
const TABLE = dbNamespace + 'slack_notifications';
Expand Down Expand Up @@ -85,7 +87,7 @@ export class SlackService {

private integrationKey = process.env['NANGO_SLACK_INTEGRATION_KEY'] || 'slack';
private nangoAdminUUID = process.env['NANGO_ADMIN_UUID'];
private env = 'prod';
private env = process.env['NANGO_ADMIN_PROD_ENV'] || 'prod';

Copy link
Collaborator

Choose a reason for hiding this comment

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

nb in shared you wont be able to use parsed, but you can refactor the class to accept the env in the constructor

constructor({ logContextGetter, featureFlags }: { logContextGetter: LogContextGetter; featureFlags: FeatureFlags }) {
this.logContextGetter = logContextGetter;
Expand Down
Loading