feat(medusa): Authentication overhaul (#4064)
* implemented bearer auth * changed naming strat * changed session auth to not use jwt * typo * changed auth header prefix for admin api token auth * fixed supporting functions to work with new session type * removed database calls for bearer auth improving performance * removed unused deps * changed auth in tests * added integration tests * Accepted suggested change Co-authored-by: Carlos R. L. Rodrigues <37986729+carlos-r-l-rodrigues@users.noreply.github.com> * Typo Co-authored-by: Oliver Windall Juhl <59018053+olivermrbl@users.noreply.github.com> * more typos Co-authored-by: Oliver Windall Juhl <59018053+olivermrbl@users.noreply.github.com> * proper formatting Co-authored-by: Oliver Windall Juhl <59018053+olivermrbl@users.noreply.github.com> * removed endregion Co-authored-by: Oliver Windall Juhl <59018053+olivermrbl@users.noreply.github.com> * removed startregion Co-authored-by: Oliver Windall Juhl <59018053+olivermrbl@users.noreply.github.com> * fixed admin JWT integration test * added more fixes to integration tests * Update OAS * Create fluffy-donkeys-hope.md * created API reference for new auth * implemented getToken in medusa-js * Apply suggestions from code review Co-authored-by: Shahed Nasser <shahednasser@gmail.com> * Apply suggestions from code review Co-authored-by: Shahed Nasser <shahednasser@gmail.com> * deleted files which should be autogenerated * Update fluffy-donkeys-hope.md * JSDoc update Co-authored-by: Oli Juhl <59018053+olivermrbl@users.noreply.github.com> * added missing route exports * implemented runtime domain safety in jwt token manager * fixed jwt manager * lint get-token files * Update fluffy-donkeys-hope.md * Revert "deleted files which should be autogenerated" This reverts commit cd5e86623b822e6a6ac37322b952143ccc493df9. * Revert "Apply suggestions from code review" This reverts commit f02f07ce58fd9fcc2dfc80cadbb9df2665108d65. * Revert "created API reference for new auth" This reverts commit c9eafbb36453f5cf8047c79e94f470cb2d023c7d. * renamed header for sending api access tokens * medusa-js - changed apiKey header --------- Co-authored-by: Oliver Windall Juhl <59018053+olivermrbl@users.noreply.github.com> Co-authored-by: Carlos R. L. Rodrigues <37986729+carlos-r-l-rodrigues@users.noreply.github.com> Co-authored-by: olivermrbl <oliver@mrbltech.com> Co-authored-by: Shahed Nasser <shahednasser@gmail.com>
This commit is contained in:
98 files changed
+864
-351
No files matched your search
@@ -0,0 +1,6 @@
|
|||||||
|
---
|
||||||
|
"@medusajs/medusa": minor
|
||||||
|
"@medusajs/medusa-js": minor
|
||||||
|
---
|
||||||
|
|
||||||
|
feat(medusa): Authentication overhaul
|
||||||
@@ -10,7 +10,7 @@ const adminSeeder = require("../../../helpers/admin-seeder")
|
|||||||
|
|
||||||
const adminReqConfig = {
|
const adminReqConfig = {
|
||||||
headers: {
|
headers: {
|
||||||
Authorization: "Bearer test_token",
|
"x-medusa-access-token": "test_token",
|
||||||
},
|
},
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -47,4 +47,20 @@ describe("/admin/auth", () => {
|
|||||||
updated_at: expect.any(String),
|
updated_at: expect.any(String),
|
||||||
})
|
})
|
||||||
})
|
})
|
||||||
|
|
||||||
|
it("creates admin JWT token correctly", async () => {
|
||||||
|
const api = useApi()
|
||||||
|
|
||||||
|
const response = await api
|
||||||
|
.post("/admin/auth/token", {
|
||||||
|
email: "admin@medusa.js",
|
||||||
|
password: "secret_password",
|
||||||
|
})
|
||||||
|
.catch((err) => {
|
||||||
|
console.log(err)
|
||||||
|
})
|
||||||
|
|
||||||
|
expect(response.status).toEqual(200)
|
||||||
|
expect(response.data.access_token).toEqual(expect.any(String))
|
||||||
|
})
|
||||||
})
|
})
|
||||||
@@ -18,7 +18,7 @@ jest.setTimeout(30000)
|
|||||||
|
|
||||||
const adminReqConfig = {
|
const adminReqConfig = {
|
||||||
headers: {
|
headers: {
|
||||||
Authorization: "Bearer test_token",
|
"x-medusa-access-token": "test_token",
|
||||||
},
|
},
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -57,7 +57,7 @@ describe("/admin/collections", () => {
|
|||||||
{
|
{
|
||||||
title: "test",
|
title: "test",
|
||||||
},
|
},
|
||||||
{ headers: { Authorization: "Bearer test_token" } }
|
{ headers: { "x-medusa-access-token": "test_token" } }
|
||||||
)
|
)
|
||||||
|
|
||||||
const response = await api.post(
|
const response = await api.post(
|
||||||
@@ -66,7 +66,7 @@ describe("/admin/collections", () => {
|
|||||||
title: "test collection creation",
|
title: "test collection creation",
|
||||||
handle: "test-handle-creation",
|
handle: "test-handle-creation",
|
||||||
},
|
},
|
||||||
{ headers: { Authorization: "Bearer test_token" } }
|
{ headers: { "x-medusa-access-token": "test_token" } }
|
||||||
)
|
)
|
||||||
|
|
||||||
expect(response.status).toEqual(200)
|
expect(response.status).toEqual(200)
|
||||||
@@ -91,12 +91,12 @@ describe("/admin/collections", () => {
|
|||||||
{
|
{
|
||||||
title: "test",
|
title: "test",
|
||||||
},
|
},
|
||||||
{ headers: { Authorization: "Bearer test_token" } }
|
{ headers: { "x-medusa-access-token": "test_token" } }
|
||||||
)
|
)
|
||||||
|
|
||||||
const response = await api.delete(
|
const response = await api.delete(
|
||||||
`/admin/collections/${creationResponse.data.collection.id}`,
|
`/admin/collections/${creationResponse.data.collection.id}`,
|
||||||
{ headers: { Authorization: "Bearer test_token" } }
|
{ headers: { "x-medusa-access-token": "test_token" } }
|
||||||
)
|
)
|
||||||
|
|
||||||
expect(response.status).toEqual(200)
|
expect(response.status).toEqual(200)
|
||||||
@@ -111,7 +111,7 @@ describe("/admin/collections", () => {
|
|||||||
const api = useApi()
|
const api = useApi()
|
||||||
|
|
||||||
const response = await api.get("/admin/collections/test-collection", {
|
const response = await api.get("/admin/collections/test-collection", {
|
||||||
headers: { Authorization: "Bearer test_token" },
|
headers: { "x-medusa-access-token": "test_token" },
|
||||||
})
|
})
|
||||||
|
|
||||||
expect(response.data).toEqual(
|
expect(response.data).toEqual(
|
||||||
@@ -160,7 +160,7 @@ describe("/admin/collections", () => {
|
|||||||
title: "test collection creation",
|
title: "test collection creation",
|
||||||
handle: "test-handle-creation",
|
handle: "test-handle-creation",
|
||||||
},
|
},
|
||||||
{ headers: { Authorization: "Bearer test_token" } }
|
{ headers: { "x-medusa-access-token": "test_token" } }
|
||||||
)
|
)
|
||||||
|
|
||||||
expect(response.status).toEqual(200)
|
expect(response.status).toEqual(200)
|
||||||
@@ -181,7 +181,7 @@ describe("/admin/collections", () => {
|
|||||||
const api = useApi()
|
const api = useApi()
|
||||||
|
|
||||||
const response = await api.get("/admin/collections", {
|
const response = await api.get("/admin/collections", {
|
||||||
headers: { Authorization: "Bearer test_token" },
|
headers: { "x-medusa-access-token": "test_token" },
|
||||||
})
|
})
|
||||||
|
|
||||||
expect(response.data).toEqual(
|
expect(response.data).toEqual(
|
||||||
@@ -261,7 +261,7 @@ describe("/admin/collections", () => {
|
|||||||
product_ids: ["test-product_filtering_1"],
|
product_ids: ["test-product_filtering_1"],
|
||||||
},
|
},
|
||||||
{
|
{
|
||||||
headers: { Authorization: "Bearer test_token" },
|
headers: { "x-medusa-access-token": "test_token" },
|
||||||
}
|
}
|
||||||
)
|
)
|
||||||
.catch((err) => console.warn(err))
|
.catch((err) => console.warn(err))
|
||||||
@@ -307,7 +307,7 @@ describe("/admin/collections", () => {
|
|||||||
|
|
||||||
const response = await api
|
const response = await api
|
||||||
.delete("/admin/collections/test-collection/products/batch", {
|
.delete("/admin/collections/test-collection/products/batch", {
|
||||||
headers: { Authorization: "Bearer test_token" },
|
headers: { "x-medusa-access-token": "test_token" },
|
||||||
data: { product_ids: ["test-product"] },
|
data: { product_ids: ["test-product"] },
|
||||||
})
|
})
|
||||||
.catch((err) => console.warn(err))
|
.catch((err) => console.warn(err))
|
||||||
@@ -328,7 +328,7 @@ describe("/admin/collections", () => {
|
|||||||
|
|
||||||
const response = await api
|
const response = await api
|
||||||
.get("/admin/collections?title=Test%20collection", {
|
.get("/admin/collections?title=Test%20collection", {
|
||||||
headers: { Authorization: "Bearer test_token" },
|
headers: { "x-medusa-access-token": "test_token" },
|
||||||
})
|
})
|
||||||
.catch((err) => console.log(err))
|
.catch((err) => console.log(err))
|
||||||
|
|
||||||
|
|||||||
@@ -8,7 +8,7 @@ const adminSeeder = require("../../../helpers/admin-seeder")
|
|||||||
|
|
||||||
const adminReqConfig = {
|
const adminReqConfig = {
|
||||||
headers: {
|
headers: {
|
||||||
Authorization: "Bearer test_token",
|
"x-medusa-access-token": "test_token",
|
||||||
},
|
},
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -20,7 +20,7 @@ jest.setTimeout(30000)
|
|||||||
|
|
||||||
const adminReqConfig = {
|
const adminReqConfig = {
|
||||||
headers: {
|
headers: {
|
||||||
Authorization: "Bearer test_token",
|
"x-medusa-access-token": "test_token",
|
||||||
},
|
},
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -43,7 +43,7 @@ describe("/admin/customers", () => {
|
|||||||
const response = await api
|
const response = await api
|
||||||
.get("/admin/customers", {
|
.get("/admin/customers", {
|
||||||
headers: {
|
headers: {
|
||||||
Authorization: "Bearer test_token",
|
"x-medusa-access-token": "test_token",
|
||||||
},
|
},
|
||||||
})
|
})
|
||||||
.catch((err) => {
|
.catch((err) => {
|
||||||
@@ -76,7 +76,7 @@ describe("/admin/customers", () => {
|
|||||||
const response = await api
|
const response = await api
|
||||||
.get("/admin/customers?has_account=true", {
|
.get("/admin/customers?has_account=true", {
|
||||||
headers: {
|
headers: {
|
||||||
Authorization: "Bearer test_token",
|
"x-medusa-access-token": "test_token",
|
||||||
},
|
},
|
||||||
})
|
})
|
||||||
.catch((err) => {
|
.catch((err) => {
|
||||||
@@ -97,7 +97,7 @@ describe("/admin/customers", () => {
|
|||||||
const response = await api
|
const response = await api
|
||||||
.get("/admin/customers?groups[]=test-group-5", {
|
.get("/admin/customers?groups[]=test-group-5", {
|
||||||
headers: {
|
headers: {
|
||||||
Authorization: "Bearer test_token",
|
"x-medusa-access-token": "test_token",
|
||||||
},
|
},
|
||||||
})
|
})
|
||||||
.catch((err) => {
|
.catch((err) => {
|
||||||
@@ -127,7 +127,7 @@ describe("/admin/customers", () => {
|
|||||||
const response = await api
|
const response = await api
|
||||||
.get("/admin/customers?q=est2@", {
|
.get("/admin/customers?q=est2@", {
|
||||||
headers: {
|
headers: {
|
||||||
Authorization: "Bearer test_token",
|
"x-medusa-access-token": "test_token",
|
||||||
},
|
},
|
||||||
})
|
})
|
||||||
.catch((err) => {
|
.catch((err) => {
|
||||||
@@ -152,7 +152,7 @@ describe("/admin/customers", () => {
|
|||||||
const response = await api
|
const response = await api
|
||||||
.get("/admin/customers?q=test1@email.com&expand=shipping_addresses", {
|
.get("/admin/customers?q=test1@email.com&expand=shipping_addresses", {
|
||||||
headers: {
|
headers: {
|
||||||
Authorization: "Bearer test_token",
|
"x-medusa-access-token": "test_token",
|
||||||
},
|
},
|
||||||
})
|
})
|
||||||
.catch((err) => {
|
.catch((err) => {
|
||||||
@@ -202,7 +202,7 @@ describe("/admin/customers", () => {
|
|||||||
},
|
},
|
||||||
{
|
{
|
||||||
headers: {
|
headers: {
|
||||||
Authorization: "Bearer test_token",
|
"x-medusa-access-token": "test_token",
|
||||||
},
|
},
|
||||||
}
|
}
|
||||||
)
|
)
|
||||||
@@ -246,7 +246,7 @@ describe("/admin/customers", () => {
|
|||||||
},
|
},
|
||||||
{
|
{
|
||||||
headers: {
|
headers: {
|
||||||
Authorization: "Bearer test_token",
|
"x-medusa-access-token": "test_token",
|
||||||
},
|
},
|
||||||
}
|
}
|
||||||
)
|
)
|
||||||
@@ -278,7 +278,7 @@ describe("/admin/customers", () => {
|
|||||||
},
|
},
|
||||||
{
|
{
|
||||||
headers: {
|
headers: {
|
||||||
Authorization: "Bearer test_token",
|
"x-medusa-access-token": "test_token",
|
||||||
},
|
},
|
||||||
}
|
}
|
||||||
)
|
)
|
||||||
@@ -301,7 +301,7 @@ describe("/admin/customers", () => {
|
|||||||
},
|
},
|
||||||
{
|
{
|
||||||
headers: {
|
headers: {
|
||||||
Authorization: "Bearer test_token",
|
"x-medusa-access-token": "test_token",
|
||||||
},
|
},
|
||||||
}
|
}
|
||||||
)
|
)
|
||||||
@@ -329,7 +329,7 @@ describe("/admin/customers", () => {
|
|||||||
},
|
},
|
||||||
{
|
{
|
||||||
headers: {
|
headers: {
|
||||||
Authorization: "Bearer test_token",
|
"x-medusa-access-token": "test_token",
|
||||||
},
|
},
|
||||||
}
|
}
|
||||||
)
|
)
|
||||||
@@ -350,7 +350,7 @@ describe("/admin/customers", () => {
|
|||||||
},
|
},
|
||||||
{
|
{
|
||||||
headers: {
|
headers: {
|
||||||
Authorization: "Bearer test_token",
|
"x-medusa-access-token": "test_token",
|
||||||
},
|
},
|
||||||
}
|
}
|
||||||
)
|
)
|
||||||
@@ -389,7 +389,7 @@ describe("/admin/customers", () => {
|
|||||||
const response = await api
|
const response = await api
|
||||||
.get("/admin/customers/test-customer-1", {
|
.get("/admin/customers/test-customer-1", {
|
||||||
headers: {
|
headers: {
|
||||||
Authorization: "Bearer test_token",
|
"x-medusa-access-token": "test_token",
|
||||||
},
|
},
|
||||||
})
|
})
|
||||||
.catch((err) => {
|
.catch((err) => {
|
||||||
@@ -417,7 +417,7 @@ describe("/admin/customers", () => {
|
|||||||
const response = await api
|
const response = await api
|
||||||
.get("/admin/customers/test-customer-1?expand=billing_address,groups", {
|
.get("/admin/customers/test-customer-1?expand=billing_address,groups", {
|
||||||
headers: {
|
headers: {
|
||||||
Authorization: "Bearer test_token",
|
"x-medusa-access-token": "test_token",
|
||||||
},
|
},
|
||||||
})
|
})
|
||||||
.catch((err) => {
|
.catch((err) => {
|
||||||
|
|||||||
@@ -20,7 +20,7 @@ jest.setTimeout(30000)
|
|||||||
|
|
||||||
const adminReqConfig = {
|
const adminReqConfig = {
|
||||||
headers: {
|
headers: {
|
||||||
Authorization: "Bearer test_token",
|
"x-medusa-access-token": "test_token",
|
||||||
},
|
},
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -666,7 +666,7 @@ describe("/admin/discounts", () => {
|
|||||||
},
|
},
|
||||||
{
|
{
|
||||||
headers: {
|
headers: {
|
||||||
Authorization: "Bearer test_token",
|
"x-medusa-access-token": "test_token",
|
||||||
},
|
},
|
||||||
}
|
}
|
||||||
)
|
)
|
||||||
@@ -770,7 +770,7 @@ describe("/admin/discounts", () => {
|
|||||||
},
|
},
|
||||||
{
|
{
|
||||||
headers: {
|
headers: {
|
||||||
Authorization: "Bearer test_token",
|
"x-medusa-access-token": "test_token",
|
||||||
},
|
},
|
||||||
}
|
}
|
||||||
)
|
)
|
||||||
@@ -1381,7 +1381,7 @@ describe("/admin/discounts", () => {
|
|||||||
|
|
||||||
const resultingDiscount = await api.get(
|
const resultingDiscount = await api.get(
|
||||||
"/admin/discounts/test-discount",
|
"/admin/discounts/test-discount",
|
||||||
{ headers: { Authorization: "Bearer test_token" } }
|
{ headers: { "x-medusa-access-token": "test_token" } }
|
||||||
)
|
)
|
||||||
|
|
||||||
expect(resultingDiscount.status).toEqual(200)
|
expect(resultingDiscount.status).toEqual(200)
|
||||||
|
|||||||
@@ -12,7 +12,7 @@ jest.setTimeout(30000)
|
|||||||
|
|
||||||
const adminReqConfig = {
|
const adminReqConfig = {
|
||||||
headers: {
|
headers: {
|
||||||
Authorization: "Bearer test_token",
|
"x-medusa-access-token": "test_token",
|
||||||
},
|
},
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -16,7 +16,7 @@ jest.setTimeout(30000)
|
|||||||
|
|
||||||
const adminReqConfig = {
|
const adminReqConfig = {
|
||||||
headers: {
|
headers: {
|
||||||
Authorization: "Bearer test_token",
|
"x-medusa-access-token": "test_token",
|
||||||
},
|
},
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -63,7 +63,7 @@ describe("/admin/gift-cards", () => {
|
|||||||
const response = await api
|
const response = await api
|
||||||
.get("/admin/gift-cards", {
|
.get("/admin/gift-cards", {
|
||||||
headers: {
|
headers: {
|
||||||
Authorization: "Bearer test_token",
|
"x-medusa-access-token": "test_token",
|
||||||
},
|
},
|
||||||
})
|
})
|
||||||
.catch((err) => {
|
.catch((err) => {
|
||||||
@@ -91,7 +91,7 @@ describe("/admin/gift-cards", () => {
|
|||||||
const response = await api
|
const response = await api
|
||||||
.get("/admin/gift-cards?q=gc", {
|
.get("/admin/gift-cards?q=gc", {
|
||||||
headers: {
|
headers: {
|
||||||
Authorization: "Bearer test_token",
|
"x-medusa-access-token": "test_token",
|
||||||
},
|
},
|
||||||
})
|
})
|
||||||
.catch((err) => {
|
.catch((err) => {
|
||||||
@@ -116,7 +116,7 @@ describe("/admin/gift-cards", () => {
|
|||||||
const response = await api
|
const response = await api
|
||||||
.get("/admin/gift-cards?q=bla", {
|
.get("/admin/gift-cards?q=bla", {
|
||||||
headers: {
|
headers: {
|
||||||
Authorization: "Bearer test_token",
|
"x-medusa-access-token": "test_token",
|
||||||
},
|
},
|
||||||
})
|
})
|
||||||
.catch((err) => {
|
.catch((err) => {
|
||||||
@@ -165,7 +165,7 @@ describe("/admin/gift-cards", () => {
|
|||||||
},
|
},
|
||||||
{
|
{
|
||||||
headers: {
|
headers: {
|
||||||
Authorization: "Bearer test_token",
|
"x-medusa-access-token": "test_token",
|
||||||
},
|
},
|
||||||
}
|
}
|
||||||
)
|
)
|
||||||
@@ -192,7 +192,7 @@ describe("/admin/gift-cards", () => {
|
|||||||
},
|
},
|
||||||
{
|
{
|
||||||
headers: {
|
headers: {
|
||||||
Authorization: "Bearer test_token",
|
"x-medusa-access-token": "test_token",
|
||||||
},
|
},
|
||||||
}
|
}
|
||||||
)
|
)
|
||||||
|
|||||||
@@ -42,7 +42,7 @@ describe("/admin/invites", () => {
|
|||||||
const response = await api
|
const response = await api
|
||||||
.get("/admin/invites", {
|
.get("/admin/invites", {
|
||||||
headers: {
|
headers: {
|
||||||
Authorization: "Bearer test_token",
|
"x-medusa-access-token": "test_token",
|
||||||
},
|
},
|
||||||
})
|
})
|
||||||
.catch((err) => {
|
.catch((err) => {
|
||||||
@@ -92,7 +92,7 @@ describe("/admin/invites", () => {
|
|||||||
password: "test123453",
|
password: "test123453",
|
||||||
},
|
},
|
||||||
{
|
{
|
||||||
headers: { Authorization: "Bearer test_token" },
|
headers: { "x-medusa-access-token": "test_token" },
|
||||||
}
|
}
|
||||||
)
|
)
|
||||||
.catch((err) => console.log(err))
|
.catch((err) => console.log(err))
|
||||||
@@ -116,14 +116,14 @@ describe("/admin/invites", () => {
|
|||||||
|
|
||||||
const createReponse = await api
|
const createReponse = await api
|
||||||
.post("/admin/invites", payload, {
|
.post("/admin/invites", payload, {
|
||||||
headers: { Authorization: "Bearer test_token" },
|
headers: { "x-medusa-access-token": "test_token" },
|
||||||
})
|
})
|
||||||
.catch((err) => console.log(err))
|
.catch((err) => console.log(err))
|
||||||
|
|
||||||
const response = await api
|
const response = await api
|
||||||
.get("/admin/invites", {
|
.get("/admin/invites", {
|
||||||
headers: {
|
headers: {
|
||||||
Authorization: "Bearer test_token",
|
"x-medusa-access-token": "test_token",
|
||||||
},
|
},
|
||||||
})
|
})
|
||||||
.catch((err) => {
|
.catch((err) => {
|
||||||
@@ -151,14 +151,14 @@ describe("/admin/invites", () => {
|
|||||||
|
|
||||||
const createReponse = await api
|
const createReponse = await api
|
||||||
.post("/admin/invites", payload, {
|
.post("/admin/invites", payload, {
|
||||||
headers: { Authorization: "Bearer test_token" },
|
headers: { "x-medusa-access-token": "test_token" },
|
||||||
})
|
})
|
||||||
.catch((err) => console.log(err))
|
.catch((err) => console.log(err))
|
||||||
|
|
||||||
const response = await api
|
const response = await api
|
||||||
.get("/admin/invites", {
|
.get("/admin/invites", {
|
||||||
headers: {
|
headers: {
|
||||||
Authorization: "Bearer test_token",
|
"x-medusa-access-token": "test_token",
|
||||||
},
|
},
|
||||||
})
|
})
|
||||||
.catch((err) => {
|
.catch((err) => {
|
||||||
@@ -189,7 +189,7 @@ describe("/admin/invites", () => {
|
|||||||
`/admin/invites/${id}/resend`,
|
`/admin/invites/${id}/resend`,
|
||||||
{},
|
{},
|
||||||
{
|
{
|
||||||
headers: { Authorization: "Bearer test_token" },
|
headers: { "x-medusa-access-token": "test_token" },
|
||||||
}
|
}
|
||||||
)
|
)
|
||||||
.catch((err) => console.log(err))
|
.catch((err) => console.log(err))
|
||||||
@@ -201,7 +201,7 @@ describe("/admin/invites", () => {
|
|||||||
const api = useApi()
|
const api = useApi()
|
||||||
|
|
||||||
const inviteResponse = await api.get("/admin/invites", {
|
const inviteResponse = await api.get("/admin/invites", {
|
||||||
headers: { Authorization: "Bearer test_token" },
|
headers: { "x-medusa-access-token": "test_token" },
|
||||||
})
|
})
|
||||||
|
|
||||||
const { token, ...rest } = inviteResponse.data.invites[0]
|
const { token, ...rest } = inviteResponse.data.invites[0]
|
||||||
@@ -219,7 +219,7 @@ describe("/admin/invites", () => {
|
|||||||
.catch((err) => console.log(err))
|
.catch((err) => console.log(err))
|
||||||
|
|
||||||
const userResponse = await api.get("/admin/users", {
|
const userResponse = await api.get("/admin/users", {
|
||||||
headers: { Authorization: "Bearer test_token" },
|
headers: { "x-medusa-access-token": "test_token" },
|
||||||
})
|
})
|
||||||
|
|
||||||
const newUser = userResponse.data.users.find(
|
const newUser = userResponse.data.users.find(
|
||||||
@@ -234,7 +234,7 @@ describe("/admin/invites", () => {
|
|||||||
const api = useApi()
|
const api = useApi()
|
||||||
|
|
||||||
const inviteResponse = await api.get("/admin/invites", {
|
const inviteResponse = await api.get("/admin/invites", {
|
||||||
headers: { Authorization: "Bearer test_token" },
|
headers: { "x-medusa-access-token": "test_token" },
|
||||||
})
|
})
|
||||||
|
|
||||||
const { token, ...rest } = inviteResponse.data.invites.find(
|
const { token, ...rest } = inviteResponse.data.invites.find(
|
||||||
@@ -254,7 +254,7 @@ describe("/admin/invites", () => {
|
|||||||
|
|
||||||
const updateResponse = await api
|
const updateResponse = await api
|
||||||
.post("/admin/invites", updatePayload, {
|
.post("/admin/invites", updatePayload, {
|
||||||
headers: { Authorization: "Bearer test_token" },
|
headers: { "x-medusa-access-token": "test_token" },
|
||||||
})
|
})
|
||||||
.catch((err) => console.log(err))
|
.catch((err) => console.log(err))
|
||||||
|
|
||||||
@@ -263,7 +263,7 @@ describe("/admin/invites", () => {
|
|||||||
const createResponse = await api.post("/admin/invites/accept", payload)
|
const createResponse = await api.post("/admin/invites/accept", payload)
|
||||||
|
|
||||||
const userResponse = await api.get("/admin/users", {
|
const userResponse = await api.get("/admin/users", {
|
||||||
headers: { Authorization: "Bearer test_token" },
|
headers: { "x-medusa-access-token": "test_token" },
|
||||||
})
|
})
|
||||||
|
|
||||||
const newUser = userResponse.data.users.find(
|
const newUser = userResponse.data.users.find(
|
||||||
@@ -302,7 +302,7 @@ describe("/admin/invites", () => {
|
|||||||
const api = useApi()
|
const api = useApi()
|
||||||
|
|
||||||
const inviteResponse = await api.get("/admin/invites", {
|
const inviteResponse = await api.get("/admin/invites", {
|
||||||
headers: { Authorization: "Bearer test_token" },
|
headers: { "x-medusa-access-token": "test_token" },
|
||||||
})
|
})
|
||||||
|
|
||||||
const { token } = inviteResponse.data.invites[0]
|
const { token } = inviteResponse.data.invites[0]
|
||||||
@@ -353,7 +353,7 @@ describe("/admin/invites", () => {
|
|||||||
|
|
||||||
const invitesBeforeDeleteRequest = await api.get("/admin/invites", {
|
const invitesBeforeDeleteRequest = await api.get("/admin/invites", {
|
||||||
headers: {
|
headers: {
|
||||||
Authorization: "Bearer test_token",
|
"x-medusa-access-token": "test_token",
|
||||||
},
|
},
|
||||||
})
|
})
|
||||||
|
|
||||||
@@ -361,13 +361,13 @@ describe("/admin/invites", () => {
|
|||||||
|
|
||||||
const response = await api
|
const response = await api
|
||||||
.delete(`/admin/invites/${inviteId}`, {
|
.delete(`/admin/invites/${inviteId}`, {
|
||||||
headers: { Authorization: "Bearer test_token" },
|
headers: { "x-medusa-access-token": "test_token" },
|
||||||
})
|
})
|
||||||
.catch((err) => console.log(err))
|
.catch((err) => console.log(err))
|
||||||
|
|
||||||
const invitesAfterDeleteRequest = await api.get("/admin/invites", {
|
const invitesAfterDeleteRequest = await api.get("/admin/invites", {
|
||||||
headers: {
|
headers: {
|
||||||
Authorization: "Bearer test_token",
|
"x-medusa-access-token": "test_token",
|
||||||
},
|
},
|
||||||
})
|
})
|
||||||
|
|
||||||
|
|||||||
@@ -52,7 +52,7 @@ describe("/admin/notes", () => {
|
|||||||
|
|
||||||
const response = await api.get("/admin/notes/note1", {
|
const response = await api.get("/admin/notes/note1", {
|
||||||
headers: {
|
headers: {
|
||||||
authorization: "Bearer test_token",
|
"x-medusa-access-token": "test_token",
|
||||||
},
|
},
|
||||||
})
|
})
|
||||||
|
|
||||||
@@ -91,7 +91,7 @@ describe("/admin/notes", () => {
|
|||||||
},
|
},
|
||||||
{
|
{
|
||||||
headers: {
|
headers: {
|
||||||
authorization: "Bearer test_token",
|
"x-medusa-access-token": "test_token",
|
||||||
},
|
},
|
||||||
}
|
}
|
||||||
)
|
)
|
||||||
@@ -136,7 +136,7 @@ describe("/admin/notes", () => {
|
|||||||
const response = await api
|
const response = await api
|
||||||
.get("/admin/notes?resource_id=resource1", {
|
.get("/admin/notes?resource_id=resource1", {
|
||||||
headers: {
|
headers: {
|
||||||
authorization: "Bearer test_token",
|
"x-medusa-access-token": "test_token",
|
||||||
},
|
},
|
||||||
})
|
})
|
||||||
.catch((err) => {
|
.catch((err) => {
|
||||||
@@ -169,7 +169,7 @@ describe("/admin/notes", () => {
|
|||||||
const response = await api
|
const response = await api
|
||||||
.get("/admin/notes?limit=2", {
|
.get("/admin/notes?limit=2", {
|
||||||
headers: {
|
headers: {
|
||||||
authorization: "Bearer test_token",
|
"x-medusa-access-token": "test_token",
|
||||||
},
|
},
|
||||||
})
|
})
|
||||||
.catch((err) => {
|
.catch((err) => {
|
||||||
@@ -204,7 +204,7 @@ describe("/admin/notes", () => {
|
|||||||
{ value: "new text" },
|
{ value: "new text" },
|
||||||
{
|
{
|
||||||
headers: {
|
headers: {
|
||||||
authorization: "Bearer test_token",
|
"x-medusa-access-token": "test_token",
|
||||||
},
|
},
|
||||||
}
|
}
|
||||||
)
|
)
|
||||||
@@ -215,7 +215,7 @@ describe("/admin/notes", () => {
|
|||||||
const response = await api
|
const response = await api
|
||||||
.get("/admin/notes/note1", {
|
.get("/admin/notes/note1", {
|
||||||
headers: {
|
headers: {
|
||||||
authorization: "Bearer test_token",
|
"x-medusa-access-token": "test_token",
|
||||||
},
|
},
|
||||||
})
|
})
|
||||||
.catch((err) => {
|
.catch((err) => {
|
||||||
@@ -246,7 +246,7 @@ describe("/admin/notes", () => {
|
|||||||
await api
|
await api
|
||||||
.delete("/admin/notes/note1", {
|
.delete("/admin/notes/note1", {
|
||||||
headers: {
|
headers: {
|
||||||
authorization: "Bearer test_token",
|
"x-medusa-access-token": "test_token",
|
||||||
},
|
},
|
||||||
})
|
})
|
||||||
.catch((err) => {
|
.catch((err) => {
|
||||||
@@ -257,7 +257,7 @@ describe("/admin/notes", () => {
|
|||||||
await api
|
await api
|
||||||
.get("/admin/notes/note1", {
|
.get("/admin/notes/note1", {
|
||||||
headers: {
|
headers: {
|
||||||
authorization: "Bearer test_token",
|
"x-medusa-access-token": "test_token",
|
||||||
},
|
},
|
||||||
})
|
})
|
||||||
.catch((err) => (error = err))
|
.catch((err) => (error = err))
|
||||||
|
|||||||
@@ -18,7 +18,7 @@ jest.setTimeout(30000)
|
|||||||
|
|
||||||
const adminReqConfig = {
|
const adminReqConfig = {
|
||||||
headers: {
|
headers: {
|
||||||
Authorization: "Bearer test_token",
|
"x-medusa-access-token": "test_token",
|
||||||
},
|
},
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -25,7 +25,7 @@ jest.setTimeout(30000)
|
|||||||
|
|
||||||
const adminHeaders = {
|
const adminHeaders = {
|
||||||
headers: {
|
headers: {
|
||||||
Authorization: "Bearer test_token",
|
"x-medusa-access-token": "test_token",
|
||||||
},
|
},
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -18,7 +18,7 @@ jest.setTimeout(30000)
|
|||||||
|
|
||||||
const adminReqConfig = {
|
const adminReqConfig = {
|
||||||
headers: {
|
headers: {
|
||||||
Authorization: "Bearer test_token",
|
"x-medusa-access-token": "test_token",
|
||||||
},
|
},
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -34,7 +34,7 @@ const {
|
|||||||
|
|
||||||
const adminReqConfig = {
|
const adminReqConfig = {
|
||||||
headers: {
|
headers: {
|
||||||
Authorization: "Bearer test_token",
|
"x-medusa-access-token": "test_token",
|
||||||
},
|
},
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -14,7 +14,7 @@ jest.setTimeout(30000)
|
|||||||
|
|
||||||
const adminHeaders = {
|
const adminHeaders = {
|
||||||
headers: {
|
headers: {
|
||||||
Authorization: "Bearer test_token",
|
"x-medusa-access-token": "test_token",
|
||||||
},
|
},
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -17,7 +17,7 @@ jest.setTimeout(30000)
|
|||||||
|
|
||||||
const adminHeaders = {
|
const adminHeaders = {
|
||||||
headers: {
|
headers: {
|
||||||
Authorization: "Bearer test_token",
|
"x-medusa-access-token": "test_token",
|
||||||
},
|
},
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -19,7 +19,7 @@ const productSeeder = require("../../../helpers/product-seeder")
|
|||||||
|
|
||||||
const adminReqConfig = {
|
const adminReqConfig = {
|
||||||
headers: {
|
headers: {
|
||||||
Authorization: "Bearer test_token",
|
"x-medusa-access-token": "test_token",
|
||||||
},
|
},
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -15,7 +15,7 @@ jest.setTimeout(30000)
|
|||||||
|
|
||||||
const adminHeaders = {
|
const adminHeaders = {
|
||||||
headers: {
|
headers: {
|
||||||
Authorization: "Bearer test_token",
|
"x-medusa-access-token": "test_token",
|
||||||
},
|
},
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -19,7 +19,7 @@ jest.setTimeout(50000)
|
|||||||
|
|
||||||
const adminReqConfig = {
|
const adminReqConfig = {
|
||||||
headers: {
|
headers: {
|
||||||
Authorization: "Bearer test_token",
|
"x-medusa-access-token": "test_token",
|
||||||
},
|
},
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -20,7 +20,7 @@ jest.setTimeout(50000)
|
|||||||
|
|
||||||
const adminReqConfig = {
|
const adminReqConfig = {
|
||||||
headers: {
|
headers: {
|
||||||
Authorization: "Bearer test_token",
|
"x-medusa-access-token": "test_token",
|
||||||
},
|
},
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -28,7 +28,7 @@ jest.setTimeout(50000)
|
|||||||
|
|
||||||
const adminHeaders = {
|
const adminHeaders = {
|
||||||
headers: {
|
headers: {
|
||||||
Authorization: "Bearer test_token",
|
"x-medusa-access-token": "test_token",
|
||||||
},
|
},
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -16,7 +16,7 @@ const testProduct1Id = "test-product1"
|
|||||||
const testProductFilteringId1 = "test-product_filtering_1"
|
const testProductFilteringId1 = "test-product_filtering_1"
|
||||||
const adminHeaders = {
|
const adminHeaders = {
|
||||||
headers: {
|
headers: {
|
||||||
Authorization: "Bearer test_token",
|
"x-medusa-access-token": "test_token",
|
||||||
},
|
},
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -18,7 +18,7 @@ jest.setTimeout(50000)
|
|||||||
|
|
||||||
const adminHeaders = {
|
const adminHeaders = {
|
||||||
headers: {
|
headers: {
|
||||||
Authorization: "Bearer test_token",
|
"x-medusa-access-token": "test_token",
|
||||||
},
|
},
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -599,7 +599,7 @@ describe("Publishable API keys", () => {
|
|||||||
|
|
||||||
const response = await api.get(`/store/products`, {
|
const response = await api.get(`/store/products`, {
|
||||||
headers: {
|
headers: {
|
||||||
Authorization: "Bearer test_token",
|
"x-medusa-access-token": "test_token",
|
||||||
"x-publishable-api-key": pubKeyId,
|
"x-publishable-api-key": pubKeyId,
|
||||||
},
|
},
|
||||||
})
|
})
|
||||||
@@ -630,7 +630,7 @@ describe("Publishable API keys", () => {
|
|||||||
|
|
||||||
const response = await api.get(`/store/products`, {
|
const response = await api.get(`/store/products`, {
|
||||||
headers: {
|
headers: {
|
||||||
Authorization: "Bearer test_token",
|
"x-medusa-access-token": "test_token",
|
||||||
"x-publishable-api-key": pubKeyId,
|
"x-publishable-api-key": pubKeyId,
|
||||||
},
|
},
|
||||||
})
|
})
|
||||||
@@ -666,7 +666,7 @@ describe("Publishable API keys", () => {
|
|||||||
`/store/products?sales_channel_id[0]=${salesChannel2.id}`,
|
`/store/products?sales_channel_id[0]=${salesChannel2.id}`,
|
||||||
{
|
{
|
||||||
headers: {
|
headers: {
|
||||||
Authorization: "Bearer test_token",
|
"x-medusa-access-token": "test_token",
|
||||||
"x-publishable-api-key": pubKeyId,
|
"x-publishable-api-key": pubKeyId,
|
||||||
},
|
},
|
||||||
}
|
}
|
||||||
@@ -698,7 +698,7 @@ describe("Publishable API keys", () => {
|
|||||||
|
|
||||||
const response = await api.get(`/store/products`, {
|
const response = await api.get(`/store/products`, {
|
||||||
headers: {
|
headers: {
|
||||||
Authorization: "Bearer test_token",
|
"x-medusa-access-token": "test_token",
|
||||||
// "x-publishable-api-key": pubKeyId,
|
// "x-publishable-api-key": pubKeyId,
|
||||||
},
|
},
|
||||||
})
|
})
|
||||||
@@ -718,7 +718,7 @@ describe("Publishable API keys", () => {
|
|||||||
|
|
||||||
const response = await api.get(`/store/products`, {
|
const response = await api.get(`/store/products`, {
|
||||||
headers: {
|
headers: {
|
||||||
Authorization: "Bearer test_token",
|
"x-medusa-access-token": "test_token",
|
||||||
"x-publishable-api-key": pubKeyId,
|
"x-publishable-api-key": pubKeyId,
|
||||||
},
|
},
|
||||||
})
|
})
|
||||||
@@ -755,7 +755,7 @@ describe("Publishable API keys", () => {
|
|||||||
`/store/products?sales_channel_id[]=${salesChannel2.id}`,
|
`/store/products?sales_channel_id[]=${salesChannel2.id}`,
|
||||||
{
|
{
|
||||||
headers: {
|
headers: {
|
||||||
Authorization: "Bearer test_token",
|
"x-medusa-access-token": "test_token",
|
||||||
"x-publishable-api-key": pubKeyId,
|
"x-publishable-api-key": pubKeyId,
|
||||||
},
|
},
|
||||||
}
|
}
|
||||||
@@ -819,7 +819,7 @@ describe("Publishable API keys", () => {
|
|||||||
|
|
||||||
const response = await api.get(`/store/products/${product1.id}`, {
|
const response = await api.get(`/store/products/${product1.id}`, {
|
||||||
headers: {
|
headers: {
|
||||||
Authorization: "Bearer test_token",
|
"x-medusa-access-token": "test_token",
|
||||||
"x-publishable-api-key": pubKeyId,
|
"x-publishable-api-key": pubKeyId,
|
||||||
},
|
},
|
||||||
})
|
})
|
||||||
@@ -845,7 +845,7 @@ describe("Publishable API keys", () => {
|
|||||||
const response = await api
|
const response = await api
|
||||||
.get(`/store/products/${product2.id}`, {
|
.get(`/store/products/${product2.id}`, {
|
||||||
headers: {
|
headers: {
|
||||||
Authorization: "Bearer test_token",
|
"x-medusa-access-token": "test_token",
|
||||||
"x-publishable-api-key": pubKeyId,
|
"x-publishable-api-key": pubKeyId,
|
||||||
},
|
},
|
||||||
})
|
})
|
||||||
@@ -862,7 +862,7 @@ describe("Publishable API keys", () => {
|
|||||||
let response = await api
|
let response = await api
|
||||||
.get(`/store/products/${product1.id}`, {
|
.get(`/store/products/${product1.id}`, {
|
||||||
headers: {
|
headers: {
|
||||||
Authorization: "Bearer test_token",
|
"x-medusa-access-token": "test_token",
|
||||||
"x-publishable-api-key": pubKeyId,
|
"x-publishable-api-key": pubKeyId,
|
||||||
},
|
},
|
||||||
})
|
})
|
||||||
@@ -875,7 +875,7 @@ describe("Publishable API keys", () => {
|
|||||||
response = await api
|
response = await api
|
||||||
.get(`/store/products/${product2.id}`, {
|
.get(`/store/products/${product2.id}`, {
|
||||||
headers: {
|
headers: {
|
||||||
Authorization: "Bearer test_token",
|
"x-medusa-access-token": "test_token",
|
||||||
"x-publishable-api-key": pubKeyId,
|
"x-publishable-api-key": pubKeyId,
|
||||||
},
|
},
|
||||||
})
|
})
|
||||||
@@ -952,7 +952,7 @@ describe("Publishable API keys", () => {
|
|||||||
},
|
},
|
||||||
{
|
{
|
||||||
headers: {
|
headers: {
|
||||||
Authorization: "Bearer test_token",
|
"x-medusa-access-token": "test_token",
|
||||||
"x-publishable-api-key": pubKeyId,
|
"x-publishable-api-key": pubKeyId,
|
||||||
},
|
},
|
||||||
}
|
}
|
||||||
@@ -1011,7 +1011,7 @@ describe("Publishable API keys", () => {
|
|||||||
},
|
},
|
||||||
{
|
{
|
||||||
headers: {
|
headers: {
|
||||||
Authorization: "Bearer test_token",
|
"x-medusa-access-token": "test_token",
|
||||||
"x-publishable-api-key": pubKeyId,
|
"x-publishable-api-key": pubKeyId,
|
||||||
},
|
},
|
||||||
}
|
}
|
||||||
@@ -1064,7 +1064,7 @@ describe("Publishable API keys", () => {
|
|||||||
},
|
},
|
||||||
{
|
{
|
||||||
headers: {
|
headers: {
|
||||||
Authorization: "Bearer test_token",
|
"x-medusa-access-token": "test_token",
|
||||||
"x-publishable-api-key": pubKeyId,
|
"x-publishable-api-key": pubKeyId,
|
||||||
},
|
},
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -11,7 +11,7 @@ const { simpleRegionFactory } = require("../../../factories")
|
|||||||
|
|
||||||
const adminReqConfig = {
|
const adminReqConfig = {
|
||||||
headers: {
|
headers: {
|
||||||
Authorization: "Bearer test_token",
|
"x-medusa-access-token": "test_token",
|
||||||
},
|
},
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -61,7 +61,7 @@ describe("/admin/regions", () => {
|
|||||||
const response = await api
|
const response = await api
|
||||||
.delete(`/admin/regions/test-region`, {
|
.delete(`/admin/regions/test-region`, {
|
||||||
headers: {
|
headers: {
|
||||||
Authorization: "Bearer test_token",
|
"x-medusa-access-token": "test_token",
|
||||||
},
|
},
|
||||||
})
|
})
|
||||||
.catch((err) => {
|
.catch((err) => {
|
||||||
@@ -87,7 +87,7 @@ describe("/admin/regions", () => {
|
|||||||
},
|
},
|
||||||
{
|
{
|
||||||
headers: {
|
headers: {
|
||||||
Authorization: "Bearer test_token",
|
"x-medusa-access-token": "test_token",
|
||||||
},
|
},
|
||||||
}
|
}
|
||||||
)
|
)
|
||||||
@@ -159,7 +159,7 @@ describe("/admin/regions", () => {
|
|||||||
const response = await api
|
const response = await api
|
||||||
.get(`/admin/regions`, {
|
.get(`/admin/regions`, {
|
||||||
headers: {
|
headers: {
|
||||||
Authorization: "Bearer test_token",
|
"x-medusa-access-token": "test_token",
|
||||||
},
|
},
|
||||||
})
|
})
|
||||||
.catch((err) => {
|
.catch((err) => {
|
||||||
@@ -188,7 +188,7 @@ describe("/admin/regions", () => {
|
|||||||
|
|
||||||
const response = await api.get(`/admin/regions?limit=2`, {
|
const response = await api.get(`/admin/regions?limit=2`, {
|
||||||
headers: {
|
headers: {
|
||||||
Authorization: "Bearer test_token",
|
"x-medusa-access-token": "test_token",
|
||||||
},
|
},
|
||||||
})
|
})
|
||||||
|
|
||||||
@@ -203,7 +203,7 @@ describe("/admin/regions", () => {
|
|||||||
const response = await api
|
const response = await api
|
||||||
.get(`/admin/regions?updated_at[gt]=10-10-2005`, {
|
.get(`/admin/regions?updated_at[gt]=10-10-2005`, {
|
||||||
headers: {
|
headers: {
|
||||||
Authorization: "Bearer test_token",
|
"x-medusa-access-token": "test_token",
|
||||||
},
|
},
|
||||||
})
|
})
|
||||||
.catch((err) => {
|
.catch((err) => {
|
||||||
@@ -257,7 +257,7 @@ describe("/admin/regions", () => {
|
|||||||
},
|
},
|
||||||
{
|
{
|
||||||
headers: {
|
headers: {
|
||||||
Authorization: "Bearer test_token",
|
"x-medusa-access-token": "test_token",
|
||||||
},
|
},
|
||||||
}
|
}
|
||||||
)
|
)
|
||||||
@@ -265,7 +265,7 @@ describe("/admin/regions", () => {
|
|||||||
const response = await api
|
const response = await api
|
||||||
.delete(`/admin/regions/test-region`, {
|
.delete(`/admin/regions/test-region`, {
|
||||||
headers: {
|
headers: {
|
||||||
Authorization: "Bearer test_token",
|
"x-medusa-access-token": "test_token",
|
||||||
},
|
},
|
||||||
})
|
})
|
||||||
.catch((err) => {
|
.catch((err) => {
|
||||||
@@ -296,7 +296,7 @@ describe("/admin/regions", () => {
|
|||||||
},
|
},
|
||||||
{
|
{
|
||||||
headers: {
|
headers: {
|
||||||
Authorization: "Bearer test_token",
|
"x-medusa-access-token": "test_token",
|
||||||
},
|
},
|
||||||
}
|
}
|
||||||
)
|
)
|
||||||
|
|||||||
@@ -47,7 +47,7 @@ describe("/admin/return-reasons", () => {
|
|||||||
const response = await api
|
const response = await api
|
||||||
.post("/admin/return-reasons", payload, {
|
.post("/admin/return-reasons", payload, {
|
||||||
headers: {
|
headers: {
|
||||||
Authorization: "Bearer test_token",
|
"x-medusa-access-token": "test_token",
|
||||||
},
|
},
|
||||||
})
|
})
|
||||||
.catch((err) => {
|
.catch((err) => {
|
||||||
@@ -80,7 +80,7 @@ describe("/admin/return-reasons", () => {
|
|||||||
const response = await api
|
const response = await api
|
||||||
.post("/admin/return-reasons", payload, {
|
.post("/admin/return-reasons", payload, {
|
||||||
headers: {
|
headers: {
|
||||||
Authorization: "Bearer test_token",
|
"x-medusa-access-token": "test_token",
|
||||||
},
|
},
|
||||||
})
|
})
|
||||||
.catch((err) => {
|
.catch((err) => {
|
||||||
@@ -107,7 +107,7 @@ describe("/admin/return-reasons", () => {
|
|||||||
const nested_response = await api
|
const nested_response = await api
|
||||||
.post("/admin/return-reasons", nested_payload, {
|
.post("/admin/return-reasons", nested_payload, {
|
||||||
headers: {
|
headers: {
|
||||||
Authorization: "Bearer test_token",
|
"x-medusa-access-token": "test_token",
|
||||||
},
|
},
|
||||||
})
|
})
|
||||||
.catch((err) => {
|
.catch((err) => {
|
||||||
@@ -141,7 +141,7 @@ describe("/admin/return-reasons", () => {
|
|||||||
const response = await api
|
const response = await api
|
||||||
.post("/admin/return-reasons", payload, {
|
.post("/admin/return-reasons", payload, {
|
||||||
headers: {
|
headers: {
|
||||||
Authorization: "Bearer test_token",
|
"x-medusa-access-token": "test_token",
|
||||||
},
|
},
|
||||||
})
|
})
|
||||||
.catch((err) => {
|
.catch((err) => {
|
||||||
@@ -168,7 +168,7 @@ describe("/admin/return-reasons", () => {
|
|||||||
const nested_response = await api
|
const nested_response = await api
|
||||||
.post("/admin/return-reasons", nested_payload, {
|
.post("/admin/return-reasons", nested_payload, {
|
||||||
headers: {
|
headers: {
|
||||||
Authorization: "Bearer test_token",
|
"x-medusa-access-token": "test_token",
|
||||||
},
|
},
|
||||||
})
|
})
|
||||||
.catch((err) => {
|
.catch((err) => {
|
||||||
@@ -185,7 +185,7 @@ describe("/admin/return-reasons", () => {
|
|||||||
const dbl_nested_response = await api
|
const dbl_nested_response = await api
|
||||||
.post("/admin/return-reasons", dbl_nested_payload, {
|
.post("/admin/return-reasons", dbl_nested_payload, {
|
||||||
headers: {
|
headers: {
|
||||||
Authorization: "Bearer test_token",
|
"x-medusa-access-token": "test_token",
|
||||||
},
|
},
|
||||||
})
|
})
|
||||||
.catch((err) => {
|
.catch((err) => {
|
||||||
@@ -209,7 +209,7 @@ describe("/admin/return-reasons", () => {
|
|||||||
const response = await api
|
const response = await api
|
||||||
.post("/admin/return-reasons", payload, {
|
.post("/admin/return-reasons", payload, {
|
||||||
headers: {
|
headers: {
|
||||||
Authorization: "Bearer test_token",
|
"x-medusa-access-token": "test_token",
|
||||||
},
|
},
|
||||||
})
|
})
|
||||||
.catch((err) => {
|
.catch((err) => {
|
||||||
@@ -229,7 +229,7 @@ describe("/admin/return-reasons", () => {
|
|||||||
const deleteResponse = await api
|
const deleteResponse = await api
|
||||||
.delete(`/admin/return-reasons/${response.data.return_reason.id}`, {
|
.delete(`/admin/return-reasons/${response.data.return_reason.id}`, {
|
||||||
headers: {
|
headers: {
|
||||||
Authorization: "Bearer test_token",
|
"x-medusa-access-token": "test_token",
|
||||||
},
|
},
|
||||||
})
|
})
|
||||||
.catch((err) => {
|
.catch((err) => {
|
||||||
@@ -259,7 +259,7 @@ describe("/admin/return-reasons", () => {
|
|||||||
const response = await api
|
const response = await api
|
||||||
.post("/admin/return-reasons", payload, {
|
.post("/admin/return-reasons", payload, {
|
||||||
headers: {
|
headers: {
|
||||||
Authorization: "Bearer test_token",
|
"x-medusa-access-token": "test_token",
|
||||||
},
|
},
|
||||||
})
|
})
|
||||||
.catch((err) => {
|
.catch((err) => {
|
||||||
@@ -285,7 +285,7 @@ describe("/admin/return-reasons", () => {
|
|||||||
},
|
},
|
||||||
{
|
{
|
||||||
headers: {
|
headers: {
|
||||||
Authorization: "Bearer test_token",
|
"x-medusa-access-token": "test_token",
|
||||||
},
|
},
|
||||||
}
|
}
|
||||||
)
|
)
|
||||||
@@ -314,7 +314,7 @@ describe("/admin/return-reasons", () => {
|
|||||||
const response = await api
|
const response = await api
|
||||||
.post("/admin/return-reasons", payload, {
|
.post("/admin/return-reasons", payload, {
|
||||||
headers: {
|
headers: {
|
||||||
Authorization: "Bearer test_token",
|
"x-medusa-access-token": "test_token",
|
||||||
},
|
},
|
||||||
})
|
})
|
||||||
.catch((err) => {
|
.catch((err) => {
|
||||||
@@ -331,7 +331,7 @@ describe("/admin/return-reasons", () => {
|
|||||||
const resp = await api
|
const resp = await api
|
||||||
.post("/admin/return-reasons", nested_payload, {
|
.post("/admin/return-reasons", nested_payload, {
|
||||||
headers: {
|
headers: {
|
||||||
Authorization: "Bearer test_token",
|
"x-medusa-access-token": "test_token",
|
||||||
},
|
},
|
||||||
})
|
})
|
||||||
.catch((err) => {
|
.catch((err) => {
|
||||||
@@ -341,7 +341,7 @@ describe("/admin/return-reasons", () => {
|
|||||||
const nested_response = await api
|
const nested_response = await api
|
||||||
.get("/admin/return-reasons", {
|
.get("/admin/return-reasons", {
|
||||||
headers: {
|
headers: {
|
||||||
Authorization: "Bearer test_token",
|
"x-medusa-access-token": "test_token",
|
||||||
},
|
},
|
||||||
})
|
})
|
||||||
.catch((err) => {
|
.catch((err) => {
|
||||||
@@ -381,7 +381,7 @@ describe("/admin/return-reasons", () => {
|
|||||||
await api
|
await api
|
||||||
.post("/admin/return-reasons", payload, {
|
.post("/admin/return-reasons", payload, {
|
||||||
headers: {
|
headers: {
|
||||||
Authorization: "Bearer test_token",
|
"x-medusa-access-token": "test_token",
|
||||||
},
|
},
|
||||||
})
|
})
|
||||||
.catch((err) => {
|
.catch((err) => {
|
||||||
@@ -391,7 +391,7 @@ describe("/admin/return-reasons", () => {
|
|||||||
const response = await api
|
const response = await api
|
||||||
.get("/admin/return-reasons", {
|
.get("/admin/return-reasons", {
|
||||||
headers: {
|
headers: {
|
||||||
Authorization: "Bearer test_token",
|
"x-medusa-access-token": "test_token",
|
||||||
},
|
},
|
||||||
})
|
})
|
||||||
.catch((err) => {
|
.catch((err) => {
|
||||||
@@ -439,7 +439,7 @@ describe("/admin/return-reasons", () => {
|
|||||||
const response = await api
|
const response = await api
|
||||||
.post("/admin/return-reasons", payload, {
|
.post("/admin/return-reasons", payload, {
|
||||||
headers: {
|
headers: {
|
||||||
Authorization: "Bearer test_token",
|
"x-medusa-access-token": "test_token",
|
||||||
},
|
},
|
||||||
})
|
})
|
||||||
.catch((err) => {
|
.catch((err) => {
|
||||||
@@ -460,7 +460,7 @@ describe("/admin/return-reasons", () => {
|
|||||||
`/admin/return-reasons/${response.data.return_reason.id}`,
|
`/admin/return-reasons/${response.data.return_reason.id}`,
|
||||||
{
|
{
|
||||||
headers: {
|
headers: {
|
||||||
Authorization: "Bearer test_token",
|
"x-medusa-access-token": "test_token",
|
||||||
},
|
},
|
||||||
}
|
}
|
||||||
)
|
)
|
||||||
@@ -476,7 +476,7 @@ describe("/admin/return-reasons", () => {
|
|||||||
const getResult = await api
|
const getResult = await api
|
||||||
.get(`/admin/return-reasons/${response.data.return_reason.id}`, {
|
.get(`/admin/return-reasons/${response.data.return_reason.id}`, {
|
||||||
headers: {
|
headers: {
|
||||||
Authorization: "Bearer test_token",
|
"x-medusa-access-token": "test_token",
|
||||||
},
|
},
|
||||||
})
|
})
|
||||||
.catch((err) => {
|
.catch((err) => {
|
||||||
@@ -499,7 +499,7 @@ describe("/admin/return-reasons", () => {
|
|||||||
const response = await api
|
const response = await api
|
||||||
.post("/admin/return-reasons", payload, {
|
.post("/admin/return-reasons", payload, {
|
||||||
headers: {
|
headers: {
|
||||||
Authorization: "Bearer test_token",
|
"x-medusa-access-token": "test_token",
|
||||||
},
|
},
|
||||||
})
|
})
|
||||||
.catch((err) => {
|
.catch((err) => {
|
||||||
@@ -526,7 +526,7 @@ describe("/admin/return-reasons", () => {
|
|||||||
const response_child = await api
|
const response_child = await api
|
||||||
.post("/admin/return-reasons", payload_child, {
|
.post("/admin/return-reasons", payload_child, {
|
||||||
headers: {
|
headers: {
|
||||||
Authorization: "Bearer test_token",
|
"x-medusa-access-token": "test_token",
|
||||||
},
|
},
|
||||||
})
|
})
|
||||||
.catch((err) => {
|
.catch((err) => {
|
||||||
@@ -547,7 +547,7 @@ describe("/admin/return-reasons", () => {
|
|||||||
const deleteResult = await api
|
const deleteResult = await api
|
||||||
.delete(`/admin/return-reasons/${response.data.return_reason.id}`, {
|
.delete(`/admin/return-reasons/${response.data.return_reason.id}`, {
|
||||||
headers: {
|
headers: {
|
||||||
Authorization: "Bearer test_token",
|
"x-medusa-access-token": "test_token",
|
||||||
},
|
},
|
||||||
})
|
})
|
||||||
.catch((err) => {
|
.catch((err) => {
|
||||||
@@ -565,7 +565,7 @@ describe("/admin/return-reasons", () => {
|
|||||||
await api
|
await api
|
||||||
.get(`/admin/return-reasons/${response.data.return_reason.id}`, {
|
.get(`/admin/return-reasons/${response.data.return_reason.id}`, {
|
||||||
headers: {
|
headers: {
|
||||||
Authorization: "Bearer test_token",
|
"x-medusa-access-token": "test_token",
|
||||||
},
|
},
|
||||||
})
|
})
|
||||||
.catch((err) => {
|
.catch((err) => {
|
||||||
@@ -576,7 +576,7 @@ describe("/admin/return-reasons", () => {
|
|||||||
await api
|
await api
|
||||||
.get(`/admin/return-reasons/${response_child.data.return_reason.id}`, {
|
.get(`/admin/return-reasons/${response_child.data.return_reason.id}`, {
|
||||||
headers: {
|
headers: {
|
||||||
Authorization: "Bearer test_token",
|
"x-medusa-access-token": "test_token",
|
||||||
},
|
},
|
||||||
})
|
})
|
||||||
.catch((err) => {
|
.catch((err) => {
|
||||||
|
|||||||
@@ -15,7 +15,7 @@ jest.setTimeout(30000)
|
|||||||
|
|
||||||
const authHeader = {
|
const authHeader = {
|
||||||
headers: {
|
headers: {
|
||||||
Authorization: "Bearer test_token",
|
"x-medusa-access-token": "test_token",
|
||||||
},
|
},
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -181,7 +181,7 @@ describe("/admin/returns", () => {
|
|||||||
{},
|
{},
|
||||||
{
|
{
|
||||||
headers: {
|
headers: {
|
||||||
Authorization: "Bearer test_token",
|
"x-medusa-access-token": "test_token",
|
||||||
},
|
},
|
||||||
}
|
}
|
||||||
)
|
)
|
||||||
|
|||||||
@@ -19,7 +19,7 @@ const startServerWithEnvironment =
|
|||||||
|
|
||||||
const adminReqConfig = {
|
const adminReqConfig = {
|
||||||
headers: {
|
headers: {
|
||||||
Authorization: "Bearer test_token",
|
"x-medusa-access-token": "test_token",
|
||||||
},
|
},
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -214,7 +214,7 @@ describe("sales channels", () => {
|
|||||||
payload,
|
payload,
|
||||||
{
|
{
|
||||||
headers: {
|
headers: {
|
||||||
authorization: "Bearer test_token",
|
"x-medusa-access-token": "test_token",
|
||||||
},
|
},
|
||||||
}
|
}
|
||||||
)
|
)
|
||||||
@@ -856,7 +856,7 @@ describe("sales channels", () => {
|
|||||||
`/admin/orders?sales_channel_id[]=${order.sales_channel_id}`,
|
`/admin/orders?sales_channel_id[]=${order.sales_channel_id}`,
|
||||||
{
|
{
|
||||||
headers: {
|
headers: {
|
||||||
authorization: "Bearer test_token",
|
"x-medusa-access-token": "test_token",
|
||||||
},
|
},
|
||||||
}
|
}
|
||||||
)
|
)
|
||||||
@@ -904,7 +904,7 @@ describe("sales channels", () => {
|
|||||||
const response = await api
|
const response = await api
|
||||||
.get(`/admin/products?sales_channel_id[]=${salesChannel.id}`, {
|
.get(`/admin/products?sales_channel_id[]=${salesChannel.id}`, {
|
||||||
headers: {
|
headers: {
|
||||||
Authorization: "Bearer test_token",
|
"x-medusa-access-token": "test_token",
|
||||||
},
|
},
|
||||||
})
|
})
|
||||||
.catch((err) => {
|
.catch((err) => {
|
||||||
@@ -964,7 +964,7 @@ describe("sales channels", () => {
|
|||||||
const response = await api
|
const response = await api
|
||||||
.post("/admin/products", payload, {
|
.post("/admin/products", payload, {
|
||||||
headers: {
|
headers: {
|
||||||
Authorization: "Bearer test_token",
|
"x-medusa-access-token": "test_token",
|
||||||
},
|
},
|
||||||
})
|
})
|
||||||
.catch((err) => {
|
.catch((err) => {
|
||||||
@@ -1005,7 +1005,7 @@ describe("sales channels", () => {
|
|||||||
const response = await api
|
const response = await api
|
||||||
.post("/admin/products", payload, {
|
.post("/admin/products", payload, {
|
||||||
headers: {
|
headers: {
|
||||||
Authorization: "Bearer test_token",
|
"x-medusa-access-token": "test_token",
|
||||||
},
|
},
|
||||||
})
|
})
|
||||||
.catch((err) => {
|
.catch((err) => {
|
||||||
@@ -1054,7 +1054,7 @@ describe("sales channels", () => {
|
|||||||
},
|
},
|
||||||
{
|
{
|
||||||
headers: {
|
headers: {
|
||||||
Authorization: "Bearer test_token",
|
"x-medusa-access-token": "test_token",
|
||||||
},
|
},
|
||||||
}
|
}
|
||||||
)
|
)
|
||||||
@@ -1077,7 +1077,7 @@ describe("sales channels", () => {
|
|||||||
},
|
},
|
||||||
{
|
{
|
||||||
headers: {
|
headers: {
|
||||||
Authorization: "Bearer test_token",
|
"x-medusa-access-token": "test_token",
|
||||||
},
|
},
|
||||||
}
|
}
|
||||||
)
|
)
|
||||||
@@ -1103,7 +1103,7 @@ describe("sales channels", () => {
|
|||||||
{},
|
{},
|
||||||
{
|
{
|
||||||
headers: {
|
headers: {
|
||||||
Authorization: "Bearer test_token",
|
"x-medusa-access-token": "test_token",
|
||||||
},
|
},
|
||||||
}
|
}
|
||||||
)
|
)
|
||||||
@@ -1131,7 +1131,7 @@ describe("sales channels", () => {
|
|||||||
},
|
},
|
||||||
{
|
{
|
||||||
headers: {
|
headers: {
|
||||||
Authorization: "Bearer test_token",
|
"x-medusa-access-token": "test_token",
|
||||||
},
|
},
|
||||||
}
|
}
|
||||||
)
|
)
|
||||||
@@ -1158,7 +1158,7 @@ describe("sales channels", () => {
|
|||||||
},
|
},
|
||||||
{
|
{
|
||||||
headers: {
|
headers: {
|
||||||
Authorization: "Bearer test_token",
|
"x-medusa-access-token": "test_token",
|
||||||
},
|
},
|
||||||
}
|
}
|
||||||
)
|
)
|
||||||
|
|||||||
@@ -15,7 +15,7 @@ const {
|
|||||||
|
|
||||||
const adminReqConfig = {
|
const adminReqConfig = {
|
||||||
headers: {
|
headers: {
|
||||||
Authorization: "Bearer test_token",
|
"x-medusa-access-token": "test_token",
|
||||||
},
|
},
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -68,7 +68,7 @@ describe("/admin/shipping-options", () => {
|
|||||||
|
|
||||||
const res = await api.post(`/admin/shipping-options/test-out`, payload, {
|
const res = await api.post(`/admin/shipping-options/test-out`, payload, {
|
||||||
headers: {
|
headers: {
|
||||||
Authorization: "Bearer test_token",
|
"x-medusa-access-token": "test_token",
|
||||||
},
|
},
|
||||||
})
|
})
|
||||||
|
|
||||||
@@ -115,7 +115,7 @@ describe("/admin/shipping-options", () => {
|
|||||||
const res = await api
|
const res = await api
|
||||||
.post(`/admin/shipping-options/test-out`, payload, {
|
.post(`/admin/shipping-options/test-out`, payload, {
|
||||||
headers: {
|
headers: {
|
||||||
Authorization: "Bearer test_token",
|
"x-medusa-access-token": "test_token",
|
||||||
},
|
},
|
||||||
})
|
})
|
||||||
.catch((err) => {
|
.catch((err) => {
|
||||||
@@ -150,7 +150,7 @@ describe("/admin/shipping-options", () => {
|
|||||||
const res = await api
|
const res = await api
|
||||||
.post(`/admin/shipping-options/test-option-req`, payload, {
|
.post(`/admin/shipping-options/test-option-req`, payload, {
|
||||||
headers: {
|
headers: {
|
||||||
Authorization: "Bearer test_token",
|
"x-medusa-access-token": "test_token",
|
||||||
},
|
},
|
||||||
})
|
})
|
||||||
.catch((err) => {
|
.catch((err) => {
|
||||||
@@ -176,7 +176,7 @@ describe("/admin/shipping-options", () => {
|
|||||||
const res = await api
|
const res = await api
|
||||||
.post(`/admin/shipping-options/test-option-req`, payload, {
|
.post(`/admin/shipping-options/test-option-req`, payload, {
|
||||||
headers: {
|
headers: {
|
||||||
Authorization: "Bearer test_token",
|
"x-medusa-access-token": "test_token",
|
||||||
},
|
},
|
||||||
})
|
})
|
||||||
.catch((err) => {
|
.catch((err) => {
|
||||||
@@ -207,7 +207,7 @@ describe("/admin/shipping-options", () => {
|
|||||||
const res = await api
|
const res = await api
|
||||||
.post(`/admin/shipping-options/test-option-req`, payload, {
|
.post(`/admin/shipping-options/test-option-req`, payload, {
|
||||||
headers: {
|
headers: {
|
||||||
Authorization: "Bearer test_token",
|
"x-medusa-access-token": "test_token",
|
||||||
},
|
},
|
||||||
})
|
})
|
||||||
.catch((err) => {
|
.catch((err) => {
|
||||||
@@ -240,7 +240,7 @@ describe("/admin/shipping-options", () => {
|
|||||||
const res = await api
|
const res = await api
|
||||||
.post(`/admin/shipping-options/test-option-req`, payload, {
|
.post(`/admin/shipping-options/test-option-req`, payload, {
|
||||||
headers: {
|
headers: {
|
||||||
Authorization: "Bearer test_token",
|
"x-medusa-access-token": "test_token",
|
||||||
},
|
},
|
||||||
})
|
})
|
||||||
.catch((err) => {
|
.catch((err) => {
|
||||||
@@ -269,7 +269,7 @@ describe("/admin/shipping-options", () => {
|
|||||||
},
|
},
|
||||||
{
|
{
|
||||||
headers: {
|
headers: {
|
||||||
Authorization: "Bearer test_token",
|
"x-medusa-access-token": "test_token",
|
||||||
},
|
},
|
||||||
}
|
}
|
||||||
)
|
)
|
||||||
@@ -312,7 +312,7 @@ describe("/admin/shipping-options", () => {
|
|||||||
|
|
||||||
const res = await api.post(`/admin/shipping-options`, payload, {
|
const res = await api.post(`/admin/shipping-options`, payload, {
|
||||||
headers: {
|
headers: {
|
||||||
Authorization: "Bearer test_token",
|
"x-medusa-access-token": "test_token",
|
||||||
},
|
},
|
||||||
})
|
})
|
||||||
|
|
||||||
@@ -324,7 +324,7 @@ describe("/admin/shipping-options", () => {
|
|||||||
const api = useApi()
|
const api = useApi()
|
||||||
const res = await api.post(`/admin/shipping-options`, payload, {
|
const res = await api.post(`/admin/shipping-options`, payload, {
|
||||||
headers: {
|
headers: {
|
||||||
Authorization: "Bearer test_token",
|
"x-medusa-access-token": "test_token",
|
||||||
},
|
},
|
||||||
})
|
})
|
||||||
|
|
||||||
@@ -348,7 +348,7 @@ describe("/admin/shipping-options", () => {
|
|||||||
try {
|
try {
|
||||||
await api.post(`/admin/shipping-options`, payload, {
|
await api.post(`/admin/shipping-options`, payload, {
|
||||||
headers: {
|
headers: {
|
||||||
Authorization: "Bearer test_token",
|
"x-medusa-access-token": "test_token",
|
||||||
},
|
},
|
||||||
})
|
})
|
||||||
} catch (error) {
|
} catch (error) {
|
||||||
@@ -374,7 +374,7 @@ describe("/admin/shipping-options", () => {
|
|||||||
try {
|
try {
|
||||||
await api.post(`/admin/shipping-options`, payload, {
|
await api.post(`/admin/shipping-options`, payload, {
|
||||||
headers: {
|
headers: {
|
||||||
Authorization: "Bearer test_token",
|
"x-medusa-access-token": "test_token",
|
||||||
},
|
},
|
||||||
})
|
})
|
||||||
} catch (error) {
|
} catch (error) {
|
||||||
@@ -399,7 +399,7 @@ describe("/admin/shipping-options", () => {
|
|||||||
const api = useApi()
|
const api = useApi()
|
||||||
const res = await api.get(`/admin/shipping-options`, {
|
const res = await api.get(`/admin/shipping-options`, {
|
||||||
headers: {
|
headers: {
|
||||||
Authorization: "Bearer test_token",
|
"x-medusa-access-token": "test_token",
|
||||||
},
|
},
|
||||||
})
|
})
|
||||||
|
|
||||||
@@ -410,7 +410,7 @@ describe("/admin/shipping-options", () => {
|
|||||||
const api = useApi()
|
const api = useApi()
|
||||||
const res = await api.get(`/admin/shipping-options?admin_only=true`, {
|
const res = await api.get(`/admin/shipping-options?admin_only=true`, {
|
||||||
headers: {
|
headers: {
|
||||||
Authorization: "Bearer test_token",
|
"x-medusa-access-token": "test_token",
|
||||||
},
|
},
|
||||||
})
|
})
|
||||||
|
|
||||||
@@ -429,7 +429,7 @@ describe("/admin/shipping-options", () => {
|
|||||||
const api = useApi()
|
const api = useApi()
|
||||||
const res = await api.get(`/admin/shipping-options?is_return=true`, {
|
const res = await api.get(`/admin/shipping-options?is_return=true`, {
|
||||||
headers: {
|
headers: {
|
||||||
Authorization: "Bearer test_token",
|
"x-medusa-access-token": "test_token",
|
||||||
},
|
},
|
||||||
})
|
})
|
||||||
|
|
||||||
@@ -450,7 +450,7 @@ describe("/admin/shipping-options", () => {
|
|||||||
`/admin/shipping-options?is_return=false&admin_only=true`,
|
`/admin/shipping-options?is_return=false&admin_only=true`,
|
||||||
{
|
{
|
||||||
headers: {
|
headers: {
|
||||||
Authorization: "Bearer test_token",
|
"x-medusa-access-token": "test_token",
|
||||||
},
|
},
|
||||||
}
|
}
|
||||||
)
|
)
|
||||||
|
|||||||
@@ -12,7 +12,7 @@ const adminSeeder = require("../../../helpers/admin-seeder")
|
|||||||
|
|
||||||
const adminReqConfig = {
|
const adminReqConfig = {
|
||||||
headers: {
|
headers: {
|
||||||
Authorization: "Bearer test_token",
|
"x-medusa-access-token": "test_token",
|
||||||
},
|
},
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -40,7 +40,7 @@ describe("/admin/store", () => {
|
|||||||
const api = useApi()
|
const api = useApi()
|
||||||
|
|
||||||
const response = await api.get("/admin/store", {
|
const response = await api.get("/admin/store", {
|
||||||
headers: { Authorization: "Bearer test_token " },
|
headers: { "x-medusa-access-token": "test_token " },
|
||||||
})
|
})
|
||||||
|
|
||||||
expect(response.status).toEqual(200)
|
expect(response.status).toEqual(200)
|
||||||
@@ -99,7 +99,7 @@ describe("/admin/store", () => {
|
|||||||
default_currency_code: "eur",
|
default_currency_code: "eur",
|
||||||
},
|
},
|
||||||
{
|
{
|
||||||
headers: { Authorization: "Bearer test_token " },
|
headers: { "x-medusa-access-token": "test_token " },
|
||||||
}
|
}
|
||||||
)
|
)
|
||||||
} catch (e) {
|
} catch (e) {
|
||||||
@@ -121,7 +121,7 @@ describe("/admin/store", () => {
|
|||||||
currencies: ["usd"],
|
currencies: ["usd"],
|
||||||
},
|
},
|
||||||
{
|
{
|
||||||
headers: { Authorization: "Bearer test_token " },
|
headers: { "x-medusa-access-token": "test_token " },
|
||||||
}
|
}
|
||||||
)
|
)
|
||||||
} catch (e) {
|
} catch (e) {
|
||||||
@@ -144,7 +144,7 @@ describe("/admin/store", () => {
|
|||||||
default_currency_code: "dkk",
|
default_currency_code: "dkk",
|
||||||
},
|
},
|
||||||
{
|
{
|
||||||
headers: { Authorization: "Bearer test_token " },
|
headers: { "x-medusa-access-token": "test_token " },
|
||||||
}
|
}
|
||||||
)
|
)
|
||||||
.catch((err) => console.log(err))
|
.catch((err) => console.log(err))
|
||||||
@@ -180,7 +180,7 @@ describe("/admin/store", () => {
|
|||||||
currencies: ["jpy", "usd"],
|
currencies: ["jpy", "usd"],
|
||||||
},
|
},
|
||||||
{
|
{
|
||||||
headers: { Authorization: "Bearer test_token " },
|
headers: { "x-medusa-access-token": "test_token " },
|
||||||
}
|
}
|
||||||
)
|
)
|
||||||
|
|
||||||
@@ -214,7 +214,7 @@ describe("/admin/store", () => {
|
|||||||
currencies: ["jpy", "usd"],
|
currencies: ["jpy", "usd"],
|
||||||
},
|
},
|
||||||
{
|
{
|
||||||
headers: { Authorization: "Bearer test_token " },
|
headers: { "x-medusa-access-token": "test_token " },
|
||||||
}
|
}
|
||||||
)
|
)
|
||||||
|
|
||||||
|
|||||||
@@ -26,7 +26,7 @@ jest.setTimeout(30000)
|
|||||||
|
|
||||||
const adminHeaders = {
|
const adminHeaders = {
|
||||||
headers: {
|
headers: {
|
||||||
Authorization: "Bearer test_token",
|
"x-medusa-access-token": "test_token",
|
||||||
},
|
},
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -17,7 +17,7 @@ jest.setTimeout(30000)
|
|||||||
|
|
||||||
const adminReqConfig = {
|
const adminReqConfig = {
|
||||||
headers: {
|
headers: {
|
||||||
Authorization: "Bearer test_token",
|
"x-medusa-access-token": "test_token",
|
||||||
},
|
},
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -331,7 +331,7 @@ describe("/admin/users", () => {
|
|||||||
const usersBeforeDelete = usersBeforeDeleteResponse.data.users
|
const usersBeforeDelete = usersBeforeDeleteResponse.data.users
|
||||||
|
|
||||||
const response = await api.delete(`/admin/users/${userId}`, {
|
const response = await api.delete(`/admin/users/${userId}`, {
|
||||||
headers: { Authorization: "Bearer test_token" },
|
headers: { "x-medusa-access-token": "test_token" },
|
||||||
})
|
})
|
||||||
|
|
||||||
const usersAfterDeleteResponse = await api.get(
|
const usersAfterDeleteResponse = await api.get(
|
||||||
|
|||||||
@@ -11,7 +11,7 @@ const productSeeder = require("../../../helpers/product-seeder")
|
|||||||
|
|
||||||
const adminHeaders = {
|
const adminHeaders = {
|
||||||
headers: {
|
headers: {
|
||||||
Authorization: "Bearer test_token",
|
"x-medusa-access-token": "test_token",
|
||||||
},
|
},
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -13,7 +13,7 @@ jest.setTimeout(50000)
|
|||||||
|
|
||||||
const adminReqConfig = {
|
const adminReqConfig = {
|
||||||
headers: {
|
headers: {
|
||||||
Authorization: "Bearer test_token",
|
"x-medusa-access-token": "test_token",
|
||||||
},
|
},
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -12,7 +12,7 @@ const orderSeeder = require("../../../../helpers/order-seeder")
|
|||||||
|
|
||||||
const adminReqConfig = {
|
const adminReqConfig = {
|
||||||
headers: {
|
headers: {
|
||||||
Authorization: "Bearer test_token",
|
"x-medusa-access-token": "test_token",
|
||||||
},
|
},
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -14,7 +14,7 @@ const {
|
|||||||
|
|
||||||
const adminReqConfig = {
|
const adminReqConfig = {
|
||||||
headers: {
|
headers: {
|
||||||
Authorization: "Bearer test_token",
|
"x-medusa-access-token": "test_token",
|
||||||
},
|
},
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -13,7 +13,7 @@ const productSeeder = require("../../../../helpers/product-seeder")
|
|||||||
|
|
||||||
const adminReqConfig = {
|
const adminReqConfig = {
|
||||||
headers: {
|
headers: {
|
||||||
Authorization: "Bearer test_token",
|
"x-medusa-access-token": "test_token",
|
||||||
},
|
},
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -39,7 +39,7 @@ function copyTemplateFile() {
|
|||||||
|
|
||||||
const adminReqConfig = {
|
const adminReqConfig = {
|
||||||
headers: {
|
headers: {
|
||||||
Authorization: "Bearer test_token",
|
"x-medusa-access-token": "test_token",
|
||||||
},
|
},
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -39,7 +39,7 @@ function copyTemplateFile() {
|
|||||||
|
|
||||||
const adminReqConfig = {
|
const adminReqConfig = {
|
||||||
headers: {
|
headers: {
|
||||||
Authorization: "Bearer test_token",
|
"x-medusa-access-token": "test_token",
|
||||||
},
|
},
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -15,7 +15,7 @@ const {
|
|||||||
|
|
||||||
const adminReqConfig = {
|
const adminReqConfig = {
|
||||||
headers: {
|
headers: {
|
||||||
Authorization: "Bearer test_token",
|
"x-medusa-access-token": "test_token",
|
||||||
},
|
},
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -59,7 +59,7 @@ describe("Claims", () => {
|
|||||||
},
|
},
|
||||||
{
|
{
|
||||||
headers: {
|
headers: {
|
||||||
authorization: "Bearer test_token",
|
"x-medusa-access-token": "test_token",
|
||||||
},
|
},
|
||||||
}
|
}
|
||||||
)
|
)
|
||||||
@@ -100,7 +100,7 @@ describe("Claims", () => {
|
|||||||
},
|
},
|
||||||
{
|
{
|
||||||
headers: {
|
headers: {
|
||||||
authorization: "Bearer test_token",
|
"x-medusa-access-token": "test_token",
|
||||||
},
|
},
|
||||||
}
|
}
|
||||||
)
|
)
|
||||||
@@ -144,7 +144,7 @@ describe("Claims", () => {
|
|||||||
},
|
},
|
||||||
{
|
{
|
||||||
headers: {
|
headers: {
|
||||||
authorization: "Bearer test_token",
|
"x-medusa-access-token": "test_token",
|
||||||
},
|
},
|
||||||
}
|
}
|
||||||
)
|
)
|
||||||
@@ -183,7 +183,7 @@ describe("Claims", () => {
|
|||||||
},
|
},
|
||||||
{
|
{
|
||||||
headers: {
|
headers: {
|
||||||
authorization: "Bearer test_token",
|
"x-medusa-access-token": "test_token",
|
||||||
},
|
},
|
||||||
}
|
}
|
||||||
)
|
)
|
||||||
@@ -219,7 +219,7 @@ describe("Claims", () => {
|
|||||||
},
|
},
|
||||||
{
|
{
|
||||||
headers: {
|
headers: {
|
||||||
authorization: "Bearer test_token",
|
"x-medusa-access-token": "test_token",
|
||||||
},
|
},
|
||||||
}
|
}
|
||||||
)
|
)
|
||||||
@@ -284,7 +284,7 @@ describe("Claims", () => {
|
|||||||
},
|
},
|
||||||
{
|
{
|
||||||
headers: {
|
headers: {
|
||||||
authorization: "Bearer test_token",
|
"x-medusa-access-token": "test_token",
|
||||||
},
|
},
|
||||||
}
|
}
|
||||||
)
|
)
|
||||||
@@ -294,7 +294,7 @@ describe("Claims", () => {
|
|||||||
{},
|
{},
|
||||||
{
|
{
|
||||||
headers: {
|
headers: {
|
||||||
authorization: "Bearer test_token",
|
"x-medusa-access-token": "test_token",
|
||||||
},
|
},
|
||||||
}
|
}
|
||||||
)
|
)
|
||||||
@@ -333,7 +333,7 @@ describe("Claims", () => {
|
|||||||
},
|
},
|
||||||
{
|
{
|
||||||
headers: {
|
headers: {
|
||||||
authorization: "Bearer test_token",
|
"x-medusa-access-token": "test_token",
|
||||||
},
|
},
|
||||||
}
|
}
|
||||||
)
|
)
|
||||||
|
|||||||
@@ -693,7 +693,7 @@ describe("tax inclusive prices", () => {
|
|||||||
|
|
||||||
const res = await api.get(`/admin/shipping-options`, {
|
const res = await api.get(`/admin/shipping-options`, {
|
||||||
headers: {
|
headers: {
|
||||||
Authorization: `Bearer test_token`,
|
"x-medusa-access-token": "test_token",
|
||||||
},
|
},
|
||||||
})
|
})
|
||||||
|
|
||||||
|
|||||||
@@ -117,7 +117,7 @@ describe("[MEDUSA_FF_TAX_INCLUSIVE_PRICING] /store/carts", () => {
|
|||||||
},
|
},
|
||||||
{
|
{
|
||||||
headers: {
|
headers: {
|
||||||
authorization: "Bearer test_token",
|
"x-medusa-access-token": "test_token",
|
||||||
},
|
},
|
||||||
}
|
}
|
||||||
)
|
)
|
||||||
@@ -163,7 +163,7 @@ describe("[MEDUSA_FF_TAX_INCLUSIVE_PRICING] /store/carts", () => {
|
|||||||
},
|
},
|
||||||
{
|
{
|
||||||
headers: {
|
headers: {
|
||||||
authorization: "Bearer test_token",
|
"x-medusa-access-token": "test_token",
|
||||||
},
|
},
|
||||||
}
|
}
|
||||||
)
|
)
|
||||||
@@ -208,7 +208,7 @@ describe("[MEDUSA_FF_TAX_INCLUSIVE_PRICING] /store/carts", () => {
|
|||||||
},
|
},
|
||||||
{
|
{
|
||||||
headers: {
|
headers: {
|
||||||
authorization: "Bearer test_token",
|
"x-medusa-access-token": "test_token",
|
||||||
},
|
},
|
||||||
}
|
}
|
||||||
)
|
)
|
||||||
@@ -253,7 +253,7 @@ describe("[MEDUSA_FF_TAX_INCLUSIVE_PRICING] /store/carts", () => {
|
|||||||
},
|
},
|
||||||
{
|
{
|
||||||
headers: {
|
headers: {
|
||||||
authorization: "Bearer test_token",
|
"x-medusa-access-token": "test_token",
|
||||||
},
|
},
|
||||||
}
|
}
|
||||||
)
|
)
|
||||||
|
|||||||
@@ -20,7 +20,7 @@ jest.setTimeout(30000)
|
|||||||
|
|
||||||
const adminHeaders = {
|
const adminHeaders = {
|
||||||
headers: {
|
headers: {
|
||||||
authorization: "Bearer test_token",
|
"x-medusa-access-token": "test_token",
|
||||||
},
|
},
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -130,5 +130,26 @@ describe("/store/auth", () => {
|
|||||||
expect(err.response.status).toEqual(401)
|
expect(err.response.status).toEqual(401)
|
||||||
}
|
}
|
||||||
})
|
})
|
||||||
|
|
||||||
|
it("creates customer JWT token correctly", async () => {
|
||||||
|
const api = useApi()
|
||||||
|
|
||||||
|
const authResponse = await api.post("/store/auth/token", {
|
||||||
|
email: "oli@test.dk",
|
||||||
|
password: "test",
|
||||||
|
})
|
||||||
|
|
||||||
|
const token = authResponse.data.access_token;
|
||||||
|
|
||||||
|
expect(token).toEqual(expect.any(String))
|
||||||
|
|
||||||
|
const me = await api.get("/store/auth", {
|
||||||
|
headers: {
|
||||||
|
Authorization: `Bearer ${token}`,
|
||||||
|
},
|
||||||
|
})
|
||||||
|
|
||||||
|
expect(me.status).toEqual(200)
|
||||||
|
})
|
||||||
})
|
})
|
||||||
})
|
})
|
||||||
@@ -972,7 +972,7 @@ describe("/store/products", () => {
|
|||||||
},
|
},
|
||||||
{
|
{
|
||||||
headers: {
|
headers: {
|
||||||
Authorization: "Bearer test_token",
|
"x-medusa-access-token": "test_token",
|
||||||
},
|
},
|
||||||
}
|
}
|
||||||
)
|
)
|
||||||
|
|||||||
@@ -16,7 +16,7 @@ const startServerWithEnvironment =
|
|||||||
|
|
||||||
const adminReqConfig = {
|
const adminReqConfig = {
|
||||||
headers: {
|
headers: {
|
||||||
Authorization: "Bearer test_token",
|
"x-medusa-access-token": "test_token",
|
||||||
},
|
},
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -63,7 +63,7 @@ describe("Swaps", () => {
|
|||||||
},
|
},
|
||||||
{
|
{
|
||||||
headers: {
|
headers: {
|
||||||
authorization: "Bearer test_token",
|
"x-medusa-access-token": "test_token",
|
||||||
},
|
},
|
||||||
}
|
}
|
||||||
)
|
)
|
||||||
@@ -122,7 +122,7 @@ describe("Swaps", () => {
|
|||||||
},
|
},
|
||||||
{
|
{
|
||||||
headers: {
|
headers: {
|
||||||
authorization: "Bearer test_token",
|
"x-medusa-access-token": "test_token",
|
||||||
},
|
},
|
||||||
}
|
}
|
||||||
)
|
)
|
||||||
@@ -182,7 +182,7 @@ describe("Swaps", () => {
|
|||||||
},
|
},
|
||||||
{
|
{
|
||||||
headers: {
|
headers: {
|
||||||
authorization: "Bearer test_token",
|
"x-medusa-access-token": "test_token",
|
||||||
},
|
},
|
||||||
}
|
}
|
||||||
)
|
)
|
||||||
@@ -193,7 +193,7 @@ describe("Swaps", () => {
|
|||||||
`/admin/swaps/${response.data.order.swaps[0].id}`,
|
`/admin/swaps/${response.data.order.swaps[0].id}`,
|
||||||
{
|
{
|
||||||
headers: {
|
headers: {
|
||||||
authorization: "Bearer test_token",
|
"x-medusa-access-token": "test_token",
|
||||||
},
|
},
|
||||||
}
|
}
|
||||||
)
|
)
|
||||||
@@ -281,7 +281,7 @@ describe("Swaps", () => {
|
|||||||
},
|
},
|
||||||
{
|
{
|
||||||
headers: {
|
headers: {
|
||||||
authorization: "Bearer test_token",
|
"x-medusa-access-token": "test_token",
|
||||||
},
|
},
|
||||||
}
|
}
|
||||||
)
|
)
|
||||||
|
|||||||
@@ -48,7 +48,7 @@ describe("/admin/tax-rates", () => {
|
|||||||
|
|
||||||
const response = await api.get("/admin/tax-rates", {
|
const response = await api.get("/admin/tax-rates", {
|
||||||
headers: {
|
headers: {
|
||||||
authorization: "Bearer test_token",
|
"x-medusa-access-token": "test_token",
|
||||||
},
|
},
|
||||||
})
|
})
|
||||||
|
|
||||||
@@ -66,7 +66,7 @@ describe("/admin/tax-rates", () => {
|
|||||||
`/admin/tax-rates?fields[]=rate&fields[]=product_count&fields[]=id&expand[]=products&rate[gt]=80`,
|
`/admin/tax-rates?fields[]=rate&fields[]=product_count&fields[]=id&expand[]=products&rate[gt]=80`,
|
||||||
{
|
{
|
||||||
headers: {
|
headers: {
|
||||||
authorization: "Bearer test_token",
|
"x-medusa-access-token": "test_token",
|
||||||
},
|
},
|
||||||
}
|
}
|
||||||
)
|
)
|
||||||
@@ -85,7 +85,7 @@ describe("/admin/tax-rates", () => {
|
|||||||
`/admin/tax-rates?region_id[]=${regions[0].id}®ion_id[]=${regions[1].id}`,
|
`/admin/tax-rates?region_id[]=${regions[0].id}®ion_id[]=${regions[1].id}`,
|
||||||
{
|
{
|
||||||
headers: {
|
headers: {
|
||||||
authorization: "Bearer test_token",
|
"x-medusa-access-token": "test_token",
|
||||||
},
|
},
|
||||||
}
|
}
|
||||||
)
|
)
|
||||||
@@ -106,7 +106,7 @@ describe("/admin/tax-rates", () => {
|
|||||||
|
|
||||||
const response = await api.get(`/admin/tax-rates/${tax_rates[0].id}`, {
|
const response = await api.get(`/admin/tax-rates/${tax_rates[0].id}`, {
|
||||||
headers: {
|
headers: {
|
||||||
authorization: "Bearer test_token",
|
"x-medusa-access-token": "test_token",
|
||||||
},
|
},
|
||||||
})
|
})
|
||||||
|
|
||||||
@@ -129,7 +129,7 @@ describe("/admin/tax-rates", () => {
|
|||||||
`/admin/tax-rates/${tax_rates[0].id}?fields[]=id&fields[]=region_id`,
|
`/admin/tax-rates/${tax_rates[0].id}?fields[]=id&fields[]=region_id`,
|
||||||
{
|
{
|
||||||
headers: {
|
headers: {
|
||||||
authorization: "Bearer test_token",
|
"x-medusa-access-token": "test_token",
|
||||||
},
|
},
|
||||||
}
|
}
|
||||||
)
|
)
|
||||||
@@ -159,7 +159,7 @@ describe("/admin/tax-rates", () => {
|
|||||||
},
|
},
|
||||||
{
|
{
|
||||||
headers: {
|
headers: {
|
||||||
authorization: "Bearer test_token",
|
"x-medusa-access-token": "test_token",
|
||||||
},
|
},
|
||||||
}
|
}
|
||||||
)
|
)
|
||||||
@@ -191,7 +191,7 @@ describe("/admin/tax-rates", () => {
|
|||||||
},
|
},
|
||||||
{
|
{
|
||||||
headers: {
|
headers: {
|
||||||
authorization: "Bearer test_token",
|
"x-medusa-access-token": "test_token",
|
||||||
},
|
},
|
||||||
}
|
}
|
||||||
)
|
)
|
||||||
@@ -231,7 +231,7 @@ describe("/admin/tax-rates", () => {
|
|||||||
},
|
},
|
||||||
{
|
{
|
||||||
headers: {
|
headers: {
|
||||||
authorization: "Bearer test_token",
|
"x-medusa-access-token": "test_token",
|
||||||
},
|
},
|
||||||
}
|
}
|
||||||
)
|
)
|
||||||
@@ -260,7 +260,7 @@ describe("/admin/tax-rates", () => {
|
|||||||
},
|
},
|
||||||
{
|
{
|
||||||
headers: {
|
headers: {
|
||||||
authorization: "Bearer test_token",
|
"x-medusa-access-token": "test_token",
|
||||||
},
|
},
|
||||||
}
|
}
|
||||||
)
|
)
|
||||||
@@ -294,7 +294,7 @@ describe("/admin/tax-rates", () => {
|
|||||||
},
|
},
|
||||||
{
|
{
|
||||||
headers: {
|
headers: {
|
||||||
authorization: "Bearer test_token",
|
"x-medusa-access-token": "test_token",
|
||||||
},
|
},
|
||||||
}
|
}
|
||||||
)
|
)
|
||||||
@@ -330,7 +330,7 @@ describe("/admin/tax-rates", () => {
|
|||||||
},
|
},
|
||||||
{
|
{
|
||||||
headers: {
|
headers: {
|
||||||
authorization: "Bearer test_token",
|
"x-medusa-access-token": "test_token",
|
||||||
},
|
},
|
||||||
}
|
}
|
||||||
)
|
)
|
||||||
@@ -361,7 +361,7 @@ describe("/admin/tax-rates", () => {
|
|||||||
},
|
},
|
||||||
{
|
{
|
||||||
headers: {
|
headers: {
|
||||||
authorization: "Bearer test_token",
|
"x-medusa-access-token": "test_token",
|
||||||
},
|
},
|
||||||
}
|
}
|
||||||
)
|
)
|
||||||
@@ -391,7 +391,7 @@ describe("/admin/tax-rates", () => {
|
|||||||
},
|
},
|
||||||
{
|
{
|
||||||
headers: {
|
headers: {
|
||||||
authorization: "Bearer test_token",
|
"x-medusa-access-token": "test_token",
|
||||||
},
|
},
|
||||||
}
|
}
|
||||||
)
|
)
|
||||||
@@ -425,7 +425,7 @@ describe("/admin/tax-rates", () => {
|
|||||||
},
|
},
|
||||||
{
|
{
|
||||||
headers: {
|
headers: {
|
||||||
authorization: "Bearer test_token",
|
"x-medusa-access-token": "test_token",
|
||||||
},
|
},
|
||||||
}
|
}
|
||||||
)
|
)
|
||||||
@@ -460,7 +460,7 @@ describe("/admin/tax-rates", () => {
|
|||||||
},
|
},
|
||||||
{
|
{
|
||||||
headers: {
|
headers: {
|
||||||
authorization: "Bearer test_token",
|
"x-medusa-access-token": "test_token",
|
||||||
},
|
},
|
||||||
}
|
}
|
||||||
)
|
)
|
||||||
@@ -499,7 +499,7 @@ describe("/admin/tax-rates", () => {
|
|||||||
},
|
},
|
||||||
{
|
{
|
||||||
headers: {
|
headers: {
|
||||||
authorization: "Bearer test_token",
|
"x-medusa-access-token": "test_token",
|
||||||
},
|
},
|
||||||
}
|
}
|
||||||
)
|
)
|
||||||
@@ -530,7 +530,7 @@ describe("/admin/tax-rates", () => {
|
|||||||
},
|
},
|
||||||
{
|
{
|
||||||
headers: {
|
headers: {
|
||||||
authorization: "Bearer test_token",
|
"x-medusa-access-token": "test_token",
|
||||||
},
|
},
|
||||||
}
|
}
|
||||||
)
|
)
|
||||||
@@ -566,7 +566,7 @@ describe("/admin/tax-rates", () => {
|
|||||||
},
|
},
|
||||||
{
|
{
|
||||||
headers: {
|
headers: {
|
||||||
authorization: "Bearer test_token",
|
"x-medusa-access-token": "test_token",
|
||||||
},
|
},
|
||||||
}
|
}
|
||||||
)
|
)
|
||||||
@@ -595,7 +595,7 @@ describe("/admin/tax-rates", () => {
|
|||||||
const api = useApi()
|
const api = useApi()
|
||||||
const response = await api.delete(`/admin/tax-rates/${rate.id}`, {
|
const response = await api.delete(`/admin/tax-rates/${rate.id}`, {
|
||||||
headers: {
|
headers: {
|
||||||
authorization: "Bearer test_token",
|
"x-medusa-access-token": "test_token",
|
||||||
},
|
},
|
||||||
})
|
})
|
||||||
|
|
||||||
|
|||||||
@@ -60,7 +60,7 @@ describe("Shipping Options Totals Calculations", () => {
|
|||||||
|
|
||||||
const res = await api.get(`/admin/shipping-options`, {
|
const res = await api.get(`/admin/shipping-options`, {
|
||||||
headers: {
|
headers: {
|
||||||
Authorization: `Bearer test_token`,
|
"x-medusa-access-token": "test_token",
|
||||||
},
|
},
|
||||||
})
|
})
|
||||||
|
|
||||||
|
|||||||
@@ -16,7 +16,7 @@ jest.setTimeout(30000)
|
|||||||
|
|
||||||
const adminReqConfig = {
|
const adminReqConfig = {
|
||||||
headers: {
|
headers: {
|
||||||
Authorization: "Bearer test_token",
|
"x-medusa-access-token": "test_token",
|
||||||
},
|
},
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -2,7 +2,7 @@ const { useApi } = require("../environment-helpers/use-api")
|
|||||||
|
|
||||||
const header = {
|
const header = {
|
||||||
headers: {
|
headers: {
|
||||||
authorization: "Bearer test_token",
|
"x-medusa-access-token": "test_token",
|
||||||
},
|
},
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -13,7 +13,7 @@ const { simpleSalesChannelFactory } = require("../../../../factories")
|
|||||||
|
|
||||||
jest.setTimeout(30000)
|
jest.setTimeout(30000)
|
||||||
|
|
||||||
const adminHeaders = { headers: { Authorization: "Bearer test_token" } }
|
const adminHeaders = { headers: { "x-medusa-access-token": "test_token" } }
|
||||||
|
|
||||||
describe("/store/carts", () => {
|
describe("/store/carts", () => {
|
||||||
let express
|
let express
|
||||||
|
|||||||
@@ -14,7 +14,7 @@ const {
|
|||||||
simpleProductFactory,
|
simpleProductFactory,
|
||||||
simpleOrderFactory,
|
simpleOrderFactory,
|
||||||
} = require("../../../../factories")
|
} = require("../../../../factories")
|
||||||
const adminHeaders = { headers: { Authorization: "Bearer test_token" } }
|
const adminHeaders = { headers: { "x-medusa-access-token": "test_token" } }
|
||||||
|
|
||||||
describe("Inventory Items endpoints", () => {
|
describe("Inventory Items endpoints", () => {
|
||||||
let appContainer
|
let appContainer
|
||||||
@@ -682,7 +682,7 @@ describe("Inventory Items endpoints", () => {
|
|||||||
],
|
],
|
||||||
prices: [{ currency_code: "usd", amount: 100 }],
|
prices: [{ currency_code: "usd", amount: 100 }],
|
||||||
},
|
},
|
||||||
{ headers: { Authorization: "Bearer test_token" } }
|
{ headers: { "x-medusa-access-token": "test_token" } }
|
||||||
)
|
)
|
||||||
|
|
||||||
const secondVariantId = response.data.product.variants.find(
|
const secondVariantId = response.data.product.variants.find(
|
||||||
@@ -720,7 +720,7 @@ describe("Inventory Items endpoints", () => {
|
|||||||
).toHaveLength(2)
|
).toHaveLength(2)
|
||||||
|
|
||||||
await api.delete(`/admin/inventory-items/${invItem2.id}`, {
|
await api.delete(`/admin/inventory-items/${invItem2.id}`, {
|
||||||
headers: { Authorization: "Bearer test_token" },
|
headers: { "x-medusa-access-token": "test_token" },
|
||||||
})
|
})
|
||||||
|
|
||||||
expect(
|
expect(
|
||||||
|
|||||||
@@ -21,7 +21,7 @@ const {
|
|||||||
|
|
||||||
jest.setTimeout(30000)
|
jest.setTimeout(30000)
|
||||||
|
|
||||||
const adminHeaders = { headers: { Authorization: "Bearer test_token" } }
|
const adminHeaders = { headers: { "x-medusa-access-token": "test_token" } }
|
||||||
|
|
||||||
describe("/store/carts", () => {
|
describe("/store/carts", () => {
|
||||||
let express
|
let express
|
||||||
|
|||||||
@@ -20,7 +20,7 @@ const {
|
|||||||
|
|
||||||
jest.setTimeout(150000)
|
jest.setTimeout(150000)
|
||||||
|
|
||||||
const adminHeaders = { headers: { Authorization: "Bearer test_token" } }
|
const adminHeaders = { headers: { "x-medusa-access-token": "test_token" } }
|
||||||
|
|
||||||
describe("/store/carts", () => {
|
describe("/store/carts", () => {
|
||||||
let express
|
let express
|
||||||
|
|||||||
@@ -83,7 +83,7 @@ describe("Create Variant", () => {
|
|||||||
],
|
],
|
||||||
prices: [{ currency_code: "usd", amount: 2300 }],
|
prices: [{ currency_code: "usd", amount: 2300 }],
|
||||||
},
|
},
|
||||||
{ headers: { Authorization: "Bearer test_token" } }
|
{ headers: { "x-medusa-access-token": "test_token" } }
|
||||||
)
|
)
|
||||||
|
|
||||||
expect(response.status).toEqual(200)
|
expect(response.status).toEqual(200)
|
||||||
@@ -160,7 +160,7 @@ describe("Create Variant", () => {
|
|||||||
],
|
],
|
||||||
prices: [{ currency_code: "usd", amount: 2300 }],
|
prices: [{ currency_code: "usd", amount: 2300 }],
|
||||||
},
|
},
|
||||||
{ headers: { Authorization: "Bearer test_token" } }
|
{ headers: { "x-medusa-access-token": "test_token" } }
|
||||||
)
|
)
|
||||||
.catch((e) => e)
|
.catch((e) => e)
|
||||||
|
|
||||||
|
|||||||
@@ -70,7 +70,7 @@ describe("Delete Variant", () => {
|
|||||||
],
|
],
|
||||||
prices: [{ currency_code: "usd", amount: 2300 }],
|
prices: [{ currency_code: "usd", amount: 2300 }],
|
||||||
},
|
},
|
||||||
{ headers: { Authorization: "Bearer test_token" } }
|
{ headers: { "x-medusa-access-token": "test_token" } }
|
||||||
)
|
)
|
||||||
|
|
||||||
const variantId = response.data.product.variants.find(
|
const variantId = response.data.product.variants.find(
|
||||||
@@ -98,7 +98,7 @@ describe("Delete Variant", () => {
|
|||||||
).toHaveLength(2)
|
).toHaveLength(2)
|
||||||
|
|
||||||
await api.delete(`/admin/products/test-product/variants/${variantId}`, {
|
await api.delete(`/admin/products/test-product/variants/${variantId}`, {
|
||||||
headers: { Authorization: "Bearer test_token" },
|
headers: { "x-medusa-access-token": "test_token" },
|
||||||
})
|
})
|
||||||
|
|
||||||
await expect(variantService.retrieve(variantId)).rejects.toThrow(
|
await expect(variantService.retrieve(variantId)).rejects.toThrow(
|
||||||
|
|||||||
@@ -12,7 +12,7 @@ jest.setTimeout(30000)
|
|||||||
|
|
||||||
const { simpleProductFactory } = require("../../../../factories")
|
const { simpleProductFactory } = require("../../../../factories")
|
||||||
|
|
||||||
const adminHeaders = { headers: { Authorization: "Bearer test_token" } }
|
const adminHeaders = { headers: { "x-medusa-access-token": "test_token" } }
|
||||||
|
|
||||||
describe("Get products", () => {
|
describe("Get products", () => {
|
||||||
let appContainer
|
let appContainer
|
||||||
|
|||||||
@@ -15,7 +15,7 @@ const {
|
|||||||
simpleSalesChannelFactory,
|
simpleSalesChannelFactory,
|
||||||
} = require("../../../../factories")
|
} = require("../../../../factories")
|
||||||
|
|
||||||
const adminHeaders = { headers: { Authorization: "Bearer test_token" } }
|
const adminHeaders = { headers: { "x-medusa-access-token": "test_token" } }
|
||||||
|
|
||||||
describe("Get variant", () => {
|
describe("Get variant", () => {
|
||||||
let appContainer
|
let appContainer
|
||||||
|
|||||||
@@ -13,7 +13,7 @@ jest.setTimeout(30000)
|
|||||||
const { simpleProductFactory } = require("../../../../factories")
|
const { simpleProductFactory } = require("../../../../factories")
|
||||||
const { simpleSalesChannelFactory } = require("../../../../factories")
|
const { simpleSalesChannelFactory } = require("../../../../factories")
|
||||||
|
|
||||||
const adminHeaders = { headers: { Authorization: "Bearer test_token" } }
|
const adminHeaders = { headers: { "x-medusa-access-token": "test_token" } }
|
||||||
|
|
||||||
describe("Create Variant", () => {
|
describe("Create Variant", () => {
|
||||||
let appContainer
|
let appContainer
|
||||||
|
|||||||
@@ -12,7 +12,7 @@ jest.setTimeout(30000)
|
|||||||
|
|
||||||
const { simpleProductFactory } = require("../../../../factories")
|
const { simpleProductFactory } = require("../../../../factories")
|
||||||
const { simpleSalesChannelFactory } = require("../../../../factories")
|
const { simpleSalesChannelFactory } = require("../../../../factories")
|
||||||
const adminHeaders = { headers: { Authorization: "Bearer test_token" } }
|
const adminHeaders = { headers: { "x-medusa-access-token": "test_token" } }
|
||||||
|
|
||||||
describe("List Variants", () => {
|
describe("List Variants", () => {
|
||||||
let appContainer
|
let appContainer
|
||||||
|
|||||||
@@ -16,7 +16,7 @@ const {
|
|||||||
simpleRegionFactory,
|
simpleRegionFactory,
|
||||||
} = require("../../../../factories")
|
} = require("../../../../factories")
|
||||||
const { simpleSalesChannelFactory } = require("../../../../factories")
|
const { simpleSalesChannelFactory } = require("../../../../factories")
|
||||||
const adminHeaders = { headers: { Authorization: "Bearer test_token" } }
|
const adminHeaders = { headers: { "x-medusa-access-token": "test_token" } }
|
||||||
|
|
||||||
describe("Inventory Items endpoints", () => {
|
describe("Inventory Items endpoints", () => {
|
||||||
let appContainer
|
let appContainer
|
||||||
|
|||||||
@@ -58,7 +58,7 @@ describe("medusa-plugin-sendgrid", () => {
|
|||||||
const response = await api.post(
|
const response = await api.post(
|
||||||
`/admin/orders/${order.id}/cancel`,
|
`/admin/orders/${order.id}/cancel`,
|
||||||
{},
|
{},
|
||||||
{ headers: { authorization: "Bearer test_token" } }
|
{ headers: { "x-medusa-access-token": "test_token" } }
|
||||||
)
|
)
|
||||||
expect(response.status).toEqual(200)
|
expect(response.status).toEqual(200)
|
||||||
|
|
||||||
@@ -146,7 +146,7 @@ describe("medusa-plugin-sendgrid", () => {
|
|||||||
const { data: fulfillmentData } = await api.post(
|
const { data: fulfillmentData } = await api.post(
|
||||||
`/admin/orders/${order.id}/fulfillment`,
|
`/admin/orders/${order.id}/fulfillment`,
|
||||||
{ items: [{ item_id: "test-item", quantity: 2 }] },
|
{ items: [{ item_id: "test-item", quantity: 2 }] },
|
||||||
{ headers: { authorization: "Bearer test_token" } }
|
{ headers: { "x-medusa-access-token": "test_token" } }
|
||||||
)
|
)
|
||||||
|
|
||||||
const fulfillment = fulfillmentData.order.fulfillments[0]
|
const fulfillment = fulfillmentData.order.fulfillments[0]
|
||||||
@@ -154,7 +154,7 @@ describe("medusa-plugin-sendgrid", () => {
|
|||||||
const response = await api.post(
|
const response = await api.post(
|
||||||
`/admin/orders/${order.id}/shipment`,
|
`/admin/orders/${order.id}/shipment`,
|
||||||
{ fulfillment_id: fulfillment.id },
|
{ fulfillment_id: fulfillment.id },
|
||||||
{ headers: { authorization: "Bearer test_token" } }
|
{ headers: { "x-medusa-access-token": "test_token" } }
|
||||||
)
|
)
|
||||||
|
|
||||||
expect(response.status).toEqual(200)
|
expect(response.status).toEqual(200)
|
||||||
@@ -344,7 +344,7 @@ describe("medusa-plugin-sendgrid", () => {
|
|||||||
additional_items: [{ variant_id: "variant-2", quantity: 1 }],
|
additional_items: [{ variant_id: "variant-2", quantity: 1 }],
|
||||||
return_items: [{ item_id: "test-item", quantity: 1 }],
|
return_items: [{ item_id: "test-item", quantity: 1 }],
|
||||||
},
|
},
|
||||||
{ headers: { authorization: "Bearer test_token" } }
|
{ headers: { "x-medusa-access-token": "test_token" } }
|
||||||
)
|
)
|
||||||
|
|
||||||
expect(response.status).toEqual(200)
|
expect(response.status).toEqual(200)
|
||||||
@@ -359,7 +359,7 @@ describe("medusa-plugin-sendgrid", () => {
|
|||||||
quantity: i.quantity,
|
quantity: i.quantity,
|
||||||
})),
|
})),
|
||||||
},
|
},
|
||||||
{ headers: { authorization: "Bearer test_token" } }
|
{ headers: { "x-medusa-access-token": "test_token" } }
|
||||||
)
|
)
|
||||||
|
|
||||||
const sendgridService = appContainer.resolve("sendgridService")
|
const sendgridService = appContainer.resolve("sendgridService")
|
||||||
@@ -386,7 +386,7 @@ describe("medusa-plugin-sendgrid", () => {
|
|||||||
},
|
},
|
||||||
{
|
{
|
||||||
headers: {
|
headers: {
|
||||||
authorization: "Bearer test_token",
|
"x-medusa-access-token": "test_token",
|
||||||
},
|
},
|
||||||
}
|
}
|
||||||
)
|
)
|
||||||
@@ -403,7 +403,7 @@ describe("medusa-plugin-sendgrid", () => {
|
|||||||
quantity: i.quantity,
|
quantity: i.quantity,
|
||||||
})),
|
})),
|
||||||
},
|
},
|
||||||
{ headers: { authorization: "Bearer test_token" } }
|
{ headers: { "x-medusa-access-token": "test_token" } }
|
||||||
)
|
)
|
||||||
|
|
||||||
const sendgridService = appContainer.resolve("sendgridService")
|
const sendgridService = appContainer.resolve("sendgridService")
|
||||||
@@ -440,7 +440,7 @@ describe("medusa-plugin-sendgrid", () => {
|
|||||||
{ reason: "missing_item", item_id: "test-item", quantity: 1 },
|
{ reason: "missing_item", item_id: "test-item", quantity: 1 },
|
||||||
],
|
],
|
||||||
},
|
},
|
||||||
{ headers: { authorization: "Bearer test_token" } }
|
{ headers: { "x-medusa-access-token": "test_token" } }
|
||||||
)
|
)
|
||||||
|
|
||||||
expect(response.status).toEqual(200)
|
expect(response.status).toEqual(200)
|
||||||
@@ -450,14 +450,14 @@ describe("medusa-plugin-sendgrid", () => {
|
|||||||
const { data: fulfillmentData } = await api.post(
|
const { data: fulfillmentData } = await api.post(
|
||||||
`/admin/orders/${order.id}/claims/${claimId}/fulfillments`,
|
`/admin/orders/${order.id}/claims/${claimId}/fulfillments`,
|
||||||
{},
|
{},
|
||||||
{ headers: { authorization: "Bearer test_token" } }
|
{ headers: { "x-medusa-access-token": "test_token" } }
|
||||||
)
|
)
|
||||||
|
|
||||||
const fulfillmentId = fulfillmentData.order.claims[0].fulfillments[0].id
|
const fulfillmentId = fulfillmentData.order.claims[0].fulfillments[0].id
|
||||||
await api.post(
|
await api.post(
|
||||||
`/admin/orders/${order.id}/claims/${claimId}/shipments`,
|
`/admin/orders/${order.id}/claims/${claimId}/shipments`,
|
||||||
{ fulfillment_id: fulfillmentId },
|
{ fulfillment_id: fulfillmentId },
|
||||||
{ headers: { authorization: "Bearer test_token" } }
|
{ headers: { "x-medusa-access-token": "test_token" } }
|
||||||
)
|
)
|
||||||
|
|
||||||
const sendgridService = appContainer.resolve("sendgridService")
|
const sendgridService = appContainer.resolve("sendgridService")
|
||||||
@@ -545,7 +545,7 @@ describe("medusa-plugin-sendgrid", () => {
|
|||||||
additional_items: [{ variant_id: "variant-2", quantity: 1 }],
|
additional_items: [{ variant_id: "variant-2", quantity: 1 }],
|
||||||
return_items: [{ item_id: "test-item", quantity: 1 }],
|
return_items: [{ item_id: "test-item", quantity: 1 }],
|
||||||
},
|
},
|
||||||
{ headers: { authorization: "Bearer test_token" } }
|
{ headers: { "x-medusa-access-token": "test_token" } }
|
||||||
)
|
)
|
||||||
|
|
||||||
expect(response.status).toEqual(200)
|
expect(response.status).toEqual(200)
|
||||||
@@ -573,14 +573,14 @@ describe("medusa-plugin-sendgrid", () => {
|
|||||||
const { data: fulfillmentData } = await api.post(
|
const { data: fulfillmentData } = await api.post(
|
||||||
`/admin/orders/${order.id}/swaps/${swapId}/fulfillments`,
|
`/admin/orders/${order.id}/swaps/${swapId}/fulfillments`,
|
||||||
{},
|
{},
|
||||||
{ headers: { authorization: "Bearer test_token" } }
|
{ headers: { "x-medusa-access-token": "test_token" } }
|
||||||
)
|
)
|
||||||
|
|
||||||
const fulfillmentId = fulfillmentData.order.swaps[0].fulfillments[0].id
|
const fulfillmentId = fulfillmentData.order.swaps[0].fulfillments[0].id
|
||||||
await api.post(
|
await api.post(
|
||||||
`/admin/orders/${order.id}/swaps/${swapId}/shipments`,
|
`/admin/orders/${order.id}/swaps/${swapId}/shipments`,
|
||||||
{ fulfillment_id: fulfillmentId },
|
{ fulfillment_id: fulfillmentId },
|
||||||
{ headers: { authorization: "Bearer test_token" } }
|
{ headers: { "x-medusa-access-token": "test_token" } }
|
||||||
)
|
)
|
||||||
|
|
||||||
const sendgridService = appContainer.resolve("sendgridService")
|
const sendgridService = appContainer.resolve("sendgridService")
|
||||||
@@ -729,7 +729,7 @@ describe("medusa-plugin-sendgrid", () => {
|
|||||||
},
|
},
|
||||||
{
|
{
|
||||||
headers: {
|
headers: {
|
||||||
authorization: "Bearer test_token",
|
"x-medusa-access-token": "test_token",
|
||||||
},
|
},
|
||||||
}
|
}
|
||||||
)
|
)
|
||||||
@@ -759,7 +759,7 @@ describe("medusa-plugin-sendgrid", () => {
|
|||||||
},
|
},
|
||||||
{
|
{
|
||||||
headers: {
|
headers: {
|
||||||
authorization: "Bearer test_token",
|
"x-medusa-access-token": "test_token",
|
||||||
},
|
},
|
||||||
}
|
}
|
||||||
)
|
)
|
||||||
|
|||||||
@@ -15,7 +15,7 @@ jest.setTimeout(5000000)
|
|||||||
|
|
||||||
const adminHeaders = {
|
const adminHeaders = {
|
||||||
headers: {
|
headers: {
|
||||||
Authorization: "Bearer test_token",
|
"x-medusa-access-token": "test_token",
|
||||||
},
|
},
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -72,7 +72,7 @@ describe("Sales channels", () => {
|
|||||||
).toHaveLength(2)
|
).toHaveLength(2)
|
||||||
|
|
||||||
await api.delete(`/admin/sales-channels/${sc.id}`, {
|
await api.delete(`/admin/sales-channels/${sc.id}`, {
|
||||||
headers: { Authorization: "Bearer test_token" },
|
headers: { "x-medusa-access-token": "test_token" },
|
||||||
})
|
})
|
||||||
|
|
||||||
await expect(salesChannelService.retrieve(sc.id)).rejects.toThrowError()
|
await expect(salesChannelService.retrieve(sc.id)).rejects.toThrowError()
|
||||||
|
|||||||
@@ -78,7 +78,7 @@ describe("Sales channels", () => {
|
|||||||
).toHaveLength(1)
|
).toHaveLength(1)
|
||||||
|
|
||||||
await api.delete(`/admin/stock-locations/${loc.id}`, {
|
await api.delete(`/admin/stock-locations/${loc.id}`, {
|
||||||
headers: { Authorization: "Bearer test_token" },
|
headers: { "x-medusa-access-token": "test_token" },
|
||||||
})
|
})
|
||||||
|
|
||||||
expect(
|
expect(
|
||||||
|
|||||||
@@ -8,7 +8,7 @@ const adminSeeder = require("../../../helpers/admin-seeder")
|
|||||||
|
|
||||||
jest.setTimeout(30000)
|
jest.setTimeout(30000)
|
||||||
|
|
||||||
const adminHeaders = { headers: { Authorization: "Bearer test_token" } }
|
const adminHeaders = { headers: { "x-medusa-access-token": "test_token" } }
|
||||||
|
|
||||||
describe("Sales channels", () => {
|
describe("Sales channels", () => {
|
||||||
let appContainer
|
let appContainer
|
||||||
|
|||||||
@@ -0,0 +1,100 @@
|
|||||||
|
const { useApi } = require("../../helpers/use-api")
|
||||||
|
|
||||||
|
const header = {
|
||||||
|
headers: {
|
||||||
|
"x-medusa-access-token": "test_token",
|
||||||
|
},
|
||||||
|
}
|
||||||
|
|
||||||
|
const resolveCall = async (path, payload, header) => {
|
||||||
|
const api = useApi()
|
||||||
|
let res
|
||||||
|
try {
|
||||||
|
const resp = await api.post(path, payload, header)
|
||||||
|
res = resp.status
|
||||||
|
} catch (expectedException) {
|
||||||
|
try {
|
||||||
|
res = expectedException.response.status
|
||||||
|
} catch (_) {
|
||||||
|
console.error(expectedException)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
return res
|
||||||
|
}
|
||||||
|
|
||||||
|
const determineFail = (actual, expected, path) => {
|
||||||
|
if (expected !== actual) {
|
||||||
|
console.log(`failed at path : ${path}`)
|
||||||
|
}
|
||||||
|
expect(actual).toEqual(expected)
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Allows you to wrap a Call function so that you may reuse some input values.
|
||||||
|
* @param {Function} fun - the function to call with partial information
|
||||||
|
* @param {Object} input - the constant input which we want to supply now
|
||||||
|
* @returns
|
||||||
|
*/
|
||||||
|
module.exports.partial = function (fun, input = {}) {
|
||||||
|
return async (remaining) => await fun({ ...remaining, ...input })
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Allows you to assert a specific code result from a POST call.
|
||||||
|
* @param {Object} input - the information needed to make the call
|
||||||
|
* (path & payload) and the expected code (code)
|
||||||
|
*/
|
||||||
|
module.exports.expectPostCallToReturn = async function (
|
||||||
|
input = {
|
||||||
|
code,
|
||||||
|
path,
|
||||||
|
payload: {},
|
||||||
|
}
|
||||||
|
) {
|
||||||
|
const res = await resolveCall(input.path, input.payload, header)
|
||||||
|
determineFail(res, input.code, input.path)
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Allows you to assert a specific code result from multiple POST
|
||||||
|
* calls.
|
||||||
|
* @param {Object} input - the collection of objects to execute
|
||||||
|
* calls from (col), a function which yields the path (pathf),
|
||||||
|
* and another one which provides the payload (payloadf), as
|
||||||
|
* well as the code (code) which we want to assert.
|
||||||
|
*/
|
||||||
|
module.exports.expectAllPostCallsToReturn = async function (
|
||||||
|
input = {
|
||||||
|
code,
|
||||||
|
col,
|
||||||
|
pathf,
|
||||||
|
payloadf,
|
||||||
|
}
|
||||||
|
) {
|
||||||
|
for (const i of input.col) {
|
||||||
|
const res = await resolveCall(
|
||||||
|
input.pathf(i),
|
||||||
|
input.payloadf ? input.payloadf(i) : {},
|
||||||
|
header
|
||||||
|
)
|
||||||
|
determineFail(res, input.code, input.pathf(i))
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Allows you to retrieve a specific object the response
|
||||||
|
* from get call,
|
||||||
|
* and simultaneously assert that the call was successful.
|
||||||
|
* @param {Object} param0 - contains the path which to
|
||||||
|
* call (path), and the object within the response.data (get)
|
||||||
|
* we want to retrieve.
|
||||||
|
* @returns {Object} found within response.data corresponding
|
||||||
|
* to the get parameter provided.
|
||||||
|
*/
|
||||||
|
module.exports.callGet = async function ({ path, get }) {
|
||||||
|
const api = useApi()
|
||||||
|
const res = await api.get(path, header)
|
||||||
|
|
||||||
|
determineFail(res.status, 200, path)
|
||||||
|
return res?.data[get]
|
||||||
|
}
|
||||||
@@ -0,0 +1,11 @@
|
|||||||
|
/* istanbul ignore file */
|
||||||
|
/* tslint:disable */
|
||||||
|
/* eslint-disable */
|
||||||
|
import { SetRelation, Merge } from "../core/ModelUtils"
|
||||||
|
|
||||||
|
export interface AdminBearerAuthRes {
|
||||||
|
/**
|
||||||
|
* Access token for subsequent authorization.
|
||||||
|
*/
|
||||||
|
accessToken?: string
|
||||||
|
}
|
||||||
@@ -0,0 +1,11 @@
|
|||||||
|
/* istanbul ignore file */
|
||||||
|
/* tslint:disable */
|
||||||
|
/* eslint-disable */
|
||||||
|
import { SetRelation, Merge } from "../core/ModelUtils"
|
||||||
|
|
||||||
|
export interface StoreBearerAuthRes {
|
||||||
|
/**
|
||||||
|
* Access token for subsequent authorization.
|
||||||
|
*/
|
||||||
|
accessToken?: string
|
||||||
|
}
|
||||||
@@ -9,6 +9,7 @@ export type { AdminAppsRes } from "./AdminAppsRes"
|
|||||||
export type { AdminAuthRes } from "./AdminAuthRes"
|
export type { AdminAuthRes } from "./AdminAuthRes"
|
||||||
export type { AdminBatchJobListRes } from "./AdminBatchJobListRes"
|
export type { AdminBatchJobListRes } from "./AdminBatchJobListRes"
|
||||||
export type { AdminBatchJobRes } from "./AdminBatchJobRes"
|
export type { AdminBatchJobRes } from "./AdminBatchJobRes"
|
||||||
|
export type { AdminBearerAuthRes } from "./AdminBearerAuthRes"
|
||||||
export type { AdminCollectionsDeleteRes } from "./AdminCollectionsDeleteRes"
|
export type { AdminCollectionsDeleteRes } from "./AdminCollectionsDeleteRes"
|
||||||
export type { AdminCollectionsListRes } from "./AdminCollectionsListRes"
|
export type { AdminCollectionsListRes } from "./AdminCollectionsListRes"
|
||||||
export type { AdminCollectionsRes } from "./AdminCollectionsRes"
|
export type { AdminCollectionsRes } from "./AdminCollectionsRes"
|
||||||
@@ -396,6 +397,7 @@ export type { StockLocationDTO } from "./StockLocationDTO"
|
|||||||
export type { StockLocationExpandedDTO } from "./StockLocationExpandedDTO"
|
export type { StockLocationExpandedDTO } from "./StockLocationExpandedDTO"
|
||||||
export type { Store } from "./Store"
|
export type { Store } from "./Store"
|
||||||
export type { StoreAuthRes } from "./StoreAuthRes"
|
export type { StoreAuthRes } from "./StoreAuthRes"
|
||||||
|
export type { StoreBearerAuthRes } from "./StoreBearerAuthRes"
|
||||||
export type { StoreCartShippingOptionsListRes } from "./StoreCartShippingOptionsListRes"
|
export type { StoreCartShippingOptionsListRes } from "./StoreCartShippingOptionsListRes"
|
||||||
export type { StoreCartsRes } from "./StoreCartsRes"
|
export type { StoreCartsRes } from "./StoreCartsRes"
|
||||||
export type { StoreCollectionsListRes } from "./StoreCollectionsListRes"
|
export type { StoreCollectionsListRes } from "./StoreCollectionsListRes"
|
||||||
|
|||||||
@@ -0,0 +1,38 @@
|
|||||||
|
/**
|
||||||
|
* `JwtTokenManager` holds JWT tokens in state.
|
||||||
|
*/
|
||||||
|
class JwtTokenManager {
|
||||||
|
private adminJwt: string | null = null;
|
||||||
|
private storeJwt: string | null = null;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Set a store or admin jwt token to be sent with each request.
|
||||||
|
*/
|
||||||
|
public registerJwt(token: string, domain: "admin" | "store") {
|
||||||
|
if (domain === "admin") {
|
||||||
|
this.adminJwt = token;
|
||||||
|
} else if (domain === "store") {
|
||||||
|
this.storeJwt = token;
|
||||||
|
} else {
|
||||||
|
throw new Error(`'domain' must be wither 'admin' or 'store' received ${domain}`)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Retrieve the store or admin jwt token
|
||||||
|
*/
|
||||||
|
public getJwt(domain: "admin" | "store") {
|
||||||
|
if (domain === "admin") {
|
||||||
|
return this.adminJwt;
|
||||||
|
} else if (domain === "store") {
|
||||||
|
return this.storeJwt;
|
||||||
|
} else {
|
||||||
|
throw new Error(`'domain' must be wither 'admin' or 'store' received ${domain}`)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Export singleton instance.
|
||||||
|
*/
|
||||||
|
export default new JwtTokenManager()
|
||||||
@@ -3,6 +3,7 @@ import * as rax from "retry-axios"
|
|||||||
import { v4 as uuidv4 } from "uuid"
|
import { v4 as uuidv4 } from "uuid"
|
||||||
|
|
||||||
import KeyManager from "./key-manager"
|
import KeyManager from "./key-manager"
|
||||||
|
import JwtTokenManager from "./jwt-token-manager"
|
||||||
|
|
||||||
const unAuthenticatedAdminEndpoints = {
|
const unAuthenticatedAdminEndpoints = {
|
||||||
"/admin/auth": "POST",
|
"/admin/auth": "POST",
|
||||||
@@ -125,7 +126,16 @@ class Client {
|
|||||||
if (this.config.apiKey && this.requiresAuthentication(path, method)) {
|
if (this.config.apiKey && this.requiresAuthentication(path, method)) {
|
||||||
defaultHeaders = {
|
defaultHeaders = {
|
||||||
...defaultHeaders,
|
...defaultHeaders,
|
||||||
Authorization: `Bearer ${this.config.apiKey}`,
|
"x-medusa-access-token": this.config.apiKey,
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
const domain: "admin" | "store" = path.includes("admin") ? "admin" : "store"
|
||||||
|
|
||||||
|
if (JwtTokenManager.getJwt(domain)) {
|
||||||
|
defaultHeaders = {
|
||||||
|
...defaultHeaders,
|
||||||
|
Authorization: `Bearer ${JwtTokenManager.getJwt(domain)}`,
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -1,5 +1,6 @@
|
|||||||
import { AdminAuthRes, AdminPostAuthReq } from "@medusajs/medusa"
|
import { AdminAuthRes, AdminPostAuthReq, AdminBearerAuthRes } from "@medusajs/medusa"
|
||||||
import { ResponsePromise } from "../../typings"
|
import { ResponsePromise } from "../../typings"
|
||||||
|
import JwtTokenManager from "../../jwt-token-manager"
|
||||||
import BaseResource from "../base"
|
import BaseResource from "../base"
|
||||||
|
|
||||||
class AdminAuthResource extends BaseResource {
|
class AdminAuthResource extends BaseResource {
|
||||||
@@ -41,6 +42,25 @@ class AdminAuthResource extends BaseResource {
|
|||||||
const path = `/admin/auth`
|
const path = `/admin/auth`
|
||||||
return this.client.request("POST", path, payload, {}, customHeaders)
|
return this.client.request("POST", path, payload, {}, customHeaders)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @description Retrieves a new JWT access token
|
||||||
|
* @param {AdminPostAuthReq} payload
|
||||||
|
* @param customHeaders
|
||||||
|
* @return {ResponsePromise<AdminBearerAuthRes>}
|
||||||
|
*/
|
||||||
|
getToken(
|
||||||
|
payload: AdminPostAuthReq,
|
||||||
|
customHeaders: Record<string, any> = {}
|
||||||
|
): ResponsePromise<AdminBearerAuthRes> {
|
||||||
|
const path = `/admin/auth/token`
|
||||||
|
return this.client.request("POST", path, payload, {}, customHeaders)
|
||||||
|
.then((res) => {
|
||||||
|
JwtTokenManager.registerJwt(res.access_token, "admin");
|
||||||
|
|
||||||
|
return res
|
||||||
|
});
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
export default AdminAuthResource
|
export default AdminAuthResource
|
||||||
@@ -2,8 +2,10 @@ import {
|
|||||||
StoreGetAuthEmailRes,
|
StoreGetAuthEmailRes,
|
||||||
StorePostAuthReq,
|
StorePostAuthReq,
|
||||||
StoreAuthRes,
|
StoreAuthRes,
|
||||||
|
StoreBearerAuthRes,
|
||||||
} from "@medusajs/medusa"
|
} from "@medusajs/medusa"
|
||||||
import { ResponsePromise } from "../typings"
|
import { ResponsePromise } from "../typings"
|
||||||
|
import JwtTokenManager from "../jwt-token-manager"
|
||||||
import BaseResource from "./base"
|
import BaseResource from "./base"
|
||||||
|
|
||||||
class AuthResource extends BaseResource {
|
class AuthResource extends BaseResource {
|
||||||
@@ -48,6 +50,25 @@ class AuthResource extends BaseResource {
|
|||||||
const path = `/store/auth/${email}`
|
const path = `/store/auth/${email}`
|
||||||
return this.client.request("GET", path, undefined, {}, customHeaders)
|
return this.client.request("GET", path, undefined, {}, customHeaders)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @description Retrieves a new JWT access token
|
||||||
|
* @param {AdminPostAuthReq} payload
|
||||||
|
* @param customHeaders
|
||||||
|
* @return {ResponsePromise<AdminBearerAuthRes>}
|
||||||
|
*/
|
||||||
|
getToken(
|
||||||
|
payload: StorePostAuthReq,
|
||||||
|
customHeaders: Record<string, any> = {}
|
||||||
|
): ResponsePromise<StoreBearerAuthRes> {
|
||||||
|
const path = `/store/auth/token`
|
||||||
|
return this.client.request("POST", path, payload, {}, customHeaders)
|
||||||
|
.then((res) => {
|
||||||
|
JwtTokenManager.registerJwt(res.data.access_token, "store");
|
||||||
|
|
||||||
|
return res
|
||||||
|
});
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
export default AuthResource
|
export default AuthResource
|
||||||
@@ -83,7 +83,7 @@
|
|||||||
"node-schedule": "^2.1.1",
|
"node-schedule": "^2.1.1",
|
||||||
"papaparse": "5.3.2",
|
"papaparse": "5.3.2",
|
||||||
"passport": "^0.6.0",
|
"passport": "^0.6.0",
|
||||||
"passport-http-bearer": "^1.0.1",
|
"passport-custom": "^1.1.1",
|
||||||
"passport-jwt": "^4.0.1",
|
"passport-jwt": "^4.0.1",
|
||||||
"passport-local": "^1.0.0",
|
"passport-local": "^1.0.0",
|
||||||
"pg": "^8.11.2",
|
"pg": "^8.11.2",
|
||||||
|
|||||||
@@ -7,7 +7,7 @@ import passport from "passport"
|
|||||||
export default (): RequestHandler => {
|
export default (): RequestHandler => {
|
||||||
return (req: Request, res: Response, next: NextFunction): void => {
|
return (req: Request, res: Response, next: NextFunction): void => {
|
||||||
passport.authenticate(
|
passport.authenticate(
|
||||||
["store-jwt", "bearer"],
|
["store-session", "store-bearer"],
|
||||||
{ session: false },
|
{ session: false },
|
||||||
(err, user) => {
|
(err, user) => {
|
||||||
if (err) {
|
if (err) {
|
||||||
|
|||||||
@@ -3,7 +3,7 @@ import passport from "passport"
|
|||||||
|
|
||||||
export default (): RequestHandler => {
|
export default (): RequestHandler => {
|
||||||
return (req: Request, res: Response, next: NextFunction): void => {
|
return (req: Request, res: Response, next: NextFunction): void => {
|
||||||
passport.authenticate(["admin-jwt", "bearer"], { session: false })(
|
passport.authenticate(["admin-session", "admin-bearer", "admin-api-token"], { session: false })(
|
||||||
req,
|
req,
|
||||||
res,
|
res,
|
||||||
next
|
next
|
||||||
|
|||||||
@@ -7,7 +7,7 @@ export default (): RequestHandler => {
|
|||||||
return next()
|
return next()
|
||||||
}
|
}
|
||||||
|
|
||||||
passport.authenticate(["store-jwt", "bearer"], { session: false })(
|
passport.authenticate(["store-session", "store-bearer"], { session: false })(
|
||||||
req,
|
req,
|
||||||
res,
|
res,
|
||||||
next
|
next
|
||||||
|
|||||||
@@ -66,15 +66,6 @@ import { validator } from "../../../../utils/validator"
|
|||||||
* $ref: "#/components/responses/500_error"
|
* $ref: "#/components/responses/500_error"
|
||||||
*/
|
*/
|
||||||
export default async (req, res) => {
|
export default async (req, res) => {
|
||||||
const {
|
|
||||||
projectConfig: { jwt_secret },
|
|
||||||
} = req.scope.resolve("configModule")
|
|
||||||
if (!jwt_secret) {
|
|
||||||
throw new MedusaError(
|
|
||||||
MedusaError.Types.NOT_FOUND,
|
|
||||||
"Please configure jwt_secret in your environment"
|
|
||||||
)
|
|
||||||
}
|
|
||||||
const validated = await validator(AdminPostAuthReq, req.body)
|
const validated = await validator(AdminPostAuthReq, req.body)
|
||||||
|
|
||||||
const authService: AuthService = req.scope.resolve("authService")
|
const authService: AuthService = req.scope.resolve("authService")
|
||||||
@@ -86,10 +77,8 @@ export default async (req, res) => {
|
|||||||
})
|
})
|
||||||
|
|
||||||
if (result.success && result.user) {
|
if (result.success && result.user) {
|
||||||
// Add JWT to cookie
|
// Set user id on session, this is stored on the server.
|
||||||
req.session.jwt = jwt.sign({ userId: result.user.id }, jwt_secret, {
|
req.session.user_id = result.user.id
|
||||||
expiresIn: "24h",
|
|
||||||
})
|
|
||||||
|
|
||||||
const cleanRes = _.omit(result.user, ["password_hash"])
|
const cleanRes = _.omit(result.user, ["password_hash"])
|
||||||
|
|
||||||
|
|||||||
@@ -42,6 +42,11 @@
|
|||||||
* $ref: "#/components/responses/500_error"
|
* $ref: "#/components/responses/500_error"
|
||||||
*/
|
*/
|
||||||
export default async (req, res) => {
|
export default async (req, res) => {
|
||||||
req.session.destroy()
|
if (req.session.customer_id) { // if we are also logged in as a customer, persist that session
|
||||||
res.status(200).end()
|
delete req.session.user_id
|
||||||
|
} else { // otherwise, destroy the session
|
||||||
|
req.session.destroy()
|
||||||
|
}
|
||||||
|
|
||||||
|
res.sendStatus(200)
|
||||||
}
|
}
|
||||||
@@ -52,8 +52,10 @@ import _ from "lodash"
|
|||||||
*/
|
*/
|
||||||
export default async (req, res) => {
|
export default async (req, res) => {
|
||||||
try {
|
try {
|
||||||
|
const userId = req.user.id || req.user.userId
|
||||||
|
|
||||||
const userService: UserService = req.scope.resolve("userService")
|
const userService: UserService = req.scope.resolve("userService")
|
||||||
const user = await userService.retrieve(req.user.userId)
|
const user = await userService.retrieve(userId)
|
||||||
|
|
||||||
const cleanRes = _.omit(user, ["password_hash"])
|
const cleanRes = _.omit(user, ["password_hash"])
|
||||||
res.status(200).json({ user: cleanRes })
|
res.status(200).json({ user: cleanRes })
|
||||||
|
|||||||
@@ -0,0 +1,102 @@
|
|||||||
|
import jwt from "jsonwebtoken"
|
||||||
|
import { MedusaError } from "medusa-core-utils"
|
||||||
|
import { EntityManager } from "typeorm"
|
||||||
|
import AuthService from "../../../../services/auth"
|
||||||
|
import { validator } from "../../../../utils/validator"
|
||||||
|
import { AdminPostAuthReq } from "./create-session"
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @oas [post] /admin/token
|
||||||
|
* operationId: "PostToken"
|
||||||
|
* summary: "User Login (JWT)"
|
||||||
|
* x-authenticated: false
|
||||||
|
* description: "After a successful login, a JWT token is returned for subsequent authorization."
|
||||||
|
* parameters:
|
||||||
|
* - (body) email=* {string} The User's email.
|
||||||
|
* - (body) password=* {string} The User's password.
|
||||||
|
* requestBody:
|
||||||
|
* content:
|
||||||
|
* application/json:
|
||||||
|
* schema:
|
||||||
|
* $ref: "#/components/schemas/AdminPostAuthReq"
|
||||||
|
* x-codegen:
|
||||||
|
* method: getToken
|
||||||
|
* x-codeSamples:
|
||||||
|
* - lang: JavaScript
|
||||||
|
* label: JS Client
|
||||||
|
* source: |
|
||||||
|
* import Medusa from "@medusajs/medusa-js"
|
||||||
|
* const medusa = new Medusa({ baseUrl: MEDUSA_BACKEND_URL, maxRetries: 3 })
|
||||||
|
* medusa.admin.auth.getToken({
|
||||||
|
* email: 'user@example.com',
|
||||||
|
* password: 'supersecret'
|
||||||
|
* })
|
||||||
|
* .then(({ accessToken }) => {
|
||||||
|
* console.log(accessToekn);
|
||||||
|
* });
|
||||||
|
* - lang: Shell
|
||||||
|
* label: cURL
|
||||||
|
* source: |
|
||||||
|
* curl --location --request POST 'https://medusa-url.com/admin/auth/token' \
|
||||||
|
* --header 'Content-Type: application/json' \
|
||||||
|
* --data-raw '{
|
||||||
|
* "email": "user@example.com",
|
||||||
|
* "password": "supersecret"
|
||||||
|
* }'
|
||||||
|
* tags:
|
||||||
|
* - Auth
|
||||||
|
* responses:
|
||||||
|
* "200":
|
||||||
|
* description: OK
|
||||||
|
* content:
|
||||||
|
* application/json:
|
||||||
|
* schema:
|
||||||
|
* $ref: "#/components/schemas/AdminBearerAuthRes"
|
||||||
|
* "400":
|
||||||
|
* $ref: "#/components/responses/400_error"
|
||||||
|
* "401":
|
||||||
|
* $ref: "#/components/responses/incorrect_credentials"
|
||||||
|
* "404":
|
||||||
|
* $ref: "#/components/responses/not_found_error"
|
||||||
|
* "409":
|
||||||
|
* $ref: "#/components/responses/invalid_state_error"
|
||||||
|
* "422":
|
||||||
|
* $ref: "#/components/responses/invalid_request_error"
|
||||||
|
* "500":
|
||||||
|
* $ref: "#/components/responses/500_error"
|
||||||
|
*/
|
||||||
|
export default async (req, res) => {
|
||||||
|
const {
|
||||||
|
projectConfig: { jwt_secret },
|
||||||
|
} = req.scope.resolve("configModule")
|
||||||
|
if (!jwt_secret) {
|
||||||
|
throw new MedusaError(
|
||||||
|
MedusaError.Types.NOT_FOUND,
|
||||||
|
"Please configure jwt_secret in your environment"
|
||||||
|
)
|
||||||
|
}
|
||||||
|
const validated = await validator(AdminPostAuthReq, req.body)
|
||||||
|
|
||||||
|
const authService: AuthService = req.scope.resolve("authService")
|
||||||
|
const manager: EntityManager = req.scope.resolve("manager")
|
||||||
|
const result = await manager.transaction(async (transactionManager) => {
|
||||||
|
return await authService
|
||||||
|
.withTransaction(transactionManager)
|
||||||
|
.authenticate(validated.email, validated.password)
|
||||||
|
})
|
||||||
|
|
||||||
|
if (result.success && result.user) {
|
||||||
|
// Create jwt token to send back
|
||||||
|
const token = jwt.sign(
|
||||||
|
{ user_id: result.user.id, domain: "admin" },
|
||||||
|
jwt_secret,
|
||||||
|
{
|
||||||
|
expiresIn: "24h",
|
||||||
|
}
|
||||||
|
)
|
||||||
|
|
||||||
|
res.json({ access_token: token })
|
||||||
|
} else {
|
||||||
|
res.sendStatus(401)
|
||||||
|
}
|
||||||
|
}
|
||||||
@@ -12,6 +12,7 @@ export default (app) => {
|
|||||||
middlewares.authenticate(),
|
middlewares.authenticate(),
|
||||||
middlewares.wrap(require("./get-session").default)
|
middlewares.wrap(require("./get-session").default)
|
||||||
)
|
)
|
||||||
|
|
||||||
route.post("/", middlewares.wrap(require("./create-session").default))
|
route.post("/", middlewares.wrap(require("./create-session").default))
|
||||||
|
|
||||||
route.delete(
|
route.delete(
|
||||||
@@ -20,6 +21,8 @@ export default (app) => {
|
|||||||
middlewares.wrap(require("./delete-session").default)
|
middlewares.wrap(require("./delete-session").default)
|
||||||
)
|
)
|
||||||
|
|
||||||
|
route.post("/token", middlewares.wrap(require("./get-token").default))
|
||||||
|
|
||||||
return app
|
return app
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -37,6 +40,19 @@ export type AdminAuthRes = {
|
|||||||
user: Omit<User, "password_hash">
|
user: Omit<User, "password_hash">
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @schema AdminBearerAuthRes
|
||||||
|
* type: object
|
||||||
|
* properties:
|
||||||
|
* accessToken:
|
||||||
|
* description: Access token for subsequent authorization.
|
||||||
|
* type: string
|
||||||
|
*/
|
||||||
|
export type AdminBearerAuthRes = {
|
||||||
|
access_token: string
|
||||||
|
}
|
||||||
|
|
||||||
export * from "./create-session"
|
export * from "./create-session"
|
||||||
export * from "./delete-session"
|
export * from "./delete-session"
|
||||||
export * from "./get-session"
|
export * from "./get-session"
|
||||||
|
export * from "./get-token"
|
||||||
@@ -9,7 +9,7 @@ describe("POST /invites/:invite_id/resend", () => {
|
|||||||
subject = await request("POST", `/admin/invites/invite_test/resend`, {
|
subject = await request("POST", `/admin/invites/invite_test/resend`, {
|
||||||
adminSession: {
|
adminSession: {
|
||||||
jwt: {
|
jwt: {
|
||||||
id: "test_user",
|
userId: "test_user",
|
||||||
},
|
},
|
||||||
},
|
},
|
||||||
})
|
})
|
||||||
|
|||||||
@@ -79,17 +79,8 @@ export default async (req, res) => {
|
|||||||
return
|
return
|
||||||
}
|
}
|
||||||
|
|
||||||
// Add JWT to cookie
|
// Set customer id on session, this is stored on the server.
|
||||||
const {
|
req.session.customer_id = result.customer?.id
|
||||||
projectConfig: { jwt_secret },
|
|
||||||
} = req.scope.resolve("configModule")
|
|
||||||
req.session.jwt_store = jwt.sign(
|
|
||||||
{ customer_id: result.customer?.id },
|
|
||||||
jwt_secret!,
|
|
||||||
{
|
|
||||||
expiresIn: "30d",
|
|
||||||
}
|
|
||||||
)
|
|
||||||
|
|
||||||
const customerService: CustomerService = req.scope.resolve("customerService")
|
const customerService: CustomerService = req.scope.resolve("customerService")
|
||||||
const customer = await customerService.retrieve(result.customer?.id || "", {
|
const customer = await customerService.retrieve(result.customer?.id || "", {
|
||||||
|
|||||||
@@ -33,6 +33,11 @@
|
|||||||
* $ref: "#/components/responses/500_error"
|
* $ref: "#/components/responses/500_error"
|
||||||
*/
|
*/
|
||||||
export default async (req, res) => {
|
export default async (req, res) => {
|
||||||
req.session.jwt_store = {}
|
if(req.session.user_id) { // if we are also logged in as a user, persist that session
|
||||||
res.json({})
|
delete req.session.customer_id
|
||||||
|
} else { // otherwise, destroy the session
|
||||||
|
req.session.destroy()
|
||||||
|
}
|
||||||
|
|
||||||
|
res.sendStatus(200)
|
||||||
}
|
}
|
||||||
@@ -0,0 +1,102 @@
|
|||||||
|
import jwt from "jsonwebtoken"
|
||||||
|
import { MedusaError } from "medusa-core-utils"
|
||||||
|
import { EntityManager } from "typeorm"
|
||||||
|
import AuthService from "../../../../services/auth"
|
||||||
|
import { validator } from "../../../../utils/validator"
|
||||||
|
import { StorePostAuthReq } from "./create-session"
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @oas [post] /store/token
|
||||||
|
* operationId: "PostToken"
|
||||||
|
* summary: "Customer Login (JWT)"
|
||||||
|
* x-authenticated: false
|
||||||
|
* description: "After a successful login, a JWT token is returned for subsequent authorization."
|
||||||
|
* parameters:
|
||||||
|
* - (body) email=* {string} The User's email.
|
||||||
|
* - (body) password=* {string} The User's password.
|
||||||
|
* requestBody:
|
||||||
|
* content:
|
||||||
|
* application/json:
|
||||||
|
* schema:
|
||||||
|
* $ref: "#/components/schemas/StorePostAuthReq"
|
||||||
|
* x-codegen:
|
||||||
|
* method: getToken
|
||||||
|
* x-codeSamples:
|
||||||
|
* - lang: JavaScript
|
||||||
|
* label: JS Client
|
||||||
|
* source: |
|
||||||
|
* import Medusa from "@medusajs/medusa-js"
|
||||||
|
* const medusa = new Medusa({ baseUrl: MEDUSA_BACKEND_URL, maxRetries: 3 })
|
||||||
|
* medusa.store.auth.getToken({
|
||||||
|
* email: 'user@example.com',
|
||||||
|
* password: 'supersecret'
|
||||||
|
* })
|
||||||
|
* .then(({ accessToken }) => {
|
||||||
|
* console.log(accessToken);
|
||||||
|
* });
|
||||||
|
* - lang: Shell
|
||||||
|
* label: cURL
|
||||||
|
* source: |
|
||||||
|
* curl --location --request POST 'https://medusa-url.com/store/auth/token' \
|
||||||
|
* --header 'Content-Type: application/json' \
|
||||||
|
* --data-raw '{
|
||||||
|
* "email": "user@example.com",
|
||||||
|
* "password": "supersecret"
|
||||||
|
* }'
|
||||||
|
* tags:
|
||||||
|
* - Auth
|
||||||
|
* responses:
|
||||||
|
* "200":
|
||||||
|
* description: OK
|
||||||
|
* content:
|
||||||
|
* application/json:
|
||||||
|
* schema:
|
||||||
|
* $ref: "#/components/schemas/StoreBearerAuthRes"
|
||||||
|
* "400":
|
||||||
|
* $ref: "#/components/responses/400_error"
|
||||||
|
* "401":
|
||||||
|
* $ref: "#/components/responses/incorrect_credentials"
|
||||||
|
* "404":
|
||||||
|
* $ref: "#/components/responses/not_found_error"
|
||||||
|
* "409":
|
||||||
|
* $ref: "#/components/responses/invalid_state_error"
|
||||||
|
* "422":
|
||||||
|
* $ref: "#/components/responses/invalid_request_error"
|
||||||
|
* "500":
|
||||||
|
* $ref: "#/components/responses/500_error"
|
||||||
|
*/
|
||||||
|
export default async (req, res) => {
|
||||||
|
const {
|
||||||
|
projectConfig: { jwt_secret },
|
||||||
|
} = req.scope.resolve("configModule")
|
||||||
|
if (!jwt_secret) {
|
||||||
|
throw new MedusaError(
|
||||||
|
MedusaError.Types.NOT_FOUND,
|
||||||
|
"Please configure jwt_secret in your environment"
|
||||||
|
)
|
||||||
|
}
|
||||||
|
const validated = await validator(StorePostAuthReq, req.body)
|
||||||
|
|
||||||
|
const authService: AuthService = req.scope.resolve("authService")
|
||||||
|
const manager: EntityManager = req.scope.resolve("manager")
|
||||||
|
const result = await manager.transaction(async (transactionManager) => {
|
||||||
|
return await authService
|
||||||
|
.withTransaction(transactionManager)
|
||||||
|
.authenticateCustomer(validated.email, validated.password)
|
||||||
|
})
|
||||||
|
|
||||||
|
if (result.success && result.customer) {
|
||||||
|
// Create jwt token to send back
|
||||||
|
const token = jwt.sign(
|
||||||
|
{ customer_id: result.customer.id, domain: "store" },
|
||||||
|
jwt_secret,
|
||||||
|
{
|
||||||
|
expiresIn: "30d",
|
||||||
|
}
|
||||||
|
)
|
||||||
|
|
||||||
|
res.json({ access_token: token })
|
||||||
|
} else {
|
||||||
|
res.sendStatus(401)
|
||||||
|
}
|
||||||
|
}
|
||||||
@@ -15,6 +15,7 @@ export default (app) => {
|
|||||||
route.get("/:email", middlewares.wrap(require("./exists").default))
|
route.get("/:email", middlewares.wrap(require("./exists").default))
|
||||||
route.delete("/", middlewares.wrap(require("./delete-session").default))
|
route.delete("/", middlewares.wrap(require("./delete-session").default))
|
||||||
route.post("/", middlewares.wrap(require("./create-session").default))
|
route.post("/", middlewares.wrap(require("./create-session").default))
|
||||||
|
route.post("/token", middlewares.wrap(require("./get-token").default))
|
||||||
|
|
||||||
return app
|
return app
|
||||||
}
|
}
|
||||||
@@ -41,6 +42,18 @@ export type StoreAuthRes = {
|
|||||||
customer: Customer
|
customer: Customer
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @schema StoreBearerAuthRes
|
||||||
|
* type: object
|
||||||
|
* properties:
|
||||||
|
* accessToken:
|
||||||
|
* description: Access token for subsequent authorization.
|
||||||
|
* type: string
|
||||||
|
*/
|
||||||
|
export type StoreBearerAuthRes = {
|
||||||
|
access_token: string
|
||||||
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @schema StoreGetAuthEmailRes
|
* @schema StoreGetAuthEmailRes
|
||||||
* type: object
|
* type: object
|
||||||
@@ -59,3 +72,4 @@ export * from "./create-session"
|
|||||||
export * from "./delete-session"
|
export * from "./delete-session"
|
||||||
export * from "./exists"
|
export * from "./exists"
|
||||||
export * from "./get-session"
|
export * from "./get-session"
|
||||||
|
export * from "./get-token"
|
||||||
@@ -103,13 +103,7 @@ export default async (req, res) => {
|
|||||||
select: defaultStoreCustomersFields,
|
select: defaultStoreCustomersFields,
|
||||||
})
|
})
|
||||||
|
|
||||||
// Add JWT to cookie
|
req.session.customer_id = customer.id
|
||||||
const {
|
|
||||||
projectConfig: { jwt_secret },
|
|
||||||
} = req.scope.resolve("configModule")
|
|
||||||
req.session.jwt_store = jwt.sign({ customer_id: customer.id }, jwt_secret!, {
|
|
||||||
expiresIn: "30d",
|
|
||||||
})
|
|
||||||
|
|
||||||
res.status(200).json({ customer })
|
res.status(200).json({ customer })
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -84,7 +84,7 @@ container.register("modulesHelper", asValue(moduleHelper))
|
|||||||
container.register("configModule", asValue(config))
|
container.register("configModule", asValue(config))
|
||||||
container.register({
|
container.register({
|
||||||
logger: asValue({
|
logger: asValue({
|
||||||
error: () => {},
|
error: () => { },
|
||||||
}),
|
}),
|
||||||
manager: asValue(MockManager),
|
manager: asValue(MockManager),
|
||||||
})
|
})
|
||||||
@@ -145,31 +145,20 @@ export async function request(method, url, opts = {}) {
|
|||||||
)
|
)
|
||||||
headers.Cookie = headers.Cookie || ""
|
headers.Cookie = headers.Cookie || ""
|
||||||
if (opts.adminSession) {
|
if (opts.adminSession) {
|
||||||
const adminSession = { ...opts.adminSession }
|
const token = jwt.sign(
|
||||||
|
{ user_id: opts.adminSession.userId || opts.adminSession.jwt?.userId, domain: "admin" },
|
||||||
|
config.projectConfig.jwt_secret
|
||||||
|
)
|
||||||
|
|
||||||
if (adminSession.jwt) {
|
headers.Authorization = `Bearer ${token}`
|
||||||
adminSession.jwt = jwt.sign(
|
|
||||||
adminSession.jwt,
|
|
||||||
config.projectConfig.jwt_secret,
|
|
||||||
{
|
|
||||||
expiresIn: "30m",
|
|
||||||
}
|
|
||||||
)
|
|
||||||
}
|
|
||||||
headers.Cookie = JSON.stringify(adminSession) || ""
|
|
||||||
}
|
}
|
||||||
if (opts.clientSession) {
|
if (opts.clientSession) {
|
||||||
if (opts.clientSession.jwt) {
|
const token = jwt.sign(
|
||||||
opts.clientSession.jwt_store = jwt.sign(
|
{ customer_id: opts.clientSession.customer_id || opts.clientSession.jwt?.customer_id, domain: "store" },
|
||||||
opts.clientSession.jwt,
|
config.projectConfig.jwt_secret
|
||||||
config.projectConfig.jwt_secret,
|
)
|
||||||
{
|
|
||||||
expiresIn: "30d",
|
|
||||||
}
|
|
||||||
)
|
|
||||||
}
|
|
||||||
|
|
||||||
headers.Cookie = JSON.stringify(opts.clientSession) || ""
|
headers.Authorization = `Bearer ${token}`
|
||||||
}
|
}
|
||||||
|
|
||||||
for (const name in headers) {
|
for (const name in headers) {
|
||||||
|
|||||||
@@ -1,8 +1,8 @@
|
|||||||
import { Express } from "express"
|
import { Express } from "express"
|
||||||
import passport from "passport"
|
import passport from "passport"
|
||||||
import { Strategy as BearerStrategy } from "passport-http-bearer"
|
import { Strategy as JWTStrategy, ExtractJwt } from "passport-jwt"
|
||||||
import { Strategy as JWTStrategy } from "passport-jwt"
|
|
||||||
import { Strategy as LocalStrategy } from "passport-local"
|
import { Strategy as LocalStrategy } from "passport-local"
|
||||||
|
import { Strategy as CustomStrategy } from "passport-custom"
|
||||||
import { AuthService } from "../services"
|
import { AuthService } from "../services"
|
||||||
import { ConfigModule, MedusaContainer } from "../types/global"
|
import { ConfigModule, MedusaContainer } from "../types/global"
|
||||||
|
|
||||||
@@ -46,43 +46,105 @@ export default async ({
|
|||||||
// calls will be authenticated based on the JWT
|
// calls will be authenticated based on the JWT
|
||||||
const { jwt_secret } = configModule.projectConfig
|
const { jwt_secret } = configModule.projectConfig
|
||||||
passport.use(
|
passport.use(
|
||||||
"admin-jwt",
|
"admin-session",
|
||||||
new JWTStrategy(
|
new CustomStrategy(
|
||||||
{
|
async (req, done) => {
|
||||||
jwtFromRequest: (req) => req.session.jwt,
|
// @ts-ignore
|
||||||
secretOrKey: jwt_secret,
|
if(req.session?.user_id) {
|
||||||
},
|
// @ts-ignore
|
||||||
async (jwtPayload, done) => {
|
return done(null, { userId: req.session.user_id })
|
||||||
return done(null, jwtPayload)
|
}
|
||||||
|
|
||||||
|
return done(null, false)
|
||||||
}
|
}
|
||||||
)
|
)
|
||||||
)
|
)
|
||||||
|
|
||||||
passport.use(
|
passport.use(
|
||||||
"store-jwt",
|
"store-session",
|
||||||
new JWTStrategy(
|
new CustomStrategy(
|
||||||
{
|
async (req, done) => {
|
||||||
jwtFromRequest: (req) => req.session.jwt_store,
|
// @ts-ignore
|
||||||
secretOrKey: jwt_secret,
|
if(req.session?.customer_id) {
|
||||||
},
|
// @ts-ignore
|
||||||
async (jwtPayload, done) => {
|
return done(null, { customer_id: req.session.customer_id })
|
||||||
return done(null, jwtPayload)
|
}
|
||||||
|
|
||||||
|
return done(null, false)
|
||||||
}
|
}
|
||||||
)
|
)
|
||||||
)
|
)
|
||||||
|
|
||||||
// Alternatively use bearer token to authenticate to the admin api
|
// Alternatively use API token to authenticate to the admin api
|
||||||
passport.use(
|
passport.use(
|
||||||
new BearerStrategy(async (token, done) => {
|
"admin-api-token",
|
||||||
const auth = await authService.authenticateAPIToken(token)
|
new CustomStrategy(async (req, done) => {
|
||||||
|
// extract the token from the header
|
||||||
|
const token = req.headers["x-medusa-access-token"];
|
||||||
|
|
||||||
|
// check if header exists and is string
|
||||||
|
// typescript will complain if we don't check for type
|
||||||
|
if (!token || typeof token !== "string") {
|
||||||
|
return done(null, false)
|
||||||
|
}
|
||||||
|
|
||||||
|
const auth = await authService.authenticateAPIToken(token);
|
||||||
if (auth.success) {
|
if (auth.success) {
|
||||||
done(null, auth.user)
|
done(null, auth.user)
|
||||||
} else {
|
} else {
|
||||||
done(auth.error)
|
done(null, false)
|
||||||
}
|
}
|
||||||
})
|
})
|
||||||
)
|
)
|
||||||
|
|
||||||
|
// Admin bearer JWT token authentication strategy, best suited for web SPAs or mobile apps
|
||||||
|
passport.use(
|
||||||
|
"admin-bearer",
|
||||||
|
new JWTStrategy(
|
||||||
|
{
|
||||||
|
jwtFromRequest: ExtractJwt.fromAuthHeaderAsBearerToken(),
|
||||||
|
secretOrKey: jwt_secret,
|
||||||
|
},
|
||||||
|
(token, done) => {
|
||||||
|
if (token.domain !== "admin") {
|
||||||
|
done(null, false)
|
||||||
|
return
|
||||||
|
}
|
||||||
|
|
||||||
|
if (!token.user_id) {
|
||||||
|
done(null, false)
|
||||||
|
return
|
||||||
|
}
|
||||||
|
|
||||||
|
done(null, { userId: token.user_id })
|
||||||
|
}
|
||||||
|
)
|
||||||
|
)
|
||||||
|
|
||||||
|
// Store bearer JWT token authentication strategy, best suited for web SPAs or mobile apps
|
||||||
|
passport.use(
|
||||||
|
"store-bearer",
|
||||||
|
new JWTStrategy(
|
||||||
|
{
|
||||||
|
jwtFromRequest: ExtractJwt.fromAuthHeaderAsBearerToken(),
|
||||||
|
secretOrKey: jwt_secret,
|
||||||
|
},
|
||||||
|
(token, done) => {
|
||||||
|
if (token.domain !== "store") {
|
||||||
|
done(null, false)
|
||||||
|
return
|
||||||
|
}
|
||||||
|
|
||||||
|
if (!token.customer_id) {
|
||||||
|
done(null, false)
|
||||||
|
return
|
||||||
|
}
|
||||||
|
|
||||||
|
done(null, { customer_id: token.customer_id })
|
||||||
|
}
|
||||||
|
)
|
||||||
|
)
|
||||||
|
|
||||||
app.use(passport.initialize())
|
app.use(passport.initialize())
|
||||||
app.use(passport.session())
|
app.use(passport.session())
|
||||||
}
|
}
|
||||||
@@ -51,20 +51,6 @@ class AuthService extends TransactionBaseService {
|
|||||||
*/
|
*/
|
||||||
async authenticateAPIToken(token: string): Promise<AuthenticateResult> {
|
async authenticateAPIToken(token: string): Promise<AuthenticateResult> {
|
||||||
return await this.atomicPhase_(async (transactionManager) => {
|
return await this.atomicPhase_(async (transactionManager) => {
|
||||||
if (process.env.NODE_ENV?.startsWith("dev")) {
|
|
||||||
try {
|
|
||||||
const user: User = await this.userService_
|
|
||||||
.withTransaction(transactionManager)
|
|
||||||
.retrieve(token)
|
|
||||||
return {
|
|
||||||
success: true,
|
|
||||||
user,
|
|
||||||
}
|
|
||||||
} catch (error) {
|
|
||||||
// ignore
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
try {
|
try {
|
||||||
const user: User = await this.userService_
|
const user: User = await this.userService_
|
||||||
.withTransaction(transactionManager)
|
.withTransaction(transactionManager)
|
||||||
@@ -138,7 +124,7 @@ class AuthService extends TransactionBaseService {
|
|||||||
* @param {string} password - the password of the user
|
* @param {string} password - the password of the user
|
||||||
* @return {{ success: (bool), customer: (object | undefined) }}
|
* @return {{ success: (bool), customer: (object | undefined) }}
|
||||||
* success: whether authentication succeeded
|
* success: whether authentication succeeded
|
||||||
* user: the user document if authentication succeeded
|
* customer: the customer document if authentication succeded
|
||||||
* error: a string with the error message
|
* error: a string with the error message
|
||||||
*/
|
*/
|
||||||
async authenticateCustomer(
|
async authenticateCustomer(
|
||||||
|
|||||||
@@ -6640,7 +6640,7 @@ __metadata:
|
|||||||
node-schedule: ^2.1.1
|
node-schedule: ^2.1.1
|
||||||
papaparse: 5.3.2
|
papaparse: 5.3.2
|
||||||
passport: ^0.6.0
|
passport: ^0.6.0
|
||||||
passport-http-bearer: ^1.0.1
|
passport-custom: ^1.1.1
|
||||||
passport-jwt: ^4.0.1
|
passport-jwt: ^4.0.1
|
||||||
passport-local: ^1.0.0
|
passport-local: ^1.0.0
|
||||||
pg: ^8.11.2
|
pg: ^8.11.2
|
||||||
@@ -35100,12 +35100,12 @@ __metadata:
|
|||||||
languageName: node
|
languageName: node
|
||||||
linkType: hard
|
linkType: hard
|
||||||
|
|
||||||
"passport-http-bearer@npm:^1.0.1":
|
"passport-custom@npm:^1.1.1":
|
||||||
version: 1.0.1
|
version: 1.1.1
|
||||||
resolution: "passport-http-bearer@npm:1.0.1"
|
resolution: "passport-custom@npm:1.1.1"
|
||||||
dependencies:
|
dependencies:
|
||||||
passport-strategy: 1.x.x
|
passport-strategy: 1.x.x
|
||||||
checksum: e6de1de6a940857581c5add7c54ecb3a8573a17b0d2b78e21e888b6a4b375f85cad8d482dcb3cbf313b479e303c337e720028feb9ff9fb26d2ecef55a6b2f55a
|
checksum: 49b6fcd125dcd60272d4f02c27acb3b61b2659f3148bc10b31b7c439314054ce32c83a12f422215bdfa83d0463668a1f38ca6e8d68ccd32c922f73ccaa5ac9b3
|
||||||
languageName: node
|
languageName: node
|
||||||
linkType: hard
|
linkType: hard
|
||||||
|
|
||||||
|
|||||||
Reference in new issue
Block a user