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

fix(utils): add barrel file #1947

Merged
merged 4 commits into from
Apr 4, 2024
Merged
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
1 change: 1 addition & 0 deletions package-lock.json

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

3 changes: 1 addition & 2 deletions packages/data-ingestion/lib/index.ts
Original file line number Diff line number Diff line change
@@ -1,7 +1,6 @@
import { BigQuery } from '@google-cloud/bigquery';
import type { BigQuery as BigQueryType } from '@google-cloud/bigquery';
import { getLogger } from '@nangohq/utils/dist/logger.js';
import { isCloud } from '@nangohq/utils/dist/environment/detection.js';
import { getLogger, isCloud } from '@nangohq/utils';

const logger = getLogger('BigQueryClient');

Expand Down
3 changes: 1 addition & 2 deletions packages/jobs/lib/activities.ts
Original file line number Diff line number Diff line change
Expand Up @@ -22,9 +22,8 @@ import {
getSyncByIdAndName,
getLastSyncDate
} from '@nangohq/shared';
import { getLogger } from '@nangohq/utils/dist/logger.js';
import { getLogger, env } from '@nangohq/utils';
import { BigQueryClient } from '@nangohq/data-ingestion/dist/index.js';
import { env } from '@nangohq/utils/dist/environment/detection.js';
import integrationService from './integration.service.js';
import type { ContinuousSyncArgs, InitialSyncArgs, ActionArgs, WebhookArgs } from './models/worker';

Expand Down
2 changes: 1 addition & 1 deletion packages/jobs/lib/app.ts
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ import { server } from './server.js';
import { cronAutoIdleDemo } from './crons/autoIdleDemo.js';
import { deleteOldActivityLogs } from './crons/deleteOldActivities.js';
import { deleteSyncsData } from './crons/deleteSyncsData.js';
import { getLogger } from '@nangohq/utils/dist/logger.js';
import { getLogger } from '@nangohq/utils';
import { JOBS_PORT } from './constants.js';

const logger = getLogger('Jobs');
Expand Down
2 changes: 1 addition & 1 deletion packages/jobs/lib/crons/autoIdleDemo.ts
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ import {
findPausableDemoSyncs,
SpanTypes
} from '@nangohq/shared';
import { getLogger } from '@nangohq/utils/dist/logger.js';
import { getLogger } from '@nangohq/utils';
import tracer from 'dd-trace';

const logger = getLogger('Jobs');
Expand Down
2 changes: 1 addition & 1 deletion packages/jobs/lib/crons/deleteOldActivities.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import * as cron from 'node-cron';
import { deleteLog, deleteLogsMessages, errorManager, ErrorSourceEnum, findOldActivities, MetricTypes, telemetry } from '@nangohq/shared';
import { getLogger } from '@nangohq/utils/dist/logger.js';
import { getLogger } from '@nangohq/utils';
import tracer from 'dd-trace';
import { setTimeout } from 'node:timers/promises';

Expand Down
2 changes: 1 addition & 1 deletion packages/jobs/lib/crons/deleteSyncsData.ts
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ import {
db,
findRecentlyDeletedSync
} from '@nangohq/shared';
import { getLogger } from '@nangohq/utils/dist/logger.js';
import { getLogger } from '@nangohq/utils';
import tracer from 'dd-trace';

const logger = getLogger('Jobs');
Expand Down
2 changes: 1 addition & 1 deletion packages/jobs/lib/integration.service.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import type { Context } from '@temporalio/activity';
import type { IntegrationServiceInterface, RunScriptOptions, ServiceResponse } from '@nangohq/shared';
import { integrationFilesAreRemote, isCloud, isProd } from '@nangohq/utils/dist/environment/detection.js';
import { integrationFilesAreRemote, isCloud, isProd } from '@nangohq/utils';
import { createActivityLogMessage, localFileService, remoteFileService, NangoError, formatScriptError, isOk } from '@nangohq/shared';
import type { Runner } from './runner/runner.js';
import { getOrStartRunner, getRunnerId } from './runner/runner.js';
Expand Down
2 changes: 1 addition & 1 deletion packages/jobs/lib/runner/local.runner.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ import { RunnerType } from './runner.js';
import type { ChildProcess } from 'child_process';
import { execSync, spawn } from 'child_process';
import { getRunnerClient } from '@nangohq/nango-runner';
import { getLogger } from '@nangohq/utils/dist/logger.js';
import { getLogger } from '@nangohq/utils';

const logger = getLogger('Jobs');

