Skip to content

Commit

Permalink
Merge pull request #151 from HubSpot/feature/autificationConfig
Browse files Browse the repository at this point in the history
fix autification config
  • Loading branch information
ksvirkou-hubspot authored Feb 9, 2022
2 parents 9318646 + dbe0263 commit 0fe4343
Show file tree
Hide file tree
Showing 42 changed files with 396 additions and 89 deletions.
11 changes: 9 additions & 2 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -216,7 +216,13 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0

- webhooks.validateSignature()

[unreleased]: https://github.com/HubSpot/hubspot-api-nodejs/compare/6.0.1-beta1...HEAD
## [6.0.1-beta2] - 2022-02-09

### Fixed

- autification configuration

[unreleased]: https://github.com/HubSpot/hubspot-api-nodejs/compare/6.0.1-beta2...HEAD
[1.0.0-beta]: https://github.com/HubSpot/hubspot-api-nodejs/releases/tag/v1.0.0-beta
[1.1.0-beta]: https://github.com/HubSpot/hubspot-api-nodejs/releases/tag/v1.1.0-beta
[2.0.1]: https://github.com/HubSpot/hubspot-api-nodejs/releases/tag/2.0.1
Expand All @@ -234,4 +240,5 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0
[5.0.0]: https://github.com/HubSpot/hubspot-api-nodejs/releases/tag/5.0.0
[6.0.0-beta]: https://github.com/HubSpot/hubspot-api-nodejs/releases/tag/6.0.0-beta
[6.0.1-beta]: https://github.com/HubSpot/hubspot-api-nodejs/releases/tag/6.0.1-beta
[6.0.1-beta]: https://github.com/HubSpot/hubspot-api-nodejs/releases/tag/6.0.1-beta1
[6.0.1-beta1]: https://github.com/HubSpot/hubspot-api-nodejs/releases/tag/6.0.1-beta1
[6.0.1-beta2]: https://github.com/HubSpot/hubspot-api-nodejs/releases/tag/6.0.1-beta2
2 changes: 1 addition & 1 deletion package-lock.json

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

2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "@hubspot/api-client",
"version": "6.0.1-beta1",
"version": "6.0.1-beta2",
"description": "NodeJS v3 [HubSpot API](https://developers.hubspot.com/docs/api/overview) SDK(Client) files",
"main": "lib/index.js",
"types": "lib/index.d.ts",
Expand Down
9 changes: 0 additions & 9 deletions src/client.ts
Original file line number Diff line number Diff line change
Expand Up @@ -39,26 +39,17 @@ export class Client {
}

public setAccessToken(token: string) {
this.cleanAuth()
this.config.accessToken = token
this.init()
}

public setApiKey(apiKey: string) {
this.cleanAuth()
this.config.apiKey = apiKey
this.init()
}

public setDeveloperApiKey(developerApiKey: string) {
this.cleanAuth()
this.config.developerApiKey = developerApiKey
this.init()
}

protected cleanAuth() {
delete this.config.accessToken
delete this.config.apiKey
delete this.config.developerApiKey
}
}
90 changes: 61 additions & 29 deletions src/configuration/ApiClientConfigurator.ts
Original file line number Diff line number Diff line change
@@ -1,47 +1,79 @@
import * as _ from 'lodash'
import { IRequestContext } from '../services/IRequestContext'
import { Observable } from '../services/Observable'
import { IConfiguration } from './IConfiguration'
import { VERSION } from './version'

