Skip to content

Commit b9b4fd4

Browse files
committed
Apply feedback
1 parent e8da54c commit b9b4fd4

File tree

4 files changed

+22
-76
lines changed

4 files changed

+22
-76
lines changed

connectors/src/admin/db.ts

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -25,7 +25,6 @@ import {
2525
import {
2626
IntercomArticle,
2727
IntercomCollection,
28-
IntercomConnectorState,
2928
} from "@connectors/lib/models/intercom";
3029
import logger from "@connectors/logger/logger";
3130

@@ -49,7 +48,6 @@ async function main(): Promise<void> {
4948
await NotionConnectorPageCacheEntry.sync({ alter: true });
5049
await NotionConnectorResourcesToCheckCacheEntry.sync({ alter: true });
5150
await GoogleDriveConfig.sync({ alter: true });
52-
await IntercomConnectorState.sync({ alter: true });
5351
await IntercomCollection.sync({ alter: true });
5452
await IntercomArticle.sync({ alter: true });
5553

connectors/src/connectors/intercom/index.ts

Lines changed: 8 additions & 22 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,6 @@
11
import { validateAccessToken } from "@connectors/connectors/intercom/lib/intercom_api";
22
import { ConnectorPermissionRetriever } from "@connectors/connectors/interface";
3-
import { Connector, ModelId, sequelize_conn } from "@connectors/lib/models";
4-
import { IntercomConnectorState } from "@connectors/lib/models/intercom";
3+
import { Connector, ModelId } from "@connectors/lib/models";
54
import { getAccessTokenFromNango } from "@connectors/lib/nango_helpers";
65
import { Err, Ok, Result } from "@connectors/lib/result";
76
import logger from "@connectors/logger/logger";
@@ -36,26 +35,13 @@ export async function createIntercomConnector(
3635
}
3736

3837
try {
39-
const connector = await sequelize_conn.transaction(async (t) => {
40-
const connector = await Connector.create(
41-
{
42-
type: "intercom",
43-
connectionId: nangoConnectionId,
44-
workspaceAPIKey: dataSourceConfig.workspaceAPIKey,
45-
workspaceId: dataSourceConfig.workspaceId,
46-
dataSourceName: dataSourceConfig.dataSourceName,
47-
defaultNewResourcePermission: "read_write",
48-
},
49-
{ transaction: t }
50-
);
51-
await IntercomConnectorState.create(
52-
{
53-
connectorId: connector.id,
54-
},
55-
{ transaction: t }
56-
);
57-
58-
return connector;
38+
const connector = await Connector.create({
39+
type: "intercom",
40+
connectionId: nangoConnectionId,
41+
workspaceAPIKey: dataSourceConfig.workspaceAPIKey,
42+
workspaceId: dataSourceConfig.workspaceId,
43+
dataSourceName: dataSourceConfig.dataSourceName,
44+
defaultNewResourcePermission: "read_write",
5945
});
6046
// @todo Daph lauch workflow await launchIntercomSyncWorkflow(connector.id);
6147
return new Ok(connector.id.toString());

connectors/src/connectors/intercom/lib/intercom_api.ts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,8 @@
11
import { Client } from "intercom-client";
22

3-
export async function validateAccessToken(notionAccessToken: string) {
3+
export async function validateAccessToken(intercomAccessToken: string) {
44
const intercomClient = new Client({
5-
tokenAuth: { token: notionAccessToken },
5+
tokenAuth: { token: intercomAccessToken },
66
});
77
try {
88
await intercomClient.admins.list(); // trying a simple request

connectors/src/lib/models/intercom.ts

Lines changed: 12 additions & 50 deletions
Original file line numberDiff line numberDiff line change
@@ -9,50 +9,6 @@ import {
99

1010
import { Connector, sequelize_conn } from "@connectors/lib/models";
1111

12-
export class IntercomConnectorState extends Model<
13-
InferAttributes<IntercomConnectorState>,
14-
InferCreationAttributes<IntercomConnectorState>
15-
> {
16-
declare id: CreationOptional<number>;
17-
declare createdAt: CreationOptional<Date>;
18-
declare updatedAt: CreationOptional<Date>;
19-
20-
declare lastGarbageCollectionFinishTime?: Date;
21-
22-
declare connectorId: ForeignKey<Connector["id"]>;
23-
}
24-
25-
IntercomConnectorState.init(
26-
{
27-
id: {
28-
type: DataTypes.INTEGER,
29-
autoIncrement: true,
30-
primaryKey: true,
31-
},
32-
createdAt: {
33-
type: DataTypes.DATE,
34-
allowNull: false,
35-
defaultValue: DataTypes.NOW,
36-
},
37-
updatedAt: {
38-
type: DataTypes.DATE,
39-
allowNull: false,
40-
defaultValue: DataTypes.NOW,
41-
},
42-
lastGarbageCollectionFinishTime: {
43-
type: DataTypes.DATE,
44-
allowNull: true,
45-
},
46-
},
47-
{
48-
sequelize: sequelize_conn,
49-
modelName: "intercom_connector_states",
50-
indexes: [{ fields: ["connectorId"], unique: true }],
51-
}
52-
);
53-
54-
Connector.hasOne(IntercomConnectorState);
55-
5612
export class IntercomCollection extends Model<
5713
InferAttributes<IntercomCollection>,
5814
InferCreationAttributes<IntercomCollection>
@@ -61,7 +17,7 @@ export class IntercomCollection extends Model<
6117
declare createdAt: CreationOptional<Date>;
6218
declare updatedAt: CreationOptional<Date>;
6319

64-
declare workspaceId: string;
20+
declare intercomWorkspaceId: string;
6521
declare collectionId: string;
6622

6723
declare helpCenterId: string | null;
@@ -90,7 +46,7 @@ IntercomCollection.init(
9046
allowNull: false,
9147
defaultValue: DataTypes.NOW,
9248
},
93-
workspaceId: {
49+
intercomWorkspaceId: {
9450
type: DataTypes.STRING,
9551
allowNull: false,
9652
},
@@ -118,7 +74,10 @@ IntercomCollection.init(
11874
{
11975
sequelize: sequelize_conn,
12076
indexes: [
121-
{ fields: ["workspaceId", "collectionId", "connectorId"], unique: true },
77+
{
78+
fields: ["intercomWorkspaceId", "collectionId", "connectorId"],
79+
unique: true,
80+
},
12281
{ fields: ["connectorId"] },
12382
{ fields: ["collectionId"] },
12483
],
@@ -135,7 +94,7 @@ export class IntercomArticle extends Model<
13594
declare createdAt: CreationOptional<Date>;
13695
declare updatedAt: CreationOptional<Date>;
13796

138-
declare workspaceId: string;
97+
declare intercomWorkspaceId: string;
13998
declare articleId: string;
14099
declare authorId: string;
141100

@@ -164,7 +123,7 @@ IntercomArticle.init(
164123
allowNull: false,
165124
defaultValue: DataTypes.NOW,
166125
},
167-
workspaceId: {
126+
intercomWorkspaceId: {
168127
type: DataTypes.STRING,
169128
allowNull: false,
170129
},
@@ -192,7 +151,10 @@ IntercomArticle.init(
192151
{
193152
sequelize: sequelize_conn,
194153
indexes: [
195-
{ fields: ["workspaceId", "articleId", "connectorId"], unique: true },
154+
{
155+
fields: ["intercomWorkspaceId", "articleId", "connectorId"],
156+
unique: true,
157+
},
196158
{ fields: ["connectorId"] },
197159
{ fields: ["articleId"] },
198160
],

0 commit comments

Comments
 (0)