From 5eff8f6aa1baa2b10a29ca18139bb40e73b15b43 Mon Sep 17 00:00:00 2001 From: "dependabot[bot]" <49699333+dependabot[bot]@users.noreply.github.com> Date: Tue, 16 Mar 2021 10:01:17 +0100 Subject: [PATCH 1/6] chore(deps): bump highlight.js from 10.4.0 to 10.5.0 in /packages/medusa (#154) Bumps [highlight.js](https://github.com/highlightjs/highlight.js) from 10.4.0 to 10.5.0. - [Release notes](https://github.com/highlightjs/highlight.js/releases) - [Changelog](https://github.com/highlightjs/highlight.js/blob/master/CHANGES.md) - [Commits](https://github.com/highlightjs/highlight.js/compare/10.4.0...10.5.0) Signed-off-by: dependabot[bot] Co-authored-by: dependabot[bot] <49699333+dependabot[bot]@users.noreply.github.com> --- packages/medusa/yarn.lock | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/packages/medusa/yarn.lock b/packages/medusa/yarn.lock index d055c6518e..cce6d678ec 100644 --- a/packages/medusa/yarn.lock +++ b/packages/medusa/yarn.lock @@ -4403,9 +4403,9 @@ has@^1.0.1, has@^1.0.3: function-bind "^1.1.1" highlight.js@^10.0.0: - version "10.4.0" - resolved "https://registry.yarnpkg.com/highlight.js/-/highlight.js-10.4.0.tgz#ef3ce475e5dfa7a48484260b49ea242ddab823a0" - integrity sha512-EfrUGcQ63oLJbj0J0RI9ebX6TAITbsDBLbsjr881L/X5fMO9+oadKzEF21C7R3ULKG6Gv3uoab2HiqVJa/4+oA== + version "10.5.0" + resolved "https://registry.yarnpkg.com/highlight.js/-/highlight.js-10.5.0.tgz#3f09fede6a865757378f2d9ebdcbc15ba268f98f" + integrity sha512-xTmvd9HiIHR6L53TMC7TKolEj65zG1XU+Onr8oi86mYa+nLcIbxTTWkpW7CsEwv/vK7u1zb8alZIMLDqqN6KTw== homedir-polyfill@^1.0.1: version "1.0.3" From 8b42f296481cc0538e9f7962ee59964e9c74444e Mon Sep 17 00:00:00 2001 From: "dependabot[bot]" <49699333+dependabot[bot]@users.noreply.github.com> Date: Tue, 16 Mar 2021 10:01:52 +0100 Subject: [PATCH 2/6] chore(deps): bump dot-prop from 4.2.0 to 4.2.1 in /e2e/prod-project (#139) Bumps [dot-prop](https://github.com/sindresorhus/dot-prop) from 4.2.0 to 4.2.1. - [Release notes](https://github.com/sindresorhus/dot-prop/releases) - [Commits](https://github.com/sindresorhus/dot-prop/compare/v4.2.0...v4.2.1) Signed-off-by: dependabot[bot] Co-authored-by: dependabot[bot] <49699333+dependabot[bot]@users.noreply.github.com> --- e2e/prod-project/yarn.lock | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/e2e/prod-project/yarn.lock b/e2e/prod-project/yarn.lock index 7ab01a5daa..2730b4a34a 100644 --- a/e2e/prod-project/yarn.lock +++ b/e2e/prod-project/yarn.lock @@ -2282,9 +2282,9 @@ domexception@^1.0.1: webidl-conversions "^4.0.2" dot-prop@^4.1.0: - version "4.2.0" - resolved "https://registry.yarnpkg.com/dot-prop/-/dot-prop-4.2.0.tgz#1f19e0c2e1aa0e32797c49799f2837ac6af69c57" - integrity sha512-tUMXrxlExSW6U2EXiiKGSBVdYgtV8qlHL+C10TsW4PURY/ic+eaysnSkwB4kA/mBlCyy/IKDJ+Lc3wbWeaXtuQ== + version "4.2.1" + resolved "https://registry.yarnpkg.com/dot-prop/-/dot-prop-4.2.1.tgz#45884194a71fc2cda71cbb4bceb3a4dd2f433ba4" + integrity sha512-l0p4+mIuJIua0mhxGoh4a+iNL9bmeK5DvnSVQa6T0OhrVmaEa1XScX5Etc673FePCJOArq/4Pa2cLGODUWTPOQ== dependencies: is-obj "^1.0.0" From f03c11c218b0b7798af513233979373877426c8a Mon Sep 17 00:00:00 2001 From: "dependabot[bot]" <49699333+dependabot[bot]@users.noreply.github.com> Date: Tue, 16 Mar 2021 10:02:25 +0100 Subject: [PATCH 3/6] chore(deps): bump ini from 1.3.5 to 1.3.8 in /e2e/prod-project (#147) Bumps [ini](https://github.com/isaacs/ini) from 1.3.5 to 1.3.8. - [Release notes](https://github.com/isaacs/ini/releases) - [Commits](https://github.com/isaacs/ini/compare/v1.3.5...v1.3.8) Signed-off-by: dependabot[bot] Co-authored-by: dependabot[bot] <49699333+dependabot[bot]@users.noreply.github.com> --- e2e/prod-project/yarn.lock | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/e2e/prod-project/yarn.lock b/e2e/prod-project/yarn.lock index 2730b4a34a..141d5e196b 100644 --- a/e2e/prod-project/yarn.lock +++ b/e2e/prod-project/yarn.lock @@ -3213,9 +3213,9 @@ inherits@2.0.3: integrity sha1-Yzwsg+PaQqUC9SRmAiSA9CCCYd4= ini@^1.3.4, ini@~1.3.0: - version "1.3.5" - resolved "https://registry.yarnpkg.com/ini/-/ini-1.3.5.tgz#eee25f56db1c9ec6085e0c22778083f596abf927" - integrity sha512-RZY5huIKCMRWDUqZlEi72f/lmXKMvuszcMBduliQ3nnWbx9X/ZBQO7DijMEYS9EhHBb2qacRUMtC7svLwe0lcw== + version "1.3.8" + resolved "https://registry.yarnpkg.com/ini/-/ini-1.3.8.tgz#a29da425b48806f34767a4efce397269af28432c" + integrity sha512-JV/yugV2uzW5iMRSiZAyDtQd+nxtUnjeLt0acNdw98kKLrvuRVyB80tsREOE7yvGVgalhZ6RNXCmEHkUKBKxew== inquirer@^7.0.0: version "7.1.0" From 34bb39afa359adc80f8066610e4849cf8ff3ea85 Mon Sep 17 00:00:00 2001 From: "dependabot[bot]" <49699333+dependabot[bot]@users.noreply.github.com> Date: Tue, 16 Mar 2021 10:13:28 +0100 Subject: [PATCH 4/6] chore(deps): bump dot-prop from 4.2.0 to 4.2.1 in /packages/medusa (#140) Bumps [dot-prop](https://github.com/sindresorhus/dot-prop) from 4.2.0 to 4.2.1. - [Release notes](https://github.com/sindresorhus/dot-prop/releases) - [Commits](https://github.com/sindresorhus/dot-prop/compare/v4.2.0...v4.2.1) Signed-off-by: dependabot[bot] Co-authored-by: dependabot[bot] <49699333+dependabot[bot]@users.noreply.github.com> --- packages/medusa/yarn.lock | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/packages/medusa/yarn.lock b/packages/medusa/yarn.lock index cce6d678ec..85c444b53d 100644 --- a/packages/medusa/yarn.lock +++ b/packages/medusa/yarn.lock @@ -3528,9 +3528,9 @@ domexception@^1.0.1: webidl-conversions "^4.0.2" dot-prop@^4.1.0: - version "4.2.0" - resolved "https://registry.yarnpkg.com/dot-prop/-/dot-prop-4.2.0.tgz#1f19e0c2e1aa0e32797c49799f2837ac6af69c57" - integrity sha512-tUMXrxlExSW6U2EXiiKGSBVdYgtV8qlHL+C10TsW4PURY/ic+eaysnSkwB4kA/mBlCyy/IKDJ+Lc3wbWeaXtuQ== + version "4.2.1" + resolved "https://registry.yarnpkg.com/dot-prop/-/dot-prop-4.2.1.tgz#45884194a71fc2cda71cbb4bceb3a4dd2f433ba4" + integrity sha512-l0p4+mIuJIua0mhxGoh4a+iNL9bmeK5DvnSVQa6T0OhrVmaEa1XScX5Etc673FePCJOArq/4Pa2cLGODUWTPOQ== dependencies: is-obj "^1.0.0" From 3d0dff58c4d6830cb8521bef6838e50442f89079 Mon Sep 17 00:00:00 2001 From: Sebastian Rindom Date: Tue, 16 Mar 2021 18:15:41 +0100 Subject: [PATCH 5/6] docs: fixture improvements + small fixes (#204) * fix: deref arrays * docs: clean up * fix: update license --- docs-util/fixture-gen/__tests__/admin/auth.js | 62 + .../fixture-gen/__tests__/admin/order.js | 90 ++ .../__tests__/admin/shipping-option.js | 4 - .../__tests__/admin/shipping-profile.js | 74 + .../fixture-gen/__tests__/admin/store.js | 56 + docs-util/fixture-gen/helpers/order-seeder.js | 2 +- docs-util/fixture-gen/package.json | 8 +- docs-util/fixture-gen/yarn.lock | 54 +- docs-util/helpers/test-server.js | 6 +- docs/api/admin-spec3.json | 1019 ++++++------ docs/api/admin-spec3.yaml | 132 +- docs/api/fixtures.json | 512 ++++-- docs/api/store-spec3.json | 1432 ++++++++--------- docs/api/store-spec3.yaml | 176 +- package.json | 1 + packages/medusa/jest.config.js | 3 - .../api/routes/admin/auth/create-session.js | 7 +- .../src/api/routes/admin/auth/get-session.js | 8 +- .../api/routes/admin/orders/create-swap.js | 2 +- .../api/routes/admin/orders/list-orders.js | 8 +- www/LICENSE | 2 +- www/src/components/json-box.js | 13 +- yarn.lock | 7 + 23 files changed, 2079 insertions(+), 1599 deletions(-) create mode 100644 docs-util/fixture-gen/__tests__/admin/auth.js create mode 100644 docs-util/fixture-gen/__tests__/admin/shipping-profile.js create mode 100644 docs-util/fixture-gen/__tests__/admin/store.js delete mode 100644 packages/medusa/jest.config.js diff --git a/docs-util/fixture-gen/__tests__/admin/auth.js b/docs-util/fixture-gen/__tests__/admin/auth.js new file mode 100644 index 0000000000..f29f15aff2 --- /dev/null +++ b/docs-util/fixture-gen/__tests__/admin/auth.js @@ -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); + }); + }); +}); diff --git a/docs-util/fixture-gen/__tests__/admin/order.js b/docs-util/fixture-gen/__tests__/admin/order.js index d364398ac8..01eb53021f 100644 --- a/docs-util/fixture-gen/__tests__/admin/order.js +++ b/docs-util/fixture-gen/__tests__/admin/order.js @@ -1,5 +1,6 @@ const { dropDatabase } = require("pg-god"); const path = require("path"); +const { ProductVariant } = require("@medusajs/medusa"); const setupServer = require("../../../helpers/setup-server"); const { useApi } = require("../../../helpers/use-api"); @@ -161,4 +162,93 @@ describe("/admin/orders", () => { 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]); + }); + }); }); diff --git a/docs-util/fixture-gen/__tests__/admin/shipping-option.js b/docs-util/fixture-gen/__tests__/admin/shipping-option.js index 353a0c515d..da8e687599 100644 --- a/docs-util/fixture-gen/__tests__/admin/shipping-option.js +++ b/docs-util/fixture-gen/__tests__/admin/shipping-option.js @@ -78,10 +78,6 @@ describe("/shipping-options", () => { fixtureWriter.addFixture("region", getRes.data.shipping_option.region); fixtureWriter.addFixture("shipping_option", getRes.data.shipping_option); - fixtureWriter.addFixture( - "shipping_profile", - getRes.data.shipping_option.shipping_profile - ); }); }); }); diff --git a/docs-util/fixture-gen/__tests__/admin/shipping-profile.js b/docs-util/fixture-gen/__tests__/admin/shipping-profile.js new file mode 100644 index 0000000000..3f347ab4ca --- /dev/null +++ b/docs-util/fixture-gen/__tests__/admin/shipping-profile.js @@ -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] + ); + }); + }); +}); diff --git a/docs-util/fixture-gen/__tests__/admin/store.js b/docs-util/fixture-gen/__tests__/admin/store.js new file mode 100644 index 0000000000..950fa13168 --- /dev/null +++ b/docs-util/fixture-gen/__tests__/admin/store.js @@ -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); + }); + }); +}); diff --git a/docs-util/fixture-gen/helpers/order-seeder.js b/docs-util/fixture-gen/helpers/order-seeder.js index c1393f980c..c1c27bb330 100644 --- a/docs-util/fixture-gen/helpers/order-seeder.js +++ b/docs-util/fixture-gen/helpers/order-seeder.js @@ -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, { variant_id: newProdVar.id, diff --git a/docs-util/fixture-gen/package.json b/docs-util/fixture-gen/package.json index 40595aaf5b..b39d71c61d 100644 --- a/docs-util/fixture-gen/package.json +++ b/docs-util/fixture-gen/package.json @@ -7,13 +7,13 @@ "build": "babel src -d dist --extensions \".ts,.js\"" }, "dependencies": { - "@medusajs/medusa": "^1.1.3", - "medusa-interfaces": "^1.1.0" + "@medusajs/medusa": "1.1.11-dev-1615562702314", + "medusa-interfaces": "1.1.1-dev-1615562702314" }, "devDependencies": { "@babel/cli": "^7.12.10", "@babel/core": "^7.12.10", "@babel/node": "^7.12.10", - "babel-preset-medusa-package": "^1.1.0" + "babel-preset-medusa-package": "1.1.0-dev-1615562702314" } -} \ No newline at end of file +} diff --git a/docs-util/fixture-gen/yarn.lock b/docs-util/fixture-gen/yarn.lock index 036fd50a59..eb96dbf44c 100644 --- a/docs-util/fixture-gen/yarn.lock +++ b/docs-util/fixture-gen/yarn.lock @@ -946,13 +946,14 @@ dependencies: "@hapi/hoek" "^9.0.0" -"@medusajs/medusa@^1.1.3": - version "1.1.3" - resolved "https://registry.yarnpkg.com/@medusajs/medusa/-/medusa-1.1.3.tgz#253cf73a45d066eb25cfa58efa81674a45759ef1" - integrity sha512-QSEe0fQuEndyJ7WUPKfaPYO5pCR5xNLT/6NAObgi2nuo4WroA2nqqU01bOuWf/Sa4PnH0YMtJ0H86qzLa0MARA== +"@medusajs/medusa@1.1.11-dev-1615562702314": + version "1.1.11-dev-1615562702314" + resolved "http://localhost:4873/@medusajs%2fmedusa/-/medusa-1.1.11-dev-1615562702314.tgz#2bd0b0ba84e38a9717a2ab44ee52bcac31162125" + integrity sha512-/23r7U+3jT33o2D2GdhRj9rWqoe0ZP8mQ2H+0ukx+QnFgD+Y/NwigNrDm98fxLwDDZmeFQx2s2EXzgBW3cO7mw== dependencies: "@babel/plugin-transform-classes" "^7.9.5" "@hapi/joi" "^16.1.8" + "@types/lodash" "^4.14.168" awilix "^4.2.3" body-parser "^1.19.0" bull "^3.12.1" @@ -970,8 +971,8 @@ joi "^17.3.0" joi-objectid "^3.0.1" jsonwebtoken "^8.5.1" - medusa-core-utils "^1.1.0" - medusa-test-utils "^1.1.1" + medusa-core-utils "1.1.0-dev-1615562702314" + medusa-test-utils "1.1.3-dev-1615562702314" morgan "^1.9.1" multer "^1.4.2" passport "^0.4.0" @@ -1065,6 +1066,11 @@ "@types/minimatch" "*" "@types/node" "*" +"@types/lodash@^4.14.168": + version "4.14.168" + resolved "http://localhost:4873/@types%2flodash/-/lodash-4.14.168.tgz#fe24632e79b7ade3f132891afff86caa5e5ce008" + integrity sha512-oVfRvqHV/V6D1yifJbVRU3TMp8OT6o6BG+U9MkwuJ3U8/CsDHvalRpsxBqivn71ztOFZBTfJMvETbqHiaNSj7Q== + "@types/minimatch@*": version "3.0.3" resolved "https://registry.yarnpkg.com/@types/minimatch/-/minimatch-3.0.3.tgz#3dca0e3f33b200fc7d1139c0cd96c1268cadfd9d" @@ -1223,10 +1229,10 @@ babel-plugin-transform-typescript-metadata@^0.3.1: dependencies: "@babel/helper-plugin-utils" "^7.0.0" -babel-preset-medusa-package@^1.1.0: - version "1.1.0" - resolved "https://registry.yarnpkg.com/babel-preset-medusa-package/-/babel-preset-medusa-package-1.1.0.tgz#3b5a5fc5679a92747a5f13ab5419252b0de67b84" - integrity sha512-1rGnObrfr4WCcmYciovqn8JbwNq2KtbEho/acQAYIxl6G3LOODK/jBH2zQHeW5k4GxjVe72JZDdqjfdm88KmEw== +babel-preset-medusa-package@1.1.0-dev-1615562702314: + version "1.1.0-dev-1615562702314" + resolved "http://localhost:4873/babel-preset-medusa-package/-/babel-preset-medusa-package-1.1.0-dev-1615562702314.tgz#c0e8a2c29054ffad39b91320f2258ea6e3eda176" + integrity sha512-1x2PPmBkTA6+6Rv7SgkuaFdTRpfngF2OfZZ62+Fy0QYSEx3tq+T3r5MlAMV8uCAZCY2gY+n6irQ8Mq6K2LS5xQ== dependencies: "@babel/plugin-proposal-class-properties" "^7.12.1" "@babel/plugin-proposal-decorators" "^7.12.1" @@ -2803,28 +2809,28 @@ media-typer@0.3.0: resolved "https://registry.yarnpkg.com/media-typer/-/media-typer-0.3.0.tgz#8710d7af0aa626f8fffa1ce00168545263255748" integrity sha1-hxDXrwqmJvj/+hzgAWhUUmMlV0g= -medusa-core-utils@^1.1.0: - version "1.1.0" - resolved "https://registry.yarnpkg.com/medusa-core-utils/-/medusa-core-utils-1.1.0.tgz#0641b365b769dbf99856025d935eef5cf5d81f2c" - integrity sha512-zocRthKhLK3eSjrXbAhZZkIMBRxyvU7GcAMFh5UCEgfe7f935vjE7r5lGTr5jTEwgwaoTUk9ep0VBekz0SEdyw== +medusa-core-utils@1.1.0-dev-1615562702314: + version "1.1.0-dev-1615562702314" + resolved "http://localhost:4873/medusa-core-utils/-/medusa-core-utils-1.1.0-dev-1615562702314.tgz#972a9e140f73a143f2c4a57d756862042c3f7178" + integrity sha512-kipde/u8SEMzcNdIHkdBd578gt1taL6O6buE/O7Ne+Egze6zbT9yrJjQrbafQigFkTfXW3ngq28yZwKxblMUlA== dependencies: joi "^17.3.0" joi-objectid "^3.0.1" -medusa-interfaces@^1.1.0: - version "1.1.0" - resolved "https://registry.yarnpkg.com/medusa-interfaces/-/medusa-interfaces-1.1.0.tgz#fdced50c2aac5956b4a40da34841df60a96d16c4" - integrity sha512-wSgHR/MYGJzj6y54u25v7lGX8gTaAJarwN2VIHDTn0lsVGlIPqJem+tbJkDLdUV7V5mERSq5FGoqnIFHeJaDgQ== +medusa-interfaces@1.1.1-dev-1615562702314: + version "1.1.1-dev-1615562702314" + resolved "http://localhost:4873/medusa-interfaces/-/medusa-interfaces-1.1.1-dev-1615562702314.tgz#c3aa0e7dff39727921d3618ec5497e59aec9ed2a" + integrity sha512-G0aG2QPaWdH4G2hri2PiAfYPGKHCQ6Fe9UVKCirH9gTf6KQgGUgBbp0GH0Bvy9o3xnxR1Wm/u0jsID4jtNQyxw== dependencies: - medusa-core-utils "^1.1.0" + medusa-core-utils "1.1.0-dev-1615562702314" -medusa-test-utils@^1.1.1: - version "1.1.1" - resolved "https://registry.yarnpkg.com/medusa-test-utils/-/medusa-test-utils-1.1.1.tgz#e6c9faf9339a2fa22f162c9864091d6e12792215" - integrity sha512-Fx55x1widi9yz3tQSvQbkACyNZMu05j9q9Ta0eDWwb1q96RpTQg0BMc0Em+ZXE9EwxWHqgDUqlAfLGmCW6aQUg== +medusa-test-utils@1.1.3-dev-1615562702314: + version "1.1.3-dev-1615562702314" + resolved "http://localhost:4873/medusa-test-utils/-/medusa-test-utils-1.1.3-dev-1615562702314.tgz#c3a50e97ab31bed9bfa9519d40ef06fcac79b826" + integrity sha512-kjMldY4ZKw+Emu59+0NEVazm+TrklB8htgGvRbY6+G7Oues14UobFDcBPILnvDROSwoxdwhsSy2Q8TycAH4cOg== dependencies: "@babel/plugin-transform-classes" "^7.9.5" - medusa-core-utils "^1.1.0" + medusa-core-utils "1.1.0-dev-1615562702314" randomatic "^3.1.1" merge-descriptors@1.0.1: diff --git a/docs-util/helpers/test-server.js b/docs-util/helpers/test-server.js index 215f28e80c..785c39fd7d 100644 --- a/docs-util/helpers/test-server.js +++ b/docs-util/helpers/test-server.js @@ -1,12 +1,14 @@ const path = require("path"); const express = require("express"); const getPort = require("get-port"); - -const loaders = require("@medusajs/medusa/dist/loaders").default; +const importFrom = require("import-from"); const initialize = async () => { const app = express(); + const cwd = process.cwd(); + const loaders = importFrom(cwd, "@medusajs/medusa/dist/loaders").default; + const { dbConnection } = await loaders({ directory: path.resolve(process.cwd()), expressApp: app, diff --git a/docs/api/admin-spec3.json b/docs/api/admin-spec3.json index f6648c935e..f4c1a9cc58 100644 --- a/docs/api/admin-spec3.json +++ b/docs/api/admin-spec3.json @@ -87,7 +87,7 @@ "application/json": { "schema": { "properties": { - "customer": { + "user": { "$ref": "#/components/schemas/user" } } @@ -134,7 +134,7 @@ "application/json": { "schema": { "properties": { - "customer": { + "user": { "$ref": "#/components/schemas/user" } } @@ -534,510 +534,6 @@ } } }, - "/discounts/{id}/regions/{region_id}": { - "post": { - "operationId": "PostDiscountsDiscountRegionsRegion", - "summary": "Adds Region availability", - "description": "Adds a Region to the list of Regions that a Discount can be used in.", - "parameters": [ - { - "in": "path", - "name": "id", - "required": true, - "description": "The id of the Discount.", - "schema": { - "type": "string" - } - }, - { - "in": "path", - "name": "region_id", - "required": true, - "description": "The id of the Region.", - "schema": { - "type": "string" - } - } - ], - "tags": [ - "Discount" - ], - "responses": { - "200": { - "description": "OK", - "content": { - "application/json": { - "schema": { - "properties": { - "discount": { - "$ref": "#/components/schemas/discount" - } - } - } - } - } - } - } - }, - "delete": { - "operationId": "DeleteDiscountsDiscountRegionsRegion", - "summary": "Remove Region availability", - "description": "Removes a Region from the list of Regions that a Discount can be used in.", - "parameters": [ - { - "in": "path", - "name": "id", - "required": true, - "description": "The id of the Discount.", - "schema": { - "type": "string" - } - }, - { - "in": "path", - "name": "region_id", - "required": true, - "description": "The id of the Region.", - "schema": { - "type": "string" - } - } - ], - "tags": [ - "Discount" - ], - "responses": { - "200": { - "description": "OK", - "content": { - "application/json": { - "schema": { - "properties": { - "discount": { - "$ref": "#/components/schemas/discount" - } - } - } - } - } - } - } - } - }, - "/discounts/{id}/products/{product_id}": { - "post": { - "operationId": "DeleteDiscountsDiscountProductsProduct", - "summary": "Remove Product availability", - "description": "Removes a Product from the list of Products that a Discount can be used for.", - "parameters": [ - { - "in": "path", - "name": "id", - "required": true, - "description": "The id of the Discount.", - "schema": { - "type": "string" - } - }, - { - "in": "path", - "name": "product_id", - "required": true, - "description": "The id of the Product.", - "schema": { - "type": "string" - } - } - ], - "tags": [ - "Discount" - ], - "responses": { - "200": { - "description": "OK", - "content": { - "application/json": { - "schema": { - "properties": { - "discount": { - "$ref": "#/components/schemas/discount" - } - } - } - } - } - } - } - } - }, - "/discounts": { - "post": { - "operationId": "PostDiscounts", - "summary": "Creates a Discount", - "description": "Creates a Discount with a given set of rules that define how the Discount behaves.", - "requestBody": { - "content": { - "application/json": { - "schema": { - "properties": { - "code": { - "type": "string", - "description": "A unique code that will be used to redeem the Discount" - }, - "is_dynamic": { - "type": "string", - "description": "Whether the Discount should have multiple instances of itself, each with a different code. This can be useful for automatically generated codes that all have to follow a common set of rules." - }, - "rule": { - "description": "The Discount Rule that defines how Discounts are calculated", - "oneOf": [ - { - "$ref": "#/components/schemas/discount_rule" - } - ] - }, - "is_disabled": { - "type": "boolean", - "description": "Whether the Discount code is disabled on creation. You will have to enable it later to make it available to Customers." - }, - "starts_at": { - "type": "string", - "format": "date-time", - "description": "The time at which the Discount should be available." - }, - "ends_at": { - "type": "string", - "format": "date-time", - "description": "The time at which the Discount should no longer be available." - }, - "regions": { - "description": "A list of Region ids representing the Regions in which the Discount can be used.", - "type": "array", - "items": { - "type": "string" - } - }, - "metadata": { - "description": "An optional set of key-value pairs to hold additional information.", - "type": "object" - } - } - } - } - } - }, - "tags": [ - "Discount" - ], - "responses": { - "200": { - "description": "OK", - "content": { - "application/json": { - "schema": { - "properties": { - "discount": { - "$ref": "#/components/schemas/discount" - } - } - } - } - } - } - } - }, - "get": { - "operationId": "GetDiscounts", - "summary": "List Discounts", - "description": "Retrieves a list of Discounts", - "tags": [ - "Discount" - ], - "responses": { - "200": { - "description": "OK", - "content": { - "application/json": { - "schema": { - "properties": { - "discount": { - "$ref": "#/components/schemas/discount" - } - } - } - } - } - } - } - } - }, - "/discounts/{id}/dynamic-codes": { - "post": { - "operationId": "PostDiscountsDiscountDynamicCodes", - "summary": "Create a dynamic Discount code", - "description": "Creates a unique code that can map to a parent Discount. This is useful if you want to automatically generate codes with the same behaviour.", - "parameters": [ - { - "in": "path", - "name": "id", - "required": true, - "description": "The id of the Discount to create the dynamic code from.\"", - "schema": { - "type": "string" - } - } - ], - "tags": [ - "Discount" - ], - "responses": { - "200": { - "description": "OK", - "content": { - "application/json": { - "schema": { - "properties": { - "discount": { - "$ref": "#/components/schemas/discount" - } - } - } - } - } - } - }, - "requestBody": { - "content": { - "application/json": { - "schema": { - "type": "object", - "required": [ - "code" - ], - "properties": { - "code": { - "type": "string", - "description": "The unique code that will be used to redeem the Discount." - }, - "metadata": { - "type": "object", - "description": "An optional set of key-value paris to hold additional information." - } - } - } - } - } - } - } - }, - "/discounts/{id}": { - "delete": { - "operationId": "DeleteDiscountsDiscount", - "summary": "Delete a Discount", - "description": "Deletes a Discount.", - "parameters": [ - { - "in": "path", - "name": "id", - "required": true, - "description": "The id of the Discount", - "schema": { - "type": "string" - } - } - ], - "tags": [ - "Discount" - ], - "responses": { - "200": { - "description": "OK", - "content": { - "application/json": { - "schema": { - "properties": { - "id": { - "type": "string", - "description": "The id of the deleted Discount" - }, - "object": { - "type": "string", - "description": "The type of the object that was deleted." - }, - "deleted": { - "type": "boolean" - } - } - } - } - } - } - } - }, - "get": { - "operationId": "GetDiscountsDiscount", - "summary": "Retrieve a Discount", - "description": "Retrieves a Discount", - "parameters": [ - { - "in": "path", - "name": "id", - "required": true, - "description": "The id of the Discount", - "schema": { - "type": "string" - } - } - ], - "tags": [ - "Discount" - ], - "responses": { - "200": { - "description": "OK", - "content": { - "application/json": { - "schema": { - "properties": { - "discount": { - "$ref": "#/components/schemas/discount" - } - } - } - } - } - } - } - }, - "post": { - "operationId": "PostDiscountsDiscount", - "summary": "Update a Discount", - "description": "Updates a Discount with a given set of rules that define how the Discount behaves.", - "parameters": [ - { - "in": "path", - "name": "id", - "required": true, - "description": "The id of the Discount.", - "schema": { - "type": "string" - } - } - ], - "requestBody": { - "content": { - "application/json": { - "schema": { - "properties": { - "code": { - "type": "string", - "description": "A unique code that will be used to redeem the Discount" - }, - "is_dynamic": { - "type": "string", - "description": "Whether the Discount should have multiple instances of itself, each with a different code. This can be useful for automatically generated codes that all have to follow a common set of rules." - }, - "rule": { - "description": "The Discount Rule that defines how Discounts are calculated", - "oneOf": [ - { - "$ref": "#/components/schemas/discount_rule" - } - ] - }, - "is_disabled": { - "type": "boolean", - "description": "Whether the Discount code is disabled on creation. You will have to enable it later to make it available to Customers." - }, - "starts_at": { - "type": "string", - "format": "date-time", - "description": "The time at which the Discount should be available." - }, - "ends_at": { - "type": "string", - "format": "date-time", - "description": "The time at which the Discount should no longer be available." - }, - "regions": { - "description": "A list of Region ids representing the Regions in which the Discount can be used.", - "type": "array", - "items": { - "type": "string" - } - } - } - } - } - } - }, - "tags": [ - "Discount" - ], - "responses": { - "200": { - "description": "OK", - "content": { - "application/json": { - "schema": { - "properties": { - "discount": { - "$ref": "#/components/schemas/discount" - } - } - } - } - } - } - } - } - }, - "/discounts/{id}/dynamic-codes/{code}": { - "delete": { - "operationId": "DeleteDiscountsDiscountDynamicCodesCode", - "summary": "Delete a dynamic code", - "description": "Deletes a dynamic code from a Discount.", - "parameters": [ - { - "in": "path", - "name": "id", - "required": true, - "description": "The id of the Discount", - "schema": { - "type": "string" - } - }, - { - "in": "path", - "name": "code", - "required": true, - "description": "The id of the Discount", - "schema": { - "type": "string" - } - } - ], - "tags": [ - "Discount" - ], - "responses": { - "200": { - "description": "OK", - "content": { - "application/json": { - "schema": { - "properties": { - "discount": { - "$ref": "#/components/schemas/discount" - } - } - } - } - } - } - } - } - }, "/gift-cards": { "post": { "operationId": "PostGiftCards", @@ -2205,8 +1701,11 @@ "application/json": { "schema": { "properties": { - "order": { - "$ref": "#/components/schemas/order" + "orders": { + "type": "array", + "items": { + "$ref": "#/components/schemas/order" + } } } } @@ -2685,6 +2184,510 @@ } } }, + "/discounts/{id}/regions/{region_id}": { + "post": { + "operationId": "PostDiscountsDiscountRegionsRegion", + "summary": "Adds Region availability", + "description": "Adds a Region to the list of Regions that a Discount can be used in.", + "parameters": [ + { + "in": "path", + "name": "id", + "required": true, + "description": "The id of the Discount.", + "schema": { + "type": "string" + } + }, + { + "in": "path", + "name": "region_id", + "required": true, + "description": "The id of the Region.", + "schema": { + "type": "string" + } + } + ], + "tags": [ + "Discount" + ], + "responses": { + "200": { + "description": "OK", + "content": { + "application/json": { + "schema": { + "properties": { + "discount": { + "$ref": "#/components/schemas/discount" + } + } + } + } + } + } + } + }, + "delete": { + "operationId": "DeleteDiscountsDiscountRegionsRegion", + "summary": "Remove Region availability", + "description": "Removes a Region from the list of Regions that a Discount can be used in.", + "parameters": [ + { + "in": "path", + "name": "id", + "required": true, + "description": "The id of the Discount.", + "schema": { + "type": "string" + } + }, + { + "in": "path", + "name": "region_id", + "required": true, + "description": "The id of the Region.", + "schema": { + "type": "string" + } + } + ], + "tags": [ + "Discount" + ], + "responses": { + "200": { + "description": "OK", + "content": { + "application/json": { + "schema": { + "properties": { + "discount": { + "$ref": "#/components/schemas/discount" + } + } + } + } + } + } + } + } + }, + "/discounts/{id}/products/{product_id}": { + "post": { + "operationId": "DeleteDiscountsDiscountProductsProduct", + "summary": "Remove Product availability", + "description": "Removes a Product from the list of Products that a Discount can be used for.", + "parameters": [ + { + "in": "path", + "name": "id", + "required": true, + "description": "The id of the Discount.", + "schema": { + "type": "string" + } + }, + { + "in": "path", + "name": "product_id", + "required": true, + "description": "The id of the Product.", + "schema": { + "type": "string" + } + } + ], + "tags": [ + "Discount" + ], + "responses": { + "200": { + "description": "OK", + "content": { + "application/json": { + "schema": { + "properties": { + "discount": { + "$ref": "#/components/schemas/discount" + } + } + } + } + } + } + } + } + }, + "/discounts": { + "post": { + "operationId": "PostDiscounts", + "summary": "Creates a Discount", + "description": "Creates a Discount with a given set of rules that define how the Discount behaves.", + "requestBody": { + "content": { + "application/json": { + "schema": { + "properties": { + "code": { + "type": "string", + "description": "A unique code that will be used to redeem the Discount" + }, + "is_dynamic": { + "type": "string", + "description": "Whether the Discount should have multiple instances of itself, each with a different code. This can be useful for automatically generated codes that all have to follow a common set of rules." + }, + "rule": { + "description": "The Discount Rule that defines how Discounts are calculated", + "oneOf": [ + { + "$ref": "#/components/schemas/discount_rule" + } + ] + }, + "is_disabled": { + "type": "boolean", + "description": "Whether the Discount code is disabled on creation. You will have to enable it later to make it available to Customers." + }, + "starts_at": { + "type": "string", + "format": "date-time", + "description": "The time at which the Discount should be available." + }, + "ends_at": { + "type": "string", + "format": "date-time", + "description": "The time at which the Discount should no longer be available." + }, + "regions": { + "description": "A list of Region ids representing the Regions in which the Discount can be used.", + "type": "array", + "items": { + "type": "string" + } + }, + "metadata": { + "description": "An optional set of key-value pairs to hold additional information.", + "type": "object" + } + } + } + } + } + }, + "tags": [ + "Discount" + ], + "responses": { + "200": { + "description": "OK", + "content": { + "application/json": { + "schema": { + "properties": { + "discount": { + "$ref": "#/components/schemas/discount" + } + } + } + } + } + } + } + }, + "get": { + "operationId": "GetDiscounts", + "summary": "List Discounts", + "description": "Retrieves a list of Discounts", + "tags": [ + "Discount" + ], + "responses": { + "200": { + "description": "OK", + "content": { + "application/json": { + "schema": { + "properties": { + "discount": { + "$ref": "#/components/schemas/discount" + } + } + } + } + } + } + } + } + }, + "/discounts/{id}/dynamic-codes": { + "post": { + "operationId": "PostDiscountsDiscountDynamicCodes", + "summary": "Create a dynamic Discount code", + "description": "Creates a unique code that can map to a parent Discount. This is useful if you want to automatically generate codes with the same behaviour.", + "parameters": [ + { + "in": "path", + "name": "id", + "required": true, + "description": "The id of the Discount to create the dynamic code from.\"", + "schema": { + "type": "string" + } + } + ], + "tags": [ + "Discount" + ], + "responses": { + "200": { + "description": "OK", + "content": { + "application/json": { + "schema": { + "properties": { + "discount": { + "$ref": "#/components/schemas/discount" + } + } + } + } + } + } + }, + "requestBody": { + "content": { + "application/json": { + "schema": { + "type": "object", + "required": [ + "code" + ], + "properties": { + "code": { + "type": "string", + "description": "The unique code that will be used to redeem the Discount." + }, + "metadata": { + "type": "object", + "description": "An optional set of key-value paris to hold additional information." + } + } + } + } + } + } + } + }, + "/discounts/{id}": { + "delete": { + "operationId": "DeleteDiscountsDiscount", + "summary": "Delete a Discount", + "description": "Deletes a Discount.", + "parameters": [ + { + "in": "path", + "name": "id", + "required": true, + "description": "The id of the Discount", + "schema": { + "type": "string" + } + } + ], + "tags": [ + "Discount" + ], + "responses": { + "200": { + "description": "OK", + "content": { + "application/json": { + "schema": { + "properties": { + "id": { + "type": "string", + "description": "The id of the deleted Discount" + }, + "object": { + "type": "string", + "description": "The type of the object that was deleted." + }, + "deleted": { + "type": "boolean" + } + } + } + } + } + } + } + }, + "get": { + "operationId": "GetDiscountsDiscount", + "summary": "Retrieve a Discount", + "description": "Retrieves a Discount", + "parameters": [ + { + "in": "path", + "name": "id", + "required": true, + "description": "The id of the Discount", + "schema": { + "type": "string" + } + } + ], + "tags": [ + "Discount" + ], + "responses": { + "200": { + "description": "OK", + "content": { + "application/json": { + "schema": { + "properties": { + "discount": { + "$ref": "#/components/schemas/discount" + } + } + } + } + } + } + } + }, + "post": { + "operationId": "PostDiscountsDiscount", + "summary": "Update a Discount", + "description": "Updates a Discount with a given set of rules that define how the Discount behaves.", + "parameters": [ + { + "in": "path", + "name": "id", + "required": true, + "description": "The id of the Discount.", + "schema": { + "type": "string" + } + } + ], + "requestBody": { + "content": { + "application/json": { + "schema": { + "properties": { + "code": { + "type": "string", + "description": "A unique code that will be used to redeem the Discount" + }, + "is_dynamic": { + "type": "string", + "description": "Whether the Discount should have multiple instances of itself, each with a different code. This can be useful for automatically generated codes that all have to follow a common set of rules." + }, + "rule": { + "description": "The Discount Rule that defines how Discounts are calculated", + "oneOf": [ + { + "$ref": "#/components/schemas/discount_rule" + } + ] + }, + "is_disabled": { + "type": "boolean", + "description": "Whether the Discount code is disabled on creation. You will have to enable it later to make it available to Customers." + }, + "starts_at": { + "type": "string", + "format": "date-time", + "description": "The time at which the Discount should be available." + }, + "ends_at": { + "type": "string", + "format": "date-time", + "description": "The time at which the Discount should no longer be available." + }, + "regions": { + "description": "A list of Region ids representing the Regions in which the Discount can be used.", + "type": "array", + "items": { + "type": "string" + } + } + } + } + } + } + }, + "tags": [ + "Discount" + ], + "responses": { + "200": { + "description": "OK", + "content": { + "application/json": { + "schema": { + "properties": { + "discount": { + "$ref": "#/components/schemas/discount" + } + } + } + } + } + } + } + } + }, + "/discounts/{id}/dynamic-codes/{code}": { + "delete": { + "operationId": "DeleteDiscountsDiscountDynamicCodesCode", + "summary": "Delete a dynamic code", + "description": "Deletes a dynamic code from a Discount.", + "parameters": [ + { + "in": "path", + "name": "id", + "required": true, + "description": "The id of the Discount", + "schema": { + "type": "string" + } + }, + { + "in": "path", + "name": "code", + "required": true, + "description": "The id of the Discount", + "schema": { + "type": "string" + } + } + ], + "tags": [ + "Discount" + ], + "responses": { + "200": { + "description": "OK", + "content": { + "application/json": { + "schema": { + "properties": { + "discount": { + "$ref": "#/components/schemas/discount" + } + } + } + } + } + } + } + } + }, "/products/{id}/options": { "post": { "operationId": "PostProductsProductOptions", diff --git a/docs/api/admin-spec3.yaml b/docs/api/admin-spec3.yaml index 6668035d49..2fbb911126 100644 --- a/docs/api/admin-spec3.yaml +++ b/docs/api/admin-spec3.yaml @@ -53,7 +53,7 @@ paths: application/json: schema: properties: - customer: + user: $ref: '#/components/schemas/user' requestBody: content: @@ -83,7 +83,7 @@ paths: application/json: schema: properties: - customer: + user: $ref: '#/components/schemas/user' /collections: post: @@ -695,6 +695,49 @@ paths: properties: 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: post: operationId: PostGiftCards @@ -867,49 +910,6 @@ paths: properties: 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': post: operationId: PostOrdersOrderShippingMethods @@ -1511,8 +1511,10 @@ paths: application/json: schema: properties: - order: - $ref: '#/components/schemas/order' + orders: + type: array + items: + $ref: '#/components/schemas/order' '/orders/{id}/swaps/{swap_id}/process-payment': post: operationId: PostOrdersOrderSwapsSwapProcessPayment @@ -3480,6 +3482,24 @@ paths: properties: shipping_profiles: $ref: '#/components/schemas/shipping_profile' + /swaps: + get: + operationId: GetSwaps + summary: List Swaps + description: Retrieves a list of Swaps. + tags: + - Swap + responses: + '200': + description: OK + content: + application/json: + schema: + properties: + swaps: + type: array + items: + $ref: '#/components/schemas/swap' '/store/currencies/{code}': post: operationId: PostStoreCurrenciesCode @@ -3590,24 +3610,6 @@ paths: type: array items: $ref: '#/components/schemas/store' - /swaps: - get: - operationId: GetSwaps - summary: List Swaps - description: Retrieves a list of Swaps. - tags: - - Swap - responses: - '200': - description: OK - content: - application/json: - schema: - properties: - swaps: - type: array - items: - $ref: '#/components/schemas/swap' /variants: get: operationId: GetVariants diff --git a/docs/api/fixtures.json b/docs/api/fixtures.json index c7b37fa53a..9cdf71cfff 100644 --- a/docs/api/fixtures.json +++ b/docs/api/fixtures.json @@ -1,7 +1,7 @@ { "resources": { "customer": { - "id": "cus_01F0BGFY6ANPB473KJ5H8V889M", + "id": "cus_01F0VY3BQPZZTZGWHPPNVW87RP", "email": "test1@email.com", "first_name": null, "last_name": null, @@ -10,21 +10,21 @@ "phone": null, "has_account": false, "orders": [], - "created_at": "2021-03-09T12:48:21.706Z", - "updated_at": "2021-03-09T12:48:21.706Z", + "created_at": "2021-03-15T21:54:00.566Z", + "updated_at": "2021-03-15T21:54:00.566Z", "deleted_at": null, "metadata": null }, "order": { - "id": "order_01F0BGFG2Z0X0ETETP0YS0HRCT", + "id": "order_01F0VY2B8H3S6R3W6EY4QMKWG1", "status": "pending", "fulfillment_status": "not_fulfilled", "payment_status": "not_paid", "display_id": 1, "cart_id": null, - "customer_id": "cus_01F0BGFG280DRD18VXM1F9GJXA", + "customer_id": "cus_01F0VY2B7Y2Y18PDQZMGWB0VF0", "customer": { - "id": "cus_01F0BGFG280DRD18VXM1F9GJXA", + "id": "cus_01F0VY2B7Y2Y18PDQZMGWB0VF0", "email": "test@email.com", "first_name": null, "last_name": null, @@ -32,14 +32,14 @@ "password_hash": null, "phone": null, "has_account": false, - "created_at": "2021-03-09T12:48:07.240Z", - "updated_at": "2021-03-09T12:48:07.240Z", + "created_at": "2021-03-15T21:53:27.294Z", + "updated_at": "2021-03-15T21:53:27.294Z", "deleted_at": null, "metadata": null }, "email": "test@email.com", "billing_address": { - "id": "addr_01F0BGFG30PG1NP6V0EDJDF6PW", + "id": "addr_01F0VY2B8HSF0DGYRRMKAD0QE4", "customer_id": null, "company": null, "first_name": "lebron", @@ -51,13 +51,13 @@ "province": null, "postal_code": null, "phone": null, - "created_at": "2021-03-09T12:48:07.263Z", - "updated_at": "2021-03-09T12:48:07.263Z", + "created_at": "2021-03-15T21:53:27.313Z", + "updated_at": "2021-03-15T21:53:27.313Z", "deleted_at": null, "metadata": null }, "shipping_address": { - "id": "addr_01F0BGFG30EBKX6C89N35YB2PX", + "id": "addr_01F0VY2B8HXBT67KYXJKMEDYR4", "customer_id": null, "company": null, "first_name": "lebron", @@ -69,22 +69,22 @@ "province": null, "postal_code": null, "phone": null, - "created_at": "2021-03-09T12:48:07.263Z", - "updated_at": "2021-03-09T12:48:07.263Z", + "created_at": "2021-03-15T21:53:27.313Z", + "updated_at": "2021-03-15T21:53:27.313Z", "deleted_at": null, "metadata": null }, - "region_id": "reg_01F0BGFG21NC3VQ662FYNF3P4Z", + "region_id": "reg_01F0VY2B7RAKG6PSVJ47KQP0PA", "region": { - "id": "reg_01F0BGFG21NC3VQ662FYNF3P4Z", + "id": "reg_01F0VY2B7RAKG6PSVJ47KQP0PA", "name": "Test Region", "currency_code": "usd", "tax_rate": "0", "tax_code": null, "payment_providers": [], "fulfillment_providers": [], - "created_at": "2021-03-09T12:48:07.233Z", - "updated_at": "2021-03-09T12:48:07.233Z", + "created_at": "2021-03-15T21:53:27.287Z", + "updated_at": "2021-03-15T21:53:27.287Z", "deleted_at": null, "metadata": null }, @@ -95,25 +95,25 @@ "id": "test-discount", "code": "TEST134", "is_dynamic": false, - "rule_id": "dru_01F0BGFG30S3FSBE67PKDCTT0Y", + "rule_id": "dru_01F0VY2B8H55AYVCW47B8DWMCN", "rule": { - "id": "dru_01F0BGFG30S3FSBE67PKDCTT0Y", + "id": "dru_01F0VY2B8H55AYVCW47B8DWMCN", "description": "Test Discount", "type": "percentage", "value": 10, "allocation": "total", "usage_limit": null, - "created_at": "2021-03-09T12:48:07.263Z", - "updated_at": "2021-03-09T12:48:07.263Z", + "created_at": "2021-03-15T21:53:27.313Z", + "updated_at": "2021-03-15T21:53:27.313Z", "deleted_at": null, "metadata": null }, "is_disabled": false, "parent_discount_id": null, - "starts_at": "2021-03-09T12:48:07.263Z", + "starts_at": "2021-03-15T21:53:27.313Z", "ends_at": null, - "created_at": "2021-03-09T12:48:07.263Z", - "updated_at": "2021-03-09T12:48:07.263Z", + "created_at": "2021-03-15T21:53:27.313Z", + "updated_at": "2021-03-15T21:53:27.313Z", "deleted_at": null, "metadata": null } @@ -121,25 +121,25 @@ "gift_cards": [], "shipping_methods": [ { - "id": "sm_01F0BGFG3SQZC01D8JP4REY0RF", - "shipping_option_id": "so_01F0BGFG2DV0GR6VD87AQ7XAB2", - "order_id": "order_01F0BGFG2Z0X0ETETP0YS0HRCT", + "id": "sm_01F0VY2B9DGWC1W2TDHHPBZD4Q", + "shipping_option_id": "so_01F0VY2B81KREYYVHH2SJQJ2NA", + "order_id": "order_01F0VY2B8H3S6R3W6EY4QMKWG1", "claim_order_id": null, "cart_id": null, "swap_id": null, "return_id": null, "shipping_option": { - "id": "so_01F0BGFG2DV0GR6VD87AQ7XAB2", + "id": "so_01F0VY2B81KREYYVHH2SJQJ2NA", "name": "test-option", - "region_id": "reg_01F0BGFG21NC3VQ662FYNF3P4Z", - "profile_id": "sp_01F0BGFG04GKTA9FTYWBT19NKJ", + "region_id": "reg_01F0VY2B7RAKG6PSVJ47KQP0PA", + "profile_id": "sp_01F0VY2B5KMSAXMSD449SFG005", "provider_id": "test-ful", "price_type": "flat_rate", "amount": 1000, "is_return": false, "data": {}, - "created_at": "2021-03-09T12:48:07.245Z", - "updated_at": "2021-03-09T12:48:07.245Z", + "created_at": "2021-03-15T21:53:27.297Z", + "updated_at": "2021-03-15T21:53:27.297Z", "deleted_at": null, "metadata": null }, @@ -152,7 +152,7 @@ "id": "test-payment", "swap_id": null, "cart_id": null, - "order_id": "order_01F0BGFG2Z0X0ETETP0YS0HRCT", + "order_id": "order_01F0VY2B8H3S6R3W6EY4QMKWG1", "amount": 10000, "currency_code": "usd", "amount_refunded": 0, @@ -160,8 +160,8 @@ "data": {}, "captured_at": null, "canceled_at": null, - "created_at": "2021-03-09T12:48:07.263Z", - "updated_at": "2021-03-09T12:48:07.263Z", + "created_at": "2021-03-15T21:53:27.313Z", + "updated_at": "2021-03-15T21:53:27.313Z", "metadata": null, "idempotency_key": null } @@ -175,7 +175,7 @@ { "id": "test-item", "cart_id": null, - "order_id": "order_01F0BGFG2Z0X0ETETP0YS0HRCT", + "order_id": "order_01F0VY2B8H3S6R3W6EY4QMKWG1", "swap_id": null, "claim_order_id": null, "title": "Line Item", @@ -192,16 +192,16 @@ "fulfilled_quantity": 1, "returned_quantity": null, "shipped_quantity": null, - "created_at": "2021-03-09T12:48:07.263Z", - "updated_at": "2021-03-09T12:48:07.263Z", + "created_at": "2021-03-15T21:53:27.313Z", + "updated_at": "2021-03-15T21:53:27.313Z", "metadata": null, "refundable": 7200 } ], "gift_card_transactions": [], "canceled_at": null, - "created_at": "2021-03-09T12:48:07.263Z", - "updated_at": "2021-03-09T12:48:07.263Z", + "created_at": "2021-03-15T21:53:27.313Z", + "updated_at": "2021-03-15T21:53:27.313Z", "metadata": null, "shipping_total": 1000, "gift_card_total": 0, @@ -213,7 +213,7 @@ "refundable_amount": 8200 }, "product": { - "id": "prod_01F0BGG4MWSZH7YYJGHGZMQKHM", + "id": "prod_01F0VY2HP5Z742ZQJ88G8K88XA", "title": "Test product", "subtitle": null, "description": "test-product-description", @@ -223,38 +223,38 @@ "thumbnail": null, "options": [ { - "id": "opt_01F0BGG4N2W8EZJP5KDV0W2250", + "id": "opt_01F0VY2HPB68E6XV3JNRW000TW", "title": "size", - "product_id": "prod_01F0BGG4MWSZH7YYJGHGZMQKHM", - "created_at": "2021-03-09T12:48:28.304Z", - "updated_at": "2021-03-09T12:48:28.304Z", + "product_id": "prod_01F0VY2HP5Z742ZQJ88G8K88XA", + "created_at": "2021-03-15T21:53:33.884Z", + "updated_at": "2021-03-15T21:53:33.884Z", "deleted_at": null, "metadata": null }, { - "id": "opt_01F0BGG4N3Q09ME0BEZG6XZGFQ", + "id": "opt_01F0VY2HPBK73EGMPH4XP2ZH1M", "title": "color", - "product_id": "prod_01F0BGG4MWSZH7YYJGHGZMQKHM", - "created_at": "2021-03-09T12:48:28.304Z", - "updated_at": "2021-03-09T12:48:28.304Z", + "product_id": "prod_01F0VY2HP5Z742ZQJ88G8K88XA", + "created_at": "2021-03-15T21:53:33.884Z", + "updated_at": "2021-03-15T21:53:33.884Z", "deleted_at": null, "metadata": null } ], "variants": [ { - "id": "variant_01F0BGG4NYDVW4V6AHKB58DQWT", + "id": "variant_01F0VY2HQ5FCB5CZS651SY4YDJ", "title": "Test variant", - "product_id": "prod_01F0BGG4MWSZH7YYJGHGZMQKHM", + "product_id": "prod_01F0VY2HP5Z742ZQJ88G8K88XA", "product": { - "id": "prod_01F0BGG4MWSZH7YYJGHGZMQKHM", + "id": "prod_01F0VY2HP5Z742ZQJ88G8K88XA", "title": "Test product", "subtitle": null, "description": "test-product-description", "handle": "test-product", "is_giftcard": false, "thumbnail": null, - "profile_id": "sp_01F0BGG4J2RGH25WZVP8S6VNGW", + "profile_id": "sp_01F0VY2HHYESK5JG3NSDWBH0EX", "weight": null, "length": null, "height": null, @@ -265,21 +265,21 @@ "material": null, "collection_id": "test-collection", "type_id": "test-type", - "created_at": "2021-03-09T12:48:28.304Z", - "updated_at": "2021-03-09T12:48:28.304Z", + "created_at": "2021-03-15T21:53:33.884Z", + "updated_at": "2021-03-15T21:53:33.884Z", "deleted_at": null, "metadata": null }, "prices": [ { - "id": "ma_01F0BGG4P5K0TCMD72MJFS0M65", + "id": "ma_01F0VY2HQA993M711M9F2QZ5K8", "currency_code": "usd", "amount": 100, "sale_amount": null, - "variant_id": "variant_01F0BGG4NYDVW4V6AHKB58DQWT", + "variant_id": "variant_01F0VY2HQ5FCB5CZS651SY4YDJ", "region_id": null, - "created_at": "2021-03-09T12:48:28.304Z", - "updated_at": "2021-03-09T12:48:28.304Z", + "created_at": "2021-03-15T21:53:33.884Z", + "updated_at": "2021-03-15T21:53:33.884Z", "deleted_at": null } ], @@ -300,33 +300,33 @@ "width": null, "options": [ { - "id": "optval_01F0BGG4NY1PRPV3FXQ3J66GQH", + "id": "optval_01F0VY2HQ5WSBTQP2VC67ZFY9V", "value": "large", - "option_id": "opt_01F0BGG4N2W8EZJP5KDV0W2250", - "variant_id": "variant_01F0BGG4NYDVW4V6AHKB58DQWT", - "created_at": "2021-03-09T12:48:28.304Z", - "updated_at": "2021-03-09T12:48:28.304Z", + "option_id": "opt_01F0VY2HPB68E6XV3JNRW000TW", + "variant_id": "variant_01F0VY2HQ5FCB5CZS651SY4YDJ", + "created_at": "2021-03-15T21:53:33.884Z", + "updated_at": "2021-03-15T21:53:33.884Z", "deleted_at": null, "metadata": null }, { - "id": "optval_01F0BGG4NYTMFH5EXJ4C7QAKSK", + "id": "optval_01F0VY2HQ5HEQPKWPZ9R85YVWS", "value": "green", - "option_id": "opt_01F0BGG4N3Q09ME0BEZG6XZGFQ", - "variant_id": "variant_01F0BGG4NYDVW4V6AHKB58DQWT", - "created_at": "2021-03-09T12:48:28.304Z", - "updated_at": "2021-03-09T12:48:28.304Z", + "option_id": "opt_01F0VY2HPBK73EGMPH4XP2ZH1M", + "variant_id": "variant_01F0VY2HQ5FCB5CZS651SY4YDJ", + "created_at": "2021-03-15T21:53:33.884Z", + "updated_at": "2021-03-15T21:53:33.884Z", "deleted_at": null, "metadata": null } ], - "created_at": "2021-03-09T12:48:28.304Z", - "updated_at": "2021-03-09T12:48:28.304Z", + "created_at": "2021-03-15T21:53:33.884Z", + "updated_at": "2021-03-15T21:53:33.884Z", "deleted_at": null, "metadata": null } ], - "profile_id": "sp_01F0BGG4J2RGH25WZVP8S6VNGW", + "profile_id": "sp_01F0VY2HHYESK5JG3NSDWBH0EX", "weight": null, "length": null, "height": null, @@ -340,8 +340,8 @@ "id": "test-collection", "title": "Test collection", "handle": null, - "created_at": "2021-03-09T12:48:28.250Z", - "updated_at": "2021-03-09T12:48:28.250Z", + "created_at": "2021-03-15T21:53:33.797Z", + "updated_at": "2021-03-15T21:53:33.797Z", "deleted_at": null, "metadata": null }, @@ -349,8 +349,8 @@ "type": { "id": "test-type", "value": "test-type", - "created_at": "2021-03-09T12:48:28.260Z", - "updated_at": "2021-03-09T12:48:28.260Z", + "created_at": "2021-03-15T21:53:33.813Z", + "updated_at": "2021-03-15T21:53:33.813Z", "deleted_at": null, "metadata": null }, @@ -358,32 +358,32 @@ { "id": "tag1", "value": "123", - "created_at": "2021-03-09T12:48:28.257Z", - "updated_at": "2021-03-09T12:48:28.257Z", + "created_at": "2021-03-15T21:53:33.809Z", + "updated_at": "2021-03-15T21:53:33.809Z", "deleted_at": null, "metadata": null }, { - "id": "ptag_01F0BGG4MRHZSMYN9Q1YQZHPWT", + "id": "ptag_01F0VY2HP14MV8695X229DHGDT", "value": "456", - "created_at": "2021-03-09T12:48:28.304Z", - "updated_at": "2021-03-09T12:48:28.304Z", + "created_at": "2021-03-15T21:53:33.884Z", + "updated_at": "2021-03-15T21:53:33.884Z", "deleted_at": null, "metadata": null } ], - "created_at": "2021-03-09T12:48:28.304Z", - "updated_at": "2021-03-09T12:48:28.304Z", + "created_at": "2021-03-15T21:53:33.884Z", + "updated_at": "2021-03-15T21:53:33.884Z", "metadata": null }, "cart": { - "id": "cart_01F0BGFQA6ETNHS7QGEZD9VTF2", + "id": "cart_01F0VYC80B1KK49045W4CZTHNW", "email": null, "billing_address_id": null, "billing_address": null, - "shipping_address_id": "addr_01F0BGFQA6YF81V6CREDHNCZMZ", + "shipping_address_id": "addr_01F0VYC80BK976RK5HE7YB9A7S", "shipping_address": { - "id": "addr_01F0BGFQA6YF81V6CREDHNCZMZ", + "id": "addr_01F0VYC80BK976RK5HE7YB9A7S", "customer_id": null, "company": null, "first_name": null, @@ -395,8 +395,8 @@ "province": null, "postal_code": null, "phone": null, - "created_at": "2021-03-09T12:48:14.638Z", - "updated_at": "2021-03-09T12:48:14.638Z", + "created_at": "2021-03-15T21:58:51.632Z", + "updated_at": "2021-03-15T21:58:51.632Z", "deleted_at": null, "metadata": null }, @@ -421,8 +421,8 @@ ], "payment_providers": [], "fulfillment_providers": [], - "created_at": "2021-03-09T12:48:14.601Z", - "updated_at": "2021-03-09T12:48:14.601Z", + "created_at": "2021-03-15T21:58:51.602Z", + "updated_at": "2021-03-15T21:58:51.602Z", "deleted_at": null, "metadata": null }, @@ -435,8 +435,8 @@ "shipping_methods": [], "type": "default", "completed_at": null, - "created_at": "2021-03-09T12:48:14.638Z", - "updated_at": "2021-03-09T12:48:14.777Z", + "created_at": "2021-03-15T21:58:51.632Z", + "updated_at": "2021-03-15T21:58:51.757Z", "deleted_at": null, "metadata": null, "idempotency_key": null, @@ -448,53 +448,53 @@ "total": 0 }, "product_collection": { - "id": "pcol_01F0BGG81W0FERCAHMR79J72G8", + "id": "pcol_01F0VY3W9433C9Q2JGZC1MVFYQ", "title": "Summer Collection", "handle": "summer-collection", - "created_at": "2021-03-09T12:48:31.804Z", - "updated_at": "2021-03-09T12:48:31.804Z", + "created_at": "2021-03-15T21:54:17.507Z", + "updated_at": "2021-03-15T21:54:17.507Z", "deleted_at": null, "metadata": null }, "discount": { - "id": "disc_01F0BGG1BJH91HJ7J9Q0NR0BR6", + "id": "disc_01F0VYCE742WAYBT38HNSVWZP6", "code": "10DISC", "is_dynamic": false, - "rule_id": "dru_01F0BGG1B3BCZ292BSRRK72JGS", + "rule_id": "dru_01F0VYCE6R1QV0DFT64EXGGVA2", "rule": { - "id": "dru_01F0BGG1B3BCZ292BSRRK72JGS", + "id": "dru_01F0VYCE6R1QV0DFT64EXGGVA2", "description": "10 Percent", "type": "percentage", "value": 10, "allocation": "total", "usage_limit": null, - "created_at": "2021-03-09T12:48:24.921Z", - "updated_at": "2021-03-09T12:48:24.921Z", + "created_at": "2021-03-15T21:58:57.998Z", + "updated_at": "2021-03-15T21:58:57.998Z", "deleted_at": null, "metadata": null }, "is_disabled": false, "parent_discount_id": null, - "starts_at": "2021-03-09T12:48:24.921Z", + "starts_at": "2021-03-15T21:58:57.998Z", "ends_at": null, - "created_at": "2021-03-09T12:48:24.921Z", - "updated_at": "2021-03-09T12:48:24.921Z", + "created_at": "2021-03-15T21:58:57.998Z", + "updated_at": "2021-03-15T21:58:57.998Z", "deleted_at": null, "metadata": null }, "product_variant": { - "id": "variant_01F0BGG4NYDVW4V6AHKB58DQWT", + "id": "variant_01F0VY2HQ5FCB5CZS651SY4YDJ", "title": "Test variant", - "product_id": "prod_01F0BGG4MWSZH7YYJGHGZMQKHM", + "product_id": "prod_01F0VY2HP5Z742ZQJ88G8K88XA", "product": { - "id": "prod_01F0BGG4MWSZH7YYJGHGZMQKHM", + "id": "prod_01F0VY2HP5Z742ZQJ88G8K88XA", "title": "Test product", "subtitle": null, "description": "test-product-description", "handle": "test-product", "is_giftcard": false, "thumbnail": null, - "profile_id": "sp_01F0BGG4J2RGH25WZVP8S6VNGW", + "profile_id": "sp_01F0VY2HHYESK5JG3NSDWBH0EX", "weight": null, "length": null, "height": null, @@ -505,21 +505,21 @@ "material": null, "collection_id": "test-collection", "type_id": "test-type", - "created_at": "2021-03-09T12:48:28.304Z", - "updated_at": "2021-03-09T12:48:28.304Z", + "created_at": "2021-03-15T21:53:33.884Z", + "updated_at": "2021-03-15T21:53:33.884Z", "deleted_at": null, "metadata": null }, "prices": [ { - "id": "ma_01F0BGG4P5K0TCMD72MJFS0M65", + "id": "ma_01F0VY2HQA993M711M9F2QZ5K8", "currency_code": "usd", "amount": 100, "sale_amount": null, - "variant_id": "variant_01F0BGG4NYDVW4V6AHKB58DQWT", + "variant_id": "variant_01F0VY2HQ5FCB5CZS651SY4YDJ", "region_id": null, - "created_at": "2021-03-09T12:48:28.304Z", - "updated_at": "2021-03-09T12:48:28.304Z", + "created_at": "2021-03-15T21:53:33.884Z", + "updated_at": "2021-03-15T21:53:33.884Z", "deleted_at": null } ], @@ -540,93 +540,93 @@ "width": null, "options": [ { - "id": "optval_01F0BGG4NY1PRPV3FXQ3J66GQH", + "id": "optval_01F0VY2HQ5WSBTQP2VC67ZFY9V", "value": "large", - "option_id": "opt_01F0BGG4N2W8EZJP5KDV0W2250", - "variant_id": "variant_01F0BGG4NYDVW4V6AHKB58DQWT", - "created_at": "2021-03-09T12:48:28.304Z", - "updated_at": "2021-03-09T12:48:28.304Z", + "option_id": "opt_01F0VY2HPB68E6XV3JNRW000TW", + "variant_id": "variant_01F0VY2HQ5FCB5CZS651SY4YDJ", + "created_at": "2021-03-15T21:53:33.884Z", + "updated_at": "2021-03-15T21:53:33.884Z", "deleted_at": null, "metadata": null }, { - "id": "optval_01F0BGG4NYTMFH5EXJ4C7QAKSK", + "id": "optval_01F0VY2HQ5HEQPKWPZ9R85YVWS", "value": "green", - "option_id": "opt_01F0BGG4N3Q09ME0BEZG6XZGFQ", - "variant_id": "variant_01F0BGG4NYDVW4V6AHKB58DQWT", - "created_at": "2021-03-09T12:48:28.304Z", - "updated_at": "2021-03-09T12:48:28.304Z", + "option_id": "opt_01F0VY2HPBK73EGMPH4XP2ZH1M", + "variant_id": "variant_01F0VY2HQ5FCB5CZS651SY4YDJ", + "created_at": "2021-03-15T21:53:33.884Z", + "updated_at": "2021-03-15T21:53:33.884Z", "deleted_at": null, "metadata": null } ], - "created_at": "2021-03-09T12:48:28.304Z", - "updated_at": "2021-03-09T12:48:28.304Z", + "created_at": "2021-03-15T21:53:33.884Z", + "updated_at": "2021-03-15T21:53:33.884Z", "deleted_at": null, "metadata": null }, "product_option": { - "id": "opt_01F0BGG4N2W8EZJP5KDV0W2250", + "id": "opt_01F0VY2HPB68E6XV3JNRW000TW", "title": "size", - "product_id": "prod_01F0BGG4MWSZH7YYJGHGZMQKHM", - "created_at": "2021-03-09T12:48:28.304Z", - "updated_at": "2021-03-09T12:48:28.304Z", + "product_id": "prod_01F0VY2HP5Z742ZQJ88G8K88XA", + "created_at": "2021-03-15T21:53:33.884Z", + "updated_at": "2021-03-15T21:53:33.884Z", "deleted_at": null, "metadata": null }, "product_option_value": { - "id": "optval_01F0BGG4NY1PRPV3FXQ3J66GQH", + "id": "optval_01F0VY2HQ5WSBTQP2VC67ZFY9V", "value": "large", - "option_id": "opt_01F0BGG4N2W8EZJP5KDV0W2250", - "variant_id": "variant_01F0BGG4NYDVW4V6AHKB58DQWT", - "created_at": "2021-03-09T12:48:28.304Z", - "updated_at": "2021-03-09T12:48:28.304Z", + "option_id": "opt_01F0VY2HPB68E6XV3JNRW000TW", + "variant_id": "variant_01F0VY2HQ5FCB5CZS651SY4YDJ", + "created_at": "2021-03-15T21:53:33.884Z", + "updated_at": "2021-03-15T21:53:33.884Z", "deleted_at": null, "metadata": null }, "money_amount": { - "id": "ma_01F0BGG4P5K0TCMD72MJFS0M65", + "id": "ma_01F0VY2HQA993M711M9F2QZ5K8", "currency_code": "usd", "amount": 100, "sale_amount": null, - "variant_id": "variant_01F0BGG4NYDVW4V6AHKB58DQWT", + "variant_id": "variant_01F0VY2HQ5FCB5CZS651SY4YDJ", "region_id": null, - "created_at": "2021-03-09T12:48:28.304Z", - "updated_at": "2021-03-09T12:48:28.304Z", + "created_at": "2021-03-15T21:53:33.884Z", + "updated_at": "2021-03-15T21:53:33.884Z", "deleted_at": null }, "gift_card": { - "id": "gift_01F0BF6H3XHRT2SF4Y05AM95B9", - "code": "HRYB-SMX4-XXQN-2SRL", + "id": "gift_01F0VY36MYBD8QJJX560HAMK08", + "code": "CUHS-0X5J-GL91-UQZE", "value": 1000, "balance": 1000, - "region_id": "reg_01F0BF6H2MZ06R2G2ZGZCAX3NS", + "region_id": "reg_01F0VY36JGWMSQDSKEA95QR4PJ", "region": { - "id": "reg_01F0BF6H2MZ06R2G2ZGZCAX3NS", + "id": "reg_01F0VY36JGWMSQDSKEA95QR4PJ", "name": "Test Region", "currency_code": "usd", "tax_rate": "0", "tax_code": null, "payment_providers": [], "fulfillment_providers": [], - "created_at": "2021-03-09T12:25:44.788Z", - "updated_at": "2021-03-09T12:25:44.788Z", + "created_at": "2021-03-15T21:53:55.279Z", + "updated_at": "2021-03-15T21:53:55.279Z", "deleted_at": null, "metadata": null }, "is_disabled": false, "ends_at": null, - "created_at": "2021-03-09T12:25:44.818Z", - "updated_at": "2021-03-09T12:25:44.818Z", + "created_at": "2021-03-15T21:53:55.325Z", + "updated_at": "2021-03-15T21:53:55.325Z", "deleted_at": null, "metadata": null }, "shipping_option": { - "id": "so_01F0BGFTXZ6V3GAJHBKHNTR54H", + "id": "so_01F0VY2QV5RYPD9HN1S5SQZPQ5", "name": "Free Shipping", - "region_id": "reg_01F0BGFTW7J0DGWKJJP3X7AWP9", + "region_id": "reg_01F0VY2QSCPG4F8KC9RN2R439T", "region": { - "id": "reg_01F0BGFTW7J0DGWKJJP3X7AWP9", + "id": "reg_01F0VY2QSCPG4F8KC9RN2R439T", "name": "Test Region", "currency_code": "usd", "tax_rate": "0", @@ -638,18 +638,18 @@ "is_installed": true } ], - "created_at": "2021-03-09T12:48:18.311Z", - "updated_at": "2021-03-09T12:48:18.311Z", + "created_at": "2021-03-15T21:53:40.140Z", + "updated_at": "2021-03-15T21:53:40.140Z", "deleted_at": null, "metadata": null }, - "profile_id": "sp_01F0BGFTVGXRBATSDBZN5SK2JP", + "profile_id": "sp_01F0VY2QRT5C25T0QHSD8EEKA4", "profile": { - "id": "sp_01F0BGFTVGXRBATSDBZN5SK2JP", + "id": "sp_01F0VY2QRT5C25T0QHSD8EEKA4", "name": "Default Shipping Profile", "type": "default", - "created_at": "2021-03-09T12:48:18.240Z", - "updated_at": "2021-03-09T12:48:18.240Z", + "created_at": "2021-03-15T21:53:40.068Z", + "updated_at": "2021-03-15T21:53:40.068Z", "deleted_at": null, "metadata": null }, @@ -659,13 +659,13 @@ "is_return": false, "requirements": [], "data": {}, - "created_at": "2021-03-09T12:48:18.354Z", - "updated_at": "2021-03-09T12:48:18.354Z", + "created_at": "2021-03-15T21:53:40.185Z", + "updated_at": "2021-03-15T21:53:40.185Z", "deleted_at": null, "metadata": null }, "region": { - "id": "reg_01F0BGFTW7J0DGWKJJP3X7AWP9", + "id": "reg_01F0VY2QSCPG4F8KC9RN2R439T", "name": "Test Region", "currency_code": "usd", "tax_rate": "0", @@ -677,17 +677,17 @@ "is_installed": true } ], - "created_at": "2021-03-09T12:48:18.311Z", - "updated_at": "2021-03-09T12:48:18.311Z", + "created_at": "2021-03-15T21:53:40.140Z", + "updated_at": "2021-03-15T21:53:40.140Z", "deleted_at": null, "metadata": null }, "return": { - "id": "ret_01F0BGFGGVWNV93E789K1DB2QK", + "id": "ret_01F0VY2BN9RSJC6GTJRG3C03X6", "status": "requested", "items": [ { - "return_id": "ret_01F0BGFGGVWNV93E789K1DB2QK", + "return_id": "ret_01F0VY2BN9RSJC6GTJRG3C03X6", "item_id": "test-item", "quantity": 1, "is_requested": true, @@ -698,38 +698,204 @@ ], "swap_id": null, "claim_order_id": null, - "order_id": "order_01F0BGFGBMCTXE6CD7KCTZG5D1", + "order_id": "order_01F0VY2BGM5TWR3PNX28SVD0MS", "shipping_method": null, "shipping_data": null, "refund_amount": 7200, "received_at": null, - "created_at": "2021-03-09T12:48:07.680Z", - "updated_at": "2021-03-09T12:48:07.680Z", + "created_at": "2021-03-15T21:53:27.696Z", + "updated_at": "2021-03-15T21:53:27.696Z", "metadata": null, - "idempotency_key": "abb55222-1d22-4852-9714-9b63baec3633" + "idempotency_key": "5992adb7-b4f9-440c-a8c2-147966807d9a" }, "notification": { - "id": "noti_01F0BGFKZ7P3NC5V1PG10S75N0", + "id": "noti_01F0VY31P10A09S6JTJM2GYV7V", "resource_type": "order", "resource_id": "order_01F0BF66ZBXNJ98WDQ9SCWH8Y7", "event_name": "order.placed", "to": "test@email.com", "provider_id": "test-not", - "created_at": "2021-03-09T12:48:11.238Z", - "updated_at": "2021-03-09T12:48:11.238Z", + "created_at": "2021-03-15T21:53:50.273Z", + "updated_at": "2021-03-15T21:53:50.273Z", "resends": [] }, "discount_rule": { - "id": "dru_01F0BGG1B3BCZ292BSRRK72JGS", + "id": "dru_01F0VYCE6R1QV0DFT64EXGGVA2", "description": "10 Percent", "type": "percentage", "value": 10, "allocation": "total", "usage_limit": null, - "created_at": "2021-03-09T12:48:24.921Z", - "updated_at": "2021-03-09T12:48:24.921Z", + "created_at": "2021-03-15T21:58:57.998Z", + "updated_at": "2021-03-15T21:58:57.998Z", "deleted_at": null, "metadata": null + }, + "user": { + "id": "admin_user", + "email": "admin@medusa.js", + "first_name": null, + "last_name": null, + "api_token": "test_token", + "created_at": "2021-03-15T21:54:22.223Z", + "updated_at": "2021-03-15T21:54:22.223Z", + "deleted_at": null, + "metadata": null + }, + "shipping_profile": { + "id": "sp_01F0VY3GHMP2QKQJDF12ZVNQ71", + "name": "Default Shipping Profile", + "type": "default", + "created_at": "2021-03-15T21:54:05.417Z", + "updated_at": "2021-03-15T21:54:05.417Z", + "deleted_at": null, + "metadata": null + }, + "store": { + "id": "store_01F0VYDX7S2T0KPWYG3VN018AZ", + "name": "Medusa Store", + "default_currency_code": "usd", + "default_currency": { + "code": "usd", + "symbol": "$", + "symbol_native": "$", + "name": "US Dollar" + }, + "currencies": [], + "swap_link_template": null, + "created_at": "2021-03-15T21:59:46.161Z", + "updated_at": "2021-03-15T21:59:46.161Z", + "metadata": null, + "payment_providers": [ + { + "id": "test-pay", + "is_installed": true + } + ], + "fulfillment_providers": [ + { + "id": "test-ful", + "is_installed": true + } + ] + }, + "swap": { + "id": "swap_01F0WX73K6ED141YQX65J55D73", + "fulfillment_status": "not_fulfilled", + "payment_status": "not_paid", + "order_id": "order_01F0WX73B3WFZ24157M3AZR369", + "additional_items": [ + { + "id": "item_01F0WX73K6Q7YSB929EPFR39E9", + "cart_id": "cart_01F0WX73ND08RYPZA1J91XTWV5", + "order_id": null, + "swap_id": "swap_01F0WX73K6ED141YQX65J55D73", + "claim_order_id": null, + "title": "test product", + "description": "test variant", + "thumbnail": null, + "is_giftcard": false, + "should_merge": true, + "allow_discounts": true, + "has_shipping": null, + "unit_price": 8000, + "variant_id": "variant_01F0WX739Y6BQZG8Y9PCK5XPRA", + "variant": { + "id": "variant_01F0WX739Y6BQZG8Y9PCK5XPRA", + "title": "test variant", + "product_id": "prod_01F0WX739NEKR6PK8XP0YD5FY8", + "product": { + "id": "prod_01F0WX739NEKR6PK8XP0YD5FY8", + "title": "test product", + "subtitle": null, + "description": null, + "handle": "test-product", + "is_giftcard": false, + "thumbnail": null, + "profile_id": "sp_01F0WX738N6YJ9KGK31YBPDHFK", + "weight": null, + "length": null, + "height": null, + "width": null, + "hs_code": null, + "origin_country": null, + "mid_code": null, + "material": null, + "collection_id": null, + "type_id": null, + "created_at": "2021-03-16T06:57:48.853Z", + "updated_at": "2021-03-16T06:57:48.853Z", + "deleted_at": null, + "metadata": null + }, + "sku": null, + "barcode": null, + "ean": null, + "upc": null, + "inventory_quantity": 1, + "allow_backorder": false, + "manage_inventory": true, + "hs_code": null, + "origin_country": null, + "mid_code": null, + "material": null, + "weight": null, + "length": null, + "height": null, + "width": null, + "created_at": "2021-03-16T06:57:48.862Z", + "updated_at": "2021-03-16T06:57:48.862Z", + "deleted_at": null, + "metadata": null + }, + "quantity": 2, + "fulfilled_quantity": null, + "returned_quantity": null, + "shipped_quantity": null, + "created_at": "2021-03-16T06:57:49.106Z", + "updated_at": "2021-03-16T06:57:49.106Z", + "metadata": {} + } + ], + "return_order": { + "id": "ret_01F0WX73KBV2QAJPYZAGPDADVW", + "status": "requested", + "items": [ + { + "return_id": "ret_01F0WX73KBV2QAJPYZAGPDADVW", + "item_id": "test-item", + "quantity": 1, + "is_requested": true, + "requested_quantity": 1, + "received_quantity": null, + "metadata": null + } + ], + "swap_id": "swap_01F0WX73K6ED141YQX65J55D73", + "claim_order_id": null, + "order_id": null, + "shipping_method": null, + "shipping_data": null, + "refund_amount": 7200, + "received_at": null, + "created_at": "2021-03-16T06:57:49.106Z", + "updated_at": "2021-03-16T06:57:49.106Z", + "metadata": null, + "idempotency_key": null + }, + "fulfillments": [], + "payment": null, + "difference_due": null, + "shipping_address_id": null, + "shipping_address": null, + "shipping_methods": [], + "cart_id": "cart_01F0WX73ND08RYPZA1J91XTWV5", + "confirmed_at": null, + "created_at": "2021-03-16T06:57:49.106Z", + "updated_at": "2021-03-16T06:57:49.106Z", + "deleted_at": null, + "metadata": null, + "idempotency_key": "360a87af-2ff7-4326-b557-042aa2ae331d" } } } \ No newline at end of file diff --git a/docs/api/store-spec3.json b/docs/api/store-spec3.json index 28e3e02a74..d0d0ab3cdc 100644 --- a/docs/api/store-spec3.json +++ b/docs/api/store-spec3.json @@ -75,635 +75,6 @@ } ], "paths": { - "/auth": { - "post": { - "operationId": "PostAuth", - "summary": "Authenticate Customer", - "description": "Logs a Customer in and authorizes them to view their details. Successful authentication will set a session cookie in the Customer's browser.", - "parameters": [], - "tags": [ - "Auth" - ], - "responses": { - "200": { - "description": "OK", - "content": { - "application/json": { - "schema": { - "properties": { - "customer": { - "$ref": "#/components/schemas/customer" - } - } - } - } - } - } - }, - "requestBody": { - "content": { - "application/json": { - "schema": { - "type": "object", - "required": [ - "email", - "password" - ], - "properties": { - "email": { - "type": "string", - "description": "The Customer's email." - }, - "password": { - "type": "string", - "description": "The Customer's password." - } - } - } - } - } - } - }, - "delete": { - "operationId": "DeleteAuth", - "summary": "Log out", - "description": "Destroys a Customer's authenticated session.", - "tags": [ - "Auth" - ], - "responses": { - "200": { - "description": "OK" - } - } - }, - "get": { - "operationId": "GetAuth", - "summary": "Get Session", - "description": "Gets the currently logged in Customer.", - "tags": [ - "Auth" - ], - "responses": { - "200": { - "description": "OK", - "content": { - "application/json": { - "schema": { - "properties": { - "customer": { - "$ref": "#/components/schemas/customer" - } - } - } - } - } - } - } - } - }, - "/auth/{email}": { - "get": { - "operationId": "GetAuthEmail", - "summary": "Check if email has account", - "description": "Checks if a Customer with the given email has signed up.", - "parameters": [ - { - "in": "path", - "name": "email", - "required": true, - "description": "The Customer's email.", - "schema": { - "type": "string" - } - } - ], - "tags": [ - "Auth" - ], - "responses": { - "200": { - "description": "OK", - "content": { - "application/json": { - "schema": { - "properties": { - "exists": { - "type": "boolean" - } - } - } - } - } - } - } - } - }, - "/customers/{id}/addresses": { - "post": { - "operationId": "PostCustomersCustomerAddresses", - "summary": "Add a Shipping Address", - "description": "Adds a Shipping Address to a Customer's saved addresses.", - "parameters": [ - { - "in": "path", - "name": "id", - "required": true, - "description": "The Customer id.", - "schema": { - "type": "string" - } - } - ], - "requestBody": { - "content": { - "application/json": { - "schema": { - "properties": { - "address": { - "description": "The Address to add to the Customer.", - "anyOf": [ - { - "$ref": "#/components/schemas/address" - } - ] - } - } - } - } - } - }, - "tags": [ - "Customer" - ], - "responses": { - "200": { - "description": "A successful response", - "content": { - "application/json": { - "schema": { - "properties": { - "customer": { - "$ref": "#/components/schemas/customer" - } - } - } - } - } - } - } - } - }, - "/customers": { - "post": { - "operationId": "PostCustomers", - "summary": "Create a Customer", - "description": "Creates a Customer account.", - "parameters": [], - "tags": [ - "Customer" - ], - "responses": { - "200": { - "description": "OK", - "content": { - "application/json": { - "schema": { - "properties": { - "customer": { - "$ref": "#/components/schemas/customer" - } - } - } - } - } - } - }, - "requestBody": { - "content": { - "application/json": { - "schema": { - "type": "object", - "required": [ - "email", - "first_name", - "last_name", - "password" - ], - "properties": { - "email": { - "type": "string", - "description": "The Customer's email address." - }, - "first_name": { - "type": "string", - "description": "The Customer's first name." - }, - "last_name": { - "type": "string", - "description": "The Customer's last name." - }, - "password": { - "type": "string", - "description": "The Customer's password for login." - }, - "phone": { - "type": "string", - "description": "The Customer's phone number." - } - } - } - } - } - } - } - }, - "/customers/{id}/addresses/{address_id}": { - "delete": { - "operationId": "DeleteCustomersCustomerAddressesAddress", - "summary": "Delete an Address", - "description": "Removes an Address from the Customer's saved addresse.", - "parameters": [ - { - "in": "path", - "name": "id", - "required": true, - "description": "The id of the Customer.", - "schema": { - "type": "string" - } - }, - { - "in": "path", - "name": "address_id", - "required": true, - "description": "The id of the Address to remove.", - "schema": { - "type": "string" - } - } - ], - "tags": [ - "Customer" - ], - "responses": { - "200": { - "description": "OK", - "content": { - "application/json": { - "schema": { - "properties": { - "customer": { - "$ref": "#/components/schemas/customer" - } - } - } - } - } - } - } - }, - "post": { - "operationId": "PostCustomersCustomerAddressesAddress", - "summary": "Update a Shipping Address", - "description": "Updates a Customer's saved Shipping Address.", - "parameters": [ - { - "in": "path", - "name": "id", - "required": true, - "description": "The Customer id.", - "schema": { - "type": "string" - } - }, - { - "in": "path", - "name": "address_id", - "required": true, - "description": "The id of the Address to update.", - "schema": { - "type": "string" - } - } - ], - "requestBody": { - "content": { - "application/json": { - "schema": { - "properties": { - "address": { - "description": "The updated Address.", - "anyOf": [ - { - "$ref": "#/components/schemas/address" - } - ] - } - } - } - } - } - }, - "tags": [ - "Customer" - ], - "responses": { - "200": { - "description": "OK", - "content": { - "application/json": { - "schema": { - "properties": { - "customer": { - "$ref": "#/components/schemas/customer" - } - } - } - } - } - } - } - } - }, - "/customers/{id}": { - "get": { - "operationId": "GetCustomersCustomer", - "summary": "Retrieves a Customer", - "description": "Retrieves a Customer - the Customer must be logged in to retrieve their details.", - "parameters": [ - { - "in": "path", - "name": "id", - "required": true, - "description": "The id of the Customer.", - "schema": { - "type": "string" - } - } - ], - "tags": [ - "Customer" - ], - "responses": { - "200": { - "description": "OK", - "content": { - "application/json": { - "schema": { - "properties": { - "customer": { - "$ref": "#/components/schemas/customer" - } - } - } - } - } - } - } - }, - "post": { - "operationId": "PostCustomersCustomer", - "summary": "Update Customer details", - "description": "Updates a Customer's saved details.", - "parameters": [ - { - "in": "path", - "name": "id", - "required": true, - "description": "The id of the Customer.", - "schema": { - "type": "string" - } - } - ], - "requestBody": { - "content": { - "application/json": { - "schema": { - "properties": { - "first_name": { - "description": "The Customer's first name.", - "type": "string" - }, - "last_name": { - "description": "The Customer's last name.", - "type": "string" - }, - "password": { - "description": "The Customer's password.", - "type": "string" - }, - "phone": { - "description": "The Customer's phone number.", - "type": "string" - } - } - } - } - } - }, - "tags": [ - "Customer" - ], - "responses": { - "200": { - "description": "OK", - "content": { - "application/json": { - "schema": { - "properties": { - "customer": { - "$ref": "#/components/schemas/customer" - } - } - } - } - } - } - } - } - }, - "/customers/{id}/payment-methods": { - "get": { - "operationId": "GetCustomersCustomerPaymentMethods", - "summary": "Retrieve saved payment methods", - "description": "Retrieves a list of a Customer's saved payment methods. Payment methods are saved with Payment Providers and it is their responsibility to fetch saved methods.", - "parameters": [ - { - "in": "path", - "name": "id", - "required": true, - "description": "The id of the Customer.", - "schema": { - "type": "string" - } - } - ], - "tags": [ - "Customer" - ], - "responses": { - "200": { - "description": "OK", - "content": { - "application/json": { - "schema": { - "properties": { - "payment_methods": { - "type": "array", - "items": { - "properties": { - "provider_id": { - "type": "string", - "description": "The id of the Payment Provider where the payment method is saved." - }, - "data": { - "type": "object", - "description": "The data needed for the Payment Provider to use the saved payment method." - } - } - } - } - } - } - } - } - } - } - } - }, - "/customers/{id}/orders": { - "get": { - "operationId": "GetCustomersCustomerOrders", - "summary": "Retrieve Customer Orders", - "description": "Retrieves a list of a Customer's Orders.", - "parameters": [ - { - "in": "path", - "name": "id", - "required": true, - "description": "The id of the Customer.", - "schema": { - "type": "string" - } - } - ], - "tags": [ - "Customer" - ], - "responses": { - "200": { - "description": "OK", - "content": { - "application/json": { - "schema": { - "properties": { - "payment_methods": { - "type": "array", - "items": { - "$ref": "#/components/schemas/order" - } - } - } - } - } - } - } - } - } - }, - "/customers/{id}/password-token": { - "post": { - "operationId": "PostCustomersCustomerPasswordToken", - "summary": "Creates a reset password token", - "description": "Creates a reset password token to be used in a subsequent /reset-password request. The password token should be sent out of band e.g. via email and will not be returned.", - "parameters": [ - { - "in": "path", - "name": "id", - "required": true, - "description": "The id of the Customer.", - "schema": { - "type": "string" - } - } - ], - "tags": [ - "Customer" - ], - "responses": { - "204": { - "description": "OK" - } - } - } - }, - "/customers/{id}/reset-password": { - "post": { - "operationId": "PostCustomersCustomerResetPassword", - "summary": "Resets Customer password", - "description": "Resets a Customer's password using a password token created by a previous /password-token request.", - "parameters": [ - { - "in": "path", - "name": "id", - "required": true, - "description": "The id of the Customer.", - "schema": { - "type": "string" - } - } - ], - "tags": [ - "Customer" - ], - "responses": { - "200": { - "description": "OK", - "content": { - "application/json": { - "schema": { - "properties": { - "customer": { - "$ref": "#/components/schemas/customer" - } - } - } - } - } - } - }, - "requestBody": { - "content": { - "application/json": { - "schema": { - "type": "object", - "required": [ - "email", - "token", - "password" - ], - "properties": { - "email": { - "type": "string", - "description": "The Customer's email." - }, - "token": { - "type": "string", - "description": "The password token created by a /password-token request." - }, - "password": { - "type": "string", - "description": "The new password to set for the Customer." - } - } - } - } - } - } - } - }, "/carts/{id}/shipping-methods": { "post": { "operationId": "PostCartsCartShippingMethod", @@ -1473,6 +844,635 @@ } } }, + "/customers/{id}/addresses": { + "post": { + "operationId": "PostCustomersCustomerAddresses", + "summary": "Add a Shipping Address", + "description": "Adds a Shipping Address to a Customer's saved addresses.", + "parameters": [ + { + "in": "path", + "name": "id", + "required": true, + "description": "The Customer id.", + "schema": { + "type": "string" + } + } + ], + "requestBody": { + "content": { + "application/json": { + "schema": { + "properties": { + "address": { + "description": "The Address to add to the Customer.", + "anyOf": [ + { + "$ref": "#/components/schemas/address" + } + ] + } + } + } + } + } + }, + "tags": [ + "Customer" + ], + "responses": { + "200": { + "description": "A successful response", + "content": { + "application/json": { + "schema": { + "properties": { + "customer": { + "$ref": "#/components/schemas/customer" + } + } + } + } + } + } + } + } + }, + "/customers": { + "post": { + "operationId": "PostCustomers", + "summary": "Create a Customer", + "description": "Creates a Customer account.", + "parameters": [], + "tags": [ + "Customer" + ], + "responses": { + "200": { + "description": "OK", + "content": { + "application/json": { + "schema": { + "properties": { + "customer": { + "$ref": "#/components/schemas/customer" + } + } + } + } + } + } + }, + "requestBody": { + "content": { + "application/json": { + "schema": { + "type": "object", + "required": [ + "email", + "first_name", + "last_name", + "password" + ], + "properties": { + "email": { + "type": "string", + "description": "The Customer's email address." + }, + "first_name": { + "type": "string", + "description": "The Customer's first name." + }, + "last_name": { + "type": "string", + "description": "The Customer's last name." + }, + "password": { + "type": "string", + "description": "The Customer's password for login." + }, + "phone": { + "type": "string", + "description": "The Customer's phone number." + } + } + } + } + } + } + } + }, + "/customers/{id}/addresses/{address_id}": { + "delete": { + "operationId": "DeleteCustomersCustomerAddressesAddress", + "summary": "Delete an Address", + "description": "Removes an Address from the Customer's saved addresse.", + "parameters": [ + { + "in": "path", + "name": "id", + "required": true, + "description": "The id of the Customer.", + "schema": { + "type": "string" + } + }, + { + "in": "path", + "name": "address_id", + "required": true, + "description": "The id of the Address to remove.", + "schema": { + "type": "string" + } + } + ], + "tags": [ + "Customer" + ], + "responses": { + "200": { + "description": "OK", + "content": { + "application/json": { + "schema": { + "properties": { + "customer": { + "$ref": "#/components/schemas/customer" + } + } + } + } + } + } + } + }, + "post": { + "operationId": "PostCustomersCustomerAddressesAddress", + "summary": "Update a Shipping Address", + "description": "Updates a Customer's saved Shipping Address.", + "parameters": [ + { + "in": "path", + "name": "id", + "required": true, + "description": "The Customer id.", + "schema": { + "type": "string" + } + }, + { + "in": "path", + "name": "address_id", + "required": true, + "description": "The id of the Address to update.", + "schema": { + "type": "string" + } + } + ], + "requestBody": { + "content": { + "application/json": { + "schema": { + "properties": { + "address": { + "description": "The updated Address.", + "anyOf": [ + { + "$ref": "#/components/schemas/address" + } + ] + } + } + } + } + } + }, + "tags": [ + "Customer" + ], + "responses": { + "200": { + "description": "OK", + "content": { + "application/json": { + "schema": { + "properties": { + "customer": { + "$ref": "#/components/schemas/customer" + } + } + } + } + } + } + } + } + }, + "/customers/{id}": { + "get": { + "operationId": "GetCustomersCustomer", + "summary": "Retrieves a Customer", + "description": "Retrieves a Customer - the Customer must be logged in to retrieve their details.", + "parameters": [ + { + "in": "path", + "name": "id", + "required": true, + "description": "The id of the Customer.", + "schema": { + "type": "string" + } + } + ], + "tags": [ + "Customer" + ], + "responses": { + "200": { + "description": "OK", + "content": { + "application/json": { + "schema": { + "properties": { + "customer": { + "$ref": "#/components/schemas/customer" + } + } + } + } + } + } + } + }, + "post": { + "operationId": "PostCustomersCustomer", + "summary": "Update Customer details", + "description": "Updates a Customer's saved details.", + "parameters": [ + { + "in": "path", + "name": "id", + "required": true, + "description": "The id of the Customer.", + "schema": { + "type": "string" + } + } + ], + "requestBody": { + "content": { + "application/json": { + "schema": { + "properties": { + "first_name": { + "description": "The Customer's first name.", + "type": "string" + }, + "last_name": { + "description": "The Customer's last name.", + "type": "string" + }, + "password": { + "description": "The Customer's password.", + "type": "string" + }, + "phone": { + "description": "The Customer's phone number.", + "type": "string" + } + } + } + } + } + }, + "tags": [ + "Customer" + ], + "responses": { + "200": { + "description": "OK", + "content": { + "application/json": { + "schema": { + "properties": { + "customer": { + "$ref": "#/components/schemas/customer" + } + } + } + } + } + } + } + } + }, + "/customers/{id}/payment-methods": { + "get": { + "operationId": "GetCustomersCustomerPaymentMethods", + "summary": "Retrieve saved payment methods", + "description": "Retrieves a list of a Customer's saved payment methods. Payment methods are saved with Payment Providers and it is their responsibility to fetch saved methods.", + "parameters": [ + { + "in": "path", + "name": "id", + "required": true, + "description": "The id of the Customer.", + "schema": { + "type": "string" + } + } + ], + "tags": [ + "Customer" + ], + "responses": { + "200": { + "description": "OK", + "content": { + "application/json": { + "schema": { + "properties": { + "payment_methods": { + "type": "array", + "items": { + "properties": { + "provider_id": { + "type": "string", + "description": "The id of the Payment Provider where the payment method is saved." + }, + "data": { + "type": "object", + "description": "The data needed for the Payment Provider to use the saved payment method." + } + } + } + } + } + } + } + } + } + } + } + }, + "/customers/{id}/orders": { + "get": { + "operationId": "GetCustomersCustomerOrders", + "summary": "Retrieve Customer Orders", + "description": "Retrieves a list of a Customer's Orders.", + "parameters": [ + { + "in": "path", + "name": "id", + "required": true, + "description": "The id of the Customer.", + "schema": { + "type": "string" + } + } + ], + "tags": [ + "Customer" + ], + "responses": { + "200": { + "description": "OK", + "content": { + "application/json": { + "schema": { + "properties": { + "payment_methods": { + "type": "array", + "items": { + "$ref": "#/components/schemas/order" + } + } + } + } + } + } + } + } + } + }, + "/customers/{id}/password-token": { + "post": { + "operationId": "PostCustomersCustomerPasswordToken", + "summary": "Creates a reset password token", + "description": "Creates a reset password token to be used in a subsequent /reset-password request. The password token should be sent out of band e.g. via email and will not be returned.", + "parameters": [ + { + "in": "path", + "name": "id", + "required": true, + "description": "The id of the Customer.", + "schema": { + "type": "string" + } + } + ], + "tags": [ + "Customer" + ], + "responses": { + "204": { + "description": "OK" + } + } + } + }, + "/customers/{id}/reset-password": { + "post": { + "operationId": "PostCustomersCustomerResetPassword", + "summary": "Resets Customer password", + "description": "Resets a Customer's password using a password token created by a previous /password-token request.", + "parameters": [ + { + "in": "path", + "name": "id", + "required": true, + "description": "The id of the Customer.", + "schema": { + "type": "string" + } + } + ], + "tags": [ + "Customer" + ], + "responses": { + "200": { + "description": "OK", + "content": { + "application/json": { + "schema": { + "properties": { + "customer": { + "$ref": "#/components/schemas/customer" + } + } + } + } + } + } + }, + "requestBody": { + "content": { + "application/json": { + "schema": { + "type": "object", + "required": [ + "email", + "token", + "password" + ], + "properties": { + "email": { + "type": "string", + "description": "The Customer's email." + }, + "token": { + "type": "string", + "description": "The password token created by a /password-token request." + }, + "password": { + "type": "string", + "description": "The new password to set for the Customer." + } + } + } + } + } + } + } + }, + "/auth": { + "post": { + "operationId": "PostAuth", + "summary": "Authenticate Customer", + "description": "Logs a Customer in and authorizes them to view their details. Successful authentication will set a session cookie in the Customer's browser.", + "parameters": [], + "tags": [ + "Auth" + ], + "responses": { + "200": { + "description": "OK", + "content": { + "application/json": { + "schema": { + "properties": { + "customer": { + "$ref": "#/components/schemas/customer" + } + } + } + } + } + } + }, + "requestBody": { + "content": { + "application/json": { + "schema": { + "type": "object", + "required": [ + "email", + "password" + ], + "properties": { + "email": { + "type": "string", + "description": "The Customer's email." + }, + "password": { + "type": "string", + "description": "The Customer's password." + } + } + } + } + } + } + }, + "delete": { + "operationId": "DeleteAuth", + "summary": "Log out", + "description": "Destroys a Customer's authenticated session.", + "tags": [ + "Auth" + ], + "responses": { + "200": { + "description": "OK" + } + } + }, + "get": { + "operationId": "GetAuth", + "summary": "Get Session", + "description": "Gets the currently logged in Customer.", + "tags": [ + "Auth" + ], + "responses": { + "200": { + "description": "OK", + "content": { + "application/json": { + "schema": { + "properties": { + "customer": { + "$ref": "#/components/schemas/customer" + } + } + } + } + } + } + } + } + }, + "/auth/{email}": { + "get": { + "operationId": "GetAuthEmail", + "summary": "Check if email has account", + "description": "Checks if a Customer with the given email has signed up.", + "parameters": [ + { + "in": "path", + "name": "email", + "required": true, + "description": "The Customer's email.", + "schema": { + "type": "string" + } + } + ], + "tags": [ + "Auth" + ], + "responses": { + "200": { + "description": "OK", + "content": { + "application/json": { + "schema": { + "properties": { + "exists": { + "type": "boolean" + } + } + } + } + } + } + } + } + }, "/orders/cart/{cart_id}": { "get": { "operationId": "GetOrdersOrderCartId", @@ -1547,84 +1547,6 @@ } } }, - "/products/{id}": { - "get": { - "operationId": "GetProductsProduct", - "summary": "Retrieves a Product", - "description": "Retrieves a Product.", - "parameters": [ - { - "in": "path", - "name": "id", - "required": true, - "description": "The id of the Product.", - "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": { - "$ref": "#/components/schemas/product" - } - } - } - } - } - } - } - } - } - }, "/regions/{id}": { "get": { "operationId": "GetRegionsRegion", @@ -1703,6 +1625,43 @@ } } }, + "/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" + } + } + } + } + } + } + } + } + }, "/shipping-options": { "get": { "operationId": "GetShippingOptions", @@ -1790,24 +1749,24 @@ } } }, - "/swaps/{cart_id}": { + "/products/{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.", + "operationId": "GetProductsProduct", + "summary": "Retrieves a Product", + "description": "Retrieves a Product.", "parameters": [ { "in": "path", - "name": "cart_id", + "name": "id", "required": true, - "description": "The id of the Cart", + "description": "The id of the Product.", "schema": { "type": "string" } } ], "tags": [ - "Swap" + "Product" ], "responses": { "200": { @@ -1816,8 +1775,49 @@ "application/json": { "schema": { "properties": { - "swap": { - "$ref": "#/components/schemas/swap" + "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": { + "$ref": "#/components/schemas/product" + } } } } diff --git a/docs/api/store-spec3.yaml b/docs/api/store-spec3.yaml index 0998688653..1b44536dbe 100644 --- a/docs/api/store-spec3.yaml +++ b/docs/api/store-spec3.yaml @@ -1025,56 +1025,6 @@ paths: properties: customer: $ref: '#/components/schemas/customer' - '/products/{id}': - get: - operationId: GetProductsProduct - summary: Retrieves a Product - description: Retrieves a Product. - parameters: - - in: path - name: id - required: true - description: The id of the Product. - 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: - $ref: '#/components/schemas/product' '/regions/{id}': get: operationId: GetRegionsRegion @@ -1125,49 +1075,20 @@ paths: type: array items: $ref: '#/components/schemas/region' - /shipping-options: + '/products/{id}': 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: - type: string - tags: - - Shipping Option - responses: - '200': - description: OK - content: - application/json: - schema: - properties: - shipping_options: - type: array - items: - $ref: '#/components/schemas/shipping_option' - '/shipping-options/{cart_id}': - get: - operationId: GetShippingOptionsCartId - summary: Retrieve Shipping Options for Cart - description: Retrieves a list of Shipping Options available to a cart. + operationId: GetProductsProduct + summary: Retrieves a Product + description: Retrieves a Product. parameters: - in: path - name: cart_id + name: id required: true - description: The id of the Cart. + description: The id of the Product. schema: type: string tags: - - Shipping Option + - Product responses: '200': description: OK @@ -1175,10 +1096,35 @@ paths: application/json: schema: properties: - shipping_options: + 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: - $ref: '#/components/schemas/shipping_option' + $ref: '#/components/schemas/product' '/swaps/{cart_id}': get: operationId: GetSwapsSwapCartId @@ -1249,6 +1195,60 @@ paths: 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: + type: string + tags: + - Shipping Option + responses: + '200': + description: OK + content: + application/json: + schema: + properties: + shipping_options: + type: array + items: + $ref: '#/components/schemas/shipping_option' + '/shipping-options/{cart_id}': + get: + operationId: GetShippingOptionsCartId + summary: Retrieve Shipping Options for Cart + description: Retrieves a list of Shipping Options available to a cart. + parameters: + - in: path + name: cart_id + required: true + description: The id of the Cart. + schema: + type: string + tags: + - Shipping Option + responses: + '200': + description: OK + content: + application/json: + schema: + properties: + shipping_options: + type: array + items: + $ref: '#/components/schemas/shipping_option' components: schemas: address: diff --git a/package.json b/package.json index 2ef0a9fa86..21de065b3c 100644 --- a/package.json +++ b/package.json @@ -35,6 +35,7 @@ "test:fixtures": "jest --config=docs-util/jest.config.js --runInBand" }, "dependencies": { + "import-from": "^3.0.0", "oas-normalize": "^2.3.1", "swagger-inline": "^3.2.2" } diff --git a/packages/medusa/jest.config.js b/packages/medusa/jest.config.js deleted file mode 100644 index 82513aa071..0000000000 --- a/packages/medusa/jest.config.js +++ /dev/null @@ -1,3 +0,0 @@ -module.exports = { - testEnvironment: "node", -} diff --git a/packages/medusa/src/api/routes/admin/auth/create-session.js b/packages/medusa/src/api/routes/admin/auth/create-session.js index 2643974152..7cb77ced09 100644 --- a/packages/medusa/src/api/routes/admin/auth/create-session.js +++ b/packages/medusa/src/api/routes/admin/auth/create-session.js @@ -1,3 +1,4 @@ +import _ from "lodash" import jwt from "jsonwebtoken" import { Validator } from "medusa-core-utils" import config from "../../../../config" @@ -19,7 +20,7 @@ import config from "../../../../config" * application/json: * schema: * properties: - * customer: + * user: * $ref: "#/components/schemas/user" */ export default async (req, res) => { @@ -46,5 +47,7 @@ export default async (req, res) => { expiresIn: "24h", }) - res.json({ user: result.user }) + const cleanRes = _.omit(result.user, ["password_hash"]) + + res.json({ user: cleanRes }) } diff --git a/packages/medusa/src/api/routes/admin/auth/get-session.js b/packages/medusa/src/api/routes/admin/auth/get-session.js index 59bdc5fa61..b4073059d9 100644 --- a/packages/medusa/src/api/routes/admin/auth/get-session.js +++ b/packages/medusa/src/api/routes/admin/auth/get-session.js @@ -1,4 +1,4 @@ -import passport from "passport" +import _ from "lodash" /** * @oas [get] /auth @@ -14,11 +14,13 @@ import passport from "passport" * application/json: * schema: * properties: - * customer: + * user: * $ref: "#/components/schemas/user" */ export default async (req, res) => { const userService = req.scope.resolve("userService") 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 }) } diff --git a/packages/medusa/src/api/routes/admin/orders/create-swap.js b/packages/medusa/src/api/routes/admin/orders/create-swap.js index 4b78d0ca09..120b2419cb 100644 --- a/packages/medusa/src/api/routes/admin/orders/create-swap.js +++ b/packages/medusa/src/api/routes/admin/orders/create-swap.js @@ -7,7 +7,7 @@ import { defaultFields, defaultRelations } from "./" * summary: "Create a Swap" * description: "Creates a Swap. Swaps are used to handle Return of previously purchased goods and Fulfillment of replacements simultaneously." * parameters: - * - (path) id=* {string} The id of the Swap. + * - (path) id=* {string} The id of the Order. * requestBody: * content: * application/json: diff --git a/packages/medusa/src/api/routes/admin/orders/list-orders.js b/packages/medusa/src/api/routes/admin/orders/list-orders.js index 88512dad55..bb8deab1df 100644 --- a/packages/medusa/src/api/routes/admin/orders/list-orders.js +++ b/packages/medusa/src/api/routes/admin/orders/list-orders.js @@ -5,7 +5,7 @@ import { defaultRelations, defaultFields } from "./" * @oas [get] /orders * operationId: "GetOrders" * summary: "List Orders" - * description: "Retrieves an list of Orders" + * description: "Retrieves a list of Orders" * tags: * - Order * responses: @@ -15,8 +15,10 @@ import { defaultRelations, defaultFields } from "./" * application/json: * schema: * properties: - * order: - * $ref: "#/components/schemas/order" + * orders: + * type: array + * items: + * $ref: "#/components/schemas/order" */ export default async (req, res) => { diff --git a/www/LICENSE b/www/LICENSE index 7e964c1ee5..8ad47e209d 100644 --- a/www/LICENSE +++ b/www/LICENSE @@ -1,6 +1,6 @@ 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 purpose with or without fee is hereby granted. diff --git a/www/src/components/json-box.js b/www/src/components/json-box.js index 6823f02536..30f43fce68 100644 --- a/www/src/components/json-box.js +++ b/www/src/components/json-box.js @@ -49,8 +49,19 @@ const JsonBox = ({ text, resourceId, endpoint, spec }) => { cleanDets["x-resourceId"] in fixtures.resources ) { toSet[name] = fixtures.resources[cleanDets["x-resourceId"]] - } else { + } else if (cleanDets.type === "array") { 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] + } } } } diff --git a/yarn.lock b/yarn.lock index b7a5130a6a..e7bc522721 100644 --- a/yarn.lock +++ b/yarn.lock @@ -5392,6 +5392,13 @@ import-fresh@^2.0.0: caller-path "^2.0.0" resolve-from "^3.0.0" +import-from@^3.0.0: + version "3.0.0" + resolved "https://registry.yarnpkg.com/import-from/-/import-from-3.0.0.tgz#055cfec38cd5a27d8057ca51376d7d3bf0891966" + integrity sha512-CiuXOFFSzkU5x/CR0+z7T91Iht4CXgfCxVOFRhh2Zyhg5wOpWvvDLQUsWl+gcN+QscYBjez8hDCt85O7RLDttQ== + dependencies: + resolve-from "^5.0.0" + import-local@^2.0.0: version "2.0.0" resolved "https://registry.yarnpkg.com/import-local/-/import-local-2.0.0.tgz#55070be38a5993cf18ef6db7e961f5bee5c5a09d" From 227cdb622234126df6087992203ce82ff9446974 Mon Sep 17 00:00:00 2001 From: Sebastian Rindom Date: Wed, 17 Mar 2021 08:34:38 +0100 Subject: [PATCH 6/6] fix: contentful sync (#206) --- .../medusa-plugin-contentful/package.json | 4 +- .../src/loaders/check-types.js | 1 + .../src/services/contentful.js | 197 +++++++++++------- .../src/services/__tests__/product-variant.js | 9 +- .../medusa/src/services/product-variant.js | 5 +- packages/medusa/src/services/product.js | 1 + 6 files changed, 133 insertions(+), 84 deletions(-) diff --git a/packages/medusa-plugin-contentful/package.json b/packages/medusa-plugin-contentful/package.json index 0a093930de..ff6a5a79eb 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.4", + "version": "1.1.4-alpha.7+739b7b3c", "description": "Contentful plugin for Medusa Commerce", "main": "index.js", "repository": { @@ -43,5 +43,5 @@ "medusa-test-utils": "^1.1.3", "redis": "^3.0.2" }, - "gitHead": "0646bd395a6056657cb0aa93c13699c4a9dbbcdd" + "gitHead": "739b7b3cc5ff31aa7a15637db2000e645c7597b1" } diff --git a/packages/medusa-plugin-contentful/src/loaders/check-types.js b/packages/medusa-plugin-contentful/src/loaders/check-types.js index 9c224621dd..de3281a388 100644 --- a/packages/medusa-plugin-contentful/src/loaders/check-types.js +++ b/packages/medusa-plugin-contentful/src/loaders/check-types.js @@ -11,6 +11,7 @@ const checkContentTypes = async (container) => { if (!product) { throw Error("Content type: `product` is missing in Contentful") } + if (!variant) { throw Error("Content type: `productVariant` is missing in Contentful") } diff --git a/packages/medusa-plugin-contentful/src/services/contentful.js b/packages/medusa-plugin-contentful/src/services/contentful.js index b0ec7ce842..da5e3bc765 100644 --- a/packages/medusa-plugin-contentful/src/services/contentful.js +++ b/packages/medusa-plugin-contentful/src/services/contentful.js @@ -96,13 +96,15 @@ class ContentfulService extends BaseService { }, }) - await asset.processForAllLocales() + const finalAsset = await asset + .processForAllLocales() + .then((ast) => ast.publish()) assets.push({ sys: { type: "Link", linkType: "Asset", - id: asset.sys.id, + id: finalAsset.sys.id, }, }) }) @@ -231,9 +233,9 @@ class ContentfulService extends BaseService { fields, }) - const ignoreIds = (await this.getIgnoreIds_("product")) || [] - ignoreIds.push(product.id) - this.redis_.set("product_ignore_ids", JSON.stringify(ignoreIds)) + // const ignoreIds = (await this.getIgnoreIds_("product")) || [] + // ignoreIds.push(product.id) + // this.redis_.set("product_ignore_ids", JSON.stringify(ignoreIds)) return result } catch (error) { throw error @@ -271,38 +273,47 @@ class ContentfulService extends BaseService { } ) - const ignoreIds = (await this.getIgnoreIds_("product_variant")) || [] - ignoreIds.push(v.id) - this.redis_.set("product_variant_ignore_ids", JSON.stringify(ignoreIds)) + // const ignoreIds = (await this.getIgnoreIds_("product_variant")) || [] + // ignoreIds.push(v.id) + // this.redis_.set("product_variant_ignore_ids", JSON.stringify(ignoreIds)) return result } catch (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 { - const ignoreIds = (await this.getIgnoreIds_("product")) || [] + // const ignoreIds = (await this.getIgnoreIds_("product")) || [] - if (ignoreIds.includes(product.id)) { - const newIgnoreIds = ignoreIds.filter((id) => id !== product.id) - this.redis_.set("product_ignore_ids", JSON.stringify(newIgnoreIds)) - return - } else { - ignoreIds.push(product.id) - this.redis_.set("product_ignore_ids", JSON.stringify(ignoreIds)) - } + // if (ignoreIds.includes(product.id)) { + // const newIgnoreIds = ignoreIds.filter((id) => id !== product.id) + // this.redis_.set("product_ignore_ids", JSON.stringify(newIgnoreIds)) + // return + // } else { + // ignoreIds.push(product.id) + // this.redis_.set("product_ignore_ids", JSON.stringify(ignoreIds)) + // } - const environment = await this.getContentfulEnvironment_() - // 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, { + const p = await this.productService_.retrieve(data.id, { relations: [ "options", "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 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({ fields: { title: { @@ -344,8 +369,8 @@ class ContentfulService extends BaseService { file: { "en-US": { contentType: "image/xyz", - fileName: p.thumbnail, - upload: p.thumbnail, + fileName: url, + upload: url, }, }, }, @@ -412,20 +437,37 @@ class ContentfulService extends BaseService { } async updateProductVariantInContentful(variant) { - try { - const ignoreIds = (await this.getIgnoreIds_("product_variant")) || [] + const updateFields = [ + "title", + "prices", + "sku", + "material", + "weight", + "length", + "height", + "origin_country", + "options", + ] - if (ignoreIds.includes(variant.id)) { - 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 found = variant.fields.find((f) => updateFields.includes(f)) + if (!found) { + return + } + + try { + // const ignoreIds = (await this.getIgnoreIds_("product_variant")) || [] + + //if (ignoreIds.includes(variant.id)) { + // 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_() // check if product exists @@ -476,19 +518,23 @@ class ContentfulService extends BaseService { const environment = await this.getContentfulEnvironment_() const productEntry = await environment.getEntry(productId) - const ignoreIds = (await this.getIgnoreIds_("product")) || [] - 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)) - } + const product = await this.productService_.retrieve(productId) - let update = { - title: - productEntry.fields[this.getCustomField("title", "product")]["en-US"], + //const ignoreIds = (await this.getIgnoreIds_("product")) || [] + //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 title = + productEntry.fields[this.getCustomField("title", "product")]["en-US"] + if (product.title !== title) { + update.title = title } // Get the thumbnail, if present @@ -497,15 +543,16 @@ class ContentfulService extends BaseService { 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( - productId, - update - ) - - return updatedProduct + if (!_.isEmpty(update)) { + await this.productService_.update(productId, update) + } } catch (error) { throw error } @@ -516,18 +563,18 @@ class ContentfulService extends BaseService { const environment = await this.getContentfulEnvironment_() const variantEntry = await environment.getEntry(variantId) - const ignoreIds = (await this.getIgnoreIds_("product_variant")) || [] - if (ignoreIds.includes(variantId)) { - const newIgnoreIds = ignoreIds.filter((id) => id !== variantId) - this.redis_.set( - "product_variant_ignore_ids", - JSON.stringify(newIgnoreIds) - ) - return - } else { - ignoreIds.push(variantId) - this.redis_.set("product_variant_ignore_ids", JSON.stringify(ignoreIds)) - } + // const ignoreIds = (await this.getIgnoreIds_("product_variant")) || [] + // if (ignoreIds.includes(variantId)) { + // const newIgnoreIds = ignoreIds.filter((id) => id !== variantId) + // this.redis_.set( + // "product_variant_ignore_ids", + // JSON.stringify(newIgnoreIds) + // ) + // return + // } else { + // ignoreIds.push(variantId) + // this.redis_.set("product_variant_ignore_ids", JSON.stringify(ignoreIds)) + // } const updatedVariant = await this.productVariantService_.update( variantId, diff --git a/packages/medusa/src/services/__tests__/product-variant.js b/packages/medusa/src/services/__tests__/product-variant.js index 77aa8f4f87..ec9418ca3e 100644 --- a/packages/medusa/src/services/__tests__/product-variant.js +++ b/packages/medusa/src/services/__tests__/product-variant.js @@ -309,7 +309,7 @@ describe("ProductVariantService", () => { "product-variant.updated", { id: IdMap.getId("ironman"), - title: "new title", + fields: ["title"], } ) @@ -333,7 +333,7 @@ describe("ProductVariantService", () => { "product-variant.updated", { id: IdMap.getId("ironman"), - title: "new title", + fields: ["title"], } ) @@ -370,10 +370,7 @@ describe("ProductVariantService", () => { "product-variant.updated", { id: IdMap.getId("ironman"), - title: "new title", - metadata: { - testing: "this", - }, + fields: ["title", "metadata"], } ) diff --git a/packages/medusa/src/services/product-variant.js b/packages/medusa/src/services/product-variant.js index 7f40d86823..42fca94c47 100644 --- a/packages/medusa/src/services/product-variant.js +++ b/packages/medusa/src/services/product-variant.js @@ -298,7 +298,10 @@ class ProductVariantService extends BaseService { const result = await variantRepo.save(variant) await this.eventBus_ .withTransaction(manager) - .emit(ProductVariantService.Events.UPDATED, result) + .emit(ProductVariantService.Events.UPDATED, { + id: result.id, + fields: Object.keys(update), + }) return result }) } diff --git a/packages/medusa/src/services/product.js b/packages/medusa/src/services/product.js index fedc1a876e..968071b890 100644 --- a/packages/medusa/src/services/product.js +++ b/packages/medusa/src/services/product.js @@ -444,6 +444,7 @@ class ProductService extends BaseService { .withTransaction(manager) .emit(ProductService.Events.UPDATED, { id: result.id, + fields: Object.keys(update), }) return result })