Expand Down
2 changes: 1 addition & 1 deletion packages/jobs/lib/runner/remote.runner.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import { getLogger } from '@nangohq/utils/dist/logger.js';
import { getLogger } from '@nangohq/utils';
import type { Runner } from './runner.js';
import { RunnerType } from './runner.js';
import { getRunnerClient } from '@nangohq/nango-runner';
Expand Down
2 changes: 1 addition & 1 deletion packages/jobs/lib/runner/render.runner.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ import type { Runner } from './runner.js';
import { RunnerType } from './runner.js';
import type { ProxyAppRouter } from '@nangohq/nango-runner';
import { getRunnerClient } from '@nangohq/nango-runner';
import { env } from '@nangohq/utils/dist/environment/detection.js';
import { env } from '@nangohq/utils';
import { NodeEnv, getPersistAPIUrl } from '@nangohq/shared';
import { RenderAPI } from './render.api.js';
import tracer from 'dd-trace';
Expand Down
3 changes: 1 addition & 2 deletions packages/jobs/lib/runner/runner.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,10 +2,9 @@ import type { KVStore } from '@nangohq/shared/lib/utils/kvstore/KVStore.js';
import { LocalRunner } from './local.runner.js';
import { RenderRunner } from './render.runner.js';
import { RemoteRunner } from './remote.runner.js';
import { isEnterprise, env } from '@nangohq/utils/dist/environment/detection.js';
import { isEnterprise, env, getLogger } from '@nangohq/utils';
import { getRedisUrl, InMemoryKVStore, RedisKVStore } from '@nangohq/shared';
import type { ProxyAppRouter } from '@nangohq/nango-runner';
import { getLogger } from '@nangohq/utils/dist/logger.js';

const logger = getLogger('Runner');

Expand Down
2 changes: 1 addition & 1 deletion packages/jobs/lib/server.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ import { createHTTPServer } from '@trpc/server/adapters/standalone';
import superjson from 'superjson';
import { z } from 'zod';
import { suspendRunner } from './runner/runner.js';
import { getLogger } from '@nangohq/utils/dist/logger.js';
import { getLogger } from '@nangohq/utils';

const logger = getLogger('Jobs');

Expand Down
3 changes: 1 addition & 2 deletions packages/jobs/lib/temporal.ts
Original file line number Diff line number Diff line change
Expand Up @@ -4,8 +4,7 @@ import * as dotenv from 'dotenv';
import { createRequire } from 'module';
import * as activities from './activities.js';
import { SYNC_TASK_QUEUE, WEBHOOK_TASK_QUEUE } from '@nangohq/shared';
import { isProd, isEnterprise } from '@nangohq/utils/dist/environment/detection.js';
import { getLogger } from '@nangohq/utils/dist/logger.js';
import { isProd, isEnterprise, getLogger } from '@nangohq/utils';

const logger = getLogger('Jobs.Temporal');

Expand Down
2 changes: 1 addition & 1 deletion packages/logs/lib/env.ts
Original file line number Diff line number Diff line change
@@ -1,3 +1,3 @@
import { parseEnvs, ENVS } from '@nangohq/utils/dist/environment/parse.js';
import { parseEnvs, ENVS } from '@nangohq/utils';

export const envs = parseEnvs(ENVS.required({ NANGO_LOGS_ES_URL: true, NANGO_LOGS_ES_USER: true, NANGO_LOGS_ES_PWD: true }));
2 changes: 1 addition & 1 deletion packages/logs/lib/utils.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import { customAlphabet } from 'nanoid';
import { getLogger } from '@nangohq/utils/dist/logger.js';
import { getLogger } from '@nangohq/utils';

export const logger = getLogger('elasticsearch');

Expand Down
2 changes: 1 addition & 1 deletion packages/persist/lib/app.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import './tracer.js';
import { getLogger } from '@nangohq/utils/dist/logger.js';
import { getLogger } from '@nangohq/utils';
import { server } from './server.js';

const logger = getLogger('Persist');
Expand Down
2 changes: 1 addition & 1 deletion packages/persist/lib/server.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ import express from 'express';
import type { Request, Response, NextFunction } from 'express';
import { validateRequest } from 'zod-express';
import { z } from 'zod';
import { getLogger } from '@nangohq/utils/dist/logger.js';
import { getLogger } from '@nangohq/utils';
import persistController from './controllers/persist.controller.js';
import { logLevelValues } from '@nangohq/shared';

Expand Down
2 changes: 1 addition & 1 deletion packages/runner/lib/app.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import './tracer.js';
import { server } from './server.js';
import { getLogger } from '@nangohq/utils/dist/logger.js';
import { getLogger } from '@nangohq/utils';

const logger = getLogger('Runner');

