Browse Source

Merge branch 'minor' into major

Michael Bromley 3 years ago
parent
commit
1888f177bc

+ 1 - 1
packages/admin-ui/src/lib/core/src/shared/components/rich-text-editor/prosemirror/context-menu/context-menu.service.ts

@@ -60,7 +60,7 @@ export class ContextMenuService {
         const visible$ = this.menuIsVisible$.pipe(filter(val => val === true));
 
         const isVisible$ = this.menuIsVisible$.pipe(
-            delayWhen(value => (value ? of(value) : interval(100).pipe(takeUntil(visible$)))),
+            delayWhen(value => (value ? of(value) : interval(250).pipe(takeUntil(visible$)))),
             distinctUntilChanged(),
         );
         this.contextMenu$ = combineLatest(groupedConfig$, isVisible$).pipe(

+ 1 - 0
packages/core/src/service/index.ts

@@ -7,6 +7,7 @@ export * from './helpers/fulfillment-state-machine/fulfillment-state';
 export * from './helpers/list-query-builder/list-query-builder';
 export * from './helpers/locale-string-hydrator/locale-string-hydrator';
 export * from './helpers/order-calculator/order-calculator';
+export * from './helpers/order-calculator/prorate';
 export * from './helpers/order-merger/order-merger';
 export * from './helpers/order-modifier/order-modifier';
 export * from './helpers/order-state-machine/order-state';

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

@@ -267,6 +267,12 @@ export class CollectionService implements OnModuleInit {
         }
         const pickProps = pick(['id', 'name', 'slug']);
         const ancestors = await this.getAncestors(collection.id, ctx);
+        if (collection.name == null || collection.slug == null) {
+            collection = this.translator.translate(
+                await this.connection.getEntityOrThrow(ctx, Collection, collection.id),
+                ctx,
+            );
+        }
         return [pickProps(rootCollection), ...ancestors.map(pickProps).reverse(), pickProps(collection)];
     }
 

+ 2 - 1
packages/create/src/helpers.ts

@@ -247,10 +247,11 @@ export function getDependencies(
         `@vendure/email-plugin${vendurePkgVersion}`,
         `@vendure/asset-server-plugin${vendurePkgVersion}`,
         `@vendure/admin-ui-plugin${vendurePkgVersion}`,
+        'dotenv',
         dbDriverPackage(dbType),
         `typescript@${TYPESCRIPT_VERSION}`,
     ];
-    const devDependencies = ['concurrently', 'dotenv', 'ts-node'];
+    const devDependencies = ['concurrently', 'ts-node'];
     return { dependencies, devDependencies };
 }
 

+ 16 - 1
packages/email-plugin/src/event-handler.ts

