Skip to content

Commit

Permalink
Nan 353 tiktok ads support tweak (NangoHQ#1701)
Browse files Browse the repository at this point in the history
* [nan-353] fix spelling

* [nan-353] debug

* [nan-353] try and access data first
  • Loading branch information
khaliqgant authored Feb 19, 2024
1 parent 2ed2259 commit adb4d32
Show file tree
Hide file tree
Showing 4 changed files with 39 additions and 37 deletions.
4 changes: 2 additions & 2 deletions packages/server/lib/controllers/appAuth.controller.ts
Original file line number Diff line number Diff line change
Expand Up @@ -246,7 +246,7 @@ class AppAuthController {
} catch (err) {
const prettyError = JSON.stringify(err, ['message', 'name'], 2);

const content = WSErrBuilder.UnkownError().message + '\n' + prettyError;
const content = WSErrBuilder.UnknownError().message + '\n' + prettyError;

await createActivityLogMessage({
level: 'error',
Expand Down Expand Up @@ -278,7 +278,7 @@ class AppAuthController {
activityLogId
);

return publisher.notifyErr(res, wsClientId, providerConfigKey, connectionId, WSErrBuilder.UnkownError(prettyError));
return publisher.notifyErr(res, wsClientId, providerConfigKey, connectionId, WSErrBuilder.UnknownError(prettyError));
}
}
}
Expand Down
46 changes: 23 additions & 23 deletions packages/server/lib/controllers/oauth.controller.ts
Original file line number Diff line number Diff line change
Expand Up @@ -185,12 +185,12 @@ class OAuthController {
level: 'error',
environment_id: environmentId,
activity_log_id: activityLogId as number,
content: WSErrBuilder.UnkownProviderTemplate(config.provider).message,
content: WSErrBuilder.UnknownProviderTemplate(config.provider).message,
timestamp: Date.now(),
url: callbackUrl
});

return publisher.notifyErr(res, wsClientId, providerConfigKey, connectionId, WSErrBuilder.UnkownProviderTemplate(config.provider));
return publisher.notifyErr(res, wsClientId, providerConfigKey, connectionId, WSErrBuilder.UnknownProviderTemplate(config.provider));
}

const session: OAuthSession = {
Expand Down Expand Up @@ -250,19 +250,19 @@ class OAuthController {
level: 'error',
environment_id: environmentId,
activity_log_id: activityLogId as number,
content: WSErrBuilder.UnkownAuthMode(template.auth_mode).message,
content: WSErrBuilder.UnknownAuthMode(template.auth_mode).message,
timestamp: Date.now(),
url: callbackUrl
});

return publisher.notifyErr(res, wsClientId, providerConfigKey, connectionId, WSErrBuilder.UnkownAuthMode(template.auth_mode));
return publisher.notifyErr(res, wsClientId, providerConfigKey, connectionId, WSErrBuilder.UnknownAuthMode(template.auth_mode));
} catch (e) {
const prettyError = JSON.stringify(e, ['message', 'name'], 2);
await createActivityLogMessage({
level: 'error',
environment_id: environmentId,
activity_log_id: activityLogId as number,
content: WSErrBuilder.UnkownError().message + '\n' + prettyError,
content: WSErrBuilder.UnknownError().message + '\n' + prettyError,
timestamp: Date.now()
});

Expand All @@ -276,7 +276,7 @@ class OAuthController {
}
});

return publisher.notifyErr(res, wsClientId, providerConfigKey, connectionId, WSErrBuilder.UnkownError(prettyError));
return publisher.notifyErr(res, wsClientId, providerConfigKey, connectionId, WSErrBuilder.UnknownError(prettyError));
}
}

Expand Down Expand Up @@ -434,7 +434,7 @@ class OAuthController {
level: 'error',
environment_id,
activity_log_id: activityLogId as number,
content: WSErrBuilder.UnkownGrantType(grantType).message,
content: WSErrBuilder.UnknownGrantType(grantType).message,
timestamp: Date.now(),
auth_mode: template.auth_mode,
url: callbackUrl,
Expand All @@ -445,12 +445,12 @@ class OAuthController {
}
});

