diff --git a/packages/vendure-plugin-invoices/CHANGELOG.md b/packages/vendure-plugin-invoices/CHANGELOG.md new file mode 100644 index 00000000..ecc71044 --- /dev/null +++ b/packages/vendure-plugin-invoices/CHANGELOG.md @@ -0,0 +1,3 @@ +# 1.1.0 (2023-08-14) + +- Allow specifying invoice template storage in DB by specifying DB engine: INVOICES_PLUGIN_DB_ENGINE=mysql ([#243](https://github.com/Pinelab-studio/pinelab-vendure-plugins/pull/243)) diff --git a/packages/vendure-plugin-invoices/README.md b/packages/vendure-plugin-invoices/README.md index ea05b78d..7fa88ca6 100644 --- a/packages/vendure-plugin-invoices/README.md +++ b/packages/vendure-plugin-invoices/README.md @@ -43,13 +43,6 @@ plugins: [ 7. Check the checkbox to `Enable invoice generation` for the current channel on order placement. 8. A default HTML template is set for you. Click the `Preview` button to view a sample PDF invoice. -If you are using Docker with node:16 or higher as base, you need to add this to your Dockerfile: - -```shell -# PhantomJS fix https://github.com/bazelbuild/rules_closure/issues/351 -ENV OPENSSL_CONF=/dev/null -``` - ## Adding invoices to your order-confirmation email Add the following link to your email template: @@ -59,6 +52,17 @@ Add the following link to your email template: When the customer clicks the link, the server will check if the `ordercode`, `channelCode` and `customer emailaddress` match with the requested order. If so, it will return the invoice. +## Increase invoice template DB storage + +By default, the plugin uses TypeOrm's `text` to store the invoice template in the DB. This might not be enough, for example when you'd like to add base64 encoded images to your invoices. This will result in the error `ER_DATA_TOO_LONG: Data too long for column 'templateString'`. You can specify your DB engine with an env variable, and the plugin will resolve the correct column type: + +```shell +# E.g. For mysql the column type 'longtext' will be used, which supports up to 4gb +INVOICES_PLUGIN_DB_ENGINE=longtext +``` + +Don't forget to run a DB migration after! Checkout https://orkhan.gitbook.io/typeorm/docs/entities for available databases and column types. + ## Google Storage strategy This plugin also includes a strategy for storing invoices in Google Storage: diff --git a/packages/vendure-plugin-invoices/package.json b/packages/vendure-plugin-invoices/package.json index f6508c54..f841527f 100644 --- a/packages/vendure-plugin-invoices/package.json +++ b/packages/vendure-plugin-invoices/package.json @@ -1,6 +1,6 @@ { "name": "@pinelab/vendure-plugin-invoices", - "version": "1.0.1", + "version": "1.1.0", "description": "Vendure plugin for invoice generation", "author": "Martijn van de Brug ", "homepage": "https://pinelab-plugins.com/", @@ -14,7 +14,8 @@ "types": "dist/index.d.ts", "files": [ "dist", - "README.md" + "README.md", + "CHANGELOG.md" ], "scripts": { "start": "yarn ts-node test/dev-server.ts", diff --git a/packages/vendure-plugin-invoices/src/api/entities/invoice-config.entity.ts b/packages/vendure-plugin-invoices/src/api/entities/invoice-config.entity.ts index d89fa671..6e917622 100644 --- a/packages/vendure-plugin-invoices/src/api/entities/invoice-config.entity.ts +++ b/packages/vendure-plugin-invoices/src/api/entities/invoice-config.entity.ts @@ -1,5 +1,7 @@ -import { Column, Entity } from 'typeorm'; -import { DeepPartial, VendureEntity } from '@vendure/core'; +import { Column, Entity, ColumnType, getMetadataArgsStorage } from 'typeorm'; +import { DeepPartial, Logger, VendureEntity } from '@vendure/core'; +import { InvoicePlugin } from '../../invoice.plugin'; +import { loggerCtx } from '../../constants'; @Entity('invoice_config') export class InvoiceConfigEntity extends VendureEntity { @@ -9,8 +11,38 @@ export class InvoiceConfigEntity extends VendureEntity { @Column() channelId!: string; + @Column({ default: false }) enabled: boolean = false; - @Column({ type: 'text', nullable: true }) + + @Column({ type: resolveTemplateColumnType(), nullable: true }) templateString?: string | null; } + +/** + * Resolve column type based on the DB engine + */ +function resolveTemplateColumnType(): ColumnType { + const dbEngine = process.env.INVOICES_PLUGIN_DB_ENGINE; + if (!dbEngine) { + return 'text'; + } else if (dbEngine === 'mysql' || 'mariadb') { + return 'longtext'; // up to 4GB + } else if (dbEngine === 'postgres') { + return 'text'; // Up to 1GB + } else if (dbEngine === 'cockroachdb') { + return 'string'; + } else if (dbEngine === 'mssql') { + return 'text'; + } else if (dbEngine === 'sqlite') { + return 'text'; + } else if (dbEngine === 'oracle') { + return 'clob'; + } else { + Logger.warn( + `No large-text column type available for DB engine "${dbEngine}", using "text". ( Contributions welcome )`, + loggerCtx + ); + } + return 'text'; +} diff --git a/packages/vendure-plugin-invoices/src/invoice.plugin.ts b/packages/vendure-plugin-invoices/src/invoice.plugin.ts index 710ade25..042fa762 100644 --- a/packages/vendure-plugin-invoices/src/invoice.plugin.ts +++ b/packages/vendure-plugin-invoices/src/invoice.plugin.ts @@ -48,8 +48,10 @@ export interface InvoicePluginConfig { resolvers: [InvoiceResolver], }, compatibility: '^2.0.0', - configuration: (config: RuntimeVendureConfig) => - InvoicePlugin.configure(config), + configuration: (config: RuntimeVendureConfig) => { + InvoicePlugin.configure(config); + return config; + }, }) export class InvoicePlugin { static config: InvoicePluginConfig;