From 90ea88882978859595f4980efb71bfe54a8b4d33 Mon Sep 17 00:00:00 2001 From: Oliver Windall Juhl <59018053+olivermrbl@users.noreply.github.com> Date: Thu, 18 Feb 2021 13:46:34 +0100 Subject: [PATCH 01/26] hotfix(medusa-fulfillment-webshipper): Cancel fulfillment idempotently (#175) --- .../src/services/webshipper-fulfillment.js | 5 +++++ 1 file changed, 5 insertions(+) diff --git a/packages/medusa-fulfillment-webshipper/src/services/webshipper-fulfillment.js b/packages/medusa-fulfillment-webshipper/src/services/webshipper-fulfillment.js index 89142f3bb6..43d96fd573 100644 --- a/packages/medusa-fulfillment-webshipper/src/services/webshipper-fulfillment.js +++ b/packages/medusa-fulfillment-webshipper/src/services/webshipper-fulfillment.js @@ -523,6 +523,11 @@ class WebshipperFulfillmentService extends FulfillmentService { .retrieve(data.id) .catch(() => undefined) + // if order does not exist, we resolve gracefully + if (!order) { + return Promise.resolve() + } + if (order) { if (order.data.attributes.status !== "pending") { if (order.data.attributes.status === "cancelled") { From e27cf72a8ca49a6586a82dde964d559c40a4415f Mon Sep 17 00:00:00 2001 From: Sebastian Rindom Date: Mon, 22 Feb 2021 08:45:01 +0100 Subject: [PATCH 02/26] feat(medusa-plugin-segment): adds category and type to segment events (#179) --- packages/medusa-plugin-segment/src/services/segment.js | 10 +++++++++- .../medusa-plugin-segment/src/subscribers/order.js | 2 ++ 2 files changed, 11 insertions(+), 1 deletion(-) diff --git a/packages/medusa-plugin-segment/src/services/segment.js b/packages/medusa-plugin-segment/src/services/segment.js index eaeddcf5e8..8c1610f493 100644 --- a/packages/medusa-plugin-segment/src/services/segment.js +++ b/packages/medusa-plugin-segment/src/services/segment.js @@ -10,11 +10,12 @@ class SegmentService extends BaseService { * write_key: Segment write key given in Segment dashboard * } */ - constructor({ totalsService }, options) { + constructor({ totalsService, productService }, options) { super() this.totalsService_ = totalsService this.options_ = options + this.productService_ = productService this.analytics_ = new Analytics(options.write_key) } @@ -129,12 +130,19 @@ class SegmentService extends BaseService { variant = item.variant.sku } + const product = await this.productService_.retrieve( + item.variant.product_id, + { relations: ["collection", "type"] } + ) + return { name, variant, price: lineTotal / 100 / item.quantity, reporting_revenue: revenue, product_id: item.variant.product_id, + category: product.collection?.title, + type: product.type?.value, sku, quantity: item.quantity, } diff --git a/packages/medusa-plugin-segment/src/subscribers/order.js b/packages/medusa-plugin-segment/src/subscribers/order.js index 3ee9ad40c7..fe422dca4a 100644 --- a/packages/medusa-plugin-segment/src/subscribers/order.js +++ b/packages/medusa-plugin-segment/src/subscribers/order.js @@ -74,6 +74,7 @@ class OrderSubscriber { "payments", "fulfillments", "returns", + "items", "gift_cards", "gift_card_transactions", "swaps", @@ -160,6 +161,7 @@ class OrderSubscriber { "shipping_methods", "payments", "fulfillments", + "items", "returns", "gift_cards", "gift_card_transactions", From 5ed9e3057d06f7a7deedd31378ed25c02aacf6b5 Mon Sep 17 00:00:00 2001 From: Sebastian Rindom Date: Mon, 22 Feb 2021 08:49:25 +0100 Subject: [PATCH 03/26] chore(release): Publish - medusa-fulfillment-webshipper@1.1.3-next.0 - medusa-plugin-segment@1.1.5-next.0 - @medusajs/medusa@1.1.10-next.0 --- packages/medusa-fulfillment-webshipper/CHANGELOG.md | 11 +++++++++++ packages/medusa-fulfillment-webshipper/package.json | 2 +- packages/medusa-plugin-segment/CHANGELOG.md | 11 +++++++++++ packages/medusa-plugin-segment/package.json | 2 +- packages/medusa/CHANGELOG.md | 11 +++++++++++ packages/medusa/package.json | 2 +- 6 files changed, 36 insertions(+), 3 deletions(-) diff --git a/packages/medusa-fulfillment-webshipper/CHANGELOG.md b/packages/medusa-fulfillment-webshipper/CHANGELOG.md index ec89b0aae2..f5275392f0 100644 --- a/packages/medusa-fulfillment-webshipper/CHANGELOG.md +++ b/packages/medusa-fulfillment-webshipper/CHANGELOG.md @@ -3,6 +3,17 @@ All notable changes to this project will be documented in this file. See [Conventional Commits](https://conventionalcommits.org) for commit guidelines. +## [1.1.3-next.0](https://github.com/medusajs/medusa/compare/medusa-fulfillment-webshipper@1.1.2...medusa-fulfillment-webshipper@1.1.3-next.0) (2021-02-22) + + +### Features + +* **medusa:** tracking links ([#177](https://github.com/medusajs/medusa/issues/177)) ([99ad43b](https://github.com/medusajs/medusa/commit/99ad43bf47c3922f391d433448b1c4affd88f457)) + + + + + ## [1.1.2](https://github.com/medusajs/medusa/compare/medusa-fulfillment-webshipper@1.1.1...medusa-fulfillment-webshipper@1.1.2) (2021-02-17) diff --git a/packages/medusa-fulfillment-webshipper/package.json b/packages/medusa-fulfillment-webshipper/package.json index ef1762db12..4e26dc0be1 100644 --- a/packages/medusa-fulfillment-webshipper/package.json +++ b/packages/medusa-fulfillment-webshipper/package.json @@ -1,6 +1,6 @@ { "name": "medusa-fulfillment-webshipper", - "version": "1.1.2", + "version": "1.1.3-next.0", "description": "Webshipper Fulfillment provider for Medusa", "main": "index.js", "repository": { diff --git a/packages/medusa-plugin-segment/CHANGELOG.md b/packages/medusa-plugin-segment/CHANGELOG.md index a2d98bcd21..875e896f4c 100644 --- a/packages/medusa-plugin-segment/CHANGELOG.md +++ b/packages/medusa-plugin-segment/CHANGELOG.md @@ -3,6 +3,17 @@ All notable changes to this project will be documented in this file. See [Conventional Commits](https://conventionalcommits.org) for commit guidelines. +## [1.1.5-next.0](https://github.com/medusajs/medusa/compare/medusa-plugin-segment@1.1.4...medusa-plugin-segment@1.1.5-next.0) (2021-02-22) + + +### Features + +* **medusa-plugin-segment:** adds category and type to segment events ([#179](https://github.com/medusajs/medusa/issues/179)) ([e27cf72](https://github.com/medusajs/medusa/commit/e27cf72a8ca49a6586a82dde964d559c40a4415f)) + + + + + ## [1.1.4](https://github.com/medusajs/medusa/compare/medusa-plugin-segment@1.1.3...medusa-plugin-segment@1.1.4) (2021-02-17) diff --git a/packages/medusa-plugin-segment/package.json b/packages/medusa-plugin-segment/package.json index 67817d6378..381fe159aa 100644 --- a/packages/medusa-plugin-segment/package.json +++ b/packages/medusa-plugin-segment/package.json @@ -1,6 +1,6 @@ { "name": "medusa-plugin-segment", - "version": "1.1.4", + "version": "1.1.5-next.0", "description": "Segment Analytics", "main": "index.js", "repository": { diff --git a/packages/medusa/CHANGELOG.md b/packages/medusa/CHANGELOG.md index 2d5fba459c..f73fb42257 100644 --- a/packages/medusa/CHANGELOG.md +++ b/packages/medusa/CHANGELOG.md @@ -3,6 +3,17 @@ All notable changes to this project will be documented in this file. See [Conventional Commits](https://conventionalcommits.org) for commit guidelines. +## [1.1.10-next.0](https://github.com/medusajs/medusa/compare/@medusajs/medusa@1.1.9...@medusajs/medusa@1.1.10-next.0) (2021-02-22) + + +### Features + +* **medusa:** tracking links ([#177](https://github.com/medusajs/medusa/issues/177)) ([99ad43b](https://github.com/medusajs/medusa/commit/99ad43bf47c3922f391d433448b1c4affd88f457)) + + + + + ## [1.1.9](https://github.com/medusajs/medusa/compare/@medusajs/medusa@1.1.8...@medusajs/medusa@1.1.9) (2021-02-18) diff --git a/packages/medusa/package.json b/packages/medusa/package.json index 8ccd34dcdb..1182b95ec4 100644 --- a/packages/medusa/package.json +++ b/packages/medusa/package.json @@ -1,6 +1,6 @@ { "name": "@medusajs/medusa", - "version": "1.1.9", + "version": "1.1.10-next.0", "description": "E-commerce for JAMstack", "main": "dist/index.js", "repository": { From 587a464e83576833ff616bde7bb26b1bb48472fe Mon Sep 17 00:00:00 2001 From: Oliver Windall Juhl <59018053+olivermrbl@users.noreply.github.com> Date: Tue, 23 Feb 2021 07:49:01 +0100 Subject: [PATCH 04/26] fix(medusa-plugin-contentful): Allow custom fields in plugin options (#180) --- .../src/loaders/check-types.js | 24 ++- .../src/services/contentful.js | 174 +++++++++++++++--- 2 files changed, 164 insertions(+), 34 deletions(-) diff --git a/packages/medusa-plugin-contentful/src/loaders/check-types.js b/packages/medusa-plugin-contentful/src/loaders/check-types.js index 88f6ea78ef..9c224621dd 100644 --- a/packages/medusa-plugin-contentful/src/loaders/check-types.js +++ b/packages/medusa-plugin-contentful/src/loaders/check-types.js @@ -19,8 +19,16 @@ const checkContentTypes = async (container) => { if (product && product.fields) { const productFields = product.fields + const customProductFields = Object.keys( + contentfulService.options_.custom_product_fields || {} + ) const keys = Object.values(productFields).map((f) => f.id) - if (!requiredProductFields.every((f) => keys.includes(f))) { + + const missingKeys = requiredProductFields.filter( + (rpf) => !keys.includes(rpf) && !customProductFields.includes(rpf) + ) + + if (missingKeys.length) { throw Error( `Contentful: Content type ${`product`} is missing some required key(s). Required: ${requiredProductFields.join( ", " @@ -32,8 +40,16 @@ const checkContentTypes = async (container) => { if (variant && variant.fields) { const variantFields = variant.fields + const customVariantFields = Object.keys( + contentfulService.options_.custom_variant_fields || {} + ) const keys = Object.values(variantFields).map((f) => f.id) - if (!requiredVariantFields.every((f) => keys.includes(f))) { + + const missingKeys = requiredVariantFields.filter( + (rpf) => !keys.includes(rpf) && !customVariantFields.includes(rpf) + ) + + if (missingKeys.length) { throw Error( `Contentful: Content type ${`productVariant`} is missing some required key(s). Required: ${requiredVariantFields.join( ", " @@ -47,13 +63,13 @@ const requiredProductFields = [ "title", "variants", "options", - "objectId", + "medusaId", "type", "collection", "tags", "handle", ] -const requiredVariantFields = ["title", "sku", "prices", "options", "objectId"] +const requiredVariantFields = ["title", "sku", "prices", "options", "medusaId"] export default checkContentTypes diff --git a/packages/medusa-plugin-contentful/src/services/contentful.js b/packages/medusa-plugin-contentful/src/services/contentful.js index 33f45acd32..b0ec7ce842 100644 --- a/packages/medusa-plugin-contentful/src/services/contentful.js +++ b/packages/medusa-plugin-contentful/src/services/contentful.js @@ -111,10 +111,27 @@ class ContentfulService extends BaseService { return assets } + getCustomField(field, type) { + const customOptions = this.options_[`custom_${type}_fields`] + + if (customOptions) { + return customOptions[field] || field + } else { + return field + } + } + async createProductInContentful(product) { try { const p = await this.productService_.retrieve(product.id, { - relations: ["variants", "options", "tags", "type", "collection"], + relations: [ + "variants", + "options", + "tags", + "type", + "collection", + "images", + ], }) const environment = await this.getContentfulEnvironment_() @@ -122,46 +139,92 @@ class ContentfulService extends BaseService { const variantLinks = this.getVariantLinks_(variantEntries) const fields = { - title: { + [this.getCustomField("title", "product")]: { "en-US": p.title, }, - variants: { + [this.getCustomField("variants", "product")]: { "en-US": variantLinks, }, - options: { + [this.getCustomField("options", "product")]: { "en-US": p.options, }, - objectId: { + [this.getCustomField("medusaId", "product")]: { "en-US": p.id, }, } + if (p.images.length > 0) { + const imageLinks = await this.createImageAssets(product) + + const thumbnailAsset = await environment.createAsset({ + fields: { + title: { + "en-US": `${p.title}`, + }, + description: { + "en-US": "", + }, + file: { + "en-US": { + contentType: "image/xyz", + fileName: p.thumbnail, + upload: p.thumbnail, + }, + }, + }, + }) + + await thumbnailAsset.processForAllLocales() + + const thumbnailLink = { + sys: { + type: "Link", + linkType: "Asset", + id: thumbnailAsset.sys.id, + }, + } + + fields.thumbnail = { + "en-US": thumbnailLink, + } + + if (imageLinks) { + fields.images = { + "en-US": imageLinks, + } + } + } + if (p.type) { const type = { "en-US": p.type.value, } - fields.type = type + + fields[this.getCustomField("type", "product")] = type } if (p.collection) { const collection = { "en-US": p.collection.title, } - fields.collection = collection + + fields[this.getCustomField("collection", "product")] = collection } if (p.tags) { const tags = { "en-US": p.tags, } - fields.tags = tags + + fields[this.getCustomField("tags", "product")] = tags } if (p.handle) { const handle = { "en-US": p.handle, } - fields.handle = handle + + fields[this.getCustomField("handle", "product")] = handle } const result = await environment.createEntryWithId("product", p.id, { @@ -189,19 +252,19 @@ class ContentfulService extends BaseService { v.id, { fields: { - title: { + [this.getCustomField("title", "variant")]: { "en-US": v.title, }, - sku: { + [this.getCustomField("sku", "variant")]: { "en-US": v.sku, }, - prices: { + [this.getCustomField("prices", "variant")]: { "en-US": v.prices, }, - options: { + [this.getCustomField("options", "variant")]: { "en-US": v.options, }, - objectId: { + [this.getCustomField("medusaId", "variant")]: { "en-US": v.id, }, }, @@ -240,7 +303,14 @@ class ContentfulService extends BaseService { } const p = await this.productService_.retrieve(product.id, { - relations: ["options", "variants", "type", "collection", "tags"], + relations: [ + "options", + "variants", + "type", + "collection", + "tags", + "images", + ], }) const variantEntries = await this.getVariantEntries_(p.variants) @@ -248,46 +318,86 @@ class ContentfulService extends BaseService { const productEntryFields = { ...productEntry.fields, - title: { + [this.getCustomField("title", "product")]: { "en-US": p.title, }, - options: { + [this.getCustomField("options", "product")]: { "en-US": p.options, }, - variants: { + [this.getCustomField("variants", "product")]: { "en-US": variantLinks, }, - objectId: { + [this.getCustomField("medusaId", "product")]: { "en-US": p.id, }, } + if (p.thumbnail) { + const thumbnailAsset = await environment.createAsset({ + fields: { + title: { + "en-US": `${p.title}`, + }, + description: { + "en-US": "", + }, + file: { + "en-US": { + contentType: "image/xyz", + fileName: p.thumbnail, + upload: p.thumbnail, + }, + }, + }, + }) + + await thumbnailAsset.processForAllLocales() + + const thumbnailLink = { + sys: { + type: "Link", + linkType: "Asset", + id: thumbnailAsset.sys.id, + }, + } + + productEntryFields.thumbnail = { + "en-US": thumbnailLink, + } + } + if (p.type) { const type = { "en-US": p.type.value, } - productEntryFields.type = type + + productEntryFields[this.getCustomField("type", "product")] = type } if (p.collection) { const collection = { "en-US": p.collection.title, } - productEntryFields.collection = collection + + productEntryFields[ + this.getCustomField("collection", "product") + ] = collection } if (p.tags) { const tags = { "en-US": p.tags, } - productEntryFields.tags = tags + + productEntryFields[this.getCustomField("tags", "product")] = tags } if (p.handle) { const handle = { "en-US": p.handle, } - productEntryFields.handle = handle + + productEntryFields[this.getCustomField("handle", "product")] = handle } productEntry.fields = productEntryFields @@ -333,19 +443,19 @@ class ContentfulService extends BaseService { const variantEntryFields = { ...variantEntry.fields, - title: { + [this.getCustomField("title", "variant")]: { "en-US": v.title, }, - sku: { + [this.getCustomField("sku", "variant")]: { "en-US": v.sku, }, - options: { + [this.getCustomField("options", "variant")]: { "en-US": v.options, }, - prices: { + [this.getCustomField("prices", "variant")]: { "en-US": v.prices, }, - objectId: { + [this.getCustomField("medusaId", "variant")]: { "en-US": v.id, }, } @@ -377,7 +487,8 @@ class ContentfulService extends BaseService { } let update = { - title: productEntry.fields.title["en-US"], + title: + productEntry.fields[this.getCustomField("title", "product")]["en-US"], } // Get the thumbnail, if present @@ -421,7 +532,10 @@ class ContentfulService extends BaseService { const updatedVariant = await this.productVariantService_.update( variantId, { - title: variantEntry.fields.title["en-US"], + title: + variantEntry.fields[this.getCustomField("title", "variant")][ + "en-US" + ], } ) From 22be418ec132944afe469106ba4b3b92f634d240 Mon Sep 17 00:00:00 2001 From: Oliver Windall Juhl <59018053+olivermrbl@users.noreply.github.com> Date: Tue, 23 Feb 2021 13:40:49 +0100 Subject: [PATCH 05/26] fix(medusa): Add querying func. on customer retrievals (#181) --- .../api/__tests__/admin/customer.js | 135 ++++++++++++++++++ .../api/helpers/customer-seeder.js | 27 ++++ .../routes/admin/customers/list-customers.js | 22 ++- packages/medusa/src/services/customer.js | 45 ++++++ 4 files changed, 225 insertions(+), 4 deletions(-) create mode 100644 integration-tests/api/__tests__/admin/customer.js create mode 100644 integration-tests/api/helpers/customer-seeder.js diff --git a/integration-tests/api/__tests__/admin/customer.js b/integration-tests/api/__tests__/admin/customer.js new file mode 100644 index 0000000000..14c4222977 --- /dev/null +++ b/integration-tests/api/__tests__/admin/customer.js @@ -0,0 +1,135 @@ +const { dropDatabase } = require("pg-god"); +const path = require("path"); + +const setupServer = require("../../../helpers/setup-server"); +const { useApi } = require("../../../helpers/use-api"); +const { initDb } = require("../../../helpers/use-db"); + +const customerSeeder = require("../../helpers/customer-seeder"); +const adminSeeder = require("../../helpers/admin-seeder"); + +jest.setTimeout(30000); + +describe("/admin/customers", () => { + let medusaProcess; + let dbConnection; + + beforeAll(async () => { + const cwd = path.resolve(path.join(__dirname, "..", "..")); + dbConnection = await initDb({ cwd }); + medusaProcess = await setupServer({ cwd }); + }); + + afterAll(async () => { + await dbConnection.close(); + await dropDatabase({ databaseName: "medusa-integration" }); + + medusaProcess.kill(); + }); + + describe("GET /admin/customers", () => { + beforeEach(async () => { + try { + await adminSeeder(dbConnection); + await customerSeeder(dbConnection); + } catch (err) { + console.log(err); + throw err; + } + }); + + afterEach(async () => { + const manager = dbConnection.manager; + await manager.query(`DELETE FROM "address"`); + await manager.query(`DELETE FROM "customer"`); + await manager.query(`DELETE FROM "user"`); + }); + + it("lists customers and query count", async () => { + const api = useApi(); + + const response = await api + .get("/admin/customers", { + headers: { + Authorization: "Bearer test_token", + }, + }) + .catch((err) => { + console.log(err); + }); + + expect(response.status).toEqual(200); + expect(response.data.count).toEqual(3); + expect(response.data.customers).toEqual( + expect.arrayContaining([ + expect.objectContaining({ + id: "test-customer-1", + }), + expect.objectContaining({ + id: "test-customer-2", + }), + expect.objectContaining({ + id: "test-customer-3", + }), + ]) + ); + }); + + it("lists customers with specific query", async () => { + const api = useApi(); + + const response = await api + .get("/admin/customers?q=test2@email.com", { + headers: { + Authorization: "Bearer test_token", + }, + }) + .catch((err) => { + console.log(err); + }); + + expect(response.status).toEqual(200); + expect(response.data.count).toEqual(1); + expect(response.data.customers).toEqual( + expect.arrayContaining([ + expect.objectContaining({ + id: "test-customer-2", + email: "test2@email.com", + }), + ]) + ); + }); + + it("lists customers with expand query", async () => { + const api = useApi(); + + const response = await api + .get("/admin/customers?q=test1@email.com&expand=shipping_addresses", { + headers: { + Authorization: "Bearer test_token", + }, + }) + .catch((err) => { + console.log(err); + }); + + expect(response.status).toEqual(200); + expect(response.data.count).toEqual(1); + console.log(response.data.customers); + expect(response.data.customers).toEqual( + expect.arrayContaining([ + expect.objectContaining({ + id: "test-customer-1", + shipping_addresses: expect.arrayContaining([ + expect.objectContaining({ + id: "test-address", + first_name: "Lebron", + last_name: "James", + }), + ]), + }), + ]) + ); + }); + }); +}); diff --git a/integration-tests/api/helpers/customer-seeder.js b/integration-tests/api/helpers/customer-seeder.js new file mode 100644 index 0000000000..78b3e22ec5 --- /dev/null +++ b/integration-tests/api/helpers/customer-seeder.js @@ -0,0 +1,27 @@ +const { Customer, Address } = require("@medusajs/medusa"); + +module.exports = async (connection, data = {}) => { + const manager = connection.manager; + + await manager.insert(Customer, { + id: "test-customer-1", + email: "test1@email.com", + }); + + await manager.insert(Customer, { + id: "test-customer-2", + email: "test2@email.com", + }); + + await manager.insert(Customer, { + id: "test-customer-3", + email: "test3@email.com", + }); + + await manager.insert(Address, { + id: "test-address", + first_name: "Lebron", + last_name: "James", + customer_id: "test-customer-1", + }); +}; diff --git a/packages/medusa/src/api/routes/admin/customers/list-customers.js b/packages/medusa/src/api/routes/admin/customers/list-customers.js index 6683f80e06..e0bcb9b9c8 100644 --- a/packages/medusa/src/api/routes/admin/customers/list-customers.js +++ b/packages/medusa/src/api/routes/admin/customers/list-customers.js @@ -2,18 +2,32 @@ export default async (req, res) => { try { const customerService = req.scope.resolve("customerService") - const limit = parseInt(req.query.limit) || 10 + const limit = parseInt(req.query.limit) || 50 const offset = parseInt(req.query.offset) || 0 + const selector = {} + + if ("q" in req.query) { + selector.q = req.query.q + } + + let expandFields = [] + if ("expand" in req.query) { + expandFields = req.query.expand.split(",") + } + const listConfig = { - relations: [], + relations: expandFields.length ? expandFields : [], skip: offset, take: limit, } - const customers = await customerService.list({}, listConfig) + const [customers, count] = await customerService.listAndCount( + selector, + listConfig + ) - res.json({ customers, count: customers.length, offset, limit }) + res.json({ customers, count, offset, limit }) } catch (error) { throw error } diff --git a/packages/medusa/src/services/customer.js b/packages/medusa/src/services/customer.js index 6db5092f03..486e89c210 100644 --- a/packages/medusa/src/services/customer.js +++ b/packages/medusa/src/services/customer.js @@ -3,6 +3,7 @@ import Scrypt from "scrypt-kdf" import _ from "lodash" import { Validator, MedusaError } from "medusa-core-utils" import { BaseService } from "medusa-interfaces" +import { Brackets } from "typeorm" /** * Provides layer to manipulate customers. @@ -132,6 +133,50 @@ class CustomerService extends BaseService { return customerRepo.find(query) } + async listAndCount( + selector, + config = { relations: [], skip: 0, take: 50, order: { created_at: "DESC" } } + ) { + const customerRepo = this.manager_.getCustomRepository( + this.customerRepository_ + ) + + let q + if ("q" in selector) { + q = selector.q + delete selector.q + } + + const query = this.buildQuery_(selector, config) + + if (q) { + const where = query.where + + delete where.email + delete where.first_name + delete where.last_name + + query.join = { + alias: "customer", + } + + query.where = qb => { + qb.where(where) + + qb.andWhere( + new Brackets(qb => { + qb.where(`customer.first_name ILIKE :q`, { q: `%${q}%` }) + .orWhere(`customer.last_name ILIKE :q`, { q: `%${q}%` }) + .orWhere(`customer.email ILIKE :q`, { q: `%${q}%` }) + }) + ) + } + } + + const [customers, count] = await customerRepo.findAndCount(query) + return [customers, count] + } + /** * Return the total number of documents in database * @return {Promise} the result of the count operation From ba39cb16db88e24b1ebf9d5d62ca0c43609db4dd Mon Sep 17 00:00:00 2001 From: Sebastian Rindom Date: Wed, 24 Feb 2021 08:52:39 +0100 Subject: [PATCH 06/26] hotfix(brightpearl): wrap inventory update in transaction --- .../src/services/brightpearl.js | 10 ++++++++-- 1 file changed, 8 insertions(+), 2 deletions(-) diff --git a/packages/medusa-plugin-brightpearl/src/services/brightpearl.js b/packages/medusa-plugin-brightpearl/src/services/brightpearl.js index a114000e52..2fd27359e8 100644 --- a/packages/medusa-plugin-brightpearl/src/services/brightpearl.js +++ b/packages/medusa-plugin-brightpearl/src/services/brightpearl.js @@ -5,6 +5,7 @@ import Brightpearl from "../utils/brightpearl" class BrightpearlService extends BaseService { constructor( { + manager, oauthService, totalsService, productVariantService, @@ -18,6 +19,7 @@ class BrightpearlService extends BaseService { ) { super() + this.manager_ = manager this.options = options this.productVariantService_ = productVariantService this.regionService_ = regionService @@ -189,8 +191,12 @@ class BrightpearlService extends BaseService { .retrieveBySKU(sku) .catch((_) => undefined) if (variant && variant.manage_inventory) { - await this.productVariantService_.update(variant.id, { - inventory_quantity: onHand, + await this.manager_.transaction((m) => { + return this.productVariantService_ + .withTransaction(m) + .update(variant.id, { + inventory_quantity: onHand, + }) }) } } From 5edcbbd7e1fe5c8955d3aaeabc22f4c95055d614 Mon Sep 17 00:00:00 2001 From: Sebastian Rindom Date: Wed, 24 Feb 2021 09:03:50 +0100 Subject: [PATCH 07/26] hotfix(brightpearl): wrap inventory update in transaction (#184) --- .../src/services/brightpearl.js | 10 ++++++++-- 1 file changed, 8 insertions(+), 2 deletions(-) diff --git a/packages/medusa-plugin-brightpearl/src/services/brightpearl.js b/packages/medusa-plugin-brightpearl/src/services/brightpearl.js index a114000e52..2fd27359e8 100644 --- a/packages/medusa-plugin-brightpearl/src/services/brightpearl.js +++ b/packages/medusa-plugin-brightpearl/src/services/brightpearl.js @@ -5,6 +5,7 @@ import Brightpearl from "../utils/brightpearl" class BrightpearlService extends BaseService { constructor( { + manager, oauthService, totalsService, productVariantService, @@ -18,6 +19,7 @@ class BrightpearlService extends BaseService { ) { super() + this.manager_ = manager this.options = options this.productVariantService_ = productVariantService this.regionService_ = regionService @@ -189,8 +191,12 @@ class BrightpearlService extends BaseService { .retrieveBySKU(sku) .catch((_) => undefined) if (variant && variant.manage_inventory) { - await this.productVariantService_.update(variant.id, { - inventory_quantity: onHand, + await this.manager_.transaction((m) => { + return this.productVariantService_ + .withTransaction(m) + .update(variant.id, { + inventory_quantity: onHand, + }) }) } } From 0c294b7b3acbc1b873aab7e90a8e596bdac48899 Mon Sep 17 00:00:00 2001 From: Sebastian Rindom Date: Thu, 25 Feb 2021 08:32:45 +0100 Subject: [PATCH 08/26] fix: add subtitle to tracks --- packages/medusa-plugin-segment/src/services/segment.js | 1 + 1 file changed, 1 insertion(+) diff --git a/packages/medusa-plugin-segment/src/services/segment.js b/packages/medusa-plugin-segment/src/services/segment.js index 8c1610f493..822ae780dd 100644 --- a/packages/medusa-plugin-segment/src/services/segment.js +++ b/packages/medusa-plugin-segment/src/services/segment.js @@ -142,6 +142,7 @@ class SegmentService extends BaseService { reporting_revenue: revenue, product_id: item.variant.product_id, category: product.collection?.title, + subtitle: product.subtitle, type: product.type?.value, sku, quantity: item.quantity, From 262af34125543d9a80bf469b5d380019b9bc8d3f Mon Sep 17 00:00:00 2001 From: Sebastian Rindom Date: Thu, 25 Feb 2021 08:34:00 +0100 Subject: [PATCH 09/26] fix: versioning --- packages/medusa-plugin-segment/package.json | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/packages/medusa-plugin-segment/package.json b/packages/medusa-plugin-segment/package.json index 381fe159aa..da763ee3c9 100644 --- a/packages/medusa-plugin-segment/package.json +++ b/packages/medusa-plugin-segment/package.json @@ -1,6 +1,6 @@ { "name": "medusa-plugin-segment", - "version": "1.1.5-next.0", + "version": "1.1.5-next.0+0c294b7b", "description": "Segment Analytics", "main": "index.js", "repository": { @@ -42,5 +42,5 @@ "medusa-core-utils": "^1.1.0", "medusa-test-utils": "^1.1.3" }, - "gitHead": "0646bd395a6056657cb0aa93c13699c4a9dbbcdd" + "gitHead": "0c294b7b3acbc1b873aab7e90a8e596bdac48899" } From e0161839746935d0686283dde482f41a60ef6548 Mon Sep 17 00:00:00 2001 From: Sebastian Rindom Date: Thu, 25 Feb 2021 08:34:16 +0100 Subject: [PATCH 10/26] chore(release): Publish - medusa-plugin-segment@1.1.5-next.1 --- packages/medusa-plugin-segment/CHANGELOG.md | 12 ++++++++++++ packages/medusa-plugin-segment/package.json | 2 +- 2 files changed, 13 insertions(+), 1 deletion(-) diff --git a/packages/medusa-plugin-segment/CHANGELOG.md b/packages/medusa-plugin-segment/CHANGELOG.md index 875e896f4c..f8d9ca4fca 100644 --- a/packages/medusa-plugin-segment/CHANGELOG.md +++ b/packages/medusa-plugin-segment/CHANGELOG.md @@ -3,6 +3,18 @@ All notable changes to this project will be documented in this file. See [Conventional Commits](https://conventionalcommits.org) for commit guidelines. +## [1.1.5-next.1](https://github.com/medusajs/medusa/compare/medusa-plugin-segment@1.1.5-next.0...medusa-plugin-segment@1.1.5-next.1) (2021-02-25) + + +### Bug Fixes + +* add subtitle to tracks ([0c294b7](https://github.com/medusajs/medusa/commit/0c294b7b3acbc1b873aab7e90a8e596bdac48899)) +* versioning ([262af34](https://github.com/medusajs/medusa/commit/262af34125543d9a80bf469b5d380019b9bc8d3f)) + + + + + ## [1.1.5-next.0](https://github.com/medusajs/medusa/compare/medusa-plugin-segment@1.1.4...medusa-plugin-segment@1.1.5-next.0) (2021-02-22) diff --git a/packages/medusa-plugin-segment/package.json b/packages/medusa-plugin-segment/package.json index da763ee3c9..a60bd4314f 100644 --- a/packages/medusa-plugin-segment/package.json +++ b/packages/medusa-plugin-segment/package.json @@ -1,6 +1,6 @@ { "name": "medusa-plugin-segment", - "version": "1.1.5-next.0+0c294b7b", + "version": "1.1.5-next.1", "description": "Segment Analytics", "main": "index.js", "repository": { From 0320788aacf93da8a8951c6a540656da1772dba4 Mon Sep 17 00:00:00 2001 From: Sebastian Rindom Date: Thu, 25 Feb 2021 08:41:55 +0100 Subject: [PATCH 11/26] fix: update-product --- .../medusa/src/api/routes/admin/products/update-product.js | 3 +++ 1 file changed, 3 insertions(+) diff --git a/packages/medusa/src/api/routes/admin/products/update-product.js b/packages/medusa/src/api/routes/admin/products/update-product.js index d017e36951..a90d759868 100644 --- a/packages/medusa/src/api/routes/admin/products/update-product.js +++ b/packages/medusa/src/api/routes/admin/products/update-product.js @@ -6,6 +6,9 @@ export default async (req, res) => { const schema = Validator.object().keys({ title: Validator.string().optional(), + subtitle: Validator.string() + .optional() + .allow(null, ""), description: Validator.string().optional(), type: Validator.object() .keys({ From 3ee3663861d46bfec9b37b6d8ecc4b06f95fa35a Mon Sep 17 00:00:00 2001 From: Sebastian Rindom Date: Thu, 25 Feb 2021 08:42:20 +0100 Subject: [PATCH 12/26] chore(release): Publish - @medusajs/medusa@1.1.10-next.1 --- packages/medusa/CHANGELOG.md | 11 +++++++++++ packages/medusa/package.json | 2 +- 2 files changed, 12 insertions(+), 1 deletion(-) diff --git a/packages/medusa/CHANGELOG.md b/packages/medusa/CHANGELOG.md index f73fb42257..21cbd19e10 100644 --- a/packages/medusa/CHANGELOG.md +++ b/packages/medusa/CHANGELOG.md @@ -3,6 +3,17 @@ All notable changes to this project will be documented in this file. See [Conventional Commits](https://conventionalcommits.org) for commit guidelines. +## [1.1.10-next.1](https://github.com/medusajs/medusa/compare/@medusajs/medusa@1.1.10-next.0...@medusajs/medusa@1.1.10-next.1) (2021-02-25) + + +### Bug Fixes + +* update-product ([0320788](https://github.com/medusajs/medusa/commit/0320788aacf93da8a8951c6a540656da1772dba4)) + + + + + ## [1.1.10-next.0](https://github.com/medusajs/medusa/compare/@medusajs/medusa@1.1.9...@medusajs/medusa@1.1.10-next.0) (2021-02-22) diff --git a/packages/medusa/package.json b/packages/medusa/package.json index 1182b95ec4..2237e89213 100644 --- a/packages/medusa/package.json +++ b/packages/medusa/package.json @@ -1,6 +1,6 @@ { "name": "@medusajs/medusa", - "version": "1.1.10-next.0", + "version": "1.1.10-next.1", "description": "E-commerce for JAMstack", "main": "dist/index.js", "repository": { From d15691188348c19fc22806d8cf7584fc5f249ce9 Mon Sep 17 00:00:00 2001 From: Sebastian Rindom Date: Thu, 25 Feb 2021 10:53:50 +0100 Subject: [PATCH 13/26] feat(segment): track shipments --- .../src/subscribers/order.js | 64 +++++++++++++++++++ 1 file changed, 64 insertions(+) diff --git a/packages/medusa-plugin-segment/src/subscribers/order.js b/packages/medusa-plugin-segment/src/subscribers/order.js index fe422dca4a..c5eac08e03 100644 --- a/packages/medusa-plugin-segment/src/subscribers/order.js +++ b/packages/medusa-plugin-segment/src/subscribers/order.js @@ -5,12 +5,76 @@ class OrderSubscriber { orderService, claimService, returnService, + fulfillmentService, }) { this.orderService_ = orderService this.returnService_ = returnService this.claimService_ = claimService + this.fulfillmentService_ = fulfillmentService + + eventBusService.subscribe( + "order.shipment_created", + async ({ id, fulfillment_id }) => { + const order = await this.orderService_.retrieve(id, { + select: [ + "shipping_total", + "discount_total", + "tax_total", + "refunded_total", + "gift_card_total", + "subtotal", + "total", + ], + relations: [ + "customer", + "billing_address", + "shipping_address", + "discounts", + "shipping_methods", + "payments", + "fulfillments", + "returns", + "items", + "gift_cards", + "gift_card_transactions", + "swaps", + "swaps.return_order", + "swaps.payment", + "swaps.shipping_methods", + "swaps.shipping_address", + "swaps.additional_items", + "swaps.fulfillments", + ], + }) + + const fulfillment = await this.fulfillmentService_.retrieve( + fulfillment_id, + { + relations: ["items"], + } + ) + + const toBuildFrom = { + ...order, + provider_id: fulfillment.provider, + items: fulfillment.items.map((i) => + order.items.find((l) => l.id === i.item_id) + ), + } + + const orderData = await segmentService.buildOrder(toBuildFrom) + const orderEvent = { + event: "Order Shipped", + userId: order.customer_id, + properties: orderData, + timestamp: fulfillment.shipped_at, + } + + segmentService.track(orderEvent) + } + ) eventBusService.subscribe("claim.created", async ({ id }) => { const claim = await this.claimService_.retrieve(id, { From 80a18d4273468cdd35fc3a8a3699a8b43b402637 Mon Sep 17 00:00:00 2001 From: Sebastian Rindom Date: Thu, 25 Feb 2021 10:54:11 +0100 Subject: [PATCH 14/26] chore(release): Publish - medusa-plugin-segment@1.1.5-next.2 --- packages/medusa-plugin-segment/CHANGELOG.md | 11 +++++++++++ packages/medusa-plugin-segment/package.json | 2 +- 2 files changed, 12 insertions(+), 1 deletion(-) diff --git a/packages/medusa-plugin-segment/CHANGELOG.md b/packages/medusa-plugin-segment/CHANGELOG.md index f8d9ca4fca..57b062b11f 100644 --- a/packages/medusa-plugin-segment/CHANGELOG.md +++ b/packages/medusa-plugin-segment/CHANGELOG.md @@ -3,6 +3,17 @@ All notable changes to this project will be documented in this file. See [Conventional Commits](https://conventionalcommits.org) for commit guidelines. +## [1.1.5-next.2](https://github.com/medusajs/medusa/compare/medusa-plugin-segment@1.1.5-next.1...medusa-plugin-segment@1.1.5-next.2) (2021-02-25) + + +### Features + +* **segment:** track shipments ([d156911](https://github.com/medusajs/medusa/commit/d15691188348c19fc22806d8cf7584fc5f249ce9)) + + + + + ## [1.1.5-next.1](https://github.com/medusajs/medusa/compare/medusa-plugin-segment@1.1.5-next.0...medusa-plugin-segment@1.1.5-next.1) (2021-02-25) diff --git a/packages/medusa-plugin-segment/package.json b/packages/medusa-plugin-segment/package.json index a60bd4314f..09e216e3ed 100644 --- a/packages/medusa-plugin-segment/package.json +++ b/packages/medusa-plugin-segment/package.json @@ -1,6 +1,6 @@ { "name": "medusa-plugin-segment", - "version": "1.1.5-next.1", + "version": "1.1.5-next.2", "description": "Segment Analytics", "main": "index.js", "repository": { From 98aa404306d55f0818d48e56c51146351ebfe306 Mon Sep 17 00:00:00 2001 From: Sebastian Rindom Date: Thu, 25 Feb 2021 11:04:18 +0100 Subject: [PATCH 15/26] fix: normalize currency code --- packages/medusa-plugin-segment/src/services/segment.js | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/packages/medusa-plugin-segment/src/services/segment.js b/packages/medusa-plugin-segment/src/services/segment.js index 822ae780dd..fc4c653142 100644 --- a/packages/medusa-plugin-segment/src/services/segment.js +++ b/packages/medusa-plugin-segment/src/services/segment.js @@ -103,7 +103,7 @@ class SegmentService extends BaseService { tax, discount, coupon, - currency: order.currency_code, + currency: order.currency_code.toUpperCase(), products: await Promise.all( order.items.map(async (item) => { let name = item.title From 12ecdb8daedaf789ebd27540ba6f74fcf7b7edd4 Mon Sep 17 00:00:00 2001 From: Sebastian Rindom Date: Thu, 25 Feb 2021 11:05:06 +0100 Subject: [PATCH 16/26] chore(release): Publish - medusa-plugin-segment@1.1.5-next.3 --- packages/medusa-plugin-segment/CHANGELOG.md | 11 +++++++++++ packages/medusa-plugin-segment/package.json | 2 +- 2 files changed, 12 insertions(+), 1 deletion(-) diff --git a/packages/medusa-plugin-segment/CHANGELOG.md b/packages/medusa-plugin-segment/CHANGELOG.md index 57b062b11f..95ff315272 100644 --- a/packages/medusa-plugin-segment/CHANGELOG.md +++ b/packages/medusa-plugin-segment/CHANGELOG.md @@ -3,6 +3,17 @@ All notable changes to this project will be documented in this file. See [Conventional Commits](https://conventionalcommits.org) for commit guidelines. +## [1.1.5-next.3](https://github.com/medusajs/medusa/compare/medusa-plugin-segment@1.1.5-next.2...medusa-plugin-segment@1.1.5-next.3) (2021-02-25) + + +### Bug Fixes + +* normalize currency code ([98aa404](https://github.com/medusajs/medusa/commit/98aa404306d55f0818d48e56c51146351ebfe306)) + + + + + ## [1.1.5-next.2](https://github.com/medusajs/medusa/compare/medusa-plugin-segment@1.1.5-next.1...medusa-plugin-segment@1.1.5-next.2) (2021-02-25) diff --git a/packages/medusa-plugin-segment/package.json b/packages/medusa-plugin-segment/package.json index 09e216e3ed..d06fc2a3ba 100644 --- a/packages/medusa-plugin-segment/package.json +++ b/packages/medusa-plugin-segment/package.json @@ -1,6 +1,6 @@ { "name": "medusa-plugin-segment", - "version": "1.1.5-next.2", + "version": "1.1.5-next.3", "description": "Segment Analytics", "main": "index.js", "repository": { From 27e5eca21d8254c1b73838fda1249405df17a9e2 Mon Sep 17 00:00:00 2001 From: Sebastian Rindom Date: Thu, 25 Feb 2021 14:07:21 +0100 Subject: [PATCH 17/26] chore(release): Publish - medusa-fulfillment-webshipper@1.1.3 - medusa-plugin-segment@1.1.5 - @medusajs/medusa@1.1.10 --- packages/medusa-fulfillment-webshipper/CHANGELOG.md | 8 ++++++++ packages/medusa-fulfillment-webshipper/package.json | 2 +- packages/medusa-plugin-segment/CHANGELOG.md | 8 ++++++++ packages/medusa-plugin-segment/package.json | 2 +- packages/medusa/CHANGELOG.md | 8 ++++++++ packages/medusa/package.json | 2 +- 6 files changed, 27 insertions(+), 3 deletions(-) diff --git a/packages/medusa-fulfillment-webshipper/CHANGELOG.md b/packages/medusa-fulfillment-webshipper/CHANGELOG.md index f5275392f0..2faa0faa67 100644 --- a/packages/medusa-fulfillment-webshipper/CHANGELOG.md +++ b/packages/medusa-fulfillment-webshipper/CHANGELOG.md @@ -3,6 +3,14 @@ All notable changes to this project will be documented in this file. See [Conventional Commits](https://conventionalcommits.org) for commit guidelines. +## [1.1.3](https://github.com/medusajs/medusa/compare/medusa-fulfillment-webshipper@1.1.3-next.0...medusa-fulfillment-webshipper@1.1.3) (2021-02-25) + +**Note:** Version bump only for package medusa-fulfillment-webshipper + + + + + ## [1.1.3-next.0](https://github.com/medusajs/medusa/compare/medusa-fulfillment-webshipper@1.1.2...medusa-fulfillment-webshipper@1.1.3-next.0) (2021-02-22) diff --git a/packages/medusa-fulfillment-webshipper/package.json b/packages/medusa-fulfillment-webshipper/package.json index 4e26dc0be1..0d644f4859 100644 --- a/packages/medusa-fulfillment-webshipper/package.json +++ b/packages/medusa-fulfillment-webshipper/package.json @@ -1,6 +1,6 @@ { "name": "medusa-fulfillment-webshipper", - "version": "1.1.3-next.0", + "version": "1.1.3", "description": "Webshipper Fulfillment provider for Medusa", "main": "index.js", "repository": { diff --git a/packages/medusa-plugin-segment/CHANGELOG.md b/packages/medusa-plugin-segment/CHANGELOG.md index 95ff315272..87f9ecc0bc 100644 --- a/packages/medusa-plugin-segment/CHANGELOG.md +++ b/packages/medusa-plugin-segment/CHANGELOG.md @@ -3,6 +3,14 @@ All notable changes to this project will be documented in this file. See [Conventional Commits](https://conventionalcommits.org) for commit guidelines. +## [1.1.5](https://github.com/medusajs/medusa/compare/medusa-plugin-segment@1.1.5-next.3...medusa-plugin-segment@1.1.5) (2021-02-25) + +**Note:** Version bump only for package medusa-plugin-segment + + + + + ## [1.1.5-next.3](https://github.com/medusajs/medusa/compare/medusa-plugin-segment@1.1.5-next.2...medusa-plugin-segment@1.1.5-next.3) (2021-02-25) diff --git a/packages/medusa-plugin-segment/package.json b/packages/medusa-plugin-segment/package.json index d06fc2a3ba..e3167bb4b4 100644 --- a/packages/medusa-plugin-segment/package.json +++ b/packages/medusa-plugin-segment/package.json @@ -1,6 +1,6 @@ { "name": "medusa-plugin-segment", - "version": "1.1.5-next.3", + "version": "1.1.5", "description": "Segment Analytics", "main": "index.js", "repository": { diff --git a/packages/medusa/CHANGELOG.md b/packages/medusa/CHANGELOG.md index 21cbd19e10..4761cae558 100644 --- a/packages/medusa/CHANGELOG.md +++ b/packages/medusa/CHANGELOG.md @@ -3,6 +3,14 @@ All notable changes to this project will be documented in this file. See [Conventional Commits](https://conventionalcommits.org) for commit guidelines. +## [1.1.10](https://github.com/medusajs/medusa/compare/@medusajs/medusa@1.1.10-next.1...@medusajs/medusa@1.1.10) (2021-02-25) + +**Note:** Version bump only for package @medusajs/medusa + + + + + ## [1.1.10-next.1](https://github.com/medusajs/medusa/compare/@medusajs/medusa@1.1.10-next.0...@medusajs/medusa@1.1.10-next.1) (2021-02-25) diff --git a/packages/medusa/package.json b/packages/medusa/package.json index 2237e89213..6e2bb9a723 100644 --- a/packages/medusa/package.json +++ b/packages/medusa/package.json @@ -1,6 +1,6 @@ { "name": "@medusajs/medusa", - "version": "1.1.10-next.1", + "version": "1.1.10", "description": "E-commerce for JAMstack", "main": "dist/index.js", "repository": { From 5cfc8d80bd3eaee93595027d0cc3ce67ae98d275 Mon Sep 17 00:00:00 2001 From: Sebastian Rindom Date: Thu, 25 Feb 2021 14:12:09 +0100 Subject: [PATCH 18/26] fix: sendgrid tracking links --- .../medusa-plugin-sendgrid/src/services/sendgrid.js | 10 +++++++--- 1 file changed, 7 insertions(+), 3 deletions(-) diff --git a/packages/medusa-plugin-sendgrid/src/services/sendgrid.js b/packages/medusa-plugin-sendgrid/src/services/sendgrid.js index 7dc39038c0..b0e38b170d 100644 --- a/packages/medusa-plugin-sendgrid/src/services/sendgrid.js +++ b/packages/medusa-plugin-sendgrid/src/services/sendgrid.js @@ -275,7 +275,7 @@ class SendGridService extends NotificationService { }) const shipment = await this.fulfillmentService_.retrieve(fulfillment_id, { - relations: ["items"], + relations: ["items", "tracking_links"], }) return { @@ -586,7 +586,9 @@ class SendGridService extends NotificationService { const refundAmount = swap.return_order.refund_amount - const shipment = await this.fulfillmentService_.retrieve(fulfillment_id) + const shipment = await this.fulfillmentService_.retrieve(fulfillment_id, { + relations: ["tracking_links"], + }) return { swap, @@ -611,7 +613,9 @@ class SendGridService extends NotificationService { relations: ["order", "order.items", "order.shipping_address"], }) - const shipment = await this.fulfillmentService_.retrieve(fulfillment_id) + const shipment = await this.fulfillmentService_.retrieve(fulfillment_id, { + relations: ["tracking_links"], + }) return { email: claim.order.email, From 7be4bb5f2daa0aad805abe0f97278f53cf3af402 Mon Sep 17 00:00:00 2001 From: Sebastian Rindom Date: Thu, 25 Feb 2021 14:37:17 +0100 Subject: [PATCH 19/26] fix: add tracking links to shipments --- packages/medusa-plugin-sendgrid/src/services/sendgrid.js | 3 +++ 1 file changed, 3 insertions(+) diff --git a/packages/medusa-plugin-sendgrid/src/services/sendgrid.js b/packages/medusa-plugin-sendgrid/src/services/sendgrid.js index b0e38b170d..0d027700f8 100644 --- a/packages/medusa-plugin-sendgrid/src/services/sendgrid.js +++ b/packages/medusa-plugin-sendgrid/src/services/sendgrid.js @@ -283,6 +283,7 @@ class SendGridService extends NotificationService { date: shipment.shipped_at.toDateString(), email: order.email, fulfillment: shipment, + tracking_links: shipment.tracking_links, tracking_number: shipment.tracking_numbers.join(", "), } } @@ -604,6 +605,7 @@ class SendGridService extends NotificationService { refund_amount: `${this.humanPrice_(refundAmount)} ${currencyCode}`, additional_total: `${this.humanPrice_(additionalTotal)} ${currencyCode}`, fulfillment: shipment, + tracking_links: shipment.tracking_links, tracking_number: shipment.tracking_numbers.join(", "), } } @@ -622,6 +624,7 @@ class SendGridService extends NotificationService { claim, order: claim.order, fulfillment: shipment, + tracking_links: shipment.tracking_links, tracking_number: shipment.tracking_numbers.join(", "), } } From cfcc9247a58054cce4889bfc782830a3b97d700b Mon Sep 17 00:00:00 2001 From: Sebastian Rindom Date: Thu, 25 Feb 2021 14:44:48 +0100 Subject: [PATCH 20/26] chore(release): Publish - medusa-plugin-brightpearl@1.1.5 - medusa-plugin-contentful@1.1.4 - medusa-plugin-sendgrid@1.1.4 - @medusajs/medusa@1.1.11 --- packages/medusa-plugin-brightpearl/CHANGELOG.md | 8 ++++++++ packages/medusa-plugin-brightpearl/package.json | 2 +- packages/medusa-plugin-contentful/CHANGELOG.md | 11 +++++++++++ packages/medusa-plugin-contentful/package.json | 2 +- packages/medusa-plugin-sendgrid/CHANGELOG.md | 12 ++++++++++++ packages/medusa-plugin-sendgrid/package.json | 2 +- packages/medusa/CHANGELOG.md | 11 +++++++++++ packages/medusa/package.json | 2 +- 8 files changed, 46 insertions(+), 4 deletions(-) diff --git a/packages/medusa-plugin-brightpearl/CHANGELOG.md b/packages/medusa-plugin-brightpearl/CHANGELOG.md index acfde4efce..6ee2fb71aa 100644 --- a/packages/medusa-plugin-brightpearl/CHANGELOG.md +++ b/packages/medusa-plugin-brightpearl/CHANGELOG.md @@ -3,6 +3,14 @@ All notable changes to this project will be documented in this file. See [Conventional Commits](https://conventionalcommits.org) for commit guidelines. +## [1.1.5](https://github.com/medusajs/medusa/compare/medusa-plugin-brightpearl@1.1.4...medusa-plugin-brightpearl@1.1.5) (2021-02-25) + +**Note:** Version bump only for package medusa-plugin-brightpearl + + + + + ## [1.1.4](https://github.com/medusajs/medusa/compare/medusa-plugin-brightpearl@1.1.3...medusa-plugin-brightpearl@1.1.4) (2021-02-17) **Note:** Version bump only for package medusa-plugin-brightpearl diff --git a/packages/medusa-plugin-brightpearl/package.json b/packages/medusa-plugin-brightpearl/package.json index f765b8d772..bdd3b8470f 100644 --- a/packages/medusa-plugin-brightpearl/package.json +++ b/packages/medusa-plugin-brightpearl/package.json @@ -1,6 +1,6 @@ { "name": "medusa-plugin-brightpearl", - "version": "1.1.4", + "version": "1.1.5", "description": "Brightpearl plugin for Medusa Commerce", "main": "index.js", "repository": { diff --git a/packages/medusa-plugin-contentful/CHANGELOG.md b/packages/medusa-plugin-contentful/CHANGELOG.md index aada6dc0bf..0fa6c1d8bc 100644 --- a/packages/medusa-plugin-contentful/CHANGELOG.md +++ b/packages/medusa-plugin-contentful/CHANGELOG.md @@ -3,6 +3,17 @@ All notable changes to this project will be documented in this file. See [Conventional Commits](https://conventionalcommits.org) for commit guidelines. +## [1.1.4](https://github.com/medusajs/medusa/compare/medusa-plugin-contentful@1.1.3...medusa-plugin-contentful@1.1.4) (2021-02-25) + + +### Bug Fixes + +* **medusa-plugin-contentful:** Allow custom fields in plugin options ([#180](https://github.com/medusajs/medusa/issues/180)) ([587a464](https://github.com/medusajs/medusa/commit/587a464e83576833ff616bde7bb26b1bb48472fe)) + + + + + ## [1.1.3](https://github.com/medusajs/medusa/compare/medusa-plugin-contentful@1.1.2...medusa-plugin-contentful@1.1.3) (2021-02-17) diff --git a/packages/medusa-plugin-contentful/package.json b/packages/medusa-plugin-contentful/package.json index f95bf1a087..0a093930de 100644 --- a/packages/medusa-plugin-contentful/package.json +++ b/packages/medusa-plugin-contentful/package.json @@ -1,6 +1,6 @@ { "name": "medusa-plugin-contentful", - "version": "1.1.3", + "version": "1.1.4", "description": "Contentful plugin for Medusa Commerce", "main": "index.js", "repository": { diff --git a/packages/medusa-plugin-sendgrid/CHANGELOG.md b/packages/medusa-plugin-sendgrid/CHANGELOG.md index d8a161b95c..1b7107ad42 100644 --- a/packages/medusa-plugin-sendgrid/CHANGELOG.md +++ b/packages/medusa-plugin-sendgrid/CHANGELOG.md @@ -3,6 +3,18 @@ All notable changes to this project will be documented in this file. See [Conventional Commits](https://conventionalcommits.org) for commit guidelines. +## [1.1.4](https://github.com/medusajs/medusa/compare/medusa-plugin-sendgrid@1.1.3...medusa-plugin-sendgrid@1.1.4) (2021-02-25) + + +### Bug Fixes + +* add tracking links to shipments ([7be4bb5](https://github.com/medusajs/medusa/commit/7be4bb5f2daa0aad805abe0f97278f53cf3af402)) +* sendgrid tracking links ([5cfc8d8](https://github.com/medusajs/medusa/commit/5cfc8d80bd3eaee93595027d0cc3ce67ae98d275)) + + + + + ## [1.1.3](https://github.com/medusajs/medusa/compare/medusa-plugin-sendgrid@1.1.2...medusa-plugin-sendgrid@1.1.3) (2021-02-17) diff --git a/packages/medusa-plugin-sendgrid/package.json b/packages/medusa-plugin-sendgrid/package.json index 762389382a..7df27324ba 100644 --- a/packages/medusa-plugin-sendgrid/package.json +++ b/packages/medusa-plugin-sendgrid/package.json @@ -1,6 +1,6 @@ { "name": "medusa-plugin-sendgrid", - "version": "1.1.3", + "version": "1.1.4", "description": "SendGrid transactional emails", "main": "index.js", "repository": { diff --git a/packages/medusa/CHANGELOG.md b/packages/medusa/CHANGELOG.md index 4761cae558..890c4e0c76 100644 --- a/packages/medusa/CHANGELOG.md +++ b/packages/medusa/CHANGELOG.md @@ -3,6 +3,17 @@ All notable changes to this project will be documented in this file. See [Conventional Commits](https://conventionalcommits.org) for commit guidelines. +## [1.1.11](https://github.com/medusajs/medusa/compare/@medusajs/medusa@1.1.10...@medusajs/medusa@1.1.11) (2021-02-25) + + +### Bug Fixes + +* **medusa:** Add querying func. on customer retrievals ([#181](https://github.com/medusajs/medusa/issues/181)) ([22be418](https://github.com/medusajs/medusa/commit/22be418ec132944afe469106ba4b3b92f634d240)) + + + + + ## [1.1.10](https://github.com/medusajs/medusa/compare/@medusajs/medusa@1.1.10-next.1...@medusajs/medusa@1.1.10) (2021-02-25) **Note:** Version bump only for package @medusajs/medusa diff --git a/packages/medusa/package.json b/packages/medusa/package.json index 6e2bb9a723..7fd7fd6f15 100644 --- a/packages/medusa/package.json +++ b/packages/medusa/package.json @@ -1,6 +1,6 @@ { "name": "@medusajs/medusa", - "version": "1.1.10", + "version": "1.1.11", "description": "E-commerce for JAMstack", "main": "dist/index.js", "repository": { From 3ca04a8ca1acdbcf7276c23647ad3ff9679173f9 Mon Sep 17 00:00:00 2001 From: Oliver Windall Juhl <59018053+olivermrbl@users.noreply.github.com> Date: Thu, 25 Feb 2021 18:38:56 +0100 Subject: [PATCH 21/26] chore: Update README.md --- README.md | 126 ++++++++++++++++++++++++++++++++++++++++-------------- 1 file changed, 93 insertions(+), 33 deletions(-) diff --git a/README.md b/README.md index c75bba9654..fbfee350b6 100644 --- a/README.md +++ b/README.md @@ -1,36 +1,96 @@ -# medusa -Medusa Monorepo +# Medusa +Medusa is a headless commerce engine built with Node.js using Express with a Postgresql database. -# MVP Roadmap (!) +## Documentation -- Finish core - - Services - - [x] Auth - - [x] Product - - [x] Product Variant - - [x] User - - [ ] Region - - [ ] Cart - - [x] Customer - - [ ] Order - - [ ] Promo Code - - [ ] Gift cards - - REST API controllers - - Admin - - Store -- Core plugins - - Payment Providers - - [ ] Stripe - - [ ] Klarna - - [ ] PayPal - - [ ] QuickPay - - Fulfillment providers - - [ ] E-conomic - - [ ] Brightpearl - - [ ] Shipmondo - - [ ] Webshipper - - Transactional Emails - - [ ] Twilio SendGrid - - Role Based Permission - - Contentful sync plugin (to send SKUs to Contentful for content enrichment) +See [Medusa Commerce API docs](https://docs.medusa-commerce.com/api/store/) for Node.js. + +## Get started in less than 5 minutes + +You can get a Medusa engine up and running in your local development environment within a couple of minutes. Perform the following steps: + +1. Install Medusa, the Medusa CLI, Medusa babel preset and Medusa interfaces + + ```bash + # core medusa + npm install @medusajs/medusa + yarn add @medusajs/medusa + + # CLI + npm install -g @medusa/medusa-cli + yarn add global @medusajs/medusa-cli + + # babel preset + npm install babel-preset-medusa-package + yarn add babel-preset-medusa-package + + # interfaces + npm install medusa-interfaces + yarn add medusa-interfaces + ``` +2. Create a file `medusa-config.js` at the root level of your Node.js project and fill in required settings + ``` + // CORS to avoid issues when consuming Medusa from a client + const STORE_CORS = "http://localhost:8000"; + + // Database URL (here we use a local database called medusa-development) + const DATABASE_URL = "postgres://localhost/medusa-development"; + + // Medusa uses Redis, so this needs configuration as well + const REDIS_URL = "redis://localhost:6379" + + // This is the place to include plugins. See API documentation for a thorough guide on plugins. + const plugins = []; + + module.exports = { + projectConfig: { + redis_url: REDIS_URL, + database_url: DATABASE_URL, + database_logging: true, + database_extra: + process.env.NODE_ENV === "production" || + process.env.NODE_ENV === "staging" + ? { + ssl: { rejectUnauthorized: false }, + } + : {}, + database_type: "postgres", + store_cors: STORE_CORS, + }, + plugins, + }; + ``` + +3. Create a Medusa user, such that you can perform authenticated calls + + ```bash + # provide email and password to the command + medusa user -e lebron@james.com -p lebronjames123 + ``` + +4. Start your Medusa engine in your local environment + + ```bash + medusa develop + ``` + +5. Open any client or API tool to start using your Medusa engine + + Medusa is running at `http://localhost:4000`. You should now investigate our [API docs](https://docs.medusa-commerce.com/api/store/) to start playing around with your new headless commerce engine. + +After these four steps and only a couple of minutes, you now have a complete commerce engine running locally. + +## Contribution + +Medusa is all about the community. Therefore, we would love for you to help us build the most robust and powerful commerce engine on the market. Whether its fixing bugs, improving our documentation or simply spreading the word, please feel free to join in. + +## Repository structure + +The Medusa repository is a mono-repository managed using Lerna. Lerna allows us to have all Medusa packages in one place, and still distribute them as separate NPM packages. + +## Licensed + +Licended under the [MIT License](https://github.com/medusajs/medusa/blob/master/LICENSE) + +## Thank you! From 4d708d230613d0bfb19ce949bd9d1b5e62b35bd1 Mon Sep 17 00:00:00 2001 From: Oliver Windall Juhl <59018053+olivermrbl@users.noreply.github.com> Date: Fri, 26 Feb 2021 07:58:59 +0100 Subject: [PATCH 22/26] hotfix(medusa): Optimize product retrieval (#185) --- .../routes/admin/products/list-products.js | 14 ++++- packages/medusa/src/repositories/product.ts | 52 ++++++++++++++++++- .../medusa/src/services/__tests__/product.js | 21 ++++---- packages/medusa/src/services/product.js | 52 ++++++++++++++----- 4 files changed, 111 insertions(+), 28 deletions(-) diff --git a/packages/medusa/src/api/routes/admin/products/list-products.js b/packages/medusa/src/api/routes/admin/products/list-products.js index e5190416fd..a1aa7b9982 100644 --- a/packages/medusa/src/api/routes/admin/products/list-products.js +++ b/packages/medusa/src/api/routes/admin/products/list-products.js @@ -14,13 +14,23 @@ export default async (req, res) => { selector.q = req.query.q } + let includeFields = [] + if ("fields" in req.query) { + includeFields = req.query.fields.split(",") + } + + let expandFields = [] + if ("expand" in req.query) { + expandFields = req.query.expand.split(",") + } + if ("is_giftcard" in req.query) { selector.is_giftcard = req.query.is_giftcard === "true" } const listConfig = { - select: defaultFields, - relations: defaultRelations, + select: includeFields.length ? includeFields : defaultFields, + relations: expandFields.length ? expandFields : defaultRelations, skip: offset, take: limit, } diff --git a/packages/medusa/src/repositories/product.ts b/packages/medusa/src/repositories/product.ts index 63659e200f..46e01c29bb 100644 --- a/packages/medusa/src/repositories/product.ts +++ b/packages/medusa/src/repositories/product.ts @@ -1,5 +1,53 @@ -import { EntityRepository, Repository } from "typeorm" +import { flatten, groupBy, map, merge } from "lodash" +import { EntityRepository, FindManyOptions, Repository } from "typeorm" import { Product } from "../models/product" @EntityRepository(Product) -export class ProductRepository extends Repository {} +export class ProductRepository extends Repository { + public async findWithRelations( + relations: Array = [], + optionsWithoutRelations: Omit, "relations"> = {} + ): Promise { + const entities = await this.find(optionsWithoutRelations) + const entitiesIds = entities.map(({ id }) => id) + + const groupedRelations = {} + for (const rel of relations) { + const [topLevel] = rel.split(".") + if (groupedRelations[topLevel]) { + groupedRelations[topLevel].push(rel) + } else { + groupedRelations[topLevel] = [rel] + } + } + + const entitiesIdsWithRelations = await Promise.all( + Object.entries(groupedRelations).map(([_, rels]) => { + return this.findByIds(entitiesIds, { + select: ["id"], + relations: rels as string[], + }) + }) + ).then(flatten) + const entitiesAndRelations = entitiesIdsWithRelations.concat(entities) + + const entitiesAndRelationsById = groupBy(entitiesAndRelations, "id") + return map(entitiesAndRelationsById, entityAndRelations => + merge({}, ...entityAndRelations) + ) + } + + public async findOneWithRelations( + relations: Array = [], + optionsWithoutRelations: Omit, "relations"> = {} + ): Promise { + // Limit 1 + optionsWithoutRelations.take = 1 + + const result = await this.findWithRelations( + relations, + optionsWithoutRelations + ) + return result[0] + } +} diff --git a/packages/medusa/src/services/__tests__/product.js b/packages/medusa/src/services/__tests__/product.js index de1eb7fe78..422bdb42e5 100644 --- a/packages/medusa/src/services/__tests__/product.js +++ b/packages/medusa/src/services/__tests__/product.js @@ -11,7 +11,8 @@ const eventBusService = { describe("ProductService", () => { describe("retrieve", () => { const productRepo = MockRepository({ - findOne: () => Promise.resolve({ id: IdMap.getId("ironman") }), + findOneWithRelations: () => + Promise.resolve({ id: IdMap.getId("ironman") }), }) const productService = new ProductService({ manager: MockManager, @@ -25,8 +26,8 @@ describe("ProductService", () => { it("successfully retrieves a product", async () => { const result = await productService.retrieve(IdMap.getId("ironman")) - expect(productRepo.findOne).toHaveBeenCalledTimes(1) - expect(productRepo.findOne).toHaveBeenCalledWith({ + expect(productRepo.findOneWithRelations).toHaveBeenCalledTimes(1) + expect(productRepo.findOneWithRelations).toHaveBeenCalledWith(undefined, { where: { id: IdMap.getId("ironman") }, }) @@ -42,7 +43,7 @@ describe("ProductService", () => { options: [], collection: { id: IdMap.getId("cat"), title: "Suits" }, }), - findOne: () => ({ + findOneWithRelations: () => ({ id: IdMap.getId("ironman"), title: "Suit", options: [], @@ -137,7 +138,7 @@ describe("ProductService", () => { describe("update", () => { const productRepository = MockRepository({ - findOne: query => { + findOneWithRelations: (rels, query) => { if (query.where.id === IdMap.getId("ironman&co")) { return Promise.resolve({ id: IdMap.getId("ironman&co"), @@ -322,7 +323,7 @@ describe("ProductService", () => { describe("addOption", () => { const productRepository = MockRepository({ - findOne: query => + findOneWithRelations: query => Promise.resolve({ id: IdMap.getId("ironman"), options: [{ title: "Color" }], @@ -395,7 +396,7 @@ describe("ProductService", () => { describe("reorderVariants", () => { const productRepository = MockRepository({ - findOne: query => + findOneWithRelations: query => Promise.resolve({ id: IdMap.getId("ironman"), variants: [{ id: IdMap.getId("green") }, { id: IdMap.getId("blue") }], @@ -453,7 +454,7 @@ describe("ProductService", () => { describe("reorderOptions", () => { const productRepository = MockRepository({ - findOne: query => + findOneWithRelations: query => Promise.resolve({ id: IdMap.getId("ironman"), options: [ @@ -519,7 +520,7 @@ describe("ProductService", () => { describe("updateOption", () => { const productRepository = MockRepository({ - findOne: query => + findOneWithRelations: query => Promise.resolve({ id: IdMap.getId("ironman"), options: [ @@ -594,7 +595,7 @@ describe("ProductService", () => { describe("deleteOption", () => { const productRepository = MockRepository({ - findOne: query => + findOneWithRelations: query => Promise.resolve({ id: IdMap.getId("ironman"), variants: [ diff --git a/packages/medusa/src/services/product.js b/packages/medusa/src/services/product.js index 7e38385f2a..38b3fb4696 100644 --- a/packages/medusa/src/services/product.js +++ b/packages/medusa/src/services/product.js @@ -93,6 +93,17 @@ class ProductService extends BaseService { const query = this.buildQuery_(selector, config) + if (config.relations && config.relations.length > 0) { + query.relations = config.relations + } + + if (config.select && config.select.length > 0) { + query.select = config.select + } + + const rels = query.relations + delete query.relations + if (q) { const where = query.where @@ -122,7 +133,7 @@ class ProductService extends BaseService { } } - return productRepo.find(query) + return productRepo.findWithRelations(rels, query) } /** @@ -143,20 +154,33 @@ class ProductService extends BaseService { * @return {Promise} the result of the find one operation. */ async retrieve(productId, config = {}) { - return this.atomicPhase_(async manager => { - const productRepo = manager.getCustomRepository(this.productRepository_) - const validatedId = this.validateId_(productId) - const query = this.buildQuery_({ id: validatedId }, config) - const product = await productRepo.findOne(query) - if (!product) { - throw new MedusaError( - MedusaError.Types.NOT_FOUND, - `Product with id: ${productId} was not found` - ) - } + const productRepo = this.manager_.getCustomRepository( + this.productRepository_ + ) + const validatedId = this.validateId_(productId) - return product - }) + const query = { where: { id: validatedId } } + + if (config.relations && config.relations.length > 0) { + query.relations = config.relations + } + + if (config.select && config.select.length > 0) { + query.select = config.select + } + + const rels = query.relations + delete query.relations + const product = await productRepo.findOneWithRelations(rels, query) + + if (!product) { + throw new MedusaError( + MedusaError.Types.NOT_FOUND, + `Product with id: ${productId} was not found` + ) + } + + return product } /** From adce71042d5b4e5570c8d27797e8f3ce603c6a5a Mon Sep 17 00:00:00 2001 From: Sebastian Rindom Date: Fri, 26 Feb 2021 12:51:20 +0100 Subject: [PATCH 23/26] hotfix(paypal): create new payment session if update fails --- .../medusa-payment-paypal/src/api/routes/hooks/paypal.js | 5 +++++ .../medusa-payment-paypal/src/services/paypal-provider.js | 2 +- 2 files changed, 6 insertions(+), 1 deletion(-) diff --git a/packages/medusa-payment-paypal/src/api/routes/hooks/paypal.js b/packages/medusa-payment-paypal/src/api/routes/hooks/paypal.js index e0ef09b680..03fa6d3276 100644 --- a/packages/medusa-payment-paypal/src/api/routes/hooks/paypal.js +++ b/packages/medusa-payment-paypal/src/api/routes/hooks/paypal.js @@ -30,6 +30,11 @@ export default async (req, res) => { const purchaseUnit = order.purchase_units[0] const cartId = purchaseUnit.custom_id + if (!cartId) { + res.sendStatus(200) + return + } + const manager = req.scope.resolve("manager") const cartService = req.scope.resolve("cartService") const orderService = req.scope.resolve("orderService") diff --git a/packages/medusa-payment-paypal/src/services/paypal-provider.js b/packages/medusa-payment-paypal/src/services/paypal-provider.js index bf78dbf388..ed868da3c8 100644 --- a/packages/medusa-payment-paypal/src/services/paypal-provider.js +++ b/packages/medusa-payment-paypal/src/services/paypal-provider.js @@ -206,7 +206,7 @@ class PayPalProviderService extends PaymentService { return sessionData } catch (error) { - throw error + return this.createPayment(cart) } } From 1b7fa59bf70b67c71709cdaf0f804aaaf2840f84 Mon Sep 17 00:00:00 2001 From: Sebastian Rindom Date: Fri, 26 Feb 2021 13:13:28 +0100 Subject: [PATCH 24/26] hotfix(paypal): create new payment session if update fails (#186) --- .../medusa-payment-paypal/src/api/routes/hooks/paypal.js | 5 +++++ .../medusa-payment-paypal/src/services/paypal-provider.js | 2 +- 2 files changed, 6 insertions(+), 1 deletion(-) diff --git a/packages/medusa-payment-paypal/src/api/routes/hooks/paypal.js b/packages/medusa-payment-paypal/src/api/routes/hooks/paypal.js index e0ef09b680..03fa6d3276 100644 --- a/packages/medusa-payment-paypal/src/api/routes/hooks/paypal.js +++ b/packages/medusa-payment-paypal/src/api/routes/hooks/paypal.js @@ -30,6 +30,11 @@ export default async (req, res) => { const purchaseUnit = order.purchase_units[0] const cartId = purchaseUnit.custom_id + if (!cartId) { + res.sendStatus(200) + return + } + const manager = req.scope.resolve("manager") const cartService = req.scope.resolve("cartService") const orderService = req.scope.resolve("orderService") diff --git a/packages/medusa-payment-paypal/src/services/paypal-provider.js b/packages/medusa-payment-paypal/src/services/paypal-provider.js index bf78dbf388..ed868da3c8 100644 --- a/packages/medusa-payment-paypal/src/services/paypal-provider.js +++ b/packages/medusa-payment-paypal/src/services/paypal-provider.js @@ -206,7 +206,7 @@ class PayPalProviderService extends PaymentService { return sessionData } catch (error) { - throw error + return this.createPayment(cart) } } From 5e2f550ae10a3eb7636edf6bf99197517a1fa7b3 Mon Sep 17 00:00:00 2001 From: Sebastian Rindom Date: Fri, 26 Feb 2021 21:07:51 +0100 Subject: [PATCH 25/26] fix: floor amounts --- .../medusa-payment-stripe/src/services/stripe-provider.js | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/packages/medusa-payment-stripe/src/services/stripe-provider.js b/packages/medusa-payment-stripe/src/services/stripe-provider.js index b55b921bd2..d81b390f3e 100644 --- a/packages/medusa-payment-stripe/src/services/stripe-provider.js +++ b/packages/medusa-payment-stripe/src/services/stripe-provider.js @@ -141,7 +141,7 @@ class StripeProviderService extends PaymentService { const amount = await this.totalsService_.getTotal(cart) const intentRequest = { - amount: amount, + amount: Math.floor(amount), currency: currency_code, setup_future_usage: "on_session", capture_method: this.options_.capture ? "automatic" : "manual", @@ -242,12 +242,12 @@ class StripeProviderService extends PaymentService { if (stripeId !== sessionData.customer) { return this.createPayment(cart) } else { - if (cart.total && sessionData.amount === cart.total) { + if (cart.total && sessionData.amount === Math.floor(cart.total)) { return sessionData } return this.stripe_.paymentIntents.update(sessionData.id, { - amount: cart.total, + amount: Math.floor(cart.total), }) } } catch (error) { @@ -309,7 +309,7 @@ class StripeProviderService extends PaymentService { const { id } = payment.data try { await this.stripe_.refunds.create({ - amount: amountToRefund, + amount: Math.floor(amountToRefund), payment_intent: id, }) From 74a6b67f9db0a66fdf3cf69be6db62ae0deea635 Mon Sep 17 00:00:00 2001 From: Sebastian Rindom Date: Fri, 26 Feb 2021 21:18:37 +0100 Subject: [PATCH 26/26] fix: round instead of floor --- .../medusa-payment-stripe/src/services/stripe-provider.js | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/packages/medusa-payment-stripe/src/services/stripe-provider.js b/packages/medusa-payment-stripe/src/services/stripe-provider.js index d81b390f3e..34406cd467 100644 --- a/packages/medusa-payment-stripe/src/services/stripe-provider.js +++ b/packages/medusa-payment-stripe/src/services/stripe-provider.js @@ -141,7 +141,7 @@ class StripeProviderService extends PaymentService { const amount = await this.totalsService_.getTotal(cart) const intentRequest = { - amount: Math.floor(amount), + amount: Math.round(amount), currency: currency_code, setup_future_usage: "on_session", capture_method: this.options_.capture ? "automatic" : "manual", @@ -242,12 +242,12 @@ class StripeProviderService extends PaymentService { if (stripeId !== sessionData.customer) { return this.createPayment(cart) } else { - if (cart.total && sessionData.amount === Math.floor(cart.total)) { + if (cart.total && sessionData.amount === Math.round(cart.total)) { return sessionData } return this.stripe_.paymentIntents.update(sessionData.id, { - amount: Math.floor(cart.total), + amount: Math.round(cart.total), }) } } catch (error) { @@ -309,7 +309,7 @@ class StripeProviderService extends PaymentService { const { id } = payment.data try { await this.stripe_.refunds.create({ - amount: Math.floor(amountToRefund), + amount: Math.round(amountToRefund), payment_intent: id, })