Skip to content

Commit fa2e432

Browse files
committed
♻️ Change contactsChangd to integrationEntitiesChanged
1 parent a199dc4 commit fa2e432

7 files changed

+28
-23
lines changed

src/models/adapter.model.ts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,7 @@ import {
1414
LoggedIntegrationEntity,
1515
} from '.';
1616
import { IntegrationEntityType } from './integration-entity.model';
17-
import { ContactsChangedData } from './contacts-changed.model';
17+
import { IntegrationEntitiesChangedData } from './integration-entities-changed.model';
1818

1919
export interface Adapter {
2020
getToken?: (config: Config) => Promise<{ apiKey: string }>;
@@ -83,5 +83,5 @@ export interface Adapter {
8383
req: Request,
8484
res?: Response,
8585
) => Promise<{ apiKey: string; apiUrl: string }>;
86-
handleWebhook?: (body: unknown) => Promise<ContactsChangedData>;
86+
handleWebhook?: (body: unknown) => Promise<IntegrationEntitiesChangedData>;
8787
}

src/models/controller.model.ts

Lines changed: 17 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,7 @@ import {
1212
ContactDelta,
1313
ContactTemplate,
1414
ContactUpdate,
15-
ContactsChangedData,
15+
IntegrationEntitiesChangedData,
1616
ServerError,
1717
} from '.';
1818
import { calendarEventsSchema, contactsSchema } from '../schemas';
@@ -35,7 +35,7 @@ import {
3535
PubSubContactsMessage,
3636
PubSubContactsState,
3737
} from './pubsub-contacts-message.model';
38-
import { PubSubContactsChangedClient } from './pubsub-contacts-changed-client.model';
38+
import { PubSubIntegrationEntitiesChangedClient } from './pubsub-integration-entities-changed-client.model';
3939

4040
const CONTACT_FETCH_TIMEOUT = 5000;
4141

@@ -54,7 +54,7 @@ export class Controller {
5454
private contactCache: ContactCache | null;
5555
private ajv: Ajv;
5656
private pubSubClient: PubSubClient | null = null;
57-
private pubSubContactsChangedClient: PubSubContactsChangedClient | null =
57+
private pubSubIntegrationEntitiesChangedClient: PubSubIntegrationEntitiesChangedClient | null =
5858
null;
5959
private integrationName: string = 'UNKNOWN';
6060
private streamingPromises = new Map<string, Promise<void>>();
@@ -67,16 +67,19 @@ export class Controller {
6767
if (this.adapter.streamContacts) {
6868
const {
6969
PUBSUB_TOPIC_NAME: topicName,
70-
PUBSUB_CONTACTS_CHANGED_TOPIC_NAME: contactsChangedTopicName,
70+
PUBSUB_INTEGRATION_ENTITIES_CHANGED_TOPIC_NAME:
71+
integrationEntitiesChangedTopicName,
7172
INTEGRATION_NAME: integrationName,
7273
} = process.env;
7374

7475
if (!topicName) {
7576
throw new Error('No PUBSUB_TOPIC_NAME provided.');
7677
}
7778

78-
if (!contactsChangedTopicName) {
79-
throw new Error('No PUBSUB_CONTACTS_CHANGED_TOPIC_NAME provided.');
79+
if (!integrationEntitiesChangedTopicName) {
80+
throw new Error(
81+
'No PUBSUB_INTEGRATION_ENTITIES_CHANGED_TOPIC_NAME provided.',
82+
);
8083
}
8184

8285
if (!integrationName) {
@@ -90,12 +93,13 @@ export class Controller {
9093
`Initialized PubSub client with topic ${topicName}`,
9194
);
9295

93-
this.pubSubContactsChangedClient = new PubSubContactsChangedClient(
94-
contactsChangedTopicName,
95-
);
96+
this.pubSubIntegrationEntitiesChangedClient =
97+
new PubSubIntegrationEntitiesChangedClient(
98+
integrationEntitiesChangedTopicName,
99+
);
96100
infoLogger(
97101
'Controller',
98-
`Initialized PubSub client with topic ${contactsChangedTopicName}`,
102+
`Initialized PubSub client with topic ${integrationEntitiesChangedTopicName}`,
99103
);
100104
}
101105
}
@@ -1309,11 +1313,11 @@ export class Controller {
13091313
throw new ServerError(501, 'Webhook handling not implemented');
13101314
}
13111315

1312-
const contactsChangedData: ContactsChangedData =
1316+
const changedData: IntegrationEntitiesChangedData =
13131317
await this.adapter.handleWebhook(req.body);
13141318

1315-
console.log('sending webhook to pubsub', contactsChangedData);
1316-
this.pubSubContactsChangedClient?.publishMessage(contactsChangedData);
1319+
console.log('sending webhook to pubsub', changedData);
1320+
this.pubSubIntegrationEntitiesChangedClient?.publishMessage(changedData);
13171321

13181322
res.sendStatus(200);
13191323
} catch (error) {

src/models/index.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@ export * from './call-event.model';
77
export * from './config.model';
88
export * from './contact-cache.model';
99
export * from './contact.model';
10-
export * from './contacts-changed.model';
10+
export * from './integration-entities-changed.model';
1111
export * from './controller.model';
1212
export * from './custom-router.model';
1313
export * from './server-error.model';

src/models/contacts-changed.model.ts renamed to src/models/integration-entities-changed.model.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
import { IntegrationEntityType } from './integration-entity.model';
22

3-
export type ContactsChangedData = {
3+
export type IntegrationEntitiesChangedData = {
44
integrationName: string;
55
data: {
66
integrationAccountId: string;

src/models/pubsub-contacts-changed-message.model.ts

Lines changed: 0 additions & 3 deletions
This file was deleted.

src/models/pubsub-contacts-changed-client.model.ts renamed to src/models/pubsub-integration-entities-changed-client.model.ts

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,10 @@
11
import { PubSub } from '@google-cloud/pubsub';
22
import { timeout } from '../util/timeout';
3-
import { PubSubContactsChangedMessage } from './pubsub-contacts-changed-message.model';
3+
import { PubSubIntegrationEntitiesChangedMessage } from './pubsub-integration-entities-changed-message.model';
44

55
const PUBLISH_TIMEOUT = 10_000;
66

7-
export class PubSubContactsChangedClient {
7+
export class PubSubIntegrationEntitiesChangedClient {
88
private client: PubSub;
99
private topicName: string;
1010

@@ -13,7 +13,7 @@ export class PubSubContactsChangedClient {
1313
this.topicName = topicName;
1414
}
1515

16-
async publishMessage(message: PubSubContactsChangedMessage) {
16+
async publishMessage(message: PubSubIntegrationEntitiesChangedMessage) {
1717
if (!this.topicName) {
1818
throw new Error('No pubsub topic name provided.');
1919
}
Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,4 @@
1+
import { IntegrationEntitiesChangedData } from './integration-entities-changed.model';
2+
3+
export type PubSubIntegrationEntitiesChangedMessage =
4+
IntegrationEntitiesChangedData;

0 commit comments

Comments
 (0)