From c046df22da4ff3839c4b251512476aee11125b19 Mon Sep 17 00:00:00 2001 From: Oleksandr Pravosudko Date: Mon, 6 Jun 2022 14:03:01 +0200 Subject: [PATCH] integrate EventHook API into v2 client --- src/client.js | 3 +- src/generated-client.js | 101 +++--------------------------- src/types/client.d.ts | 3 +- src/types/generated-client.d.ts | 42 ++++--------- templates/helpers/operation-v3.js | 10 +++ templates/helpers/operation.js | 6 +- test/it/eventhook-crud.ts | 32 +++++----- test/it/eventhook-lifecycle.ts | 10 +-- 8 files changed, 60 insertions(+), 147 deletions(-) diff --git a/src/client.js b/src/client.js index 2b9d0b4df..6dadccf99 100644 --- a/src/client.js +++ b/src/client.js @@ -21,7 +21,7 @@ const DEFAULT_USER_AGENT = `${packageJson.name}/${packageJson.version} node/${pr const repoUrl = 'https://github.com/okta/okta-sdk-nodejs'; const { OAuth } = require('./oauth'); const { getAffectedResources } = require('./request-middleware'); -const { AuthenticatorApi, SchemaApi, UserTypeApi, InlineHookApi, ProfileMappingApi, DomainApi, LinkedObjectApi, SystemLogApi, FeatureApi, GroupApi } = require('./generated'); +const { AuthenticatorApi, SchemaApi, UserTypeApi, InlineHookApi, ProfileMappingApi, DomainApi, LinkedObjectApi, SystemLogApi, FeatureApi, GroupApi, EventHookApi } = require('./generated'); const { createConfiguration } = require('./generated/configuration'); const { ServerConfiguration } = require('./generated/servers'); const { Observable } = require('./generated/rxjsStub'); @@ -117,6 +117,7 @@ class Client extends GeneratedApiClient { this.systemLogApi = new SystemLogApi(configuration); this.featureApi = new FeatureApi(configuration); this.groupApi = new GroupApi(configuration); + this.eventHookApi = new EventHookApi(configuration); } } diff --git a/src/generated-client.js b/src/generated-client.js index 7a371eb0a..7140bf82f 100644 --- a/src/generated-client.js +++ b/src/generated-client.js @@ -3450,13 +3450,7 @@ class GeneratedApiClient { * @returns {Collection} A collection that will yield {@link EventHook} instances. */ listEventHooks() { - let url = `${this.baseUrl}/api/v1/eventHooks`; - - return new Collection( - this.http, - url, - new ModelFactory(models.EventHook, this), - ); + return this.eventHookApi.listEventHooks(); } /** @@ -3470,18 +3464,7 @@ class GeneratedApiClient { if (!eventHook) { return Promise.reject(new Error('OKTA API createEventHook parameter eventHook is required.')); } - let url = `${this.baseUrl}/api/v1/eventHooks`; - - const resources = []; - - const request = this.http.postJson( - url, - { - body: eventHook - }, - { resources } - ); - return request.then(jsonRes => new models.EventHook(jsonRes, this)); + return this.eventHookApi.createEventHook(eventHook); } /** @@ -3494,18 +3477,7 @@ class GeneratedApiClient { if (!eventHookId) { return Promise.reject(new Error('OKTA API deleteEventHook parameter eventHookId is required.')); } - let url = `${this.baseUrl}/api/v1/eventHooks/${eventHookId}`; - - const resources = [ - `${this.baseUrl}/api/v1/eventHooks/${eventHookId}` - ]; - - const request = this.http.delete( - url, - null, - { resources } - ); - return request; + return this.eventHookApi.deleteEventHook(eventHookId); } /** @@ -3519,18 +3491,7 @@ class GeneratedApiClient { if (!eventHookId) { return Promise.reject(new Error('OKTA API getEventHook parameter eventHookId is required.')); } - let url = `${this.baseUrl}/api/v1/eventHooks/${eventHookId}`; - - const resources = [ - `${this.baseUrl}/api/v1/eventHooks/${eventHookId}` - ]; - - const request = this.http.getJson( - url, - null, - { resources } - ); - return request.then(jsonRes => new models.EventHook(jsonRes, this)); + return this.eventHookApi.getEventHook(eventHookId); } /** @@ -3548,20 +3509,7 @@ class GeneratedApiClient { if (!eventHook) { return Promise.reject(new Error('OKTA API updateEventHook parameter eventHook is required.')); } - let url = `${this.baseUrl}/api/v1/eventHooks/${eventHookId}`; - - const resources = [ - `${this.baseUrl}/api/v1/eventHooks/${eventHookId}` - ]; - - const request = this.http.putJson( - url, - { - body: eventHook - }, - { resources } - ); - return request.then(jsonRes => new models.EventHook(jsonRes, this)); + return this.eventHookApi.updateEventHook(eventHookId, eventHook); } /** @@ -3575,18 +3523,7 @@ class GeneratedApiClient { if (!eventHookId) { return Promise.reject(new Error('OKTA API activateEventHook parameter eventHookId is required.')); } - let url = `${this.baseUrl}/api/v1/eventHooks/${eventHookId}/lifecycle/activate`; - - const resources = [ - `${this.baseUrl}/api/v1/eventHooks/${eventHookId}` - ]; - - const request = this.http.postJson( - url, - null, - { resources } - ); - return request.then(jsonRes => new models.EventHook(jsonRes, this)); + return this.eventHookApi.activateEventHook(eventHookId); } /** @@ -3600,18 +3537,7 @@ class GeneratedApiClient { if (!eventHookId) { return Promise.reject(new Error('OKTA API deactivateEventHook parameter eventHookId is required.')); } - let url = `${this.baseUrl}/api/v1/eventHooks/${eventHookId}/lifecycle/deactivate`; - - const resources = [ - `${this.baseUrl}/api/v1/eventHooks/${eventHookId}` - ]; - - const request = this.http.postJson( - url, - null, - { resources } - ); - return request.then(jsonRes => new models.EventHook(jsonRes, this)); + return this.eventHookApi.deactivateEventHook(eventHookId); } /** @@ -3625,18 +3551,7 @@ class GeneratedApiClient { if (!eventHookId) { return Promise.reject(new Error('OKTA API verifyEventHook parameter eventHookId is required.')); } - let url = `${this.baseUrl}/api/v1/eventHooks/${eventHookId}/lifecycle/verify`; - - const resources = [ - `${this.baseUrl}/api/v1/eventHooks/${eventHookId}` - ]; - - const request = this.http.postJson( - url, - null, - { resources } - ); - return request.then(jsonRes => new models.EventHook(jsonRes, this)); + return this.eventHookApi.verifyEventHook(eventHookId); } /** diff --git a/src/types/client.d.ts b/src/types/client.d.ts index 4eddabeab..f8c1b8444 100644 --- a/src/types/client.d.ts +++ b/src/types/client.d.ts @@ -15,7 +15,7 @@ import { OAuth } from './oauth'; import { Http } from './http'; import { RequestExecutor } from './request-executor'; import { V2Configuration } from './configuration'; -import { AuthenticatorApi, SchemaApi, UserTypeApi, InlineHookApi, ProfileMappingApi, DomainApi, LinkedObjectApi, SystemLogApi, FeatureApi, GroupApi } from './generated'; +import { AuthenticatorApi, SchemaApi, UserTypeApi, InlineHookApi, ProfileMappingApi, DomainApi, LinkedObjectApi, SystemLogApi, FeatureApi, GroupApi, EventHookApi } from './generated'; export declare class Client extends ParameterizedOperationsClient { constructor(config?: V2Configuration); @@ -39,4 +39,5 @@ export declare class Client extends ParameterizedOperationsClient { systemLogApi: SystemLogApi; featureApi: FeatureApi; groupApi: GroupApi; + eventHookApi: EventHookApi; } diff --git a/src/types/generated-client.d.ts b/src/types/generated-client.d.ts index f4a4e4a34..09557ba04 100644 --- a/src/types/generated-client.d.ts +++ b/src/types/generated-client.d.ts @@ -33,7 +33,6 @@ import { ReadStream } from 'fs'; import { OAuth2Token } from './models/OAuth2Token'; import { AppUser } from './models/AppUser'; import { AppUserOptions } from './models/AppUser'; -import { Authenticator } from './models/Authenticator'; import { AuthorizationServer } from './models/AuthorizationServer'; import { AuthorizationServerOptions } from './models/AuthorizationServer'; import { OAuth2Claim } from './models/OAuth2Claim'; @@ -57,33 +56,12 @@ import { EmailTemplateTestRequestOptions } from './models/EmailTemplateTestReque import { ThemeResponse } from './models/ThemeResponse'; import { ThemeOptions } from './models/Theme'; import { ImageUploadResponse } from './models/ImageUploadResponse'; -import { DomainListResponse } from './models/DomainListResponse'; -import { Domain } from './models/Domain'; -import { DomainCertificate } from './models/DomainCertificate'; -import { EventHook } from './models/EventHook'; -import { EventHookOptions } from './models/EventHook'; -import { Feature } from './models/Feature'; -import { Group } from './models/Group'; -import { GroupRule } from './models/GroupRule'; -import { Role } from './models/Role'; -import { AssignRoleRequest } from './models/AssignRoleRequest'; -import { CatalogApplication } from './models/CatalogApplication'; -import { User } from './models/User'; import { IdentityProvider } from './models/IdentityProvider'; import { IdentityProviderOptions } from './models/IdentityProvider'; import { JsonWebKeyOptions } from './models/JsonWebKey'; import { IdentityProviderApplicationUser } from './models/IdentityProviderApplicationUser'; import { UserIdentityProviderLinkRequestOptions } from './models/UserIdentityProviderLinkRequest'; import { SocialAuthToken } from './models/SocialAuthToken'; -import { InlineHook } from './models/InlineHook'; -import { InlineHookPayload } from './models/InlineHookPayload'; -import { InlineHookResponse } from './models/InlineHookResponse'; -import { LogEvent } from './models/LogEvent'; -import { ProfileMapping } from './models/ProfileMapping'; -import { UserSchema } from './models/UserSchema'; -import { GroupSchema } from './models/GroupSchema'; -import { LinkedObject } from './models/LinkedObject'; -import { UserType } from './models/UserType'; import { OrgSetting } from './models/OrgSetting'; import { OrgSettingOptions } from './models/OrgSetting'; import { OrgContactTypeObj } from './models/OrgContactTypeObj'; @@ -105,6 +83,7 @@ import { ThreatInsightConfiguration } from './models/ThreatInsightConfiguration' import { ThreatInsightConfigurationOptions } from './models/ThreatInsightConfiguration'; import { TrustedOrigin } from './models/TrustedOrigin'; import { TrustedOriginOptions } from './models/TrustedOrigin'; +import { User } from './models/User'; import { CreateUserRequestOptions } from './models/CreateUserRequest'; import { UserOptions } from './models/User'; import { AppLink } from './models/AppLink'; @@ -118,11 +97,14 @@ import { SecurityQuestion } from './models/SecurityQuestion'; import { ActivateFactorRequestOptions } from './models/ActivateFactorRequest'; import { VerifyUserFactorResponse } from './models/VerifyUserFactorResponse'; import { VerifyFactorRequestOptions } from './models/VerifyFactorRequest'; +import { Group } from './models/Group'; import { UserActivationToken } from './models/UserActivationToken'; import { TempPassword } from './models/TempPassword'; import { ResetPasswordToken } from './models/ResetPasswordToken'; import { ResponseLinks } from './models/ResponseLinks'; +import { Role } from './models/Role'; import { AssignRoleRequestOptions } from './models/AssignRoleRequest'; +import { CatalogApplication } from './models/CatalogApplication'; import { NetworkZone } from './models/NetworkZone'; import { NetworkZoneOptions } from './models/NetworkZone'; @@ -308,14 +290,14 @@ export declare class GeneratedApiClient { getDomain(domainId: string): Promise; createCertificate(domainId: string, domainCertificate: v3.DomainCertificate): Promise; verifyDomain(domainId: string): Promise; - listEventHooks(): Collection; - createEventHook(eventHook: EventHookOptions): Promise; - deleteEventHook(eventHookId: string): Promise; - getEventHook(eventHookId: string): Promise; - updateEventHook(eventHookId: string, eventHook: EventHookOptions): Promise; - activateEventHook(eventHookId: string): Promise; - deactivateEventHook(eventHookId: string): Promise; - verifyEventHook(eventHookId: string): Promise; + listEventHooks(): Promise>; + createEventHook(eventHook: v3.EventHook): Promise; + deleteEventHook(eventHookId: string): Promise; + getEventHook(eventHookId: string): Promise; + updateEventHook(eventHookId: string, eventHook: v3.EventHook): Promise; + activateEventHook(eventHookId: string): Promise; + deactivateEventHook(eventHookId: string): Promise; + verifyEventHook(eventHookId: string): Promise; listFeatures(): Promise>; getFeature(featureId: string): Promise; listFeatureDependencies(featureId: string): Promise>; diff --git a/templates/helpers/operation-v3.js b/templates/helpers/operation-v3.js index 684a71782..77998935b 100644 --- a/templates/helpers/operation-v3.js +++ b/templates/helpers/operation-v3.js @@ -90,6 +90,16 @@ const V3ApiOperations = { 'removeUserFromGroup', 'updateGroup', 'updateGroupRule', + ], + EventHookApi: [ + 'activateEventHook', + 'createEventHook', + 'deactivateEventHook', + 'deleteEventHook', + 'getEventHook', + 'listEventHooks', + 'updateEventHook', + 'verifyEventHook', ] }; diff --git a/templates/helpers/operation.js b/templates/helpers/operation.js index faa4e5d0a..ac2936d0f 100644 --- a/templates/helpers/operation.js +++ b/templates/helpers/operation.js @@ -262,7 +262,11 @@ const typeScriptClientImportBuilder = operations => { const [args, returnType] = getOperationArgumentsAndReturnType(operation, { tagV3Methods: true }); const typeNames = convertTypeObjectsToTypeNames(args, returnType); const importableTypes = typeNames.filter(isImportableType); - return acc.concat(importableTypes); + if (!isV3Api(operation.operationId)) { + return acc.concat(importableTypes); + } else { + return acc; + } }, []); const uniqueImportTypes = new Set([...operationsImportTypes]); diff --git a/test/it/eventhook-crud.ts b/test/it/eventhook-crud.ts index e756b6b49..67ee339f1 100644 --- a/test/it/eventhook-crud.ts +++ b/test/it/eventhook-crud.ts @@ -3,7 +3,7 @@ import { Client, Collection, DefaultRequestExecutor, - EventHook } from '@okta/okta-sdk-nodejs'; + v3 } from '@okta/okta-sdk-nodejs'; import getMockEventHook = require('./mocks/eventhook'); let orgUrl = process.env.OKTA_CLIENT_ORGURL; @@ -21,14 +21,14 @@ describe('Event Hook Crud API', () => { describe('Create Event hook', () => { let eventHook; afterEach(async () => { - await eventHook.deactivate(); - await eventHook.delete(); + await client.deactivateEventHook(eventHook.id); + await client.deleteEventHook(eventHook.id); }); it('should return correct model', async () => { const mockEventHook = getMockEventHook(); eventHook = await client.createEventHook(mockEventHook); - expect(eventHook).to.be.instanceOf(EventHook); + expect(eventHook).to.be.instanceOf(v3.EventHook); expect(eventHook.id).to.be.exist; expect(eventHook.name).to.be.equal(mockEventHook.name); }); @@ -40,8 +40,8 @@ describe('Event Hook Crud API', () => { eventHook = await client.createEventHook(getMockEventHook()); }); afterEach(async () => { - await eventHook.deactivate(); - await eventHook.delete(); + await client.deactivateEventHook(eventHook.id); + await client.deleteEventHook(eventHook.id); }); it('should return a collection of EventHooks', async () => { @@ -49,7 +49,7 @@ describe('Event Hook Crud API', () => { expect(collection).to.be.instanceOf(Collection); let ehFound = false; await collection.each(eh => { - expect(eh).to.be.instanceOf(EventHook); + expect(eh).to.be.instanceOf(v3.EventHook); if (eh.name === eventHook.name) { ehFound = true; return false; @@ -65,13 +65,13 @@ describe('Event Hook Crud API', () => { eventHook = await client.createEventHook(getMockEventHook()); }); afterEach(async () => { - await eventHook.deactivate(); - await eventHook.delete(); + await client.deactivateEventHook(eventHook.id); + await client.deleteEventHook(eventHook.id); }); it('should get EventHook by id', async () => { const eventHookFromGet = await client.getEventHook(eventHook.id); - expect(eventHookFromGet).to.be.instanceOf(EventHook); + expect(eventHookFromGet).to.be.instanceOf(v3.EventHook); expect(eventHookFromGet.name).to.equal(eventHook.name); }); }); @@ -82,14 +82,14 @@ describe('Event Hook Crud API', () => { eventHook = await client.createEventHook(getMockEventHook()); }); afterEach(async () => { - await eventHook.deactivate(); - await eventHook.delete(); + await client.deactivateEventHook(eventHook.id); + await client.deleteEventHook(eventHook.id); }); it('should update name for created eventHook', async () => { const mockName = 'Mock update event hook'; eventHook.name = mockName; - const updatedEventHook = await eventHook.update(); + const updatedEventHook = await client.updateEventHook(eventHook.id, eventHook); expect(updatedEventHook.id).to.equal(eventHook.id); expect(updatedEventHook.name).to.equal(mockName); }); @@ -102,9 +102,9 @@ describe('Event Hook Crud API', () => { }); it('should not get eventHook after deletion', async () => { - await eventHook.deactivate(); - const res = await eventHook.delete(); - expect(res.status).to.equal(204); + await client.deactivateEventHook(eventHook.id); + const res = await client.deleteEventHook(eventHook.id); + expect(res).to.be.undefined; try { await client.getEventHook(eventHook.id); } catch (e) { diff --git a/test/it/eventhook-lifecycle.ts b/test/it/eventhook-lifecycle.ts index 2c68c6af6..2cf7d0fe5 100644 --- a/test/it/eventhook-lifecycle.ts +++ b/test/it/eventhook-lifecycle.ts @@ -19,17 +19,17 @@ describe('Event Hook Lifecycle API', () => { eventHook = await client.createEventHook(getMockEventHook()); }); afterEach(async () => { - await eventHook.deactivate(); - await eventHook.delete(); + await client.deactivateEventHook(eventHook.id); + await client.deleteEventHook(eventHook.id); }); it('should activate event hook', async () => { - const res = await eventHook.activate(); + const res = await client.activateEventHook(eventHook.id); expect(res.status).to.equal('ACTIVE'); }); it('should deactive event hook', async () => { - const res = await eventHook.deactivate(); + const res = await client.deactivateEventHook(eventHook.id); expect(res.status).to.equal('INACTIVE'); }); @@ -38,7 +38,7 @@ describe('Event Hook Lifecycle API', () => { // https://developer.okta.com/docs/reference/api/event-hooks/#verify-event-hook it('should get error response with status 400 and code E0000001', async () => { try { - await eventHook.verify(); + await client.verifyEventHook(eventHook.id); } catch (err) { expect(err.status).to.equal(400); expect(err.errorCode).to.equal('E0000001');