Skip to content

Commit 4e4efb3

Browse files
committed
♻️ pubsub message type
1 parent 6d79702 commit 4e4efb3

File tree

3 files changed

+13
-4
lines changed

3 files changed

+13
-4
lines changed

src/models/controller.model.ts

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -29,6 +29,7 @@ import { CacheItemStateType } from "./cache-item-state.model";
2929
import { CalendarFilterOptions } from "./calendar-filter-options.model";
3030
import { IntegrationErrorType } from "./integration-error.model";
3131
import { PubSubClient } from "./pubsub-client.model";
32+
import { PubSubContactsMessage } from "./pubsub-contacts-message.model";
3233

3334
const CONTACT_FETCH_TIMEOUT = 3000;
3435

@@ -55,7 +56,7 @@ export class Controller {
5556

5657
const { PUBSUB_TOPIC_NAME: topicName } = process.env;
5758

58-
if (isProduction()) {
59+
if (isProduction() && typeof this.adapter.streamContacts === "function") {
5960
if (!topicName) {
6061
throw new Error("No pubsub topic name provided.");
6162
}
@@ -202,7 +203,7 @@ export class Controller {
202203
throw new Error("Invalid contacts received");
203204
}
204205

205-
const message = {
206+
const message: PubSubContactsMessage = {
206207
userId: providerConfig.userId,
207208
timestamp,
208209
contacts: contacts.map((contact) =>

src/models/pubsub-client.model.ts

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
11
import { PubSub } from "@google-cloud/pubsub";
22
import { errorLogger, infoLogger } from "../util";
3+
import { PubSubContactsMessage } from "./pubsub-contacts-message.model";
34

45
export class PubSubClient {
56
private client: PubSub;
@@ -10,7 +11,7 @@ export class PubSubClient {
1011
this.topicName = topicName;
1112
}
1213

13-
async publishMessage(message: unknown) {
14+
async publishMessage(message: PubSubContactsMessage) {
1415
try {
1516
if (!this.topicName) {
1617
throw new Error("No pubsub topic name provided.");
@@ -23,7 +24,7 @@ export class PubSubClient {
2324

2425
infoLogger(
2526
PubSubClient.name,
26-
`Published message ${json} to topic ${this.topicName}`
27+
`Published ${message.contacts.length} contacts for user ${message.userId} to topic ${this.topicName}`
2728
);
2829
} catch (error) {
2930
console.error(error);
Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,7 @@
1+
import { Contact } from "./contact.model";
2+
3+
export type PubSubContactsMessage = {
4+
userId: string;
5+
timestamp: number;
6+
contacts: Contact[];
7+
};

0 commit comments

Comments
 (0)