Skip to content

Commit

Permalink
Company-specific link/unlink events
Browse files Browse the repository at this point in the history
Adds event hooks that a company can extend when a link is created
or unlinked.

We are using this with our custom Kusto/Azure Data Explorer
integration where we are more actively ingesting changes to
link data.
  • Loading branch information
jeffwilcox committed Jan 7, 2024
1 parent 59895c3 commit cc2b07f
Show file tree
Hide file tree
Showing 6 changed files with 42 additions and 13 deletions.
2 changes: 1 addition & 1 deletion business/account.ts
Original file line number Diff line number Diff line change
Expand Up @@ -420,7 +420,7 @@ export class Account {
};
const eventData = {
github: {
id: id,
id,
login: this._login,
},
aad: aadIdentity,
Expand Down
13 changes: 11 additions & 2 deletions business/operations/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -64,13 +64,16 @@ import {
NoCacheNoBackground,
SupportedLinkType,
UnlinkPurpose,
type LinkEvent,
type UnlinkEvent,
} from '../../interfaces';
import { CreateError, ErrorHelper } from '../../lib/transitional';
import { Team } from '../team';
import { IRepositoryMetadataProvider } from '../entities/repositoryMetadata/repositoryMetadataProvider';
import { isAuthorizedSystemAdministrator } from './administration';
import type { ConfigGitHubOrganizationsSpecializedList } from '../../config/github.organizations.types';
import { type GitHubTokenType, getGitHubTokenTypeFromValue } from '../../lib/github/appTokens';
import getCompanySpecificDeployment from '../../middleware/companySpecificDeployment';

export * from './core';

Expand Down Expand Up @@ -1291,11 +1294,17 @@ export class Operations

// Eventually link/unlink should move from context into operations here to centralize more than just the events

async fireLinkEvent(value): Promise<void> {
async fireLinkEvent(value: LinkEvent): Promise<void> {
const companySpecific = getCompanySpecificDeployment();
companySpecific?.events?.linking?.onLink && companySpecific.events.linking.onLink(this.providers, value);
await fireEvent(this.config, 'link', value);
}

async fireUnlinkEvent(value): Promise<void> {
async fireUnlinkEvent(value: UnlinkEvent): Promise<void> {
const corporateId = value?.aad?.id;
const companySpecific = getCompanySpecificDeployment();
companySpecific?.events?.linking?.onUnlink &&
companySpecific.events.linking.onUnlink(this.providers, corporateId);
await fireEvent(this.config, 'unlink', value);
}

Expand Down
16 changes: 8 additions & 8 deletions interfaces/companySpecific/features/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,14 +3,14 @@
// Licensed under the MIT license. See LICENSE file in the project root for full license information.
//

import { ICompanySpecificAugmentApiMetadata } from './augmentApiMetadata';
import { ICompanySpecificFeatureDemo } from './demo';
import { ICompanySpecificFeatureFirehose } from './firehose';
import { ICompanySpecificFeatureMailProvider } from './mailProvider';
import { ICompanySpecificFeatureOrganizationJoinAcl } from './organizationJoinAcl';
import { ICompanySpecificFeatureOrganizationSudo } from './organizationSudo';
import { ICompanySpecificFeaturePortalSudo } from './portalSudo';
import { ICompanySpecificFeatureRepositoryState } from './repositoryActions';
import type { ICompanySpecificAugmentApiMetadata } from './augmentApiMetadata';
import type { ICompanySpecificFeatureDemo } from './demo';
import type { ICompanySpecificFeatureFirehose } from './firehose';
import type { ICompanySpecificFeatureMailProvider } from './mailProvider';
import type { ICompanySpecificFeatureOrganizationJoinAcl } from './organizationJoinAcl';
import type { ICompanySpecificFeatureOrganizationSudo } from './organizationSudo';
import type { ICompanySpecificFeaturePortalSudo } from './portalSudo';
import type { ICompanySpecificFeatureRepositoryState } from './repositoryActions';

export * from './organizationSudo';
export * from './portalSudo';
Expand Down
1 change: 1 addition & 0 deletions interfaces/companySpecific/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -11,3 +11,4 @@ export * from './administration';
export * from './passport';
export * from './views';
export * from './urls';
export * from './events';
21 changes: 19 additions & 2 deletions interfaces/github/operations.ts
Original file line number Diff line number Diff line change
Expand Up @@ -32,13 +32,30 @@ export interface IOperationsProviders {
providers: IProviders;
}

export type LinkEvent = ICorporateLink & {
linkId: string;
correlationId: string;
};

export type UnlinkEvent = {
github: {
id: number;
login: string;
};
aad: {
preferredName: string;
userPrincipalName: string;
id: string;
};
};

export interface IOperationsLinks {
getLinks(options?: any): Promise<ICorporateLink[]>;
getLinkByThirdPartyId(thirdPartyId: string): Promise<ICorporateLink>;
getLinkByThirdPartyUsername(username: string): Promise<ICorporateLink>;
tryGetLink(login: string): Promise<ICorporateLink>;
fireLinkEvent(value): Promise<void>;
fireUnlinkEvent(value): Promise<void>;
fireLinkEvent(value: LinkEvent): Promise<void>;
fireUnlinkEvent(value: UnlinkEvent): Promise<void>;
}

export interface IOperationsNotifications {
Expand Down
2 changes: 2 additions & 0 deletions interfaces/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,7 @@ import type {
ICorporationAdministrationSection,
IAttachCompanySpecificStrings,
ICompanySpecificFeatures,
ICompanySpecificEvents,
IAttachCompanySpecificViews,
IAttachCompanySpecificUrls,
} from './companySpecific';
Expand All @@ -34,6 +35,7 @@ import type { IProviders } from './providers';

export interface ICompanySpecificStartupProperties {
isCompanySpecific: true;
events?: ICompanySpecificEvents;
routes?: IAttachCompanySpecificRoutes;
middleware?: IAttachCompanySpecificMiddleware;
administrationSection?: ICorporationAdministrationSection;
Expand Down

0 comments on commit cc2b07f

Please sign in to comment.