Przeglądaj źródła

chore: Remove some deprecated APIs

Michael Bromley 2 lat temu
rodzic
commit
220322b9e7

+ 1 - 0
docs/content/migrating-from-v1/breaking-api-changes.md

@@ -208,3 +208,4 @@ If you are using the `@vendure/ui-devkit` package to generate custom ui extensio
        ```
   2. Start the server and login as administrator. For each channel that you'd like to use Stripe payments, you need to create a payment method with payment handler Stripe payment and the apiKey and webhookSigningSecret belonging to that channel's Stripe account.
 - If you are using the **BullMQJobQueuePlugin**, the minimum Redis recommended version is 6.2.0.
+- The `WorkerHealthIndicator` which was deprecated in v1.3.0 has been removed, as well as the `jobQueueOptions.enableWorkerHealthCheck` config option.

+ 1 - 1
packages/core/src/config/promotion/conditions/customer-group-condition.ts

@@ -5,7 +5,7 @@ import { Subscription } from 'rxjs';
 import { TtlCache } from '../../../common/ttl-cache';
 import { idsAreEqual } from '../../../common/utils';
 import { EventBus } from '../../../event-bus/event-bus';
-import { CustomerGroupEvent } from '../../../event-bus/events/customer-group-event';
+import { CustomerGroupEvent } from '../../../event-bus/events/customer-group-change-event';
 import { PromotionCondition } from '../promotion-condition';
 
 let customerService: import('../../../service/services/customer.service').CustomerService;

+ 0 - 14
packages/core/src/config/vendure-config.ts

@@ -888,20 +888,6 @@ export interface JobQueueOptions {
      * _processed_ or not.
      */
     activeQueues?: string[];
-    /**
-     * @description
-     * When set to `true`, a health check will be run on the worker. This is done by
-     * adding a `check-worker-health` job to the job queue, which, when successfully
-     * processed by the worker, indicates that it is healthy.
-     *
-     * **Important Note:** This health check is unreliable and can be affected by
-     * existing long running jobs, see [this issue](https://github.com/vendure-ecommerce/vendure/issues/1112)
-     * for further details. For this reason, the health check will be removed entirely in the next major version.
-     *
-     * @since 1.3.0
-     * @default false
-     */
-    enableWorkerHealthCheck?: boolean;
     /**
      * @description
      * Prefixes all job queue names with the passed string. This is useful with multiple deployments

+ 24 - 0
packages/core/src/event-bus/events/customer-group-change-event.ts

@@ -0,0 +1,24 @@
+import { RequestContext } from '../../api/common/request-context';
+import { Customer } from '../../entity/customer/customer.entity';
+import { CustomerGroup } from '../../entity/customer-group/customer-group.entity';
+import { VendureEvent } from '../vendure-event';
+
+/**
+ * @description
+ * This event is fired whenever one or more {@link Customer} is assigned to or removed from a
+ * {@link CustomerGroup}.
+ *
+ * @docsCategory events
+ * @docsPage Event Types
+ * @since 1.4
+ */
+export class CustomerGroupChangeEvent extends VendureEvent {
+    constructor(
+        public ctx: RequestContext,
+        public customers: Customer[],
+        public customGroup: CustomerGroup,
+        public type: 'assigned' | 'removed',
+    ) {
+        super();
+    }
+}

+ 0 - 29
packages/core/src/event-bus/events/customer-group-entity-event.ts

@@ -1,29 +0,0 @@
-import { CreateCustomerGroupInput, UpdateCustomerGroupInput } from '@vendure/common/lib/generated-types';
-import { ID } from '@vendure/common/lib/shared-types';
-
-import { RequestContext } from '../../api';
-import { CustomerGroup } from '../../entity';
-import { VendureEntityEvent } from '../vendure-entity-event';
-
-type CustomerGroupInputTypes = CreateCustomerGroupInput | UpdateCustomerGroupInput | ID;
-
-/**
- * @description
- * This event is fired whenever a {@link CustomerGroup} is added, updated or deleted.
- * Use this event instead of {@link CustomerGroupEvent} until the next major version!
- *
- * @docsCategory events
- * @docsPage Event Types
- * @since 1.4
- */
-export class CustomerGroupEntityEvent extends VendureEntityEvent<CustomerGroup, CustomerGroupInputTypes> {
-    // TODO: Rename to CustomerGroupEvent in v2
-    constructor(
-        ctx: RequestContext,
-        entity: CustomerGroup,
-        type: 'created' | 'updated' | 'deleted',
-        input?: CustomerGroupInputTypes,
-    ) {
-        super(entity, type, ctx, input);
-    }
-}

+ 14 - 31
packages/core/src/event-bus/events/customer-group-event.ts

@@ -1,44 +1,27 @@
-import { RequestContext } from '../../api/common/request-context';
-import { Customer } from '../../entity/customer/customer.entity';
-import { CustomerGroup } from '../../entity/customer-group/customer-group.entity';
-import { VendureEvent } from '../vendure-event';
+import { CreateCustomerGroupInput, UpdateCustomerGroupInput } from '@vendure/common/lib/generated-types';
+import { ID } from '@vendure/common/lib/shared-types';
 
-/**
- * @description
- * This event is fired whenever one or more {@link Customer} is assigned to or removed from a
- * {@link CustomerGroup}.
- *
- * @docsCategory events
- * @docsPage Event Types
- * @deprecated Use {@link CustomerGroupChangeEvent} instead
- */
-export class CustomerGroupEvent extends VendureEvent {
-    constructor(
-        public ctx: RequestContext,
-        public customers: Customer[],
-        public customGroup: CustomerGroup,
-        public type: 'assigned' | 'removed',
-    ) {
-        super();
-    }
-}
+import { RequestContext } from '../../api';
+import { CustomerGroup } from '../../entity';
+import { VendureEntityEvent } from '../vendure-entity-event';
+
+type CustomerGroupInputTypes = CreateCustomerGroupInput | UpdateCustomerGroupInput | ID;
 
 /**
  * @description
- * This event is fired whenever one or more {@link Customer} is assigned to or removed from a
- * {@link CustomerGroup}.
+ * This event is fired whenever a {@link CustomerGroup} is added, updated or deleted.
  *
  * @docsCategory events
  * @docsPage Event Types
  * @since 1.4
  */
-export class CustomerGroupChangeEvent extends VendureEvent {
+export class CustomerGroupEvent extends VendureEntityEvent<CustomerGroup, CustomerGroupInputTypes> {
     constructor(
-        public ctx: RequestContext,
-        public customers: Customer[],
-        public customGroup: CustomerGroup,
-        public type: 'assigned' | 'removed',
+        ctx: RequestContext,
+        entity: CustomerGroup,
+        type: 'created' | 'updated' | 'deleted',
+        input?: CustomerGroupInputTypes,
     ) {
-        super();
+        super(entity, type, ctx, input);
     }
 }

+ 1 - 1
packages/core/src/event-bus/index.ts

@@ -16,8 +16,8 @@ export * from './events/country-event';
 export * from './events/coupon-code-event';
 export * from './events/customer-address-event';
 export * from './events/customer-event';
-export * from './events/customer-group-entity-event';
 export * from './events/customer-group-event';
+export * from './events/customer-group-change-event';
 export * from './events/facet-event';
 export * from './events/facet-value-event';
 export * from './events/fulfillment-event';

+ 1 - 9
packages/core/src/health-check/health-check.module.ts

@@ -8,29 +8,21 @@ import { JobQueueModule } from '../job-queue/job-queue.module';
 
 import { HealthCheckRegistryService } from './health-check-registry.service';
 import { HealthController } from './health-check.controller';
-import { WorkerHealthIndicator } from './worker-health-indicator';
 
 @Module({
     imports: [TerminusModule, ConfigModule, JobQueueModule],
     controllers: [HealthController],
-    providers: [HealthCheckRegistryService, WorkerHealthIndicator],
+    providers: [HealthCheckRegistryService],
     exports: [HealthCheckRegistryService],
 })
 export class HealthCheckModule {
     constructor(
         private configService: ConfigService,
         private healthCheckRegistryService: HealthCheckRegistryService,
-        private worker: WorkerHealthIndicator,
     ) {
         // Register all configured health checks
         for (const strategy of this.configService.systemOptions.healthChecks) {
             this.healthCheckRegistryService.registerIndicatorFunction(strategy.getHealthIndicator());
         }
-
-        // TODO: Remove in v2
-        const { enableWorkerHealthCheck, jobQueueStrategy } = this.configService.jobQueueOptions;
-        if (enableWorkerHealthCheck && isInspectableJobQueueStrategy(jobQueueStrategy)) {
-            this.healthCheckRegistryService.registerIndicatorFunction([() => this.worker.isHealthy()]);
-        }
     }
 }

+ 0 - 58
packages/core/src/health-check/worker-health-indicator.ts

@@ -1,58 +0,0 @@
-import { Injectable, OnModuleInit } from '@nestjs/common';
-import { HealthCheckError, HealthIndicator, HealthIndicatorResult } from '@nestjs/terminus';
-
-import { ConfigService } from '../config/config.service';
-import { isInspectableJobQueueStrategy } from '../config/job-queue/inspectable-job-queue-strategy';
-import { Logger } from '../config/logger/vendure-logger';
-import { JobQueue } from '../job-queue/job-queue';
-import { JobQueueService } from '../job-queue/job-queue.service';
-
-export const WORKER_HEALTH_QUEUE_NAME = 'check-worker-health';
-
-@Injectable()
-export class WorkerHealthIndicator extends HealthIndicator implements OnModuleInit {
-    private queue: JobQueue | undefined;
-    constructor(private jobQueueService: JobQueueService, private configService: ConfigService) {
-        super();
-    }
-
-    async onModuleInit() {
-        const { jobQueueStrategy, enableWorkerHealthCheck } = this.configService.jobQueueOptions;
-        if (enableWorkerHealthCheck && isInspectableJobQueueStrategy(jobQueueStrategy)) {
-            this.queue = await this.jobQueueService.createQueue({
-                name: WORKER_HEALTH_QUEUE_NAME,
-                process: async job => {
-                    return { workerPid: process.pid };
-                },
-            });
-        }
-    }
-
-    /**
-     * This health check works by adding a job to the queue and checking whether it got picked up
-     * by a worker.
-     */
-    async isHealthy(): Promise<HealthIndicatorResult> {
-        if (this.queue) {
-            const job = await this.queue.add({});
-            let isHealthy: boolean;
-            try {
-                isHealthy = !!(await job.updates({ timeoutMs: 10000 }).toPromise());
-            } catch (e: any) {
-                Logger.error(e.message);
-                isHealthy = false;
-            }
-            const result = this.getStatus('worker', isHealthy);
-
-            if (isHealthy) {
-                return result;
-            }
-            throw new HealthCheckError('Worker health check failed', result);
-        } else {
-            throw new HealthCheckError(
-                'Current JobQueueStrategy does not support internal health checks',
-                this.getStatus('worker', false),
-            );
-        }
-    }
-}

+ 5 - 7
packages/core/src/service/services/customer-group.service.ts

@@ -20,8 +20,8 @@ import { TransactionalConnection } from '../../connection/transactional-connecti
 import { Customer } from '../../entity/customer/customer.entity';
 import { CustomerGroup } from '../../entity/customer-group/customer-group.entity';
 import { EventBus } from '../../event-bus/event-bus';
-import { CustomerGroupEntityEvent } from '../../event-bus/events/customer-group-entity-event';
-import { CustomerGroupChangeEvent, CustomerGroupEvent } from '../../event-bus/events/customer-group-event';
+import { CustomerGroupChangeEvent } from '../../event-bus/events/customer-group-change-event';
+import { CustomerGroupEvent } from '../../event-bus/events/customer-group-event';
 import { CustomFieldRelationService } from '../helpers/custom-field-relation/custom-field-relation.service';
 import { ListQueryBuilder } from '../helpers/list-query-builder/list-query-builder';
 import { patchEntity } from '../helpers/utils/patch-entity';
@@ -107,7 +107,7 @@ export class CustomerGroupService {
         }
         const savedCustomerGroup = await assertFound(this.findOne(ctx, newCustomerGroup.id));
         await this.customFieldRelationService.updateRelations(ctx, CustomerGroup, input, savedCustomerGroup);
-        this.eventBus.publish(new CustomerGroupEntityEvent(ctx, savedCustomerGroup, 'created', input));
+        this.eventBus.publish(new CustomerGroupEvent(ctx, savedCustomerGroup, 'created', input));
         return assertFound(this.findOne(ctx, savedCustomerGroup.id));
     }
 
@@ -121,7 +121,7 @@ export class CustomerGroupService {
             input,
             updatedCustomerGroup,
         );
-        this.eventBus.publish(new CustomerGroupEntityEvent(ctx, customerGroup, 'updated', input));
+        this.eventBus.publish(new CustomerGroupEvent(ctx, customerGroup, 'updated', input));
         return assertFound(this.findOne(ctx, customerGroup.id));
     }
 
@@ -130,7 +130,7 @@ export class CustomerGroupService {
         try {
             const deletedGroup = new CustomerGroup(group);
             await this.connection.getRepository(ctx, CustomerGroup).remove(group);
-            this.eventBus.publish(new CustomerGroupEntityEvent(ctx, deletedGroup, 'deleted', id));
+            this.eventBus.publish(new CustomerGroupEvent(ctx, deletedGroup, 'deleted', id));
             return {
                 result: DeletionResult.DELETED,
             };
@@ -163,7 +163,6 @@ export class CustomerGroupService {
         }
 
         await this.connection.getRepository(ctx, Customer).save(customers, { reload: false });
-        this.eventBus.publish(new CustomerGroupEvent(ctx, customers, group, 'assigned'));
         this.eventBus.publish(new CustomerGroupChangeEvent(ctx, customers, group, 'assigned'));
 
         return assertFound(this.findOne(ctx, group.id));
@@ -190,7 +189,6 @@ export class CustomerGroupService {
             });
         }
         await this.connection.getRepository(ctx, Customer).save(customers, { reload: false });
-        this.eventBus.publish(new CustomerGroupEvent(ctx, customers, group, 'removed'));
         this.eventBus.publish(new CustomerGroupChangeEvent(ctx, customers, group, 'removed'));
         return assertFound(this.findOne(ctx, group.id));
     }

+ 0 - 5
packages/core/src/service/services/order.service.ts

@@ -1505,11 +1505,6 @@ export class OrderService {
                 .getRepository(ctx, Session)
                 .update(sessions.map(s => s.id) as string[], { activeOrder: null });
         }
-
-        // TODO: v2 - Will not be needed after adding `{ onDelete: 'CASCADE' }` constraint to ShippingLine.order
-        for (const shippingLine of orderToDelete.shippingLines) {
-            await this.connection.getRepository(ctx, ShippingLine).delete(shippingLine.id);
-        }
         await this.connection.getRepository(ctx, Order).delete(orderToDelete.id);
     }
 

+ 0 - 7
packages/core/src/service/services/product-option-group.service.ts

@@ -173,13 +173,6 @@ export class ProductOptionGroupService {
                 await this.connection.getRepository(ctx, Product).save(product, { reload: false });
             }
 
-            // TODO: V2 rely on onDelete: CASCADE rather than this manual loop
-            for (const translation of optionGroup.translations) {
-                await this.connection
-                    .getRepository(ctx, ProductOptionGroupTranslation)
-                    .remove(translation as ProductOptionGroupTranslation);
-            }
-
             try {
                 await this.connection.getRepository(ctx, ProductOptionGroup).remove(optionGroup);
             } catch (e: any) {

+ 0 - 6
packages/core/src/service/services/product-option.service.ts

@@ -126,12 +126,6 @@ export class ProductOptionService {
         } else {
             // hard delete
             try {
-                // TODO: V2 rely on onDelete: CASCADE rather than this manual loop
-                for (const translation of productOption.translations) {
-                    await this.connection
-                        .getRepository(ctx, ProductOptionTranslation)
-                        .remove(translation as ProductOptionTranslation);
-                }
                 await this.connection.getRepository(ctx, ProductOption).remove(productOption);
             } catch (e: any) {
                 Logger.error(e.message, undefined, e.stack);