return publisher.notifyErr(res, channel, providerConfigKey, connectionId, WSErrBuilder.UnkownGrantType(grantType));
return publisher.notifyErr(res, channel, providerConfigKey, connectionId, WSErrBuilder.UnknownGrantType(grantType));
}
} catch (error: any) {
const prettyError = JSON.stringify(error, ['message', 'name'], 2);

const content = WSErrBuilder.UnkownError().message + '\n' + prettyError;
const content = WSErrBuilder.UnknownError().message + '\n' + prettyError;

await telemetry.log(LogTypes.AUTH_TOKEN_REQUEST_FAILURE, `OAuth2 request process failed ${content}`, LogActionEnum.AUTH, {
callbackUrl,
Expand All @@ -472,7 +472,7 @@ class OAuthController {
}
});

return publisher.notifyErr(res, channel, providerConfigKey, connectionId, WSErrBuilder.UnkownError(prettyError));
return publisher.notifyErr(res, channel, providerConfigKey, connectionId, WSErrBuilder.UnknownError(prettyError));
}
}

Expand Down Expand Up @@ -553,7 +553,7 @@ class OAuthController {
} catch (error: any) {
const prettyError = JSON.stringify(error, ['message', 'name'], 2);

const content = WSErrBuilder.UnkownError().message + '\n' + prettyError;
const content = WSErrBuilder.UnknownError().message + '\n' + prettyError;

await createActivityLogMessage({
level: 'error',
Expand All @@ -568,7 +568,7 @@ class OAuthController {
}
});

return publisher.notifyErr(res, channel, providerConfigKey, connectionId, WSErrBuilder.UnkownError(prettyError));
return publisher.notifyErr(res, channel, providerConfigKey, connectionId, WSErrBuilder.UnknownError(prettyError));
}
}

Expand Down Expand Up @@ -736,14 +736,14 @@ class OAuthController {
level: 'error',
environment_id: session.environmentId,
activity_log_id: activityLogId as number,
content: WSErrBuilder.UnkownAuthMode(session.authMode).message,
content: WSErrBuilder.UnknownAuthMode(session.authMode).message,
state: state as string,
timestamp: Date.now(),
auth_mode: session.authMode,
url: req.originalUrl
});

return publisher.notifyErr(res, channel, providerConfigKey, connectionId, WSErrBuilder.UnkownAuthMode(session.authMode));
return publisher.notifyErr(res, channel, providerConfigKey, connectionId, WSErrBuilder.UnknownAuthMode(session.authMode));
} catch (e) {
const prettyError = JSON.stringify(e, ['message', 'name'], 2);

Expand All @@ -754,7 +754,7 @@ class OAuthController {
metadata: errorManager.getExpressRequestContext(req)
});

const content = WSErrBuilder.UnkownError().message + '\n' + prettyError;
const content = WSErrBuilder.UnknownError().message + '\n' + prettyError;

await createActivityLogMessage({
level: 'error',
Expand All @@ -767,7 +767,7 @@ class OAuthController {
}
});

return publisher.notifyErr(res, channel, providerConfigKey, connectionId, WSErrBuilder.UnkownError(prettyError));
return publisher.notifyErr(res, channel, providerConfigKey, connectionId, WSErrBuilder.UnknownError(prettyError));
}
}

Expand Down Expand Up @@ -958,7 +958,7 @@ class OAuthController {
activityLogId
);

return publisher.notifyErr(res, channel, providerConfigKey, connectionId, WSErrBuilder.UnkownError());
return publisher.notifyErr(res, channel, providerConfigKey, connectionId, WSErrBuilder.UnknownError());
}

const accountId = (await environmentService.getAccountIdFromEnvironment(session.environmentId)) as number;
Expand Down Expand Up @@ -1081,7 +1081,7 @@ class OAuthController {
level: 'error',
environment_id,
activity_log_id: activityLogId as number,
content: WSErrBuilder.UnkownError().message + '\n' + prettyError,
content: WSErrBuilder.UnknownError().message + '\n' + prettyError,
timestamp: Date.now()
});

Expand All @@ -1092,14 +1092,14 @@ class OAuthController {
provider_config_key: providerConfigKey,
environment_id,
auth_mode: template.auth_mode,
error: WSErrBuilder.UnkownError().message + '\n' + prettyError,
error: WSErrBuilder.UnknownError().message + '\n' + prettyError,
operation: AuthOperation.UNKNOWN
},
session.provider,
activityLogId
);

