Browse Source

Merge branch 'minor' into major

Michael Bromley 2 years ago
parent
commit
c98ba2f32d

+ 15 - 0
CHANGELOG.md

@@ -1,3 +1,18 @@
+## <small>1.9.3 (2023-02-15)</small>
+
+
+#### Fixes
+
+* **admin-ui** Fix UI for long channel list tab on Administrator detail page (#2018) ([7fdd875](https://github.com/vendure-ecommerce/vendure/commit/7fdd875)), closes [#2018](https://github.com/vendure-ecommerce/vendure/issues/2018)
+* **admin-ui** Redirect to loginUrl if configured on Forbidden GraphQL error (#2012) ([53b78d2](https://github.com/vendure-ecommerce/vendure/commit/53b78d2)), closes [#2012](https://github.com/vendure-ecommerce/vendure/issues/2012)
+* **core** Fix auth of admin and customer users with the same email (#2016) ([3c76b2f](https://github.com/vendure-ecommerce/vendure/commit/3c76b2f)), closes [#2016](https://github.com/vendure-ecommerce/vendure/issues/2016)
+* **core** Fix deletion of product options (#2017) ([a3698b5](https://github.com/vendure-ecommerce/vendure/commit/a3698b5)), closes [#2017](https://github.com/vendure-ecommerce/vendure/issues/2017)
+* **payments-plugin** Improve handling of Braintree customerId errors ([4d9f49e](https://github.com/vendure-ecommerce/vendure/commit/4d9f49e))
+
+#### Features
+
+* **asset-server-plugin** Add configurable Cache-Control header (#2005) ([316d04d](https://github.com/vendure-ecommerce/vendure/commit/316d04d)), closes [#2005](https://github.com/vendure-ecommerce/vendure/issues/2005)
+
 ## <small>1.9.2 (2023-01-18)</small>
 
 

+ 3 - 1
docs/content/deployment/_index.md

@@ -8,4 +8,6 @@ showtoc: false
 
 This section contains guides for deploying a Vendure application to production.
 
-We are planning to publish specific guides for popular platforms soon. For now, you can find platform-specific information in our [Deployment discussion category](https://github.com/vendure-ecommerce/vendure/discussions/categories/deployment).
+For a quick and simple deployment, we recommend following the [Deploying to Northflank guide]({{< relref "deploy-to-northflank" >}}).
+
+Community-contributed information about deploying to other platforms can be found in our [Deployment discussion category](https://github.com/vendure-ecommerce/vendure/discussions/categories/deployment).

BIN
docs/content/deployment/deploy-to-northflank/01-create-template-screen.webp


BIN
docs/content/deployment/deploy-to-northflank/02-paste-config.webp


BIN
docs/content/deployment/deploy-to-northflank/03-run-template.webp


BIN
docs/content/deployment/deploy-to-northflank/04-find-project.webp


BIN
docs/content/deployment/deploy-to-northflank/05-server-service.webp


BIN
docs/content/deployment/deploy-to-northflank/06-find-url.webp


BIN
docs/content/deployment/deploy-to-northflank/deploy-to-northflank.webp


+ 241 - 0
docs/content/deployment/deploy-to-northflank/index.md

@@ -0,0 +1,241 @@
+---
+title: "Deploying to Northflank"
+showtoc: true
+images: 
+    - "/docs/deployment/deploy-to-northflank/deploy-to-northflank.webp"
+---
+
+{{< figure src="./deploy-to-northflank.webp" >}}
+
+[Northflank](https://northflank.com) is a comprehensive developer platform to build and scale your apps. It has an outstanding developer experience and has a free tier for small projects, and is well-suited for deploying and scaling Vendure applications.
+
+This guide will walk you through the steps to deploy [a sample Vendure application](https://github.com/vendure-ecommerce/one-click-deploy) to Northflank.
+
+## Set up your free Northflank account
+
+Go to the Northflank [sign up page](https://app.northflank.com/signup) to create a new account. As part of the sign-up you'll be asked for credit card details, but you won't be charged unless you upgrade to a paid plan.
+
+## Create a custom template
+
+A template defines the infrastructure that is needed to run your Vendure server. Namely, a **server**, a **worker**, and a **Postgres database**.
+
+Click the templates menu item in the left sidebar and click the "Create template" button.
+
+{{< figure src="./01-create-template-screen.webp" >}}
+
+Fill in the name of the template (though note that the name will be replaced by the name "Vendure Template" based on the configuration below).
+
+Now paste the following configuration into the "Template" code editor:
+
+{{< figure src="./02-paste-config.webp" >}}
+
+
+```json
+{
+  "name": "Vendure Template",
+  "description": "Vendure is a modern, open-source headless commerce framework built with TypeScript & Node.js.",
+  "apiVersion": "v1",
+  "project": {
+    "spec": {
+      "name": "Vendure Template",
+      "description": "Vendure is a modern, open-source headless commerce framework built with TypeScript & Node.js.",
+      "region": "europe-west",
+      "color": "#57637A"
+    }
+  },
+  "spec": {
+    "kind": "Workflow",
+    "spec": {
+      "type": "sequential",
+      "steps": [
+        {
+          "kind": "Addon",
+          "spec": {
+            "name": "database",
+            "type": "postgres",
+            "version": "latest",
+            "billing": {
+              "deploymentPlan": "nf-compute-10",
+              "storageClass": "ssd",
+              "storage": 4096,
+              "replicas": 1
+            },
+            "tlsEnabled": false,
+            "externalAccessEnabled": false
+          }
+        },
+        {
+          "kind": "SecretGroup",
+          "spec": {
+            "name": "secrets",
+            "secretType": "environment-arguments",
+            "priority": 10,
+            "secrets": {
+              "variables": {
+                "APP_ENV": "production",
+                "COOKIE_SECRET": "${fn.randomSecret(32)}",
+                "SUPERADMIN_USERNAME": "superadmin",
+                "SUPERADMIN_PASSWORD": "superadmin",
+                "DB_SCHEMA": "public"
+              }
+            },
+            "addonDependencies": [
+              {
+                "addonId": "database",
+                "keys": [
+                  {
+                    "keyName": "HOST",
+                    "aliases": ["DB_HOST"]
+                  },
+                  {
+                    "keyName": "PORT",
+                    "aliases": ["DB_PORT"]
+                  },
+                  {
+                    "keyName": "DATABASE",
+                    "aliases": ["DB_NAME"]
+                  },
+                  {
+                    "keyName": "USERNAME",
+                    "aliases": ["DB_USERNAME"]
+                  },
+                  {
+                    "keyName": "PASSWORD",
+                    "aliases": ["DB_PASSWORD"]
+                  }
+                ]
+              }
+            ]
+          }
+        },
+        {
+          "kind": "BuildService",
+          "spec": {
+            "name": "build",
+            "billing": {
+              "deploymentPlan": "nf-compute-10"
+            },
+            "vcsData": {
+              "projectUrl": "https://github.com/vendure-ecommerce/one-click-deploy",
+              "projectType": "github"
+            },
+            "buildSettings": {
+              "dockerfile": {
+                "buildEngine": "kaniko",
+                "dockerFilePath": "/Dockerfile",
+                "dockerWorkDir": "/",
+                "useCache": false
+              }
+            }
+          }
+        },
+        {
+          "kind": "Workflow",
+          "spec": {
+            "type": "parallel",
+            "steps": [
+              {
+                "kind": "DeploymentService",
+                "spec": {
+                  "name": "server",
+                  "billing": {
+                    "deploymentPlan": "nf-compute-10"
+                  },
+                  "deployment": {
+                    "instances": 1,
+                    "docker": {
+                      "configType": "customCommand",
+                      "customCommand": "yarn start:server"
+                    },
+                    "internal": {
+                      "id": "build",
+                      "branch": "master",
+                      "buildSHA": "latest"
+                    }
+                  },
+                  "ports": [
+                    {
+                      "name": "p01",
+                      "internalPort": 3000,
+                      "public": true,
+                      "protocol": "HTTP"
+                    }
+                  ]
+                }
+              },
+              {
+                "kind": "DeploymentService",
+                "spec": {
+                  "name": "worker",
+                  "billing": {
+                    "deploymentPlan": "nf-compute-10"
+                  },
+                  "deployment": {
+                    "instances": 1,
+                    "docker": {
+                      "configType": "customCommand",
+                      "customCommand": "yarn start:worker"
+                    },
+                    "internal": {
+                      "id": "build",
+                      "branch": "master",
+                      "buildSHA": "latest"
+                    }
+                  }
+                }
+              }
+            ]
+          }
+        },
+        {
+          "kind": "Build",
+          "spec": {
+            "id": "build",
+            "type": "service",
+            "branch": "master"
+          }
+        }
+      ]
+    }
+  }
+}
+```
+
+Then click the "Create template" button.
+
+## Run the template
+
+Next, click the "run template" button to start the deployment process.
+
+{{< figure src="./03-run-template.webp" >}}
+
+Once the template run has completed, you should be able to see the newly-created project in the project selector.
+
+{{< figure src="./04-find-project.webp" >}}
+
+## Find the public URL
+
+Click the "Services" menu item in the left sidebar and then click the "Server" service.
+
+{{< figure src="./05-server-service.webp" >}}
+
+In the top right corner you'll see the public URL of your new Vendure server!
+
+Note that it may take a few minutes for the server to start up and populate all the test data because the free tier has limited CPU and memory resources.
+
+Once it is ready, you can navigate to the public URL and append `/admin` to the end of the URL to access the admin panel.
+
+{{< figure src="./06-find-url.webp" >}}
+
+
+Congratulations on deploying your Vendure server!
+
+
+## Next steps
+
+Now that you have a basic Vendure server up and running, you can explore some of the other features offered by Northflank that you might need for a full production setup:
+
+- [Set up a MinIO instance](https://northflank.com/docs/v1/application/databases-and-persistence/deploy-databases-on-northflank/deploy-minio-on-northflank) for storing assets using our [S3 asset storage integration]({{< relref "s3asset-storage-strategy" >}}#configures3assetstorage).
+- [Set up a Redis instance](https://northflank.com/docs/v1/application/databases-and-persistence/deploy-databases-on-northflank/deploy-redis-on-northflank) so that you can take advantage of our highly performant [BullMQJobQueuePlugin]({{< relref "bull-mqjob-queue-plugin" >}}) and set up [Redis-based session caching]({{< relref "session-cache-strategy" >}}) to handle multi-instance deployments.
+- With the above in place, you can safely start to [scale your server instances](https://northflank.com/docs/v1/application/scale/scaling-replicas) to handle more traffic. 
+- [Add a custom domain](https://northflank.com/docs/v1/application/domains/add-a-domain-to-your-account) using Northflank's powerful DNS management system.

+ 3 - 1
docs/content/developer-guide/importing-product-data.md

@@ -174,7 +174,7 @@ export const initialData: InitialData = {
 * `defaultZone`: Sets the default shipping & tax zone for the default Channel. The zone must correspond to a value of `zone` set in the `countries` array. 
 * `taxRates`: For each item, a new [TaxCategory]({{< relref "tax-category" >}}) is created, and then a [TaxRate]({{< relref "tax-rate" >}}) is created for each unique zone defined in the `countries` array. 
 * `shippingMethods`: Allows simple flat-rate [ShippingMethods]({{< relref "shipping-method" >}}) to be defined.
-* `collections`: Allows Collections to be created. Currently, only collections based on facet values can be created (`code: 'facet-value-filter'`). The `assetPaths` and `facetValueNames` value must correspond to a values specified in the products csv file. The name should match the value specified in the product csv file (or can be a normalized - lower-case & hyphenated - version thereof). If there are FacetValues in multiple Facets with the same name, the facet may be specified with a colon delimiter, e.g. `brand:apple`, `flavour: apple`.
+* `collections`: Allows Collections to be created. Currently, only collections based on facet values can be created (`code: 'facet-value-filter'`). The `assetPaths` and `facetValueNames` values must correspond to a value specified in the products csv file. The name should match the value specified in the product csv file (or can be a normalized - lower-case & hyphenated - version thereof). If there are FacetValues in multiple Facets with the same name, the facet may be specified with a colon delimiter, e.g. `brand:apple`, `flavour: apple`.
 
 ## Populating The Server
 
@@ -218,6 +218,8 @@ populate(
   },
 );
 ```
+**Attention:** When removing the `DefaultJobQueuePlugin` from the plugins list as in the code snippet above, one should manually rebuild the search index in order for the newly added products to appear.
+In the Admin UI this can be done by navigating to the Products page and clicking the gear icon next to the search input.
 
 ### Custom populate scripts
 

+ 1 - 1
docs/content/developer-guide/testing.md

@@ -95,7 +95,7 @@ afterAll(async () => {
 
 An explanation of the options:
 
-* `productsCsvPath` This is a path to a CSV file containing product data. See [Product Import Format]({{< relref "importing-product-data" >}}#product-import-format). You can see [an example used in the Vendure e2e tests](https://github.com/vendure-ecommerce/vendure/blob/master/packages/core/e2e/fixtures/e2e-products-full.csv) to get an idea of how it works. To start with you can just copy this file directly and use it as-is.
+* `productsCsvPath` This is a path to an optional CSV file containing product data. See [Product Import Format]({{< relref "importing-product-data" >}}#product-import-format). You can see [an example used in the Vendure e2e tests](https://github.com/vendure-ecommerce/vendure/blob/master/packages/core/e2e/fixtures/e2e-products-full.csv) to get an idea of how it works. To start with you can just copy this file directly and use it as-is.
 * `initialData` This is an object which defines how other non-product data (Collections, ShippingMethods, Countries etc.) is populated. See [Initial Data Format]({{< relref "importing-product-data" >}}#initial-data). You can [copy this example from the Vendure e2e tests](https://github.com/vendure-ecommerce/vendure/blob/master/e2e-common/e2e-initial-data.ts)
 * `customerCount` Specifies the number of fake Customers to create. Defaults to 10 if not specified.
 

+ 1 - 1
packages/core/src/service/services/product-variant.service.ts

@@ -740,7 +740,7 @@ export class ProductVariantService {
         if (
             !samplesEach(
                 optionIds,
-                optionGroups.map(g => g.options.map(o => o.id)),
+                activeOptions.map(g => g.options.map(o => o.id)),
             )
         ) {
             this.throwIncompatibleOptionsError(optionGroups);

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

@@ -101,7 +101,7 @@ import { BraintreePluginOptions } from './types';
  *       // Braintree account.
  *       paypal: {
  *         flow: 'checkout',
- *         amount: order.totalWithTax,
+ *         amount: order.totalWithTax / 100,
  *         currency: 'GBP',
  *       },
  *     }),

+ 23 - 2
packages/payments-plugin/src/braintree/braintree.resolver.ts

@@ -3,6 +3,7 @@ import { Args, Query, Resolver } from '@nestjs/graphql';
 import {
     ActiveOrderService,
     Ctx,
+    Customer,
     ID,
     InternalServerError,
     Logger,
@@ -48,10 +49,30 @@ export class BraintreeResolver {
             const args = await this.getPaymentMethodArgs(ctx);
             const gateway = getGateway(args, this.options);
             try {
-                const result = await gateway.clientToken.generate({
+                let result = await gateway.clientToken.generate({
                     customerId: includeCustomerId === false ? undefined : customerId,
                 });
-                return result.clientToken;
+                if (result.success === true) {
+                    return result.clientToken;
+                } else {
+                    if (result.message === 'Customer specified by customer_id does not exist') {
+                        // For some reason the custom_id is invalid. This could occur e.g. if the ID was created on the Sandbox endpoint and now
+                        // we switched to Production. In this case, we will remove it and allow a new one
+                        // to be generated when the payment is created.
+                        if (this.options.storeCustomersInBraintree) {
+                            order.customer.customFields.braintreeCustomerId = undefined;
+                            await this.connection.getRepository(ctx, Customer).save(order.customer);
+                        }
+                        result = await gateway.clientToken.generate({ customerId: undefined });
+                        if (result.success === true) {
+                            return result.clientToken;
+                        }
+                    }
+                    Logger.error(`Could not generate Braintree clientToken: ${result.message}`, loggerCtx);
+                    throw new InternalServerError(
+                        `Could not generate Braintree clientToken: ${result.message}`,
+                    );
+                }
             } catch (e: any) {
                 Logger.error(
                     `Could not generate Braintree clientToken. Check the configured credentials.`,

+ 13 - 2
packages/testing/src/data-population/populate-for-testing.ts

@@ -35,11 +35,22 @@ export async function populateForTesting<T extends INestApplicationContext>(
     return app;
 }
 
-async function populateProducts(app: INestApplicationContext, productsCsvPath: string, logging: boolean) {
+async function populateProducts(
+    app: INestApplicationContext,
+    productsCsvPath: string | undefined,
+    logging: boolean,
+) {
+    if (!productsCsvPath) {
+        if (logging) {
+            console.log(`\nNo product data provided, skipping product import`);
+        }
+        return;
+    }
+
     const importResult = await importProductsFromCsv(app, productsCsvPath, LanguageCode.en);
     if (importResult.errors && importResult.errors.length) {
         console.log(`${importResult.errors.length} errors encountered when importing product data:`);
-        await console.log(importResult.errors.join('\n'));
+        console.log(importResult.errors.join('\n'));
     }
 
     if (logging) {

+ 2 - 2
packages/testing/src/types.ts

@@ -14,9 +14,9 @@ export type Mutable<T> = { -readonly [K in keyof T]: T[K] };
 export interface TestServerOptions {
     /**
      * @description
-     * The path to a CSV file containing product data to import.
+     * The path to an optional CSV file containing product data to import.
      */
-    productsCsvPath: string;
+    productsCsvPath?: string;
     /**
      * @description
      * An object containing non-product data which is used to populate the database.