@@ -130,6 +130,7 @@ import {
  */
 export class EmailEventHandler<T extends string = string, Event extends EventWithContext = EventWithContext> {
     private setRecipientFn: (event: Event) => string;
+    private setLanguageCodeFn: (event: Event) => LanguageCode | undefined;
     private setTemplateVarsFn: SetTemplateVarsFn<Event>;
     private setAttachmentsFn?: SetAttachmentsFn<Event>;
     private setOptionalAddressFieldsFn?: SetOptionalAddressFieldsFn<Event>;
@@ -178,6 +179,19 @@ export class EmailEventHandler<T extends string = string, Event extends EventWit
         return this;
     }
 
+    /**
+     * @description
+     * A function which allows to override the language of the email. If not defined, the language from the context will be used.
+     *
+     * @since 1.8.0
+     */
+    setLanguageCode(
+        setLanguageCodeFn: (event: Event) => LanguageCode | undefined,
+    ): EmailEventHandler<T, Event> {
+        this.setLanguageCodeFn = setLanguageCodeFn;
+        return this;
+    }
+
     /**
      * @description
      * A function which returns an object hash of variables which will be made available to the Handlebars template
@@ -343,7 +357,8 @@ export class EmailEventHandler<T extends string = string, Event extends EventWit
             );
         }
         const { ctx } = event;
-        const configuration = this.getBestConfiguration(ctx.channel.code, ctx.languageCode);
+        const languageCode = this.setLanguageCodeFn?.(event) || ctx.languageCode;
+        const configuration = this.getBestConfiguration(ctx.channel.code, languageCode);
         const subject = configuration ? configuration.subject : this.defaultSubject;
         if (subject == null) {
             throw new Error(

+ 22 - 0
packages/email-plugin/src/plugin.spec.ts

@@ -369,6 +369,28 @@ describe('EmailPlugin', () => {
             expect(onSend.mock.calls[1][0].subject).toBe('Servus, Test!');
             expect(onSend.mock.calls[1][0].body).toContain('German body.');
         });
+
+        it('set LanguageCode', async () => {
+            const handler = new EmailEventListener('test')
+                .on(MockEvent)
+                .setFrom('"test from" <noreply@test.com>')
+                .setSubject('Hello, {{ name }}!')
+                .setRecipient(() => 'test@test.com')
+                .setLanguageCode(() => LanguageCode.de)
+                .setTemplateVars(() => ({ name: 'Test' }))
+                .addTemplate({
+                    channelCode: 'default',
+                    languageCode: LanguageCode.de,
+                    templateFile: 'body.de.hbs',
+                    subject: 'Servus, {{ name }}!',
+                });
+
+            const ctxEn = RequestContext.deserialize({ ...ctx, _languageCode: LanguageCode.en } as any);
+            eventBus.publish(new MockEvent(ctxEn, true));
+            await pause();
+            expect(onSend.mock.calls[1][0].subject).toBe('Servus, Test!');
+            expect(onSend.mock.calls[1][0].body).toContain('German body.');
+        });
     });
 
     describe('loadData', () => {

+ 3 - 75
packages/email-plugin/src/types.ts

@@ -2,6 +2,7 @@ import { LanguageCode } from '@vendure/common/lib/generated-types';
 import { Omit } from '@vendure/common/lib/omit';
 import { Injector, RequestContext, VendureEvent } from '@vendure/core';
 import { Attachment } from 'nodemailer/lib/mailer';
+import SMTPTransport from 'nodemailer/lib/smtp-transport';
 
 import { EmailEventHandler } from './event-handler';
 
@@ -97,20 +98,6 @@ export interface EmailPluginDevModeOptions extends Omit<EmailPluginOptions, 'tra
     route: string;
 }
 
-/**
- * @description
- * The credentials used for sending email via SMTP
- *
- * @docsCategory EmailPlugin
- * @docsPage Email Plugin Types
- */
-export interface SMTPCredentials {
-    /** @description The username */
-    user: string;
-    /** @description The password */
-    pass: string;
-}
-
 /**
  * @description
  * A union of all the possible transport options for sending emails.
@@ -127,58 +114,13 @@ export type EmailTransportOptions =
 
 /**
  * @description
- * A subset of the SMTP transport options of [Nodemailer](https://nodemailer.com/smtp/)
+ * The SMTP transport options of [Nodemailer](https://nodemailer.com/smtp/)
  *
  * @docsCategory EmailPlugin
  * @docsPage Transport Options
  */
-export interface SMTPTransportOptions {
+export interface SMTPTransportOptions extends SMTPTransport.Options {
     type: 'smtp';
-    /**
-     * @description
-     * the hostname or IP address to connect to (defaults to ‘localhost’)
-     */
-    host: string;
-    /**
-     * @description
-     * The port to connect to (defaults to 25 or 465)
-     */
-    port: number;
-    /**
-     * @description
-     * Defines authentication data
-     */
-    auth: SMTPCredentials;
-    /**
-     * @description
-     * Defines if the connection should use SSL (if true) or not (if false)
-     */
-    secure?: boolean;
-    /**
-     * @description
-     * Turns off STARTTLS support if true
-     */
-    ignoreTLS?: boolean;
-    /**
-     * @description
-     * Forces the client to use STARTTLS. Returns an error if upgrading the connection is not possible or fails.
-     */
-    requireTLS?: boolean;
-    /**
-     * @description
-     * Optional hostname of the client, used for identifying to the server
-     */
-    name?: string;
-    /**
-     * @description
-     * The local interface to bind to for network connections
-     */
-    localAddress?: string;
-    /**
-     * @description
-     * Defines preferred authentication method, e.g. ‘PLAIN’
-     */
-    authMethod?: string;
     /**
      * @description
      * If true, uses the configured {@link VendureLogger} to log messages from Nodemailer as it interacts with
@@ -187,20 +129,6 @@ export interface SMTPTransportOptions {
      * @default false
      */
     logging?: boolean;
-    /**
-     * @description
-     * If set to true, then logs SMTP traffic without message content.
-     *
-     * @default false
-     */
-    transactionLog?: boolean;
-    /**
-     * @description
-     * If set to true, then logs SMTP traffic and message content, otherwise logs only transaction events.
-     *
-     * @default false
-     */
-    debug?: boolean;
 }
 
 /**

+ 6 - 1
packages/payments-plugin/src/braintree/braintree.handler.ts

@@ -41,7 +41,12 @@ export const braintreePaymentMethodHandler = new PaymentMethodHandler({
         try {
             await entityHydrator.hydrate(ctx, order, { relations: ['customer'] });
             const customer = order.customer;
-            if (options.storeCustomersInBraintree && ctx.activeUserId && customer) {
+            if (
+                options.storeCustomersInBraintree &&
+                ctx.activeUserId &&
+                customer &&
+                metadata.includeCustomerId !== false
+            ) {
                 customerId = await getBraintreeCustomerId(ctx, gateway, customer);
             }
             return processPayment(ctx, gateway, order, amount, metadata.nonce, customerId, options);

+ 20 - 0
packages/payments-plugin/src/braintree/braintree.plugin.ts

@@ -215,6 +215,26 @@ import { BraintreePluginOptions } from './types';
  * `, { includeCustomerId: false });
  * ```
  *
+ * as well as in the metadata of the `addPaymentToOrder` mutation:
+ *
+ * ```TypeScript
+ * const { addPaymentToOrder } = await graphQlClient.query(gql`
+ *   mutation AddPayment($input: PaymentInput!) {
+ *     addPaymentToOrder(input: $input) {
+ *       ...Order
+ *       ...ErrorResult
+ *     }
+ *   }`, {
+ *     input: {
+ *       method: 'braintree',
+ *       metadata: {
+ *         ...paymentResult,
+ *         includeCustomerId: false,
+ *       },
+ *     }
+ *   );
+ * ```
+ *
  * @docsCategory payments-plugin
  * @docsPage BraintreePlugin
  */