|
1 | 1 | import { Logger } from '@nestjs/common';
|
2 |
| -import * as chalk from 'chalk'; |
3 |
| -import { ApplicationPluginConfig, CustomEmbeddedFieldConfig, CustomEmbeddedFields } from '@gauzy/common'; |
| 2 | +import { ConfigService } from '@nestjs/config'; |
| 3 | +import { ApplicationPluginConfig, CustomEmbeddedFieldConfig } from '@gauzy/common'; |
4 | 4 | import { GauzyCorePlugin as Plugin, IOnPluginBootstrap, IOnPluginDestroy } from '@gauzy/plugin';
|
5 | 5 | import { ZapierModule } from './zapier.module';
|
6 | 6 | import { ZapierWebhookSubscription } from './zapier-webhook-subscription.entity';
|
7 | 7 |
|
8 |
| -// Extend the CustomEmbeddedFields interface to include our custom entities |
9 |
| -interface ZapierCustomFields extends CustomEmbeddedFields { |
10 |
| - IntegrationSetting?: CustomEmbeddedFieldConfig[]; |
11 |
| - ZapierWebhookSubscription?: CustomEmbeddedFieldConfig[]; |
12 |
| -} |
13 |
| - |
14 | 8 | @Plugin({
|
15 | 9 | /**
|
16 | 10 | * An array of modules that will be imported and registered with the plugin.
|
@@ -78,25 +72,33 @@ interface ZapierCustomFields extends CustomEmbeddedFields {
|
78 | 72 | }
|
79 | 73 | })
|
80 | 74 | export class IntegrationZapierPlugin implements IOnPluginBootstrap, IOnPluginDestroy {
|
81 |
| - // We enable by default additional logging for each event to avoid cluttering the logs |
82 |
| - private logEnabled = true; |
| 75 | + private readonly logger = new Logger(IntegrationZapierPlugin.name); |
| 76 | + |
| 77 | + constructor(private readonly _config: ConfigService) {} |
83 | 78 |
|
84 | 79 | /**
|
85 |
| - * Called when the plugin is being initialized. |
| 80 | + * Lifecycle hook invoked during the plugin's bootstrap phase. |
| 81 | + * Validates essential Zapier OAuth configurations and logs the API base URL. |
86 | 82 | */
|
87 |
| - onPluginBootstrap(): void | Promise<void> { |
88 |
| - if (this.logEnabled) { |
89 |
| - console.log(chalk.green(`${IntegrationZapierPlugin.name} is being bootstrapped...`)); |
| 83 | + onPluginBootstrap(): void { |
| 84 | + this.logger.log(`${IntegrationZapierPlugin.name} is being bootstrapped...`); |
| 85 | + |
| 86 | + const clientId = this._config.get<string>('zapier.clientId'); |
| 87 | + const clientSecret = this._config.get<string>('zapier.clientSecret'); |
| 88 | + |
| 89 | + if (!clientId || !clientSecret) { |
| 90 | + this.logger.warn( |
| 91 | + 'Zapier OAuth credentials are not fully configured. Please set GAUZY_ZAPIER_CLIENT_ID and GAUZY_ZAPIER_CLIENT_SECRET.' |
| 92 | + ); |
| 93 | + } else { |
| 94 | + this.logger.log('Zapier OAuth credentials are configured successfully.'); |
90 | 95 | }
|
91 | 96 | }
|
92 | 97 |
|
93 | 98 | /**
|
94 | 99 | * Called when the plugin is being destroyed.
|
95 | 100 | */
|
96 | 101 | onPluginDestroy(): void | Promise<void> {
|
97 |
| - if (this.logEnabled) { |
98 |
| - const logger = new Logger(IntegrationZapierPlugin.name); |
99 |
| - logger.log(`${IntegrationZapierPlugin.name} is being destroyed...`) |
100 |
| - } |
| 102 | + this.logger.log(`${IntegrationZapierPlugin.name} is being destroyed...`); |
101 | 103 | }
|
102 | 104 | }
|
0 commit comments