Expand Down
2 changes: 1 addition & 1 deletion packages/runner/lib/monitor.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ import fs from 'fs';
import { stringifyError, type NangoProps } from '@nangohq/shared';
import * as superjson from 'superjson';
import { fetch } from 'undici';
import { getLogger } from '@nangohq/utils/dist/logger.js';
import { getLogger } from '@nangohq/utils';

const MEMORY_WARNING_PERCENTAGE_THRESHOLD = 75;
const logger = getLogger('Runner');
Expand Down
2 changes: 1 addition & 1 deletion packages/server/lib/clients/auth.client.ts
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ import { BasicStrategy } from 'passport-http';
import express from 'express';
import session from 'express-session';
import path from 'path';
import { AUTH_ENABLED, isBasicAuthEnabled } from '@nangohq/utils/dist/environment/detection.js';
import { AUTH_ENABLED, isBasicAuthEnabled } from '@nangohq/utils';
import { dirname, userService, database } from '@nangohq/shared';
import crypto from 'crypto';
import util from 'util';
Expand Down
2 changes: 1 addition & 1 deletion packages/server/lib/clients/email.client.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import formData from 'form-data';
import Mailgun from 'mailgun.js';
import { getLogger } from '@nangohq/utils/dist/logger.js';
import { getLogger } from '@nangohq/utils';

const logger = getLogger('Server.EmailClient');

