docs: oas (#197)

Adds OpenAPI specification of Storefront and Admin APIs.
Updates docs project.
This commit is contained in:
Sebastian Rindom authored and GitHub committed 2021-03-10 11:51:54 +01:00
1 parent 975de99ee7
commit 8edb32c742
240 files changed
+23592 -419

No files matched your search

@@ -0,0 +1,17 @@
const Scrypt = require("scrypt-kdf");
const { User } = require("@medusajs/medusa");
module.exports = async (connection, data = {}) => {
const manager = connection.manager;
const buf = await Scrypt.kdf("secret_password", { logN: 1, r: 1, p: 1 });
const password_hash = buf.toString("base64");
await manager.insert(User, {
id: "admin_user",
email: "admin@medusa.js",
api_token: "test_token",
password_hash,
...data,
});
};
@@ -0,0 +1,47 @@
const { Customer, Region, Cart } = require("@medusajs/medusa");
module.exports = async (connection, data = {}) => {
const manager = connection.manager;
await manager.insert(Region, {
id: "test-region",
name: "Test Region",
currency_code: "usd",
tax_rate: 0,
});
await manager.query(
`UPDATE "country" SET region_id='test-region' WHERE iso_2 = 'us'`
);
await manager.insert(Customer, {
id: "test-customer",
email: "test@email.com",
});
await manager.insert(Customer, {
id: "test-customer-2",
email: "test-2@email.com",
});
await manager.insert(Customer, {
id: "some-customer",
email: "some-customer@email.com",
});
const cart = manager.create(Cart, {
id: "test-cart",
customer_id: "some-customer",
email: "some-customer@email.com",
shipping_address: {
id: "test-shipping-address",
first_name: "lebron",
country_code: "us",
},
region_id: "test-region",
currency_code: "usd",
items: [],
});
await manager.save(cart);
};
@@ -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",
});
};
@@ -0,0 +1,152 @@
const {
ShippingProfile,
Customer,
MoneyAmount,
LineItem,
Country,
ShippingOption,
ShippingMethod,
Product,
ProductOption,
ProductVariant,
Region,
Order,
} = require("@medusajs/medusa");
module.exports = async (connection, data = {}) => {
const manager = connection.manager;
const defaultProfile = await manager.findOne(ShippingProfile, {
type: "default",
});
const prodOption = manager.create(ProductOption, {
title: "Size",
});
const newProdOption = await manager.save(prodOption);
const prod = manager.create(Product, {
title: "test product",
profile_id: defaultProfile.id,
options: [newProdOption],
});
const newProd = await manager.save(prod);
const prodVar = manager.create(ProductVariant, {
title: "test variant",
product_id: newProd.id,
inventory_quantity: 1,
options: [
{
option_id: newProdOption.id,
value: "Size",
},
],
});
const newProdVar = manager.save(prodVar);
const ma = manager.create(MoneyAmount, {
variant_id: newProdVar.id,
currency_code: "usd",
amount: 8000,
});
await manager.save(ma);
const region = manager.create(Region, {
name: "Test Region",
currency_code: "usd",
tax_rate: 0,
});
const newReg = await manager.save(region);
await manager.query(
`UPDATE "country" SET region_id='${newReg.id}' WHERE iso_2 = 'us'`
);
const customer = manager.create(Customer, {
email: "test@email.com",
});
const newCustomer = await manager.save(customer);
const shipOpt = manager.create(ShippingOption, {
name: "test-option",
provider_id: "test-ful",
region_id: newReg.id,
profile_id: defaultProfile.id,
price_type: "flat_rate",
amount: 1000,
data: {},
});
const newShipOpt = await manager.save(shipOpt);
const order = manager.create(Order, {
customer_id: newCustomer.id,
email: "test@email.com",
billing_address: {
first_name: "lebron",
},
shipping_address: {
first_name: "lebron",
country_code: "us",
},
region_id: newReg.id,
currency_code: "usd",
tax_rate: 0,
discounts: [
{
id: "test-discount",
code: "TEST134",
is_dynamic: false,
rule: {
id: "test-rule",
description: "Test Discount",
type: "percentage",
value: 10,
allocation: "total",
},
is_disabled: false,
regions: [
{
id: newReg.id,
},
],
},
],
payments: [
{
id: "test-payment",
amount: 10000,
currency_code: "usd",
amount_refunded: 0,
provider_id: "test",
data: {},
},
],
items: [
{
id: "test-item",
fulfilled_quantity: 1,
title: "Line Item",
description: "Line Item Desc",
thumbnail: "https://test.js/1234",
unit_price: 8000,
quantity: 1,
variant_id: newProdVar.id,
},
],
...data,
});
const newOrder = await manager.save(order);
const shipMeth = manager.create(ShippingMethod, {
order_id: newOrder.id,
shipping_option_id: newShipOpt.id,
price: 1000,
data: {},
});
await manager.save(shipMeth);
return newOrder;
};
@@ -0,0 +1,68 @@
const {
ProductCollection,
ProductTag,
ProductType,
Region,
Product,
ShippingProfile,
ProductVariant,
} = require("@medusajs/medusa");
module.exports = async (connection, data = {}) => {
const manager = connection.manager;
const defaultProfile = await manager.findOne(ShippingProfile, {
type: "default",
});
const coll = manager.create(ProductCollection, {
id: "test-collection",
title: "Test collection",
});
await manager.save(coll);
const tag = manager.create(ProductTag, {
id: "tag1",
value: "123",
});
await manager.save(tag);
const type = manager.create(ProductType, {
id: "test-type",
value: "test-type",
});
await manager.save(type);
await manager.insert(Region, {
id: "test-region",
name: "Test Region",
currency_code: "usd",
tax_rate: 0,
});
await manager.insert(Product, {
id: "test-product",
title: "Test product",
profile_id: defaultProfile.id,
description: "test-product-description",
collection_id: "test-collection",
type: { id: "test-type", value: "test-type" },
tags: [
{ id: "tag1", value: "123" },
{ tag: "tag2", value: "456" },
],
options: [{ id: "test-option", title: "Default value" }],
});
await manager.insert(ProductVariant, {
id: "test-variant",
inventory_quantity: 10,
title: "Test variant",
product_id: "test-product",
prices: [{ id: "test-price", currency_code: "usd", amount: 100 }],
options: [{ id: "test-variant-option", value: "Default variant" }],
});
};