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

sdk/sync: proxy should log to console #1640

Merged
merged 1 commit into from
Feb 8, 2024
Merged
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
38 changes: 26 additions & 12 deletions packages/shared/lib/sdk/sync.ts
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@ import axios from 'axios';
import { getPersistAPIUrl, safeStringify } from '../utils/utils.js';
import type { IntegrationWithCreds } from '@nangohq/node/lib/types.js';
import type { UserProvidedProxyConfiguration } from '../models/Proxy.js';
import logger from '../logger/console.js';

/*
*
Expand Down Expand Up @@ -333,6 +334,19 @@ export class NangoAction {
for (const log of activityLogs) {
if (log.level === 'debug') continue;
await this.log(log.content, { level: log.level });
switch (log.level) {
case 'error':
logger.error(log.content);
break;
case 'warn':
logger.warn(log.content);
break;
case 'info':
logger.info(log.content);
break;
default:
logger.debug(log.content);
}
}
}

Expand Down Expand Up @@ -396,7 +410,7 @@ export class NangoAction {
}

public async setFieldMapping(fieldMapping: Record<string, string>): Promise<AxiosResponse<void>> {
console.warn('setFieldMapping is deprecated. Please use setMetadata instead.');
logger.warn('setFieldMapping is deprecated. Please use setMetadata instead.');
return this.nango.setMetadata(this.providerConfigKey as string, this.connectionId as string, fieldMapping);
}

Expand All @@ -413,7 +427,7 @@ export class NangoAction {
}

public async getFieldMapping(): Promise<Metadata> {
console.warn('getFieldMapping is deprecated. Please use getMetadata instead.');
logger.warn('getFieldMapping is deprecated. Please use getMetadata instead.');
const metadata = await this.nango.getMetadata(this.providerConfigKey as string, this.connectionId as string);
return (metadata['fieldMapping'] as Metadata) || {};
}
Expand Down Expand Up @@ -450,7 +464,7 @@ export class NangoAction {
const content = safeStringify(args);

if (this.dryRun) {
console.log(...args);
logger.info([...args]);
return;
}

Expand All @@ -469,7 +483,7 @@ export class NangoAction {
});

if (response.status > 299) {
console.error(`Request to persist API (log) failed: errorCode=${response.status} response='${JSON.stringify(response.data)}'`, this.stringify());
logger.error(`Request to persist API (log) failed: errorCode=${response.status} response='${JSON.stringify(response.data)}'`, this.stringify());
throw new Error(`Cannot save log for activityLogId '${this.activityLogId}'`);
}
return;
Expand Down Expand Up @@ -600,7 +614,7 @@ export class NangoSync extends NangoAction {
}
});
if (response.status > 299) {
console.error(
logger.error(
`Request to persist API (setLastSyncDate) failed: errorCode=${response.status} response='${JSON.stringify(response.data)}'`,
this.stringify()
);
Expand All @@ -613,14 +627,14 @@ export class NangoSync extends NangoAction {
* Deprecated, please use batchSave
*/
public async batchSend<T = any>(results: T[], model: string): Promise<boolean | null> {
console.warn('batchSend will be deprecated in future versions. Please use batchSave instead.');
logger.warn('batchSend will be deprecated in future versions. Please use batchSave instead.');
return this.batchSave(results, model);
}

public async batchSave<T = any>(results: T[], model: string): Promise<boolean | null> {
if (!results || results.length === 0) {
if (this.dryRun) {
console.log('batchSave received an empty array. No records to save.');
logger.info('batchSave received an empty array. No records to save.');
}
return true;
}
Expand Down Expand Up @@ -651,7 +665,7 @@ export class NangoSync extends NangoAction {
}
});
if (response.status > 299) {
console.error(
logger.error(
`Request to persist API (batchSave) failed: errorCode=${response.status} response='${JSON.stringify(response.data)}'`,
this.stringify()
);
Expand All @@ -664,7 +678,7 @@ export class NangoSync extends NangoAction {
public async batchDelete<T = any>(results: T[], model: string): Promise<boolean | null> {
if (!results || results.length === 0) {
if (this.dryRun) {
console.log('batchDelete received an empty array. No records to delete.');
logger.info('batchDelete received an empty array. No records to delete.');
}
return true;
}
Expand Down Expand Up @@ -695,7 +709,7 @@ export class NangoSync extends NangoAction {
}
});
if (response.status > 299) {
console.error(
logger.error(
`Request to persist API (batchDelete) failed: errorCode=${response.status} response='${JSON.stringify(response.data)}'`,
this.stringify()
);
Expand All @@ -708,7 +722,7 @@ export class NangoSync extends NangoAction {
public async batchUpdate<T = any>(results: T[], model: string): Promise<boolean | null> {
if (!results || results.length === 0) {
if (this.dryRun) {
console.log('batchUpdate received an empty array. No records to update.');
logger.info('batchUpdate received an empty array. No records to update.');
}
return true;
}
Expand Down Expand Up @@ -739,7 +753,7 @@ export class NangoSync extends NangoAction {
}
});
if (response.status > 299) {
console.error(
logger.error(
`Request to persist API (batchUpdate) failed: errorCode=${response.status} response='${JSON.stringify(response.data)}'`,
this.stringify()
);
Expand Down
Loading