Expand Down
2 changes: 1 addition & 1 deletion packages/server/lib/clients/publisher.client.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ import type { WebSocket } from 'ws';
import type { RedisClientType } from 'redis';
import * as uuid from 'uuid';
import { createClient } from 'redis';
import { getLogger } from '@nangohq/utils/dist/logger.js';
import { getLogger } from '@nangohq/utils';
import type { WSErr } from '../utils/web-socket-error.js';
import { errorHtml, successHtml } from '../utils/utils.js';
import { getRedisUrl } from '@nangohq/shared';
Expand Down
3 changes: 1 addition & 2 deletions packages/server/lib/controllers/access.middleware.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,5 @@
import type { Request, Response, NextFunction } from 'express';
import { isCloud, isBasicAuthEnabled } from '@nangohq/utils/dist/environment/detection.js';
import { getLogger } from '@nangohq/utils/dist/logger.js';
import { isCloud, isBasicAuthEnabled, getLogger } from '@nangohq/utils';
import {
LogActionEnum,
ErrorSourceEnum,
Expand Down
2 changes: 1 addition & 1 deletion packages/server/lib/controllers/account.controller.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import type { Request, Response, NextFunction } from 'express';
import type { LogLevel } from '@nangohq/shared';
import { isCloud } from '@nangohq/utils/dist/environment/detection.js';
import { isCloud } from '@nangohq/utils';
import { getEnvironmentAndAccountId, accountService, userService, errorManager, LogActionEnum, createActivityLogAndLogMessage } from '@nangohq/shared';
import { getUserAccountAndEnvironmentFromSession } from '../utils/utils.js';

Expand Down
3 changes: 1 addition & 2 deletions packages/server/lib/controllers/auth.controller.ts
Original file line number Diff line number Diff line change
Expand Up @@ -6,8 +6,7 @@ import { resetPasswordSecret, getUserAccountAndEnvironmentFromSession } from '..
import jwt from 'jsonwebtoken';
import EmailClient from '../clients/email.client.js';
import type { User, Result } from '@nangohq/shared';
import { isCloud, baseUrl, basePublicUrl } from '@nangohq/utils/dist/environment/detection.js';
import { getLogger } from '@nangohq/utils/dist/logger.js';
import { isCloud, baseUrl, basePublicUrl, getLogger } from '@nangohq/utils';
import {
userService,
accountService,
Expand Down
2 changes: 1 addition & 1 deletion packages/server/lib/controllers/config.controller.ts
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ import type {
Integration as ProviderIntegration,
Config
} from '@nangohq/shared';
import { isHosted } from '@nangohq/utils/dist/environment/detection.js';
import { isHosted } from '@nangohq/utils';
import {
flowService,
getConfigWithEndpointsByProviderConfigKey,
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
@@ -1,6 +1,6 @@
import type { Request, Response, NextFunction } from 'express';
import type { Environment } from '@nangohq/shared';
import { isCloud, baseUrl } from '@nangohq/utils/dist/environment/detection.js';
import { isCloud, baseUrl } from '@nangohq/utils';
import {
accountService,
hmacService,
Expand Down
2 changes: 1 addition & 1 deletion packages/server/lib/controllers/onboarding.controller.ts
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,7 @@ import {
AnalyticsTypes
} from '@nangohq/shared';
import type { CustomerFacingDataRecord, IncomingPreBuiltFlowConfig } from '@nangohq/shared';
import { getLogger } from '@nangohq/utils/dist/logger.js';
import { getLogger } from '@nangohq/utils';
import { getUserAccountAndEnvironmentFromSession } from '../utils/utils.js';

const logger = getLogger('Server.Onboarding');
Expand Down
2 changes: 1 addition & 1 deletion packages/server/lib/controllers/ratelimit.middleware.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ import { createClient } from 'redis';
import type { RateLimiterRes } from 'rate-limiter-flexible';
import { RateLimiterRedis, RateLimiterMemory } from 'rate-limiter-flexible';
import { getAccount, getRedisUrl } from '@nangohq/shared';
import { getLogger } from '@nangohq/utils/dist/logger.js';
import { getLogger } from '@nangohq/utils';

const logger = getLogger('RateLimiter');

Expand Down
2 changes: 1 addition & 1 deletion packages/server/lib/controllers/user.controller.ts
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
import { getUserAccountAndEnvironmentFromSession } from '../utils/utils.js';
import type { Request, Response, NextFunction } from 'express';
import EmailClient from '../clients/email.client.js';
import { isCloud, isEnterprise, basePublicUrl } from '@nangohq/utils/dist/environment/detection.js';
import { isCloud, isEnterprise, basePublicUrl } from '@nangohq/utils';
import { errorManager, userService } from '@nangohq/shared';

export interface GetUser {
Expand Down
2 changes: 1 addition & 1 deletion packages/server/lib/jobs/index.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import { isCloud } from '@nangohq/utils/dist/environment/detection.js';
import { isCloud } from '@nangohq/utils';
import { encryptionManager } from '@nangohq/shared';

export async function encryptDataRecords(): Promise<void> {
Expand Down
3 changes: 1 addition & 2 deletions packages/server/lib/server.ts
Original file line number Diff line number Diff line change
Expand Up @@ -33,8 +33,7 @@ import passport from 'passport';
import environmentController from './controllers/environment.controller.js';
import accountController from './controllers/account.controller.js';
import type { Response, Request } from 'express';
import { isCloud, isEnterprise, AUTH_ENABLED, MANAGED_AUTH_ENABLED, isBasicAuthEnabled } from '@nangohq/utils/dist/environment/detection.js';
import { getLogger } from '@nangohq/utils/dist/logger.js';
import { isCloud, isEnterprise, AUTH_ENABLED, MANAGED_AUTH_ENABLED, isBasicAuthEnabled, getLogger } from '@nangohq/utils';
import { getGlobalOAuthCallbackUrl, environmentService, getPort, errorManager, getWebsocketsPath, packageJsonFile } from '@nangohq/shared';
import oAuthSessionService from './services/oauth-session.service.js';
import migrate from './utils/migrate.js';
Expand Down
2 changes: 1 addition & 1 deletion packages/server/lib/utils/migrate.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import { getLogger } from '@nangohq/utils/dist/logger.js';
import { getLogger } from '@nangohq/utils';

const logger = getLogger('Server');

Expand Down
2 changes: 1 addition & 1 deletion packages/server/lib/utils/utils.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ import { fileURLToPath } from 'url';
import path from 'path';
import type { Request } from 'express';
import type { User, Environment, Account, Template as ProviderTemplate, ServiceResponse } from '@nangohq/shared';
import { getLogger } from '@nangohq/utils/dist/logger.js';
import { getLogger } from '@nangohq/utils';
import type { WSErr } from './web-socket-error.js';
import { NangoError, userService, environmentService, interpolateString } from '@nangohq/shared';

Expand Down
15 changes: 15 additions & 0 deletions packages/utils/lib/errors.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
import { serializeError } from 'serialize-error';

/**
* Transform any Error or primitive to a json object
*/
export function errorToObject(err: unknown) {
return serializeError(err);
}

/**
* Transform any Error or primitive to a string
*/
export function stringifyError(err: unknown) {
return JSON.stringify(serializeError(err));
}
Copy link
Collaborator Author

Choose a reason for hiding this comment

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

Note: I'm adding that but don't import it until we fix the packaging of the cli

5 changes: 5 additions & 0 deletions packages/utils/lib/index.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
export * from './environment/constants.js';
export * from './environment/detection.js';
export * from './environment/parse.js';
export * from './errors.js';
export * from './logger.js';
1 change: 1 addition & 0 deletions packages/utils/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@
"license": "SEE LICENSE IN LICENSE FILE IN GIT REPOSITORY",
"dependencies": {
"winston": "3.8.2",
"serialize-error": "11.0.3",
"zod": "3.22.4"
},
"devDependencies": {
Expand Down
Loading