Skip to content

Commit 0f3f1ce

Browse files
authored
fix(events): handle domain verification failed (#1543)
1 parent 4ef8f19 commit 0f3f1ce

6 files changed

Lines changed: 175 additions & 3 deletions

File tree

src/common/interfaces/event.interface.ts

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -44,6 +44,8 @@ import {
4444
import {
4545
OrganizationDomain,
4646
OrganizationDomainResponse,
47+
OrganizationDomainVerificationFailed,
48+
OrganizationDomainVerificationFailedResponse,
4749
} from '../../organization-domains/interfaces';
4850
import {
4951
AuthenticationRadarRiskDetectedEventData,
@@ -656,12 +658,12 @@ export interface OrganizationDomainVerifiedEventResponse extends EventResponseBa
656658

657659
export interface OrganizationDomainVerificationFailedEvent extends EventBase {
658660
event: 'organization_domain.verification_failed';
659-
data: OrganizationDomain;
661+
data: OrganizationDomainVerificationFailed;
660662
}
661663

662664
export interface OrganizationDomainVerificationFailedEventResponse extends EventResponseBase {
663665
event: 'organization_domain.verification_failed';
664-
data: OrganizationDomainResponse;
666+
data: OrganizationDomainVerificationFailedResponse;
665667
}
666668

667669
export interface OrganizationDomainCreatedEvent extends EventBase {

src/common/serializers/event.serializer.ts

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -38,6 +38,7 @@ import {
3838
deserializeVaultDekDecryptedEvent,
3939
deserializeVaultByokKeyVerificationCompletedEvent,
4040
} from '../../vault/serializers/vault-event.serializer';
41+
import { deserializeOrganizationDomainVerificationFailed } from '../../organization-domains/serializers/organization-domain-verification-failed.serializer';
4142

4243
export const deserializeEvent = (event: EventResponse): Event => {
4344
const eventBase: EventBase = {
@@ -210,8 +211,13 @@ export const deserializeEvent = (event: EventResponse): Event => {
210211
event: event.event,
211212
data: deserializeOrganization(event.data),
212213
};
213-
case 'organization_domain.verified':
214214
case 'organization_domain.verification_failed':
215+
return {
216+
...eventBase,
217+
event: event.event,
218+
data: deserializeOrganizationDomainVerificationFailed(event.data),
219+
};
220+
case 'organization_domain.verified':
215221
case 'organization_domain.created':
216222
case 'organization_domain.updated':
217223
case 'organization_domain.deleted':

src/events/events.spec.ts

Lines changed: 123 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,10 @@ import {
88
FlagCreatedEvent,
99
FlagCreatedEventResponse,
1010
ListResponse,
11+
OrganizationDomainCreatedEvent,
12+
OrganizationDomainCreatedEventResponse,
13+
OrganizationDomainVerificationFailedEvent,
14+
OrganizationDomainVerificationFailedEventResponse,
1115
VaultDataCreatedEvent,
1216
VaultDataCreatedEventResponse,
1317
VaultDataUpdatedEvent,
@@ -31,6 +35,10 @@ import {
3135
} from '../common/interfaces';
3236
import { WorkOS } from '../workos';
3337
import { ConnectionType } from '../sso/interfaces';
38+
import {
39+
OrganizationDomainState,
40+
OrganizationDomainVerificationStrategy,
41+
} from '../organization-domains/interfaces';
3442

3543
describe('Event', () => {
3644
beforeEach(() => fetch.resetMocks());
@@ -736,5 +744,120 @@ describe('Event', () => {
736744
});
737745
});
738746
});
747+
748+
describe('organization domain events', () => {
749+
it('deserializes organization_domain.created events', async () => {
750+
const response: OrganizationDomainCreatedEventResponse = {
751+
event: 'organization_domain.created',
752+
id: 'event_01DOMAINCREATED001',
753+
data: {
754+
id: 'org_domain_01TESTDOMAIN',
755+
state: OrganizationDomainState.Pending,
756+
domain: 'example.com',
757+
object: 'organization_domain',
758+
created_at: '2026-04-06T06:24:06.749Z',
759+
updated_at: '2026-04-06T06:24:06.749Z',
760+
organization_id: 'org_01TESTORGANIZATION',
761+
verification_strategy:
762+
OrganizationDomainVerificationStrategy.Manual,
763+
},
764+
context: {},
765+
created_at: '2026-04-06T06:24:06.776Z',
766+
};
767+
768+
const expected: OrganizationDomainCreatedEvent = {
769+
event: 'organization_domain.created',
770+
id: 'event_01DOMAINCREATED001',
771+
data: {
772+
id: 'org_domain_01TESTDOMAIN',
773+
state: OrganizationDomainState.Pending,
774+
domain: 'example.com',
775+
object: 'organization_domain',
776+
createdAt: '2026-04-06T06:24:06.749Z',
777+
updatedAt: '2026-04-06T06:24:06.749Z',
778+
organizationId: 'org_01TESTORGANIZATION',
779+
verificationStrategy: OrganizationDomainVerificationStrategy.Manual,
780+
},
781+
context: {},
782+
createdAt: '2026-04-06T06:24:06.776Z',
783+
};
784+
785+
fetchOnce({
786+
object: 'list',
787+
data: [response],
788+
list_metadata: {},
789+
});
790+
791+
const list = await workos.events.listEvents({
792+
events: ['organization_domain.created'],
793+
});
794+
795+
expect(list).toEqual({
796+
object: 'list',
797+
data: [expected],
798+
listMetadata: {},
799+
});
800+
});
801+
802+
it('deserializes organization_domain.verification_failed events', async () => {
803+
const response: OrganizationDomainVerificationFailedEventResponse = {
804+
event: 'organization_domain.verification_failed',
805+
id: 'event_01DOMAIN0002',
806+
data: {
807+
reason: 'domain_verification_period_expired',
808+
organization_domain: {
809+
id: 'org_domain_0TESTDOMAIN',
810+
state: OrganizationDomainState.Failed,
811+
domain: 'example.com',
812+
object: 'organization_domain',
813+
created_at: '2026-03-07T02:24:56.621Z',
814+
updated_at: '2026-04-06T02:25:00.494Z',
815+
organization_id: 'org_01TESTORGANIZATION',
816+
verification_token: 'FAKETOKEN',
817+
verification_strategy: OrganizationDomainVerificationStrategy.Dns,
818+
},
819+
},
820+
context: {},
821+
created_at: '2026-04-06T02:26:05.430Z',
822+
};
823+
824+
const expected: OrganizationDomainVerificationFailedEvent = {
825+
event: 'organization_domain.verification_failed',
826+
id: 'event_01DOMAIN0002',
827+
data: {
828+
reason: 'domain_verification_period_expired',
829+
organizationDomain: {
830+
id: 'org_domain_0TESTDOMAIN',
831+
state: OrganizationDomainState.Failed,
832+
domain: 'example.com',
833+
object: 'organization_domain',
834+
createdAt: '2026-03-07T02:24:56.621Z',
835+
updatedAt: '2026-04-06T02:25:00.494Z',
836+
organizationId: 'org_01TESTORGANIZATION',
837+
verificationToken: 'FAKETOKEN',
838+
verificationStrategy: OrganizationDomainVerificationStrategy.Dns,
839+
},
840+
},
841+
context: {},
842+
createdAt: '2026-04-06T02:26:05.430Z',
843+
};
844+
845+
fetchOnce({
846+
object: 'list',
847+
data: [response],
848+
list_metadata: {},
849+
});
850+
851+
const list = await workos.events.listEvents({
852+
events: ['organization_domain.verification_failed'],
853+
});
854+
855+
expect(list).toEqual({
856+
object: 'list',
857+
data: [expected],
858+
listMetadata: {},
859+
});
860+
});
861+
});
739862
});
740863
});
Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,2 +1,3 @@
11
export * from './create-organization-domain-options.interface';
22
export * from './organization-domain.interface';
3+
export * from './organization-domain-verification-failed.interface';
Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,14 @@
1+
import {
2+
OrganizationDomain,
3+
OrganizationDomainResponse,
4+
} from './organization-domain.interface';
5+
6+
export interface OrganizationDomainVerificationFailed {
7+
reason: string;
8+
organizationDomain: OrganizationDomain;
9+
}
10+
11+
export interface OrganizationDomainVerificationFailedResponse {
12+
reason: string;
13+
organization_domain: OrganizationDomainResponse;
14+
}
Lines changed: 26 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,26 @@
1+
import {
2+
OrganizationDomainVerificationFailed,
3+
OrganizationDomainVerificationFailedResponse,
4+
} from '../interfaces';
5+
import {
6+
deserializeOrganizationDomain,
7+
serializeOrganizationDomain,
8+
} from './organization-domain.serializer';
9+
10+
export const deserializeOrganizationDomainVerificationFailed = (
11+
organizationDomainVerificationFailed: OrganizationDomainVerificationFailedResponse,
12+
): OrganizationDomainVerificationFailed => ({
13+
reason: organizationDomainVerificationFailed.reason,
14+
organizationDomain: deserializeOrganizationDomain(
15+
organizationDomainVerificationFailed.organization_domain,
16+
),
17+
});
18+
19+
export const serializeOrganizationDomainVerificationFailed = (
20+
organizationDomainVerificationFailed: OrganizationDomainVerificationFailed,
21+
): OrganizationDomainVerificationFailedResponse => ({
22+
reason: organizationDomainVerificationFailed.reason,
23+
organization_domain: serializeOrganizationDomain(
24+
organizationDomainVerificationFailed.organizationDomain,
25+
),
26+
});

0 commit comments

Comments
 (0)