-
Notifications
You must be signed in to change notification settings - Fork 593
/
Copy pathintegration-zapier.plugin.ts
102 lines (94 loc) · 3.24 KB
/
integration-zapier.plugin.ts
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
import { Logger } from '@nestjs/common';
import { ApplicationPluginConfig, CustomEmbeddedFieldConfig } from '@gauzy/common';
import { GauzyCorePlugin as Plugin, IOnPluginBootstrap, IOnPluginDestroy } from '@gauzy/plugin';
import { ZapierModule } from './zapier.module';
import { ZapierWebhookSubscription } from './zapier-webhook-subscription.entity';
import { ConfigService } from '@nestjs/config';
@Plugin({
/**
* An array of modules that will be imported and registered with the plugin.
*/
imports: [ZapierModule],
/**
* Entity needed for Zapier integration that extends the existing
* IntegrationSetting entity to store webhook subscription data
*/
entities: [ZapierWebhookSubscription],
/**
* A callback that receives the main plugin configuration object and allows
* custom modifications before returning the final configuration.
*
* @param {ApplicationPluginConfig} config - The initial plugin configuration object.
* @returns {ApplicationPluginConfig} - The modified plugin configuration object.
*/
configuration: (config: ApplicationPluginConfig): ApplicationPluginConfig => {
// Initialize customFields if it doesn't exist
if (!config.customFields) {
config.customFields = {};
}
// Add custom fields for Zapier webhook subscriptions
const integrationSettingFields: CustomEmbeddedFieldConfig[] = [
{
name: 'webhookSubscriptions',
type: 'relation',
relationType: 'one-to-many',
entity: ZapierWebhookSubscription,
nullable: true,
onDelete: 'CASCADE'
}
];
// Add custom fields for Zapier webhook subscription details
const webhookSubscriptionFields: CustomEmbeddedFieldConfig[] = [
{
name: 'targetUrl',
type: 'string',
nullable: false,
index: true
},
{
name: 'event',
type: 'string',
nullable: false,
index: true
},
{
name: 'isActive',
type: 'boolean',
nullable: false,
default: true
}
];
// Update the customFields object properties instead of reassignment
Object.assign(config.customFields, {
IntegrationSetting: integrationSettingFields,
ZapierWebhookSubscription: webhookSubscriptionFields
});
return config;
}
})
export class IntegrationZapierPlugin implements IOnPluginBootstrap, IOnPluginDestroy {
private readonly logger = new Logger(IntegrationZapierPlugin.name);
constructor(private readonly _config: ConfigService) { }
/**
* Called when the plugin is being initialized.
*/
onPluginBootstrap(): void | Promise<void> {
this.logger.log(`${IntegrationZapierPlugin.name} is being bootstrapped...`);
// Log Zapier configuration status
const clientId = this._config.get<string>('zapier.clientId');
const clientSecret = this._config.get<string>('zapier.clientSecret');
const apiBaseUrl = this._config.get<string>('baseUrl');
if (!clientId || !clientSecret) {
this.logger.warn('Zapier OAuth credentials not fully configured! Please set GAUZY_ZAPIER_CLIENT_ID and GAUZY_ZAPIER_CLIENT_SECRET')
} else {
this.logger.log('Zapier OAuth credentials configured successfully');
}
this.logger.debug(`Zapier API base URL: ${apiBaseUrl}`);
}
/**
* Called when the plugin is being destroyed.
*/
onPluginDestroy(): void | Promise<void> {
this.logger.log(`${IntegrationZapierPlugin.name} is being destroyed...`)
}
}