export class ApiClientConfigurator {
public static getParams<RequestContextType extends IRequestContext, ResponseContextType>(config: IConfiguration) {
let params = {}
public static getParams<
RequestContextType extends IRequestContext,
ResponseContextType,
ObservableRequestContextType,
ObservableResponseContextType
>(
config: IConfiguration,
observableRequestContextParam: new (promise: Promise<RequestContextType>) => ObservableRequestContextType,
observableResponseContextParam: new (promise: Promise<ResponseContextType>) => ObservableResponseContextType,
) {
return {
middleware: [
this.getHeaderMiddleware<
RequestContextType,
ResponseContextType,
ObservableRequestContextType,
ObservableResponseContextType
>(observableRequestContextParam, observableResponseContextParam),
],
authMethods: this.getAuthMethods(config),
}
}

protected static getAuthMethods(config: IConfiguration) {
let authMethods = {}

if (config.accessToken) {
params = {
authMethods: {
oauth2: {
accessToken: config.accessToken,
},
middleware: [this.getHeaderMiddleware<RequestContextType, ResponseContextType>()],
authMethods = Object.assign(authMethods, {
oauth2: {
accessToken: config.accessToken,
},
}
} else if (config.apiKey) {
params = {
authMethods: {
hapikey: config.apiKey,
})
authMethods = Object.assign(authMethods, {
oauth2_legacy: {
accessToken: config.accessToken,
},
middleware: [this.getHeaderMiddleware<RequestContextType, ResponseContextType>()],
}
} else if (config.developerApiKey) {
params = {
authMethods: {
hapikey: config.developerApiKey,
},
middleware: [this.getHeaderMiddleware<RequestContextType, ResponseContextType>()],
}
})
}

if (config.apiKey) {
authMethods = Object.assign(authMethods, {
hapikey: config.apiKey,
})
}

if (config.developerApiKey) {
authMethods = Object.assign(authMethods, {
developer_hapikey: config.developerApiKey,
})
}

return params
return authMethods
}

protected static getHeaderMiddleware<RequestContextType extends IRequestContext, ResponseContextType>() {
protected static getHeaderMiddleware<
RequestContextType extends IRequestContext,
ResponseContextType,
ObservableRequestContextType,
ObservableResponseContextType
>(
observableRequestContextParam: new (promise: Promise<RequestContextType>) => ObservableRequestContextType,
observableResponseContextParam: new (promise: Promise<ResponseContextType>) => ObservableResponseContextType,
) {
return {
pre(context: RequestContextType): Observable<RequestContextType> {
pre(context: RequestContextType): ObservableRequestContextType {
context.setHeaderParam('User-agent', `hubspot-api-client-nodejs; ${VERSION}`)
return new Observable<RequestContextType>(Promise.resolve(context))
return new observableRequestContextParam(Promise.resolve(context))
},
post(context: ResponseContextType): Observable<ResponseContextType> {
return new Observable<ResponseContextType>(Promise.resolve(context))
post(context: ResponseContextType): ObservableResponseContextType {
return new observableResponseContextParam(Promise.resolve(context))
},
}
}
Expand Down
10 changes: 9 additions & 1 deletion src/discovery/automation/actions/ActionsDiscovery.ts
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@ import {
ResponseContext,
RevisionsApi,
} from '../../../../codegen/automation/actions/index'
import { Observable } from '../../../../codegen/automation/actions/rxjsStub'
import { ApiClientConfigurator } from '../../../configuration/ApiClientConfigurator'
import { IConfiguration } from '../../../configuration/IConfiguration'

Expand All @@ -17,7 +18,14 @@ export class ActionsDiscovery {
public revisionsApi: RevisionsApi

constructor(config: IConfiguration) {
const configuration = createConfiguration(ApiClientConfigurator.getParams<RequestContext, ResponseContext>(config))
const configuration = createConfiguration(
ApiClientConfigurator.getParams<
RequestContext,
ResponseContext,
Observable<RequestContext>,
Observable<ResponseContext>
>(config, Observable, Observable),
)

this.callbacksApi = new CallbacksApi(configuration)
this.definitionsApi = new DefinitionsApi(configuration)
Expand Down
10 changes: 9 additions & 1 deletion src/discovery/cms/audit_logs/AuditLogsDiscovery.ts
Original file line number Diff line number Diff line change
@@ -1,13 +1,21 @@
import { createConfiguration } from '../../../../codegen/cms/audit_logs/configuration'
import { AuditLogsApi, RequestContext, ResponseContext } from '../../../../codegen/cms/audit_logs/index'
import { Observable } from '../../../../codegen/cms/audit_logs/rxjsStub'
import { ApiClientConfigurator } from '../../../configuration/ApiClientConfigurator'
import { IConfiguration } from '../../../configuration/IConfiguration'

export class AuditLogsDiscovery {
public auditLogsApi: AuditLogsApi

constructor(config: IConfiguration) {
const configuration = createConfiguration(ApiClientConfigurator.getParams<RequestContext, ResponseContext>(config))
const configuration = createConfiguration(
ApiClientConfigurator.getParams<
RequestContext,
ResponseContext,
Observable<RequestContext>,
Observable<ResponseContext>
>(config, Observable, Observable),
)

this.auditLogsApi = new AuditLogsApi(configuration)
}
Expand Down
10 changes: 9 additions & 1 deletion src/discovery/cms/blogs/authors/AuthorsDiscovery.ts
Original file line number Diff line number Diff line change
@@ -1,13 +1,21 @@
import { createConfiguration } from '../../../../../codegen/cms/blogs/authors/configuration'
import { BlogAuthorsApi, RequestContext, ResponseContext } from '../../../../../codegen/cms/blogs/authors/index'
import { Observable } from '../../../../../codegen/cms/blogs/authors/rxjsStub'
import { ApiClientConfigurator } from '../../../../configuration/ApiClientConfigurator'
import { IConfiguration } from '../../../../configuration/IConfiguration'

export class AuthorsDiscovery {
public blogAuthorsApi: BlogAuthorsApi

constructor(config: IConfiguration) {
const configuration = createConfiguration(ApiClientConfigurator.getParams<RequestContext, ResponseContext>(config))
const configuration = createConfiguration(
ApiClientConfigurator.getParams<
RequestContext,
ResponseContext,
Observable<RequestContext>,
Observable<ResponseContext>
>(config, Observable, Observable),
)

this.blogAuthorsApi = new BlogAuthorsApi(configuration)
}
Expand Down
10 changes: 9 additions & 1 deletion src/discovery/cms/blogs/blog_posts/BlogPostsDiscovery.ts
Original file line number Diff line number Diff line change
@@ -1,13 +1,21 @@
import { createConfiguration } from '../../../../../codegen/cms/blogs/blog_posts/configuration'
import { BlogPostsApi, RequestContext, ResponseContext } from '../../../../../codegen/cms/blogs/blog_posts/index'
import { Observable } from '../../../../../codegen/cms/blogs/blog_posts/rxjsStub'
import { ApiClientConfigurator } from '../../../../configuration/ApiClientConfigurator'
import { IConfiguration } from '../../../../configuration/IConfiguration'

export class BlogPostsDiscovery {
public blogPostsApi: BlogPostsApi

constructor(config: IConfiguration) {
const configuration = createConfiguration(ApiClientConfigurator.getParams<RequestContext, ResponseContext>(config))
const configuration = createConfiguration(
ApiClientConfigurator.getParams<
RequestContext,
ResponseContext,
Observable<RequestContext>,
Observable<ResponseContext>
>(config, Observable, Observable),
)

this.blogPostsApi = new BlogPostsApi(configuration)
}
Expand Down
10 changes: 9 additions & 1 deletion src/discovery/cms/blogs/tags/TagsDiscovery.ts
Original file line number Diff line number Diff line change
@@ -1,13 +1,21 @@
import { createConfiguration } from '../../../../../codegen/cms/blogs/tags/configuration'
import { BlogTagsApi, RequestContext, ResponseContext } from '../../../../../codegen/cms/blogs/tags/index'
import { Observable } from '../../../../../codegen/cms/blogs/tags/rxjsStub'
import { ApiClientConfigurator } from '../../../../configuration/ApiClientConfigurator'
import { IConfiguration } from '../../../../configuration/IConfiguration'

export class TagsDiscovery {
public blogTagsApi: BlogTagsApi

constructor(config: IConfiguration) {
const configuration = createConfiguration(ApiClientConfigurator.getParams<RequestContext, ResponseContext>(config))
const configuration = createConfiguration(
ApiClientConfigurator.getParams<
RequestContext,
ResponseContext,
Observable<RequestContext>,
Observable<ResponseContext>
>(config, Observable, Observable),
)

this.blogTagsApi = new BlogTagsApi(configuration)
}
Expand Down
10 changes: 9 additions & 1 deletion src/discovery/cms/domains/DomainsDiscovery.ts
Original file line number Diff line number Diff line change
@@ -1,13 +1,21 @@
import { createConfiguration } from '../../../../codegen/cms/domains/configuration'
import { DomainsApi, RequestContext, ResponseContext } from '../../../../codegen/cms/domains/index'
import { Observable } from '../../../../codegen/cms/domains/rxjsStub'
import { ApiClientConfigurator } from '../../../configuration/ApiClientConfigurator'
import { IConfiguration } from '../../../configuration/IConfiguration'

export class DomainsDiscovery {
public domainsApi: DomainsApi

constructor(config: IConfiguration) {
const configuration = createConfiguration(ApiClientConfigurator.getParams<RequestContext, ResponseContext>(config))
const configuration = createConfiguration(
ApiClientConfigurator.getParams<
RequestContext,
ResponseContext,
Observable<RequestContext>,
Observable<ResponseContext>
>(config, Observable, Observable),
)

this.domainsApi = new DomainsApi(configuration)
}
Expand Down
10 changes: 9 additions & 1 deletion src/discovery/cms/hubdb/HubdbDiscovery.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
import { createConfiguration } from '../../../../codegen/cms/hubdb/configuration'
import { RequestContext, ResponseContext, RowsApi, RowsBatchApi, TablesApi } from '../../../../codegen/cms/hubdb/index'
import { Observable } from '../../../../codegen/cms/hubdb/rxjsStub'
import { ApiClientConfigurator } from '../../../configuration/ApiClientConfigurator'
import { IConfiguration } from '../../../configuration/IConfiguration'

Expand All @@ -9,7 +10,14 @@ export class HubdbDiscovery {
public tablesApi: TablesApi

constructor(config: IConfiguration) {
const configuration = createConfiguration(ApiClientConfigurator.getParams<RequestContext, ResponseContext>(config))
const configuration = createConfiguration(
ApiClientConfigurator.getParams<
RequestContext,
ResponseContext,
Observable<RequestContext>,
Observable<ResponseContext>
>(config, Observable, Observable),
)

this.rowsApi = new RowsApi(configuration)
this.rowsBatchApi = new RowsBatchApi(configuration)
Expand Down
10 changes: 9 additions & 1 deletion src/discovery/cms/performance/PerformanceDiscovery.ts
Original file line number Diff line number Diff line change
@@ -1,13 +1,21 @@
import { createConfiguration } from '../../../../codegen/cms/performance/configuration'
import { PublicPerformanceApi, RequestContext, ResponseContext } from '../../../../codegen/cms/performance/index'
import { Observable } from '../../../../codegen/cms/performance/rxjsStub'
import { ApiClientConfigurator } from '../../../configuration/ApiClientConfigurator'
import { IConfiguration } from '../../../configuration/IConfiguration'

export class PerformanceDiscovery {
public publicPerformanceApi: PublicPerformanceApi

constructor(config: IConfiguration) {
const configuration = createConfiguration(ApiClientConfigurator.getParams<RequestContext, ResponseContext>(config))
const configuration = createConfiguration(
ApiClientConfigurator.getParams<
RequestContext,
ResponseContext,
Observable<RequestContext>,
Observable<ResponseContext>
>(config, Observable, Observable),
)

this.publicPerformanceApi = new PublicPerformanceApi(configuration)
}
Expand Down
10 changes: 9 additions & 1 deletion src/discovery/cms/site_search/SiteSearchDiscovery.ts
Original file line number Diff line number Diff line change
@@ -1,13 +1,21 @@
import { createConfiguration } from '../../../../codegen/cms/site_search/configuration'
import { PublicApi, RequestContext, ResponseContext } from '../../../../codegen/cms/site_search/index'
import { Observable } from '../../../../codegen/cms/site_search/rxjsStub'
import { ApiClientConfigurator } from '../../../configuration/ApiClientConfigurator'
import { IConfiguration } from '../../../configuration/IConfiguration'

export class SiteSearchDiscovery {
public publicApi: PublicApi

constructor(config: IConfiguration) {
const configuration = createConfiguration(ApiClientConfigurator.getParams<RequestContext, ResponseContext>(config))
const configuration = createConfiguration(
ApiClientConfigurator.getParams<
RequestContext,
ResponseContext,
Observable<RequestContext>,
Observable<ResponseContext>
>(config, Observable, Observable),
)

this.publicApi = new PublicApi(configuration)
}
Expand Down
Loading

0 comments on commit 0fe4343

Please sign in to comment.