vendure-ecommerce / vendure-plus-issues

Report issues on Vendure Plus plugins here
0 stars 1 forks source link

Error while issuing giftcard (error.entity-with-id-not-found) #6

Closed koljam closed 1 year ago

koljam commented 1 year ago

The full error:

[worker] Error: error.entity-with-id-not-found
[worker]     at TransactionalConnection.getEntityOrThrowInternal (C:\Users\kolja\Documents\GitHub\venduretest\node_modules\@vendure\core\src\connection\transactional-connection.ts:250:19)
[worker]     at processTicksAndRejections (node:internal/process/task_queues:95:5)
[worker]     at async AssetService.update (C:\Users\kolja\Documents\GitHub\venduretest\node_modules\@vendure\core\src\service\services\asset.service.ts:315:23)
[worker]     at async GiftCardRenderer.createGiftCardImageAsset (C:\Users\kolja\Documents\GitHub\venduretest\libs\plugin-gift-card\src\lib\service\gift-card-renderer.ts:56:9)
[worker]     at async C:\Users\kolja\Documents\GitHub\venduretest\libs\plugin-gift-card\src\lib\service\gift-card.service.ts:105:37

The file gets created and is stored in the file system and it is accessible from the assets-page, but no email is sent and it is not visible on the giftcards page.

Steps to reproduce

  1. Follow Getting Started steps to install Vendure (use npx, database: mysql)
  2. Install dependencies using npm or yarn (tested both)
  3. Install Giftcard Plugin as described in docs
  4. Fix smaller issues like this one
  5. yarn dev or npm run dev
  6. Create a customer
  7. Enable "Image generation" in Admin UI
  8. Change a few parameters
  9. Issue a new Giftcard and see error in console

Versions tested Node 18.13.0 and as a docker image: node:16 Docker image yarn 1.22.19 npm 9.2.0 Vendure 1.9.1 and 1.9.2 Database mariadb:10.7

package.json

{
  "name": "venduretest",
  "version": "0.1.0",
  "private": true,
  "scripts": {
    "dev:server": "ts-node ./src/index.ts",
    "dev:worker": "ts-node ./src/index-worker.ts",
    "dev": "concurrently yarn:dev:*",
    "build": "tsc",
    "start:server": "node ./dist/index.js",
    "start:worker": "node ./dist/index-worker.js",
    "start": "concurrently yarn:start:*",
    "migration:generate": "ts-node migration generate",
    "migration:run": "ts-node migration run",
    "migration:revert": "ts-node migration revert"
  },
  "dependencies": {
    "@vendure-plus/gift-card-plugin": "^0.1.1",
    "@vendure/admin-ui-plugin": "^1.9.2",
    "@vendure/asset-server-plugin": "^1.9.2",
    "@vendure/core": "^1.9.2",
    "@vendure/email-plugin": "^1.9.2",
    "@vendure/ui-devkit": "^1.9.2",
    "dotenv": "16.0.3",
    "mysql": "2.18.1",
    "typescript": "4.3.5"
  },
  "devDependencies": {
    "concurrently": "7.6.0",
    "ts-node": "10.9.1"
  }
}

vendure-config.ts

import {
    dummyPaymentHandler,
    DefaultJobQueuePlugin,
    DefaultSearchPlugin,
    VendureConfig,
} from "@vendure/core";
import {defaultEmailHandlers, EmailPlugin} from "@vendure/email-plugin";
import {AssetServerPlugin} from "@vendure/asset-server-plugin";
import {AdminUiPlugin} from "@vendure/admin-ui-plugin";
import "dotenv/config";
import path from "path";

import {GiftCardPlugin} from "@vendure-plus/gift-card-plugin";
import {compileUiExtensions} from "@vendure/ui-devkit/compiler";
import {
    giftCardDeliveryConfirmationEmailHandler,
    giftCardEmailHandler,
} from "./plugins/giftcard/gift-card-email-handlers";

const IS_DEV = process.env.APP_ENV === "dev";