return publisher.notifyErr(res, channel, providerConfigKey, connectionId, WSErrBuilder.UnkownError(prettyError));
return publisher.notifyErr(res, channel, providerConfigKey, connectionId, WSErrBuilder.UnknownError(prettyError));
}
}

Expand Down Expand Up @@ -1230,7 +1230,7 @@ class OAuthController {
level: 'error',
environment_id,
activity_log_id: activityLogId as number,
content: WSErrBuilder.UnkownError().message + '\n' + prettyError,
content: WSErrBuilder.UnknownError().message + '\n' + prettyError,
timestamp: Date.now()
});

Expand All @@ -1241,14 +1241,14 @@ class OAuthController {
provider_config_key: providerConfigKey,
environment_id,
auth_mode: template.auth_mode,
error: WSErrBuilder.UnkownError().message + '\n' + prettyError,
error: WSErrBuilder.UnknownError().message + '\n' + prettyError,
operation: AuthOperation.UNKNOWN
},
session.provider,
activityLogId
);

return publisher.notifyErr(res, channel, providerConfigKey, connectionId, WSErrBuilder.UnkownError(prettyError));
return publisher.notifyErr(res, channel, providerConfigKey, connectionId, WSErrBuilder.UnknownError(prettyError));
});
}
}
Expand Down
10 changes: 5 additions & 5 deletions packages/server/lib/utils/web-socket-error.ts
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ export interface WSErr {
}

export class WSErrBuilder {
public static UnkownAuthMode(authMode: string): WSErr {
public static UnknownAuthMode(authMode: string): WSErr {
return {
type: 'auth_mode_err',
message: `Auth mode ${authMode} not supported.`
Expand Down Expand Up @@ -32,7 +32,7 @@ export class WSErrBuilder {
};
}

public static UnkownGrantType(grantType: string): WSErr {
public static UnknownGrantType(grantType: string): WSErr {
return {
type: 'grant_type_err',
message: `The grant type "${grantType}" is not supported by this OAuth flow.`
Expand Down Expand Up @@ -81,7 +81,7 @@ export class WSErrBuilder {
};
}

public static UnkownProviderTemplate(providerTemplate: string): WSErr {
public static UnknownProviderTemplate(providerTemplate: string): WSErr {
return {
type: 'unknown_config_key',
message: `No Provider Configuration with key "${providerTemplate}".`
Expand All @@ -95,10 +95,10 @@ export class WSErrBuilder {
};
}

public static UnkownError(errorMessage?: string): WSErr {
public static UnknownError(errorMessage?: string): WSErr {
return {
type: 'unknown_err',
message: `Unkown error during the Oauth flow.${errorMessage ? ' ' + errorMessage : ''}`
message: `Unknown error during the Oauth flow.${errorMessage ? ' ' + errorMessage : ''}`
};
}

Expand Down
16 changes: 9 additions & 7 deletions packages/shared/lib/clients/provider.client.ts
Original file line number Diff line number Diff line change
Expand Up @@ -205,15 +205,17 @@ class ProviderClient {

const response = await axios.post(tokenUrl, body);

console.log(response.data);

if (response.status === 200 && response.data !== null) {
return {
access_token: response.data.data['access_token'],
token_type: response.data.data['token_type'],
scope: response.data.data['scope'],
expires_in: response.data.data['expires_in'],
refresh_token: response.data.data['refresh_token'],
refresh_token_expires_in: response.data.data['refresh_token_expires_in'],
open_id: response.data.data['open_id'],
access_token: response.data?.access_token || response.data.data['access_token'],
token_type: response.data?.token_type || response.data.data['token_type'],
scope: response.data?.scope || response.data.data['scope'],
expires_in: response.data?.expires_in || response.data.data['expires_in'],
refresh_token: response.data?.refresh_token || response.data.data['refresh_token'],
refresh_token_expires_in: response.data?.refresh_token_expires_in || response.data.data['refresh_token_expires_in'],
open_id: response.data?.open_id || response.data.data['open_id'],
request_id: response.data['request_id']
};
}
Expand Down

0 comments on commit adb4d32

Please sign in to comment.