fix merge conflicts

This commit is contained in:
olivermrbl
2021-03-17 08:52:00 +01:00
29 changed files with 2847 additions and 1807 deletions
@@ -0,0 +1,62 @@
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 adminSeeder = require("../../helpers/admin-seeder");
const fixtureWriter = require("../../utils/write-fixture").default;
jest.setTimeout(30000);
describe("/admin/auth", () => {
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-fixtures" });
medusaProcess.kill();
});
describe("POST /admin/products", () => {
beforeEach(async () => {
try {
await adminSeeder(dbConnection);
} catch (err) {
console.log(err);
throw err;
}
});
afterEach(async () => {
const manager = dbConnection.manager;
await manager.query(`DELETE FROM "user"`);
});
it("authenticates user", async () => {
const api = useApi();
const response = await api
.post("/admin/auth", {
email: "admin@medusa.js",
password: "secret_password",
})
.catch((err) => {
console.log(err);
});
expect(response.status).toEqual(200);
fixtureWriter.addFixture("user", response.data.user);
});
});
});
@@ -1,5 +1,6 @@
const { dropDatabase } = require("pg-god"); const { dropDatabase } = require("pg-god");
const path = require("path"); const path = require("path");
const { ProductVariant } = require("@medusajs/medusa");
const setupServer = require("../../../helpers/setup-server"); const setupServer = require("../../../helpers/setup-server");
const { useApi } = require("../../../helpers/use-api"); const { useApi } = require("../../../helpers/use-api");
@@ -161,4 +162,93 @@ describe("/admin/orders", () => {
fixtureWriter.addFixture("return", response.data.order.returns[0]); fixtureWriter.addFixture("return", response.data.order.returns[0]);
}); });
}); });
describe("POST /admin/orders/:id/swaps", () => {
let id;
let varId;
beforeEach(async () => {
try {
await adminSeeder(dbConnection);
const order = await orderSeeder(dbConnection, {
fulfillment_status: "fulfilled",
payment_status: "captured",
});
id = order.id;
const pVar = await dbConnection.manager.findOne(ProductVariant, {});
varId = pVar.id;
} catch (err) {
console.log(err);
throw err;
}
});
afterEach(async () => {
const manager = dbConnection.manager;
await manager.query(`DELETE FROM "fulfillment_item"`);
await manager.query(`DELETE FROM "fulfillment"`);
await manager.query(`DELETE FROM "return_item"`);
await manager.query(`DELETE FROM "return"`);
await manager.query(`DELETE FROM "claim_image"`);
await manager.query(`DELETE FROM "claim_tag"`);
await manager.query(`DELETE FROM "claim_item"`);
await manager.query(`DELETE FROM "shipping_method"`);
await manager.query(`DELETE FROM "line_item"`);
await manager.query(`DELETE FROM "swap"`);
await manager.query(`DELETE FROM "cart"`);
await manager.query(`DELETE FROM "claim_order"`);
await manager.query(`DELETE FROM "money_amount"`);
await manager.query(`DELETE FROM "product_option_value"`);
await manager.query(`DELETE FROM "product_option"`);
await manager.query(`DELETE FROM "product_variant"`);
await manager.query(`DELETE FROM "product"`);
await manager.query(`DELETE FROM "shipping_option"`);
await manager.query(`DELETE FROM "discount"`);
await manager.query(`DELETE FROM "payment"`);
await manager.query(`DELETE FROM "order"`);
await manager.query(`DELETE FROM "customer"`);
await manager.query(
`UPDATE "country" SET region_id=NULL WHERE iso_2 = 'us'`
);
await manager.query(`DELETE FROM "region"`);
await manager.query(`DELETE FROM "user"`);
});
it("creates a swap", async () => {
const api = useApi();
const { data } = await api.get(`/admin/orders/${id}`, {
headers: {
authorization: "Bearer test_token",
},
});
const order = data.order;
const response = await api.post(
`/admin/orders/${id}/swaps`,
{
return_items: [
{
item_id: order.items[0].id,
quantity: 1,
},
],
additional_items: [
{
variant_id: varId,
quantity: 2,
},
],
},
{
headers: {
authorization: "Bearer test_token",
},
}
);
expect(response.status).toEqual(200);
fixtureWriter.addFixture("swap", response.data.order.swaps[0]);
});
});
}); });
@@ -78,10 +78,6 @@ describe("/shipping-options", () => {
fixtureWriter.addFixture("region", getRes.data.shipping_option.region); fixtureWriter.addFixture("region", getRes.data.shipping_option.region);
fixtureWriter.addFixture("shipping_option", getRes.data.shipping_option); fixtureWriter.addFixture("shipping_option", getRes.data.shipping_option);
fixtureWriter.addFixture(
"shipping_profile",
getRes.data.shipping_option.shipping_profile
);
}); });
}); });
}); });
@@ -0,0 +1,74 @@
const { dropDatabase } = require("pg-god");
const path = require("path");
const { Region } = require("@medusajs/medusa");
const setupServer = require("../../../helpers/setup-server");
const { useApi } = require("../../../helpers/use-api");
const { initDb } = require("../../../helpers/use-db");
const adminSeeder = require("../../helpers/admin-seeder");
const fixtureWriter = require("../../utils/write-fixture").default;
jest.setTimeout(30000);
describe("/shipping-profiles", () => {
let medusaProcess;
let dbConnection;
beforeAll(async () => {
const cwd = path.resolve(path.join(__dirname, "..", ".."));
dbConnection = await initDb({ cwd });
medusaProcess = await setupServer({ cwd });
});
afterAll(async () => {
dbConnection.close();
await dropDatabase({ databaseName: "medusa-fixtures" });
medusaProcess.kill();
});
describe("POST /admin/shipping-profiles", () => {
let regId;
beforeEach(async () => {
await adminSeeder(dbConnection);
const manager = dbConnection.manager;
const created = manager.create(Region, {
name: "Test Region",
currency_code: "usd",
tax_rate: 0,
fulfillment_providers: [
{
id: "test-ful",
},
],
});
const newReg = await manager.save(created);
regId = newReg.id;
});
afterEach(async () => {
const manager = dbConnection.manager;
await manager.query(`DELETE FROM "shipping_option"`);
await manager.query(`DELETE FROM "region"`);
await manager.query(`DELETE FROM "user"`);
});
it("creates a cart", async () => {
const api = useApi();
const getRes = await api.get(`/admin/shipping-profiles`, {
headers: {
Authorization: "Bearer test_token",
},
});
expect(getRes.status).toEqual(200);
fixtureWriter.addFixture(
"shipping_profile",
getRes.data.shipping_profiles[0]
);
});
});
});
@@ -0,0 +1,56 @@
const { dropDatabase } = require("pg-god");
const path = require("path");
const { Region } = require("@medusajs/medusa");
const setupServer = require("../../../helpers/setup-server");
const { useApi } = require("../../../helpers/use-api");
const { initDb } = require("../../../helpers/use-db");
const adminSeeder = require("../../helpers/admin-seeder");
const fixtureWriter = require("../../utils/write-fixture").default;
jest.setTimeout(30000);
describe("/shipping-profiles", () => {
let medusaProcess;
let dbConnection;
beforeAll(async () => {
const cwd = path.resolve(path.join(__dirname, "..", ".."));
dbConnection = await initDb({ cwd });
medusaProcess = await setupServer({ cwd });
});
afterAll(async () => {
dbConnection.close();
await dropDatabase({ databaseName: "medusa-fixtures" });
medusaProcess.kill();
});
describe("GET /admin/store", () => {
let regId;
beforeEach(async () => {
await adminSeeder(dbConnection);
});
afterEach(async () => {
const manager = dbConnection.manager;
await manager.query(`DELETE FROM "user"`);
});
it("creates a cart", async () => {
const api = useApi();
const getRes = await api.get(`/admin/store`, {
headers: {
Authorization: "Bearer test_token",
},
});
expect(getRes.status).toEqual(200);
fixtureWriter.addFixture("store", getRes.data.store);
});
});
});
@@ -43,7 +43,7 @@ module.exports = async (connection, data = {}) => {
}, },
], ],
}); });
const newProdVar = manager.save(prodVar); const newProdVar = await manager.save(prodVar);
const ma = manager.create(MoneyAmount, { const ma = manager.create(MoneyAmount, {
variant_id: newProdVar.id, variant_id: newProdVar.id,
+3 -3
View File
@@ -7,13 +7,13 @@
"build": "babel src -d dist --extensions \".ts,.js\"" "build": "babel src -d dist --extensions \".ts,.js\""
}, },
"dependencies": { "dependencies": {
"@medusajs/medusa": "1.1.11-dev-1615546466988", "@medusajs/medusa": "1.1.11-dev-1615929449260",
"medusa-interfaces": "1.1.1-dev-1615546466988" "medusa-interfaces": "1.1.1-dev-1615929449260"
}, },
"devDependencies": { "devDependencies": {
"@babel/cli": "^7.12.10", "@babel/cli": "^7.12.10",
"@babel/core": "^7.12.10", "@babel/core": "^7.12.10",
"@babel/node": "^7.12.10", "@babel/node": "^7.12.10",
"babel-preset-medusa-package": "1.1.0-dev-1615546466988" "babel-preset-medusa-package": "1.1.0-dev-1615929449260"
} }
} }
+24 -24
View File
@@ -946,10 +946,10 @@
dependencies: dependencies:
"@hapi/hoek" "^9.0.0" "@hapi/hoek" "^9.0.0"
"@medusajs/medusa@1.1.11-dev-1615546466988": "@medusajs/medusa@1.1.11-dev-1615929449260":
version "1.1.11-dev-1615546466988" version "1.1.11-dev-1615929449260"
resolved "http://localhost:4873/@medusajs%2fmedusa/-/medusa-1.1.11-dev-1615546466988.tgz#6d09c9ae174cee30a70e76e7e50e69bfc7d4b92a" resolved "http://localhost:4873/@medusajs%2fmedusa/-/medusa-1.1.11-dev-1615929449260.tgz#4635d197df491fa10ad80c6fda5818edb6cbe9ad"
integrity sha512-Y9gB8VXoZ/SN00UB8hRJ4xWRdSZX3mCz19ls2SDP4SrqUlWcG04LZDYeKbXQqXRKFFzwR/yNnWOCkLvlrK+69w== integrity sha512-Yx94TuEWe76MLslv1PmDOIDrEJ5lQz8cL2rikK7OquK4oyt0Y8xCE5MNgiiZCP71/sv3TMCoTx0GZxrl02vk8w==
dependencies: dependencies:
"@babel/plugin-transform-classes" "^7.9.5" "@babel/plugin-transform-classes" "^7.9.5"
"@hapi/joi" "^16.1.8" "@hapi/joi" "^16.1.8"
@@ -971,8 +971,8 @@
joi "^17.3.0" joi "^17.3.0"
joi-objectid "^3.0.1" joi-objectid "^3.0.1"
jsonwebtoken "^8.5.1" jsonwebtoken "^8.5.1"
medusa-core-utils "1.1.0-dev-1615546466988" medusa-core-utils "1.1.0-dev-1615929449260"
medusa-test-utils "1.1.3-dev-1615546466988" medusa-test-utils "1.1.3-dev-1615929449260"
morgan "^1.9.1" morgan "^1.9.1"
multer "^1.4.2" multer "^1.4.2"
passport "^0.4.0" passport "^0.4.0"
@@ -1184,10 +1184,10 @@ babel-plugin-transform-typescript-metadata@^0.3.1:
dependencies: dependencies:
"@babel/helper-plugin-utils" "^7.0.0" "@babel/helper-plugin-utils" "^7.0.0"
babel-preset-medusa-package@1.1.0-dev-1615546466988: babel-preset-medusa-package@1.1.0-dev-1615929449260:
version "1.1.0-dev-1615546466988" version "1.1.0-dev-1615929449260"
resolved "http://localhost:4873/babel-preset-medusa-package/-/babel-preset-medusa-package-1.1.0-dev-1615546466988.tgz#7b99e2a01c4aa9ccd0f293ca6015c866cae941b5" resolved "http://localhost:4873/babel-preset-medusa-package/-/babel-preset-medusa-package-1.1.0-dev-1615929449260.tgz#668c9d5f7e385ca1f3b0c681b6e90f0195d45025"
integrity sha512-lMNL7fpsVgHJsiX69p7VLmNh7wCjA6nRZq9nslRisBYgeZ4O5fpatlXvL22kU4HaxGhhhF6n5LdpovCcvXoJYg== integrity sha512-y3GY3HFPPWOCY6OZ3rh3Ybms/LI6PzvD6Mo+nP6RBw1us6p4UAle1EoQrOp4gXYb5WX9PsYN5TwVUwgDNO7uwg==
dependencies: dependencies:
"@babel/plugin-proposal-class-properties" "^7.12.1" "@babel/plugin-proposal-class-properties" "^7.12.1"
"@babel/plugin-proposal-decorators" "^7.12.1" "@babel/plugin-proposal-decorators" "^7.12.1"
@@ -2649,28 +2649,28 @@ media-typer@0.3.0:
resolved "https://registry.yarnpkg.com/media-typer/-/media-typer-0.3.0.tgz#8710d7af0aa626f8fffa1ce00168545263255748" resolved "https://registry.yarnpkg.com/media-typer/-/media-typer-0.3.0.tgz#8710d7af0aa626f8fffa1ce00168545263255748"
integrity sha1-hxDXrwqmJvj/+hzgAWhUUmMlV0g= integrity sha1-hxDXrwqmJvj/+hzgAWhUUmMlV0g=
medusa-core-utils@1.1.0-dev-1615546466988: medusa-core-utils@1.1.0-dev-1615929449260:
version "1.1.0-dev-1615546466988" version "1.1.0-dev-1615929449260"
resolved "http://localhost:4873/medusa-core-utils/-/medusa-core-utils-1.1.0-dev-1615546466988.tgz#dfcc316b59d24c0c03c2f3eb53f8c9fe9771cc03" resolved "http://localhost:4873/medusa-core-utils/-/medusa-core-utils-1.1.0-dev-1615929449260.tgz#ad6334e195a77cbf1764ea637f6071a4441adf68"
integrity sha512-LHKb/CiNTgbCDHJPt32QCnm4/J39uMasv19TUSB3/8Np85RWalXWQjMWmQF+f/pFuzB0/6bx7z4SFiYK6dw7YQ== integrity sha512-udhVtrOWoab7Mljb4r427+iCZ1vy/XJb+yr6Q8xZe535on6DYpjahEiuLgkyy19wX50kVv5yt3raTE4Vg3yKEw==
dependencies: dependencies:
joi "^17.3.0" joi "^17.3.0"
joi-objectid "^3.0.1" joi-objectid "^3.0.1"
medusa-interfaces@1.1.1-dev-1615546466988: medusa-interfaces@1.1.1-dev-1615929449260:
version "1.1.1-dev-1615546466988" version "1.1.1-dev-1615929449260"
resolved "http://localhost:4873/medusa-interfaces/-/medusa-interfaces-1.1.1-dev-1615546466988.tgz#0e109781d8691b8495c79e4d3bccd5c63668fcf0" resolved "http://localhost:4873/medusa-interfaces/-/medusa-interfaces-1.1.1-dev-1615929449260.tgz#6034b9f472591b85294430ecce8c68a8b05bd58a"
integrity sha512-Hc+aSqTwPU63HJDi11eGj5uP3ebCi3BC5YEDptumMf/JRDDZdwq8SRcwtCNKMBSIlPpsqjBqHcm8Dn7uvwXhhA== integrity sha512-w4ORNLHtec/DbMTLCfWatcUU9uVZfQtiOV12/quxg+N9K/2yk7jl8SAWhFiCc0gbT7Trwy1+V8esGEaAIPqMkQ==
dependencies: dependencies:
medusa-core-utils "1.1.0-dev-1615546466988" medusa-core-utils "1.1.0-dev-1615929449260"
medusa-test-utils@1.1.3-dev-1615546466988: medusa-test-utils@1.1.3-dev-1615929449260:
version "1.1.3-dev-1615546466988" version "1.1.3-dev-1615929449260"
resolved "http://localhost:4873/medusa-test-utils/-/medusa-test-utils-1.1.3-dev-1615546466988.tgz#85e3f5b435fe4259cab3ac69bad9a23d1b301c4f" resolved "http://localhost:4873/medusa-test-utils/-/medusa-test-utils-1.1.3-dev-1615929449260.tgz#7b6d81c6eae1147e5f36d7242021f9f245e8662d"
integrity sha512-ZBqX7+UEFYXcdoRFnNiv6uv3UR+bU2IBLMVdAk+/FpxX9GYBW385LKoUiCs6oRIAtHqFICHh+RNuakI2v7ra7A== integrity sha512-Kqxf8/HjusYvVLf6jjdC62ci68JGyE20P1W8suB7cM8qnXNJHuKh5EXhFJRFX00tgr3N2oq68qrAUNcakB0IKA==
dependencies: dependencies:
"@babel/plugin-transform-classes" "^7.9.5" "@babel/plugin-transform-classes" "^7.9.5"
medusa-core-utils "1.1.0-dev-1615546466988" medusa-core-utils "1.1.0-dev-1615929449260"
randomatic "^3.1.1" randomatic "^3.1.1"
merge-descriptors@1.0.1: merge-descriptors@1.0.1:
+2 -2
View File
@@ -6,8 +6,8 @@ const importFrom = require("import-from");
const initialize = async () => { const initialize = async () => {
const app = express(); const app = express();
const loaders = importFrom(process.cwd(), "@medusajs/medusa/dist/loaders") const cwd = process.cwd();
.default; const loaders = importFrom(cwd, "@medusajs/medusa/dist/loaders").default;
const { dbConnection } = await loaders({ const { dbConnection } = await loaders({
directory: path.resolve(process.cwd()), directory: path.resolve(process.cwd()),
+694 -325
View File
File diff suppressed because it is too large Load Diff
+49 -47
View File
@@ -53,7 +53,7 @@ paths:
application/json: application/json:
schema: schema:
properties: properties:
customer: user:
$ref: '#/components/schemas/user' $ref: '#/components/schemas/user'
requestBody: requestBody:
content: content:
@@ -83,7 +83,7 @@ paths:
application/json: application/json:
schema: schema:
properties: properties:
customer: user:
$ref: '#/components/schemas/user' $ref: '#/components/schemas/user'
/collections: /collections:
post: post:
@@ -695,6 +695,49 @@ paths:
properties: properties:
discount: discount:
$ref: '#/components/schemas/discount' $ref: '#/components/schemas/discount'
/notifications:
get:
operationId: GetNotifications
summary: List Notifications
description: Retrieves a list of Notifications.
tags:
- Notification
responses:
'200':
description: OK
content:
application/json:
schema:
properties:
notifications:
type: array
items:
$ref: '#/components/schemas/notification'
'/notifications/{id}/resend':
post:
operationId: PostNotificationsNotificationResend
summary: Resend Notification
description: >-
Resends a previously sent notifications, with the same data but
optionally to a different address
parameters:
- in: path
name: id
required: true
description: The id of the Notification
schema:
type: string
tags:
- Notification
responses:
'200':
description: OK
content:
application/json:
schema:
properties:
notification:
$ref: '#/components/schemas/notification'
/gift-cards: /gift-cards:
post: post:
operationId: PostGiftCards operationId: PostGiftCards
@@ -867,49 +910,6 @@ paths:
properties: properties:
gift_card: gift_card:
$ref: '#/components/schemas/gift_card' $ref: '#/components/schemas/gift_card'
/notifications:
get:
operationId: GetNotifications
summary: List Notifications
description: Retrieves a list of Notifications.
tags:
- Notification
responses:
'200':
description: OK
content:
application/json:
schema:
properties:
notifications:
type: array
items:
$ref: '#/components/schemas/notification'
'/notifications/{id}/resend':
post:
operationId: PostNotificationsNotificationResend
summary: Resend Notification
description: >-
Resends a previously sent notifications, with the same data but
optionally to a different address
parameters:
- in: path
name: id
required: true
description: The id of the Notification
schema:
type: string
tags:
- Notification
responses:
'200':
description: OK
content:
application/json:
schema:
properties:
notification:
$ref: '#/components/schemas/notification'
'/orders/{id}/shipping-methods': '/orders/{id}/shipping-methods':
post: post:
operationId: PostOrdersOrderShippingMethods operationId: PostOrdersOrderShippingMethods
@@ -1511,8 +1511,10 @@ paths:
application/json: application/json:
schema: schema:
properties: properties:
order: orders:
$ref: '#/components/schemas/order' type: array
items:
$ref: '#/components/schemas/order'
'/orders/{id}/swaps/{swap_id}/process-payment': '/orders/{id}/swaps/{swap_id}/process-payment':
post: post:
operationId: PostOrdersOrderSwapsSwapProcessPayment operationId: PostOrdersOrderSwapsSwapProcessPayment
+742 -523
View File
File diff suppressed because it is too large Load Diff
+733 -724
View File
File diff suppressed because it is too large Load Diff
+145 -50
View File
@@ -1000,6 +1000,7 @@ paths:
application/json: application/json:
schema: schema:
properties: properties:
<<<<<<< HEAD
id: id:
description: The id of the Gift Card description: The id of the Gift Card
code: code:
@@ -1104,6 +1105,8 @@ paths:
application/json: application/json:
schema: schema:
properties: properties:
=======
>>>>>>> origin/master
customer: customer:
$ref: '#/components/schemas/customer' $ref: '#/components/schemas/customer'
'/regions/{id}': '/regions/{id}':
@@ -1156,6 +1159,7 @@ paths:
type: array type: array
items: items:
$ref: '#/components/schemas/region' $ref: '#/components/schemas/region'
<<<<<<< HEAD
'/swaps/{cart_id}': '/swaps/{cart_id}':
get: get:
operationId: GetSwapsSwapCartId operationId: GetSwapsSwapCartId
@@ -1180,11 +1184,15 @@ paths:
swap: swap:
$ref: '#/components/schemas/swap' $ref: '#/components/schemas/swap'
/shipping-options: /shipping-options:
=======
'/products/{id}':
>>>>>>> origin/master
get: get:
operationId: GetShippingOptions operationId: GetProductsProduct
summary: Retrieve Shipping Options summary: Retrieves a Product
description: Retrieves a list of Shipping Options. description: Retrieves a Product.
parameters: parameters:
<<<<<<< HEAD
- in: query - in: query
name: is_return name: is_return
description: >- description: >-
@@ -1200,6 +1208,140 @@ paths:
- in: query - in: query
name: region_id name: region_id
description: the Region to retrieve Shipping Options from. description: the Region to retrieve Shipping Options from.
=======
- in: path
name: id
required: true
description: The id of the Product.
>>>>>>> origin/master
schema:
type: string
tags:
- Product
responses:
'200':
description: OK
content:
application/json:
schema:
properties:
product:
$ref: '#/components/schemas/product'
/products:
get:
operationId: GetProducts
summary: List Products
description: Retrieves a list of Products.
tags:
- Product
responses:
'200':
description: OK
content:
application/json:
schema:
properties:
count:
description: The total number of Products.
type: integer
offset:
description: The offset for pagination.
type: integer
limit:
description: 'The maxmimum number of Products to return,'
type: integer
products:
type: array
items:
<<<<<<< HEAD
$ref: '#/components/schemas/shipping_option'
=======
$ref: '#/components/schemas/product'
'/swaps/{cart_id}':
get:
operationId: GetSwapsSwapCartId
summary: Retrieve Swap by Cart id
description: Retrieves a Swap by the id of the Cart used to confirm the Swap.
parameters:
- in: path
name: cart_id
required: true
description: The id of the Cart
schema:
type: string
tags:
- Swap
responses:
'200':
description: OK
content:
application/json:
schema:
properties:
swap:
$ref: '#/components/schemas/swap'
>>>>>>> origin/master
'/variants/{variant_id}':
get:
operationId: GetVariantsVariant
summary: Retrieve a Product Variant
description: Retrieves a Product Variant by id
parameters:
- in: path
name: variant_id
required: true
description: The id of the Product Variant.
schema:
type: string
tags:
- Product Variant
responses:
'200':
description: OK
content:
application/json:
schema:
properties:
variant:
$ref: '#/components/schemas/product_variant'
/variants:
get:
operationId: GetVariants
summary: Retrieve Product Variants
description: Retrieves a list of Product Variants
parameters:
- in: query
name: ids
description: A comma separated list of Product Variant ids to filter by.
schema:
type: string
tags:
- Product Variant
responses:
'200':
description: OK
content:
application/json:
schema:
properties:
variants:
type: array
items:
$ref: '#/components/schemas/product_variant'
/shipping-options:
get:
operationId: GetShippingOptions
summary: Retrieve Shipping Options
description: Retrieves a list of Shipping Options.
parameters:
- in: query
name: product_ids
description: A comma separated list of Product ids to filter Shipping Options by.
schema:
type: string
- in: query
name: region_id
description: the Region to retrieve Shipping Options from.
schema: schema:
type: string type: string
tags: tags:
@@ -1240,53 +1382,6 @@ paths:
type: array type: array
items: items:
$ref: '#/components/schemas/shipping_option' $ref: '#/components/schemas/shipping_option'
'/variants/{variant_id}':
get:
operationId: GetVariantsVariant
summary: Retrieve a Product Variant
description: Retrieves a Product Variant by id
parameters:
- in: path
name: variant_id
required: true
description: The id of the Product Variant.
schema:
type: string
tags:
- Product Variant
responses:
'200':
description: OK
content:
application/json:
schema:
properties:
variant:
$ref: '#/components/schemas/product_variant'
/variants:
get:
operationId: GetVariants
summary: Retrieve Product Variants
description: Retrieves a list of Product Variants
parameters:
- in: query
name: ids
description: A comma separated list of Product Variant ids to filter by.
schema:
type: string
tags:
- Product Variant
responses:
'200':
description: OK
content:
application/json:
schema:
properties:
variants:
type: array
items:
$ref: '#/components/schemas/product_variant'
components: components:
schemas: schemas:
address: address:
+6 -6
View File
@@ -2282,9 +2282,9 @@ domexception@^1.0.1:
webidl-conversions "^4.0.2" webidl-conversions "^4.0.2"
dot-prop@^4.1.0: dot-prop@^4.1.0:
version "4.2.0" version "4.2.1"
resolved "https://registry.yarnpkg.com/dot-prop/-/dot-prop-4.2.0.tgz#1f19e0c2e1aa0e32797c49799f2837ac6af69c57" resolved "https://registry.yarnpkg.com/dot-prop/-/dot-prop-4.2.1.tgz#45884194a71fc2cda71cbb4bceb3a4dd2f433ba4"
integrity sha512-tUMXrxlExSW6U2EXiiKGSBVdYgtV8qlHL+C10TsW4PURY/ic+eaysnSkwB4kA/mBlCyy/IKDJ+Lc3wbWeaXtuQ== integrity sha512-l0p4+mIuJIua0mhxGoh4a+iNL9bmeK5DvnSVQa6T0OhrVmaEa1XScX5Etc673FePCJOArq/4Pa2cLGODUWTPOQ==
dependencies: dependencies:
is-obj "^1.0.0" is-obj "^1.0.0"
@@ -3213,9 +3213,9 @@ inherits@2.0.3:
integrity sha1-Yzwsg+PaQqUC9SRmAiSA9CCCYd4= integrity sha1-Yzwsg+PaQqUC9SRmAiSA9CCCYd4=
ini@^1.3.4, ini@~1.3.0: ini@^1.3.4, ini@~1.3.0:
version "1.3.5" version "1.3.8"
resolved "https://registry.yarnpkg.com/ini/-/ini-1.3.5.tgz#eee25f56db1c9ec6085e0c22778083f596abf927" resolved "https://registry.yarnpkg.com/ini/-/ini-1.3.8.tgz#a29da425b48806f34767a4efce397269af28432c"
integrity sha512-RZY5huIKCMRWDUqZlEi72f/lmXKMvuszcMBduliQ3nnWbx9X/ZBQO7DijMEYS9EhHBb2qacRUMtC7svLwe0lcw== integrity sha512-JV/yugV2uzW5iMRSiZAyDtQd+nxtUnjeLt0acNdw98kKLrvuRVyB80tsREOE7yvGVgalhZ6RNXCmEHkUKBKxew==
inquirer@^7.0.0: inquirer@^7.0.0:
version "7.1.0" version "7.1.0"
+1
View File
@@ -36,6 +36,7 @@
"test:fixtures": "jest --config=docs-util/jest.config.js --runInBand" "test:fixtures": "jest --config=docs-util/jest.config.js --runInBand"
}, },
"dependencies": { "dependencies": {
"import-from": "^3.0.0",
"oas-normalize": "^2.3.1", "oas-normalize": "^2.3.1",
"swagger-inline": "^3.2.2" "swagger-inline": "^3.2.2"
} }
@@ -1,6 +1,6 @@
{ {
"name": "medusa-plugin-contentful", "name": "medusa-plugin-contentful",
"version": "1.1.4", "version": "1.1.4-alpha.7+739b7b3c",
"description": "Contentful plugin for Medusa Commerce", "description": "Contentful plugin for Medusa Commerce",
"main": "index.js", "main": "index.js",
"repository": { "repository": {
@@ -43,5 +43,5 @@
"medusa-test-utils": "^1.1.3", "medusa-test-utils": "^1.1.3",
"redis": "^3.0.2" "redis": "^3.0.2"
}, },
"gitHead": "0646bd395a6056657cb0aa93c13699c4a9dbbcdd" "gitHead": "739b7b3cc5ff31aa7a15637db2000e645c7597b1"
} }
@@ -11,6 +11,7 @@ const checkContentTypes = async (container) => {
if (!product) { if (!product) {
throw Error("Content type: `product` is missing in Contentful") throw Error("Content type: `product` is missing in Contentful")
} }
if (!variant) { if (!variant) {
throw Error("Content type: `productVariant` is missing in Contentful") throw Error("Content type: `productVariant` is missing in Contentful")
} }
@@ -96,13 +96,15 @@ class ContentfulService extends BaseService {
}, },
}) })
await asset.processForAllLocales() const finalAsset = await asset
.processForAllLocales()
.then((ast) => ast.publish())
assets.push({ assets.push({
sys: { sys: {
type: "Link", type: "Link",
linkType: "Asset", linkType: "Asset",
id: asset.sys.id, id: finalAsset.sys.id,
}, },
}) })
}) })
@@ -231,9 +233,9 @@ class ContentfulService extends BaseService {
fields, fields,
}) })
const ignoreIds = (await this.getIgnoreIds_("product")) || [] // const ignoreIds = (await this.getIgnoreIds_("product")) || []
ignoreIds.push(product.id) // ignoreIds.push(product.id)
this.redis_.set("product_ignore_ids", JSON.stringify(ignoreIds)) // this.redis_.set("product_ignore_ids", JSON.stringify(ignoreIds))
return result return result
} catch (error) { } catch (error) {
throw error throw error
@@ -271,38 +273,47 @@ class ContentfulService extends BaseService {
} }
) )
const ignoreIds = (await this.getIgnoreIds_("product_variant")) || [] // const ignoreIds = (await this.getIgnoreIds_("product_variant")) || []
ignoreIds.push(v.id) // ignoreIds.push(v.id)
this.redis_.set("product_variant_ignore_ids", JSON.stringify(ignoreIds)) // this.redis_.set("product_variant_ignore_ids", JSON.stringify(ignoreIds))
return result return result
} catch (error) { } catch (error) {
throw error throw error
} }
} }
async updateProductInContentful(product) { async updateProductInContentful(data) {
const updateFields = [
"variants",
"options",
"tags",
"title",
"tags",
"type",
"type_id",
"collection",
"collection_id",
"thumbnail",
]
const found = data.fields.find((f) => updateFields.includes(f))
if (!found) {
return
}
try { try {
const ignoreIds = (await this.getIgnoreIds_("product")) || [] // const ignoreIds = (await this.getIgnoreIds_("product")) || []
if (ignoreIds.includes(product.id)) { // if (ignoreIds.includes(product.id)) {
const newIgnoreIds = ignoreIds.filter((id) => id !== product.id) // const newIgnoreIds = ignoreIds.filter((id) => id !== product.id)
this.redis_.set("product_ignore_ids", JSON.stringify(newIgnoreIds)) // this.redis_.set("product_ignore_ids", JSON.stringify(newIgnoreIds))
return // return
} else { // } else {
ignoreIds.push(product.id) // ignoreIds.push(product.id)
this.redis_.set("product_ignore_ids", JSON.stringify(ignoreIds)) // this.redis_.set("product_ignore_ids", JSON.stringify(ignoreIds))
} // }
const environment = await this.getContentfulEnvironment_() const p = await this.productService_.retrieve(data.id, {
// check if product exists
let productEntry = undefined
try {
productEntry = await environment.getEntry(product.id)
} catch (error) {
return this.createProductInContentful(product)
}
const p = await this.productService_.retrieve(product.id, {
relations: [ relations: [
"options", "options",
"variants", "variants",
@@ -313,6 +324,15 @@ class ContentfulService extends BaseService {
], ],
}) })
const environment = await this.getContentfulEnvironment_()
// check if product exists
let productEntry = undefined
try {
productEntry = await environment.getEntry(data.id)
} catch (error) {
return this.createProductInContentful(p)
}
const variantEntries = await this.getVariantEntries_(p.variants) const variantEntries = await this.getVariantEntries_(p.variants)
const variantLinks = this.getVariantLinks_(variantEntries) const variantLinks = this.getVariantLinks_(variantEntries)
@@ -332,7 +352,12 @@ class ContentfulService extends BaseService {
}, },
} }
if (p.thumbnail) { if (data.fields.includes("thumbnail") && p.thumbnail) {
let url = p.thumbnail
if (p.thumbnail.startsWith("//")) {
url = `https:${url}`
}
const thumbnailAsset = await environment.createAsset({ const thumbnailAsset = await environment.createAsset({
fields: { fields: {
title: { title: {
@@ -344,8 +369,8 @@ class ContentfulService extends BaseService {
file: { file: {
"en-US": { "en-US": {
contentType: "image/xyz", contentType: "image/xyz",
fileName: p.thumbnail, fileName: url,
upload: p.thumbnail, upload: url,
}, },
}, },
}, },
@@ -412,20 +437,37 @@ class ContentfulService extends BaseService {
} }
async updateProductVariantInContentful(variant) { async updateProductVariantInContentful(variant) {
try { const updateFields = [
const ignoreIds = (await this.getIgnoreIds_("product_variant")) || [] "title",
"prices",
"sku",
"material",
"weight",
"length",
"height",
"origin_country",
"options",
]
if (ignoreIds.includes(variant.id)) { const found = variant.fields.find((f) => updateFields.includes(f))
const newIgnoreIds = ignoreIds.filter((id) => id !== variant.id) if (!found) {
this.redis_.set( return
"product_variant_ignore_ids", }
JSON.stringify(newIgnoreIds)
) try {
return // const ignoreIds = (await this.getIgnoreIds_("product_variant")) || []
} else {
ignoreIds.push(variant.id) //if (ignoreIds.includes(variant.id)) {
this.redis_.set("product_variant_ignore_ids", JSON.stringify(ignoreIds)) // const newIgnoreIds = ignoreIds.filter((id) => id !== variant.id)
} // this.redis_.set(
// "product_variant_ignore_ids",
// JSON.stringify(newIgnoreIds)
// )
// return
//} else {
// ignoreIds.push(variant.id)
// this.redis_.set("product_variant_ignore_ids", JSON.stringify(ignoreIds))
//}
const environment = await this.getContentfulEnvironment_() const environment = await this.getContentfulEnvironment_()
// check if product exists // check if product exists
@@ -476,19 +518,23 @@ class ContentfulService extends BaseService {
const environment = await this.getContentfulEnvironment_() const environment = await this.getContentfulEnvironment_()
const productEntry = await environment.getEntry(productId) const productEntry = await environment.getEntry(productId)
const ignoreIds = (await this.getIgnoreIds_("product")) || [] const product = await this.productService_.retrieve(productId)
if (ignoreIds.includes(productId)) {
const newIgnoreIds = ignoreIds.filter((id) => id !== productId)
this.redis_.set("product_ignore_ids", JSON.stringify(newIgnoreIds))
return
} else {
ignoreIds.push(productId)
this.redis_.set("product_ignore_ids", JSON.stringify(ignoreIds))
}
let update = { //const ignoreIds = (await this.getIgnoreIds_("product")) || []
title: //if (ignoreIds.includes(productId)) {
productEntry.fields[this.getCustomField("title", "product")]["en-US"], // const newIgnoreIds = ignoreIds.filter((id) => id !== productId)
// this.redis_.set("product_ignore_ids", JSON.stringify(newIgnoreIds))
// return
//} else {
// ignoreIds.push(productId)
// this.redis_.set("product_ignore_ids", JSON.stringify(ignoreIds))
//}
let update = {}
const title =
productEntry.fields[this.getCustomField("title", "product")]["en-US"]
if (product.title !== title) {
update.title = title
} }
// Get the thumbnail, if present // Get the thumbnail, if present
@@ -497,15 +543,16 @@ class ContentfulService extends BaseService {
productEntry.fields.thumbnail["en-US"].sys.id productEntry.fields.thumbnail["en-US"].sys.id
) )
update.thumbnail = thumb.fields.file["en-US"].url if (thumb.fields.file["en-US"].url) {
if (!product.thumbnail.includes(thumb.fields.file["en-US"].url)) {
update.thumbnail = thumb.fields.file["en-US"].url
}
}
} }
const updatedProduct = await this.productService_.update( if (!_.isEmpty(update)) {
productId, await this.productService_.update(productId, update)
update }
)
return updatedProduct
} catch (error) { } catch (error) {
throw error throw error
} }
@@ -516,18 +563,18 @@ class ContentfulService extends BaseService {
const environment = await this.getContentfulEnvironment_() const environment = await this.getContentfulEnvironment_()
const variantEntry = await environment.getEntry(variantId) const variantEntry = await environment.getEntry(variantId)
const ignoreIds = (await this.getIgnoreIds_("product_variant")) || [] // const ignoreIds = (await this.getIgnoreIds_("product_variant")) || []
if (ignoreIds.includes(variantId)) { // if (ignoreIds.includes(variantId)) {
const newIgnoreIds = ignoreIds.filter((id) => id !== variantId) // const newIgnoreIds = ignoreIds.filter((id) => id !== variantId)
this.redis_.set( // this.redis_.set(
"product_variant_ignore_ids", // "product_variant_ignore_ids",
JSON.stringify(newIgnoreIds) // JSON.stringify(newIgnoreIds)
) // )
return // return
} else { // } else {
ignoreIds.push(variantId) // ignoreIds.push(variantId)
this.redis_.set("product_variant_ignore_ids", JSON.stringify(ignoreIds)) // this.redis_.set("product_variant_ignore_ids", JSON.stringify(ignoreIds))
} // }
const updatedVariant = await this.productVariantService_.update( const updatedVariant = await this.productVariantService_.update(
variantId, variantId,
@@ -1,3 +1,4 @@
import _ from "lodash"
import jwt from "jsonwebtoken" import jwt from "jsonwebtoken"
import { Validator } from "medusa-core-utils" import { Validator } from "medusa-core-utils"
import config from "../../../../config" import config from "../../../../config"
@@ -19,7 +20,7 @@ import config from "../../../../config"
* application/json: * application/json:
* schema: * schema:
* properties: * properties:
* customer: * user:
* $ref: "#/components/schemas/user" * $ref: "#/components/schemas/user"
*/ */
export default async (req, res) => { export default async (req, res) => {
@@ -46,5 +47,7 @@ export default async (req, res) => {
expiresIn: "24h", expiresIn: "24h",
}) })
res.json({ user: result.user }) const cleanRes = _.omit(result.user, ["password_hash"])
res.json({ user: cleanRes })
} }
@@ -1,4 +1,4 @@
import passport from "passport" import _ from "lodash"
/** /**
* @oas [get] /auth * @oas [get] /auth
@@ -14,11 +14,13 @@ import passport from "passport"
* application/json: * application/json:
* schema: * schema:
* properties: * properties:
* customer: * user:
* $ref: "#/components/schemas/user" * $ref: "#/components/schemas/user"
*/ */
export default async (req, res) => { export default async (req, res) => {
const userService = req.scope.resolve("userService") const userService = req.scope.resolve("userService")
const user = await userService.retrieve(req.user.userId) const user = await userService.retrieve(req.user.userId)
res.status(200).json({ user })
const cleanRes = _.omit(user, ["password_hash"])
res.status(200).json({ user: cleanRes })
} }
@@ -7,7 +7,7 @@ import { defaultFields, defaultRelations } from "./"
* summary: "Create a Swap" * summary: "Create a Swap"
* description: "Creates a Swap. Swaps are used to handle Return of previously purchased goods and Fulfillment of replacements simultaneously." * description: "Creates a Swap. Swaps are used to handle Return of previously purchased goods and Fulfillment of replacements simultaneously."
* parameters: * parameters:
* - (path) id=* {string} The id of the Swap. * - (path) id=* {string} The id of the Order.
* requestBody: * requestBody:
* content: * content:
* application/json: * application/json:
@@ -6,7 +6,7 @@ import { MedusaError, Validator } from "medusa-core-utils"
* @oas [get] /orders * @oas [get] /orders
* operationId: "GetOrders" * operationId: "GetOrders"
* summary: "List Orders" * summary: "List Orders"
* description: "Retrieves an list of Orders" * description: "Retrieves a list of Orders"
* tags: * tags:
* - Order * - Order
* responses: * responses:
@@ -16,8 +16,10 @@ import { MedusaError, Validator } from "medusa-core-utils"
* application/json: * application/json:
* schema: * schema:
* properties: * properties:
* order: * orders:
* $ref: "#/components/schemas/order" * type: array
* items:
* $ref: "#/components/schemas/order"
*/ */
export default async (req, res) => { export default async (req, res) => {
const schema = Validator.orderFilter() const schema = Validator.orderFilter()
@@ -309,7 +309,7 @@ describe("ProductVariantService", () => {
"product-variant.updated", "product-variant.updated",
{ {
id: IdMap.getId("ironman"), id: IdMap.getId("ironman"),
title: "new title", fields: ["title"],
} }
) )
@@ -333,7 +333,7 @@ describe("ProductVariantService", () => {
"product-variant.updated", "product-variant.updated",
{ {
id: IdMap.getId("ironman"), id: IdMap.getId("ironman"),
title: "new title", fields: ["title"],
} }
) )
@@ -370,10 +370,7 @@ describe("ProductVariantService", () => {
"product-variant.updated", "product-variant.updated",
{ {
id: IdMap.getId("ironman"), id: IdMap.getId("ironman"),
title: "new title", fields: ["title", "metadata"],
metadata: {
testing: "this",
},
} }
) )
@@ -298,7 +298,10 @@ class ProductVariantService extends BaseService {
const result = await variantRepo.save(variant) const result = await variantRepo.save(variant)
await this.eventBus_ await this.eventBus_
.withTransaction(manager) .withTransaction(manager)
.emit(ProductVariantService.Events.UPDATED, result) .emit(ProductVariantService.Events.UPDATED, {
id: result.id,
fields: Object.keys(update),
})
return result return result
}) })
} }
+1
View File
@@ -444,6 +444,7 @@ class ProductService extends BaseService {
.withTransaction(manager) .withTransaction(manager)
.emit(ProductService.Events.UPDATED, { .emit(ProductService.Events.UPDATED, {
id: result.id, id: result.id,
fields: Object.keys(update),
}) })
return result return result
}) })
+3 -3
View File
@@ -3501,9 +3501,9 @@ domexception@^1.0.1:
webidl-conversions "^4.0.2" webidl-conversions "^4.0.2"
dot-prop@^4.1.0: dot-prop@^4.1.0:
version "4.2.0" version "4.2.1"
resolved "https://registry.yarnpkg.com/dot-prop/-/dot-prop-4.2.0.tgz#1f19e0c2e1aa0e32797c49799f2837ac6af69c57" resolved "https://registry.yarnpkg.com/dot-prop/-/dot-prop-4.2.1.tgz#45884194a71fc2cda71cbb4bceb3a4dd2f433ba4"
integrity sha512-tUMXrxlExSW6U2EXiiKGSBVdYgtV8qlHL+C10TsW4PURY/ic+eaysnSkwB4kA/mBlCyy/IKDJ+Lc3wbWeaXtuQ== integrity sha512-l0p4+mIuJIua0mhxGoh4a+iNL9bmeK5DvnSVQa6T0OhrVmaEa1XScX5Etc673FePCJOArq/4Pa2cLGODUWTPOQ==
dependencies: dependencies:
is-obj "^1.0.0" is-obj "^1.0.0"
+1 -1
View File
@@ -1,6 +1,6 @@
The BSD Zero Clause License (0BSD) The BSD Zero Clause License (0BSD)
Copyright (c) 2020 Gatsby Inc. Copyright (c) 2020 Medusa Commerce
Permission to use, copy, modify, and/or distribute this software for any Permission to use, copy, modify, and/or distribute this software for any
purpose with or without fee is hereby granted. purpose with or without fee is hereby granted.
+12 -1
View File
@@ -49,8 +49,19 @@ const JsonBox = ({ text, resourceId, endpoint, spec }) => {
cleanDets["x-resourceId"] in fixtures.resources cleanDets["x-resourceId"] in fixtures.resources
) { ) {
toSet[name] = fixtures.resources[cleanDets["x-resourceId"]] toSet[name] = fixtures.resources[cleanDets["x-resourceId"]]
} else { } else if (cleanDets.type === "array") {
toSet[name] = cleanDets toSet[name] = cleanDets
if (cleanDets.items.$ref) {
const [, ...path] = cleanDets.items.$ref.split("/")
let cleanObj = deref(path, spec)
if (
cleanObj["x-resourceId"] &&
cleanObj["x-resourceId"] in fixtures.resources
) {
cleanObj = fixtures.resources[cleanObj["x-resourceId"]]
}
toSet[name] = [cleanObj]
}
} }
} }
} }