export const config: VendureConfig = {
    apiOptions: {
        port: 3000,
        adminApiPath: "admin-api",
        shopApiPath: "shop-api",
        // The following options are useful in development mode,
        // but are best turned off for production for security
        // reasons.
        ...(IS_DEV
            ? {
                    adminApiPlayground: {
                        settings: {"request.credentials": "include"} as any,
                    },
                    adminApiDebug: true,
                    shopApiPlayground: {
                        settings: {"request.credentials": "include"} as any,
                    },
                    shopApiDebug: true,
              }
            : {}),
    },
    authOptions: {
        tokenMethod: ["bearer", "cookie"],
        superadminCredentials: {
            identifier: process.env.SUPERADMIN_USERNAME,
            password: process.env.SUPERADMIN_PASSWORD,
        },
        cookieOptions: {
            secret: process.env.COOKIE_SECRET,
        },
    },
    dbConnectionOptions: {
        type: "mysql",
        // See the README.md "Migrations" section for an explanation of
        // the `synchronize` and `migrations` options.
        synchronize: true,
        migrations: [path.join(__dirname, "./migrations/*.+(js|ts)")],
        logging: false,
        database: process.env.DB_NAME,
        host: process.env.DB_HOST,
        port: +process.env.DB_PORT,
        username: process.env.DB_USERNAME,
        password: process.env.DB_PASSWORD,
    },
    paymentOptions: {
        paymentMethodHandlers: [dummyPaymentHandler],
    },
    // When adding or altering custom field definitions, the database will
    // need to be updated. See the "Migrations" section in README.md.
    customFields: {},
    plugins: [
        GiftCardPlugin.init({
            defaultImagePaths: [
                // The plugin ships with some generic gift card images you can use to get started
                "node_modules/@vendure-plus/gift-card-plugin/assets/default-gift-card-black.jpg",
                "node_modules/@vendure-plus/gift-card-plugin/assets/default-gift-card-gold.jpg",
                "node_modules/@vendure-plus/gift-card-plugin/assets/default-gift-card-silver.jpg",
            ],
            createDefaultGiftCardProduct: {
                // On bootstrap, a new ProductVariant will be created with the following details
                name: "Gift Card",
                sku: "GC01",
            },
        }),
        AdminUiPlugin.init({
            route: "admin",
            port: 3002,
            app: compileUiExtensions({
                outputPath: path.join(__dirname, "../admin-ui"),
                extensions: [GiftCardPlugin.uiExtensions],
                devMode: false,
            }),
        }),
        AssetServerPlugin.init({
            route: "assets",
            assetUploadDir: path.join(__dirname, "../static/assets"),
            // For local dev, the correct value for assetUrlPrefix should
            // be guessed correctly, but for production it will usually need
            // to be set manually to match your production url.
            assetUrlPrefix: IS_DEV
                ? undefined
                : "https://www.my-shop.com/assets",
        }),
        DefaultJobQueuePlugin.init({useDatabaseForBuffer: true}),
        DefaultSearchPlugin.init({
            bufferUpdates: false,
            indexStockStatus: true,
        }),
        EmailPlugin.init({
            devMode: true,
            outputPath: path.join(__dirname, "../static/email/test-emails"),
            route: "mailbox",
            handlers: [
                ...defaultEmailHandlers,
                giftCardEmailHandler,
                giftCardDeliveryConfirmationEmailHandler,
            ],
            templatePath: path.join(__dirname, "../static/email/templates"),
            globalTemplateVars: {
                // The following variables will change depending on your storefront implementation.
                // Here we are assuming a storefront running at http://localhost:8080.
                fromAddress: '"example" <noreply@example.com>',
                verifyEmailAddressUrl: "http://localhost:8080/verify",
                passwordResetUrl: "http://localhost:8080/password-reset",
                changeEmailAddressUrl:
                    "http://localhost:8080/verify-email-address-change",
            },
        }),
    ],
};
michaelbromley commented 1 year ago

This should be fixed in v0.1.2 :)