From 4961aece1c7d94f93d31126a0ccf95bf17b676e9 Mon Sep 17 00:00:00 2001 From: Shahed Nasser Date: Sun, 4 Sep 2022 21:08:05 +0300 Subject: [PATCH] docs: Add request and error examples (#2109) --- docs/api/admin-spec3-base.json | 173 ---------- docs/api/admin-spec3-base.yaml | 321 ++++++++++++++++++ docs/api/store-spec3-base.json | 84 ----- docs/api/store-spec3-base.yaml | 227 +++++++++++++ .../src/api/middlewares/await-middleware.ts | 15 + .../src/api/middlewares/error-handler.ts | 16 + .../api/routes/admin/apps/authorize-app.ts | 27 ++ .../medusa/src/api/routes/admin/apps/list.ts | 21 ++ .../api/routes/admin/auth/create-session.ts | 33 +- .../api/routes/admin/auth/delete-session.ts | 28 ++ .../src/api/routes/admin/auth/get-session.ts | 31 +- .../routes/admin/batch/cancel-batch-job.ts | 31 ++ .../routes/admin/batch/confirm-batch-job.ts | 31 ++ .../routes/admin/batch/create-batch-job.ts | 39 +++ .../api/routes/admin/batch/get-batch-job.ts | 31 ++ .../api/routes/admin/batch/list-batch-jobs.ts | 31 ++ .../routes/admin/collections/add-products.ts | 27 ++ .../admin/collections/create-collection.ts | 37 ++ .../admin/collections/delete-collection.ts | 31 ++ .../admin/collections/get-collection.ts | 31 ++ .../admin/collections/list-collections.ts | 31 ++ .../admin/collections/remove-products.ts | 27 ++ .../admin/collections/update-collection.ts | 37 ++ .../customer-groups/add-customers-batch.ts | 45 +++ .../customer-groups/create-customer-group.ts | 37 ++ .../customer-groups/delete-customer-group.ts | 31 ++ .../customer-groups/delete-customers-batch.ts | 45 +++ .../get-customer-group-customers.ts | 31 ++ .../customer-groups/get-customer-group.ts | 31 ++ .../customer-groups/list-customer-groups.ts | 32 +- .../customer-groups/update-customer-group.ts | 37 ++ .../routes/admin/customers/create-customer.ts | 43 +++ .../routes/admin/customers/get-customer.ts | 31 ++ .../routes/admin/customers/list-customers.ts | 31 ++ .../routes/admin/customers/update-customer.ts | 37 ++ .../api/routes/admin/discounts/add-region.ts | 31 ++ .../admin/discounts/create-condition.ts | 39 ++- .../routes/admin/discounts/create-discount.ts | 50 +++ .../admin/discounts/create-dynamic-code.ts | 38 +++ .../admin/discounts/delete-condition.ts | 31 ++ .../routes/admin/discounts/delete-discount.ts | 31 ++ .../admin/discounts/delete-dynamic-code.ts | 31 ++ .../routes/admin/discounts/get-condition.ts | 34 +- .../admin/discounts/get-discount-by-code.ts | 31 ++ .../routes/admin/discounts/get-discount.ts | 31 ++ .../routes/admin/discounts/list-discounts.ts | 31 ++ .../routes/admin/discounts/remove-region.ts | 31 ++ .../admin/discounts/update-condition.ts | 41 +++ .../routes/admin/discounts/update-discount.ts | 37 ++ .../admin/draft-orders/create-draft-order.ts | 59 ++++ .../admin/draft-orders/create-line-item.ts | 37 ++ .../admin/draft-orders/delete-draft-order.ts | 31 ++ .../admin/draft-orders/delete-line-item.ts | 31 ++ .../admin/draft-orders/get-draft-order.ts | 31 ++ .../admin/draft-orders/list-draft-orders.ts | 31 ++ .../admin/draft-orders/register-payment.ts | 31 ++ .../admin/draft-orders/update-draft-order.ts | 37 ++ .../admin/draft-orders/update-line-item.ts | 37 ++ .../admin/gift-cards/create-gift-card.ts | 37 ++ .../admin/gift-cards/delete-gift-card.ts | 31 ++ .../routes/admin/gift-cards/get-gift-card.ts | 31 ++ .../admin/gift-cards/list-gift-cards.ts | 31 ++ .../admin/gift-cards/update-gift-card.ts | 37 ++ .../api/routes/admin/invites/accept-invite.ts | 50 +++ .../api/routes/admin/invites/create-invite.ts | 42 +++ .../api/routes/admin/invites/delete-invite.ts | 31 ++ .../api/routes/admin/invites/list-invites.ts | 31 ++ .../api/routes/admin/invites/resend-invite.ts | 34 ++ .../src/api/routes/admin/notes/create-note.ts | 41 +++ .../src/api/routes/admin/notes/delete-note.ts | 31 ++ .../src/api/routes/admin/notes/get-note.ts | 31 ++ .../src/api/routes/admin/notes/list-notes.ts | 31 ++ .../src/api/routes/admin/notes/update-note.ts | 38 ++- .../admin/notifications/list-notifications.ts | 31 ++ .../notifications/resend-notification.ts | 31 ++ .../admin/orders/add-shipping-method.ts | 39 +++ .../api/routes/admin/orders/archive-order.ts | 31 ++ .../api/routes/admin/orders/cancel-claim.ts | 31 ++ .../admin/orders/cancel-fulfillment-claim.ts | 31 ++ .../admin/orders/cancel-fulfillment-swap.ts | 31 ++ .../routes/admin/orders/cancel-fulfillment.ts | 31 ++ .../api/routes/admin/orders/cancel-order.ts | 31 ++ .../api/routes/admin/orders/cancel-swap.ts | 31 ++ .../routes/admin/orders/capture-payment.ts | 31 ++ .../api/routes/admin/orders/complete-order.ts | 31 ++ .../admin/orders/create-claim-shipment.ts | 37 ++ .../api/routes/admin/orders/create-claim.ts | 49 +++ .../routes/admin/orders/create-fulfillment.ts | 47 +++ .../routes/admin/orders/create-shipment.ts | 37 ++ .../admin/orders/create-swap-shipment.ts | 37 ++ .../api/routes/admin/orders/create-swap.ts | 47 +++ .../api/routes/admin/orders/fulfill-claim.ts | 31 ++ .../api/routes/admin/orders/fulfill-swap.ts | 31 ++ .../src/api/routes/admin/orders/get-order.ts | 31 ++ .../api/routes/admin/orders/list-orders.ts | 31 ++ .../admin/orders/process-swap-payment.ts | 31 ++ .../api/routes/admin/orders/refund-payment.ts | 39 +++ .../api/routes/admin/orders/request-return.ts | 47 +++ .../api/routes/admin/orders/update-claim.ts | 37 ++ .../api/routes/admin/orders/update-order.ts | 37 ++ .../admin/price-lists/add-prices-batch.ts | 49 +++ .../admin/price-lists/create-price-list.ts | 56 +++ .../admin/price-lists/delete-price-list.ts | 31 ++ .../admin/price-lists/delete-prices-batch.ts | 41 +++ .../price-lists/delete-product-prices.ts | 31 ++ .../price-lists/delete-variant-prices.ts | 31 ++ .../admin/price-lists/get-price-list.ts | 31 ++ .../price-lists/list-price-list-products.ts | 31 ++ .../admin/price-lists/list-price-lists.ts | 31 ++ .../admin/price-lists/update-price-list.ts | 37 ++ .../admin/product-tags/list-product-tags.ts | 31 ++ .../admin/product-types/list-product-types.ts | 31 ++ .../api/routes/admin/products/add-option.ts | 37 ++ .../routes/admin/products/create-product.ts | 39 +++ .../routes/admin/products/create-variant.ts | 62 ++++ .../routes/admin/products/delete-option.ts | 31 ++ .../routes/admin/products/delete-product.ts | 31 ++ .../routes/admin/products/delete-variant.ts | 31 ++ .../api/routes/admin/products/get-product.ts | 31 ++ .../routes/admin/products/list-products.ts | 31 ++ .../admin/products/list-tag-usage-count.ts | 31 ++ .../api/routes/admin/products/list-types.ts | 31 ++ .../routes/admin/products/list-variants.ts | 21 ++ .../api/routes/admin/products/set-metadata.ts | 39 +++ .../routes/admin/products/update-option.ts | 37 ++ .../routes/admin/products/update-product.ts | 38 +++ .../routes/admin/products/update-variant.ts | 58 ++++ .../api/routes/admin/regions/add-country.ts | 37 ++ .../admin/regions/add-fulfillment-provider.ts | 37 ++ .../admin/regions/add-payment-provider.ts | 37 ++ .../api/routes/admin/regions/create-region.ts | 59 ++++ .../api/routes/admin/regions/delete-region.ts | 31 ++ .../admin/regions/get-fulfillment-options.ts | 31 ++ .../api/routes/admin/regions/get-region.ts | 31 ++ .../api/routes/admin/regions/list-regions.ts | 31 ++ .../routes/admin/regions/remove-country.ts | 31 ++ .../regions/remove-fulfillment-provider.ts | 31 ++ .../admin/regions/remove-payment-provider.ts | 31 ++ .../api/routes/admin/regions/update-region.ts | 37 ++ .../admin/return-reasons/create-reason.ts | 39 +++ .../admin/return-reasons/delete-reason.ts | 31 ++ .../routes/admin/return-reasons/get-reason.ts | 31 ++ .../admin/return-reasons/list-reasons.ts | 31 ++ .../admin/return-reasons/update-reason.ts | 37 ++ .../api/routes/admin/returns/cancel-return.ts | 31 ++ .../api/routes/admin/returns/list-returns.ts | 31 ++ .../routes/admin/returns/receive-return.ts | 47 +++ .../admin/sales-channels/add-product-batch.ts | 45 +++ .../sales-channels/create-sales-channel.ts | 38 +++ .../sales-channels/delete-products-batch.ts | 45 +++ .../sales-channels/delete-sales-channel.ts | 31 ++ .../admin/sales-channels/get-sales-channel.ts | 31 ++ .../sales-channels/list-sales-channels.ts | 31 ++ .../sales-channels/update-sales-channel.ts | 37 ++ .../create-shipping-option.ts | 46 +++ .../delete-shipping-option.ts | 31 ++ .../shipping-options/get-shipping-option.ts | 31 ++ .../shipping-options/list-shipping-options.ts | 31 ++ .../update-shipping-option.ts | 49 +++ .../create-shipping-profile.ts | 37 ++ .../delete-shipping-profile.ts | 31 ++ .../shipping-profiles/get-shipping-profile.ts | 31 ++ .../list-shipping-profiles.ts | 31 ++ .../update-shipping-profile.ts | 37 ++ .../api/routes/admin/store/add-currency.ts | 31 ++ .../src/api/routes/admin/store/get-store.ts | 31 ++ .../admin/store/list-payment-providers.ts | 31 ++ .../routes/admin/store/list-tax-providers.ts | 31 ++ .../api/routes/admin/store/remove-currency.ts | 31 ++ .../api/routes/admin/store/update-store.ts | 37 ++ .../src/api/routes/admin/swaps/get-swap.ts | 31 ++ .../src/api/routes/admin/swaps/list-swaps.ts | 31 ++ .../admin/tax-rates/add-to-product-types.ts | 41 +++ .../routes/admin/tax-rates/add-to-products.ts | 41 +++ .../tax-rates/add-to-shipping-options.ts | 41 +++ .../routes/admin/tax-rates/create-tax-rate.ts | 41 +++ .../routes/admin/tax-rates/delete-tax-rate.ts | 31 ++ .../routes/admin/tax-rates/get-tax-rate.ts | 31 ++ .../routes/admin/tax-rates/list-tax-rates.ts | 31 ++ .../tax-rates/remove-from-product-types.ts | 41 +++ .../admin/tax-rates/remove-from-products.ts | 41 +++ .../tax-rates/remove-from-shipping-options.ts | 41 +++ .../routes/admin/tax-rates/update-tax-rate.ts | 37 ++ .../api/routes/admin/uploads/create-upload.ts | 37 +- .../api/routes/admin/uploads/delete-upload.ts | 37 ++ .../routes/admin/uploads/get-download-url.ts | 37 ++ .../src/api/routes/admin/users/create-user.ts | 39 +++ .../src/api/routes/admin/users/delete-user.ts | 31 ++ .../src/api/routes/admin/users/get-user.ts | 31 ++ .../src/api/routes/admin/users/list-users.ts | 31 ++ .../admin/users/reset-password-token.ts | 40 +++ .../api/routes/admin/users/reset-password.ts | 39 +++ .../src/api/routes/admin/users/update-user.ts | 38 ++- .../routes/admin/variants/list-variants.ts | 31 ++ .../api/routes/store/auth/create-session.ts | 34 ++ .../api/routes/store/auth/delete-session.ts | 21 ++ .../src/api/routes/store/auth/exists.ts | 22 ++ .../src/api/routes/store/auth/get-session.ts | 32 +- .../routes/store/carts/add-shipping-method.ts | 34 +- .../api/routes/store/carts/calculate-taxes.ts | 15 + .../api/routes/store/carts/complete-cart.ts | 24 ++ .../src/api/routes/store/carts/create-cart.ts | 24 ++ .../routes/store/carts/create-line-item.ts | 32 ++ .../store/carts/create-payment-sessions.ts | 24 ++ .../api/routes/store/carts/delete-discount.ts | 24 ++ .../routes/store/carts/delete-line-item.ts | 24 ++ .../store/carts/delete-payment-session.ts | 24 ++ .../src/api/routes/store/carts/get-cart.ts | 24 ++ .../store/carts/refresh-payment-session.ts | 24 ++ .../routes/store/carts/set-payment-session.ts | 30 ++ .../src/api/routes/store/carts/update-cart.ts | 30 ++ .../routes/store/carts/update-line-item.ts | 30 ++ .../store/carts/update-payment-session.ts | 32 ++ .../store/collections/get-collection.ts | 24 ++ .../store/collections/list-collections.ts | 24 ++ .../routes/store/customers/create-address.ts | 55 +++ .../routes/store/customers/create-customer.ts | 34 ++ .../routes/store/customers/delete-address.ts | 30 ++ .../routes/store/customers/get-customer.ts | 30 ++ .../store/customers/get-payment-methods.ts | 30 ++ .../api/routes/store/customers/list-orders.ts | 30 ++ .../store/customers/reset-password-token.ts | 35 ++ .../routes/store/customers/reset-password.ts | 36 ++ .../routes/store/customers/update-address.ts | 36 ++ .../routes/store/customers/update-customer.ts | 36 ++ .../routes/store/gift-cards/get-gift-card.ts | 24 ++ .../routes/store/orders/get-order-by-cart.ts | 24 ++ .../src/api/routes/store/orders/get-order.ts | 24 ++ .../api/routes/store/orders/lookup-order.ts | 27 ++ .../api/routes/store/products/get-product.ts | 24 ++ .../routes/store/products/list-products.ts | 24 ++ .../src/api/routes/store/products/search.ts | 30 +- .../api/routes/store/regions/get-region.ts | 24 ++ .../api/routes/store/regions/list-regions.ts | 24 ++ .../routes/store/return-reasons/get-reason.ts | 24 ++ .../store/return-reasons/list-reasons.ts | 24 ++ .../api/routes/store/returns/create-return.ts | 42 +++ .../store/shipping-options/list-options.ts | 24 ++ .../shipping-options/list-shipping-options.ts | 24 ++ .../src/api/routes/store/swaps/create-swap.ts | 54 +++ .../routes/store/swaps/get-swap-by-cart.ts | 24 ++ .../api/routes/store/variants/get-variant.ts | 15 + .../routes/store/variants/list-variants.ts | 15 + scripts/build-openapi.js | 19 +- www/docs/docusaurus.config.js | 5 +- www/docs/src/css/custom.css | 17 + 246 files changed, 8566 insertions(+), 285 deletions(-) delete mode 100644 docs/api/admin-spec3-base.json create mode 100644 docs/api/admin-spec3-base.yaml delete mode 100644 docs/api/store-spec3-base.json create mode 100644 docs/api/store-spec3-base.yaml diff --git a/docs/api/admin-spec3-base.json b/docs/api/admin-spec3-base.json deleted file mode 100644 index 8cfc3c2283..0000000000 --- a/docs/api/admin-spec3-base.json +++ /dev/null @@ -1,173 +0,0 @@ -{ - "openapi": "3.0.0", - "info": { - "version": "1.0.0", - "title": "Medusa Admin API", - "description": "API reference for Medusa's Admin endpoints. All endpoints are prefixed with `/admin`.", - "license": { - "name": "MIT", - "url": "https://github.com/medusajs/medusa/blob/master/LICENSE" - } - }, - "tags": [ - { - "name": "Auth", - "description": "Auth endpoints that allow authorization of admin Users and manages their sessions." - }, - { - "name": "App", - "description": "App endpoints that allow handling apps in Medusa.", - "x-resourceId": "OAuth" - }, - { - "name": "Batch Job", - "description": "Batch Job endpoints that allow handling batch jobs in Medusa.", - "x-resourceId": "batch_job" - }, - { - "name": "Claim", - "description": "Claim endpoints that allow handling claims in Medusa.", - "x-resourceId": "claim_order" - }, - { - "name": "Collection", - "description": "Collection endpoints that allow handling collections in Medusa.", - "x-resourceId": "product_collection" - }, - { - "name": "Customer", - "description": "Customer endpoints that allow handling customers in Medusa.", - "x-resourceId": "customer" - }, - { - "name": "Customer Group", - "description": "Customer Group endpoints that allow handling customer groups in Medusa.", - "x-resourceId": "customer_group" - }, - { - "name": "Discount", - "description": "Discount endpoints that allow handling discounts in Medusa.", - "x-resourceId": "discount" - }, - { - "name": "Discount Condition", - "description": "Discount Condition endpoints that allow handling discount conditions in Medusa.", - "x-resourceId": "discount_condition" - }, - { - "name": "Draft Order", - "description": "Draft Order endpoints that allow handling draft orders in Medusa.", - "x-resourceId": "draft-order" - }, - { - "name": "Gift Card", - "description": "Gift Card endpoints that allow handling gift cards in Medusa.", - "x-resourceId": "gift_card" - }, - { - "name": "Invite", - "description": "Invite endpoints that allow handling invites in Medusa.", - "x-resourceId": "invite" - }, - { - "name": "Note", - "description": "Note endpoints that allow handling notes in Medusa.", - "x-resourceId": "note" - }, - { - "name": "Notification", - "description": "Notification endpoints that allow handling notifications in Medusa.", - "x-resourceId": "notification" - }, - { - "name": "Order", - "description": "Order endpoints that allow handling orders in Medusa.", - "x-resourceId": "order" - }, - { - "name": "Price List", - "description": "Price List endpoints that allow handling price lists in Medusa.", - "x-resourceId": "price_list" - }, - { - "name": "Product", - "description": "Product endpoints that allow handling products in Medusa.", - "x-resourceId": "product" - }, - { - "name": "Product Tag", - "description": "Product Tag endpoints that allow handling product tags in Medusa.", - "x-resourceId": "product_tag" - }, - { - "name": "Product Types", - "description": "Product Types endpoints that allow handling product types in Medusa.", - "x-resourceId": "product_type" - }, - { - "name": "Product Variant", - "description": "Product Variant endpoints that allow handling product variants in Medusa.", - "x-resourceId": "product_variant" - }, - { - "name": "Region", - "description": "Region endpoints that allow handling regions in Medusa.", - "x-resourceId": "region" - }, - { - "name": "Return Reason", - "description": "Return Reason endpoints that allow handling return reasons in Medusa.", - "x-resourceId": "return_reason" - }, - { - "name": "Return", - "description": "Return endpoints that allow handling returns in Medusa.", - "x-resourceId": "return" - }, - { - "name": "Sales Channel", - "description": "Sales Channel endpoints that allow handling sales channels in Medusa.", - "x-resourceId": "sales_channel" - }, - { - "name": "Shipping Option", - "description": "Shipping Option endpoints that allow handling shipping options in Medusa.", - "x-resourceId": "shipping_option" - }, - { - "name": "Shipping Profile", - "description": "Shipping Profile endpoints that allow handling shipping profiles in Medusa.", - "x-resourceId": "shipping_profile" - }, - { - "name": "Store", - "description": "Store endpoints that allow handling stores in Medusa.", - "x-resourceId": "store" - }, - { - "name": "Swap", - "description": "Swap endpoints that allow handling swaps in Medusa.", - "x-resourceId": "swap" - }, - { - "name": "Tax Rate", - "description": "Tax Rate endpoints that allow handling tax rates in Medusa.", - "x-resourceId": "tax_rate" - }, - { - "name": "Upload", - "description": "Upload endpoints that allow handling uploads in Medusa." - }, - { - "name": "User", - "description": "User endpoints that allow handling users in Medusa.", - "x-resourceId": "user" - } - ], - "servers": [ - { - "url": "https://api.medusa-commerce.com/admin" - } - ], - "paths": {} -} diff --git a/docs/api/admin-spec3-base.yaml b/docs/api/admin-spec3-base.yaml new file mode 100644 index 0000000000..1c7dabb2b2 --- /dev/null +++ b/docs/api/admin-spec3-base.yaml @@ -0,0 +1,321 @@ +openapi: 3.0.0 +info: + version: 1.0.0 + title: Medusa Admin API + description: | + API reference for Medusa's Admin endpoints. All endpoints are prefixed with `/admin`. + + ## Authentication + + There are two ways to send authenticated requests to the Medusa server: Using a user's API token, or using a Cookie Session ID. + + + license: + name: MIT + url: https://github.com/medusajs/medusa/blob/master/LICENSE +tags: +- name: Auth + description: Auth endpoints that allow authorization of admin Users and manages + their sessions. +- name: App + description: App endpoints that allow handling apps in Medusa. + x-resourceId: OAuth +- name: Batch Job + description: Batch Job endpoints that allow handling batch jobs in Medusa. + x-resourceId: batch_job +- name: Claim + description: Claim endpoints that allow handling claims in Medusa. + x-resourceId: claim_order +- name: Collection + description: Collection endpoints that allow handling collections in Medusa. + x-resourceId: product_collection +- name: Customer + description: Customer endpoints that allow handling customers in Medusa. + x-resourceId: customer +- name: Customer Group + description: Customer Group endpoints that allow handling customer groups in Medusa. + x-resourceId: customer_group +- name: Discount + description: Discount endpoints that allow handling discounts in Medusa. + x-resourceId: discount +- name: Discount Condition + description: Discount Condition endpoints that allow handling discount conditions + in Medusa. + x-resourceId: discount_condition +- name: Draft Order + description: Draft Order endpoints that allow handling draft orders in Medusa. + x-resourceId: draft-order +- name: Gift Card + description: Gift Card endpoints that allow handling gift cards in Medusa. + x-resourceId: gift_card +- name: Invite + description: Invite endpoints that allow handling invites in Medusa. + x-resourceId: invite +- name: Note + description: Note endpoints that allow handling notes in Medusa. + x-resourceId: note +- name: Notification + description: Notification endpoints that allow handling notifications in Medusa. + x-resourceId: notification +- name: Order + description: Order endpoints that allow handling orders in Medusa. + x-resourceId: order +- name: Price List + description: Price List endpoints that allow handling price lists in Medusa. + x-resourceId: price_list +- name: Product + description: Product endpoints that allow handling products in Medusa. + x-resourceId: product +- name: Product Tag + description: Product Tag endpoints that allow handling product tags in Medusa. + x-resourceId: product_tag +- name: Product Type + description: Product Types endpoints that allow handling product types in Medusa. + x-resourceId: product_type +- name: Product Variant + description: Product Variant endpoints that allow handling product variants in Medusa. + x-resourceId: product_variant +- name: Region + description: Region endpoints that allow handling regions in Medusa. + x-resourceId: region +- name: Return Reason + description: Return Reason endpoints that allow handling return reasons in Medusa. + x-resourceId: return_reason +- name: Return + description: Return endpoints that allow handling returns in Medusa. + x-resourceId: return +- name: Sales Channel + description: Sales Channel endpoints that allow handling sales channels in Medusa. + x-resourceId: sales_channel +- name: Shipping Option + description: Shipping Option endpoints that allow handling shipping options in Medusa. + x-resourceId: shipping_option +- name: Shipping Profile + description: Shipping Profile endpoints that allow handling shipping profiles in + Medusa. + x-resourceId: shipping_profile +- name: Store + description: Store endpoints that allow handling stores in Medusa. + x-resourceId: store +- name: Swap + description: Swap endpoints that allow handling swaps in Medusa. + x-resourceId: swap +- name: Tax Rate + description: Tax Rate endpoints that allow handling tax rates in Medusa. + x-resourceId: tax_rate +- name: Upload + description: Upload endpoints that allow handling uploads in Medusa. +- name: User + description: User endpoints that allow handling users in Medusa. + x-resourceId: user +servers: +- url: https://api.medusa-commerce.com/admin +paths: {} +components: + responses: + default_error: + description: Default Error + content: + application/json: + schema: + $ref: "#/components/schemas/error" + example: + code: "unknown_error" + message: "An unknown error occurred." + type: "unknown_error" + invalid_state_error: + description: Invalid State Error + content: + application/json: + schema: + $ref: "#/components/schemas/error" + example: + code: "unknown_error" + message: "The request conflicted with another request. You may retry the request with the provided Idempotency-Key." + type: "QueryRunnerAlreadyReleasedError" + invalid_request_error: + description: Invalid Request Error + content: + application/json: + schema: + $ref: "#/components/schemas/error" + example: + code: "invalid_request_error" + message: "Discount with code TEST already exists." + type: "duplicate_error" + not_found_error: + description: Not Found Error + content: + application/json: + schema: + $ref: "#/components/schemas/error" + example: + message: "Entity with id 1 was not found" + type: "not_found" + 400_error: + description: Client Error or Multiple Errors + content: + application/json: + schema: + oneOf: + - $ref: "#/components/schemas/error" + - $ref: "#/components/schemas/multiple_errors" + examples: + not_allowed: + $ref: "#/components/examples/not_allowed_error" + invalid_data: + $ref: "#/components/examples/invalid_data_error" + multiple_errors: + $ref: "#/components/examples/multiple_errors" + 500_error: + description: Server Error + content: + application/json: + schema: + $ref: "#/components/schemas/error" + examples: + database: + $ref: "#/components/examples/database_error" + unexpected_state: + $ref: "#/components/examples/unexpected_state_error" + invalid_argument: + $ref: "#/components/examples/invalid_argument_error" + default_error: + $ref: "#/components/examples/default_error" + unauthorized: + description: 'User is not authorized. Must log in first' + content: + text/plain: + schema: + type: string + default: Unauthorized + example: Unauthorized + incorrect_credentials: + description: 'User does not exist or incorrect credentials' + content: + text/plain: + schema: + type: string + default: Unauthorized + example: Unauthorized + examples: + not_allowed_error: + summary: Not Allowed Error + value: + message: "Discount must be set to dynamic" + type: "not_allowed" + invalid_data_error: + summary: Invalid Data Error + value: + message: "first_name must be a string" + type: "invalid_data" + multiple_errors: + summary: Multiple Errors + value: + message: "Provided request body contains errors. Please check the data and retry the request" + errors: + - message: "first_name must be a string" + type: "invalid_data" + - message: "Discount must be set to dynamic" + type: "not_allowed" + database_error: + summary: Database Error + value: + code: "api_error" + message: "An error occured while hashing password" + type: "database_error" + unexpected_state_error: + summary: Unexpected State Error + value: + message: "cart.total must be defined" + type: "unexpected_state" + invalid_argument_error: + summary: Invalid Argument Error + value: + message: "cart.total must be defined" + type: "unexpected_state" + default_error: + summary: Default Error + value: + code: "unknown_error" + message: "An unknown error occurred." + type: "unknown_error" + securitySchemes: + api_token: + type: http + x-displayName: API Token + description: | + Use a user's API Token to send authenticated requests. + + ### How to Add API Token to a User + + At the moment, there's no direct way of adding an API Token for a user. The only way it can be done is through directly editing the database. + + If you're using a PostgreSQL database, you can run the following commands in your command line to add API token: + + ```bash + psql -d -U + UPDATE public.user SET api_token='' WHERE email=''; + ``` + + Where: + - `` is the name of the database schema you use for the Medusa server. + - `` is the name of the user that has privileges over the database schema. + - `` is the API token you want to associate with the user. You can use [this tool to generate a random token](https://randomkeygen.com/). + - `` is the email address of the admin user you want to have this API token. + + ### How to Use the API Token + + The API token can be used for Bearer Authentication. It's passed in the `Authorization` header as the following: + + ``` + Authorization: Bearer {api_token} + ``` + + In this API reference, you'll find in the cURL request samples the use of `{api_token}`. This is where you must pass the API token. + + If you're alternatively following along with the JS Client request samples, you must provide the `apiKey` option when creating the Medusa client: + + ```js + const medusa = new Medusa({ baseUrl: MEDUSA_BACKEND_URL, maxRetries: 3, apiKey: '{api_token}' }) + ``` + scheme: bearer + cookie_auth: + type: apiKey + in: cookie + name: connect.sid + x-displayName: Cookie Session ID + description: | + Use a cookie session to send authenticated requests. + + ### How to Obtain the Cookie Session + + If you're sending requests through a browser, using JS Client, or using tools like Postman, the cookie session should be automatically set when the admin user is logged in. + + If you're sending requests using cURL, you must set the Session ID in the cookie manually. + + To do that, send a request to [authenticate the user](#tag/Auth/operation/PostAuth) and pass the cURL option `-v`: + + ```bash + curl -v --location --request POST 'https://medusa-url.com/admin/auth' \ + --header 'Content-Type: application/json' \ + --data-raw '{ + "email": "user@example.com", + "password": "supersecret" + }' + ``` + + The headers will be logged in the terminal as well as the response. You should find in the headers a Cookie header similar to this: + + ```bash + Set-Cookie: connect.sid=s%3A2Bu8BkaP9JUfHu9rG59G16Ma0QZf6Gj1.WT549XqX37PN8n0OecqnMCq798eLjZC5IT7yiDCBHPM; + ``` + + Copy the value after `connect.sid` (without the `;` at the end) and pass it as a cookie in subsequent requests as the following: + + ```bash + curl --location --request GET 'https://medusa-url.com/admin/products' \ + --header 'Cookie: connect.sid={sid}' + ``` + + Where `{sid}` is the value of `connect.sid` that you copied. \ No newline at end of file diff --git a/docs/api/store-spec3-base.json b/docs/api/store-spec3-base.json deleted file mode 100644 index 777afcd8fb..0000000000 --- a/docs/api/store-spec3-base.json +++ /dev/null @@ -1,84 +0,0 @@ -{ - "openapi": "3.0.0", - "info": { - "version": "1.0.0", - "title": "Medusa Storefront API", - "description": "API reference for Medusa's Storefront endpoints. All endpoints are prefixed with `/store`.", - "license": { - "name": "MIT", - "url": "https://github.com/medusajs/medusa/blob/master/LICENSE" - } - }, - "tags": [ - { - "name": "Auth", - "description": "Auth endpoints that allow authorization of customers and manages their sessions." - }, - { - "name": "Cart", - "description": "Cart endpoints that allow handling carts in Medusa.", - "x-resourceId": "cart" - }, - { - "name": "Collection", - "description": "Collection endpoints that allow handling collections in Medusa.", - "x-resourceId": "product_collection" - }, - { - "name": "Customer", - "description": "Customer endpoints that allow handling customers in Medusa.", - "x-resourceId": "customer" - }, - { - "name": "Gift Card", - "description": "Gift Card endpoints that allow handling gift cards in Medusa.", - "x-resourceId": "gift_card" - }, - { - "name": "Order", - "description": "Order endpoints that allow handling orders in Medusa.", - "x-resourceId": "order" - }, - { - "name": "Product", - "description": "Product endpoints that allow handling products in Medusa.", - "x-resourceId": "product" - }, - { - "name": "Product Variant", - "description": "Product Variant endpoints that allow handling product variants in Medusa.", - "x-resourceId": "product_variant" - }, - { - "name": "Region", - "description": "Region endpoints that allow handling regions in Medusa.", - "x-resourceId": "region" - }, - { - "name": "Return Reason", - "description": "Return Reason endpoints that allow handling return reasons in Medusa.", - "x-resourceId": "return_reason" - }, - { - "name": "Return", - "description": "Return endpoints that allow handling returns in Medusa.", - "x-resourceId": "return" - }, - { - "name": "Shipping Option", - "description": "Shipping Option endpoints that allow handling shipping options in Medusa.", - "x-resourceId": "shipping_option" - }, - { - "name": "Swap", - "description": "Swap endpoints that allow handling swaps in Medusa.", - "x-resourceId": "swap" - } - ], - "servers": [ - { - "url": "https://api.medusa-commerce.com/store" - } - ], - "paths": {} -} diff --git a/docs/api/store-spec3-base.yaml b/docs/api/store-spec3-base.yaml new file mode 100644 index 0000000000..c7b0babcc8 --- /dev/null +++ b/docs/api/store-spec3-base.yaml @@ -0,0 +1,227 @@ +openapi: 3.0.0 +info: + version: 1.0.0 + title: Medusa Storefront API + description: | + API reference for Medusa's Storefront endpoints. All endpoints are prefixed with `/store`. + + ## Authentication + + To send requests as an authenticated customer, you must use the Cookie Session ID. + + + license: + name: MIT + url: https://github.com/medusajs/medusa/blob/master/LICENSE +tags: +- name: Auth + description: Auth endpoints that allow authorization of customers and manages their + sessions. +- name: Cart + description: Cart endpoints that allow handling carts in Medusa. + x-resourceId: cart +- name: Collection + description: Collection endpoints that allow handling collections in Medusa. + x-resourceId: product_collection +- name: Customer + description: Customer endpoints that allow handling customers in Medusa. + x-resourceId: customer +- name: Gift Card + description: Gift Card endpoints that allow handling gift cards in Medusa. + x-resourceId: gift_card +- name: Order + description: Order endpoints that allow handling orders in Medusa. + x-resourceId: order +- name: Product + description: Product endpoints that allow handling products in Medusa. + x-resourceId: product +- name: Product Variant + description: Product Variant endpoints that allow handling product variants in Medusa. + x-resourceId: product_variant +- name: Region + description: Region endpoints that allow handling regions in Medusa. + x-resourceId: region +- name: Return Reason + description: Return Reason endpoints that allow handling return reasons in Medusa. + x-resourceId: return_reason +- name: Return + description: Return endpoints that allow handling returns in Medusa. + x-resourceId: return +- name: Shipping Option + description: Shipping Option endpoints that allow handling shipping options in Medusa. + x-resourceId: shipping_option +- name: Swap + description: Swap endpoints that allow handling swaps in Medusa. + x-resourceId: swap +servers: +- url: https://api.medusa-commerce.com/store +paths: {} +components: + responses: + default_error: + description: Default Error + content: + application/json: + schema: + $ref: "#/components/schemas/error" + example: + code: "unknown_error" + message: "An unknown error occurred." + type: "unknown_error" + invalid_state_error: + description: Invalid State Error + content: + application/json: + schema: + $ref: "#/components/schemas/error" + example: + code: "unknown_error" + message: "The request conflicted with another request. You may retry the request with the provided Idempotency-Key." + type: "QueryRunnerAlreadyReleasedError" + invalid_request_error: + description: Invalid Request Error + content: + application/json: + schema: + $ref: "#/components/schemas/error" + example: + code: "invalid_request_error" + message: "Discount with code TEST already exists." + type: "duplicate_error" + not_found_error: + description: Not Found Error + content: + application/json: + schema: + $ref: "#/components/schemas/error" + example: + message: "Entity with id 1 was not found" + type: "not_found" + 400_error: + description: Client Error or Multiple Errors + content: + application/json: + schema: + oneOf: + - $ref: "#/components/schemas/error" + - $ref: "#/components/schemas/multiple_errors" + examples: + not_allowed: + $ref: "#/components/examples/not_allowed_error" + invalid_data: + $ref: "#/components/examples/invalid_data_error" + multiple_errors: + $ref: "#/components/examples/multiple_errors" + 500_error: + description: Server Error + content: + application/json: + schema: + $ref: "#/components/schemas/error" + examples: + database: + $ref: "#/components/examples/database_error" + unexpected_state: + $ref: "#/components/examples/unexpected_state_error" + invalid_argument: + $ref: "#/components/examples/invalid_argument_error" + default_error: + $ref: "#/components/examples/default_error" + unauthorized: + description: 'User is not authorized. Must log in first' + content: + text/plain: + schema: + type: string + default: Unauthorized + example: Unauthorized + incorrect_credentials: + description: 'User does not exist or incorrect credentials' + content: + text/plain: + schema: + type: string + default: Unauthorized + example: Unauthorized + examples: + not_allowed_error: + summary: Not Allowed Error + value: + message: "Discount must be set to dynamic" + type: "not_allowed" + invalid_data_error: + summary: Invalid Data Error + value: + message: "first_name must be a string" + type: "invalid_data" + multiple_errors: + summary: Multiple Errors + value: + message: "Provided request body contains errors. Please check the data and retry the request" + errors: + - message: "first_name must be a string" + type: "invalid_data" + - message: "Discount must be set to dynamic" + type: "not_allowed" + database_error: + summary: Database Error + value: + code: "api_error" + message: "An error occured while hashing password" + type: "database_error" + unexpected_state_error: + summary: Unexpected State Error + value: + message: "cart.total must be defined" + type: "unexpected_state" + invalid_argument_error: + summary: Invalid Argument Error + value: + message: "cart.total must be defined" + type: "unexpected_state" + default_error: + summary: Default Error + value: + code: "unknown_error" + message: "An unknown error occurred." + type: "unknown_error" + securitySchemes: + cookie_auth: + type: apiKey + x-displayName: Cookie Session ID + in: cookie + name: connect.sid + description: | + Use a cookie session to send authenticated requests. + + ### How to Obtain the Cookie Session + + If you're sending requests through a browser, using JS Client, or using tools like Postman, the cookie session should be automatically set when the customer is logged in. + + If you're sending requests using cURL, you must set the Session ID in the cookie manually. + + To do that, send a request to [authenticate the customer](#tag/Auth/operation/PostAuth) and pass the cURL option `-v`: + + ```bash + curl -v --location --request POST 'https://medusa-url.com/store/auth' \ + --header 'Content-Type: application/json' \ + --data-raw '{ + "email": "user@example.com", + "password": "supersecret" + }' + ``` + + The headers will be logged in the terminal as well as the response. You should find in the headers a Cookie header similar to this: + + ```bash + Set-Cookie: connect.sid=s%3A2Bu8BkaP9JUfHu9rG59G16Ma0QZf6Gj1.WT549XqX37PN8n0OecqnMCq798eLjZC5IT7yiDCBHPM; + ``` + + Copy the value after `connect.sid` (without the `;` at the end) and pass it as a cookie in subsequent requests as the following: + + ```bash + curl --location --request GET 'https://medusa-url.com/store/customers/me/orders' \ + --header 'Cookie: connect.sid={sid}' + ``` + + Where `{sid}` is the value of `connect.sid` that you copied. \ No newline at end of file diff --git a/packages/medusa/src/api/middlewares/await-middleware.ts b/packages/medusa/src/api/middlewares/await-middleware.ts index f9e02e8a6c..3f1b4edb09 100644 --- a/packages/medusa/src/api/middlewares/await-middleware.ts +++ b/packages/medusa/src/api/middlewares/await-middleware.ts @@ -15,3 +15,18 @@ export default (fn: handler): RequestHandler => { return fn(req, res).catch(next) } } + +/** + * @schema multiple_errors + * title: "Multiple Errors" + * x-resourceId: multiple_errors + * properties: + * errors: + * type: array + * description: Array of errors + * items: + * $ref: "#/components/schemas/error" + * message: + * type: string + * default: "Provided request body contains errors. Please check the data and retry the request" + */ \ No newline at end of file diff --git a/packages/medusa/src/api/middlewares/error-handler.ts b/packages/medusa/src/api/middlewares/error-handler.ts index 6690665915..14001b33b4 100644 --- a/packages/medusa/src/api/middlewares/error-handler.ts +++ b/packages/medusa/src/api/middlewares/error-handler.ts @@ -67,3 +67,19 @@ export default () => { res.status(statusCode).json(errObj) } } + +/** + * @schema error + * title: "Response Error" + * x-resourceId: error + * properties: + * code: + * type: string + * description: A slug code to indicate the type of the error. + * message: + * type: string + * description: Description of the error that occurred. + * type: + * type: string + * description: A slug indicating the type of the error. + */ \ No newline at end of file diff --git a/packages/medusa/src/api/routes/admin/apps/authorize-app.ts b/packages/medusa/src/api/routes/admin/apps/authorize-app.ts index 38634e9109..65b126b150 100644 --- a/packages/medusa/src/api/routes/admin/apps/authorize-app.ts +++ b/packages/medusa/src/api/routes/admin/apps/authorize-app.ts @@ -27,6 +27,21 @@ import { validator } from "../../../../utils/validator" * code: * type: string * description: The code for the generated token. + * x-codeSamples: + * - lang: Shell + * label: cURL + * source: | + * curl --location --request POST 'https://medusa-url.com/admin/apps/authorizations' \ + * --header 'Authorization: Bearer {api_token}' \ + * --header 'Content-Type: application/json' \ + * --data-raw '{ + * "application_name": "example", + * "state": "ready", + * "code": "token" + * }' + * security: + * - api_token: [] + * - cookie_auth: [] * tags: * - App * responses: @@ -38,6 +53,18 @@ import { validator } from "../../../../utils/validator" * properties: * apps: * $ref: "#/components/schemas/OAuth" + * "400": + * $ref: "#/components/responses/400_error" + * "401": + * $ref: "#/components/responses/unauthorized" + * "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 validated = await validator(AdminPostAppsReq, req.body) diff --git a/packages/medusa/src/api/routes/admin/apps/list.ts b/packages/medusa/src/api/routes/admin/apps/list.ts index ab452a5f09..69e7ea67fe 100644 --- a/packages/medusa/src/api/routes/admin/apps/list.ts +++ b/packages/medusa/src/api/routes/admin/apps/list.ts @@ -6,6 +6,15 @@ import { OauthService } from "../../../../services" * summary: "List applications" * description: "Retrieve a list of applications." * x-authenticated: true + * x-codeSamples: + * - lang: Shell + * label: cURL + * source: | + * curl --location --request GET 'https://medusa-url.com/admin/apps' \ + * --header 'Authorization: Bearer {api_token}' + * security: + * - api_token: [] + * - cookie_auth: [] * tags: * - App * responses: @@ -19,6 +28,18 @@ import { OauthService } from "../../../../services" * type: array * items: * $ref: "#/components/schemas/OAuth" + * "400": + * $ref: "#/components/responses/400_error" + * "401": + * $ref: "#/components/responses/unauthorized" + * "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 oauthService: OauthService = req.scope.resolve("oauthService") diff --git a/packages/medusa/src/api/routes/admin/auth/create-session.ts b/packages/medusa/src/api/routes/admin/auth/create-session.ts index 11fe81f142..e0339c653a 100644 --- a/packages/medusa/src/api/routes/admin/auth/create-session.ts +++ b/packages/medusa/src/api/routes/admin/auth/create-session.ts @@ -32,6 +32,27 @@ import { validator } from "../../../../utils/validator" * type: string * description: The User's password. * format: password + * 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.createSession({ + * email: 'user@example.com', + * password: 'supersecret' + * }).then((({ user }) => { + * console.log(user.id); + * }); + * - lang: Shell + * label: cURL + * source: | + * curl --location --request POST 'https://medusa-url.com/admin/auth' \ + * --header 'Content-Type: application/json' \ + * --data-raw '{ + * "email": "user@example.com", + * "password": "supersecret" + * }' * tags: * - Auth * responses: @@ -43,8 +64,18 @@ import { validator } from "../../../../utils/validator" * properties: * user: * $ref: "#/components/schemas/user" + * "400": + * $ref: "#/components/responses/400_error" * "401": - * description: The user doesn't exist or the credentials are incorrect. + * $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') diff --git a/packages/medusa/src/api/routes/admin/auth/delete-session.ts b/packages/medusa/src/api/routes/admin/auth/delete-session.ts index 8760fe1d3c..3a87ee4196 100644 --- a/packages/medusa/src/api/routes/admin/auth/delete-session.ts +++ b/packages/medusa/src/api/routes/admin/auth/delete-session.ts @@ -4,11 +4,39 @@ * summary: "Delete Session" * x-authenticated: true * description: "Deletes the current session for the logged in user." + * x-codeSamples: + * - lang: JavaScript + * label: JS Client + * source: | + * import Medusa from "@medusajs/medusa-js" + * const medusa = new Medusa({ baseUrl: MEDUSA_BACKEND_URL, maxRetries: 3 }) + * // must be previously logged in or use api token + * medusa.admin.auth.deleteSession() + * - lang: Shell + * label: cURL + * source: | + * curl --location --request DELETE 'https://medusa-url.com/admin/auth' \ + * --header 'Authorization: Bearer {api_token}' + * security: + * - api_token: [] + * - cookie_auth: [] * tags: * - Auth * responses: * "200": * description: OK + * "400": + * $ref: "#/components/responses/400_error" + * "401": + * $ref: "#/components/responses/unauthorized" + * "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) => { req.session.destroy() diff --git a/packages/medusa/src/api/routes/admin/auth/get-session.ts b/packages/medusa/src/api/routes/admin/auth/get-session.ts index a694525fa0..1e36a9e616 100644 --- a/packages/medusa/src/api/routes/admin/auth/get-session.ts +++ b/packages/medusa/src/api/routes/admin/auth/get-session.ts @@ -7,6 +7,25 @@ import _ from "lodash" * summary: "Get Session" * x-authenticated: true * description: "Gets the currently logged in User." + * x-codeSamples: + * - lang: JavaScript + * label: JS Client + * source: | + * import Medusa from "@medusajs/medusa-js" + * const medusa = new Medusa({ baseUrl: MEDUSA_BACKEND_URL, maxRetries: 3 }) + * // must be previously logged in or use api token + * medusa.admin.auth.getSession() + * .then(({ user }) => { + * console.log(user.id); + * }); + * - lang: Shell + * label: cURL + * source: | + * curl --location --request GET 'https://medusa-url.com/admin/auth' \ + * --header 'Authorization: Bearer {api_token}' + * security: + * - api_token: [] + * - cookie_auth: [] * tags: * - Auth * responses: @@ -19,7 +38,17 @@ import _ from "lodash" * user: * $ref: "#/components/schemas/user" * "400": - * description: An error occurred. + * $ref: "#/components/responses/400_error" + * "401": + * $ref: "#/components/responses/unauthorized" + * "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) => { try { diff --git a/packages/medusa/src/api/routes/admin/batch/cancel-batch-job.ts b/packages/medusa/src/api/routes/admin/batch/cancel-batch-job.ts index af582be151..21dd02012d 100644 --- a/packages/medusa/src/api/routes/admin/batch/cancel-batch-job.ts +++ b/packages/medusa/src/api/routes/admin/batch/cancel-batch-job.ts @@ -9,6 +9,25 @@ import { EntityManager } from "typeorm" * x-authenticated: true * parameters: * - (path) id=* {string} The ID of the batch job. + * x-codeSamples: + * - lang: JavaScript + * label: JS Client + * source: | + * import Medusa from "@medusajs/medusa-js" + * const medusa = new Medusa({ baseUrl: MEDUSA_BACKEND_URL, maxRetries: 3 }) + * // must be previously logged in or use api token + * medusa.admin.batchJobs.cancel(batch_job_id) + * .then(({ batch_job }) => { + * console.log(batch_job.id); + * }); + * - lang: Shell + * label: cURL + * source: | + * curl --location --request POST 'https://medusa-url.com/admin/batch-jobs/{id}/cancel' \ + * --header 'Authorization: Bearer {api_token}' + * security: + * - api_token: [] + * - cookie_auth: [] * tags: * - Batch Job * responses: @@ -20,6 +39,18 @@ import { EntityManager } from "typeorm" * properties: * batch_job: * $ref: "#/components/schemas/batch_job" + * "400": + * $ref: "#/components/responses/400_error" + * "401": + * $ref: "#/components/responses/unauthorized" + * "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) => { let batch_job = req.batch_job diff --git a/packages/medusa/src/api/routes/admin/batch/confirm-batch-job.ts b/packages/medusa/src/api/routes/admin/batch/confirm-batch-job.ts index 7601b105c6..3cafd8ff6e 100644 --- a/packages/medusa/src/api/routes/admin/batch/confirm-batch-job.ts +++ b/packages/medusa/src/api/routes/admin/batch/confirm-batch-job.ts @@ -9,6 +9,25 @@ import { EntityManager } from "typeorm" * x-authenticated: true * parameters: * - (path) id=* {string} The ID of the batch job. + * x-codeSamples: + * - lang: JavaScript + * label: JS Client + * source: | + * import Medusa from "@medusajs/medusa-js" + * const medusa = new Medusa({ baseUrl: MEDUSA_BACKEND_URL, maxRetries: 3 }) + * // must be previously logged in or use api token + * medusa.admin.batchJobs.confirm(batch_job_id) + * .then(({ batch_job }) => { + * console.log(batch_job.id); + * }); + * - lang: Shell + * label: cURL + * source: | + * curl --location --request POST 'https://medusa-url.com/admin/batch-jobs/{id}/confirm' \ + * --header 'Authorization: Bearer {api_token}' + * security: + * - api_token: [] + * - cookie_auth: [] * tags: * - Batch Job * responses: @@ -20,6 +39,18 @@ import { EntityManager } from "typeorm" * properties: * batch_job: * $ref: "#/components/schemas/batch_job" + * "400": + * $ref: "#/components/responses/400_error" + * "401": + * $ref: "#/components/responses/unauthorized" + * "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) => { let batch_job = req.batch_job diff --git a/packages/medusa/src/api/routes/admin/batch/create-batch-job.ts b/packages/medusa/src/api/routes/admin/batch/create-batch-job.ts index 6eff9eb59e..498df2c1c0 100644 --- a/packages/medusa/src/api/routes/admin/batch/create-batch-job.ts +++ b/packages/medusa/src/api/routes/admin/batch/create-batch-job.ts @@ -46,6 +46,33 @@ import { validator } from "../../../../utils/validator" * type: boolean * description: Set a batch job in dry_run mode to get some information on what will be done without applying any modifications. * default: false + * x-codeSamples: + * - lang: JavaScript + * label: JS Client + * source: | + * import Medusa from "@medusajs/medusa-js" + * const medusa = new Medusa({ baseUrl: MEDUSA_BACKEND_URL, maxRetries: 3 }) + * // must be previously logged in or use api token + * medusa.admin.batchJobs.create({ + * type: 'product-export', + * context: {}, + * dry_run: false + * }).then((({ batch_job }) => { + * console.log(batch_job.id); + * }); + * - lang: Shell + * label: cURL + * source: | + * curl --location --request POST 'https://medusa-url.com/admin/batch-jobs' \ + * --header 'Content-Type: application/json' \ + * --header 'Authorization: Bearer {api_token}' \ + * --data-raw '{ + * "type": "product-export", + * "context": { } + * }' + * security: + * - api_token: [] + * - cookie_auth: [] * tags: * - Batch Job * responses: @@ -57,6 +84,18 @@ import { validator } from "../../../../utils/validator" * properties: * batch_job: * $ref: "#/components/schemas/batch_job" + * "400": + * $ref: "#/components/responses/400_error" + * "401": + * $ref: "#/components/responses/unauthorized" + * "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 validated = await validator(AdminPostBatchesReq, req.body) diff --git a/packages/medusa/src/api/routes/admin/batch/get-batch-job.ts b/packages/medusa/src/api/routes/admin/batch/get-batch-job.ts index 2c16bccba9..5884d210e4 100644 --- a/packages/medusa/src/api/routes/admin/batch/get-batch-job.ts +++ b/packages/medusa/src/api/routes/admin/batch/get-batch-job.ts @@ -6,6 +6,25 @@ * x-authenticated: true * parameters: * - (path) id=* {string} The ID of the Batch Job + * x-codeSamples: + * - lang: JavaScript + * label: JS Client + * source: | + * import Medusa from "@medusajs/medusa-js" + * const medusa = new Medusa({ baseUrl: MEDUSA_BACKEND_URL, maxRetries: 3 }) + * // must be previously logged in or use api token + * medusa.admin.batchJobs.retrieve(batch_job_id) + * .then(({ batch_job }) => { + * console.log(batch_job.id); + * }); + * - lang: Shell + * label: cURL + * source: | + * curl --location --request GET 'https://medusa-url.com/admin/batch-jobs/{id}' \ + * --header 'Authorization: Bearer {api_token}' + * security: + * - api_token: [] + * - cookie_auth: [] * tags: * - Batch Job * responses: @@ -17,6 +36,18 @@ * properties: * batch_job: * $ref: "#/components/schemas/batch_job" + * "400": + * $ref: "#/components/responses/400_error" + * "401": + * $ref: "#/components/responses/unauthorized" + * "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 batch_job = req.batch_job diff --git a/packages/medusa/src/api/routes/admin/batch/list-batch-jobs.ts b/packages/medusa/src/api/routes/admin/batch/list-batch-jobs.ts index 2360fc801d..5ef8a2b092 100644 --- a/packages/medusa/src/api/routes/admin/batch/list-batch-jobs.ts +++ b/packages/medusa/src/api/routes/admin/batch/list-batch-jobs.ts @@ -210,6 +210,25 @@ import { isDefined } from "../../../../utils" * type: string * description: filter by dates greater than or equal to this date * format: date + * x-codeSamples: + * - lang: JavaScript + * label: JS Client + * source: | + * import Medusa from "@medusajs/medusa-js" + * const medusa = new Medusa({ baseUrl: MEDUSA_BACKEND_URL, maxRetries: 3 }) + * // must be previously logged in or use api token + * medusa.admin.batchJobs.list() + * .then(({ batch_jobs, limit, offset, count }) => { + * console.log(batch_jobs.length); + * }); + * - lang: Shell + * label: cURL + * source: | + * curl --location --request GET 'https://medusa-url.com/admin/batch-jobs' \ + * --header 'Authorization: Bearer {api_token}' + * security: + * - api_token: [] + * - cookie_auth: [] * tags: * - Batch Job * responses: @@ -232,6 +251,18 @@ import { isDefined } from "../../../../utils" * limit: * type: integer * description: The number of items per page + * "400": + * $ref: "#/components/responses/400_error" + * "401": + * $ref: "#/components/responses/unauthorized" + * "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: Request, res) => { const batchService: BatchJobService = req.scope.resolve("batchJobService") diff --git a/packages/medusa/src/api/routes/admin/collections/add-products.ts b/packages/medusa/src/api/routes/admin/collections/add-products.ts index d1925f2f10..02a3d2d773 100644 --- a/packages/medusa/src/api/routes/admin/collections/add-products.ts +++ b/packages/medusa/src/api/routes/admin/collections/add-products.ts @@ -25,6 +25,21 @@ import ProductCollectionService from "../../../../services/product-collection" * items: * description: "The ID of a Product to add to the Product Collection." * type: string + * x-codeSamples: + * - lang: Shell + * label: cURL + * source: | + * curl --location --request POST 'https://medusa-url.com/admin/collections/{id}/products/batch' \ + * --header 'Authorization: Bearer {api_token}' \ + * --header 'Content-Type: application/json' \ + * --data-raw '{ + * "product_ids": [ + * "prod_01G1G5V2MBA328390B5AXJ610F" + * ] + * }' + * security: + * - api_token: [] + * - cookie_auth: [] * tags: * - Collection * responses: @@ -36,6 +51,18 @@ import ProductCollectionService from "../../../../services/product-collection" * properties: * collection: * $ref: "#/components/schemas/product_collection" + * "400": + * $ref: "#/components/responses/400_error" + * "401": + * $ref: "#/components/responses/unauthorized" + * "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: Request, res: Response) => { const { id } = req.params diff --git a/packages/medusa/src/api/routes/admin/collections/create-collection.ts b/packages/medusa/src/api/routes/admin/collections/create-collection.ts index 415a7299d6..d232e1edaf 100644 --- a/packages/medusa/src/api/routes/admin/collections/create-collection.ts +++ b/packages/medusa/src/api/routes/admin/collections/create-collection.ts @@ -25,6 +25,31 @@ import { EntityManager } from "typeorm" * metadata: * description: An optional set of key-value pairs to hold additional information. * type: object + * x-codeSamples: + * - lang: JavaScript + * label: JS Client + * source: | + * import Medusa from "@medusajs/medusa-js" + * const medusa = new Medusa({ baseUrl: MEDUSA_BACKEND_URL, maxRetries: 3 }) + * // must be previously logged in or use api token + * medusa.admin.collections.create({ + * title: 'New Collection' + * }) + * .then(({ collection }) => { + * console.log(collection.id); + * }); + * - lang: Shell + * label: cURL + * source: | + * curl --location --request POST 'https://medusa-url.com/admin/collections' \ + * --header 'Authorization: Bearer {api_token}' \ + * --header 'Content-Type: application/json' \ + * --data-raw '{ + * "title": "New Collection" + * }' + * security: + * - api_token: [] + * - cookie_auth: [] * tags: * - Collection * responses: @@ -36,6 +61,18 @@ import { EntityManager } from "typeorm" * properties: * collection: * $ref: "#/components/schemas/product_collection" + * "400": + * $ref: "#/components/responses/400_error" + * "401": + * $ref: "#/components/responses/unauthorized" + * "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: Request, res: Response) => { const { validatedBody } = req as { validatedBody: AdminPostCollectionsReq } diff --git a/packages/medusa/src/api/routes/admin/collections/delete-collection.ts b/packages/medusa/src/api/routes/admin/collections/delete-collection.ts index e31a668871..963d6212dc 100644 --- a/packages/medusa/src/api/routes/admin/collections/delete-collection.ts +++ b/packages/medusa/src/api/routes/admin/collections/delete-collection.ts @@ -11,6 +11,25 @@ import ProductCollectionService from "../../../../services/product-collection" * x-authenticated: true * parameters: * - (path) id=* {string} The ID of the Collection. + * x-codeSamples: + * - lang: JavaScript + * label: JS Client + * source: | + * import Medusa from "@medusajs/medusa-js" + * const medusa = new Medusa({ baseUrl: MEDUSA_BACKEND_URL, maxRetries: 3 }) + * // must be previously logged in or use api token + * medusa.admin.collections.delete(collection_id) + * .then(({ id, object, deleted }) => { + * console.log(id); + * }); + * - lang: Shell + * label: cURL + * source: | + * curl --location --request DELETE 'https://medusa-url.com/admin/collections/{id}' \ + * --header 'Authorization: Bearer {api_token}' + * security: + * - api_token: [] + * - cookie_auth: [] * tags: * - Collection * responses: @@ -31,6 +50,18 @@ import ProductCollectionService from "../../../../services/product-collection" * type: boolean * description: Whether the collection was deleted successfully or not. * default: true + * "400": + * $ref: "#/components/responses/400_error" + * "401": + * $ref: "#/components/responses/unauthorized" + * "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: Request, res: Response) => { const { id } = req.params diff --git a/packages/medusa/src/api/routes/admin/collections/get-collection.ts b/packages/medusa/src/api/routes/admin/collections/get-collection.ts index 76d47cac74..96c404d449 100644 --- a/packages/medusa/src/api/routes/admin/collections/get-collection.ts +++ b/packages/medusa/src/api/routes/admin/collections/get-collection.ts @@ -10,6 +10,25 @@ import { defaultAdminCollectionsRelations } from "." * x-authenticated: true * parameters: * - (path) id=* {string} The ID of the Product Collection + * x-codeSamples: + * - lang: JavaScript + * label: JS Client + * source: | + * import Medusa from "@medusajs/medusa-js" + * const medusa = new Medusa({ baseUrl: MEDUSA_BACKEND_URL, maxRetries: 3 }) + * // must be previously logged in or use api token + * medusa.admin.collections.retrieve(collection_id) + * .then(({ collection }) => { + * console.log(collection.id); + * }); + * - lang: Shell + * label: cURL + * source: | + * curl --location --request GET 'https://medusa-url.com/admin/collections/{id}' \ + * --header 'Authorization: Bearer {api_token}' + * security: + * - api_token: [] + * - cookie_auth: [] * tags: * - Collection * responses: @@ -21,6 +40,18 @@ import { defaultAdminCollectionsRelations } from "." * properties: * collection: * $ref: "#/components/schemas/product_collection" + * "400": + * $ref: "#/components/responses/400_error" + * "401": + * $ref: "#/components/responses/unauthorized" + * "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: Request, res: Response) => { const { id } = req.params diff --git a/packages/medusa/src/api/routes/admin/collections/list-collections.ts b/packages/medusa/src/api/routes/admin/collections/list-collections.ts index a25b1ec741..82e9ce6afc 100644 --- a/packages/medusa/src/api/routes/admin/collections/list-collections.ts +++ b/packages/medusa/src/api/routes/admin/collections/list-collections.ts @@ -84,6 +84,25 @@ import { Type } from "class-transformer" * type: string * description: filter by dates greater than or equal to this date * format: date + * x-codeSamples: + * - lang: JavaScript + * label: JS Client + * source: | + * import Medusa from "@medusajs/medusa-js" + * const medusa = new Medusa({ baseUrl: MEDUSA_BACKEND_URL, maxRetries: 3 }) + * // must be previously logged in or use api token + * medusa.admin.collections.list() + * .then(({ collections, limit, offset, count }) => { + * console.log(collections.length); + * }); + * - lang: Shell + * label: cURL + * source: | + * curl --location --request GET 'https://medusa-url.com/admin/collections' \ + * --header 'Authorization: Bearer {api_token}' + * security: + * - api_token: [] + * - cookie_auth: [] * tags: * - Collection * responses: @@ -106,6 +125,18 @@ import { Type } from "class-transformer" * limit: * type: integer * description: The number of items per page + * "400": + * $ref: "#/components/responses/400_error" + * "401": + * $ref: "#/components/responses/unauthorized" + * "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: Request, res: Response) => { const productCollectionService: ProductCollectionService = req.scope.resolve( diff --git a/packages/medusa/src/api/routes/admin/collections/remove-products.ts b/packages/medusa/src/api/routes/admin/collections/remove-products.ts index a2b155d541..a1e95e0563 100644 --- a/packages/medusa/src/api/routes/admin/collections/remove-products.ts +++ b/packages/medusa/src/api/routes/admin/collections/remove-products.ts @@ -25,6 +25,21 @@ import ProductCollectionService from "../../../../services/product-collection" * items: * description: "The ID of a Product to add to the Product Collection." * type: string + * x-codeSamples: + * - lang: Shell + * label: cURL + * source: | + * curl --location --request DELETE 'https://medusa-url.com/admin/collections/{id}/products/batch' \ + * --header 'Authorization: Bearer {api_token}' \ + * --header 'Content-Type: application/json' \ + * --data-raw '{ + * "product_ids": [ + * "prod_01G1G5V2MBA328390B5AXJ610F" + * ] + * }' + * security: + * - api_token: [] + * - cookie_auth: [] * tags: * - Collection * responses: @@ -47,6 +62,18 @@ import ProductCollectionService from "../../../../services/product-collection" * items: * description: "The ID of a Product to add to the Product Collection." * type: string + * "400": + * $ref: "#/components/responses/400_error" + * "401": + * $ref: "#/components/responses/unauthorized" + * "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: Request, res: Response) => { const { id } = req.params diff --git a/packages/medusa/src/api/routes/admin/collections/update-collection.ts b/packages/medusa/src/api/routes/admin/collections/update-collection.ts index d7773136e6..dd90c1323f 100644 --- a/packages/medusa/src/api/routes/admin/collections/update-collection.ts +++ b/packages/medusa/src/api/routes/admin/collections/update-collection.ts @@ -25,6 +25,31 @@ import ProductCollectionService from "../../../../services/product-collection" * metadata: * description: An optional set of key-value pairs to hold additional information. * type: object + * x-codeSamples: + * - lang: JavaScript + * label: JS Client + * source: | + * import Medusa from "@medusajs/medusa-js" + * const medusa = new Medusa({ baseUrl: MEDUSA_BACKEND_URL, maxRetries: 3 }) + * // must be previously logged in or use api token + * medusa.admin.collections.update(collection_id, { + * title: 'New Collection' + * }) + * .then(({ collection }) => { + * console.log(collection.id); + * }); + * - lang: Shell + * label: cURL + * source: | + * curl --location --request POST 'https://medusa-url.com/admin/collections/{id}' \ + * --header 'Authorization: Bearer {api_token}' \ + * --header 'Content-Type: application/json' \ + * --data-raw '{ + * "title": "New Collection" + * }' + * security: + * - api_token: [] + * - cookie_auth: [] * tags: * - Collection * responses: @@ -36,6 +61,18 @@ import ProductCollectionService from "../../../../services/product-collection" * properties: * collection: * $ref: "#/components/schemas/product_collection" + * "400": + * $ref: "#/components/responses/400_error" + * "401": + * $ref: "#/components/responses/unauthorized" + * "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: Request, res: Response) => { const { id } = req.params diff --git a/packages/medusa/src/api/routes/admin/customer-groups/add-customers-batch.ts b/packages/medusa/src/api/routes/admin/customer-groups/add-customers-batch.ts index 4727317073..16df1ea384 100644 --- a/packages/medusa/src/api/routes/admin/customer-groups/add-customers-batch.ts +++ b/packages/medusa/src/api/routes/admin/customer-groups/add-customers-batch.ts @@ -32,6 +32,39 @@ import { validator } from "../../../../utils/validator" * id: * description: ID of the customer * type: string + * x-codeSamples: + * - lang: JavaScript + * label: JS Client + * source: | + * import Medusa from "@medusajs/medusa-js" + * const medusa = new Medusa({ baseUrl: MEDUSA_BACKEND_URL, maxRetries: 3 }) + * // must be previously logged in or use api token + * medusa.admin.customerGroups.addCustomers(customer_group_id, { + * customer_ids: [ + * { + * id: customer_id + * } + * ] + * }) + * .then(({ customer_group }) => { + * console.log(customer_group.id); + * }); + * - lang: Shell + * label: cURL + * source: | + * curl --location --request POST 'https://medusa-url.com/admin/customer-groups/{id}/customers/batch' \ + * --header 'Authorization: Bearer {api_token}' \ + * --header 'Content-Type: application/json' \ + * --data-raw '{ + * "customer_ids": [ + * { + * "id": "cus_01G2Q4BS9GAHDBMDEN4ZQZCJB2" + * } + * ] + * }' + * security: + * - api_token: [] + * - cookie_auth: [] * tags: * - Customer Group * responses: @@ -43,6 +76,18 @@ import { validator } from "../../../../utils/validator" * properties: * customer_group: * $ref: "#/components/schemas/customer_group" + * "400": + * $ref: "#/components/responses/400_error" + * "401": + * $ref: "#/components/responses/unauthorized" + * "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: Request, res: Response) => { diff --git a/packages/medusa/src/api/routes/admin/customer-groups/create-customer-group.ts b/packages/medusa/src/api/routes/admin/customer-groups/create-customer-group.ts index bec19a5376..0b3fb044c5 100644 --- a/packages/medusa/src/api/routes/admin/customer-groups/create-customer-group.ts +++ b/packages/medusa/src/api/routes/admin/customer-groups/create-customer-group.ts @@ -14,6 +14,31 @@ import { validator } from "../../../../utils/validator" * parameters: * - (body) name=* {string} Name of the customer group * - (body) metadata {object} Metadata for the customer. + * x-codeSamples: + * - lang: JavaScript + * label: JS Client + * source: | + * import Medusa from "@medusajs/medusa-js" + * const medusa = new Medusa({ baseUrl: MEDUSA_BACKEND_URL, maxRetries: 3 }) + * // must be previously logged in or use api token + * medusa.admin.customerGroups.create({ + * name: 'VIP' + * }) + * .then(({ customer_group }) => { + * console.log(customer_group.id); + * }); + * - lang: Shell + * label: cURL + * source: | + * curl --location --request POST 'https://medusa-url.com/admin/customer-groups' \ + * --header 'Authorization: Bearer {api_token}' \ + * --header 'Content-Type: application/json' \ + * --data-raw '{ + * "name": "VIP" + * }' + * security: + * - api_token: [] + * - cookie_auth: [] * tags: * - Customer Group * responses: @@ -25,6 +50,18 @@ import { validator } from "../../../../utils/validator" * properties: * customer_group: * $ref: "#/components/schemas/customer_group" + * "400": + * $ref: "#/components/responses/400_error" + * "401": + * $ref: "#/components/responses/unauthorized" + * "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: Request, res: Response) => { diff --git a/packages/medusa/src/api/routes/admin/customer-groups/delete-customer-group.ts b/packages/medusa/src/api/routes/admin/customer-groups/delete-customer-group.ts index 495f2edb70..8d1264bbf7 100644 --- a/packages/medusa/src/api/routes/admin/customer-groups/delete-customer-group.ts +++ b/packages/medusa/src/api/routes/admin/customer-groups/delete-customer-group.ts @@ -11,6 +11,25 @@ import { EntityManager } from "typeorm" * x-authenticated: true * parameters: * - (path) id=* {string} The ID of the Customer Group + * x-codeSamples: + * - lang: JavaScript + * label: JS Client + * source: | + * import Medusa from "@medusajs/medusa-js" + * const medusa = new Medusa({ baseUrl: MEDUSA_BACKEND_URL, maxRetries: 3 }) + * // must be previously logged in or use api token + * medusa.admin.customerGroups.delete(customer_group_id) + * .then(({ id, object, deleted }) => { + * console.log(id); + * }); + * - lang: Shell + * label: cURL + * source: | + * curl --location --request DELETE 'https://medusa-url.com/admin/customer-groups/{id}' \ + * --header 'Authorization: Bearer {api_token}' + * security: + * - api_token: [] + * - cookie_auth: [] * tags: * - Customer Group * responses: @@ -31,6 +50,18 @@ import { EntityManager } from "typeorm" * type: boolean * description: Whether the customer group was deleted successfully or not. * default: true + * "400": + * $ref: "#/components/responses/400_error" + * "401": + * $ref: "#/components/responses/unauthorized" + * "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: Request, res: Response) => { diff --git a/packages/medusa/src/api/routes/admin/customer-groups/delete-customers-batch.ts b/packages/medusa/src/api/routes/admin/customer-groups/delete-customers-batch.ts index edfcf63327..ff6fe76a25 100644 --- a/packages/medusa/src/api/routes/admin/customer-groups/delete-customers-batch.ts +++ b/packages/medusa/src/api/routes/admin/customer-groups/delete-customers-batch.ts @@ -32,6 +32,39 @@ import { validator } from "../../../../utils/validator" * id: * description: ID of the customer * type: string + * x-codeSamples: + * - lang: JavaScript + * label: JS Client + * source: | + * import Medusa from "@medusajs/medusa-js" + * const medusa = new Medusa({ baseUrl: MEDUSA_BACKEND_URL, maxRetries: 3 }) + * // must be previously logged in or use api token + * medusa.admin.customerGroups.removeCustomers(customer_group_id, { + * customer_ids: [ + * { + * id: customer_id + * } + * ] + * }) + * .then(({ customer_group }) => { + * console.log(customer_group.id); + * }); + * - lang: Shell + * label: cURL + * source: | + * curl --location --request DELETE 'https://medusa-url.com/admin/customer-groups/{id}/customers/batch' \ + * --header 'Authorization: Bearer {api_token}' \ + * --header 'Content-Type: application/json' \ + * --data-raw '{ + * "customer_ids": [ + * { + * "id": "cus_01G2Q4BS9GAHDBMDEN4ZQZCJB2" + * } + * ] + * }' + * security: + * - api_token: [] + * - cookie_auth: [] * tags: * - Customer Group * responses: @@ -43,6 +76,18 @@ import { validator } from "../../../../utils/validator" * properties: * customer_group: * $ref: "#/components/schemas/customer_group" + * "400": + * $ref: "#/components/responses/400_error" + * "401": + * $ref: "#/components/responses/unauthorized" + * "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: Request, res: Response) => { diff --git a/packages/medusa/src/api/routes/admin/customer-groups/get-customer-group-customers.ts b/packages/medusa/src/api/routes/admin/customer-groups/get-customer-group-customers.ts index 43ea70b869..73d4d4c501 100644 --- a/packages/medusa/src/api/routes/admin/customer-groups/get-customer-group-customers.ts +++ b/packages/medusa/src/api/routes/admin/customer-groups/get-customer-group-customers.ts @@ -10,6 +10,25 @@ import CustomerController from "../../../../controllers/customers" * x-authenticated: true * parameters: * - (path) id=* {string} The ID of the customer group. + * x-codeSamples: + * - lang: JavaScript + * label: JS Client + * source: | + * import Medusa from "@medusajs/medusa-js" + * const medusa = new Medusa({ baseUrl: MEDUSA_BACKEND_URL, maxRetries: 3 }) + * // must be previously logged in or use api token + * medusa.admin.customerGroups.listCustomers(customer_group_id) + * .then(({ customers }) => { + * console.log(customers.length); + * }); + * - lang: Shell + * label: cURL + * source: | + * curl --location --request GET 'https://medusa-url.com/admin/customer-groups/{id}/customers' \ + * --header 'Authorization: Bearer {api_token}' + * security: + * - api_token: [] + * - cookie_auth: [] * tags: * - Customer Group * responses: @@ -32,6 +51,18 @@ import CustomerController from "../../../../controllers/customers" * limit: * type: integer * description: The number of items per page + * "400": + * $ref: "#/components/responses/400_error" + * "401": + * $ref: "#/components/responses/unauthorized" + * "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: Request, res: Response) => { const { id } = req.params diff --git a/packages/medusa/src/api/routes/admin/customer-groups/get-customer-group.ts b/packages/medusa/src/api/routes/admin/customer-groups/get-customer-group.ts index ef355ad106..dc31c59c23 100644 --- a/packages/medusa/src/api/routes/admin/customer-groups/get-customer-group.ts +++ b/packages/medusa/src/api/routes/admin/customer-groups/get-customer-group.ts @@ -13,6 +13,25 @@ import { FindParams } from "../../../../types/common" * - (path) id=* {string} The ID of the Customer Group. * - (query) expand {string} (Comma separated) Which fields should be expanded in the customer group. * - (query) fields {string} (Comma separated) Which fields should be included in the customer group. + * x-codeSamples: + * - lang: JavaScript + * label: JS Client + * source: | + * import Medusa from "@medusajs/medusa-js" + * const medusa = new Medusa({ baseUrl: MEDUSA_BACKEND_URL, maxRetries: 3 }) + * // must be previously logged in or use api token + * medusa.admin.customerGroups.retrieve(customer_group_id) + * .then(({ customer_group }) => { + * console.log(customer_group.id); + * }); + * - lang: Shell + * label: cURL + * source: | + * curl --location --request GET 'https://medusa-url.com/admin/customer-groups/{id}' \ + * --header 'Authorization: Bearer {api_token}' + * security: + * - api_token: [] + * - cookie_auth: [] * tags: * - Customer Group * responses: @@ -24,6 +43,18 @@ import { FindParams } from "../../../../types/common" * properties: * customer_group: * $ref: "#/components/schemas/customer_group" + * "400": + * $ref: "#/components/responses/400_error" + * "401": + * $ref: "#/components/responses/unauthorized" + * "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: Request, res: Response) => { const { id } = req.params diff --git a/packages/medusa/src/api/routes/admin/customer-groups/list-customer-groups.ts b/packages/medusa/src/api/routes/admin/customer-groups/list-customer-groups.ts index b0ce19e49e..84b50f76e1 100644 --- a/packages/medusa/src/api/routes/admin/customer-groups/list-customer-groups.ts +++ b/packages/medusa/src/api/routes/admin/customer-groups/list-customer-groups.ts @@ -99,7 +99,25 @@ import { Type } from "class-transformer" * format: date * - (query) limit=10 {integer} Limit the number of customer groups returned. * - (query) expand {string} (Comma separated) Which fields should be expanded in each customer groups of the result. - + * x-codeSamples: + * - lang: JavaScript + * label: JS Client + * source: | + * import Medusa from "@medusajs/medusa-js" + * const medusa = new Medusa({ baseUrl: MEDUSA_BACKEND_URL, maxRetries: 3 }) + * // must be previously logged in or use api token + * medusa.admin.customerGroups.list() + * .then(({ customer_groups, limit, offset, count }) => { + * console.log(customer_groups.id); + * }); + * - lang: Shell + * label: cURL + * source: | + * curl --location --request GET 'https://medusa-url.com/admin/customer-groups' \ + * --header 'Authorization: Bearer {api_token}' + * security: + * - api_token: [] + * - cookie_auth: [] * tags: * - Customer Group * responses: @@ -122,6 +140,18 @@ import { Type } from "class-transformer" * limit: * type: integer * description: The number of items per page + * "400": + * $ref: "#/components/responses/400_error" + * "401": + * $ref: "#/components/responses/unauthorized" + * "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: Request, res: Response) => { const customerGroupService: CustomerGroupService = req.scope.resolve( diff --git a/packages/medusa/src/api/routes/admin/customer-groups/update-customer-group.ts b/packages/medusa/src/api/routes/admin/customer-groups/update-customer-group.ts index 54313279ff..6b39ea2355 100644 --- a/packages/medusa/src/api/routes/admin/customer-groups/update-customer-group.ts +++ b/packages/medusa/src/api/routes/admin/customer-groups/update-customer-group.ts @@ -26,6 +26,31 @@ import { validator } from "../../../../utils/validator" * metadata: * description: "Metadata for the customer." * type: object + * x-codeSamples: + * - lang: JavaScript + * label: JS Client + * source: | + * import Medusa from "@medusajs/medusa-js" + * const medusa = new Medusa({ baseUrl: MEDUSA_BACKEND_URL, maxRetries: 3 }) + * // must be previously logged in or use api token + * medusa.admin.customerGroups.update(customer_group_id, { + * name: 'VIP' + * }) + * .then(({ customer_group }) => { + * console.log(customer_group.id); + * }); + * - lang: Shell + * label: cURL + * source: | + * curl --location --request POST 'https://medusa-url.com/admin/customer-groups/{id}' \ + * --header 'Authorization: Bearer {api_token}' \ + * --header 'Content-Type: application/json' \ + * --data-raw '{ + * "name": "VIP" + * }' + * security: + * - api_token: [] + * - cookie_auth: [] * tags: * - Customer Group * responses: @@ -37,6 +62,18 @@ import { validator } from "../../../../utils/validator" * properties: * customer_group: * $ref: "#/components/schemas/customer_group" + * "400": + * $ref: "#/components/responses/400_error" + * "401": + * $ref: "#/components/responses/unauthorized" + * "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: Request, res: Response) => { diff --git a/packages/medusa/src/api/routes/admin/customers/create-customer.ts b/packages/medusa/src/api/routes/admin/customers/create-customer.ts index e26d2a6117..9d3d7cf6e6 100644 --- a/packages/medusa/src/api/routes/admin/customers/create-customer.ts +++ b/packages/medusa/src/api/routes/admin/customers/create-customer.ts @@ -42,6 +42,37 @@ import { EntityManager } from "typeorm" * type: object * tags: * - Customer + * x-codeSamples: + * - lang: JavaScript + * label: JS Client + * source: | + * import Medusa from "@medusajs/medusa-js" + * const medusa = new Medusa({ baseUrl: MEDUSA_BACKEND_URL, maxRetries: 3 }) + * // must be previously logged in or use api token + * medusa.admin.customers.create({ + * email: 'user@example.com', + * first_name: 'Caterina', + * last_name: 'Yost', + * password: 'supersecret' + * }) + * .then(({ customer }) => { + * console.log(customer.id); + * }); + * - lang: Shell + * label: cURL + * source: | + * curl --location --request POST 'https://medusa-url.com/admin/customers' \ + * --header 'Authorization: Bearer {api_token}' \ + * --header 'Content-Type: application/json' \ + * --data-raw '{ + * "email": "user@example.com", + * "first_name": "Caterina", + * "last_name": "Yost", + * "password": "supersecret" + * }' + * security: + * - api_token: [] + * - cookie_auth: [] * responses: * 201: * description: OK @@ -51,6 +82,18 @@ import { EntityManager } from "typeorm" * properties: * customer: * $ref: "#/components/schemas/customer" + * "400": + * $ref: "#/components/responses/400_error" + * "401": + * $ref: "#/components/responses/unauthorized" + * "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 validated = await validator(AdminPostCustomersReq, req.body) diff --git a/packages/medusa/src/api/routes/admin/customers/get-customer.ts b/packages/medusa/src/api/routes/admin/customers/get-customer.ts index d388b1a884..85c997eb6a 100644 --- a/packages/medusa/src/api/routes/admin/customers/get-customer.ts +++ b/packages/medusa/src/api/routes/admin/customers/get-customer.ts @@ -13,6 +13,25 @@ import { validator } from "../../../../utils/validator" * - (path) id=* {string} The ID of the Customer. * - (query) expand {string} (Comma separated) Which fields should be expanded in the customer. * - (query) fields {string} (Comma separated) Which fields should be included in the customer. + * x-codeSamples: + * - lang: JavaScript + * label: JS Client + * source: | + * import Medusa from "@medusajs/medusa-js" + * const medusa = new Medusa({ baseUrl: MEDUSA_BACKEND_URL, maxRetries: 3 }) + * // must be previously logged in or use api token + * medusa.admin.customers.retrieve(customer_id) + * .then(({ customer }) => { + * console.log(customer.id); + * }); + * - lang: Shell + * label: cURL + * source: | + * curl --location --request GET 'https://medusa-url.com/admin/customers/{id}' \ + * --header 'Authorization: Bearer {api_token}' + * security: + * - api_token: [] + * - cookie_auth: [] * tags: * - Customer * responses: @@ -24,6 +43,18 @@ import { validator } from "../../../../utils/validator" * properties: * customer: * $ref: "#/components/schemas/customer" + * "400": + * $ref: "#/components/responses/400_error" + * "401": + * $ref: "#/components/responses/unauthorized" + * "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 { id } = req.params diff --git a/packages/medusa/src/api/routes/admin/customers/list-customers.ts b/packages/medusa/src/api/routes/admin/customers/list-customers.ts index 896b6a1932..757f2a637e 100644 --- a/packages/medusa/src/api/routes/admin/customers/list-customers.ts +++ b/packages/medusa/src/api/routes/admin/customers/list-customers.ts @@ -16,6 +16,25 @@ import customerController from "../../../../controllers/customers" * - (query) expand {string} (Comma separated) Which fields should be expanded in each customer. * - (query) q {string} a search term to search email, first_name, and last_name. * - (query) groups[] {string} group IDs to search customers by. + * x-codeSamples: + * - lang: JavaScript + * label: JS Client + * source: | + * import Medusa from "@medusajs/medusa-js" + * const medusa = new Medusa({ baseUrl: MEDUSA_BACKEND_URL, maxRetries: 3 }) + * // must be previously logged in or use api token + * medusa.admin.customers.list() + * .then(({ customers, limit, offset, count }) => { + * console.log(customers.length); + * }); + * - lang: Shell + * label: cURL + * source: | + * curl --location --request GET 'https://medusa-url.com/admin/customers' \ + * --header 'Authorization: Bearer {api_token}' + * security: + * - api_token: [] + * - cookie_auth: [] * tags: * - Customer * responses: @@ -38,6 +57,18 @@ import customerController from "../../../../controllers/customers" * limit: * type: integer * description: The number of items per page + * "400": + * $ref: "#/components/responses/400_error" + * "401": + * $ref: "#/components/responses/unauthorized" + * "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 result = await customerController.listAndCount( diff --git a/packages/medusa/src/api/routes/admin/customers/update-customer.ts b/packages/medusa/src/api/routes/admin/customers/update-customer.ts index 975d6e93f2..8880651745 100644 --- a/packages/medusa/src/api/routes/admin/customers/update-customer.ts +++ b/packages/medusa/src/api/routes/admin/customers/update-customer.ts @@ -60,6 +60,31 @@ import { validator } from "../../../../utils/validator" * metadata: * description: An optional set of key-value pairs to hold additional information. * type: object + * x-codeSamples: + * - lang: JavaScript + * label: JS Client + * source: | + * import Medusa from "@medusajs/medusa-js" + * const medusa = new Medusa({ baseUrl: MEDUSA_BACKEND_URL, maxRetries: 3 }) + * // must be previously logged in or use api token + * medusa.admin.customers.update(customer_id, { + * first_name: 'Dolly' + * }) + * .then(({ customer }) => { + * console.log(customer.id); + * }); + * - lang: Shell + * label: cURL + * source: | + * curl --location --request POST 'https://medusa-url.com/admin/customers/{id}' \ + * --header 'Authorization: Bearer {api_token}' \ + * --header 'Content-Type: application/json' \ + * --data-raw '{ + * "first_name": "Dolly" + * }' + * security: + * - api_token: [] + * - cookie_auth: [] * tags: * - Customer * responses: @@ -71,6 +96,18 @@ import { validator } from "../../../../utils/validator" * properties: * customer: * $ref: "#/components/schemas/customer" + * "400": + * $ref: "#/components/responses/400_error" + * "401": + * $ref: "#/components/responses/unauthorized" + * "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 { id } = req.params diff --git a/packages/medusa/src/api/routes/admin/discounts/add-region.ts b/packages/medusa/src/api/routes/admin/discounts/add-region.ts index 226f35e95e..957061cb7c 100644 --- a/packages/medusa/src/api/routes/admin/discounts/add-region.ts +++ b/packages/medusa/src/api/routes/admin/discounts/add-region.ts @@ -13,6 +13,25 @@ import { EntityManager } from "typeorm" * parameters: * - (path) id=* {string} The ID of the Discount. * - (path) region_id=* {string} The ID of the Region. + * x-codeSamples: + * - lang: JavaScript + * label: JS Client + * source: | + * import Medusa from "@medusajs/medusa-js" + * const medusa = new Medusa({ baseUrl: MEDUSA_BACKEND_URL, maxRetries: 3 }) + * // must be previously logged in or use api token + * medusa.admin.discounts.addRegion(discount_id, region_id) + * .then(({ discount }) => { + * console.log(discount.id); + * }); + * - lang: Shell + * label: cURL + * source: | + * curl --location --request POST 'https://medusa-url.com/admin/discounts/{id}/regions/{region_id}' \ + * --header 'Authorization: Bearer {api_token}' + * security: + * - api_token: [] + * - cookie_auth: [] * tags: * - Discount * responses: @@ -24,6 +43,18 @@ import { EntityManager } from "typeorm" * properties: * discount: * $ref: "#/components/schemas/discount" + * "400": + * $ref: "#/components/responses/400_error" + * "401": + * $ref: "#/components/responses/unauthorized" + * "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 { discount_id, region_id } = req.params diff --git a/packages/medusa/src/api/routes/admin/discounts/create-condition.ts b/packages/medusa/src/api/routes/admin/discounts/create-condition.ts index a6189525ff..5018ed4fe5 100644 --- a/packages/medusa/src/api/routes/admin/discounts/create-condition.ts +++ b/packages/medusa/src/api/routes/admin/discounts/create-condition.ts @@ -55,7 +55,32 @@ import { validator } from "../../../../utils/validator" * description: list of customer group IDs if the condition is applied on customer groups. * items: * type: string - + * x-codeSamples: + * - lang: JavaScript + * label: JS Client + * source: | + * import Medusa from "@medusajs/medusa-js" + * import { DiscountConditionOperator } from "@medusajs/medusa" + * const medusa = new Medusa({ baseUrl: MEDUSA_BACKEND_URL, maxRetries: 3 }) + * // must be previously logged in or use api token + * medusa.admin.discounts.createCondition(discount_id, { + * operator: DiscountConditionOperator.IN + * }) + * .then(({ discount }) => { + * console.log(discount.id); + * }); + * - lang: Shell + * label: cURL + * source: | + * curl --location --request POST 'https://medusa-url.com/admin/discounts/{id}/conditions' \ + * --header 'Authorization: Bearer {api_token}' \ + * --header 'Content-Type: application/json' \ + * --data-raw '{ + * "operator": "in" + * }' + * security: + * - api_token: [] + * - cookie_auth: [] * tags: * - Discount Condition * responses: @@ -67,6 +92,18 @@ import { validator } from "../../../../utils/validator" * properties: * discount: * $ref: "#/components/schemas/discount" + * "400": + * $ref: "#/components/responses/400_error" + * "401": + * $ref: "#/components/responses/unauthorized" + * "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 { discount_id } = req.params diff --git a/packages/medusa/src/api/routes/admin/discounts/create-discount.ts b/packages/medusa/src/api/routes/admin/discounts/create-discount.ts index bbf84f8305..1980d7e715 100644 --- a/packages/medusa/src/api/routes/admin/discounts/create-discount.ts +++ b/packages/medusa/src/api/routes/admin/discounts/create-discount.ts @@ -139,6 +139,44 @@ import { validator } from "../../../../utils/validator" * metadata: * description: An optional set of key-value pairs to hold additional information. * type: object + * x-codeSamples: + * - lang: JavaScript + * label: JS Client + * source: | + * import Medusa from "@medusajs/medusa-js" + * import { AllocationType, DiscountRuleType } from "@medusajs/medusa" + * const medusa = new Medusa({ baseUrl: MEDUSA_BACKEND_URL, maxRetries: 3 }) + * // must be previously logged in or use api token + * medusa.admin.discounts.create({ + * code: 'TEST', + * rule: { + * type: DiscountRuleType.FIXED, + * value: 10, + * allocation: AllocationType.ITEM + * }, + * is_dynamic: false, + * is_disabled: false + * }) + * .then(({ discount }) => { + * console.log(discount.id); + * }); + * - lang: Shell + * label: cURL + * source: | + * curl --location --request POST 'https://medusa-url.com/admin/discounts' \ + * --header 'Authorization: Bearer {api_token}' \ + * --header 'Content-Type: application/json' \ + * --data-raw '{ + * "code": "TEST", + * "rule": { + * "type": "fixed", + * "value": 10, + * "allocation": "item" + * } + * }' + * security: + * - api_token: [] + * - cookie_auth: [] * tags: * - Discount * responses: @@ -150,6 +188,18 @@ import { validator } from "../../../../utils/validator" * properties: * discount: * $ref: "#/components/schemas/discount" + * "400": + * $ref: "#/components/responses/400_error" + * "401": + * $ref: "#/components/responses/unauthorized" + * "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) => { diff --git a/packages/medusa/src/api/routes/admin/discounts/create-dynamic-code.ts b/packages/medusa/src/api/routes/admin/discounts/create-dynamic-code.ts index 5dabee0b00..5a96802261 100644 --- a/packages/medusa/src/api/routes/admin/discounts/create-dynamic-code.ts +++ b/packages/medusa/src/api/routes/admin/discounts/create-dynamic-code.ts @@ -22,6 +22,32 @@ import { validator } from "../../../../utils/validator" * - (body) code=* {string} The unique code that will be used to redeem the Discount. * - (body) usage_limit=1 {number} amount of times the discount can be applied. * - (body) metadata {object} An optional set of key-value paris to hold additional information. + * x-codeSamples: + * - lang: JavaScript + * label: JS Client + * source: | + * import Medusa from "@medusajs/medusa-js" + * const medusa = new Medusa({ baseUrl: MEDUSA_BACKEND_URL, maxRetries: 3 }) + * // must be previously logged in or use api token + * medusa.admin.discounts.createDynamicCode(discount_id, { + * code: 'TEST', + * usage_limit: 1 + * }) + * .then(({ discount }) => { + * console.log(discount.id); + * }); + * - lang: Shell + * label: cURL + * source: | + * curl --location --request POST 'https://medusa-url.com/admin/discounts/{id}/dynamic-codes' \ + * --header 'Authorization: Bearer {api_token}' \ + * --header 'Content-Type: application/json' \ + * --data-raw '{ + * "code": "TEST" + * }' + * security: + * - api_token: [] + * - cookie_auth: [] * tags: * - Discount * responses: @@ -33,6 +59,18 @@ import { validator } from "../../../../utils/validator" * properties: * discount: * $ref: "#/components/schemas/discount" + * "400": + * $ref: "#/components/responses/400_error" + * "401": + * $ref: "#/components/responses/unauthorized" + * "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 { discount_id } = req.params diff --git a/packages/medusa/src/api/routes/admin/discounts/delete-condition.ts b/packages/medusa/src/api/routes/admin/discounts/delete-condition.ts index bc0a119dd4..4cfd133f7b 100644 --- a/packages/medusa/src/api/routes/admin/discounts/delete-condition.ts +++ b/packages/medusa/src/api/routes/admin/discounts/delete-condition.ts @@ -20,6 +20,25 @@ import { validator } from "../../../../utils/validator" * - (path) condition_id=* {string} The ID of the DiscountCondition * - (query) expand {string} Comma separated list of relations to include in the results. * - (query) fields {string} Comma separated list of fields to include in the results. + * x-codeSamples: + * - lang: JavaScript + * label: JS Client + * source: | + * import Medusa from "@medusajs/medusa-js" + * const medusa = new Medusa({ baseUrl: MEDUSA_BACKEND_URL, maxRetries: 3 }) + * // must be previously logged in or use api token + * medusa.admin.discounts.deleteCondition(discount_id, condition_id) + * .then(({ id, object, deleted }) => { + * console.log(id); + * }); + * - lang: Shell + * label: cURL + * source: | + * curl --location --request DELETE 'https://medusa-url.com/admin/discounts/{id}/conditions/{condition_id}' \ + * --header 'Authorization: Bearer {api_token}' + * security: + * - api_token: [] + * - cookie_auth: [] * tags: * - Discount Condition * responses: @@ -43,6 +62,18 @@ import { validator } from "../../../../utils/validator" * discount: * description: The Discount to which the condition used to belong * $ref: "#/components/schemas/discount" + * "400": + * $ref: "#/components/responses/400_error" + * "401": + * $ref: "#/components/responses/unauthorized" + * "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 { discount_id, condition_id } = req.params diff --git a/packages/medusa/src/api/routes/admin/discounts/delete-discount.ts b/packages/medusa/src/api/routes/admin/discounts/delete-discount.ts index 04100d530b..93632a7711 100644 --- a/packages/medusa/src/api/routes/admin/discounts/delete-discount.ts +++ b/packages/medusa/src/api/routes/admin/discounts/delete-discount.ts @@ -9,6 +9,25 @@ import { EntityManager } from "typeorm" * x-authenticated: true * parameters: * - (path) id=* {string} The ID of the Discount + * x-codeSamples: + * - lang: JavaScript + * label: JS Client + * source: | + * import Medusa from "@medusajs/medusa-js" + * const medusa = new Medusa({ baseUrl: MEDUSA_BACKEND_URL, maxRetries: 3 }) + * // must be previously logged in or use api token + * medusa.admin.discounts.delete(discount_id) + * .then(({ id, object, deleted }) => { + * console.log(id); + * }); + * - lang: Shell + * label: cURL + * source: | + * curl --location --request DELETE 'https://medusa-url.com/admin/discounts/{id}' \ + * --header 'Authorization: Bearer {api_token}' + * security: + * - api_token: [] + * - cookie_auth: [] * tags: * - Discount * responses: @@ -29,6 +48,18 @@ import { EntityManager } from "typeorm" * type: boolean * description: Whether the discount was deleted successfully or not. * default: true + * "400": + * $ref: "#/components/responses/400_error" + * "401": + * $ref: "#/components/responses/unauthorized" + * "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 { discount_id } = req.params diff --git a/packages/medusa/src/api/routes/admin/discounts/delete-dynamic-code.ts b/packages/medusa/src/api/routes/admin/discounts/delete-dynamic-code.ts index 8e4b62e7b6..c2308d758c 100644 --- a/packages/medusa/src/api/routes/admin/discounts/delete-dynamic-code.ts +++ b/packages/medusa/src/api/routes/admin/discounts/delete-dynamic-code.ts @@ -12,6 +12,25 @@ import { EntityManager } from "typeorm" * parameters: * - (path) id=* {string} The ID of the Discount * - (path) code=* {string} The ID of the Discount + * x-codeSamples: + * - lang: JavaScript + * label: JS Client + * source: | + * import Medusa from "@medusajs/medusa-js" + * const medusa = new Medusa({ baseUrl: MEDUSA_BACKEND_URL, maxRetries: 3 }) + * // must be previously logged in or use api token + * medusa.admin.discounts.deleteDynamicCode(discount_id, code) + * .then(({ discount }) => { + * console.log(discount.id); + * }); + * - lang: Shell + * label: cURL + * source: | + * curl --location --request DELETE 'https://medusa-url.com/admin/discounts/{id}/dynamic-codes/{code}' \ + * --header 'Authorization: Bearer {api_token}' + * security: + * - api_token: [] + * - cookie_auth: [] * tags: * - Discount * responses: @@ -23,6 +42,18 @@ import { EntityManager } from "typeorm" * properties: * discount: * $ref: "#/components/schemas/discount" + * "400": + * $ref: "#/components/responses/400_error" + * "401": + * $ref: "#/components/responses/unauthorized" + * "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 { discount_id, code } = req.params diff --git a/packages/medusa/src/api/routes/admin/discounts/get-condition.ts b/packages/medusa/src/api/routes/admin/discounts/get-condition.ts index 687a42bcea..aed2572d74 100644 --- a/packages/medusa/src/api/routes/admin/discounts/get-condition.ts +++ b/packages/medusa/src/api/routes/admin/discounts/get-condition.ts @@ -15,14 +15,32 @@ import { validator } from "../../../../utils/validator" * @oas [get] /discounts/{discount_id}/conditions/{condition_id} * operationId: "GetDiscountsDiscountConditionsCondition" * summary: "Gets a DiscountCondition" + * description: "Gets a DiscountCondition" * x-authenticated: true * parameters: * - (path) discount_id=* {string} The ID of the Discount. * - (path) condition_id=* {string} The ID of the DiscountCondition. * - (query) expand {string} Comma separated list of relations to include in the results. * - (query) fields {string} Comma separated list of fields to include in the results. - * description: "Gets a DiscountCondition" - + * x-codeSamples: + * - lang: JavaScript + * label: JS Client + * source: | + * import Medusa from "@medusajs/medusa-js" + * const medusa = new Medusa({ baseUrl: MEDUSA_BACKEND_URL, maxRetries: 3 }) + * // must be previously logged in or use api token + * medusa.admin.discounts.getCondition(discount_id, condition_id) + * .then(({ discount_condition }) => { + * console.log(discount_condition.id); + * }); + * - lang: Shell + * label: cURL + * source: | + * curl --location --request GET 'https://medusa-url.com/admin/discounts/{id}/conditions/{condition_id}' \ + * --header 'Authorization: Bearer {api_token}' + * security: + * - api_token: [] + * - cookie_auth: [] * tags: * - Discount Condition * responses: @@ -34,6 +52,18 @@ import { validator } from "../../../../utils/validator" * properties: * discount_condition: * $ref: "#/components/schemas/discount_condition" + * "400": + * $ref: "#/components/responses/400_error" + * "401": + * $ref: "#/components/responses/unauthorized" + * "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) => { diff --git a/packages/medusa/src/api/routes/admin/discounts/get-discount-by-code.ts b/packages/medusa/src/api/routes/admin/discounts/get-discount-by-code.ts index 160479a6c9..3abfd3e3a5 100644 --- a/packages/medusa/src/api/routes/admin/discounts/get-discount-by-code.ts +++ b/packages/medusa/src/api/routes/admin/discounts/get-discount-by-code.ts @@ -15,6 +15,25 @@ import { validator } from "../../../../utils/validator" * - (path) code=* {string} The code of the Discount * - (query) expand {string} Comma separated list of relations to include in the results. * - (query) fields {string} Comma separated list of fields to include in the results. + * x-codeSamples: + * - lang: JavaScript + * label: JS Client + * source: | + * import Medusa from "@medusajs/medusa-js" + * const medusa = new Medusa({ baseUrl: MEDUSA_BACKEND_URL, maxRetries: 3 }) + * // must be previously logged in or use api token + * medusa.admin.discounts.retrieveByCode(code) + * .then(({ discount }) => { + * console.log(discount.id); + * }); + * - lang: Shell + * label: cURL + * source: | + * curl --location --request GET 'https://medusa-url.com/admin/discounts/code/{code}' \ + * --header 'Authorization: Bearer {api_token}' + * security: + * - api_token: [] + * - cookie_auth: [] * tags: * - Discount * responses: @@ -26,6 +45,18 @@ import { validator } from "../../../../utils/validator" * properties: * discount: * $ref: "#/components/schemas/discount" + * "400": + * $ref: "#/components/responses/400_error" + * "401": + * $ref: "#/components/responses/unauthorized" + * "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 { code } = req.params diff --git a/packages/medusa/src/api/routes/admin/discounts/get-discount.ts b/packages/medusa/src/api/routes/admin/discounts/get-discount.ts index a410999366..ea9061449f 100644 --- a/packages/medusa/src/api/routes/admin/discounts/get-discount.ts +++ b/packages/medusa/src/api/routes/admin/discounts/get-discount.ts @@ -15,6 +15,25 @@ import { validator } from "../../../../utils/validator" * - (path) id=* {string} The ID of the Discount * - (query) expand {string} Comma separated list of relations to include in the results. * - (query) fields {string} Comma separated list of fields to include in the results. + * x-codeSamples: + * - lang: JavaScript + * label: JS Client + * source: | + * import Medusa from "@medusajs/medusa-js" + * const medusa = new Medusa({ baseUrl: MEDUSA_BACKEND_URL, maxRetries: 3 }) + * // must be previously logged in or use api token + * medusa.admin.discounts.retrieve(discount_id) + * .then(({ discount }) => { + * console.log(discount.id); + * }); + * - lang: Shell + * label: cURL + * source: | + * curl --location --request GET 'https://medusa-url.com/admin/discounts/{id}' \ + * --header 'Authorization: Bearer {api_token}' + * security: + * - api_token: [] + * - cookie_auth: [] * tags: * - Discount * responses: @@ -26,6 +45,18 @@ import { validator } from "../../../../utils/validator" * properties: * discount: * $ref: "#/components/schemas/discount" + * "400": + * $ref: "#/components/responses/400_error" + * "401": + * $ref: "#/components/responses/unauthorized" + * "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 { discount_id } = req.params diff --git a/packages/medusa/src/api/routes/admin/discounts/list-discounts.ts b/packages/medusa/src/api/routes/admin/discounts/list-discounts.ts index 7a725db09a..5aa78af038 100644 --- a/packages/medusa/src/api/routes/admin/discounts/list-discounts.ts +++ b/packages/medusa/src/api/routes/admin/discounts/list-discounts.ts @@ -43,6 +43,25 @@ import { isDefined } from "../../../../utils" * - (query) limit=20 {number} The number of items in the response * - (query) offset=0 {number} The offset of items in response * - (query) expand {string} Comma separated list of relations to include in the results. + * x-codeSamples: + * - lang: JavaScript + * label: JS Client + * source: | + * import Medusa from "@medusajs/medusa-js" + * const medusa = new Medusa({ baseUrl: MEDUSA_BACKEND_URL, maxRetries: 3 }) + * // must be previously logged in or use api token + * medusa.admin.discounts.list() + * .then(({ discounts, limit, offset, count }) => { + * console.log(discounts.id); + * }); + * - lang: Shell + * label: cURL + * source: | + * curl --location --request GET 'https://medusa-url.com/admin/discounts' \ + * --header 'Authorization: Bearer {api_token}' + * security: + * - api_token: [] + * - cookie_auth: [] * tags: * - Discount * responses: @@ -65,6 +84,18 @@ import { isDefined } from "../../../../utils" * limit: * type: integer * description: The number of items per page + * "400": + * $ref: "#/components/responses/400_error" + * "401": + * $ref: "#/components/responses/unauthorized" + * "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 validated = await validator(AdminGetDiscountsParams, req.query) diff --git a/packages/medusa/src/api/routes/admin/discounts/remove-region.ts b/packages/medusa/src/api/routes/admin/discounts/remove-region.ts index a273fdc1c2..445244ec79 100644 --- a/packages/medusa/src/api/routes/admin/discounts/remove-region.ts +++ b/packages/medusa/src/api/routes/admin/discounts/remove-region.ts @@ -12,6 +12,25 @@ import { EntityManager } from "typeorm" * parameters: * - (path) id=* {string} The ID of the Discount. * - (path) region_id=* {string} The ID of the Region. + * x-codeSamples: + * - lang: JavaScript + * label: JS Client + * source: | + * import Medusa from "@medusajs/medusa-js" + * const medusa = new Medusa({ baseUrl: MEDUSA_BACKEND_URL, maxRetries: 3 }) + * // must be previously logged in or use api token + * medusa.admin.discounts.removeRegion(discount_id, region_id) + * .then(({ discount }) => { + * console.log(discount.id); + * }); + * - lang: Shell + * label: cURL + * source: | + * curl --location --request DELETE 'https://medusa-url.com/admin/discounts/{id}/regions/{region_id}' \ + * --header 'Authorization: Bearer {api_token}' + * security: + * - api_token: [] + * - cookie_auth: [] * tags: * - Discount * responses: @@ -23,6 +42,18 @@ import { EntityManager } from "typeorm" * properties: * discount: * $ref: "#/components/schemas/discount" + * "400": + * $ref: "#/components/responses/400_error" + * "401": + * $ref: "#/components/responses/unauthorized" + * "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 { discount_id, region_id } = req.params diff --git a/packages/medusa/src/api/routes/admin/discounts/update-condition.ts b/packages/medusa/src/api/routes/admin/discounts/update-condition.ts index b172fdaaa2..bcc2f181fb 100644 --- a/packages/medusa/src/api/routes/admin/discounts/update-condition.ts +++ b/packages/medusa/src/api/routes/admin/discounts/update-condition.ts @@ -50,6 +50,35 @@ import { validator } from "../../../../utils/validator" * description: list of customer group IDs if the condition is applied on customer groups. * items: * type: string + * x-codeSamples: + * - lang: JavaScript + * label: JS Client + * source: | + * import Medusa from "@medusajs/medusa-js" + * const medusa = new Medusa({ baseUrl: MEDUSA_BACKEND_URL, maxRetries: 3 }) + * // must be previously logged in or use api token + * medusa.admin.discounts.updateCondition(discount_id, condition_id, { + * products: [ + * product_id + * ] + * }) + * .then(({ discount }) => { + * console.log(discount.id); + * }); + * - lang: Shell + * label: cURL + * source: | + * curl --location --request POST 'https://medusa-url.com/admin/discounts/{id}/conditions/{condition}' \ + * --header 'Authorization: Bearer {api_token}' \ + * --header 'Content-Type: application/json' \ + * --data-raw '{ + * "products": [ + * "prod_01G1G5V2MBA328390B5AXJ610F" + * ] + * }' + * security: + * - api_token: [] + * - cookie_auth: [] * tags: * - Discount * responses: @@ -61,6 +90,18 @@ import { validator } from "../../../../utils/validator" * properties: * discount: * $ref: "#/components/schemas/discount" + * "400": + * $ref: "#/components/responses/400_error" + * "401": + * $ref: "#/components/responses/unauthorized" + * "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) => { diff --git a/packages/medusa/src/api/routes/admin/discounts/update-discount.ts b/packages/medusa/src/api/routes/admin/discounts/update-discount.ts index 3d465e4f75..0078ab7f44 100644 --- a/packages/medusa/src/api/routes/admin/discounts/update-discount.ts +++ b/packages/medusa/src/api/routes/admin/discounts/update-discount.ts @@ -127,6 +127,31 @@ import { validator } from "../../../../utils/validator" * metadata: * description: An object containing metadata of the discount * type: object + * x-codeSamples: + * - lang: JavaScript + * label: JS Client + * source: | + * import Medusa from "@medusajs/medusa-js" + * const medusa = new Medusa({ baseUrl: MEDUSA_BACKEND_URL, maxRetries: 3 }) + * // must be previously logged in or use api token + * medusa.admin.discounts.update(discount_id, { + * code: 'TEST' + * }) + * .then(({ discount }) => { + * console.log(discount.id); + * }); + * - lang: Shell + * label: cURL + * source: | + * curl --location --request POST 'https://medusa-url.com/admin/discounts/{id}' \ + * --header 'Authorization: Bearer {api_token}' \ + * --header 'Content-Type: application/json' \ + * --data-raw '{ + * "code": "TEST" + * }' + * security: + * - api_token: [] + * - cookie_auth: [] * tags: * - Discount * responses: @@ -138,6 +163,18 @@ import { validator } from "../../../../utils/validator" * properties: * discount: * $ref: "#/components/schemas/discount" + * "400": + * $ref: "#/components/responses/400_error" + * "401": + * $ref: "#/components/responses/unauthorized" + * "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 { discount_id } = req.params diff --git a/packages/medusa/src/api/routes/admin/draft-orders/create-draft-order.ts b/packages/medusa/src/api/routes/admin/draft-orders/create-draft-order.ts index 259850f190..84e11460bb 100644 --- a/packages/medusa/src/api/routes/admin/draft-orders/create-draft-order.ts +++ b/packages/medusa/src/api/routes/admin/draft-orders/create-draft-order.ts @@ -116,6 +116,53 @@ import { validator } from "../../../../utils/validator" * metadata: * description: The optional key-value map with additional details about the Draft Order. * type: object + * x-codeSamples: + * - lang: JavaScript + * label: JS Client + * source: | + * import Medusa from "@medusajs/medusa-js" + * const medusa = new Medusa({ baseUrl: MEDUSA_BACKEND_URL, maxRetries: 3 }) + * // must be previously logged in or use api token + * medusa.admin.draftOrders.create({ + * email: 'user@example.com', + * region_id, + * items: [ + * { + * quantity: 1 + * } + * ], + * shipping_methods: [ + * { + * option_id + * } + * ], + * }) + * .then(({ draft_order }) => { + * console.log(draft_order.id); + * }); + * - lang: Shell + * label: cURL + * source: | + * curl --location --request POST 'https://medusa-url.com/admin/draft-orders' \ + * --header 'Authorization: Bearer {api_token}' \ + * --header 'Content-Type: application/json' \ + * --data-raw '{ + * "email": "user@example.com", + * "region_id": "{region_id}" + * "items": [ + * { + * "quantity": 1 + * } + * ], + * "shipping_methods": [ + * { + * "option_id": "{option_id}" + * } + * ] + * }' + * security: + * - api_token: [] + * - cookie_auth: [] * tags: * - Draft Order * responses: @@ -127,6 +174,18 @@ import { validator } from "../../../../utils/validator" * properties: * draft_order: * $ref: "#/components/schemas/draft-order" + * "400": + * $ref: "#/components/responses/400_error" + * "401": + * $ref: "#/components/responses/unauthorized" + * "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) => { diff --git a/packages/medusa/src/api/routes/admin/draft-orders/create-line-item.ts b/packages/medusa/src/api/routes/admin/draft-orders/create-line-item.ts index e44168070d..c25ad0bbac 100644 --- a/packages/medusa/src/api/routes/admin/draft-orders/create-line-item.ts +++ b/packages/medusa/src/api/routes/admin/draft-orders/create-line-item.ts @@ -52,6 +52,31 @@ import { validator } from "../../../../utils/validator" * metadata: * description: The optional key-value map with additional details about the Line Item. * type: object + * x-codeSamples: + * - lang: JavaScript + * label: JS Client + * source: | + * import Medusa from "@medusajs/medusa-js" + * const medusa = new Medusa({ baseUrl: MEDUSA_BACKEND_URL, maxRetries: 3 }) + * // must be previously logged in or use api token + * medusa.admin.draftOrders.addLineItem(draft_order_id, { + * quantity: 1 + * }) + * .then(({ draft_order }) => { + * console.log(draft_order.id); + * }); + * - lang: Shell + * label: cURL + * source: | + * curl --location --request POST 'https://medusa-url.com/admin/draft-orders/{id}/line-items' \ + * --header 'Authorization: Bearer {api_token}' \ + * --header 'Content-Type: application/json' \ + * --data-raw '{ + * "quantity": 1 + * }' + * security: + * - api_token: [] + * - cookie_auth: [] * tags: * - Draft Order * responses: @@ -63,6 +88,18 @@ import { validator } from "../../../../utils/validator" * properties: * draft_order: * $ref: "#/components/schemas/draft-order" + * "400": + * $ref: "#/components/responses/400_error" + * "401": + * $ref: "#/components/responses/unauthorized" + * "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) => { diff --git a/packages/medusa/src/api/routes/admin/draft-orders/delete-draft-order.ts b/packages/medusa/src/api/routes/admin/draft-orders/delete-draft-order.ts index bf5ec150e0..472fa3aa49 100644 --- a/packages/medusa/src/api/routes/admin/draft-orders/delete-draft-order.ts +++ b/packages/medusa/src/api/routes/admin/draft-orders/delete-draft-order.ts @@ -8,6 +8,25 @@ import { EntityManager } from "typeorm" * x-authenticated: true * parameters: * - (path) id=* {string} The ID of the Draft Order. + * x-codeSamples: + * - lang: JavaScript + * label: JS Client + * source: | + * import Medusa from "@medusajs/medusa-js" + * const medusa = new Medusa({ baseUrl: MEDUSA_BACKEND_URL, maxRetries: 3 }) + * // must be previously logged in or use api token + * medusa.admin.draftOrders.delete(draft_order_id) + * .then(({ id, object, deleted }) => { + * console.log(id); + * }); + * - lang: Shell + * label: cURL + * source: | + * curl --location --request DELETE 'https://medusa-url.com/admin/draft-orders/{id}' \ + * --header 'Authorization: Bearer {api_token}' + * security: + * - api_token: [] + * - cookie_auth: [] * tags: * - Draft Order * responses: @@ -28,6 +47,18 @@ import { EntityManager } from "typeorm" * type: boolean * description: Whether the draft order was deleted successfully or not. * default: true + * "400": + * $ref: "#/components/responses/400_error" + * "401": + * $ref: "#/components/responses/unauthorized" + * "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 { id } = req.params diff --git a/packages/medusa/src/api/routes/admin/draft-orders/delete-line-item.ts b/packages/medusa/src/api/routes/admin/draft-orders/delete-line-item.ts index fc5308fb22..f42b536121 100644 --- a/packages/medusa/src/api/routes/admin/draft-orders/delete-line-item.ts +++ b/packages/medusa/src/api/routes/admin/draft-orders/delete-line-item.ts @@ -18,6 +18,25 @@ import { MedusaError } from "medusa-core-utils" * parameters: * - (path) id=* {string} The ID of the Draft Order. * - (path) line_id=* {string} The ID of the Draft Order. + * x-codeSamples: + * - lang: JavaScript + * label: JS Client + * source: | + * import Medusa from "@medusajs/medusa-js" + * const medusa = new Medusa({ baseUrl: MEDUSA_BACKEND_URL, maxRetries: 3 }) + * // must be previously logged in or use api token + * medusa.admin.draftOrders.removeLineItem(draft_order_id, item_id) + * .then(({ draft_order }) => { + * console.log(draft_order.id); + * }); + * - lang: Shell + * label: cURL + * source: | + * curl --location --request DELETE 'https://medusa-url.com/admin/draft-orders/{id}/line-items/{line_id}' \ + * --header 'Authorization: Bearer {api_token}' + * security: + * - api_token: [] + * - cookie_auth: [] * tags: * - Draft Order * responses: @@ -29,6 +48,18 @@ import { MedusaError } from "medusa-core-utils" * properties: * draft_order: * $ref: "#/components/schemas/draft-order" + * "400": + * $ref: "#/components/responses/400_error" + * "401": + * $ref: "#/components/responses/unauthorized" + * "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) => { diff --git a/packages/medusa/src/api/routes/admin/draft-orders/get-draft-order.ts b/packages/medusa/src/api/routes/admin/draft-orders/get-draft-order.ts index 279de073c2..ee80b5fa79 100644 --- a/packages/medusa/src/api/routes/admin/draft-orders/get-draft-order.ts +++ b/packages/medusa/src/api/routes/admin/draft-orders/get-draft-order.ts @@ -16,6 +16,25 @@ import { DraftOrder } from "../../../.." * x-authenticated: true * parameters: * - (path) id=* {string} The ID of the Draft Order. + * x-codeSamples: + * - lang: JavaScript + * label: JS Client + * source: | + * import Medusa from "@medusajs/medusa-js" + * const medusa = new Medusa({ baseUrl: MEDUSA_BACKEND_URL, maxRetries: 3 }) + * // must be previously logged in or use api token + * medusa.admin.draftOrders.retrieve(draft_order_id) + * .then(({ draft_order }) => { + * console.log(draft_order.id); + * }); + * - lang: Shell + * label: cURL + * source: | + * curl --location --request GET 'https://medusa-url.com/admin/draft-orders/{id}' \ + * --header 'Authorization: Bearer {api_token}' + * security: + * - api_token: [] + * - cookie_auth: [] * tags: * - Draft Order * responses: @@ -27,6 +46,18 @@ import { DraftOrder } from "../../../.." * properties: * draft_order: * $ref: "#/components/schemas/draft-order" + * "400": + * $ref: "#/components/responses/400_error" + * "401": + * $ref: "#/components/responses/unauthorized" + * "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) => { diff --git a/packages/medusa/src/api/routes/admin/draft-orders/list-draft-orders.ts b/packages/medusa/src/api/routes/admin/draft-orders/list-draft-orders.ts index 9762118051..3d5ab61be0 100644 --- a/packages/medusa/src/api/routes/admin/draft-orders/list-draft-orders.ts +++ b/packages/medusa/src/api/routes/admin/draft-orders/list-draft-orders.ts @@ -21,6 +21,25 @@ import { validator } from "../../../../utils/validator" * - (query) offset=0 {number} The number of items to skip before the results. * - (query) limit=50 {number} Limit the number of items returned. * - (query) q {string} a search term to search emails in carts associated with draft orders and display IDs of draft orders + * x-codeSamples: + * - lang: JavaScript + * label: JS Client + * source: | + * import Medusa from "@medusajs/medusa-js" + * const medusa = new Medusa({ baseUrl: MEDUSA_BACKEND_URL, maxRetries: 3 }) + * // must be previously logged in or use api token + * medusa.admin.draftOrders.list() + * .then(({ draft_orders, limit, offset, count }) => { + * console.log(draft_orders.length); + * }); + * - lang: Shell + * label: cURL + * source: | + * curl --location --request GET 'https://medusa-url.com/admin/draft-orders' \ + * --header 'Authorization: Bearer {api_token}' + * security: + * - api_token: [] + * - cookie_auth: [] * tags: * - Draft Order * responses: @@ -43,6 +62,18 @@ import { validator } from "../../../../utils/validator" * limit: * type: integer * description: The number of items per page + * "400": + * $ref: "#/components/responses/400_error" + * "401": + * $ref: "#/components/responses/unauthorized" + * "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) => { diff --git a/packages/medusa/src/api/routes/admin/draft-orders/register-payment.ts b/packages/medusa/src/api/routes/admin/draft-orders/register-payment.ts index 702af23ff1..3f1a425c45 100644 --- a/packages/medusa/src/api/routes/admin/draft-orders/register-payment.ts +++ b/packages/medusa/src/api/routes/admin/draft-orders/register-payment.ts @@ -19,6 +19,25 @@ import { EntityManager } from "typeorm" * x-authenticated: true * parameters: * - (path) id=* {String} The Draft Order id. + * x-codeSamples: + * - lang: JavaScript + * label: JS Client + * source: | + * import Medusa from "@medusajs/medusa-js" + * const medusa = new Medusa({ baseUrl: MEDUSA_BACKEND_URL, maxRetries: 3 }) + * // must be previously logged in or use api token + * medusa.admin.draftOrders.markPaid(draft_order_id) + * .then(({ order }) => { + * console.log(order.id); + * }); + * - lang: Shell + * label: cURL + * source: | + * curl --location --request POST 'https://medusa-url.com/admin/draft-orders/{id}/pay' \ + * --header 'Authorization: Bearer {api_token}' + * security: + * - api_token: [] + * - cookie_auth: [] * tags: * - Draft Order * responses: @@ -30,6 +49,18 @@ import { EntityManager } from "typeorm" * properties: * order: * $ref: "#/components/schemas/draft-order" + * "400": + * $ref: "#/components/responses/400_error" + * "401": + * $ref: "#/components/responses/unauthorized" + * "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) => { diff --git a/packages/medusa/src/api/routes/admin/draft-orders/update-draft-order.ts b/packages/medusa/src/api/routes/admin/draft-orders/update-draft-order.ts index a80f826440..721c815c0c 100644 --- a/packages/medusa/src/api/routes/admin/draft-orders/update-draft-order.ts +++ b/packages/medusa/src/api/routes/admin/draft-orders/update-draft-order.ts @@ -68,6 +68,31 @@ import { validator } from "../../../../utils/validator" * customer_id: * description: "The ID of the Customer to associate the Draft Order with." * type: string + * x-codeSamples: + * - lang: JavaScript + * label: JS Client + * source: | + * import Medusa from "@medusajs/medusa-js" + * const medusa = new Medusa({ baseUrl: MEDUSA_BACKEND_URL, maxRetries: 3 }) + * // must be previously logged in or use api token + * medusa.admin.draftOrders.update(draft_order_id, { + * email: "user@example.com" + * }) + * .then(({ draft_order }) => { + * console.log(draft_order.id); + * }); + * - lang: Shell + * label: cURL + * source: | + * curl --location --request POST 'https://medusa-url.com/admin/draft-orders/{id}' \ + * --header 'Authorization: Bearer {api_token}' \ + * --header 'Content-Type: application/json' \ + * --data-raw '{ + * "email": "user@example.com" + * }' + * security: + * - api_token: [] + * - cookie_auth: [] * tags: * - Draft Order * responses: @@ -79,6 +104,18 @@ import { validator } from "../../../../utils/validator" * properties: * draft_order: * $ref: "#/components/schemas/draft-order" + * "400": + * $ref: "#/components/responses/400_error" + * "401": + * $ref: "#/components/responses/unauthorized" + * "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) => { diff --git a/packages/medusa/src/api/routes/admin/draft-orders/update-line-item.ts b/packages/medusa/src/api/routes/admin/draft-orders/update-line-item.ts index 7ccb96cb62..6a51c3a9d0 100644 --- a/packages/medusa/src/api/routes/admin/draft-orders/update-line-item.ts +++ b/packages/medusa/src/api/routes/admin/draft-orders/update-line-item.ts @@ -38,6 +38,31 @@ import { validator } from "../../../../utils/validator" * metadata: * description: The optional key-value map with additional details about the Line Item. * type: object + * x-codeSamples: + * - lang: JavaScript + * label: JS Client + * source: | + * import Medusa from "@medusajs/medusa-js" + * const medusa = new Medusa({ baseUrl: MEDUSA_BACKEND_URL, maxRetries: 3 }) + * // must be previously logged in or use api token + * medusa.admin.draftOrders.updateLineItem(draft_order_id, line_id, { + * quantity: 1 + * }) + * .then(({ draft_order }) => { + * console.log(draft_order.id); + * }); + * - lang: Shell + * label: cURL + * source: | + * curl --location --request POST 'https://medusa-url.com/admin/draft-orders/{id}/line-items/{line_id}' \ + * --header 'Authorization: Bearer {api_token}' \ + * --header 'Content-Type: application/json' \ + * --data-raw '{ + * "quantity": 1 + * }' + * security: + * - api_token: [] + * - cookie_auth: [] * tags: * - Draft Order * responses: @@ -49,6 +74,18 @@ import { validator } from "../../../../utils/validator" * properties: * draft_order: * $ref: "#/components/schemas/draft-order" + * "400": + * $ref: "#/components/responses/400_error" + * "401": + * $ref: "#/components/responses/unauthorized" + * "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) => { diff --git a/packages/medusa/src/api/routes/admin/gift-cards/create-gift-card.ts b/packages/medusa/src/api/routes/admin/gift-cards/create-gift-card.ts index bc3733357f..55ace20dac 100644 --- a/packages/medusa/src/api/routes/admin/gift-cards/create-gift-card.ts +++ b/packages/medusa/src/api/routes/admin/gift-cards/create-gift-card.ts @@ -35,6 +35,31 @@ import { EntityManager } from "typeorm" * metadata: * description: An optional set of key-value pairs to hold additional information. * type: object + * x-codeSamples: + * - lang: JavaScript + * label: JS Client + * source: | + * import Medusa from "@medusajs/medusa-js" + * const medusa = new Medusa({ baseUrl: MEDUSA_BACKEND_URL, maxRetries: 3 }) + * // must be previously logged in or use api token + * medusa.admin.giftCards.create({ + * region_id + * }) + * .then(({ gift_card }) => { + * console.log(gift_card.id); + * }); + * - lang: Shell + * label: cURL + * source: | + * curl --location --request POST 'https://medusa-url.com/admin/gift-cards' \ + * --header 'Authorization: Bearer {api_token}' \ + * --header 'Content-Type: application/json' \ + * --data-raw '{ + * "region_id": "{region_id}" + * }' + * security: + * - api_token: [] + * - cookie_auth: [] * tags: * - Gift Card * responses: @@ -46,6 +71,18 @@ import { EntityManager } from "typeorm" * properties: * gift_card: * $ref: "#/components/schemas/gift_card" + * "400": + * $ref: "#/components/responses/400_error" + * "401": + * $ref: "#/components/responses/unauthorized" + * "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 validated = await validator(AdminPostGiftCardsReq, req.body) diff --git a/packages/medusa/src/api/routes/admin/gift-cards/delete-gift-card.ts b/packages/medusa/src/api/routes/admin/gift-cards/delete-gift-card.ts index 9bd27d7582..e6d7715587 100644 --- a/packages/medusa/src/api/routes/admin/gift-cards/delete-gift-card.ts +++ b/packages/medusa/src/api/routes/admin/gift-cards/delete-gift-card.ts @@ -8,6 +8,25 @@ import { EntityManager } from "typeorm" * x-authenticated: true * parameters: * - (path) id=* {string} The ID of the Gift Card to delete. + * x-codeSamples: + * - lang: JavaScript + * label: JS Client + * source: | + * import Medusa from "@medusajs/medusa-js" + * const medusa = new Medusa({ baseUrl: MEDUSA_BACKEND_URL, maxRetries: 3 }) + * // must be previously logged in or use api token + * medusa.admin.giftCards.delete(gift_card_id) + * .then(({ id, object, deleted }) => { + * console.log(id); + * }); + * - lang: Shell + * label: cURL + * source: | + * curl --location --request DELETE 'https://medusa-url.com/admin/gift-cards/{id}' \ + * --header 'Authorization: Bearer {api_token}' + * security: + * - api_token: [] + * - cookie_auth: [] * tags: * - Gift Card * responses: @@ -28,6 +47,18 @@ import { EntityManager } from "typeorm" * type: boolean * description: Whether the gift card was deleted successfully or not. * default: true + * "400": + * $ref: "#/components/responses/400_error" + * "401": + * $ref: "#/components/responses/unauthorized" + * "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 { id } = req.params diff --git a/packages/medusa/src/api/routes/admin/gift-cards/get-gift-card.ts b/packages/medusa/src/api/routes/admin/gift-cards/get-gift-card.ts index aed27a2b0d..c1366fd520 100644 --- a/packages/medusa/src/api/routes/admin/gift-cards/get-gift-card.ts +++ b/packages/medusa/src/api/routes/admin/gift-cards/get-gift-card.ts @@ -8,6 +8,25 @@ import { defaultAdminGiftCardFields, defaultAdminGiftCardRelations } from "./" * x-authenticated: true * parameters: * - (path) id=* {string} The ID of the Gift Card. + * x-codeSamples: + * - lang: JavaScript + * label: JS Client + * source: | + * import Medusa from "@medusajs/medusa-js" + * const medusa = new Medusa({ baseUrl: MEDUSA_BACKEND_URL, maxRetries: 3 }) + * // must be previously logged in or use api token + * medusa.admin.giftCards.retrieve(gift_card_id) + * .then(({ gift_card }) => { + * console.log(gift_card.id); + * }); + * - lang: Shell + * label: cURL + * source: | + * curl --location --request GET 'https://medusa-url.com/admin/gift-cards/{id}' \ + * --header 'Authorization: Bearer {api_token}' + * security: + * - api_token: [] + * - cookie_auth: [] * tags: * - Gift Card * responses: @@ -19,6 +38,18 @@ import { defaultAdminGiftCardFields, defaultAdminGiftCardRelations } from "./" * properties: * gift_card: * $ref: "#/components/schemas/gift_card" + * "400": + * $ref: "#/components/responses/400_error" + * "401": + * $ref: "#/components/responses/unauthorized" + * "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 { id } = req.params diff --git a/packages/medusa/src/api/routes/admin/gift-cards/list-gift-cards.ts b/packages/medusa/src/api/routes/admin/gift-cards/list-gift-cards.ts index fb1e373337..b5ab702437 100644 --- a/packages/medusa/src/api/routes/admin/gift-cards/list-gift-cards.ts +++ b/packages/medusa/src/api/routes/admin/gift-cards/list-gift-cards.ts @@ -16,6 +16,25 @@ import { isDefined } from "../../../../utils" * - (query) offset=0 {number} The number of items to skip before the results. * - (query) limit=50 {number} Limit the number of items returned. * - (query) q {string} a search term to search by code or display ID + * x-codeSamples: + * - lang: JavaScript + * label: JS Client + * source: | + * import Medusa from "@medusajs/medusa-js" + * const medusa = new Medusa({ baseUrl: MEDUSA_BACKEND_URL, maxRetries: 3 }) + * // must be previously logged in or use api token + * medusa.admin.giftCards.list() + * .then(({ gift_cards, limit, offset, count }) => { + * console.log(gift_cards.length); + * }); + * - lang: Shell + * label: cURL + * source: | + * curl --location --request GET 'https://medusa-url.com/admin/gift-cards' \ + * --header 'Authorization: Bearer {api_token}' + * security: + * - api_token: [] + * - cookie_auth: [] * tags: * - Gift Card * responses: @@ -38,6 +57,18 @@ import { isDefined } from "../../../../utils" * limit: * type: integer * description: The number of items per page + * "400": + * $ref: "#/components/responses/400_error" + * "401": + * $ref: "#/components/responses/unauthorized" + * "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 validated = await validator(AdminGetGiftCardsParams, req.query) diff --git a/packages/medusa/src/api/routes/admin/gift-cards/update-gift-card.ts b/packages/medusa/src/api/routes/admin/gift-cards/update-gift-card.ts index 9ba5815d52..a9156346f3 100644 --- a/packages/medusa/src/api/routes/admin/gift-cards/update-gift-card.ts +++ b/packages/medusa/src/api/routes/admin/gift-cards/update-gift-card.ts @@ -35,6 +35,31 @@ import { EntityManager } from "typeorm" * metadata: * description: An optional set of key-value pairs to hold additional information. * type: object + * x-codeSamples: + * - lang: JavaScript + * label: JS Client + * source: | + * import Medusa from "@medusajs/medusa-js" + * const medusa = new Medusa({ baseUrl: MEDUSA_BACKEND_URL, maxRetries: 3 }) + * // must be previously logged in or use api token + * medusa.admin.giftCards.update(gift_card_id, { + * region_id + * }) + * .then(({ gift_card }) => { + * console.log(gift_card.id); + * }); + * - lang: Shell + * label: cURL + * source: | + * curl --location --request POST 'https://medusa-url.com/admin/gift-cards/{id}' \ + * --header 'Authorization: Bearer {api_token}' \ + * --header 'Content-Type: application/json' \ + * --data-raw '{ + * "region_id": "{region_id}" + * }' + * security: + * - api_token: [] + * - cookie_auth: [] * tags: * - Gift Card * responses: @@ -46,6 +71,18 @@ import { EntityManager } from "typeorm" * properties: * gift_card: * $ref: "#/components/schemas/gift_card" + * "400": + * $ref: "#/components/responses/400_error" + * "401": + * $ref: "#/components/responses/unauthorized" + * "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 { id } = req.params diff --git a/packages/medusa/src/api/routes/admin/invites/accept-invite.ts b/packages/medusa/src/api/routes/admin/invites/accept-invite.ts index 6f21d6d3ed..a00ea52dbd 100644 --- a/packages/medusa/src/api/routes/admin/invites/accept-invite.ts +++ b/packages/medusa/src/api/routes/admin/invites/accept-invite.ts @@ -39,11 +39,61 @@ import { EntityManager } from "typeorm" * description: The desired password for the User * type: string * format: password + * x-codeSamples: + * - lang: JavaScript + * label: JS Client + * source: | + * import Medusa from "@medusajs/medusa-js" + * const medusa = new Medusa({ baseUrl: MEDUSA_BACKEND_URL, maxRetries: 3 }) + * // must be previously logged in or use api token + * medusa.admin.invites.accept({ + * token, + * user: { + * first_name: 'Brigitte', + * last_name: 'Collier', + * password: 'supersecret' + * } + * }) + * .then(() => { + * // successful + * }) + * .catch(() => { + * // an error occurred + * }); + * - lang: Shell + * label: cURL + * source: | + * curl --location --request POST 'https://medusa-url.com/admin/invites/accept' \ + * --header 'Authorization: Bearer {api_token}' \ + * --header 'Content-Type: application/json' \ + * --data-raw '{ + * "token": "{token}", + * "user": { + * "first_name": "Brigitte", + * "last_name": "Collier", + * "password": "supersecret" + * } + * }' + * security: + * - api_token: [] + * - cookie_auth: [] * tags: * - Invite * responses: * 200: * description: OK + * "400": + * $ref: "#/components/responses/400_error" + * "401": + * $ref: "#/components/responses/unauthorized" + * "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 validated = await validator(AdminPostInvitesInviteAcceptReq, req.body) diff --git a/packages/medusa/src/api/routes/admin/invites/create-invite.ts b/packages/medusa/src/api/routes/admin/invites/create-invite.ts index 6343f4e293..1d8e6aee59 100644 --- a/packages/medusa/src/api/routes/admin/invites/create-invite.ts +++ b/packages/medusa/src/api/routes/admin/invites/create-invite.ts @@ -27,11 +27,53 @@ import { EntityManager } from "typeorm" * description: "The role of the user to be created." * type: string * enum: [admin, member, developer] + * x-codeSamples: + * - lang: JavaScript + * label: JS Client + * source: | + * import Medusa from "@medusajs/medusa-js" + * const medusa = new Medusa({ baseUrl: MEDUSA_BACKEND_URL, maxRetries: 3 }) + * // must be previously logged in or use api token + * medusa.admin.invites.create({ + * user: "user@example.com", + * role: "admin" + * }) + * .then(() => { + * // successful + * }) + * .catch(() => { + * // an error occurred + * }); + * - lang: Shell + * label: cURL + * source: | + * curl --location --request POST 'https://medusa-url.com/admin/invites' \ + * --header 'Authorization: Bearer {api_token}' \ + * --header 'Content-Type: application/json' \ + * --data-raw '{ + * "user": "user@example.com", + * "role": "admin" + * }' + * security: + * - api_token: [] + * - cookie_auth: [] * tags: * - Invite * responses: * 200: * description: OK + * "400": + * $ref: "#/components/responses/400_error" + * "401": + * $ref: "#/components/responses/unauthorized" + * "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 validated = await validator(AdminPostInvitesReq, req.body) diff --git a/packages/medusa/src/api/routes/admin/invites/delete-invite.ts b/packages/medusa/src/api/routes/admin/invites/delete-invite.ts index 17e527a998..c53a1026cf 100644 --- a/packages/medusa/src/api/routes/admin/invites/delete-invite.ts +++ b/packages/medusa/src/api/routes/admin/invites/delete-invite.ts @@ -9,6 +9,25 @@ import InviteService from "../../../../services/invite" * x-authenticated: true * parameters: * - (path) invite_id=* {string} The ID of the Invite + * x-codeSamples: + * - lang: JavaScript + * label: JS Client + * source: | + * import Medusa from "@medusajs/medusa-js" + * const medusa = new Medusa({ baseUrl: MEDUSA_BACKEND_URL, maxRetries: 3 }) + * // must be previously logged in or use api token + * medusa.admin.invites.delete(invite_id) + * .then(({ id, object, deleted }) => { + * console.log(id); + * }); + * - lang: Shell + * label: cURL + * source: | + * curl --location --request DELETE 'https://medusa-url.com/admin/invites/{invite_id}' \ + * --header 'Authorization: Bearer {api_token}' + * security: + * - api_token: [] + * - cookie_auth: [] * tags: * - Invite * responses: @@ -29,6 +48,18 @@ import InviteService from "../../../../services/invite" * type: boolean * description: Whether or not the Invite was deleted. * default: true + * "400": + * $ref: "#/components/responses/400_error" + * "401": + * $ref: "#/components/responses/unauthorized" + * "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 { invite_id } = req.params diff --git a/packages/medusa/src/api/routes/admin/invites/list-invites.ts b/packages/medusa/src/api/routes/admin/invites/list-invites.ts index 2d9182219a..a859fa3923 100644 --- a/packages/medusa/src/api/routes/admin/invites/list-invites.ts +++ b/packages/medusa/src/api/routes/admin/invites/list-invites.ts @@ -6,6 +6,25 @@ import InviteService from "../../../../services/invite" * summary: "Lists all Invites" * description: "Lists all Invites" * x-authenticated: true + * x-codeSamples: + * - lang: JavaScript + * label: JS Client + * source: | + * import Medusa from "@medusajs/medusa-js" + * const medusa = new Medusa({ baseUrl: MEDUSA_BACKEND_URL, maxRetries: 3 }) + * // must be previously logged in or use api token + * medusa.admin.invites.list() + * .then(({ invites }) => { + * console.log(invites.length); + * }); + * - lang: Shell + * label: cURL + * source: | + * curl --location --request GET 'https://medusa-url.com/admin/invites' \ + * --header 'Authorization: Bearer {api_token}' + * security: + * - api_token: [] + * - cookie_auth: [] * tags: * - Invite * responses: @@ -19,6 +38,18 @@ import InviteService from "../../../../services/invite" * type: array * items: * $ref: "#/components/schemas/invite" + * "400": + * $ref: "#/components/responses/400_error" + * "401": + * $ref: "#/components/responses/unauthorized" + * "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 inviteService: InviteService = req.scope.resolve("inviteService") diff --git a/packages/medusa/src/api/routes/admin/invites/resend-invite.ts b/packages/medusa/src/api/routes/admin/invites/resend-invite.ts index 0dd0798008..3a52f6e213 100644 --- a/packages/medusa/src/api/routes/admin/invites/resend-invite.ts +++ b/packages/medusa/src/api/routes/admin/invites/resend-invite.ts @@ -9,11 +9,45 @@ import { EntityManager } from "typeorm" * x-authenticated: true * parameters: * - (path) invite_id=* {string} The ID of the Invite + * x-codeSamples: + * - lang: JavaScript + * label: JS Client + * source: | + * import Medusa from "@medusajs/medusa-js" + * const medusa = new Medusa({ baseUrl: MEDUSA_BACKEND_URL, maxRetries: 3 }) + * // must be previously logged in or use api token + * medusa.admin.invites.resend(invite_id) + * .then(() => { + * // successful + * }) + * .catch(() => { + * // an error occurred + * }); + * - lang: Shell + * label: cURL + * source: | + * curl --location --request POST 'https://medusa-url.com/admin/invites/{invite_id}/resend' \ + * --header 'Authorization: Bearer {api_token}' + * security: + * - api_token: [] + * - cookie_auth: [] * tags: * - Invite * responses: * 200: * description: OK + * "400": + * $ref: "#/components/responses/400_error" + * "401": + * $ref: "#/components/responses/unauthorized" + * "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 { invite_id } = req.params diff --git a/packages/medusa/src/api/routes/admin/notes/create-note.ts b/packages/medusa/src/api/routes/admin/notes/create-note.ts index df9f8dad4b..bb9bbf899f 100644 --- a/packages/medusa/src/api/routes/admin/notes/create-note.ts +++ b/packages/medusa/src/api/routes/admin/notes/create-note.ts @@ -28,6 +28,35 @@ import { EntityManager } from "typeorm" * value: * type: string * description: The content of the Note to create. + * x-codeSamples: + * - lang: JavaScript + * label: JS Client + * source: | + * import Medusa from "@medusajs/medusa-js" + * const medusa = new Medusa({ baseUrl: MEDUSA_BACKEND_URL, maxRetries: 3 }) + * // must be previously logged in or use api token + * medusa.admin.notes.create({ + * resource_id, + * resource_type: 'order', + * value: 'We delivered this order' + * }) + * .then(({ note }) => { + * console.log(note.id); + * }); + * - lang: Shell + * label: cURL + * source: | + * curl --location --request POST 'https://medusa-url.com/admin/notes' \ + * --header 'Authorization: Bearer {api_token}' \ + * --header 'Content-Type: application/json' \ + * --data-raw '{ + * "resource_id": "{resource_id}", + * "resource_type": "order", + * "value": "We delivered this order" + * }' + * security: + * - api_token: [] + * - cookie_auth: [] * tags: * - Note * responses: @@ -39,6 +68,18 @@ import { EntityManager } from "typeorm" * properties: * note: * $ref: "#/components/schemas/note" + * "400": + * $ref: "#/components/responses/400_error" + * "401": + * $ref: "#/components/responses/unauthorized" + * "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) => { diff --git a/packages/medusa/src/api/routes/admin/notes/delete-note.ts b/packages/medusa/src/api/routes/admin/notes/delete-note.ts index 26db70f0d3..f427060d3b 100644 --- a/packages/medusa/src/api/routes/admin/notes/delete-note.ts +++ b/packages/medusa/src/api/routes/admin/notes/delete-note.ts @@ -9,6 +9,25 @@ import NoteService from "../../../../services/note" * x-authenticated: true * parameters: * - (path) id=* {string} The ID of the Note to delete. + * x-codeSamples: + * - lang: JavaScript + * label: JS Client + * source: | + * import Medusa from "@medusajs/medusa-js" + * const medusa = new Medusa({ baseUrl: MEDUSA_BACKEND_URL, maxRetries: 3 }) + * // must be previously logged in or use api token + * medusa.admin.notes.delete(note_id) + * .then(({ id, object, deleted }) => { + * console.log(id); + * }); + * - lang: Shell + * label: cURL + * source: | + * curl --location --request DELETE 'https://medusa-url.com/admin/notes/{id}' \ + * --header 'Authorization: Bearer {api_token}' + * security: + * - api_token: [] + * - cookie_auth: [] * tags: * - Note * responses: @@ -29,6 +48,18 @@ import NoteService from "../../../../services/note" * type: boolean * description: Whether or not the Note was deleted. * default: true + * "400": + * $ref: "#/components/responses/400_error" + * "401": + * $ref: "#/components/responses/unauthorized" + * "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 { id } = req.params diff --git a/packages/medusa/src/api/routes/admin/notes/get-note.ts b/packages/medusa/src/api/routes/admin/notes/get-note.ts index bbdc610411..4df52b5f9f 100644 --- a/packages/medusa/src/api/routes/admin/notes/get-note.ts +++ b/packages/medusa/src/api/routes/admin/notes/get-note.ts @@ -8,6 +8,25 @@ import NoteService from "../../../../services/note" * x-authenticated: true * parameters: * - (path) id=* {string} The ID of the note to retrieve. + * x-codeSamples: + * - lang: JavaScript + * label: JS Client + * source: | + * import Medusa from "@medusajs/medusa-js" + * const medusa = new Medusa({ baseUrl: MEDUSA_BACKEND_URL, maxRetries: 3 }) + * // must be previously logged in or use api token + * medusa.admin.notes.retrieve(note_id) + * .then(({ note }) => { + * console.log(note.id); + * }); + * - lang: Shell + * label: cURL + * source: | + * curl --location --request GET 'https://medusa-url.com/admin/notes/{id}' \ + * --header 'Authorization: Bearer {api_token}' + * security: + * - api_token: [] + * - cookie_auth: [] * tags: * - Note * responses: @@ -19,6 +38,18 @@ import NoteService from "../../../../services/note" * properties: * note: * $ref: "#/components/schemas/note" + * "400": + * $ref: "#/components/responses/400_error" + * "401": + * $ref: "#/components/responses/unauthorized" + * "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 { id } = req.params diff --git a/packages/medusa/src/api/routes/admin/notes/list-notes.ts b/packages/medusa/src/api/routes/admin/notes/list-notes.ts index 24990453be..92d8a0c9e3 100644 --- a/packages/medusa/src/api/routes/admin/notes/list-notes.ts +++ b/packages/medusa/src/api/routes/admin/notes/list-notes.ts @@ -15,6 +15,25 @@ import { validator } from "../../../../utils/validator" * - (query) limit=50 {number} The number of notes to get * - (query) offset=0 {number} The offset at which to get notes * - (query) resource_id {string} The ID which the notes belongs to + * x-codeSamples: + * - lang: JavaScript + * label: JS Client + * source: | + * import Medusa from "@medusajs/medusa-js" + * const medusa = new Medusa({ baseUrl: MEDUSA_BACKEND_URL, maxRetries: 3 }) + * // must be previously logged in or use api token + * medusa.admin.notes.list() + * .then(({ notes, limit, offset, count }) => { + * console.log(notes.length); + * }); + * - lang: Shell + * label: cURL + * source: | + * curl --location --request GET 'https://medusa-url.com/admin/notes' \ + * --header 'Authorization: Bearer {api_token}' + * security: + * - api_token: [] + * - cookie_auth: [] * tags: * - Note * responses: @@ -37,6 +56,18 @@ import { validator } from "../../../../utils/validator" * limit: * type: integer * description: The number of items per page + * "400": + * $ref: "#/components/responses/400_error" + * "401": + * $ref: "#/components/responses/unauthorized" + * "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 validated = await validator(AdminGetNotesParams, req.query) diff --git a/packages/medusa/src/api/routes/admin/notes/update-note.ts b/packages/medusa/src/api/routes/admin/notes/update-note.ts index c3f33379c0..12befc7937 100644 --- a/packages/medusa/src/api/routes/admin/notes/update-note.ts +++ b/packages/medusa/src/api/routes/admin/notes/update-note.ts @@ -21,6 +21,31 @@ import { EntityManager } from "typeorm" * value: * type: string * description: The updated description of the Note. + * x-codeSamples: + * - lang: JavaScript + * label: JS Client + * source: | + * import Medusa from "@medusajs/medusa-js" + * const medusa = new Medusa({ baseUrl: MEDUSA_BACKEND_URL, maxRetries: 3 }) + * // must be previously logged in or use api token + * medusa.admin.notes.update(note_id, { + * value: 'We delivered this order' + * }) + * .then(({ note }) => { + * console.log(note.id); + * }); + * - lang: Shell + * label: cURL + * source: | + * curl --location --request POST 'https://medusa-url.com/admin/notes/{id}' \ + * --header 'Authorization: Bearer {api_token}' \ + * --header 'Content-Type: application/json' \ + * --data-raw '{ + * "value": "We delivered this order" + * }' + * security: + * - api_token: [] + * - cookie_auth: [] * tags: * - Note * responses: @@ -32,7 +57,18 @@ import { EntityManager } from "typeorm" * properties: * note: * $ref: "#/components/schemas/note" - * + * "400": + * $ref: "#/components/responses/400_error" + * "401": + * $ref: "#/components/responses/unauthorized" + * "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 { id } = req.params diff --git a/packages/medusa/src/api/routes/admin/notifications/list-notifications.ts b/packages/medusa/src/api/routes/admin/notifications/list-notifications.ts index c03cc3e378..b922fa779d 100644 --- a/packages/medusa/src/api/routes/admin/notifications/list-notifications.ts +++ b/packages/medusa/src/api/routes/admin/notifications/list-notifications.ts @@ -27,6 +27,25 @@ import { validator } from "../../../../utils/validator" * - (query) resource_id {string} The ID of the resource that the Notification refers to. * - (query) to {string} The address that the Notification was sent to. This will usually be an email address, but represent other addresses such as a chat bot user id * - (query) include_resends {string} A boolean indicating whether the result set should include resent notifications or not + * x-codeSamples: + * - lang: JavaScript + * label: JS Client + * source: | + * import Medusa from "@medusajs/medusa-js" + * const medusa = new Medusa({ baseUrl: MEDUSA_BACKEND_URL, maxRetries: 3 }) + * // must be previously logged in or use api token + * medusa.admin.notifications.list() + * .then(({ notifications }) => { + * console.log(notifications.length); + * }); + * - lang: Shell + * label: cURL + * source: | + * curl --location --request GET 'https://medusa-url.com/admin/notifications' \ + * --header 'Authorization: Bearer {api_token}' + * security: + * - api_token: [] + * - cookie_auth: [] * tags: * - Notification * responses: @@ -40,6 +59,18 @@ import { validator } from "../../../../utils/validator" * type: array * items: * $ref: "#/components/schemas/notification" + * "400": + * $ref: "#/components/responses/400_error" + * "401": + * $ref: "#/components/responses/unauthorized" + * "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 notificationService: NotificationService = req.scope.resolve( diff --git a/packages/medusa/src/api/routes/admin/notifications/resend-notification.ts b/packages/medusa/src/api/routes/admin/notifications/resend-notification.ts index 6cc8cf9f87..fb89235db3 100644 --- a/packages/medusa/src/api/routes/admin/notifications/resend-notification.ts +++ b/packages/medusa/src/api/routes/admin/notifications/resend-notification.ts @@ -26,6 +26,25 @@ import { validator } from "../../../../utils/validator" * to: * description: "A new address or user identifier that the Notification should be sent to" * type: string + * x-codeSamples: + * - lang: JavaScript + * label: JS Client + * source: | + * import Medusa from "@medusajs/medusa-js" + * const medusa = new Medusa({ baseUrl: MEDUSA_BACKEND_URL, maxRetries: 3 }) + * // must be previously logged in or use api token + * medusa.admin.notifications.resend(notification_id) + * .then(({ notification }) => { + * console.log(notification.id); + * }); + * - lang: Shell + * label: cURL + * source: | + * curl --location --request POST 'https://medusa-url.com/admin/notifications/{id}/resend' \ + * --header 'Authorization: Bearer {api_token}' + * security: + * - api_token: [] + * - cookie_auth: [] * tags: * - Notification * responses: @@ -37,6 +56,18 @@ import { validator } from "../../../../utils/validator" * properties: * notification: * $ref: "#/components/schemas/notification" + * "400": + * $ref: "#/components/responses/400_error" + * "401": + * $ref: "#/components/responses/unauthorized" + * "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 { id } = req.params diff --git a/packages/medusa/src/api/routes/admin/orders/add-shipping-method.ts b/packages/medusa/src/api/routes/admin/orders/add-shipping-method.ts index e73da51d8f..4e42a8b22f 100644 --- a/packages/medusa/src/api/routes/admin/orders/add-shipping-method.ts +++ b/packages/medusa/src/api/routes/admin/orders/add-shipping-method.ts @@ -22,6 +22,33 @@ import { EntityManager } from "typeorm" * - (body) price=* {integer} The price (excluding VAT) that should be charged for the Shipping Method * - (body) option_id=* {string} The ID of the Shipping Option to create the Shipping Method from. * - (body) data {object} The data required for the Shipping Option to create a Shipping Method. This will depend on the Fulfillment Provider. + * x-codeSamples: + * - lang: JavaScript + * label: JS Client + * source: | + * import Medusa from "@medusajs/medusa-js" + * const medusa = new Medusa({ baseUrl: MEDUSA_BACKEND_URL, maxRetries: 3 }) + * // must be previously logged in or use api token + * medusa.admin.orders.addShippingMethod(order_id, { + * price: 1000, + * option_id + * }) + * .then(({ order }) => { + * console.log(order.id); + * }); + * - lang: Shell + * label: cURL + * source: | + * curl --location --request POST 'https://medusa-url.com/admin/orders/{id}/shipping-methods' \ + * --header 'Authorization: Bearer {api_token}' \ + * --header 'Content-Type: application/json' \ + * --data-raw '{ + * "price": 1000, + * "option_id": "{option_id}" + * }' + * security: + * - api_token: [] + * - cookie_auth: [] * tags: * - Order * responses: @@ -33,6 +60,18 @@ import { EntityManager } from "typeorm" * properties: * order: * $ref: "#/components/schemas/order" + * "400": + * $ref: "#/components/responses/400_error" + * "401": + * $ref: "#/components/responses/unauthorized" + * "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 { id } = req.params diff --git a/packages/medusa/src/api/routes/admin/orders/archive-order.ts b/packages/medusa/src/api/routes/admin/orders/archive-order.ts index 021e574bce..7070647323 100644 --- a/packages/medusa/src/api/routes/admin/orders/archive-order.ts +++ b/packages/medusa/src/api/routes/admin/orders/archive-order.ts @@ -9,6 +9,25 @@ import { EntityManager } from "typeorm" * x-authenticated: true * parameters: * - (path) id=* {string} The ID of the Order. + * x-codeSamples: + * - lang: JavaScript + * label: JS Client + * source: | + * import Medusa from "@medusajs/medusa-js" + * const medusa = new Medusa({ baseUrl: MEDUSA_BACKEND_URL, maxRetries: 3 }) + * // must be previously logged in or use api token + * medusa.admin.orders.archive(order_id) + * .then(({ order }) => { + * console.log(order.id); + * }); + * - lang: Shell + * label: cURL + * source: | + * curl --location --request POST 'https://medusa-url.com/admin/orders/{id}/archive' \ + * --header 'Authorization: Bearer {api_token}' + * security: + * - api_token: [] + * - cookie_auth: [] * tags: * - Order * responses: @@ -20,6 +39,18 @@ import { EntityManager } from "typeorm" * properties: * order: * $ref: "#/components/schemas/order" + * "400": + * $ref: "#/components/responses/400_error" + * "401": + * $ref: "#/components/responses/unauthorized" + * "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 { id } = req.params diff --git a/packages/medusa/src/api/routes/admin/orders/cancel-claim.ts b/packages/medusa/src/api/routes/admin/orders/cancel-claim.ts index 87f6d278de..0c34e6ee8a 100644 --- a/packages/medusa/src/api/routes/admin/orders/cancel-claim.ts +++ b/packages/medusa/src/api/routes/admin/orders/cancel-claim.ts @@ -13,6 +13,25 @@ import { MedusaError } from "medusa-core-utils" * parameters: * - (path) id=* {string} The ID of the Order. * - (path) claim_id=* {string} The ID of the Claim. + * x-codeSamples: + * - lang: JavaScript + * label: JS Client + * source: | + * import Medusa from "@medusajs/medusa-js" + * const medusa = new Medusa({ baseUrl: MEDUSA_BACKEND_URL, maxRetries: 3 }) + * // must be previously logged in or use api token + * medusa.admin.orders.cancelClaim(order_id, claim_id) + * .then(({ order }) => { + * console.log(order.id); + * }); + * - lang: Shell + * label: cURL + * source: | + * curl --location --request POST 'https://medusa-url.com/admin/orders/{id}/claims/{claim_id}/cancel' \ + * --header 'Authorization: Bearer {api_token}' + * security: + * - api_token: [] + * - cookie_auth: [] * tags: * - Claim * responses: @@ -24,6 +43,18 @@ import { MedusaError } from "medusa-core-utils" * properties: * order: * $ref: "#/components/schemas/order" + * "400": + * $ref: "#/components/responses/400_error" + * "401": + * $ref: "#/components/responses/unauthorized" + * "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 { id, claim_id } = req.params diff --git a/packages/medusa/src/api/routes/admin/orders/cancel-fulfillment-claim.ts b/packages/medusa/src/api/routes/admin/orders/cancel-fulfillment-claim.ts index 437710121f..bd465d5fee 100644 --- a/packages/medusa/src/api/routes/admin/orders/cancel-fulfillment-claim.ts +++ b/packages/medusa/src/api/routes/admin/orders/cancel-fulfillment-claim.ts @@ -18,6 +18,25 @@ import { MedusaError } from "medusa-core-utils" * - (path) id=* {string} The ID of the Order which the Claim relates to. * - (path) claim_id=* {string} The ID of the Claim which the Fulfillment relates to. * - (path) fulfillment_id=* {string} The ID of the Fulfillment. + * x-codeSamples: + * - lang: JavaScript + * label: JS Client + * source: | + * import Medusa from "@medusajs/medusa-js" + * const medusa = new Medusa({ baseUrl: MEDUSA_BACKEND_URL, maxRetries: 3 }) + * // must be previously logged in or use api token + * medusa.admin.orders.cancelClaimFulfillment(order_id, claim_id, fulfillment_id) + * .then(({ order }) => { + * console.log(order.id); + * }); + * - lang: Shell + * label: cURL + * source: | + * curl --location --request POST 'https://medusa-url.com/admin/orders/{id}/claims/{claim_id}/fulfillments/{fulfillment_id}/cancel' \ + * --header 'Authorization: Bearer {api_token}' + * security: + * - api_token: [] + * - cookie_auth: [] * tags: * - Fulfillment * responses: @@ -29,6 +48,18 @@ import { MedusaError } from "medusa-core-utils" * properties: * order: * $ref: "#/components/schemas/order" + * "400": + * $ref: "#/components/responses/400_error" + * "401": + * $ref: "#/components/responses/unauthorized" + * "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 { id, claim_id, fulfillment_id } = req.params diff --git a/packages/medusa/src/api/routes/admin/orders/cancel-fulfillment-swap.ts b/packages/medusa/src/api/routes/admin/orders/cancel-fulfillment-swap.ts index 2b975a9d06..18d723943e 100644 --- a/packages/medusa/src/api/routes/admin/orders/cancel-fulfillment-swap.ts +++ b/packages/medusa/src/api/routes/admin/orders/cancel-fulfillment-swap.ts @@ -18,6 +18,25 @@ import { MedusaError } from "medusa-core-utils" * - (path) id=* {string} The ID of the Order which the Swap relates to. * - (path) swap_id=* {string} The ID of the Swap which the Fulfillment relates to. * - (path) fulfillment_id=* {string} The ID of the Fulfillment. + * x-codeSamples: + * - lang: JavaScript + * label: JS Client + * source: | + * import Medusa from "@medusajs/medusa-js" + * const medusa = new Medusa({ baseUrl: MEDUSA_BACKEND_URL, maxRetries: 3 }) + * // must be previously logged in or use api token + * medusa.admin.orders.cancelSwapFulfillment(order_id, swap_id, fulfillment_id) + * .then(({ order }) => { + * console.log(order.id); + * }); + * - lang: Shell + * label: cURL + * source: | + * curl --location --request POST 'https://medusa-url.com/admin/orders/{id}/swaps/{swap_id}/fulfillments/{fulfillment_id}/cancel' \ + * --header 'Authorization: Bearer {api_token}' + * security: + * - api_token: [] + * - cookie_auth: [] * tags: * - Fulfillment * responses: @@ -29,6 +48,18 @@ import { MedusaError } from "medusa-core-utils" * properties: * order: * $ref: "#/components/schemas/order" + * "400": + * $ref: "#/components/responses/400_error" + * "401": + * $ref: "#/components/responses/unauthorized" + * "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 { id, swap_id, fulfillment_id } = req.params diff --git a/packages/medusa/src/api/routes/admin/orders/cancel-fulfillment.ts b/packages/medusa/src/api/routes/admin/orders/cancel-fulfillment.ts index 5e1e26e334..5f34a01f21 100644 --- a/packages/medusa/src/api/routes/admin/orders/cancel-fulfillment.ts +++ b/packages/medusa/src/api/routes/admin/orders/cancel-fulfillment.ts @@ -13,6 +13,25 @@ import { MedusaError } from "medusa-core-utils" * parameters: * - (path) id=* {string} The ID of the Order which the Fulfillment relates to. * - (path) fulfillment_id=* {string} The ID of the Fulfillment + * x-codeSamples: + * - lang: JavaScript + * label: JS Client + * source: | + * import Medusa from "@medusajs/medusa-js" + * const medusa = new Medusa({ baseUrl: MEDUSA_BACKEND_URL, maxRetries: 3 }) + * // must be previously logged in or use api token + * medusa.admin.orders.cancelFulfillment(order_id, fulfillment_id) + * .then(({ order }) => { + * console.log(order.id); + * }); + * - lang: Shell + * label: cURL + * source: | + * curl --location --request POST 'https://medusa-url.com/admin/orders/{id}/fulfillments/{fulfillment_id}/cancel' \ + * --header 'Authorization: Bearer {api_token}' + * security: + * - api_token: [] + * - cookie_auth: [] * tags: * - Fulfillment * responses: @@ -24,6 +43,18 @@ import { MedusaError } from "medusa-core-utils" * properties: * order: * $ref: "#/components/schemas/order" + * "400": + * $ref: "#/components/responses/400_error" + * "401": + * $ref: "#/components/responses/unauthorized" + * "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 { id, fulfillment_id } = req.params diff --git a/packages/medusa/src/api/routes/admin/orders/cancel-order.ts b/packages/medusa/src/api/routes/admin/orders/cancel-order.ts index 8f64ffda99..c60966521f 100644 --- a/packages/medusa/src/api/routes/admin/orders/cancel-order.ts +++ b/packages/medusa/src/api/routes/admin/orders/cancel-order.ts @@ -11,6 +11,25 @@ import { EntityManager } from "typeorm" * x-authenticated: true * parameters: * - (path) id=* {string} The ID of the Order. + * x-codeSamples: + * - lang: JavaScript + * label: JS Client + * source: | + * import Medusa from "@medusajs/medusa-js" + * const medusa = new Medusa({ baseUrl: MEDUSA_BACKEND_URL, maxRetries: 3 }) + * // must be previously logged in or use api token + * medusa.admin.orders.cancel(order_id) + * .then(({ order }) => { + * console.log(order.id); + * }); + * - lang: Shell + * label: cURL + * source: | + * curl --location --request POST 'https://medusa-url.com/admin/orders/{id}/cancel' \ + * --header 'Authorization: Bearer {api_token}' + * security: + * - api_token: [] + * - cookie_auth: [] * tags: * - Order * responses: @@ -22,6 +41,18 @@ import { EntityManager } from "typeorm" * properties: * order: * $ref: "#/components/schemas/order" + * "400": + * $ref: "#/components/responses/400_error" + * "401": + * $ref: "#/components/responses/unauthorized" + * "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 { id } = req.params diff --git a/packages/medusa/src/api/routes/admin/orders/cancel-swap.ts b/packages/medusa/src/api/routes/admin/orders/cancel-swap.ts index 97c1061313..4563dd90c4 100644 --- a/packages/medusa/src/api/routes/admin/orders/cancel-swap.ts +++ b/packages/medusa/src/api/routes/admin/orders/cancel-swap.ts @@ -13,6 +13,25 @@ import { MedusaError } from "medusa-core-utils" * parameters: * - (path) id=* {string} The ID of the Order. * - (path) swap_id=* {string} The ID of the Swap. + * x-codeSamples: + * - lang: JavaScript + * label: JS Client + * source: | + * import Medusa from "@medusajs/medusa-js" + * const medusa = new Medusa({ baseUrl: MEDUSA_BACKEND_URL, maxRetries: 3 }) + * // must be previously logged in or use api token + * medusa.admin.orders.cancelSwap(order_id, swap_id) + * .then(({ order }) => { + * console.log(order.id); + * }); + * - lang: Shell + * label: cURL + * source: | + * curl --location --request POST 'https://medusa-url.com/admin/orders/{order_id}/swaps/{swap_id}/cancel' \ + * --header 'Authorization: Bearer {api_token}' + * security: + * - api_token: [] + * - cookie_auth: [] * tags: * - Swap * responses: @@ -24,6 +43,18 @@ import { MedusaError } from "medusa-core-utils" * properties: * order: * $ref: "#/components/schemas/order" + * "400": + * $ref: "#/components/responses/400_error" + * "401": + * $ref: "#/components/responses/unauthorized" + * "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 { id, swap_id } = req.params diff --git a/packages/medusa/src/api/routes/admin/orders/capture-payment.ts b/packages/medusa/src/api/routes/admin/orders/capture-payment.ts index ed4cf6d838..8678ce866d 100644 --- a/packages/medusa/src/api/routes/admin/orders/capture-payment.ts +++ b/packages/medusa/src/api/routes/admin/orders/capture-payment.ts @@ -11,6 +11,25 @@ import { EntityManager } from "typeorm" * x-authenticated: true * parameters: * - (path) id=* {string} The ID of the Order. + * x-codeSamples: + * - lang: JavaScript + * label: JS Client + * source: | + * import Medusa from "@medusajs/medusa-js" + * const medusa = new Medusa({ baseUrl: MEDUSA_BACKEND_URL, maxRetries: 3 }) + * // must be previously logged in or use api token + * medusa.admin.orders.capturePayment(order_id) + * .then(({ order }) => { + * console.log(order.id); + * }); + * - lang: Shell + * label: cURL + * source: | + * curl --location --request POST 'https://medusa-url.com/admin/orders/{id}/capture' \ + * --header 'Authorization: Bearer {api_token}' + * security: + * - api_token: [] + * - cookie_auth: [] * tags: * - Order * responses: @@ -22,6 +41,18 @@ import { EntityManager } from "typeorm" * properties: * order: * $ref: "#/components/schemas/order" + * "400": + * $ref: "#/components/responses/400_error" + * "401": + * $ref: "#/components/responses/unauthorized" + * "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 { id } = req.params diff --git a/packages/medusa/src/api/routes/admin/orders/complete-order.ts b/packages/medusa/src/api/routes/admin/orders/complete-order.ts index 6e1fdb7555..e69d7e37f8 100644 --- a/packages/medusa/src/api/routes/admin/orders/complete-order.ts +++ b/packages/medusa/src/api/routes/admin/orders/complete-order.ts @@ -9,6 +9,25 @@ import { EntityManager } from "typeorm" * x-authenticated: true * parameters: * - (path) id=* {string} The ID of the Order. + * x-codeSamples: + * - lang: JavaScript + * label: JS Client + * source: | + * import Medusa from "@medusajs/medusa-js" + * const medusa = new Medusa({ baseUrl: MEDUSA_BACKEND_URL, maxRetries: 3 }) + * // must be previously logged in or use api token + * medusa.admin.orders.complete(order_id) + * .then(({ order }) => { + * console.log(order.id); + * }); + * - lang: Shell + * label: cURL + * source: | + * curl --location --request POST 'https://medusa-url.com/admin/orders/{id}/complete' \ + * --header 'Authorization: Bearer {api_token}' + * security: + * - api_token: [] + * - cookie_auth: [] * tags: * - Order * responses: @@ -20,6 +39,18 @@ import { EntityManager } from "typeorm" * properties: * order: * $ref: "#/components/schemas/order" + * "400": + * $ref: "#/components/responses/400_error" + * "401": + * $ref: "#/components/responses/unauthorized" + * "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 { id } = req.params diff --git a/packages/medusa/src/api/routes/admin/orders/create-claim-shipment.ts b/packages/medusa/src/api/routes/admin/orders/create-claim-shipment.ts index 17901305fa..01e1854824 100644 --- a/packages/medusa/src/api/routes/admin/orders/create-claim-shipment.ts +++ b/packages/medusa/src/api/routes/admin/orders/create-claim-shipment.ts @@ -29,6 +29,31 @@ import { EntityManager } from "typeorm" * type: array * items: * type: string + * x-codeSamples: + * - lang: JavaScript + * label: JS Client + * source: | + * import Medusa from "@medusajs/medusa-js" + * const medusa = new Medusa({ baseUrl: MEDUSA_BACKEND_URL, maxRetries: 3 }) + * // must be previously logged in or use api token + * medusa.admin.orders.createClaimShipment(order_id, claim_id, { + * fulfillment_id + * }) + * .then(({ order }) => { + * console.log(order.id); + * }); + * - lang: Shell + * label: cURL + * source: | + * curl --location --request POST 'https://medusa-url.com/admin/orders/{id}/claims/{claim_id}/shipments' \ + * --header 'Authorization: Bearer {api_token}' \ + * --header 'Content-Type: application/json' \ + * --data-raw '{ + * "fulfillment_id": "{fulfillment_id}" + * }' + * security: + * - api_token: [] + * - cookie_auth: [] * tags: * - Claim * responses: @@ -40,6 +65,18 @@ import { EntityManager } from "typeorm" * properties: * order: * $ref: "#/components/schemas/order" + * "400": + * $ref: "#/components/responses/400_error" + * "401": + * $ref: "#/components/responses/unauthorized" + * "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 { id, claim_id } = req.params diff --git a/packages/medusa/src/api/routes/admin/orders/create-claim.ts b/packages/medusa/src/api/routes/admin/orders/create-claim.ts index 08e8c66bc8..f478364feb 100644 --- a/packages/medusa/src/api/routes/admin/orders/create-claim.ts +++ b/packages/medusa/src/api/routes/admin/orders/create-claim.ts @@ -126,6 +126,43 @@ import { validator } from "../../../../utils/validator" * metadata: * description: An optional set of key-value pairs to hold additional information. * type: object + * x-codeSamples: + * - lang: JavaScript + * label: JS Client + * source: | + * import Medusa from "@medusajs/medusa-js" + * const medusa = new Medusa({ baseUrl: MEDUSA_BACKEND_URL, maxRetries: 3 }) + * // must be previously logged in or use api token + * medusa.admin.orders.createClaim(order_id, { + * type: 'refund', + * claim_items: [ + * { + * item_id, + * quantity: 1 + * } + * ] + * }) + * .then(({ order }) => { + * console.log(order.id); + * }); + * - lang: Shell + * label: cURL + * source: | + * curl --location --request POST 'https://medusa-url.com/admin/orders/{id}/claims' \ + * --header 'Authorization: Bearer {api_token}' \ + * --header 'Content-Type: application/json' \ + * --data-raw '{ + * "type": "refund", + * "claim_items": [ + * { + * "item_id": "asdsd", + * "quantity": 1 + * } + * ] + * }' + * security: + * - api_token: [] + * - cookie_auth: [] * tags: * - Claim * responses: @@ -137,6 +174,18 @@ import { validator } from "../../../../utils/validator" * properties: * order: * $ref: "#/components/schemas/order" + * "400": + * $ref: "#/components/responses/400_error" + * "401": + * $ref: "#/components/responses/unauthorized" + * "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) => { diff --git a/packages/medusa/src/api/routes/admin/orders/create-fulfillment.ts b/packages/medusa/src/api/routes/admin/orders/create-fulfillment.ts index 354be55bbc..f8e1965726 100644 --- a/packages/medusa/src/api/routes/admin/orders/create-fulfillment.ts +++ b/packages/medusa/src/api/routes/admin/orders/create-fulfillment.ts @@ -50,6 +50,41 @@ import { validator } from "../../../../utils/validator" * metadata: * description: An optional set of key-value pairs to hold additional information. * type: object + * x-codeSamples: + * - lang: JavaScript + * label: JS Client + * source: | + * import Medusa from "@medusajs/medusa-js" + * const medusa = new Medusa({ baseUrl: MEDUSA_BACKEND_URL, maxRetries: 3 }) + * // must be previously logged in or use api token + * medusa.admin.orders.createFulfillment(order_id, { + * items: [ + * { + * item_id, + * quantity: 1 + * } + * ] + * }) + * .then(({ order }) => { + * console.log(order.id); + * }); + * - lang: Shell + * label: cURL + * source: | + * curl --location --request POST 'https://medusa-url.com/admin/orders/{id}/fulfillment' \ + * --header 'Authorization: Bearer {api_token}' \ + * --header 'Content-Type: application/json' \ + * --data-raw '{ + * "items": [ + * { + * "item_id": "{item_id}", + * "quantity": 1 + * } + * ] + * }' + * security: + * - api_token: [] + * - cookie_auth: [] * tags: * - Fulfillment * responses: @@ -61,6 +96,18 @@ import { validator } from "../../../../utils/validator" * properties: * order: * $ref: "#/components/schemas/order" + * "400": + * $ref: "#/components/responses/400_error" + * "401": + * $ref: "#/components/responses/unauthorized" + * "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 { id } = req.params diff --git a/packages/medusa/src/api/routes/admin/orders/create-shipment.ts b/packages/medusa/src/api/routes/admin/orders/create-shipment.ts index 156ea81e0c..084e03e91a 100644 --- a/packages/medusa/src/api/routes/admin/orders/create-shipment.ts +++ b/packages/medusa/src/api/routes/admin/orders/create-shipment.ts @@ -38,6 +38,31 @@ import { validator } from "../../../../utils/validator" * no_notification: * description: If set to true no notification will be send related to this Shipment. * type: boolean + * x-codeSamples: + * - lang: JavaScript + * label: JS Client + * source: | + * import Medusa from "@medusajs/medusa-js" + * const medusa = new Medusa({ baseUrl: MEDUSA_BACKEND_URL, maxRetries: 3 }) + * // must be previously logged in or use api token + * medusa.admin.orders.createShipment(order_id, { + * fulfillment_id + * }) + * .then(({ order }) => { + * console.log(order.id); + * }); + * - lang: Shell + * label: cURL + * source: | + * curl --location --request POST 'https://medusa-url.com/admin/orders/{id}/shipment' \ + * --header 'Authorization: Bearer {api_token}' \ + * --header 'Content-Type: application/json' \ + * --data-raw '{ + * "fulfillment_id": "{fulfillment_id}" + * }' + * security: + * - api_token: [] + * - cookie_auth: [] * tags: * - Order * responses: @@ -49,6 +74,18 @@ import { validator } from "../../../../utils/validator" * properties: * order: * $ref: "#/components/schemas/order" + * "400": + * $ref: "#/components/responses/400_error" + * "401": + * $ref: "#/components/responses/unauthorized" + * "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 { id } = req.params diff --git a/packages/medusa/src/api/routes/admin/orders/create-swap-shipment.ts b/packages/medusa/src/api/routes/admin/orders/create-swap-shipment.ts index 44da0e50e3..f08bf076cd 100644 --- a/packages/medusa/src/api/routes/admin/orders/create-swap-shipment.ts +++ b/packages/medusa/src/api/routes/admin/orders/create-swap-shipment.ts @@ -38,6 +38,31 @@ import { validator } from "../../../../utils/validator" * no_notification: * description: If set to true no notification will be send related to this Claim. * type: boolean + * x-codeSamples: + * - lang: JavaScript + * label: JS Client + * source: | + * import Medusa from "@medusajs/medusa-js" + * const medusa = new Medusa({ baseUrl: MEDUSA_BACKEND_URL, maxRetries: 3 }) + * // must be previously logged in or use api token + * medusa.admin.orders.createSwapShipment(order_id, swap_id, { + * fulfillment_id + * }) + * .then(({ order }) => { + * console.log(order.id); + * }); + * - lang: Shell + * label: cURL + * source: | + * curl --location --request POST 'https://medusa-url.com/admin/orders/{id}/swaps/{swap_id}/shipments' \ + * --header 'Authorization: Bearer {api_token}' \ + * --header 'Content-Type: application/json' \ + * --data-raw '{ + * "fulfillment_id": "{fulfillment_id}" + * }' + * security: + * - api_token: [] + * - cookie_auth: [] * tags: * - Swap * responses: @@ -49,6 +74,18 @@ import { validator } from "../../../../utils/validator" * properties: * order: * $ref: "#/components/schemas/order" + * "400": + * $ref: "#/components/responses/400_error" + * "401": + * $ref: "#/components/responses/unauthorized" + * "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 { id, swap_id } = req.params diff --git a/packages/medusa/src/api/routes/admin/orders/create-swap.ts b/packages/medusa/src/api/routes/admin/orders/create-swap.ts index b7878ec3cc..4a161c5e08 100644 --- a/packages/medusa/src/api/routes/admin/orders/create-swap.ts +++ b/packages/medusa/src/api/routes/admin/orders/create-swap.ts @@ -105,6 +105,41 @@ import { validator } from "../../../../utils/validator" * description: If true, swaps can be completed with items out of stock * type: boolean * default: true + * x-codeSamples: + * - lang: JavaScript + * label: JS Client + * source: | + * import Medusa from "@medusajs/medusa-js" + * const medusa = new Medusa({ baseUrl: MEDUSA_BACKEND_URL, maxRetries: 3 }) + * // must be previously logged in or use api token + * medusa.admin.orders.createSwap(order_id, { + * return_items: [ + * { + * item_id, + * quantity: 1 + * } + * ] + * }) + * .then(({ order }) => { + * console.log(order.id); + * }); + * - lang: Shell + * label: cURL + * source: | + * curl --location --request POST 'https://medusa-url.com/admin/orders/{id}/swaps' \ + * --header 'Authorization: Bearer {api_token}' \ + * --header 'Content-Type: application/json' \ + * --data-raw '{ + * "return_items": [ + * { + * "item_id": "asfasf", + * "quantity": 1 + * } + * ] + * }' + * security: + * - api_token: [] + * - cookie_auth: [] * tags: * - Swap * responses: @@ -116,6 +151,18 @@ import { validator } from "../../../../utils/validator" * properties: * order: * $ref: "#/components/schemas/order" + * "400": + * $ref: "#/components/responses/400_error" + * "401": + * $ref: "#/components/responses/unauthorized" + * "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 { id } = req.params diff --git a/packages/medusa/src/api/routes/admin/orders/fulfill-claim.ts b/packages/medusa/src/api/routes/admin/orders/fulfill-claim.ts index 9dbf5346bc..6995187cdd 100644 --- a/packages/medusa/src/api/routes/admin/orders/fulfill-claim.ts +++ b/packages/medusa/src/api/routes/admin/orders/fulfill-claim.ts @@ -25,6 +25,25 @@ import { validator } from "../../../../utils/validator" * no_notification: * description: If set to true no notification will be send related to this Claim. * type: boolean + * x-codeSamples: + * - lang: JavaScript + * label: JS Client + * source: | + * import Medusa from "@medusajs/medusa-js" + * const medusa = new Medusa({ baseUrl: MEDUSA_BACKEND_URL, maxRetries: 3 }) + * // must be previously logged in or use api token + * medusa.admin.orders.fulfillClaim(order_id, claim_id) + * .then(({ order }) => { + * console.log(order.id); + * }); + * - lang: Shell + * label: cURL + * source: | + * curl --location --request POST 'https://medusa-url.com/admin/orders/{id}/claims/{claim_id}/fulfillments' \ + * --header 'Authorization: Bearer {api_token}' + * security: + * - api_token: [] + * - cookie_auth: [] * tags: * - Fulfillment * responses: @@ -36,6 +55,18 @@ import { validator } from "../../../../utils/validator" * properties: * order: * $ref: "#/components/schemas/order" + * "400": + * $ref: "#/components/responses/400_error" + * "401": + * $ref: "#/components/responses/unauthorized" + * "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 { id, claim_id } = req.params diff --git a/packages/medusa/src/api/routes/admin/orders/fulfill-swap.ts b/packages/medusa/src/api/routes/admin/orders/fulfill-swap.ts index fcdb03f6ac..2e20b48619 100644 --- a/packages/medusa/src/api/routes/admin/orders/fulfill-swap.ts +++ b/packages/medusa/src/api/routes/admin/orders/fulfill-swap.ts @@ -25,6 +25,25 @@ import { validator } from "../../../../utils/validator" * no_notification: * description: If set to true no notification will be send related to this Claim. * type: boolean + * x-codeSamples: + * - lang: JavaScript + * label: JS Client + * source: | + * import Medusa from "@medusajs/medusa-js" + * const medusa = new Medusa({ baseUrl: MEDUSA_BACKEND_URL, maxRetries: 3 }) + * // must be previously logged in or use api token + * medusa.admin.orders.fulfillSwap(order_id, swap_id) + * .then(({ order }) => { + * console.log(order.id); + * }); + * - lang: Shell + * label: cURL + * source: | + * curl --location --request POST 'https://medusa-url.com/admin/orders/{id}/swaps/{swap_id}/fulfillments' \ + * --header 'Authorization: Bearer {api_token}' + * security: + * - api_token: [] + * - cookie_auth: [] * tags: * - Fulfillment * responses: @@ -36,6 +55,18 @@ import { validator } from "../../../../utils/validator" * properties: * order: * $ref: "#/components/schemas/order" + * "400": + * $ref: "#/components/responses/400_error" + * "401": + * $ref: "#/components/responses/unauthorized" + * "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 { id, swap_id } = req.params diff --git a/packages/medusa/src/api/routes/admin/orders/get-order.ts b/packages/medusa/src/api/routes/admin/orders/get-order.ts index 9e88eb96d3..1444b6f872 100644 --- a/packages/medusa/src/api/routes/admin/orders/get-order.ts +++ b/packages/medusa/src/api/routes/admin/orders/get-order.ts @@ -8,6 +8,25 @@ import { OrderService } from "../../../../services" * x-authenticated: true * parameters: * - (path) id=* {string} The ID of the Order. + * x-codeSamples: + * - lang: JavaScript + * label: JS Client + * source: | + * import Medusa from "@medusajs/medusa-js" + * const medusa = new Medusa({ baseUrl: MEDUSA_BACKEND_URL, maxRetries: 3 }) + * // must be previously logged in or use api token + * medusa.admin.orders.retrieve(order_id) + * .then(({ order }) => { + * console.log(order.id); + * }); + * - lang: Shell + * label: cURL + * source: | + * curl --location --request GET 'https://medusa-url.com/admin/orders/{id}' \ + * --header 'Authorization: Bearer {api_token}' + * security: + * - api_token: [] + * - cookie_auth: [] * tags: * - Order * responses: @@ -19,6 +38,18 @@ import { OrderService } from "../../../../services" * properties: * order: * $ref: "#/components/schemas/order" + * "400": + * $ref: "#/components/responses/400_error" + * "401": + * $ref: "#/components/responses/unauthorized" + * "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 { id } = req.params diff --git a/packages/medusa/src/api/routes/admin/orders/list-orders.ts b/packages/medusa/src/api/routes/admin/orders/list-orders.ts index 1be15dd8bd..22ecbfa0ee 100644 --- a/packages/medusa/src/api/routes/admin/orders/list-orders.ts +++ b/packages/medusa/src/api/routes/admin/orders/list-orders.ts @@ -153,6 +153,25 @@ import { pick } from "lodash" * - (query) limit=50 {integer} Limit the number of orders returned. * - (query) expand {string} (Comma separated) Which fields should be expanded in each order of the result. * - (query) fields {string} (Comma separated) Which fields should be included in each order of the result. + * x-codeSamples: + * - lang: JavaScript + * label: JS Client + * source: | + * import Medusa from "@medusajs/medusa-js" + * const medusa = new Medusa({ baseUrl: MEDUSA_BACKEND_URL, maxRetries: 3 }) + * // must be previously logged in or use api token + * medusa.admin.orders.list() + * .then(({ orders, limit, offset, count }) => { + * console.log(orders.length); + * }); + * - lang: Shell + * label: cURL + * source: | + * curl --location --request GET 'https://medusa-url.com/admin/orders' \ + * --header 'Authorization: Bearer {api_token}' + * security: + * - api_token: [] + * - cookie_auth: [] * tags: * - Order * responses: @@ -175,6 +194,18 @@ import { pick } from "lodash" * limit: * type: integer * description: The number of items per page + * "400": + * $ref: "#/components/responses/400_error" + * "401": + * $ref: "#/components/responses/unauthorized" + * "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 orderService: OrderService = req.scope.resolve("orderService") diff --git a/packages/medusa/src/api/routes/admin/orders/process-swap-payment.ts b/packages/medusa/src/api/routes/admin/orders/process-swap-payment.ts index d50a3c507d..aa383ef42a 100644 --- a/packages/medusa/src/api/routes/admin/orders/process-swap-payment.ts +++ b/packages/medusa/src/api/routes/admin/orders/process-swap-payment.ts @@ -12,6 +12,25 @@ import { EntityManager } from "typeorm" * parameters: * - (path) id=* {string} The ID of the Order. * - (path) swap_id=* {string} The ID of the Swap. + * x-codeSamples: + * - lang: JavaScript + * label: JS Client + * source: | + * import Medusa from "@medusajs/medusa-js" + * const medusa = new Medusa({ baseUrl: MEDUSA_BACKEND_URL, maxRetries: 3 }) + * // must be previously logged in or use api token + * medusa.admin.orders.processSwapPayment(order_id, swap_id) + * .then(({ order }) => { + * console.log(order.id); + * }); + * - lang: Shell + * label: cURL + * source: | + * curl --location --request POST 'https://medusa-url.com/admin/orders/{id}/swaps/{swap_id}/process-payment' \ + * --header 'Authorization: Bearer {api_token}' + * security: + * - api_token: [] + * - cookie_auth: [] * tags: * - Swap * responses: @@ -23,6 +42,18 @@ import { EntityManager } from "typeorm" * properties: * order: * $ref: "#/components/schemas/order" + * "400": + * $ref: "#/components/responses/400_error" + * "401": + * $ref: "#/components/responses/unauthorized" + * "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 { id, swap_id } = req.params diff --git a/packages/medusa/src/api/routes/admin/orders/refund-payment.ts b/packages/medusa/src/api/routes/admin/orders/refund-payment.ts index 2faa47ef85..650c46db5d 100644 --- a/packages/medusa/src/api/routes/admin/orders/refund-payment.ts +++ b/packages/medusa/src/api/routes/admin/orders/refund-payment.ts @@ -39,6 +39,33 @@ import { EntityManager } from "typeorm" * no_notification: * description: If set to true no notification will be send related to this Refund. * type: boolean + * x-codeSamples: + * - lang: JavaScript + * label: JS Client + * source: | + * import Medusa from "@medusajs/medusa-js" + * const medusa = new Medusa({ baseUrl: MEDUSA_BACKEND_URL, maxRetries: 3 }) + * // must be previously logged in or use api token + * medusa.admin.orders.refundPayment(order_id, { + * amount: 1000, + * reason: 'Do not like it' + * }) + * .then(({ order }) => { + * console.log(order.id); + * }); + * - lang: Shell + * label: cURL + * source: | + * curl --location --request POST 'https://medusa-url.com/admin/orders/adasda/refund' \ + * --header 'Authorization: Bearer {api_token}' \ + * --header 'Content-Type: application/json' \ + * --data-raw '{ + * "amount": 1000, + * "reason": "Do not like it" + * }' + * security: + * - api_token: [] + * - cookie_auth: [] * tags: * - Order * responses: @@ -50,6 +77,18 @@ import { EntityManager } from "typeorm" * properties: * order: * $ref: "#/components/schemas/order" + * "400": + * $ref: "#/components/responses/400_error" + * "401": + * $ref: "#/components/responses/unauthorized" + * "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 { id } = req.params diff --git a/packages/medusa/src/api/routes/admin/orders/request-return.ts b/packages/medusa/src/api/routes/admin/orders/request-return.ts index 4fa67a96fc..bdb43e4b71 100644 --- a/packages/medusa/src/api/routes/admin/orders/request-return.ts +++ b/packages/medusa/src/api/routes/admin/orders/request-return.ts @@ -79,6 +79,41 @@ import { validator } from "../../../../utils/validator" * refund: * description: The amount to refund. * type: integer + * x-codeSamples: + * - lang: JavaScript + * label: JS Client + * source: | + * import Medusa from "@medusajs/medusa-js" + * const medusa = new Medusa({ baseUrl: MEDUSA_BACKEND_URL, maxRetries: 3 }) + * // must be previously logged in or use api token + * medusa.admin.orders.requestReturn(order_id, { + * items: [ + * { + * item_id, + * quantity: 1 + * } + * ] + * }) + * .then(({ order }) => { + * console.log(order.id); + * }); + * - lang: Shell + * label: cURL + * source: | + * curl --location --request POST 'https://medusa-url.com/admin/orders/{id}/return' \ + * --header 'Authorization: Bearer {api_token}' \ + * --header 'Content-Type: application/json' \ + * --data-raw '{ + * "items": [ + * { + * "item_id": "{item_id}", + * "quantity": 1 + * } + * ] + * }' + * security: + * - api_token: [] + * - cookie_auth: [] * tags: * - Return * - Order @@ -91,6 +126,18 @@ import { validator } from "../../../../utils/validator" * properties: * order: * $ref: "#/components/schemas/order" + * "400": + * $ref: "#/components/responses/400_error" + * "401": + * $ref: "#/components/responses/unauthorized" + * "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 { id } = req.params diff --git a/packages/medusa/src/api/routes/admin/orders/update-claim.ts b/packages/medusa/src/api/routes/admin/orders/update-claim.ts index cb176b095f..4b741eea98 100644 --- a/packages/medusa/src/api/routes/admin/orders/update-claim.ts +++ b/packages/medusa/src/api/routes/admin/orders/update-claim.ts @@ -105,6 +105,31 @@ import { EntityManager } from "typeorm" * metadata: * description: An optional set of key-value pairs to hold additional information. * type: object + * x-codeSamples: + * - lang: JavaScript + * label: JS Client + * source: | + * import Medusa from "@medusajs/medusa-js" + * const medusa = new Medusa({ baseUrl: MEDUSA_BACKEND_URL, maxRetries: 3 }) + * // must be previously logged in or use api token + * medusa.admin.orders.updateClaim(order_id, claim_id, { + * no_notification: true + * }) + * .then(({ order }) => { + * console.log(order.id); + * }); + * - lang: Shell + * label: cURL + * source: | + * curl --location --request POST 'https://medusa-url.com/admin/orders/{id}/claims/{claim_id}' \ + * --header 'Authorization: Bearer {api_token}' \ + * --header 'Content-Type: application/json' \ + * --data-raw '{ + * "no_notification": true + * }' + * security: + * - api_token: [] + * - cookie_auth: [] * tags: * - Claim * responses: @@ -116,6 +141,18 @@ import { EntityManager } from "typeorm" * properties: * order: * $ref: "#/components/schemas/order" + * "400": + * $ref: "#/components/responses/400_error" + * "401": + * $ref: "#/components/responses/unauthorized" + * "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 { id, claim_id } = req.params diff --git a/packages/medusa/src/api/routes/admin/orders/update-order.ts b/packages/medusa/src/api/routes/admin/orders/update-order.ts index 287e528043..ff013dc7e1 100644 --- a/packages/medusa/src/api/routes/admin/orders/update-order.ts +++ b/packages/medusa/src/api/routes/admin/orders/update-order.ts @@ -90,6 +90,31 @@ import { validator } from "../../../../utils/validator" * no_notification: * description: A flag to indicate if no notifications should be emitted related to the updated order. * type: boolean + * x-codeSamples: + * - lang: JavaScript + * label: JS Client + * source: | + * import Medusa from "@medusajs/medusa-js" + * const medusa = new Medusa({ baseUrl: MEDUSA_BACKEND_URL, maxRetries: 3 }) + * // must be previously logged in or use api token + * medusa.admin.orders.update(order_id, { + * email: 'user@example.com' + * }) + * .then(({ order }) => { + * console.log(order.id); + * }); + * - lang: Shell + * label: cURL + * source: | + * curl --location --request POST 'https://medusa-url.com/admin/orders/adasda' \ + * --header 'Authorization: Bearer {api_token}' \ + * --header 'Content-Type: application/json' \ + * --data-raw '{ + * "email": "user@example.com" + * }' + * security: + * - api_token: [] + * - cookie_auth: [] * tags: * - Order * responses: @@ -101,6 +126,18 @@ import { validator } from "../../../../utils/validator" * properties: * order: * $ref: "#/components/schemas/order" + * "400": + * $ref: "#/components/responses/400_error" + * "401": + * $ref: "#/components/responses/unauthorized" + * "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) => { diff --git a/packages/medusa/src/api/routes/admin/price-lists/add-prices-batch.ts b/packages/medusa/src/api/routes/admin/price-lists/add-prices-batch.ts index 43b17b8a4b..facfd03ade 100644 --- a/packages/medusa/src/api/routes/admin/price-lists/add-prices-batch.ts +++ b/packages/medusa/src/api/routes/admin/price-lists/add-prices-batch.ts @@ -56,6 +56,43 @@ import { EntityManager } from "typeorm" * override: * description: "If true the prices will replace all existing prices associated with the Price List." * type: boolean + * x-codeSamples: + * - lang: JavaScript + * label: JS Client + * source: | + * import Medusa from "@medusajs/medusa-js" + * const medusa = new Medusa({ baseUrl: MEDUSA_BACKEND_URL, maxRetries: 3 }) + * // must be previously logged in or use api token + * medusa.admin.priceLists.addPrices(price_list_id, { + * prices: [ + * { + * amount: 1000, + * variant_id, + * currency_code: 'eur' + * } + * ] + * }) + * .then(({ price_list }) => { + * console.log(price_list.id); + * }); + * - lang: Shell + * label: cURL + * source: | + * curl --location --request POST 'https://medusa-url.com/admin/price-lists/{id}/prices/batch' \ + * --header 'Authorization: Bearer {api_token}' \ + * --header 'Content-Type: application/json' \ + * --data-raw '{ + * "prices": [ + * { + * "amount": 100, + * "variant_id": "afasfa", + * "currency_code": "eur" + * } + * ] + * }' + * security: + * - api_token: [] + * - cookie_auth: [] * tags: * - Price List * responses: @@ -67,6 +104,18 @@ import { EntityManager } from "typeorm" * properties: * price_list: * $ref: "#/components/schemas/price_list" + * "400": + * $ref: "#/components/responses/400_error" + * "401": + * $ref: "#/components/responses/unauthorized" + * "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 { id } = req.params diff --git a/packages/medusa/src/api/routes/admin/price-lists/create-price-list.ts b/packages/medusa/src/api/routes/admin/price-lists/create-price-list.ts index cca93408a9..94525eda00 100644 --- a/packages/medusa/src/api/routes/admin/price-lists/create-price-list.ts +++ b/packages/medusa/src/api/routes/admin/price-lists/create-price-list.ts @@ -98,6 +98,50 @@ import { Type } from "class-transformer" * id: * description: The ID of a customer group * type: string + * x-codeSamples: + * - lang: JavaScript + * label: JS Client + * source: | + * import Medusa from "@medusajs/medusa-js" + * import { PriceListType } from "@medusajs/medusa" + * const medusa = new Medusa({ baseUrl: MEDUSA_BACKEND_URL, maxRetries: 3 }) + * // must be previously logged in or use api token + * medusa.admin.priceLists.create({ + * name: 'New Price List', + * description: 'A new price list', + * type: PriceListType.SALE, + * prices: [ + * { + * amount: 1000, + * variant_id, + * currency_code: 'eur' + * } + * ] + * }) + * .then(({ price_list }) => { + * console.log(price_list.id); + * }); + * - lang: Shell + * label: cURL + * source: | + * curl --location --request POST 'https://medusa-url.com/admin/price-lists' \ + * --header 'Authorization: Bearer {api_token}' \ + * --header 'Content-Type: application/json' \ + * --data-raw '{ + * "name": "New Price List", + * "description": "A new price list", + * "type": "sale", + * "prices": [ + * { + * "amount": 1000, + * "variant_id": "afafa", + * "currency_code": "eur" + * } + * ] + * }' + * security: + * - api_token: [] + * - cookie_auth: [] * tags: * - Price List * responses: @@ -109,6 +153,18 @@ import { Type } from "class-transformer" * properties: * price_list: * $ref: "#/components/schemas/price_list" + * "400": + * $ref: "#/components/responses/400_error" + * "401": + * $ref: "#/components/responses/unauthorized" + * "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: Request, res) => { const priceListService: PriceListService = diff --git a/packages/medusa/src/api/routes/admin/price-lists/delete-price-list.ts b/packages/medusa/src/api/routes/admin/price-lists/delete-price-list.ts index 9862c36d1f..79702ae893 100644 --- a/packages/medusa/src/api/routes/admin/price-lists/delete-price-list.ts +++ b/packages/medusa/src/api/routes/admin/price-lists/delete-price-list.ts @@ -9,6 +9,25 @@ import PriceListService from "../../../../services/price-list" * x-authenticated: true * parameters: * - (path) id=* {string} The ID of the Price List to delete. + * x-codeSamples: + * - lang: JavaScript + * label: JS Client + * source: | + * import Medusa from "@medusajs/medusa-js" + * const medusa = new Medusa({ baseUrl: MEDUSA_BACKEND_URL, maxRetries: 3 }) + * // must be previously logged in or use api token + * medusa.admin.priceLists.delete(price_list_id) + * .then(({ id, object, deleted }) => { + * console.log(id); + * }); + * - lang: Shell + * label: cURL + * source: | + * curl --location --request DELETE 'https://medusa-url.com/admin/price-lists/{id}' \ + * --header 'Authorization: Bearer {api_token}' + * security: + * - api_token: [] + * - cookie_auth: [] * tags: * - Price List * responses: @@ -29,6 +48,18 @@ import PriceListService from "../../../../services/price-list" * type: boolean * description: Whether or not the items were deleted. * default: true + * "400": + * $ref: "#/components/responses/400_error" + * "401": + * $ref: "#/components/responses/unauthorized" + * "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 { id } = req.params diff --git a/packages/medusa/src/api/routes/admin/price-lists/delete-prices-batch.ts b/packages/medusa/src/api/routes/admin/price-lists/delete-prices-batch.ts index 94dcc05ba4..084bb1cefb 100644 --- a/packages/medusa/src/api/routes/admin/price-lists/delete-prices-batch.ts +++ b/packages/medusa/src/api/routes/admin/price-lists/delete-prices-batch.ts @@ -22,6 +22,35 @@ import { validator } from "../../../../utils/validator" * type: array * items: * type: string + * x-codeSamples: + * - lang: JavaScript + * label: JS Client + * source: | + * import Medusa from "@medusajs/medusa-js" + * const medusa = new Medusa({ baseUrl: MEDUSA_BACKEND_URL, maxRetries: 3 }) + * // must be previously logged in or use api token + * medusa.admin.priceLists.deletePrices(price_list_id, { + * price_ids: [ + * price_id + * ] + * }) + * .then(({ ids, object, deleted }) => { + * console.log(ids.length); + * }); + * - lang: Shell + * label: cURL + * source: | + * curl --location --request DELETE 'https://medusa-url.com/admin/price-lists/{id}/prices/batch' \ + * --header 'Authorization: Bearer {api_token}' \ + * --header 'Content-Type: application/json' \ + * --data-raw '{ + * "price_ids": [ + * "adasfa" + * ] + * }' + * security: + * - api_token: [] + * - cookie_auth: [] * tags: * - Price List * responses: @@ -44,6 +73,18 @@ import { validator } from "../../../../utils/validator" * type: boolean * description: Whether or not the items were deleted. * default: true + * "400": + * $ref: "#/components/responses/400_error" + * "401": + * $ref: "#/components/responses/unauthorized" + * "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 { id } = req.params diff --git a/packages/medusa/src/api/routes/admin/price-lists/delete-product-prices.ts b/packages/medusa/src/api/routes/admin/price-lists/delete-product-prices.ts index fe52565131..f42df8dca6 100644 --- a/packages/medusa/src/api/routes/admin/price-lists/delete-product-prices.ts +++ b/packages/medusa/src/api/routes/admin/price-lists/delete-product-prices.ts @@ -10,6 +10,25 @@ import PriceListService from "../../../../services/price-list" * parameters: * - (path) id=* {string} The ID of the Price List that the Money Amounts that will be deleted belongs to. * - (path) product_id=* {string} The ID of the product from which the money amount will be deleted. + * x-codeSamples: + * - lang: JavaScript + * label: JS Client + * source: | + * import Medusa from "@medusajs/medusa-js" + * const medusa = new Medusa({ baseUrl: MEDUSA_BACKEND_URL, maxRetries: 3 }) + * // must be previously logged in or use api token + * medusa.admin.priceLists.deleteProductPrices(price_list_id, product_id) + * .then(({ ids, object, deleted }) => { + * console.log(ids.length); + * }); + * - lang: Shell + * label: cURL + * source: | + * curl --location --request DELETE 'https://medusa-url.com/admin/price-lists/{id}/products/{product_id}/prices' \ + * --header 'Authorization: Bearer {api_token}' + * security: + * - api_token: [] + * - cookie_auth: [] * tags: * - Price List * responses: @@ -32,6 +51,18 @@ import PriceListService from "../../../../services/price-list" * type: boolean * description: Whether or not the items were deleted. * default: true + * "400": + * $ref: "#/components/responses/400_error" + * "401": + * $ref: "#/components/responses/unauthorized" + * "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 { id, product_id } = req.params diff --git a/packages/medusa/src/api/routes/admin/price-lists/delete-variant-prices.ts b/packages/medusa/src/api/routes/admin/price-lists/delete-variant-prices.ts index f38457851e..0c7163533f 100644 --- a/packages/medusa/src/api/routes/admin/price-lists/delete-variant-prices.ts +++ b/packages/medusa/src/api/routes/admin/price-lists/delete-variant-prices.ts @@ -10,6 +10,25 @@ import PriceListService from "../../../../services/price-list" * parameters: * - (path) id=* {string} The ID of the Price List that the Money Amounts that will be deleted belongs to. * - (path) variant_id=* {string} The ID of the variant from which the money amount will be deleted. + * x-codeSamples: + * - lang: JavaScript + * label: JS Client + * source: | + * import Medusa from "@medusajs/medusa-js" + * const medusa = new Medusa({ baseUrl: MEDUSA_BACKEND_URL, maxRetries: 3 }) + * // must be previously logged in or use api token + * medusa.admin.priceLists.deleteVariantPrices(price_list_id, variant_id) + * .then(({ ids, object, deleted }) => { + * console.log(ids); + * }); + * - lang: Shell + * label: cURL + * source: | + * curl --location --request DELETE 'https://medusa-url.com/admin/price-lists/{id}/variants/{variant_id}/prices' \ + * --header 'Authorization: Bearer {api_token}' + * security: + * - api_token: [] + * - cookie_auth: [] * tags: * - Price List * responses: @@ -32,6 +51,18 @@ import PriceListService from "../../../../services/price-list" * type: boolean * description: Whether or not the items were deleted. * default: true + * "400": + * $ref: "#/components/responses/400_error" + * "401": + * $ref: "#/components/responses/unauthorized" + * "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 { id, variant_id } = req.params diff --git a/packages/medusa/src/api/routes/admin/price-lists/get-price-list.ts b/packages/medusa/src/api/routes/admin/price-lists/get-price-list.ts index 13fc214ca4..cece6f6a3b 100644 --- a/packages/medusa/src/api/routes/admin/price-lists/get-price-list.ts +++ b/packages/medusa/src/api/routes/admin/price-lists/get-price-list.ts @@ -11,6 +11,25 @@ import PriceListService from "../../../../services/price-list" * x-authenticated: true * parameters: * - (path) id=* {string} The ID of the Price List. + * x-codeSamples: + * - lang: JavaScript + * label: JS Client + * source: | + * import Medusa from "@medusajs/medusa-js" + * const medusa = new Medusa({ baseUrl: MEDUSA_BACKEND_URL, maxRetries: 3 }) + * // must be previously logged in or use api token + * medusa.admin.priceLists.retrieve(price_list_id) + * .then(({ price_list }) => { + * console.log(price_list.id); + * }); + * - lang: Shell + * label: cURL + * source: | + * curl --location --request GET 'https://medusa-url.com/admin/price-lists/{id}' \ + * --header 'Authorization: Bearer {api_token}' + * security: + * - api_token: [] + * - cookie_auth: [] * tags: * - Price List * responses: @@ -22,6 +41,18 @@ import PriceListService from "../../../../services/price-list" * properties: * price_list: * $ref: "#/components/schemas/price_list" + * "400": + * $ref: "#/components/responses/400_error" + * "401": + * $ref: "#/components/responses/unauthorized" + * "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 { id } = req.params diff --git a/packages/medusa/src/api/routes/admin/price-lists/list-price-list-products.ts b/packages/medusa/src/api/routes/admin/price-lists/list-price-list-products.ts index adbafc4518..c00598ad77 100644 --- a/packages/medusa/src/api/routes/admin/price-lists/list-price-list-products.ts +++ b/packages/medusa/src/api/routes/admin/price-lists/list-price-list-products.ts @@ -133,6 +133,25 @@ import { isDefined } from "../../../../utils" * - (query) limit=50 {integer} Limit the number of products returned. * - (query) expand {string} (Comma separated) Which fields should be expanded in each product of the result. * - (query) fields {string} (Comma separated) Which fields should be included in each product of the result. + * x-codeSamples: + * - lang: JavaScript + * label: JS Client + * source: | + * import Medusa from "@medusajs/medusa-js" + * const medusa = new Medusa({ baseUrl: MEDUSA_BACKEND_URL, maxRetries: 3 }) + * // must be previously logged in or use api token + * medusa.admin.priceLists.listProducts(price_list_id) + * .then(({ products, limit, offset, count }) => { + * console.log(products.length); + * }); + * - lang: Shell + * label: cURL + * source: | + * curl --location --request GET 'https://medusa-url.com/admin/price-lists/{id}/products' \ + * --header 'Authorization: Bearer {api_token}' + * security: + * - api_token: [] + * - cookie_auth: [] * tags: * - Product * responses: @@ -155,6 +174,18 @@ import { isDefined } from "../../../../utils" * limit: * type: integer * description: The number of items per page + * "400": + * $ref: "#/components/responses/400_error" + * "401": + * $ref: "#/components/responses/unauthorized" + * "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: Request, res) => { const { id } = req.params diff --git a/packages/medusa/src/api/routes/admin/price-lists/list-price-lists.ts b/packages/medusa/src/api/routes/admin/price-lists/list-price-lists.ts index 6653e086fd..8e575f2039 100644 --- a/packages/medusa/src/api/routes/admin/price-lists/list-price-lists.ts +++ b/packages/medusa/src/api/routes/admin/price-lists/list-price-lists.ts @@ -114,6 +114,25 @@ import { Type } from "class-transformer" * type: string * description: filter by dates greater than or equal to this date * format: date + * x-codeSamples: + * - lang: JavaScript + * label: JS Client + * source: | + * import Medusa from "@medusajs/medusa-js" + * const medusa = new Medusa({ baseUrl: MEDUSA_BACKEND_URL, maxRetries: 3 }) + * // must be previously logged in or use api token + * medusa.admin.priceLists.list() + * .then(({ price_lists, limit, offset, count }) => { + * console.log(price_lists.length); + * }); + * - lang: Shell + * label: cURL + * source: | + * curl --location --request GET 'https://medusa-url.com/admin/price-lists' \ + * --header 'Authorization: Bearer {api_token}' + * security: + * - api_token: [] + * - cookie_auth: [] * tags: * - Price List * responses: @@ -136,6 +155,18 @@ import { Type } from "class-transformer" * limit: * type: integer * description: The number of items per page + * "400": + * $ref: "#/components/responses/400_error" + * "401": + * $ref: "#/components/responses/unauthorized" + * "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: Request, res) => { const validated = req.validatedQuery diff --git a/packages/medusa/src/api/routes/admin/price-lists/update-price-list.ts b/packages/medusa/src/api/routes/admin/price-lists/update-price-list.ts index 6b53148151..9088be5edd 100644 --- a/packages/medusa/src/api/routes/admin/price-lists/update-price-list.ts +++ b/packages/medusa/src/api/routes/admin/price-lists/update-price-list.ts @@ -99,6 +99,31 @@ import { EntityManager } from "typeorm" * id: * description: The ID of a customer group * type: string + * x-codeSamples: + * - lang: JavaScript + * label: JS Client + * source: | + * import Medusa from "@medusajs/medusa-js" + * const medusa = new Medusa({ baseUrl: MEDUSA_BACKEND_URL, maxRetries: 3 }) + * // must be previously logged in or use api token + * medusa.admin.priceLists.update(price_list_id, { + * name: 'New Price List' + * }) + * .then(({ price_list }) => { + * console.log(price_list.id); + * }); + * - lang: Shell + * label: cURL + * source: | + * curl --location --request POST 'https://medusa-url.com/admin/price-lists/{id}' \ + * --header 'Authorization: Bearer {api_token}' \ + * --header 'Content-Type: application/json' \ + * --data-raw '{ + * "name": "New Price List" + * }' + * security: + * - api_token: [] + * - cookie_auth: [] * tags: * - Price List * responses: @@ -110,6 +135,18 @@ import { EntityManager } from "typeorm" * properties: * price_list: * $ref: "#/components/schemas/price_list" + * "400": + * $ref: "#/components/responses/400_error" + * "401": + * $ref: "#/components/responses/unauthorized" + * "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 { id } = req.params diff --git a/packages/medusa/src/api/routes/admin/product-tags/list-product-tags.ts b/packages/medusa/src/api/routes/admin/product-tags/list-product-tags.ts index a4757cdf54..be3ff0460a 100644 --- a/packages/medusa/src/api/routes/admin/product-tags/list-product-tags.ts +++ b/packages/medusa/src/api/routes/admin/product-tags/list-product-tags.ts @@ -92,6 +92,25 @@ import { isDefined } from "../../../../utils" * type: string * description: filter by dates greater than or equal to this date * format: date + * x-codeSamples: + * - lang: JavaScript + * label: JS Client + * source: | + * import Medusa from "@medusajs/medusa-js" + * const medusa = new Medusa({ baseUrl: MEDUSA_BACKEND_URL, maxRetries: 3 }) + * // must be previously logged in or use api token + * medusa.admin.productTags.list() + * .then(({ product_tags }) => { + * console.log(product_tags.length); + * }); + * - lang: Shell + * label: cURL + * source: | + * curl --location --request GET 'https://medusa-url.com/admin/product-tags' \ + * --header 'Authorization: Bearer {api_token}' + * security: + * - api_token: [] + * - cookie_auth: [] * tags: * - Product Tag * responses: @@ -112,6 +131,18 @@ import { isDefined } from "../../../../utils" * limit: * type: integer * description: The number of items per page + * "400": + * $ref: "#/components/responses/400_error" + * "401": + * $ref: "#/components/responses/unauthorized" + * "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 validated = await validator(AdminGetProductTagsParams, req.query) diff --git a/packages/medusa/src/api/routes/admin/product-types/list-product-types.ts b/packages/medusa/src/api/routes/admin/product-types/list-product-types.ts index 84f6e69fbd..fdc9ae4955 100644 --- a/packages/medusa/src/api/routes/admin/product-types/list-product-types.ts +++ b/packages/medusa/src/api/routes/admin/product-types/list-product-types.ts @@ -92,6 +92,25 @@ import { isDefined } from "../../../../utils" * type: string * description: filter by dates greater than or equal to this date * format: date + * x-codeSamples: + * - lang: JavaScript + * label: JS Client + * source: | + * import Medusa from "@medusajs/medusa-js" + * const medusa = new Medusa({ baseUrl: MEDUSA_BACKEND_URL, maxRetries: 3 }) + * // must be previously logged in or use api token + * medusa.admin.productTypes.list() + * .then(({ product_types }) => { + * console.log(product_types.length); + * }); + * - lang: Shell + * label: cURL + * source: | + * curl --location --request GET 'https://medusa-url.com/admin/product-types' \ + * --header 'Authorization: Bearer {api_token}' + * security: + * - api_token: [] + * - cookie_auth: [] * tags: * - Product Type * responses: @@ -112,6 +131,18 @@ import { isDefined } from "../../../../utils" * limit: * type: integer * description: The number of items per page + * "400": + * $ref: "#/components/responses/400_error" + * "401": + * $ref: "#/components/responses/unauthorized" + * "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 validated = await validator(AdminGetProductTypesParams, req.query) diff --git a/packages/medusa/src/api/routes/admin/products/add-option.ts b/packages/medusa/src/api/routes/admin/products/add-option.ts index 3fa80b9020..257a61ad80 100644 --- a/packages/medusa/src/api/routes/admin/products/add-option.ts +++ b/packages/medusa/src/api/routes/admin/products/add-option.ts @@ -23,6 +23,31 @@ import { EntityManager } from "typeorm" * title: * description: "The title the Product Option will be identified by i.e. \"Size\"" * type: string + * x-codeSamples: + * - lang: JavaScript + * label: JS Client + * source: | + * import Medusa from "@medusajs/medusa-js" + * const medusa = new Medusa({ baseUrl: MEDUSA_BACKEND_URL, maxRetries: 3 }) + * // must be previously logged in or use api token + * medusa.admin.products.addOption(product_id, { + * title: 'Size' + * }) + * .then(({ product }) => { + * console.log(product.id); + * }); + * - lang: Shell + * label: cURL + * source: | + * curl --location --request POST 'https://medusa-url.com/admin/products/{id}/options' \ + * --header 'Authorization: Bearer {api_token}' \ + * --header 'Content-Type: application/json' \ + * --data-raw '{ + * "title": "Size" + * }' + * security: + * - api_token: [] + * - cookie_auth: [] * tags: * - Product * responses: @@ -34,6 +59,18 @@ import { EntityManager } from "typeorm" * properties: * product: * $ref: "#/components/schemas/product" + * "400": + * $ref: "#/components/responses/400_error" + * "401": + * $ref: "#/components/responses/unauthorized" + * "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 { id } = req.params diff --git a/packages/medusa/src/api/routes/admin/products/create-product.ts b/packages/medusa/src/api/routes/admin/products/create-product.ts index 803bbdbe08..4ea205a1fc 100644 --- a/packages/medusa/src/api/routes/admin/products/create-product.ts +++ b/packages/medusa/src/api/routes/admin/products/create-product.ts @@ -245,6 +245,33 @@ import { validator } from "../../../../utils/validator" * metadata: * description: An optional set of key-value pairs with additional information. * type: object + * x-codeSamples: + * - lang: JavaScript + * label: JS Client + * source: | + * import Medusa from "@medusajs/medusa-js" + * const medusa = new Medusa({ baseUrl: MEDUSA_BACKEND_URL, maxRetries: 3 }) + * // must be previously logged in or use api token + * medusa.admin.products.create({ + * title: 'Shirt', + * is_giftcard: false, + * discountable: true + * }) + * .then(({ product }) => { + * console.log(product.id); + * }); + * - lang: Shell + * label: cURL + * source: | + * curl --location --request POST 'https://medusa-url.com/admin/products' \ + * --header 'Authorization: Bearer {api_token}' \ + * --header 'Content-Type: application/json' \ + * --data-raw '{ + * "title": "Shirt" + * }' + * security: + * - api_token: [] + * - cookie_auth: [] * tags: * - Product * responses: @@ -256,6 +283,18 @@ import { validator } from "../../../../utils/validator" * properties: * product: * $ref: "#/components/schemas/product" + * "400": + * $ref: "#/components/responses/400_error" + * "401": + * $ref: "#/components/responses/unauthorized" + * "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 validated = await validator(AdminPostProductsReq, req.body) diff --git a/packages/medusa/src/api/routes/admin/products/create-variant.ts b/packages/medusa/src/api/routes/admin/products/create-variant.ts index 5e4958ab3f..faa276dbc2 100644 --- a/packages/medusa/src/api/routes/admin/products/create-variant.ts +++ b/packages/medusa/src/api/routes/admin/products/create-variant.ts @@ -124,6 +124,56 @@ import { EntityManager } from "typeorm" * value: * description: The value to give for the Product Option. * type: string + * x-codeSamples: + * - lang: JavaScript + * label: JS Client + * source: | + * import Medusa from "@medusajs/medusa-js" + * const medusa = new Medusa({ baseUrl: MEDUSA_BACKEND_URL, maxRetries: 3 }) + * // must be previously logged in or use api token + * medusa.admin.products.createVariant(product_id, { + * title: 'Color', + * prices: [ + * { + * amount: 1000, + * currency_code: "eur" + * } + * ], + * options: [ + * { + * option_id, + * value: 'S' + * } + * ], + * inventory_quantity: 100 + * }) + * .then(({ product }) => { + * console.log(product.id); + * }); + * - lang: Shell + * label: cURL + * source: | + * curl --location --request POST 'https://medusa-url.com/admin/products/{id}/variants' \ + * --header 'Authorization: Bearer {api_token}' \ + * --header 'Content-Type: application/json' \ + * --data-raw '{ + * "title": "Color", + * "prices": [ + * { + * "amount": 1000, + * "currency_code": "eur" + * } + * ], + * "options": [ + * { + * "option_id": "asdasf", + * "value": "S" + * } + * ] + * }' + * security: + * - api_token: [] + * - cookie_auth: [] * tags: * - Product * responses: @@ -135,6 +185,18 @@ import { EntityManager } from "typeorm" * properties: * product: * $ref: "#/components/schemas/product" + * "400": + * $ref: "#/components/responses/400_error" + * "401": + * $ref: "#/components/responses/unauthorized" + * "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 { id } = req.params diff --git a/packages/medusa/src/api/routes/admin/products/delete-option.ts b/packages/medusa/src/api/routes/admin/products/delete-option.ts index e5e7909dc2..13b2cde77e 100644 --- a/packages/medusa/src/api/routes/admin/products/delete-option.ts +++ b/packages/medusa/src/api/routes/admin/products/delete-option.ts @@ -12,6 +12,25 @@ import { ProductService } from "../../../../services" * parameters: * - (path) id=* {string} The ID of the Product. * - (path) option_id=* {string} The ID of the Product Option. + * x-codeSamples: + * - lang: JavaScript + * label: JS Client + * source: | + * import Medusa from "@medusajs/medusa-js" + * const medusa = new Medusa({ baseUrl: MEDUSA_BACKEND_URL, maxRetries: 3 }) + * // must be previously logged in or use api token + * medusa.admin.products.deleteOption(product_id, option_id) + * .then(({ option_id, object, delete, product }) => { + * console.log(product.id); + * }); + * - lang: Shell + * label: cURL + * source: | + * curl --location --request DELETE 'https://medusa-url.com/admin/products/{id}/options/{option_id}' \ + * --header 'Authorization: Bearer {api_token}' + * security: + * - api_token: [] + * - cookie_auth: [] * tags: * - Product * responses: @@ -34,6 +53,18 @@ import { ProductService } from "../../../../services" * default: true * product: * $ref: "#/components/schemas/product" + * "400": + * $ref: "#/components/responses/400_error" + * "401": + * $ref: "#/components/responses/unauthorized" + * "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 { id, option_id } = req.params diff --git a/packages/medusa/src/api/routes/admin/products/delete-product.ts b/packages/medusa/src/api/routes/admin/products/delete-product.ts index f8955a7067..2b83ba4ef9 100644 --- a/packages/medusa/src/api/routes/admin/products/delete-product.ts +++ b/packages/medusa/src/api/routes/admin/products/delete-product.ts @@ -9,6 +9,25 @@ import { ProductService } from "../../../../services" * x-authenticated: true * parameters: * - (path) id=* {string} The ID of the Product. + * x-codeSamples: + * - lang: JavaScript + * label: JS Client + * source: | + * import Medusa from "@medusajs/medusa-js" + * const medusa = new Medusa({ baseUrl: MEDUSA_BACKEND_URL, maxRetries: 3 }) + * // must be previously logged in or use api token + * medusa.admin.products.delete(product_id) + * .then(({ id, object, deleted }) => { + * console.log(id); + * }); + * - lang: Shell + * label: cURL + * source: | + * curl --location --request DELETE 'https://medusa-url.com/admin/products/asfsaf' \ + * --header 'Authorization: Bearer {api_token}' + * security: + * - api_token: [] + * - cookie_auth: [] * tags: * - Product * responses: @@ -29,6 +48,18 @@ import { ProductService } from "../../../../services" * type: boolean * description: Whether or not the items were deleted. * default: true + * "400": + * $ref: "#/components/responses/400_error" + * "401": + * $ref: "#/components/responses/unauthorized" + * "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 { id } = req.params diff --git a/packages/medusa/src/api/routes/admin/products/delete-variant.ts b/packages/medusa/src/api/routes/admin/products/delete-variant.ts index ecf09a932f..e3bde0c880 100644 --- a/packages/medusa/src/api/routes/admin/products/delete-variant.ts +++ b/packages/medusa/src/api/routes/admin/products/delete-variant.ts @@ -16,6 +16,25 @@ import { EntityManager } from "typeorm" * parameters: * - (path) id=* {string} The ID of the Product. * - (path) variant_id=* {string} The ID of the Product Variant. + * x-codeSamples: + * - lang: JavaScript + * label: JS Client + * source: | + * import Medusa from "@medusajs/medusa-js" + * const medusa = new Medusa({ baseUrl: MEDUSA_BACKEND_URL, maxRetries: 3 }) + * // must be previously logged in or use api token + * medusa.admin.products.deleteVariant(product_id, variant_id) + * .then(({ variant_id, object, deleted, product }) => { + * console.log(product.id); + * }); + * - lang: Shell + * label: cURL + * source: | + * curl --location --request DELETE 'https://medusa-url.com/admin/products/{id}/variants/{variant_id}' \ + * --header 'Authorization: Bearer {api_token}' + * security: + * - api_token: [] + * - cookie_auth: [] * tags: * - Product * responses: @@ -38,6 +57,18 @@ import { EntityManager } from "typeorm" * default: true * product: * $ref: "#/components/schemas/product" + * "400": + * $ref: "#/components/responses/400_error" + * "401": + * $ref: "#/components/responses/unauthorized" + * "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 { id, variant_id } = req.params diff --git a/packages/medusa/src/api/routes/admin/products/get-product.ts b/packages/medusa/src/api/routes/admin/products/get-product.ts index 5ebb548054..f4ac30e6cb 100644 --- a/packages/medusa/src/api/routes/admin/products/get-product.ts +++ b/packages/medusa/src/api/routes/admin/products/get-product.ts @@ -8,6 +8,25 @@ import { PricingService, ProductService } from "../../../../services" * x-authenticated: true * parameters: * - (path) id=* {string} The ID of the Product. + * x-codeSamples: + * - lang: JavaScript + * label: JS Client + * source: | + * import Medusa from "@medusajs/medusa-js" + * const medusa = new Medusa({ baseUrl: MEDUSA_BACKEND_URL, maxRetries: 3 }) + * // must be previously logged in or use api token + * medusa.admin.products.retrieve(product_id) + * .then(({ product }) => { + * console.log(product.id); + * }); + * - lang: Shell + * label: cURL + * source: | + * curl --location --request GET 'https://medusa-url.com/admin/products/{id}' \ + * --header 'Authorization: Bearer {api_token}' + * security: + * - api_token: [] + * - cookie_auth: [] * tags: * - Product * responses: @@ -19,6 +38,18 @@ import { PricingService, ProductService } from "../../../../services" * properties: * product: * $ref: "#/components/schemas/product" + * "400": + * $ref: "#/components/responses/400_error" + * "401": + * $ref: "#/components/responses/unauthorized" + * "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 { id } = req.params diff --git a/packages/medusa/src/api/routes/admin/products/list-products.ts b/packages/medusa/src/api/routes/admin/products/list-products.ts index 5e2a2fe2be..c71e6a1e2b 100644 --- a/packages/medusa/src/api/routes/admin/products/list-products.ts +++ b/packages/medusa/src/api/routes/admin/products/list-products.ts @@ -148,6 +148,25 @@ import { Type } from "class-transformer" * - (query) limit=50 {integer} Limit the number of products returned. * - (query) expand {string} (Comma separated) Which fields should be expanded in each product of the result. * - (query) fields {string} (Comma separated) Which fields should be included in each product of the result. + * x-codeSamples: + * - lang: JavaScript + * label: JS Client + * source: | + * import Medusa from "@medusajs/medusa-js" + * const medusa = new Medusa({ baseUrl: MEDUSA_BACKEND_URL, maxRetries: 3 }) + * // must be previously logged in or use api token + * medusa.admin.products.list() + * .then(({ products, limit, offset, count }) => { + * console.log(products.length); + * }); + * - lang: Shell + * label: cURL + * source: | + * curl --location --request GET 'https://medusa-url.com/admin/products' \ + * --header 'Authorization: Bearer {api_token}' + * security: + * - api_token: [] + * - cookie_auth: [] * tags: * - Product * responses: @@ -170,6 +189,18 @@ import { Type } from "class-transformer" * limit: * type: integer * description: The number of items per page + * "400": + * $ref: "#/components/responses/400_error" + * "401": + * $ref: "#/components/responses/unauthorized" + * "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 productService: ProductService = req.scope.resolve("productService") diff --git a/packages/medusa/src/api/routes/admin/products/list-tag-usage-count.ts b/packages/medusa/src/api/routes/admin/products/list-tag-usage-count.ts index 3bd5ee597e..3c70f8a212 100644 --- a/packages/medusa/src/api/routes/admin/products/list-tag-usage-count.ts +++ b/packages/medusa/src/api/routes/admin/products/list-tag-usage-count.ts @@ -6,6 +6,25 @@ import { ProductService } from "../../../../services" * summary: "List Product Tags Usage Number" * description: "Retrieves a list of Product Tags with how many times each is used." * x-authenticated: true + * x-codeSamples: + * - lang: JavaScript + * label: JS Client + * source: | + * import Medusa from "@medusajs/medusa-js" + * const medusa = new Medusa({ baseUrl: MEDUSA_BACKEND_URL, maxRetries: 3 }) + * // must be previously logged in or use api token + * medusa.admin.products.listTags() + * .then(({ tags }) => { + * console.log(tags.length); + * }); + * - lang: Shell + * label: cURL + * source: | + * curl --location --request GET 'https://medusa-url.com/admin/products/tag-usage' \ + * --header 'Authorization: Bearer {api_token}' + * security: + * - api_token: [] + * - cookie_auth: [] * tags: * - Product Tag * responses: @@ -28,6 +47,18 @@ import { ProductService } from "../../../../services" * value: * description: The value of the tag. * type: string + * "400": + * $ref: "#/components/responses/400_error" + * "401": + * $ref: "#/components/responses/unauthorized" + * "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 productService: ProductService = req.scope.resolve("productService") diff --git a/packages/medusa/src/api/routes/admin/products/list-types.ts b/packages/medusa/src/api/routes/admin/products/list-types.ts index 301858b4ef..f2b0f026b3 100644 --- a/packages/medusa/src/api/routes/admin/products/list-types.ts +++ b/packages/medusa/src/api/routes/admin/products/list-types.ts @@ -6,6 +6,25 @@ import { ProductService } from "../../../../services" * summary: "List Product Types" * description: "Retrieves a list of Product Types." * x-authenticated: true + * x-codeSamples: + * - lang: JavaScript + * label: JS Client + * source: | + * import Medusa from "@medusajs/medusa-js" + * const medusa = new Medusa({ baseUrl: MEDUSA_BACKEND_URL, maxRetries: 3 }) + * // must be previously logged in or use api token + * medusa.admin.products.listTypes() + * .then(({ types }) => { + * console.log(types.length); + * }); + * - lang: Shell + * label: cURL + * source: | + * curl --location --request GET 'https://medusa-url.com/admin/products/types' \ + * --header 'Authorization: Bearer {api_token}' + * security: + * - api_token: [] + * - cookie_auth: [] * tags: * - Product * responses: @@ -19,6 +38,18 @@ import { ProductService } from "../../../../services" * type: array * items: * $ref: "#/components/schemas/product_type" + * "400": + * $ref: "#/components/responses/400_error" + * "401": + * $ref: "#/components/responses/unauthorized" + * "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 productService: ProductService = req.scope.resolve("productService") diff --git a/packages/medusa/src/api/routes/admin/products/list-variants.ts b/packages/medusa/src/api/routes/admin/products/list-variants.ts index b5972c6e35..a3a22ed26b 100644 --- a/packages/medusa/src/api/routes/admin/products/list-variants.ts +++ b/packages/medusa/src/api/routes/admin/products/list-variants.ts @@ -20,6 +20,15 @@ import { validator } from "../../../../utils/validator" * - (query) expand {string} Comma separated string of the relations to include. * - (query) offset=0 {integer} How many items to skip before the results. * - (query) limit=100 {integer} Limit the number of items returned. + * x-codeSamples: + * - lang: Shell + * label: cURL + * source: | + * curl --location --request GET 'https://medusa-url.com/admin/products/{id}/variants' \ + * --header 'Authorization: Bearer {api_token}' + * security: + * - api_token: [] + * - cookie_auth: [] * tags: * - Product * responses: @@ -42,6 +51,18 @@ import { validator } from "../../../../utils/validator" * limit: * type: integer * description: The number of items per page + * "400": + * $ref: "#/components/responses/400_error" + * "401": + * $ref: "#/components/responses/unauthorized" + * "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: Request, res: Response) => { const { id } = req.params diff --git a/packages/medusa/src/api/routes/admin/products/set-metadata.ts b/packages/medusa/src/api/routes/admin/products/set-metadata.ts index 909784962c..b3eaac5fb0 100644 --- a/packages/medusa/src/api/routes/admin/products/set-metadata.ts +++ b/packages/medusa/src/api/routes/admin/products/set-metadata.ts @@ -26,6 +26,33 @@ import { EntityManager } from "typeorm" * value: * description: The metadata value * type: string + * x-codeSamples: + * - lang: JavaScript + * label: JS Client + * source: | + * import Medusa from "@medusajs/medusa-js" + * const medusa = new Medusa({ baseUrl: MEDUSA_BACKEND_URL, maxRetries: 3 }) + * // must be previously logged in or use api token + * medusa.admin.products.setMetadata(product_id, { + * key: 'test', + * value: 'true' + * }) + * .then(({ product }) => { + * console.log(product.id); + * }); + * - lang: Shell + * label: cURL + * source: | + * curl --location --request POST 'https://medusa-url.com/admin/products/{id}/metadata' \ + * --header 'Authorization: Bearer {api_token}' \ + * --header 'Content-Type: application/json' \ + * --data-raw '{ + * "key": "test", + * "value": "true" + * }' + * security: + * - api_token: [] + * - cookie_auth: [] * tags: * - Product * responses: @@ -37,6 +64,18 @@ import { EntityManager } from "typeorm" * properties: * product: * $ref: "#/components/schemas/product" + * "400": + * $ref: "#/components/responses/400_error" + * "401": + * $ref: "#/components/responses/unauthorized" + * "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 { id } = req.params diff --git a/packages/medusa/src/api/routes/admin/products/update-option.ts b/packages/medusa/src/api/routes/admin/products/update-option.ts index 9883b9351d..b9a293f6b0 100644 --- a/packages/medusa/src/api/routes/admin/products/update-option.ts +++ b/packages/medusa/src/api/routes/admin/products/update-option.ts @@ -24,6 +24,31 @@ import { EntityManager } from "typeorm" * title: * description: "The title of the Product Option" * type: string + * x-codeSamples: + * - lang: JavaScript + * label: JS Client + * source: | + * import Medusa from "@medusajs/medusa-js" + * const medusa = new Medusa({ baseUrl: MEDUSA_BACKEND_URL, maxRetries: 3 }) + * // must be previously logged in or use api token + * medusa.admin.products.updateOption(product_id, option_id, { + * title: 'Size' + * }) + * .then(({ product }) => { + * console.log(product.id); + * }); + * - lang: Shell + * label: cURL + * source: | + * curl --location --request POST 'https://medusa-url.com/admin/products/{id}/options/{option_id}' \ + * --header 'Authorization: Bearer {api_token}' \ + * --header 'Content-Type: application/json' \ + * --data-raw '{ + * "title": "Size" + * }' + * security: + * - api_token: [] + * - cookie_auth: [] * tags: * - Product * responses: @@ -35,6 +60,18 @@ import { EntityManager } from "typeorm" * properties: * product: * $ref: "#/components/schemas/product" + * "400": + * $ref: "#/components/responses/400_error" + * "401": + * $ref: "#/components/responses/unauthorized" + * "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 { id, option_id } = req.params diff --git a/packages/medusa/src/api/routes/admin/products/update-product.ts b/packages/medusa/src/api/routes/admin/products/update-product.ts index 680bf58f75..f6d1c14f5a 100644 --- a/packages/medusa/src/api/routes/admin/products/update-product.ts +++ b/packages/medusa/src/api/routes/admin/products/update-product.ts @@ -228,6 +228,32 @@ import { validator } from "../../../../utils/validator" * metadata: * description: An optional set of key-value pairs with additional information. * type: object + * x-codeSamples: + * - lang: JavaScript + * label: JS Client + * source: | + * import Medusa from "@medusajs/medusa-js" + * const medusa = new Medusa({ baseUrl: MEDUSA_BACKEND_URL, maxRetries: 3 }) + * // must be previously logged in or use api token + * medusa.admin.products.update(product_id, { + * title: 'Shirt', + * images: [] + * }) + * .then(({ product }) => { + * console.log(product.id); + * }); + * - lang: Shell + * label: cURL + * source: | + * curl --location --request POST 'https://medusa-url.com/admin/products/{id}' \ + * --header 'Authorization: Bearer {api_token}' \ + * --header 'Content-Type: application/json' \ + * --data-raw '{ + * "title": "Size" + * }' + * security: + * - api_token: [] + * - cookie_auth: [] * tags: * - Product * responses: @@ -239,6 +265,18 @@ import { validator } from "../../../../utils/validator" * properties: * product: * $ref: "#/components/schemas/product" + * "400": + * $ref: "#/components/responses/400_error" + * "401": + * $ref: "#/components/responses/unauthorized" + * "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 { id } = req.params diff --git a/packages/medusa/src/api/routes/admin/products/update-variant.ts b/packages/medusa/src/api/routes/admin/products/update-variant.ts index e8fc412c94..e823f2b1e3 100644 --- a/packages/medusa/src/api/routes/admin/products/update-variant.ts +++ b/packages/medusa/src/api/routes/admin/products/update-variant.ts @@ -33,6 +33,8 @@ import { EntityManager } from "typeorm" * content: * application/json: * schema: + * required: + * - prices * properties: * title: * description: The title to identify the Product Variant by. @@ -125,6 +127,50 @@ import { EntityManager } from "typeorm" * value: * description: The value to give for the Product Option. * type: string + * x-codeSamples: + * - lang: JavaScript + * label: JS Client + * source: | + * import Medusa from "@medusajs/medusa-js" + * const medusa = new Medusa({ baseUrl: MEDUSA_BACKEND_URL, maxRetries: 3 }) + * // must be previously logged in or use api token + * medusa.admin.products.updateVariant(product_id, variant_id, { + * title: 'Color', + * prices: [ + * { + * amount: 1000, + * currency_code: "eur" + * } + * ], + * options: [ + * { + * option_id, + * value: 'S' + * } + * ], + * inventory_quantity: 100 + * }) + * .then(({ product }) => { + * console.log(product.id); + * }); + * - lang: Shell + * label: cURL + * source: | + * curl --location --request POST 'https://medusa-url.com/admin/products/asfsaf/variants/saaga' \ + * --header 'Authorization: Bearer {api_token}' \ + * --header 'Content-Type: application/json' \ + * --data-raw '{ + * "title": "Color", + * "prices": [ + * { + * "amount": 1000, + * "currency_code": "eur" + * } + * ] + * }' + * security: + * - api_token: [] + * - cookie_auth: [] * tags: * - Product * responses: @@ -136,6 +182,18 @@ import { EntityManager } from "typeorm" * properties: * product: * $ref: "#/components/schemas/product" + * "400": + * $ref: "#/components/responses/400_error" + * "401": + * $ref: "#/components/responses/unauthorized" + * "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 { id, variant_id } = req.params diff --git a/packages/medusa/src/api/routes/admin/regions/add-country.ts b/packages/medusa/src/api/routes/admin/regions/add-country.ts index 33ca5610f6..2c797b9dee 100644 --- a/packages/medusa/src/api/routes/admin/regions/add-country.ts +++ b/packages/medusa/src/api/routes/admin/regions/add-country.ts @@ -27,6 +27,31 @@ import { validator } from "../../../../utils/validator" * externalDocs: * url: https://en.wikipedia.org/wiki/ISO_3166-1_alpha-2#Officially_assigned_code_elements * description: See a list of codes. + * x-codeSamples: + * - lang: JavaScript + * label: JS Client + * source: | + * import Medusa from "@medusajs/medusa-js" + * const medusa = new Medusa({ baseUrl: MEDUSA_BACKEND_URL, maxRetries: 3 }) + * // must be previously logged in or use api token + * medusa.admin.regions.addCountry(region_id, { + * country_code: 'dk' + * }) + * .then(({ region }) => { + * console.log(region.id); + * }); + * - lang: Shell + * label: cURL + * source: | + * curl --location --request POST 'https://medusa-url.com/admin/regions/{region_id}/countries' \ + * --header 'Authorization: Bearer {api_token}' \ + * --header 'Content-Type: application/json' \ + * --data-raw '{ + * "country_code": "dk" + * }' + * security: + * - api_token: [] + * - cookie_auth: [] * tags: * - Region * responses: @@ -38,6 +63,18 @@ import { validator } from "../../../../utils/validator" * properties: * region: * $ref: "#/components/schemas/region" + * "400": + * $ref: "#/components/responses/400_error" + * "401": + * $ref: "#/components/responses/unauthorized" + * "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 { region_id } = req.params diff --git a/packages/medusa/src/api/routes/admin/regions/add-fulfillment-provider.ts b/packages/medusa/src/api/routes/admin/regions/add-fulfillment-provider.ts index 29b6fa76ef..bab882cd2f 100644 --- a/packages/medusa/src/api/routes/admin/regions/add-fulfillment-provider.ts +++ b/packages/medusa/src/api/routes/admin/regions/add-fulfillment-provider.ts @@ -24,6 +24,31 @@ import { validator } from "../../../../utils/validator" * provider_id: * description: "The ID of the Fulfillment Provider to add." * type: string + * x-codeSamples: + * - lang: JavaScript + * label: JS Client + * source: | + * import Medusa from "@medusajs/medusa-js" + * const medusa = new Medusa({ baseUrl: MEDUSA_BACKEND_URL, maxRetries: 3 }) + * // must be previously logged in or use api token + * medusa.admin.regions.addFulfillmentProvider(region_id, { + * provider_id: 'manual' + * }) + * .then(({ region }) => { + * console.log(region.id); + * }); + * - lang: Shell + * label: cURL + * source: | + * curl --location --request POST 'https://medusa-url.com/admin/regions/{id}/fulfillment-providers' \ + * --header 'Authorization: Bearer {api_token}' \ + * --header 'Content-Type: application/json' \ + * --data-raw '{ + * "provider_id": "manual" + * }' + * security: + * - api_token: [] + * - cookie_auth: [] * tags: * - Region * responses: @@ -35,6 +60,18 @@ import { validator } from "../../../../utils/validator" * properties: * region: * $ref: "#/components/schemas/region" + * "400": + * $ref: "#/components/responses/400_error" + * "401": + * $ref: "#/components/responses/unauthorized" + * "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 { region_id } = req.params diff --git a/packages/medusa/src/api/routes/admin/regions/add-payment-provider.ts b/packages/medusa/src/api/routes/admin/regions/add-payment-provider.ts index 8cb05a6b26..72cd656a0c 100644 --- a/packages/medusa/src/api/routes/admin/regions/add-payment-provider.ts +++ b/packages/medusa/src/api/routes/admin/regions/add-payment-provider.ts @@ -24,6 +24,31 @@ import { validator } from "../../../../utils/validator" * provider_id: * description: "The ID of the Payment Provider to add." * type: string + * x-codeSamples: + * - lang: JavaScript + * label: JS Client + * source: | + * import Medusa from "@medusajs/medusa-js" + * const medusa = new Medusa({ baseUrl: MEDUSA_BACKEND_URL, maxRetries: 3 }) + * // must be previously logged in or use api token + * medusa.admin.regions.addPaymentProvider(region_id, { + * provider_id: 'manual' + * }) + * .then(({ region }) => { + * console.log(region.id); + * }); + * - lang: Shell + * label: cURL + * source: | + * curl --location --request POST 'https://medusa-url.com/admin/regions/{id}/payment-providers' \ + * --header 'Authorization: Bearer {api_token}' \ + * --header 'Content-Type: application/json' \ + * --data-raw '{ + * "provider_id": "manual" + * }' + * security: + * - api_token: [] + * - cookie_auth: [] * tags: * - Region * responses: @@ -35,6 +60,18 @@ import { validator } from "../../../../utils/validator" * properties: * region: * $ref: "#/components/schemas/region" + * "400": + * $ref: "#/components/responses/400_error" + * "401": + * $ref: "#/components/responses/unauthorized" + * "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 { region_id } = req.params diff --git a/packages/medusa/src/api/routes/admin/regions/create-region.ts b/packages/medusa/src/api/routes/admin/regions/create-region.ts index 6027d52209..e62737c172 100644 --- a/packages/medusa/src/api/routes/admin/regions/create-region.ts +++ b/packages/medusa/src/api/routes/admin/regions/create-region.ts @@ -61,6 +61,53 @@ import { defaultAdminRegionRelations, defaultAdminRegionFields } from "." * type: array * items: * type: string + * x-codeSamples: + * - lang: JavaScript + * label: JS Client + * source: | + * import Medusa from "@medusajs/medusa-js" + * const medusa = new Medusa({ baseUrl: MEDUSA_BACKEND_URL, maxRetries: 3 }) + * // must be previously logged in or use api token + * medusa.admin.regions.create({ + * name: 'Europe', + * currency_code: 'eur', + * tax_rate: 0, + * payment_providers: [ + * 'manual' + * ], + * fulfillment_providers: [ + * 'manual' + * ], + * countries: [ + * 'DK' + * ] + * }) + * .then(({ region }) => { + * console.log(region.id); + * }); + * - lang: Shell + * label: cURL + * source: | + * curl --location --request POST 'https://medusa-url.com/admin/regions' \ + * --header 'Authorization: Bearer {api_token}' \ + * --header 'Content-Type: application/json' \ + * --data-raw '{ + * "name": "Europe", + * "currency_code": "eur", + * "tax_rate": 0, + * "payment_providers": [ + * "manual" + * ], + * "fulfillment_providers": [ + * "manual" + * ], + * "countries": [ + * "DK" + * ] + * }' + * security: + * - api_token: [] + * - cookie_auth: [] * tags: * - Region * responses: @@ -72,6 +119,18 @@ import { defaultAdminRegionRelations, defaultAdminRegionFields } from "." * properties: * region: * $ref: "#/components/schemas/region" + * "400": + * $ref: "#/components/responses/400_error" + * "401": + * $ref: "#/components/responses/unauthorized" + * "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 validated = await validator(AdminPostRegionsReq, req.body) diff --git a/packages/medusa/src/api/routes/admin/regions/delete-region.ts b/packages/medusa/src/api/routes/admin/regions/delete-region.ts index 54629ca7c9..ec6715c642 100644 --- a/packages/medusa/src/api/routes/admin/regions/delete-region.ts +++ b/packages/medusa/src/api/routes/admin/regions/delete-region.ts @@ -9,6 +9,25 @@ import RegionService from "../../../../services/region" * x-authenticated: true * parameters: * - (path) id=* {string} The ID of the Region. + * x-codeSamples: + * - lang: JavaScript + * label: JS Client + * source: | + * import Medusa from "@medusajs/medusa-js" + * const medusa = new Medusa({ baseUrl: MEDUSA_BACKEND_URL, maxRetries: 3 }) + * // must be previously logged in or use api token + * medusa.admin.regions.delete(region_id) + * .then(({ id, object, deleted }) => { + * console.log(id); + * }); + * - lang: Shell + * label: cURL + * source: | + * curl --location --request DELETE 'https://medusa-url.com/admin/regions/{id}' \ + * --header 'Authorization: Bearer {api_token}' + * security: + * - api_token: [] + * - cookie_auth: [] * tags: * - Region * responses: @@ -29,6 +48,18 @@ import RegionService from "../../../../services/region" * type: boolean * description: Whether or not the items were deleted. * default: true + * "400": + * $ref: "#/components/responses/400_error" + * "401": + * $ref: "#/components/responses/unauthorized" + * "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 { region_id } = req.params diff --git a/packages/medusa/src/api/routes/admin/regions/get-fulfillment-options.ts b/packages/medusa/src/api/routes/admin/regions/get-fulfillment-options.ts index aef8f97159..0061941f06 100644 --- a/packages/medusa/src/api/routes/admin/regions/get-fulfillment-options.ts +++ b/packages/medusa/src/api/routes/admin/regions/get-fulfillment-options.ts @@ -10,6 +10,25 @@ import RegionService from "../../../../services/region" * x-authenticated: true * parameters: * - (path) id=* {string} The ID of the Region. + * x-codeSamples: + * - lang: JavaScript + * label: JS Client + * source: | + * import Medusa from "@medusajs/medusa-js" + * const medusa = new Medusa({ baseUrl: MEDUSA_BACKEND_URL, maxRetries: 3 }) + * // must be previously logged in or use api token + * medusa.admin.regions.retrieveFulfillmentOptions(region_id) + * .then(({ fulfillment_options }) => { + * console.log(fulfillment_options.length); + * }); + * - lang: Shell + * label: cURL + * source: | + * curl --location --request GET 'https://medusa-url.com/admin/regions/{id}/fulfillment-options' \ + * --header 'Authorization: Bearer {api_token}' + * security: + * - api_token: [] + * - cookie_auth: [] * tags: * - Region * responses: @@ -33,6 +52,18 @@ import RegionService from "../../../../services/region" * - id: "manual-fulfillment" * - id: "manual-fulfillment-return" * is_return: true + * "400": + * $ref: "#/components/responses/400_error" + * "401": + * $ref: "#/components/responses/unauthorized" + * "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 { region_id } = req.params diff --git a/packages/medusa/src/api/routes/admin/regions/get-region.ts b/packages/medusa/src/api/routes/admin/regions/get-region.ts index 96af4b1322..e52aa5234c 100644 --- a/packages/medusa/src/api/routes/admin/regions/get-region.ts +++ b/packages/medusa/src/api/routes/admin/regions/get-region.ts @@ -10,6 +10,25 @@ import RegionService from "../../../../services/region" * x-authenticated: true * parameters: * - (path) id=* {string} The ID of the Region. + * x-codeSamples: + * - lang: JavaScript + * label: JS Client + * source: | + * import Medusa from "@medusajs/medusa-js" + * const medusa = new Medusa({ baseUrl: MEDUSA_BACKEND_URL, maxRetries: 3 }) + * // must be previously logged in or use api token + * medusa.admin.regions.retrieve(region_id) + * .then(({ region }) => { + * console.log(region.id); + * }); + * - lang: Shell + * label: cURL + * source: | + * curl --location --request GET 'https://medusa-url.com/admin/regions/{id}' \ + * --header 'Authorization: Bearer {api_token}' + * security: + * - api_token: [] + * - cookie_auth: [] * tags: * - Region * responses: @@ -21,6 +40,18 @@ import RegionService from "../../../../services/region" * properties: * region: * $ref: "#/components/schemas/region" + * "400": + * $ref: "#/components/responses/400_error" + * "401": + * $ref: "#/components/responses/unauthorized" + * "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 { region_id } = req.params diff --git a/packages/medusa/src/api/routes/admin/regions/list-regions.ts b/packages/medusa/src/api/routes/admin/regions/list-regions.ts index 846e788236..816a396fe4 100644 --- a/packages/medusa/src/api/routes/admin/regions/list-regions.ts +++ b/packages/medusa/src/api/routes/admin/regions/list-regions.ts @@ -47,6 +47,25 @@ import { validator } from "../../../../utils/validator" * type: object * required: false * description: Date comparison for when resulting region was deleted, i.e. less than, greater than etc. + * x-codeSamples: + * - lang: JavaScript + * label: JS Client + * source: | + * import Medusa from "@medusajs/medusa-js" + * const medusa = new Medusa({ baseUrl: MEDUSA_BACKEND_URL, maxRetries: 3 }) + * // must be previously logged in or use api token + * medusa.admin.regions.list() + * .then(({ regions, limit, offset, count }) => { + * console.log(regions.length); + * }); + * - lang: Shell + * label: cURL + * source: | + * curl --location --request GET 'https://medusa-url.com/admin/regions' \ + * --header 'Authorization: Bearer {api_token}' + * security: + * - api_token: [] + * - cookie_auth: [] * tags: * - Region * responses: @@ -69,6 +88,18 @@ import { validator } from "../../../../utils/validator" * limit: * type: integer * description: The number of items per page + * "400": + * $ref: "#/components/responses/400_error" + * "401": + * $ref: "#/components/responses/unauthorized" + * "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 validated = await validator(AdminGetRegionsParams, req.query) diff --git a/packages/medusa/src/api/routes/admin/regions/remove-country.ts b/packages/medusa/src/api/routes/admin/regions/remove-country.ts index 42bc3ecc31..820fb3df99 100644 --- a/packages/medusa/src/api/routes/admin/regions/remove-country.ts +++ b/packages/medusa/src/api/routes/admin/regions/remove-country.ts @@ -20,6 +20,25 @@ import RegionService from "../../../../services/region" * externalDocs: * url: https://en.wikipedia.org/wiki/ISO_4217#Active_codes * description: See a list of codes. + * x-codeSamples: + * - lang: JavaScript + * label: JS Client + * source: | + * import Medusa from "@medusajs/medusa-js" + * const medusa = new Medusa({ baseUrl: MEDUSA_BACKEND_URL, maxRetries: 3 }) + * // must be previously logged in or use api token + * medusa.admin.regions.deleteCountry(region_id, 'dk') + * .then(({ region }) => { + * console.log(region.id); + * }); + * - lang: Shell + * label: cURL + * source: | + * curl --location --request DELETE 'https://medusa-url.com/admin/regions/{id}/countries/dk' \ + * --header 'Authorization: Bearer {api_token}' + * security: + * - api_token: [] + * - cookie_auth: [] * tags: * - Region * responses: @@ -31,6 +50,18 @@ import RegionService from "../../../../services/region" * properties: * region: * $ref: "#/components/schemas/region" + * "400": + * $ref: "#/components/responses/400_error" + * "401": + * $ref: "#/components/responses/unauthorized" + * "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 { region_id, country_code } = req.params diff --git a/packages/medusa/src/api/routes/admin/regions/remove-fulfillment-provider.ts b/packages/medusa/src/api/routes/admin/regions/remove-fulfillment-provider.ts index 96e778bbf9..458c7928a3 100644 --- a/packages/medusa/src/api/routes/admin/regions/remove-fulfillment-provider.ts +++ b/packages/medusa/src/api/routes/admin/regions/remove-fulfillment-provider.ts @@ -12,6 +12,25 @@ import RegionService from "../../../../services/region" * parameters: * - (path) id=* {string} The ID of the Region. * - (path) provider_id=* {string} The ID of the Fulfillment Provider. + * x-codeSamples: + * - lang: JavaScript + * label: JS Client + * source: | + * import Medusa from "@medusajs/medusa-js" + * const medusa = new Medusa({ baseUrl: MEDUSA_BACKEND_URL, maxRetries: 3 }) + * // must be previously logged in or use api token + * medusa.admin.regions.deleteFulfillmentProvider(region_id, 'manual') + * .then(({ region }) => { + * console.log(region.id); + * }); + * - lang: Shell + * label: cURL + * source: | + * curl --location --request DELETE 'https://medusa-url.com/admin/regions/{id}/fulfillment-providers/manual' \ + * --header 'Authorization: Bearer {api_token}' + * security: + * - api_token: [] + * - cookie_auth: [] * tags: * - Region * responses: @@ -23,6 +42,18 @@ import RegionService from "../../../../services/region" * properties: * region: * $ref: "#/components/schemas/region" + * "400": + * $ref: "#/components/responses/400_error" + * "401": + * $ref: "#/components/responses/unauthorized" + * "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 { region_id, provider_id } = req.params diff --git a/packages/medusa/src/api/routes/admin/regions/remove-payment-provider.ts b/packages/medusa/src/api/routes/admin/regions/remove-payment-provider.ts index 7faed2b11b..04841566a6 100644 --- a/packages/medusa/src/api/routes/admin/regions/remove-payment-provider.ts +++ b/packages/medusa/src/api/routes/admin/regions/remove-payment-provider.ts @@ -12,6 +12,25 @@ import RegionService from "../../../../services/region" * parameters: * - (path) id=* {string} The ID of the Region. * - (path) provider_id=* {string} The ID of the Payment Provider. + * x-codeSamples: + * - lang: JavaScript + * label: JS Client + * source: | + * import Medusa from "@medusajs/medusa-js" + * const medusa = new Medusa({ baseUrl: MEDUSA_BACKEND_URL, maxRetries: 3 }) + * // must be previously logged in or use api token + * medusa.admin.regions.deletePaymentProvider(region_id, 'manual') + * .then(({ region }) => { + * console.log(region.id); + * }); + * - lang: Shell + * label: cURL + * source: | + * curl --location --request DELETE 'https://medusa-url.com/admin/regions/{id}/payment-providers/manual' \ + * --header 'Authorization: Bearer {api_token}' + * security: + * - api_token: [] + * - cookie_auth: [] * tags: * - Region * responses: @@ -23,6 +42,18 @@ import RegionService from "../../../../services/region" * properties: * region: * $ref: "#/components/schemas/region" + * "400": + * $ref: "#/components/responses/400_error" + * "401": + * $ref: "#/components/responses/unauthorized" + * "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 { region_id, provider_id } = req.params diff --git a/packages/medusa/src/api/routes/admin/regions/update-region.ts b/packages/medusa/src/api/routes/admin/regions/update-region.ts index 7cbce73dfe..5a2189a678 100644 --- a/packages/medusa/src/api/routes/admin/regions/update-region.ts +++ b/packages/medusa/src/api/routes/admin/regions/update-region.ts @@ -64,6 +64,31 @@ import { defaultAdminRegionRelations, defaultAdminRegionFields } from "." * type: array * items: * type: string + * x-codeSamples: + * - lang: JavaScript + * label: JS Client + * source: | + * import Medusa from "@medusajs/medusa-js" + * const medusa = new Medusa({ baseUrl: MEDUSA_BACKEND_URL, maxRetries: 3 }) + * // must be previously logged in or use api token + * medusa.admin.regions.update(region_id, { + * name: 'Europe' + * }) + * .then(({ region }) => { + * console.log(region.id); + * }); + * - lang: Shell + * label: cURL + * source: | + * curl --location --request POST 'https://medusa-url.com/admin/regions/{id}' \ + * --header 'Authorization: Bearer {api_token}' \ + * --header 'Content-Type: application/json' \ + * --data-raw '{ + * "name": "Europe" + * }' + * security: + * - api_token: [] + * - cookie_auth: [] * tags: * - Region * responses: @@ -75,6 +100,18 @@ import { defaultAdminRegionRelations, defaultAdminRegionFields } from "." * properties: * region: * $ref: "#/components/schemas/region" + * "400": + * $ref: "#/components/responses/400_error" + * "401": + * $ref: "#/components/responses/unauthorized" + * "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 { region_id } = req.params diff --git a/packages/medusa/src/api/routes/admin/return-reasons/create-reason.ts b/packages/medusa/src/api/routes/admin/return-reasons/create-reason.ts index c23c7b2f6c..343a7a78c6 100644 --- a/packages/medusa/src/api/routes/admin/return-reasons/create-reason.ts +++ b/packages/medusa/src/api/routes/admin/return-reasons/create-reason.ts @@ -37,6 +37,33 @@ import { EntityManager } from "typeorm" * metadata: * description: An optional set of key-value pairs with additional information. * type: object + * x-codeSamples: + * - lang: JavaScript + * label: JS Client + * source: | + * import Medusa from "@medusajs/medusa-js" + * const medusa = new Medusa({ baseUrl: MEDUSA_BACKEND_URL, maxRetries: 3 }) + * // must be previously logged in or use api token + * medusa.admin.returnReasons.create({ + * label: 'Damaged', + * value: 'damaged' + * }) + * .then(({ return_reason }) => { + * console.log(return_reason.id); + * }); + * - lang: Shell + * label: cURL + * source: | + * curl --location --request POST 'https://medusa-url.com/admin/return-reasons' \ + * --header 'Authorization: Bearer {api_token}' \ + * --header 'Content-Type: application/json' \ + * --data-raw '{ + * "label": "Damaged", + * "value": "damaged" + * }' + * security: + * - api_token: [] + * - cookie_auth: [] * tags: * - Return Reason * responses: @@ -48,6 +75,18 @@ import { EntityManager } from "typeorm" * properties: * return_reason: * $ref: "#/components/schemas/return_reason" + * "400": + * $ref: "#/components/responses/400_error" + * "401": + * $ref: "#/components/responses/unauthorized" + * "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 validated = await validator(AdminPostReturnReasonsReq, req.body) diff --git a/packages/medusa/src/api/routes/admin/return-reasons/delete-reason.ts b/packages/medusa/src/api/routes/admin/return-reasons/delete-reason.ts index e8d17aab9c..c27b7677f4 100644 --- a/packages/medusa/src/api/routes/admin/return-reasons/delete-reason.ts +++ b/packages/medusa/src/api/routes/admin/return-reasons/delete-reason.ts @@ -9,6 +9,25 @@ import { ReturnReasonService } from "../../../../services" * x-authenticated: true * parameters: * - (path) id=* {string} The ID of the return reason + * x-codeSamples: + * - lang: JavaScript + * label: JS Client + * source: | + * import Medusa from "@medusajs/medusa-js" + * const medusa = new Medusa({ baseUrl: MEDUSA_BACKEND_URL, maxRetries: 3 }) + * // must be previously logged in or use api token + * medusa.admin.returnReasons.delete(return_reason_id) + * .then(({ id, object, deleted }) => { + * console.log(id); + * }); + * - lang: Shell + * label: cURL + * source: | + * curl --location --request DELETE 'https://medusa-url.com/admin/return-reasons/{id}' \ + * --header 'Authorization: Bearer {api_token}' + * security: + * - api_token: [] + * - cookie_auth: [] * tags: * - Return Reason * responses: @@ -29,6 +48,18 @@ import { ReturnReasonService } from "../../../../services" * type: boolean * description: Whether or not the items were deleted. * default: true + * "400": + * $ref: "#/components/responses/400_error" + * "401": + * $ref: "#/components/responses/unauthorized" + * "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 { id } = req.params diff --git a/packages/medusa/src/api/routes/admin/return-reasons/get-reason.ts b/packages/medusa/src/api/routes/admin/return-reasons/get-reason.ts index 260b967b78..581ca1cbc0 100644 --- a/packages/medusa/src/api/routes/admin/return-reasons/get-reason.ts +++ b/packages/medusa/src/api/routes/admin/return-reasons/get-reason.ts @@ -13,6 +13,25 @@ import { ReturnReasonService } from "../../../../services" * x-authenticated: true * parameters: * - (path) id=* {string} The ID of the Return Reason. + * x-codeSamples: + * - lang: JavaScript + * label: JS Client + * source: | + * import Medusa from "@medusajs/medusa-js" + * const medusa = new Medusa({ baseUrl: MEDUSA_BACKEND_URL, maxRetries: 3 }) + * // must be previously logged in or use api token + * medusa.admin.returnReasons.retrieve(return_reason_id) + * .then(({ return_reason }) => { + * console.log(return_reason.id); + * }); + * - lang: Shell + * label: cURL + * source: | + * curl --location --request GET 'https://medusa-url.com/admin/return-reasons/{id}' \ + * --header 'Authorization: Bearer {api_token}' + * security: + * - api_token: [] + * - cookie_auth: [] * tags: * - Return Reason * responses: @@ -24,6 +43,18 @@ import { ReturnReasonService } from "../../../../services" * properties: * return_reason: * $ref: "#/components/schemas/return_reason" + * "400": + * $ref: "#/components/responses/400_error" + * "401": + * $ref: "#/components/responses/unauthorized" + * "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 { id } = req.params diff --git a/packages/medusa/src/api/routes/admin/return-reasons/list-reasons.ts b/packages/medusa/src/api/routes/admin/return-reasons/list-reasons.ts index 861e387370..afea7d1e0f 100644 --- a/packages/medusa/src/api/routes/admin/return-reasons/list-reasons.ts +++ b/packages/medusa/src/api/routes/admin/return-reasons/list-reasons.ts @@ -12,6 +12,25 @@ import { FindConfig, Selector } from "../../../../types/common" * summary: "List Return Reasons" * description: "Retrieves a list of Return Reasons." * x-authenticated: true + * x-codeSamples: + * - lang: JavaScript + * label: JS Client + * source: | + * import Medusa from "@medusajs/medusa-js" + * const medusa = new Medusa({ baseUrl: MEDUSA_BACKEND_URL, maxRetries: 3 }) + * // must be previously logged in or use api token + * medusa.admin.returnReasons.list() + * .then(({ return_reasons }) => { + * console.log(return_reasons.length); + * }); + * - lang: Shell + * label: cURL + * source: | + * curl --location --request GET 'https://medusa-url.com/admin/return-reasons' \ + * --header 'Authorization: Bearer {api_token}' + * security: + * - api_token: [] + * - cookie_auth: [] * tags: * - Return Reason * responses: @@ -25,6 +44,18 @@ import { FindConfig, Selector } from "../../../../types/common" * type: array * items: * $ref: "#/components/schemas/return_reason" + * "400": + * $ref: "#/components/responses/400_error" + * "401": + * $ref: "#/components/responses/unauthorized" + * "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 returnReasonService: ReturnReasonService = req.scope.resolve( diff --git a/packages/medusa/src/api/routes/admin/return-reasons/update-reason.ts b/packages/medusa/src/api/routes/admin/return-reasons/update-reason.ts index 71df342bde..4b7094b95f 100644 --- a/packages/medusa/src/api/routes/admin/return-reasons/update-reason.ts +++ b/packages/medusa/src/api/routes/admin/return-reasons/update-reason.ts @@ -33,6 +33,31 @@ import { EntityManager } from "typeorm" * metadata: * description: An optional set of key-value pairs with additional information. * type: object + * x-codeSamples: + * - lang: JavaScript + * label: JS Client + * source: | + * import Medusa from "@medusajs/medusa-js" + * const medusa = new Medusa({ baseUrl: MEDUSA_BACKEND_URL, maxRetries: 3 }) + * // must be previously logged in or use api token + * medusa.admin.returnReasons.update(return_reason_id, { + * label: 'Damaged' + * }) + * .then(({ return_reason }) => { + * console.log(return_reason.id); + * }); + * - lang: Shell + * label: cURL + * source: | + * curl --location --request POST 'https://medusa-url.com/admin/return-reasons/{id}' \ + * --header 'Authorization: Bearer {api_token}' \ + * --header 'Content-Type: application/json' \ + * --data-raw '{ + * "label": "Damaged" + * }' + * security: + * - api_token: [] + * - cookie_auth: [] * tags: * - Return Reason * responses: @@ -44,6 +69,18 @@ import { EntityManager } from "typeorm" * properties: * return_reason: * $ref: "#/components/schemas/return_reason" + * "400": + * $ref: "#/components/responses/400_error" + * "401": + * $ref: "#/components/responses/unauthorized" + * "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 { id } = req.params diff --git a/packages/medusa/src/api/routes/admin/returns/cancel-return.ts b/packages/medusa/src/api/routes/admin/returns/cancel-return.ts index 38d6d2ad08..7096d5246f 100644 --- a/packages/medusa/src/api/routes/admin/returns/cancel-return.ts +++ b/packages/medusa/src/api/routes/admin/returns/cancel-return.ts @@ -12,6 +12,25 @@ import { EntityManager } from "typeorm" * description: "Registers a Return as canceled." * parameters: * - (path) id=* {string} The ID of the Return. + * x-codeSamples: + * - lang: JavaScript + * label: JS Client + * source: | + * import Medusa from "@medusajs/medusa-js" + * const medusa = new Medusa({ baseUrl: MEDUSA_BACKEND_URL, maxRetries: 3 }) + * // must be previously logged in or use api token + * medusa.admin.returns.cancel(return_id) + * .then(({ order }) => { + * console.log(order.id); + * }); + * - lang: Shell + * label: cURL + * source: | + * curl --location --request POST 'https://medusa-url.com/admin/returns/{id}/cancel' \ + * --header 'Authorization: Bearer {api_token}' + * security: + * - api_token: [] + * - cookie_auth: [] * tags: * - Return * responses: @@ -23,6 +42,18 @@ import { EntityManager } from "typeorm" * properties: * order: * $ref: "#/components/schemas/order" + * "400": + * $ref: "#/components/responses/400_error" + * "401": + * $ref: "#/components/responses/unauthorized" + * "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 { id } = req.params diff --git a/packages/medusa/src/api/routes/admin/returns/list-returns.ts b/packages/medusa/src/api/routes/admin/returns/list-returns.ts index 3f0d3124ab..491ab656fc 100644 --- a/packages/medusa/src/api/routes/admin/returns/list-returns.ts +++ b/packages/medusa/src/api/routes/admin/returns/list-returns.ts @@ -14,6 +14,25 @@ import { Return } from "../../../../models" * parameters: * - (query) limit=50 {number} The upper limit for the amount of responses returned. * - (query) offset=0 {number} The offset of the list returned. + * x-codeSamples: + * - lang: JavaScript + * label: JS Client + * source: | + * import Medusa from "@medusajs/medusa-js" + * const medusa = new Medusa({ baseUrl: MEDUSA_BACKEND_URL, maxRetries: 3 }) + * // must be previously logged in or use api token + * medusa.admin.returns.list() + * .then(({ returns, limit, offset, count }) => { + * console.log(returns.length); + * }); + * - lang: Shell + * label: cURL + * source: | + * curl --location --request GET 'https://medusa-url.com/admin/returns' \ + * --header 'Authorization: Bearer {api_token}' + * security: + * - api_token: [] + * - cookie_auth: [] * tags: * - Return * responses: @@ -36,6 +55,18 @@ import { Return } from "../../../../models" * limit: * type: integer * description: The number of items per page + * "400": + * $ref: "#/components/responses/400_error" + * "401": + * $ref: "#/components/responses/unauthorized" + * "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 returnService: ReturnService = req.scope.resolve("returnService") diff --git a/packages/medusa/src/api/routes/admin/returns/receive-return.ts b/packages/medusa/src/api/routes/admin/returns/receive-return.ts index c804a95460..9a9b1690a3 100644 --- a/packages/medusa/src/api/routes/admin/returns/receive-return.ts +++ b/packages/medusa/src/api/routes/admin/returns/receive-return.ts @@ -43,6 +43,41 @@ import { isDefined } from "../../../../utils" * refund: * description: The amount to refund. * type: number + * x-codeSamples: + * - lang: JavaScript + * label: JS Client + * source: | + * import Medusa from "@medusajs/medusa-js" + * const medusa = new Medusa({ baseUrl: MEDUSA_BACKEND_URL, maxRetries: 3 }) + * // must be previously logged in or use api token + * medusa.admin.returns.receive(return_id, { + * items: [ + * { + * item_id, + * quantity: 1 + * } + * ] + * }) + * .then(({ return }) => { + * console.log(return.id); + * }); + * - lang: Shell + * label: cURL + * source: | + * curl --location --request POST 'https://medusa-url.com/admin/returns/{id}/receive' \ + * --header 'Authorization: Bearer {api_token}' \ + * --header 'Content-Type: application/json' \ + * --data-raw '{ + * "items": [ + * { + * "item_id": "asafg", + * "quantity": 1 + * } + * ] + * }' + * security: + * - api_token: [] + * - cookie_auth: [] * tags: * - Return * responses: @@ -54,6 +89,18 @@ import { isDefined } from "../../../../utils" * properties: * return: * $ref: "#/components/schemas/return" + * "400": + * $ref: "#/components/responses/400_error" + * "401": + * $ref: "#/components/responses/unauthorized" + * "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 { id } = req.params diff --git a/packages/medusa/src/api/routes/admin/sales-channels/add-product-batch.ts b/packages/medusa/src/api/routes/admin/sales-channels/add-product-batch.ts index f5dc460358..98a6fea8c4 100644 --- a/packages/medusa/src/api/routes/admin/sales-channels/add-product-batch.ts +++ b/packages/medusa/src/api/routes/admin/sales-channels/add-product-batch.ts @@ -32,6 +32,39 @@ import { Type } from "class-transformer" * id: * type: string * description: The ID of the product + * x-codeSamples: + * - lang: JavaScript + * label: JS Client + * source: | + * import Medusa from "@medusajs/medusa-js" + * const medusa = new Medusa({ baseUrl: MEDUSA_BACKEND_URL, maxRetries: 3 }) + * // must be previously logged in or use api token + * medusa.admin.salesChannels.addProducts(sales_channel_id, { + * product_ids: [ + * { + * id: product_id + * } + * ] + * }) + * .then(({ sales_channel }) => { + * console.log(sales_channel.id); + * }); + * - lang: Shell + * label: cURL + * source: | + * curl --location --request POST 'https://medusa-url.com/admin/sales-channels/afasf/products/batch' \ + * --header 'Authorization: Bearer {api_token}' \ + * --header 'Content-Type: application/json' \ + * --data-raw '{ + * "product_ids": [ + * { + * "id": "{product_id}" + * } + * ] + * }' + * security: + * - api_token: [] + * - cookie_auth: [] * tags: * - Sales Channel * responses: @@ -43,6 +76,18 @@ import { Type } from "class-transformer" * properties: * sales_channel: * $ref: "#/components/schemas/sales_channel" + * "400": + * $ref: "#/components/responses/400_error" + * "401": + * $ref: "#/components/responses/unauthorized" + * "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: Request, res: Response): Promise => { const validatedBody = diff --git a/packages/medusa/src/api/routes/admin/sales-channels/create-sales-channel.ts b/packages/medusa/src/api/routes/admin/sales-channels/create-sales-channel.ts index 66254dfc1e..36af725475 100644 --- a/packages/medusa/src/api/routes/admin/sales-channels/create-sales-channel.ts +++ b/packages/medusa/src/api/routes/admin/sales-channels/create-sales-channel.ts @@ -27,6 +27,32 @@ import SalesChannelService from "../../../../services/sales-channel" * is_disabled: * description: Whether the Sales Channel is disabled or not. * type: boolean + * x-codeSamples: + * - lang: JavaScript + * label: JS Client + * source: | + * import Medusa from "@medusajs/medusa-js" + * const medusa = new Medusa({ baseUrl: MEDUSA_BACKEND_URL, maxRetries: 3 }) + * // must be previously logged in or use api token + * medusa.admin.salesChannels.create({ + * name: 'App', + * description: 'Mobile app' + * }) + * .then(({ sales_channel }) => { + * console.log(sales_channel.id); + * }); + * - lang: Shell + * label: cURL + * source: | + * curl --location --request POST 'https://medusa-url.com/admin/sales-channels' \ + * --header 'Authorization: Bearer {api_token}' \ + * --header 'Content-Type: application/json' \ + * --data-raw '{ + * "name": "App" + * }' + * security: + * - api_token: [] + * - cookie_auth: [] * tags: * - Sales Channel * responses: @@ -38,6 +64,18 @@ import SalesChannelService from "../../../../services/sales-channel" * properties: * sales_channel: * $ref: "#/components/schemas/sales_channel" + * "400": + * $ref: "#/components/responses/400_error" + * "401": + * $ref: "#/components/responses/unauthorized" + * "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: Request, res: Response) => { diff --git a/packages/medusa/src/api/routes/admin/sales-channels/delete-products-batch.ts b/packages/medusa/src/api/routes/admin/sales-channels/delete-products-batch.ts index c41b5ed022..d7983c2710 100644 --- a/packages/medusa/src/api/routes/admin/sales-channels/delete-products-batch.ts +++ b/packages/medusa/src/api/routes/admin/sales-channels/delete-products-batch.ts @@ -32,6 +32,39 @@ import { Type } from "class-transformer" * id: * description: The ID of a product * type: string + * x-codeSamples: + * - lang: JavaScript + * label: JS Client + * source: | + * import Medusa from "@medusajs/medusa-js" + * const medusa = new Medusa({ baseUrl: MEDUSA_BACKEND_URL, maxRetries: 3 }) + * // must be previously logged in or use api token + * medusa.admin.salesChannels.removeProducts(sales_channel_id, { + * product_ids: [ + * { + * id: product_id + * } + * ] + * }) + * .then(({ sales_channel }) => { + * console.log(sales_channel.id); + * }); + * - lang: Shell + * label: cURL + * source: | + * curl --location --request DELETE 'https://medusa-url.com/admin/sales-channels/{id}/products/batch' \ + * --header 'Authorization: Bearer {api_token}' \ + * --header 'Content-Type: application/json' \ + * --data-raw '{ + * "product_ids": [ + * { + * "id": "{product_id}" + * } + * ] + * }' + * security: + * - api_token: [] + * - cookie_auth: [] * tags: * - Sales Channel * responses: @@ -43,6 +76,18 @@ import { Type } from "class-transformer" * properties: * sales_channel: * $ref: "#/components/schemas/sales_channel" + * "400": + * $ref: "#/components/responses/400_error" + * "401": + * $ref: "#/components/responses/unauthorized" + * "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: Request, res: Response) => { diff --git a/packages/medusa/src/api/routes/admin/sales-channels/delete-sales-channel.ts b/packages/medusa/src/api/routes/admin/sales-channels/delete-sales-channel.ts index 838a9e098d..c11aed6442 100644 --- a/packages/medusa/src/api/routes/admin/sales-channels/delete-sales-channel.ts +++ b/packages/medusa/src/api/routes/admin/sales-channels/delete-sales-channel.ts @@ -11,6 +11,25 @@ import { SalesChannelService } from "../../../../services/" * x-authenticated: true * parameters: * - (path) id=* {string} The ID of the Sales channel. + * x-codeSamples: + * - lang: JavaScript + * label: JS Client + * source: | + * import Medusa from "@medusajs/medusa-js" + * const medusa = new Medusa({ baseUrl: MEDUSA_BACKEND_URL, maxRetries: 3 }) + * // must be previously logged in or use api token + * medusa.admin.salesChannels.delete(sales_channel_id) + * .then(({ id, object, deleted }) => { + * console.log(id); + * }); + * - lang: Shell + * label: cURL + * source: | + * curl --location --request DELETE 'https://medusa-url.com/admin/sales-channels/{id}' \ + * --header 'Authorization: Bearer {api_token}' + * security: + * - api_token: [] + * - cookie_auth: [] * tags: * - Sales Channel * responses: @@ -31,6 +50,18 @@ import { SalesChannelService } from "../../../../services/" * type: boolean * description: Whether or not the items were deleted. * default: true + * "400": + * $ref: "#/components/responses/400_error" + * "401": + * $ref: "#/components/responses/unauthorized" + * "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: Request, res: Response): Promise => { const { id } = req.params diff --git a/packages/medusa/src/api/routes/admin/sales-channels/get-sales-channel.ts b/packages/medusa/src/api/routes/admin/sales-channels/get-sales-channel.ts index f9819c31be..d5511740e9 100644 --- a/packages/medusa/src/api/routes/admin/sales-channels/get-sales-channel.ts +++ b/packages/medusa/src/api/routes/admin/sales-channels/get-sales-channel.ts @@ -10,6 +10,25 @@ import { SalesChannelService } from "../../../../services" * x-authenticated: true * parameters: * - (path) id=* {string} The ID of the Sales channel. + * x-codeSamples: + * - lang: JavaScript + * label: JS Client + * source: | + * import Medusa from "@medusajs/medusa-js" + * const medusa = new Medusa({ baseUrl: MEDUSA_BACKEND_URL, maxRetries: 3 }) + * // must be previously logged in or use api token + * medusa.admin.salesChannels.retrieve(sales_channel_id) + * .then(({ sales_channel }) => { + * console.log(sales_channel.id); + * }); + * - lang: Shell + * label: cURL + * source: | + * curl --location --request GET 'https://medusa-url.com/admin/sales-channels/{id}' \ + * --header 'Authorization: Bearer {api_token}' + * security: + * - api_token: [] + * - cookie_auth: [] * tags: * - Sales Channel * responses: @@ -21,6 +40,18 @@ import { SalesChannelService } from "../../../../services" * properties: * sales_channel: * $ref: "#/components/schemas/sales_channel" + * "400": + * $ref: "#/components/responses/400_error" + * "401": + * $ref: "#/components/responses/unauthorized" + * "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: Request, res: Response): Promise => { const { id } = req.params diff --git a/packages/medusa/src/api/routes/admin/sales-channels/list-sales-channels.ts b/packages/medusa/src/api/routes/admin/sales-channels/list-sales-channels.ts index b064bb4d02..f1aa54f16f 100644 --- a/packages/medusa/src/api/routes/admin/sales-channels/list-sales-channels.ts +++ b/packages/medusa/src/api/routes/admin/sales-channels/list-sales-channels.ts @@ -91,6 +91,25 @@ import { removeUndefinedProperties } from "../../../../utils" * - (query) limit=20 {integer} Limit the number of sales channels returned. * - (query) expand {string} (Comma separated) Which fields should be expanded in each sales channel of the result. * - (query) fields {string} (Comma separated) Which fields should be included in each sales channel of the result. + * x-codeSamples: + * - lang: JavaScript + * label: JS Client + * source: | + * import Medusa from "@medusajs/medusa-js" + * const medusa = new Medusa({ baseUrl: MEDUSA_BACKEND_URL, maxRetries: 3 }) + * // must be previously logged in or use api token + * medusa.admin.salesChannels.list() + * .then(({ sales_channels, limit, offset, count }) => { + * console.log(sales_channels.length); + * }); + * - lang: Shell + * label: cURL + * source: | + * curl --location --request GET 'https://medusa-url.com/admin/sales-channels' \ + * --header 'Authorization: Bearer {api_token}' + * security: + * - api_token: [] + * - cookie_auth: [] * tags: * - Sales Channel * responses: @@ -113,6 +132,18 @@ import { removeUndefinedProperties } from "../../../../utils" * limit: * type: integer * description: The number of items per page + * "400": + * $ref: "#/components/responses/400_error" + * "401": + * $ref: "#/components/responses/unauthorized" + * "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: Request, res: Response) => { const salesChannelService: SalesChannelService = req.scope.resolve( diff --git a/packages/medusa/src/api/routes/admin/sales-channels/update-sales-channel.ts b/packages/medusa/src/api/routes/admin/sales-channels/update-sales-channel.ts index 502a38c9e9..b924922596 100644 --- a/packages/medusa/src/api/routes/admin/sales-channels/update-sales-channel.ts +++ b/packages/medusa/src/api/routes/admin/sales-channels/update-sales-channel.ts @@ -26,6 +26,31 @@ import { EntityManager } from "typeorm" * is_disabled: * type: boolean * description: Indication of if the sales channel is active. + * x-codeSamples: + * - lang: JavaScript + * label: JS Client + * source: | + * import Medusa from "@medusajs/medusa-js" + * const medusa = new Medusa({ baseUrl: MEDUSA_BACKEND_URL, maxRetries: 3 }) + * // must be previously logged in or use api token + * medusa.admin.salesChannels.update(sales_channel_id, { + * name: 'App' + * }) + * .then(({ sales_channel }) => { + * console.log(sales_channel.id); + * }); + * - lang: Shell + * label: cURL + * source: | + * curl --location --request POST 'https://medusa-url.com/admin/sales-channels/{id}' \ + * --header 'Authorization: Bearer {api_token}' \ + * --header 'Content-Type: application/json' \ + * --data-raw '{ + * "name": "App" + * }' + * security: + * - api_token: [] + * - cookie_auth: [] * tags: * - Sales Channel * responses: @@ -37,6 +62,18 @@ import { EntityManager } from "typeorm" * properties: * sales_channel: * $ref: "#/components/schemas/sales_channel" + * "400": + * $ref: "#/components/responses/400_error" + * "401": + * $ref: "#/components/responses/unauthorized" + * "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: Request, res: Response) => { const { id } = req.params diff --git a/packages/medusa/src/api/routes/admin/shipping-options/create-shipping-option.ts b/packages/medusa/src/api/routes/admin/shipping-options/create-shipping-option.ts index 347c810712..ee617d8800 100644 --- a/packages/medusa/src/api/routes/admin/shipping-options/create-shipping-option.ts +++ b/packages/medusa/src/api/routes/admin/shipping-options/create-shipping-option.ts @@ -81,6 +81,40 @@ import { EntityManager } from "typeorm" * metadata: * description: An optional set of key-value pairs with additional information. * type: object + * x-codeSamples: + * - lang: JavaScript + * label: JS Client + * source: | + * import Medusa from "@medusajs/medusa-js" + * const medusa = new Medusa({ baseUrl: MEDUSA_BACKEND_URL, maxRetries: 3 }) + * // must be previously logged in or use api token + * medusa.admin.shippingOptions.create({ + * name: 'PostFake', + * region_id: "saasf", + * provider_id: "manual", + * data: { + * }, + * price_type: 'flat_rate' + * }) + * .then(({ shipping_option }) => { + * console.log(shipping_option.id); + * }); + * - lang: Shell + * label: cURL + * source: | + * curl --location --request POST 'https://medusa-url.com/admin/shipping-options' \ + * --header 'Authorization: Bearer {api_token}' \ + * --header 'Content-Type: application/json' \ + * --data-raw '{ + * "name": "PostFake", + * "region_id": "afasf", + * "provider_id": "manual", + * "data": {}, + * "price_type": "flat_rate" + * }' + * security: + * - api_token: [] + * - cookie_auth: [] * tags: * - Shipping Option * responses: @@ -92,6 +126,18 @@ import { EntityManager } from "typeorm" * properties: * shipping_option: * $ref: "#/components/schemas/shipping_option" + * "400": + * $ref: "#/components/responses/400_error" + * "401": + * $ref: "#/components/responses/unauthorized" + * "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 validated = await validator(AdminPostShippingOptionsReq, req.body) diff --git a/packages/medusa/src/api/routes/admin/shipping-options/delete-shipping-option.ts b/packages/medusa/src/api/routes/admin/shipping-options/delete-shipping-option.ts index 97325577ae..a7a05631d4 100644 --- a/packages/medusa/src/api/routes/admin/shipping-options/delete-shipping-option.ts +++ b/packages/medusa/src/api/routes/admin/shipping-options/delete-shipping-option.ts @@ -8,6 +8,25 @@ import { EntityManager } from "typeorm" * x-authenticated: true * parameters: * - (path) id=* {string} The ID of the Shipping Option. + * x-codeSamples: + * - lang: JavaScript + * label: JS Client + * source: | + * import Medusa from "@medusajs/medusa-js" + * const medusa = new Medusa({ baseUrl: MEDUSA_BACKEND_URL, maxRetries: 3 }) + * // must be previously logged in or use api token + * medusa.admin.shippingOptions.delete(option_id) + * .then(({ id, object, deleted }) => { + * console.log(id); + * }); + * - lang: Shell + * label: cURL + * source: | + * curl --location --request DELETE 'https://medusa-url.com/admin/shipping-options/{option_id}' \ + * --header 'Authorization: Bearer {api_token}' + * security: + * - api_token: [] + * - cookie_auth: [] * tags: * - Shipping Option * responses: @@ -28,6 +47,18 @@ import { EntityManager } from "typeorm" * type: boolean * description: Whether or not the items were deleted. * default: true + * "400": + * $ref: "#/components/responses/400_error" + * "401": + * $ref: "#/components/responses/unauthorized" + * "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 { option_id } = req.params diff --git a/packages/medusa/src/api/routes/admin/shipping-options/get-shipping-option.ts b/packages/medusa/src/api/routes/admin/shipping-options/get-shipping-option.ts index 6406c11a19..6716f38987 100644 --- a/packages/medusa/src/api/routes/admin/shipping-options/get-shipping-option.ts +++ b/packages/medusa/src/api/routes/admin/shipping-options/get-shipping-option.ts @@ -6,6 +6,25 @@ * x-authenticated: true * parameters: * - (path) id=* {string} The ID of the Shipping Option. + * x-codeSamples: + * - lang: JavaScript + * label: JS Client + * source: | + * import Medusa from "@medusajs/medusa-js" + * const medusa = new Medusa({ baseUrl: MEDUSA_BACKEND_URL, maxRetries: 3 }) + * // must be previously logged in or use api token + * medusa.admin.shippingOptions.retrieve(option_id) + * .then(({ shipping_option }) => { + * console.log(shipping_option.id); + * }); + * - lang: Shell + * label: cURL + * source: | + * curl --location --request GET 'https://medusa-url.com/admin/shipping-options/{id}' \ + * --header 'Authorization: Bearer {api_token}' + * security: + * - api_token: [] + * - cookie_auth: [] * tags: * - Shipping Option * responses: @@ -17,6 +36,18 @@ * properties: * shipping_option: * $ref: "#/components/schemas/shipping_option" + * "400": + * $ref: "#/components/responses/400_error" + * "401": + * $ref: "#/components/responses/unauthorized" + * "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 { option_id } = req.params diff --git a/packages/medusa/src/api/routes/admin/shipping-options/list-shipping-options.ts b/packages/medusa/src/api/routes/admin/shipping-options/list-shipping-options.ts index b7662973ab..f773c3e728 100644 --- a/packages/medusa/src/api/routes/admin/shipping-options/list-shipping-options.ts +++ b/packages/medusa/src/api/routes/admin/shipping-options/list-shipping-options.ts @@ -28,6 +28,25 @@ import { validator } from "../../../../utils/validator" * schema: * type: boolean * description: Flag for fetching admin specific options + * x-codeSamples: + * - lang: JavaScript + * label: JS Client + * source: | + * import Medusa from "@medusajs/medusa-js" + * const medusa = new Medusa({ baseUrl: MEDUSA_BACKEND_URL, maxRetries: 3 }) + * // must be previously logged in or use api token + * medusa.admin.shippingOptions.list() + * .then(({ shipping_options, count }) => { + * console.log(shipping_options.length); + * }); + * - lang: Shell + * label: cURL + * source: | + * curl --location --request GET 'https://medusa-url.com/admin/shipping-options' \ + * --header 'Authorization: Bearer {api_token}' + * security: + * - api_token: [] + * - cookie_auth: [] * tags: * - Shipping Option * responses: @@ -44,6 +63,18 @@ import { validator } from "../../../../utils/validator" * count: * type: integer * description: The total number of items available + * "400": + * $ref: "#/components/responses/400_error" + * "401": + * $ref: "#/components/responses/unauthorized" + * "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 validatedParams = await validator( diff --git a/packages/medusa/src/api/routes/admin/shipping-options/update-shipping-option.ts b/packages/medusa/src/api/routes/admin/shipping-options/update-shipping-option.ts index a4f3286f74..2c7f235d11 100644 --- a/packages/medusa/src/api/routes/admin/shipping-options/update-shipping-option.ts +++ b/packages/medusa/src/api/routes/admin/shipping-options/update-shipping-option.ts @@ -60,6 +60,43 @@ import { EntityManager } from "typeorm" * amount: * description: The amount to compare with. * type: integer + * x-codeSamples: + * - lang: JavaScript + * label: JS Client + * source: | + * import Medusa from "@medusajs/medusa-js" + * const medusa = new Medusa({ baseUrl: MEDUSA_BACKEND_URL, maxRetries: 3 }) + * // must be previously logged in or use api token + * medusa.admin.shippingOptions.update(option_id, { + * name: 'PostFake', + * requirements: [ + * { + * id, + * type: 'max_subtotal', + * amount: 1000 + * } + * ] + * }) + * .then(({ shipping_option }) => { + * console.log(shipping_option.id); + * }); + * - lang: Shell + * label: cURL + * source: | + * curl --location --request POST 'https://medusa-url.com/admin/shipping-options/{id}' \ + * --header 'Authorization: Bearer {api_token}' \ + * --header 'Content-Type: application/json' \ + * --data-raw '{ + * "requirements": [ + * { + * "type": "max_subtotal", + * "amount": 1000 + * } + * ] + * }' + * security: + * - api_token: [] + * - cookie_auth: [] * tags: * - Shipping Option * responses: @@ -71,6 +108,18 @@ import { EntityManager } from "typeorm" * properties: * shipping_option: * $ref: "#/components/schemas/shipping_option" + * "400": + * $ref: "#/components/responses/400_error" + * "401": + * $ref: "#/components/responses/unauthorized" + * "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 { option_id } = req.params diff --git a/packages/medusa/src/api/routes/admin/shipping-profiles/create-shipping-profile.ts b/packages/medusa/src/api/routes/admin/shipping-profiles/create-shipping-profile.ts index cd9778a584..ca224ba78f 100644 --- a/packages/medusa/src/api/routes/admin/shipping-profiles/create-shipping-profile.ts +++ b/packages/medusa/src/api/routes/admin/shipping-profiles/create-shipping-profile.ts @@ -19,6 +19,31 @@ import { EntityManager } from "typeorm" * name: * description: "The name of the Shipping Profile" * type: string + * x-codeSamples: + * - lang: JavaScript + * label: JS Client + * source: | + * import Medusa from "@medusajs/medusa-js" + * const medusa = new Medusa({ baseUrl: MEDUSA_BACKEND_URL, maxRetries: 3 }) + * // must be previously logged in or use api token + * medusa.admin.shippingProfiles.create({ + * name: 'Large Products' + * }) + * .then(({ shipping_profile }) => { + * console.log(shipping_profile.id); + * }); + * - lang: Shell + * label: cURL + * source: | + * curl --location --request POST 'https://medusa-url.com/admin/shipping-profiles' \ + * --header 'Authorization: Bearer {api_token}' \ + * --header 'Content-Type: application/json' \ + * --data-raw '{ + * "name": "Large Products" + * }' + * security: + * - api_token: [] + * - cookie_auth: [] * tags: * - Shipping Profile * responses: @@ -30,6 +55,18 @@ import { EntityManager } from "typeorm" * properties: * shipping_profile: * $ref: "#/components/schemas/shipping_profile" + * "400": + * $ref: "#/components/responses/400_error" + * "401": + * $ref: "#/components/responses/unauthorized" + * "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 validated = await validator(AdminPostShippingProfilesReq, req.body) diff --git a/packages/medusa/src/api/routes/admin/shipping-profiles/delete-shipping-profile.ts b/packages/medusa/src/api/routes/admin/shipping-profiles/delete-shipping-profile.ts index 96547d7d06..1c2b58da25 100644 --- a/packages/medusa/src/api/routes/admin/shipping-profiles/delete-shipping-profile.ts +++ b/packages/medusa/src/api/routes/admin/shipping-profiles/delete-shipping-profile.ts @@ -9,6 +9,25 @@ import { ShippingProfileService } from "../../../../services" * x-authenticated: true * parameters: * - (path) id=* {string} The ID of the Shipping Profile. + * x-codeSamples: + * - lang: JavaScript + * label: JS Client + * source: | + * import Medusa from "@medusajs/medusa-js" + * const medusa = new Medusa({ baseUrl: MEDUSA_BACKEND_URL, maxRetries: 3 }) + * // must be previously logged in or use api token + * medusa.admin.shippingProfiles.delete(profile_id) + * .then(({ id, object, deleted }) => { + * console.log(id); + * }); + * - lang: Shell + * label: cURL + * source: | + * curl --location --request DELETE 'https://medusa-url.com/admin/shipping-profiles/{id}' \ + * --header 'Authorization: Bearer {api_token}' + * security: + * - api_token: [] + * - cookie_auth: [] * tags: * - Shipping Profile * responses: @@ -29,6 +48,18 @@ import { ShippingProfileService } from "../../../../services" * type: boolean * description: Whether or not the items were deleted. * default: true + * "400": + * $ref: "#/components/responses/400_error" + * "401": + * $ref: "#/components/responses/unauthorized" + * "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 { profile_id } = req.params diff --git a/packages/medusa/src/api/routes/admin/shipping-profiles/get-shipping-profile.ts b/packages/medusa/src/api/routes/admin/shipping-profiles/get-shipping-profile.ts index 3da47c61e3..2220695c10 100644 --- a/packages/medusa/src/api/routes/admin/shipping-profiles/get-shipping-profile.ts +++ b/packages/medusa/src/api/routes/admin/shipping-profiles/get-shipping-profile.ts @@ -13,6 +13,25 @@ import { ShippingProfileService } from "../../../../services" * x-authenticated: true * parameters: * - (path) id=* {string} The ID of the Shipping Profile. + * x-codeSamples: + * - lang: JavaScript + * label: JS Client + * source: | + * import Medusa from "@medusajs/medusa-js" + * const medusa = new Medusa({ baseUrl: MEDUSA_BACKEND_URL, maxRetries: 3 }) + * // must be previously logged in or use api token + * medusa.admin.shippingProfiles.retrieve(profile_id) + * .then(({ shipping_profile }) => { + * console.log(shipping_profile.id); + * }); + * - lang: Shell + * label: cURL + * source: | + * curl --location --request GET 'https://medusa-url.com/admin/shipping-profiles/{id}' \ + * --header 'Authorization: Bearer {api_token}' + * security: + * - api_token: [] + * - cookie_auth: [] * tags: * - Shipping Profile * responses: @@ -24,6 +43,18 @@ import { ShippingProfileService } from "../../../../services" * properties: * shipping_profile: * $ref: "#/components/schemas/shipping_profile" + * "400": + * $ref: "#/components/responses/400_error" + * "401": + * $ref: "#/components/responses/unauthorized" + * "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 { profile_id } = req.params diff --git a/packages/medusa/src/api/routes/admin/shipping-profiles/list-shipping-profiles.ts b/packages/medusa/src/api/routes/admin/shipping-profiles/list-shipping-profiles.ts index a0306b6eb6..76f44b0e3f 100644 --- a/packages/medusa/src/api/routes/admin/shipping-profiles/list-shipping-profiles.ts +++ b/packages/medusa/src/api/routes/admin/shipping-profiles/list-shipping-profiles.ts @@ -6,6 +6,25 @@ import { ShippingProfileService } from "../../../../services" * summary: "List Shipping Profiles" * description: "Retrieves a list of Shipping Profile." * x-authenticated: true + * x-codeSamples: + * - lang: JavaScript + * label: JS Client + * source: | + * import Medusa from "@medusajs/medusa-js" + * const medusa = new Medusa({ baseUrl: MEDUSA_BACKEND_URL, maxRetries: 3 }) + * // must be previously logged in or use api token + * medusa.admin.shippingProfiles.list() + * .then(({ shipping_profiles }) => { + * console.log(shipping_profiles.length); + * }); + * - lang: Shell + * label: cURL + * source: | + * curl --location --request GET 'https://medusa-url.com/admin/shipping-profiles' \ + * --header 'Authorization: Bearer {api_token}' + * security: + * - api_token: [] + * - cookie_auth: [] * tags: * - Shipping Profile * responses: @@ -19,6 +38,18 @@ import { ShippingProfileService } from "../../../../services" * type: array * items: * $ref: "#/components/schemas/shipping_profile" + * "400": + * $ref: "#/components/responses/400_error" + * "401": + * $ref: "#/components/responses/unauthorized" + * "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 profileService: ShippingProfileService = req.scope.resolve( diff --git a/packages/medusa/src/api/routes/admin/shipping-profiles/update-shipping-profile.ts b/packages/medusa/src/api/routes/admin/shipping-profiles/update-shipping-profile.ts index 885542d1af..5410fad46b 100644 --- a/packages/medusa/src/api/routes/admin/shipping-profiles/update-shipping-profile.ts +++ b/packages/medusa/src/api/routes/admin/shipping-profiles/update-shipping-profile.ts @@ -19,6 +19,31 @@ import { EntityManager } from "typeorm" * name: * description: "The name of the Shipping Profile" * type: string + * x-codeSamples: + * - lang: JavaScript + * label: JS Client + * source: | + * import Medusa from "@medusajs/medusa-js" + * const medusa = new Medusa({ baseUrl: MEDUSA_BACKEND_URL, maxRetries: 3 }) + * // must be previously logged in or use api token + * medusa.admin.shippingProfiles.update(shipping_profile_id, { + * name: 'Large Products' + * }) + * .then(({ shipping_profile }) => { + * console.log(shipping_profile.id); + * }); + * - lang: Shell + * label: cURL + * source: | + * curl --location --request POST 'https://medusa-url.com/admin/shipping-profiles/{id} \ + * --header 'Authorization: Bearer {api_token}' \ + * --header 'Content-Type: application/json' \ + * --data-raw '{ + * "name": "Large Products" + * }' + * security: + * - api_token: [] + * - cookie_auth: [] * tags: * - Shipping Profile * responses: @@ -30,6 +55,18 @@ import { EntityManager } from "typeorm" * properties: * shipping_profile: * $ref: "#/components/schemas/shipping_profile" + * "400": + * $ref: "#/components/responses/400_error" + * "401": + * $ref: "#/components/responses/unauthorized" + * "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 { profile_id } = req.params diff --git a/packages/medusa/src/api/routes/admin/store/add-currency.ts b/packages/medusa/src/api/routes/admin/store/add-currency.ts index 7bc0b81245..70a8732bcd 100644 --- a/packages/medusa/src/api/routes/admin/store/add-currency.ts +++ b/packages/medusa/src/api/routes/admin/store/add-currency.ts @@ -16,6 +16,25 @@ import { EntityManager } from "typeorm" * externalDocs: * url: https://en.wikipedia.org/wiki/ISO_4217#Active_codes * description: See a list of codes. + * x-codeSamples: + * - lang: JavaScript + * label: JS Client + * source: | + * import Medusa from "@medusajs/medusa-js" + * const medusa = new Medusa({ baseUrl: MEDUSA_BACKEND_URL, maxRetries: 3 }) + * // must be previously logged in or use api token + * medusa.admin.store.addCurrency('eur') + * .then(({ store }) => { + * console.log(store.id); + * }); + * - lang: Shell + * label: cURL + * source: | + * curl --location --request POST 'https://medusa-url.com/admin/store/currencies/eur' \ + * --header 'Authorization: Bearer {api_token}' + * security: + * - api_token: [] + * - cookie_auth: [] * tags: * - Store * responses: @@ -27,6 +46,18 @@ import { EntityManager } from "typeorm" * properties: * store: * $ref: "#/components/schemas/store" + * "400": + * $ref: "#/components/responses/400_error" + * "401": + * $ref: "#/components/responses/unauthorized" + * "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 { currency_code } = req.params diff --git a/packages/medusa/src/api/routes/admin/store/get-store.ts b/packages/medusa/src/api/routes/admin/store/get-store.ts index 22b3b5c870..c448b1d84d 100644 --- a/packages/medusa/src/api/routes/admin/store/get-store.ts +++ b/packages/medusa/src/api/routes/admin/store/get-store.ts @@ -13,6 +13,25 @@ import { FlagRouter } from "../../../../utils/flag-router" * summary: "Retrieve Store details." * description: "Retrieves the Store details" * x-authenticated: true + * x-codeSamples: + * - lang: JavaScript + * label: JS Client + * source: | + * import Medusa from "@medusajs/medusa-js" + * const medusa = new Medusa({ baseUrl: MEDUSA_BACKEND_URL, maxRetries: 3 }) + * // must be previously logged in or use api token + * medusa.admin.store.retrieve() + * .then(({ store }) => { + * console.log(store.id); + * }); + * - lang: Shell + * label: cURL + * source: | + * curl --location --request GET 'https://medusa-url.com/admin/store' \ + * --header 'Authorization: Bearer {api_token}' + * security: + * - api_token: [] + * - cookie_auth: [] * tags: * - Store * responses: @@ -24,6 +43,18 @@ import { FlagRouter } from "../../../../utils/flag-router" * properties: * store: * $ref: "#/components/schemas/store" + * "400": + * $ref: "#/components/responses/400_error" + * "401": + * $ref: "#/components/responses/unauthorized" + * "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 storeService: StoreService = req.scope.resolve("storeService") diff --git a/packages/medusa/src/api/routes/admin/store/list-payment-providers.ts b/packages/medusa/src/api/routes/admin/store/list-payment-providers.ts index 7c1ad38c7b..51a036848b 100644 --- a/packages/medusa/src/api/routes/admin/store/list-payment-providers.ts +++ b/packages/medusa/src/api/routes/admin/store/list-payment-providers.ts @@ -5,6 +5,25 @@ import { PaymentProviderService } from "../../../../services" * summary: "Retrieve configured Payment Providers" * description: "Retrieves the configured Payment Providers" * x-authenticated: true + * x-codeSamples: + * - lang: JavaScript + * label: JS Client + * source: | + * import Medusa from "@medusajs/medusa-js" + * const medusa = new Medusa({ baseUrl: MEDUSA_BACKEND_URL, maxRetries: 3 }) + * // must be previously logged in or use api token + * medusa.admin.store.listPaymentProviders() + * .then(({ payment_providers }) => { + * console.log(payment_providers.length); + * }); + * - lang: Shell + * label: cURL + * source: | + * curl --location --request GET 'https://medusa-url.com/admin/store/payment-providers' \ + * --header 'Authorization: Bearer {api_token}' + * security: + * - api_token: [] + * - cookie_auth: [] * tags: * - Store * responses: @@ -18,6 +37,18 @@ import { PaymentProviderService } from "../../../../services" * type: array * items: * $ref: "#/components/schemas/payment_provider" + * "400": + * $ref: "#/components/responses/400_error" + * "401": + * $ref: "#/components/responses/unauthorized" + * "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 paymentProviderService: PaymentProviderService = req.scope.resolve( diff --git a/packages/medusa/src/api/routes/admin/store/list-tax-providers.ts b/packages/medusa/src/api/routes/admin/store/list-tax-providers.ts index af67f97b57..77223ad10b 100644 --- a/packages/medusa/src/api/routes/admin/store/list-tax-providers.ts +++ b/packages/medusa/src/api/routes/admin/store/list-tax-providers.ts @@ -6,6 +6,25 @@ import { TaxProviderService } from "../../../../services" * summary: "Retrieve configured Tax Providers" * description: "Retrieves the configured Tax Providers" * x-authenticated: true + * x-codeSamples: + * - lang: JavaScript + * label: JS Client + * source: | + * import Medusa from "@medusajs/medusa-js" + * const medusa = new Medusa({ baseUrl: MEDUSA_BACKEND_URL, maxRetries: 3 }) + * // must be previously logged in or use api token + * medusa.admin.store.listTaxProviders() + * .then(({ tax_providers }) => { + * console.log(tax_providers.length); + * }); + * - lang: Shell + * label: cURL + * source: | + * curl --location --request GET 'https://medusa-url.com/admin/store/tax-providers' \ + * --header 'Authorization: Bearer {api_token}' + * security: + * - api_token: [] + * - cookie_auth: [] * tags: * - Store * responses: @@ -19,6 +38,18 @@ import { TaxProviderService } from "../../../../services" * type: array * items: * $ref: "#/components/schemas/tax_provider" + * "400": + * $ref: "#/components/responses/400_error" + * "401": + * $ref: "#/components/responses/unauthorized" + * "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 taxProviderService: TaxProviderService = diff --git a/packages/medusa/src/api/routes/admin/store/remove-currency.ts b/packages/medusa/src/api/routes/admin/store/remove-currency.ts index 6a038f29d9..3e0aa55763 100644 --- a/packages/medusa/src/api/routes/admin/store/remove-currency.ts +++ b/packages/medusa/src/api/routes/admin/store/remove-currency.ts @@ -17,6 +17,25 @@ import { EntityManager } from "typeorm" * externalDocs: * url: https://en.wikipedia.org/wiki/ISO_4217#Active_codes * description: See a list of codes. + * x-codeSamples: + * - lang: JavaScript + * label: JS Client + * source: | + * import Medusa from "@medusajs/medusa-js" + * const medusa = new Medusa({ baseUrl: MEDUSA_BACKEND_URL, maxRetries: 3 }) + * // must be previously logged in or use api token + * medusa.admin.store.deleteCurrency('eur') + * .then(({ store }) => { + * console.log(store.id); + * }); + * - lang: Shell + * label: cURL + * source: | + * curl --location --request DELETE 'https://medusa-url.com/admin/store/currencies/eur' \ + * --header 'Authorization: Bearer {api_token}' + * security: + * - api_token: [] + * - cookie_auth: [] * tags: * - Store * responses: @@ -28,6 +47,18 @@ import { EntityManager } from "typeorm" * properties: * store: * $ref: "#/components/schemas/store" + * "400": + * $ref: "#/components/responses/400_error" + * "401": + * $ref: "#/components/responses/unauthorized" + * "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 { currency_code } = req.params diff --git a/packages/medusa/src/api/routes/admin/store/update-store.ts b/packages/medusa/src/api/routes/admin/store/update-store.ts index aa45888932..87b975c2d3 100644 --- a/packages/medusa/src/api/routes/admin/store/update-store.ts +++ b/packages/medusa/src/api/routes/admin/store/update-store.ts @@ -41,6 +41,31 @@ import { EntityManager } from "typeorm" * metadata: * description: "An optional set of key-value pairs with additional information." * type: object + * x-codeSamples: + * - lang: JavaScript + * label: JS Client + * source: | + * import Medusa from "@medusajs/medusa-js" + * const medusa = new Medusa({ baseUrl: MEDUSA_BACKEND_URL, maxRetries: 3 }) + * // must be previously logged in or use api token + * medusa.admin.store.update({ + * name: 'Medusa Store' + * }) + * .then(({ store }) => { + * console.log(store.id); + * }); + * - lang: Shell + * label: cURL + * source: | + * curl --location --request POST 'https://medusa-url.com/admin/store' \ + * --header 'Authorization: Bearer {api_token}' \ + * --header 'Content-Type: application/json' \ + * --data-raw '{ + * "name": "Medusa Store" + * }' + * security: + * - api_token: [] + * - cookie_auth: [] * tags: * - Store * responses: @@ -52,6 +77,18 @@ import { EntityManager } from "typeorm" * properties: * store: * $ref: "#/components/schemas/store" + * "400": + * $ref: "#/components/responses/400_error" + * "401": + * $ref: "#/components/responses/unauthorized" + * "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 validatedBody = await validator(AdminPostStoreReq, req.body) diff --git a/packages/medusa/src/api/routes/admin/swaps/get-swap.ts b/packages/medusa/src/api/routes/admin/swaps/get-swap.ts index d341c44e57..f07f007ff5 100644 --- a/packages/medusa/src/api/routes/admin/swaps/get-swap.ts +++ b/packages/medusa/src/api/routes/admin/swaps/get-swap.ts @@ -10,6 +10,25 @@ import { SwapService } from "../../../../services" * x-authenticated: true * parameters: * - (path) id=* {string} The ID of the Swap. + * x-codeSamples: + * - lang: JavaScript + * label: JS Client + * source: | + * import Medusa from "@medusajs/medusa-js" + * const medusa = new Medusa({ baseUrl: MEDUSA_BACKEND_URL, maxRetries: 3 }) + * // must be previously logged in or use api token + * medusa.admin.swaps.retrieve(swap_id) + * .then(({ swap }) => { + * console.log(swap.id); + * }); + * - lang: Shell + * label: cURL + * source: | + * curl --location --request GET 'https://medusa-url.com/admin/swaps/{id}' \ + * --header 'Authorization: Bearer {api_token}' + * security: + * - api_token: [] + * - cookie_auth: [] * tags: * - Swap * responses: @@ -21,6 +40,18 @@ import { SwapService } from "../../../../services" * properties: * swap: * $ref: "#/components/schemas/swap" + * "400": + * $ref: "#/components/responses/400_error" + * "401": + * $ref: "#/components/responses/unauthorized" + * "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 { id } = req.params diff --git a/packages/medusa/src/api/routes/admin/swaps/list-swaps.ts b/packages/medusa/src/api/routes/admin/swaps/list-swaps.ts index a1a224f1f3..c05f6f0429 100644 --- a/packages/medusa/src/api/routes/admin/swaps/list-swaps.ts +++ b/packages/medusa/src/api/routes/admin/swaps/list-swaps.ts @@ -13,6 +13,25 @@ import { validator } from "../../../../utils/validator" * - (query) limit=50 {number} The upper limit for the amount of responses returned. * - (query) offset=0 {number} The offset of the list returned. * x-authenticated: true + * x-codeSamples: + * - lang: JavaScript + * label: JS Client + * source: | + * import Medusa from "@medusajs/medusa-js" + * const medusa = new Medusa({ baseUrl: MEDUSA_BACKEND_URL, maxRetries: 3 }) + * // must be previously logged in or use api token + * medusa.admin.swaps.list() + * .then(({ swaps }) => { + * console.log(swaps.length); + * }); + * - lang: Shell + * label: cURL + * source: | + * curl --location --request GET 'https://medusa-url.com/admin/swaps' \ + * --header 'Authorization: Bearer {api_token}' + * security: + * - api_token: [] + * - cookie_auth: [] * tags: * - Swap * responses: @@ -35,6 +54,18 @@ import { validator } from "../../../../utils/validator" * limit: * type: integer * description: The number of items per page + * "400": + * $ref: "#/components/responses/400_error" + * "401": + * $ref: "#/components/responses/unauthorized" + * "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 swapService: SwapService = req.scope.resolve("swapService") diff --git a/packages/medusa/src/api/routes/admin/tax-rates/add-to-product-types.ts b/packages/medusa/src/api/routes/admin/tax-rates/add-to-product-types.ts index 0721ceca4c..6679550469 100644 --- a/packages/medusa/src/api/routes/admin/tax-rates/add-to-product-types.ts +++ b/packages/medusa/src/api/routes/admin/tax-rates/add-to-product-types.ts @@ -44,6 +44,35 @@ import { validator } from "../../../../utils/validator" * description: "The IDs of the types of products to associate with this tax rate" * items: * type: string + * x-codeSamples: + * - lang: JavaScript + * label: JS Client + * source: | + * import Medusa from "@medusajs/medusa-js" + * const medusa = new Medusa({ baseUrl: MEDUSA_BACKEND_URL, maxRetries: 3 }) + * // must be previously logged in or use api token + * medusa.admin.taxRates.addProductTypes(tax_rate_id, { + * product_types: [ + * product_type_id + * ] + * }) + * .then(({ tax_rate }) => { + * console.log(tax_rate.id); + * }); + * - lang: Shell + * label: cURL + * source: | + * curl --location --request POST 'https://medusa-url.com/admin/tax-rates/{id}/product-types/batch' \ + * --header 'Authorization: Bearer {api_token}' \ + * --header 'Content-Type: application/json' \ + * --data-raw '{ + * "product_types": [ + * "{product_type_id}" + * ] + * }' + * security: + * - api_token: [] + * - cookie_auth: [] * tags: * - Tax Rate * responses: @@ -55,6 +84,18 @@ import { validator } from "../../../../utils/validator" * properties: * tax_rate: * $ref: "#/components/schemas/tax_rate" + * "400": + * $ref: "#/components/responses/400_error" + * "401": + * $ref: "#/components/responses/unauthorized" + * "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 value = await validator( diff --git a/packages/medusa/src/api/routes/admin/tax-rates/add-to-products.ts b/packages/medusa/src/api/routes/admin/tax-rates/add-to-products.ts index cc589dbc58..c8b7a0016a 100644 --- a/packages/medusa/src/api/routes/admin/tax-rates/add-to-products.ts +++ b/packages/medusa/src/api/routes/admin/tax-rates/add-to-products.ts @@ -44,6 +44,35 @@ import { validator } from "../../../../utils/validator" * description: "The IDs of the products to associate with this tax rate" * items: * type: string + * x-codeSamples: + * - lang: JavaScript + * label: JS Client + * source: | + * import Medusa from "@medusajs/medusa-js" + * const medusa = new Medusa({ baseUrl: MEDUSA_BACKEND_URL, maxRetries: 3 }) + * // must be previously logged in or use api token + * medusa.admin.taxRates.addProducts(tax_rate_id, { + * products: [ + * product_id + * ] + * }) + * .then(({ tax_rate }) => { + * console.log(tax_rate.id); + * }); + * - lang: Shell + * label: cURL + * source: | + * curl --location --request POST 'https://medusa-url.com/admin/tax-rates/{id}/products/batch' \ + * --header 'Authorization: Bearer {api_token}' \ + * --header 'Content-Type: application/json' \ + * --data-raw '{ + * "products": [ + * "{product_id}" + * ] + * }' + * security: + * - api_token: [] + * - cookie_auth: [] * tags: * - Tax Rate * responses: @@ -55,6 +84,18 @@ import { validator } from "../../../../utils/validator" * properties: * tax_rate: * $ref: "#/components/schemas/tax_rate" + * "400": + * $ref: "#/components/responses/400_error" + * "401": + * $ref: "#/components/responses/unauthorized" + * "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 value = await validator(AdminPostTaxRatesTaxRateProductsReq, req.body) diff --git a/packages/medusa/src/api/routes/admin/tax-rates/add-to-shipping-options.ts b/packages/medusa/src/api/routes/admin/tax-rates/add-to-shipping-options.ts index b12a722b27..fac7d76315 100644 --- a/packages/medusa/src/api/routes/admin/tax-rates/add-to-shipping-options.ts +++ b/packages/medusa/src/api/routes/admin/tax-rates/add-to-shipping-options.ts @@ -44,6 +44,35 @@ import { validator } from "../../../../utils/validator" * description: "The IDs of the shipping options to associate with this tax rate" * items: * type: string + * x-codeSamples: + * - lang: JavaScript + * label: JS Client + * source: | + * import Medusa from "@medusajs/medusa-js" + * const medusa = new Medusa({ baseUrl: MEDUSA_BACKEND_URL, maxRetries: 3 }) + * // must be previously logged in or use api token + * medusa.admin.taxRates.addShippingOptions(tax_rate_id, { + * shipping_options: [ + * shipping_option_id + * ] + * }) + * .then(({ tax_rate }) => { + * console.log(tax_rate.id); + * }); + * - lang: Shell + * label: cURL + * source: | + * curl --location --request POST 'https://medusa-url.com/admin/tax-rates/{id}/shipping-options/batch' \ + * --header 'Authorization: Bearer {api_token}' \ + * --header 'Content-Type: application/json' \ + * --data-raw '{ + * "shipping_options": [ + * "{shipping_option_id}" + * ] + * }' + * security: + * - api_token: [] + * - cookie_auth: [] * tags: * - Tax Rate * responses: @@ -55,6 +84,18 @@ import { validator } from "../../../../utils/validator" * properties: * tax_rate: * $ref: "#/components/schemas/tax_rate" + * "400": + * $ref: "#/components/responses/400_error" + * "401": + * $ref: "#/components/responses/unauthorized" + * "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 value = await validator( diff --git a/packages/medusa/src/api/routes/admin/tax-rates/create-tax-rate.ts b/packages/medusa/src/api/routes/admin/tax-rates/create-tax-rate.ts index 6ad7a5fb74..a8dcc404fc 100644 --- a/packages/medusa/src/api/routes/admin/tax-rates/create-tax-rate.ts +++ b/packages/medusa/src/api/routes/admin/tax-rates/create-tax-rate.ts @@ -71,6 +71,35 @@ import { isDefined } from "../../../../utils" * description: "The IDs of the types of products associated with this tax rate" * items: * type: string + * x-codeSamples: + * - lang: JavaScript + * label: JS Client + * source: | + * import Medusa from "@medusajs/medusa-js" + * const medusa = new Medusa({ baseUrl: MEDUSA_BACKEND_URL, maxRetries: 3 }) + * // must be previously logged in or use api token + * medusa.admin.taxRates.create({ + * code: 'TEST', + * name: 'New Tax Rate', + * region_id + * }) + * .then(({ tax_rate }) => { + * console.log(tax_rate.id); + * }); + * - lang: Shell + * label: cURL + * source: | + * curl --location --request POST 'https://medusa-url.com/admin/tax-rates' \ + * --header 'Authorization: Bearer {api_token}' \ + * --header 'Content-Type: application/json' \ + * --data-raw '{ + * "code": "TEST", + * "name": "New Tax Rate", + * "region_id": "{region_id}" + * }' + * security: + * - api_token: [] + * - cookie_auth: [] * tags: * - Tax Rate * responses: @@ -82,6 +111,18 @@ import { isDefined } from "../../../../utils" * properties: * tax_rate: * $ref: "#/components/schemas/tax_rate" + * "400": + * $ref: "#/components/responses/400_error" + * "401": + * $ref: "#/components/responses/unauthorized" + * "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 value = await validator(AdminPostTaxRatesReq, req.body) diff --git a/packages/medusa/src/api/routes/admin/tax-rates/delete-tax-rate.ts b/packages/medusa/src/api/routes/admin/tax-rates/delete-tax-rate.ts index f97a1fad9f..789101f7d3 100644 --- a/packages/medusa/src/api/routes/admin/tax-rates/delete-tax-rate.ts +++ b/packages/medusa/src/api/routes/admin/tax-rates/delete-tax-rate.ts @@ -9,6 +9,25 @@ import { TaxRateService } from "../../../../services" * x-authenticated: true * parameters: * - (path) id=* {string} The ID of the Shipping Option. + * x-codeSamples: + * - lang: JavaScript + * label: JS Client + * source: | + * import Medusa from "@medusajs/medusa-js" + * const medusa = new Medusa({ baseUrl: MEDUSA_BACKEND_URL, maxRetries: 3 }) + * // must be previously logged in or use api token + * medusa.admin.taxRates.delete(tax_rate_id) + * .then(({ id, object, deleted }) => { + * console.log(id); + * }); + * - lang: Shell + * label: cURL + * source: | + * curl --location --request DELETE 'https://medusa-url.com/admin/tax-rates/{id}' \ + * --header 'Authorization: Bearer {api_token}' + * security: + * - api_token: [] + * - cookie_auth: [] * tags: * - Tax Rate * responses: @@ -29,6 +48,18 @@ import { TaxRateService } from "../../../../services" * type: boolean * description: Whether or not the items were deleted. * default: true + * "400": + * $ref: "#/components/responses/400_error" + * "401": + * $ref: "#/components/responses/unauthorized" + * "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 { id } = req.params diff --git a/packages/medusa/src/api/routes/admin/tax-rates/get-tax-rate.ts b/packages/medusa/src/api/routes/admin/tax-rates/get-tax-rate.ts index ff42468538..747220a3c4 100644 --- a/packages/medusa/src/api/routes/admin/tax-rates/get-tax-rate.ts +++ b/packages/medusa/src/api/routes/admin/tax-rates/get-tax-rate.ts @@ -31,6 +31,25 @@ import { validator } from "../../../../utils/validator" * items: * type: string * x-authenticated: true + * x-codeSamples: + * - lang: JavaScript + * label: JS Client + * source: | + * import Medusa from "@medusajs/medusa-js" + * const medusa = new Medusa({ baseUrl: MEDUSA_BACKEND_URL, maxRetries: 3 }) + * // must be previously logged in or use api token + * medusa.admin.taxRates.retrieve(tax_rate_id) + * .then(({ tax_rate }) => { + * console.log(tax_rate.id); + * }); + * - lang: Shell + * label: cURL + * source: | + * curl --location --request GET 'https://medusa-url.com/admin/tax-rates/{id}' \ + * --header 'Authorization: Bearer {api_token}' + * security: + * - api_token: [] + * - cookie_auth: [] * tags: * - Tax Rate * responses: @@ -42,6 +61,18 @@ import { validator } from "../../../../utils/validator" * properties: * tax_rate: * $ref: "#/components/schemas/tax_rate" + * "400": + * $ref: "#/components/responses/400_error" + * "401": + * $ref: "#/components/responses/unauthorized" + * "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 value = await validator(AdminGetTaxRatesTaxRateParams, req.query) diff --git a/packages/medusa/src/api/routes/admin/tax-rates/list-tax-rates.ts b/packages/medusa/src/api/routes/admin/tax-rates/list-tax-rates.ts index c50e9e2fcc..12272726f9 100644 --- a/packages/medusa/src/api/routes/admin/tax-rates/list-tax-rates.ts +++ b/packages/medusa/src/api/routes/admin/tax-rates/list-tax-rates.ts @@ -71,6 +71,25 @@ import { validator } from "../../../../utils/validator" * type: array * items: * type: string + * x-codeSamples: + * - lang: JavaScript + * label: JS Client + * source: | + * import Medusa from "@medusajs/medusa-js" + * const medusa = new Medusa({ baseUrl: MEDUSA_BACKEND_URL, maxRetries: 3 }) + * // must be previously logged in or use api token + * medusa.admin.taxRates.list() + * .then(({ tax_rates, limit, offset, count }) => { + * console.log(tax_rates.length); + * }); + * - lang: Shell + * label: cURL + * source: | + * curl --location --request GET 'https://medusa-url.com/admin/tax-rates' \ + * --header 'Authorization: Bearer {api_token}' + * security: + * - api_token: [] + * - cookie_auth: [] * tags: * - Tax Rate * responses: @@ -93,6 +112,18 @@ import { validator } from "../../../../utils/validator" * limit: * type: integer * description: The number of items per page + * "400": + * $ref: "#/components/responses/400_error" + * "401": + * $ref: "#/components/responses/unauthorized" + * "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 value = await validator(AdminGetTaxRatesParams, req.query) diff --git a/packages/medusa/src/api/routes/admin/tax-rates/remove-from-product-types.ts b/packages/medusa/src/api/routes/admin/tax-rates/remove-from-product-types.ts index 83ec2c5b79..e146d3ff46 100644 --- a/packages/medusa/src/api/routes/admin/tax-rates/remove-from-product-types.ts +++ b/packages/medusa/src/api/routes/admin/tax-rates/remove-from-product-types.ts @@ -44,6 +44,35 @@ import { validator } from "../../../../utils/validator" * description: "The IDs of the types of products to remove association with this tax rate" * items: * type: string + * x-codeSamples: + * - lang: JavaScript + * label: JS Client + * source: | + * import Medusa from "@medusajs/medusa-js" + * const medusa = new Medusa({ baseUrl: MEDUSA_BACKEND_URL, maxRetries: 3 }) + * // must be previously logged in or use api token + * medusa.admin.taxRates.removeProductTypes(tax_rate_id, { + * product_types: [ + * product_type_id + * ] + * }) + * .then(({ tax_rate }) => { + * console.log(tax_rate.id); + * }); + * - lang: Shell + * label: cURL + * source: | + * curl --location --request DELETE 'https://medusa-url.com/admin/tax-rates/{id}/product-types/batch' \ + * --header 'Authorization: Bearer {api_token}' \ + * --header 'Content-Type: application/json' \ + * --data-raw '{ + * "product_types": [ + * "{product_type_id}" + * ] + * }' + * security: + * - api_token: [] + * - cookie_auth: [] * tags: * - Tax Rate * responses: @@ -55,6 +84,18 @@ import { validator } from "../../../../utils/validator" * properties: * tax_rate: * $ref: "#/components/schemas/tax_rate" + * "400": + * $ref: "#/components/responses/400_error" + * "401": + * $ref: "#/components/responses/unauthorized" + * "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 value = await validator( diff --git a/packages/medusa/src/api/routes/admin/tax-rates/remove-from-products.ts b/packages/medusa/src/api/routes/admin/tax-rates/remove-from-products.ts index a32c292909..430b80db5f 100644 --- a/packages/medusa/src/api/routes/admin/tax-rates/remove-from-products.ts +++ b/packages/medusa/src/api/routes/admin/tax-rates/remove-from-products.ts @@ -44,6 +44,35 @@ import { validator } from "../../../../utils/validator" * description: "The IDs of the products to remove association with this tax rate" * items: * type: string + * x-codeSamples: + * - lang: JavaScript + * label: JS Client + * source: | + * import Medusa from "@medusajs/medusa-js" + * const medusa = new Medusa({ baseUrl: MEDUSA_BACKEND_URL, maxRetries: 3 }) + * // must be previously logged in or use api token + * medusa.admin.taxRates.removeProducts(tax_rate_id, { + * products: [ + * product_id + * ] + * }) + * .then(({ tax_rate }) => { + * console.log(tax_rate.id); + * }); + * - lang: Shell + * label: cURL + * source: | + * curl --location --request DELETE 'https://medusa-url.com/admin/tax-rates/{id}/products/batch' \ + * --header 'Authorization: Bearer {api_token}' \ + * --header 'Content-Type: application/json' \ + * --data-raw '{ + * "products": [ + * "{product_id}" + * ] + * }' + * security: + * - api_token: [] + * - cookie_auth: [] * tags: * - Tax Rate * responses: @@ -55,6 +84,18 @@ import { validator } from "../../../../utils/validator" * properties: * tax_rate: * $ref: "#/components/schemas/tax_rate" + * "400": + * $ref: "#/components/responses/400_error" + * "401": + * $ref: "#/components/responses/unauthorized" + * "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 value = await validator(AdminDeleteTaxRatesTaxRateProductsReq, req.body) diff --git a/packages/medusa/src/api/routes/admin/tax-rates/remove-from-shipping-options.ts b/packages/medusa/src/api/routes/admin/tax-rates/remove-from-shipping-options.ts index 74f773f58b..0e8845e4c8 100644 --- a/packages/medusa/src/api/routes/admin/tax-rates/remove-from-shipping-options.ts +++ b/packages/medusa/src/api/routes/admin/tax-rates/remove-from-shipping-options.ts @@ -44,6 +44,35 @@ import { validator } from "../../../../utils/validator" * description: "The IDs of the shipping options to remove association with this tax rate" * items: * type: string + * x-codeSamples: + * - lang: JavaScript + * label: JS Client + * source: | + * import Medusa from "@medusajs/medusa-js" + * const medusa = new Medusa({ baseUrl: MEDUSA_BACKEND_URL, maxRetries: 3 }) + * // must be previously logged in or use api token + * medusa.admin.taxRates.removeShippingOptions(tax_rate_id, { + * shipping_options: [ + * shipping_option_id + * ] + * }) + * .then(({ tax_rate }) => { + * console.log(tax_rate.id); + * }); + * - lang: Shell + * label: cURL + * source: | + * curl --location --request DELETE 'https://medusa-url.com/admin/tax-rates/{id}/shipping-options/batch' \ + * --header 'Authorization: Bearer {api_token}' \ + * --header 'Content-Type: application/json' \ + * --data-raw '{ + * "shipping_options": [ + * "{shipping_option_id}" + * ] + * }' + * security: + * - api_token: [] + * - cookie_auth: [] * tags: * - Tax Rate * responses: @@ -55,6 +84,18 @@ import { validator } from "../../../../utils/validator" * properties: * tax_rate: * $ref: "#/components/schemas/tax_rate" + * "400": + * $ref: "#/components/responses/400_error" + * "401": + * $ref: "#/components/responses/unauthorized" + * "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 value = await validator( diff --git a/packages/medusa/src/api/routes/admin/tax-rates/update-tax-rate.ts b/packages/medusa/src/api/routes/admin/tax-rates/update-tax-rate.ts index 5121835a6c..1413cdf4ca 100644 --- a/packages/medusa/src/api/routes/admin/tax-rates/update-tax-rate.ts +++ b/packages/medusa/src/api/routes/admin/tax-rates/update-tax-rate.ts @@ -67,6 +67,31 @@ import { isDefined } from "../../../../utils" * description: "The IDs of the types of products associated with this tax rate" * items: * type: string + * x-codeSamples: + * - lang: JavaScript + * label: JS Client + * source: | + * import Medusa from "@medusajs/medusa-js" + * const medusa = new Medusa({ baseUrl: MEDUSA_BACKEND_URL, maxRetries: 3 }) + * // must be previously logged in or use api token + * medusa.admin.taxRates.update(tax_rate_id, { + * name: 'New Tax Rate' + * }) + * .then(({ tax_rate }) => { + * console.log(tax_rate.id); + * }); + * - lang: Shell + * label: cURL + * source: | + * curl --location --request POST 'https://medusa-url.com/admin/tax-rates/{id}' \ + * --header 'Authorization: Bearer {api_token}' \ + * --header 'Content-Type: application/json' \ + * --data-raw '{ + * "name": "New Tax Rate" + * }' + * security: + * - api_token: [] + * - cookie_auth: [] * tags: * - Tax Rate * responses: @@ -78,6 +103,18 @@ import { isDefined } from "../../../../utils" * properties: * tax_rate: * $ref: "#/components/schemas/tax_rate" + * "400": + * $ref: "#/components/responses/400_error" + * "401": + * $ref: "#/components/responses/unauthorized" + * "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 value = await validator(AdminPostTaxRatesTaxRateReq, req.body) diff --git a/packages/medusa/src/api/routes/admin/uploads/create-upload.ts b/packages/medusa/src/api/routes/admin/uploads/create-upload.ts index 174bf2bff4..7e93d532db 100644 --- a/packages/medusa/src/api/routes/admin/uploads/create-upload.ts +++ b/packages/medusa/src/api/routes/admin/uploads/create-upload.ts @@ -6,8 +6,6 @@ import fs from "fs" * summary: "Uploads a file" * description: "Uploads a file to the specific fileservice that is installed in Medusa." * x-authenticated: true - * tags: - * - Upload * requestBody: * content: * multipart/form-data: @@ -17,6 +15,29 @@ import fs from "fs" * files: * type: string * format: binary + * x-codeSamples: + * - lang: JavaScript + * label: JS Client + * source: | + * import Medusa from "@medusajs/medusa-js" + * const medusa = new Medusa({ baseUrl: MEDUSA_BACKEND_URL, maxRetries: 3 }) + * // must be previously logged in or use api token + * medusa.admin.uploads.create(file) + * .then(({ uploads }) => { + * console.log(uploads.length); + * }); + * - lang: Shell + * label: cURL + * source: | + * curl --location --request POST 'https://medusa-url.com/admin/uploads' \ + * --header 'Authorization: Bearer {api_token}' \ + * --header 'Content-Type: image/jpeg' \ + * --data-binary '{file_path}' + * security: + * - api_token: [] + * - cookie_auth: [] + * tags: + * - Upload * responses: * 200: * description: OK @@ -33,6 +54,18 @@ import fs from "fs" * type: string * description: The URL of the uploaded file. * format: uri + * "400": + * $ref: "#/components/responses/400_error" + * "401": + * $ref: "#/components/responses/unauthorized" + * "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) => { try { diff --git a/packages/medusa/src/api/routes/admin/uploads/delete-upload.ts b/packages/medusa/src/api/routes/admin/uploads/delete-upload.ts index 0affea868a..b5551fdedc 100644 --- a/packages/medusa/src/api/routes/admin/uploads/delete-upload.ts +++ b/packages/medusa/src/api/routes/admin/uploads/delete-upload.ts @@ -16,6 +16,31 @@ import { IsString } from "class-validator" * file_key: * description: "key of the file to delete" * type: string + * x-codeSamples: + * - lang: JavaScript + * label: JS Client + * source: | + * import Medusa from "@medusajs/medusa-js" + * const medusa = new Medusa({ baseUrl: MEDUSA_BACKEND_URL, maxRetries: 3 }) + * // must be previously logged in or use api token + * medusa.admin.uploads.delete({ + * file_key + * }) + * .then(({ id, object, deleted }) => { + * console.log(id); + * }); + * - lang: Shell + * label: cURL + * source: | + * curl --location --request DELETE 'https://medusa-url.com/admin/uploads' \ + * --header 'Authorization: Bearer {api_token}' \ + * --header 'Content-Type: application/json' \ + * --data-raw '{ + * "file_key": "{file_key}" + * }' + * security: + * - api_token: [] + * - cookie_auth: [] * tags: * - Upload * responses: @@ -36,6 +61,18 @@ import { IsString } from "class-validator" * type: boolean * description: Whether or not the items were deleted. * default: true + * "400": + * $ref: "#/components/responses/400_error" + * "401": + * $ref: "#/components/responses/unauthorized" + * "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 validated = req.validatedBody as AdminDeleteUploadsReq diff --git a/packages/medusa/src/api/routes/admin/uploads/get-download-url.ts b/packages/medusa/src/api/routes/admin/uploads/get-download-url.ts index db264e85b1..16298e0975 100644 --- a/packages/medusa/src/api/routes/admin/uploads/get-download-url.ts +++ b/packages/medusa/src/api/routes/admin/uploads/get-download-url.ts @@ -17,6 +17,31 @@ import { IsString } from "class-validator" * file_key: * description: "key of the file to obtain the download link for" * type: string + * x-codeSamples: + * - lang: JavaScript + * label: JS Client + * source: | + * import Medusa from "@medusajs/medusa-js" + * const medusa = new Medusa({ baseUrl: MEDUSA_BACKEND_URL, maxRetries: 3 }) + * // must be previously logged in or use api token + * medusa.admin.uploads.getPresignedDownloadUrl({ + * file_key + * }) + * .then(({ download_url }) => { + * console.log(download_url); + * }); + * - lang: Shell + * label: cURL + * source: | + * curl --location --request POST 'https://medusa-url.com/admin/uploads/download-url' \ + * --header 'Authorization: Bearer {api_token}' \ + * --header 'Content-Type: application/json' \ + * --data-raw '{ + * "file_key": "{file_key}" + * }' + * security: + * - api_token: [] + * - cookie_auth: [] * tags: * - Upload * responses: @@ -29,6 +54,18 @@ import { IsString } from "class-validator" * download_url: * type: string * description: The Download URL of the file + * "400": + * $ref: "#/components/responses/400_error" + * "401": + * $ref: "#/components/responses/unauthorized" + * "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 fileService: AbstractFileService = req.scope.resolve("fileService") diff --git a/packages/medusa/src/api/routes/admin/users/create-user.ts b/packages/medusa/src/api/routes/admin/users/create-user.ts index 1ed8d7e202..0c6b3b6d21 100644 --- a/packages/medusa/src/api/routes/admin/users/create-user.ts +++ b/packages/medusa/src/api/routes/admin/users/create-user.ts @@ -38,6 +38,33 @@ import { EntityManager } from "typeorm" * description: "The Users password." * type: string * format: password + * x-codeSamples: + * - lang: JavaScript + * label: JS Client + * source: | + * import Medusa from "@medusajs/medusa-js" + * const medusa = new Medusa({ baseUrl: MEDUSA_BACKEND_URL, maxRetries: 3 }) + * // must be previously logged in or use api token + * medusa.admin.users.create({ + * email: 'user@example.com', + * password: 'supersecret' + * }) + * .then(({ user }) => { + * console.log(user.id); + * }); + * - lang: Shell + * label: cURL + * source: | + * curl --location --request POST 'https://medusa-url.com/admin/users' \ + * --header 'Authorization: Bearer {api_token}' \ + * --header 'Content-Type: application/json' \ + * --data-raw '{ + * "email": "user@example.com", + * "password": "supersecret" + * }' + * security: + * - api_token: [] + * - cookie_auth: [] * tags: * - User * responses: @@ -49,6 +76,18 @@ import { EntityManager } from "typeorm" * properties: * user: * $ref: "#/components/schemas/user" + * "400": + * $ref: "#/components/responses/400_error" + * "401": + * $ref: "#/components/responses/unauthorized" + * "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 validated = await validator(AdminCreateUserRequest, req.body) diff --git a/packages/medusa/src/api/routes/admin/users/delete-user.ts b/packages/medusa/src/api/routes/admin/users/delete-user.ts index a68ca5fe67..525451371c 100644 --- a/packages/medusa/src/api/routes/admin/users/delete-user.ts +++ b/packages/medusa/src/api/routes/admin/users/delete-user.ts @@ -9,6 +9,25 @@ import UserService from "../../../../services/user" * x-authenticated: true * parameters: * - (path) id=* {string} The ID of the User. + * x-codeSamples: + * - lang: JavaScript + * label: JS Client + * source: | + * import Medusa from "@medusajs/medusa-js" + * const medusa = new Medusa({ baseUrl: MEDUSA_BACKEND_URL, maxRetries: 3 }) + * // must be previously logged in or use api token + * medusa.admin.users.delete(user_id) + * .then(({ id, object, deleted }) => { + * console.log(id); + * }); + * - lang: Shell + * label: cURL + * source: | + * curl --location --request DELETE 'https://medusa-url.com/admin/users/{id}' \ + * --header 'Authorization: Bearer {api_token}' + * security: + * - api_token: [] + * - cookie_auth: [] * tags: * - Users * responses: @@ -29,6 +48,18 @@ import UserService from "../../../../services/user" * type: boolean * description: Whether or not the items were deleted. * default: true + * "400": + * $ref: "#/components/responses/400_error" + * "401": + * $ref: "#/components/responses/unauthorized" + * "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 { user_id } = req.params diff --git a/packages/medusa/src/api/routes/admin/users/get-user.ts b/packages/medusa/src/api/routes/admin/users/get-user.ts index cddebaca94..b14b662fda 100644 --- a/packages/medusa/src/api/routes/admin/users/get-user.ts +++ b/packages/medusa/src/api/routes/admin/users/get-user.ts @@ -8,6 +8,25 @@ import UserService from "../../../../services/user" * x-authenticated: true * parameters: * - (path) id=* {string} The ID of the User. + * x-codeSamples: + * - lang: JavaScript + * label: JS Client + * source: | + * import Medusa from "@medusajs/medusa-js" + * const medusa = new Medusa({ baseUrl: MEDUSA_BACKEND_URL, maxRetries: 3 }) + * // must be previously logged in or use api token + * medusa.admin.users.retrieve(user_id) + * .then(({ user }) => { + * console.log(user.id); + * }); + * - lang: Shell + * label: cURL + * source: | + * curl --location --request GET 'https://medusa-url.com/admin/users/{id}' \ + * --header 'Authorization: Bearer {api_token}' + * security: + * - api_token: [] + * - cookie_auth: [] * tags: * - User * responses: @@ -19,6 +38,18 @@ import UserService from "../../../../services/user" * properties: * user: * $ref: "#/components/schemas/user" + * "400": + * $ref: "#/components/responses/400_error" + * "401": + * $ref: "#/components/responses/unauthorized" + * "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 { user_id } = req.params diff --git a/packages/medusa/src/api/routes/admin/users/list-users.ts b/packages/medusa/src/api/routes/admin/users/list-users.ts index 3e142a156a..80c653fffa 100644 --- a/packages/medusa/src/api/routes/admin/users/list-users.ts +++ b/packages/medusa/src/api/routes/admin/users/list-users.ts @@ -6,6 +6,25 @@ import UserService from "../../../../services/user" * summary: "Retrieve all users" * description: "Retrieves all users." * x-authenticated: true + * x-codeSamples: + * - lang: JavaScript + * label: JS Client + * source: | + * import Medusa from "@medusajs/medusa-js" + * const medusa = new Medusa({ baseUrl: MEDUSA_BACKEND_URL, maxRetries: 3 }) + * // must be previously logged in or use api token + * medusa.admin.users.list() + * .then(({ users }) => { + * console.log(users.length); + * }); + * - lang: Shell + * label: cURL + * source: | + * curl --location --request GET 'https://medusa-url.com/admin/users' \ + * --header 'Authorization: Bearer {api_token}' + * security: + * - api_token: [] + * - cookie_auth: [] * tags: * - User * responses: @@ -19,6 +38,18 @@ import UserService from "../../../../services/user" * type: array * items: * $ref: "#/components/schemas/user" + * "400": + * $ref: "#/components/responses/400_error" + * "401": + * $ref: "#/components/responses/unauthorized" + * "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 userService: UserService = req.scope.resolve("userService") diff --git a/packages/medusa/src/api/routes/admin/users/reset-password-token.ts b/packages/medusa/src/api/routes/admin/users/reset-password-token.ts index 5da2d96315..807a188234 100644 --- a/packages/medusa/src/api/routes/admin/users/reset-password-token.ts +++ b/packages/medusa/src/api/routes/admin/users/reset-password-token.ts @@ -20,11 +20,51 @@ import { EntityManager } from "typeorm" * description: "The Users email." * type: string * format: email + * x-codeSamples: + * - lang: JavaScript + * label: JS Client + * source: | + * import Medusa from "@medusajs/medusa-js" + * const medusa = new Medusa({ baseUrl: MEDUSA_BACKEND_URL, maxRetries: 3 }) + * // must be previously logged in or use api token + * medusa.admin.users.sendResetPasswordToken({ + * email: 'user@example.com' + * }) + * .then(() => { + * // successful + * }) + * .catch(() => { + * // error occurred + * }); + * - lang: Shell + * label: cURL + * source: | + * curl --location --request POST 'https://medusa-url.com/admin/users/password-token' \ + * --header 'Authorization: Bearer {api_token}' \ + * --header 'Content-Type: application/json' \ + * --data-raw '{ + * "email": "user@example.com" + * }' + * security: + * - api_token: [] + * - cookie_auth: [] * tags: * - User * responses: * 204: * description: OK + * "400": + * $ref: "#/components/responses/400_error" + * "401": + * $ref: "#/components/responses/unauthorized" + * "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 validated = await validator(AdminResetPasswordTokenRequest, req.body) diff --git a/packages/medusa/src/api/routes/admin/users/reset-password.ts b/packages/medusa/src/api/routes/admin/users/reset-password.ts index 70c2da56c1..f7769bcb5b 100644 --- a/packages/medusa/src/api/routes/admin/users/reset-password.ts +++ b/packages/medusa/src/api/routes/admin/users/reset-password.ts @@ -33,6 +33,33 @@ import { EntityManager } from "typeorm" * description: "The Users new password." * type: string * format: password + * x-codeSamples: + * - lang: JavaScript + * label: JS Client + * source: | + * import Medusa from "@medusajs/medusa-js" + * const medusa = new Medusa({ baseUrl: MEDUSA_BACKEND_URL, maxRetries: 3 }) + * // must be previously logged in or use api token + * medusa.admin.users.resetPassword({ + * token: 'supersecrettoken', + * password: 'supersecret' + * }) + * .then(({ user }) => { + * console.log(user.id); + * }); + * - lang: Shell + * label: cURL + * source: | + * curl --location --request POST 'https://medusa-url.com/admin/users/reset-password' \ + * --header 'Authorization: Bearer {api_token}' \ + * --header 'Content-Type: application/json' \ + * --data-raw '{ + * "token": "supersecrettoken", + * "password": "supersecret" + * }' + * security: + * - api_token: [] + * - cookie_auth: [] * tags: * - User * responses: @@ -44,6 +71,18 @@ import { EntityManager } from "typeorm" * properties: * user: * $ref: "#/components/schemas/user" + * "400": + * $ref: "#/components/responses/400_error" + * "401": + * $ref: "#/components/responses/unauthorized" + * "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 validated = await validator(AdminResetPasswordRequest, req.body) diff --git a/packages/medusa/src/api/routes/admin/users/update-user.ts b/packages/medusa/src/api/routes/admin/users/update-user.ts index 189af25cf3..7cc14d7005 100644 --- a/packages/medusa/src/api/routes/admin/users/update-user.ts +++ b/packages/medusa/src/api/routes/admin/users/update-user.ts @@ -34,7 +34,31 @@ import { EntityManager } from "typeorm" * metadata: * description: An optional set of key-value pairs with additional information. * type: object - * + * x-codeSamples: + * - lang: JavaScript + * label: JS Client + * source: | + * import Medusa from "@medusajs/medusa-js" + * const medusa = new Medusa({ baseUrl: MEDUSA_BACKEND_URL, maxRetries: 3 }) + * // must be previously logged in or use api token + * medusa.admin.users.update(user_id, { + * first_name: 'Marcellus' + * }) + * .then(({ user }) => { + * console.log(user.id); + * }); + * - lang: Shell + * label: cURL + * source: | + * curl --location --request POST 'https://medusa-url.com/admin/users/{id}' \ + * --header 'Authorization: Bearer {api_token}' \ + * --header 'Content-Type: application/json' \ + * --data-raw '{ + * "first_name": "Marcellus" + * }' + * security: + * - api_token: [] + * - cookie_auth: [] * tags: * - User * responses: @@ -46,6 +70,18 @@ import { EntityManager } from "typeorm" * properties: * user: * $ref: "#/components/schemas/user" + * "400": + * $ref: "#/components/responses/400_error" + * "401": + * $ref: "#/components/responses/unauthorized" + * "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 { user_id } = req.params diff --git a/packages/medusa/src/api/routes/admin/variants/list-variants.ts b/packages/medusa/src/api/routes/admin/variants/list-variants.ts index 6af7f741a0..9b996dfb3b 100644 --- a/packages/medusa/src/api/routes/admin/variants/list-variants.ts +++ b/packages/medusa/src/api/routes/admin/variants/list-variants.ts @@ -18,6 +18,25 @@ import { validator } from "../../../../utils/validator" * - (query) q {string} Query used for searching variants. * - (query) offset=0 {integer} How many variants to skip in the result. * - (query) limit=20 {integer} Limit the number of variants returned. + * x-codeSamples: + * - lang: JavaScript + * label: JS Client + * source: | + * import Medusa from "@medusajs/medusa-js" + * const medusa = new Medusa({ baseUrl: MEDUSA_BACKEND_URL, maxRetries: 3 }) + * // must be previously logged in or use api token + * medusa.admin.variants.list() + * .then(({ variants, limit, offset, count }) => { + * console.log(variants.length); + * }); + * - lang: Shell + * label: cURL + * source: | + * curl --location --request GET 'https://medusa-url.com/admin/variants' \ + * --header 'Authorization: Bearer {api_token}' + * security: + * - api_token: [] + * - cookie_auth: [] * tags: * - Product Variant * responses: @@ -40,6 +59,18 @@ import { validator } from "../../../../utils/validator" * limit: * type: integer * description: The number of items per page + * "400": + * $ref: "#/components/responses/400_error" + * "401": + * $ref: "#/components/responses/unauthorized" + * "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 variantService: ProductVariantService = req.scope.resolve( diff --git a/packages/medusa/src/api/routes/store/auth/create-session.ts b/packages/medusa/src/api/routes/store/auth/create-session.ts index b965e5d952..f2037a988c 100644 --- a/packages/medusa/src/api/routes/store/auth/create-session.ts +++ b/packages/medusa/src/api/routes/store/auth/create-session.ts @@ -13,6 +13,28 @@ import { EntityManager } from "typeorm" * parameters: * - (body) email=* {string} The Customer's email. * - (body) password=* {string} The Customer's password. + * 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.auth.authenticate({ + * email: 'user@example.com', + * password: 'user@example.com' + * }) + * .then(({ customer }) => { + * console.log(customer.id); + * }); + * - lang: Shell + * label: cURL + * source: | + * curl --location --request POST 'https://medusa-url.com/store/auth' \ + * --header 'Content-Type: application/json' \ + * --data-raw '{ + * "email": "user@example.com", + * "password": "supersecret" + * }' * tags: * - Auth * responses: @@ -24,6 +46,18 @@ import { EntityManager } from "typeorm" * properties: * customer: * $ref: "#/components/schemas/customer" + * "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 validated = await validator(StorePostAuthReq, req.body) diff --git a/packages/medusa/src/api/routes/store/auth/delete-session.ts b/packages/medusa/src/api/routes/store/auth/delete-session.ts index 784b1e108f..91be8254ef 100644 --- a/packages/medusa/src/api/routes/store/auth/delete-session.ts +++ b/packages/medusa/src/api/routes/store/auth/delete-session.ts @@ -3,11 +3,32 @@ * operationId: "DeleteAuth" * summary: "Log out" * description: "Destroys a Customer's authenticated session." + * x-authenticated: true + * x-codeSamples: + * - lang: Shell + * label: cURL + * source: | + * curl --location --request DELETE 'https://medusa-url.com/store/auth' \ + * --header 'Cookie: connect.sid={sid}' + * security: + * - cookie_auth: [] * tags: * - Auth * responses: * "200": * description: OK + * "400": + * $ref: "#/components/responses/400_error" + * "401": + * $ref: "#/components/responses/unauthorized" + * "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) => { req.session.jwt = {} diff --git a/packages/medusa/src/api/routes/store/auth/exists.ts b/packages/medusa/src/api/routes/store/auth/exists.ts index 6baeda0b75..0dbdc1a92c 100644 --- a/packages/medusa/src/api/routes/store/auth/exists.ts +++ b/packages/medusa/src/api/routes/store/auth/exists.ts @@ -12,6 +12,18 @@ import CustomerService from "../../../../services/customer" * format: email * required: true * description: The email to check if exists. + * 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.auth.exists('user@example.com') + * - lang: Shell + * label: cURL + * source: | + * curl --location --request GET 'https://medusa-url.com/store/auth/user@example.com' \ + * --header 'Cookie: connect.sid={sid}' * tags: * - Auth * responses: @@ -24,6 +36,16 @@ import CustomerService from "../../../../services/customer" * exists: * type: boolean * description: Whether email exists or not. + * "400": + * $ref: "#/components/responses/400_error" + * "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 { email } = req.params diff --git a/packages/medusa/src/api/routes/store/auth/get-session.ts b/packages/medusa/src/api/routes/store/auth/get-session.ts index af856a46f4..e37b4ec491 100644 --- a/packages/medusa/src/api/routes/store/auth/get-session.ts +++ b/packages/medusa/src/api/routes/store/auth/get-session.ts @@ -5,11 +5,27 @@ import CustomerService from "../../../../services/customer" * summary: "Get Session" * description: "Gets the currently logged in Customer." * x-authenticated: true + * x-codeSamples: + * - lang: JavaScript + * label: JS Client + * source: | + * import Medusa from "@medusajs/medusa-js" + * const medusa = new Medusa({ baseUrl: MEDUSA_BACKEND_URL, maxRetries: 3 }) + * // must be previously logged + * medusa.auth.getSession() + * .then(({ customer }) => { + * console.log(customer.id); + * }); + * - lang: Shell + * label: cURL + * source: | + * curl --location --request GET 'https://medusa-url.com/store/auth' \ + * --header 'Cookie: connect.sid={sid}' + * security: + * - cookie_auth: [] * tags: * - Auth * responses: - * "401": - * description: Unauthorized * "200": * description: OK * content: @@ -18,6 +34,18 @@ import CustomerService from "../../../../services/customer" * properties: * customer: * $ref: "#/components/schemas/customer" + * "400": + * $ref: "#/components/responses/400_error" + * "401": + * $ref: "#/components/responses/unauthorized" + * "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) => { if (req.user && req.user.customer_id) { diff --git a/packages/medusa/src/api/routes/store/carts/add-shipping-method.ts b/packages/medusa/src/api/routes/store/carts/add-shipping-method.ts index e1471eb649..a932102f47 100644 --- a/packages/medusa/src/api/routes/store/carts/add-shipping-method.ts +++ b/packages/medusa/src/api/routes/store/carts/add-shipping-method.ts @@ -11,12 +11,32 @@ import { validator } from "../../../../utils/validator" * operationId: "PostCartsCartShippingMethod" * description: "Adds a Shipping Method to the Cart." * summary: "Add a Shipping Method" - * tags: - * - Cart * parameters: * - (path) id=* {string} The cart ID. * - (body) option_id=* {string} ID of the shipping option to create the method from * - (body) data {Object} Used to hold any data that the shipping method may need to process the fulfillment of the order. Look at the documentation for your installed fulfillment providers to find out what to send. + * 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.carts.addShippingMethod(cart_id, { + * option_id + * }) + * .then(({ cart }) => { + * console.log(cart.id); + * }); + * - lang: Shell + * label: cURL + * source: | + * curl --location --request POST 'https://medusa-url.com/store/carts/{id}/shipping-methods' \ + * --header 'Content-Type: application/json' \ + * --data-raw '{ + * "option_id": "{option_id}", + * }' + * tags: + * - Cart * responses: * "200": * description: OK @@ -26,6 +46,16 @@ import { validator } from "../../../../utils/validator" * properties: * cart: * $ref: "#/components/schemas/cart" + * "400": + * $ref: "#/components/responses/400_error" + * "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 { id } = req.params diff --git a/packages/medusa/src/api/routes/store/carts/calculate-taxes.ts b/packages/medusa/src/api/routes/store/carts/calculate-taxes.ts index 64e79befe3..62f378f234 100644 --- a/packages/medusa/src/api/routes/store/carts/calculate-taxes.ts +++ b/packages/medusa/src/api/routes/store/carts/calculate-taxes.ts @@ -12,6 +12,11 @@ import { decorateLineItemsWithTotals } from "./decorate-line-items-with-totals" * this may involve making 3rd party API calls to a Tax Provider service." * parameters: * - (path) id=* {String} The Cart ID. + * x-codeSamples: + * - lang: Shell + * label: cURL + * source: | + * curl --location --request POST 'https://medusa-url.com/store/carts/{id}/taxes' * tags: * - Cart * responses: @@ -23,6 +28,16 @@ import { decorateLineItemsWithTotals } from "./decorate-line-items-with-totals" * properties: * cart: * $ref: "#/components/schemas/cart" + * "400": + * $ref: "#/components/responses/400_error" + * "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 { id } = req.params diff --git a/packages/medusa/src/api/routes/store/carts/complete-cart.ts b/packages/medusa/src/api/routes/store/carts/complete-cart.ts index 9362885efd..05305c680f 100644 --- a/packages/medusa/src/api/routes/store/carts/complete-cart.ts +++ b/packages/medusa/src/api/routes/store/carts/complete-cart.ts @@ -15,6 +15,20 @@ import { IdempotencyKeyService } from "../../../../services" * will generate one for the request." * parameters: * - (path) id=* {String} The Cart id. + * 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.carts.complete(cart_id) + * .then(({ cart }) => { + * console.log(cart.id); + * }); + * - lang: Shell + * label: cURL + * source: | + * curl --location --request POST 'https://medusa-url.com/store/carts/{id}/complete' * tags: * - Cart * responses: @@ -50,6 +64,16 @@ import { IdempotencyKeyService } from "../../../../services" * properties: * cart: * $ref: "#/components/schemas/swap" + * "400": + * $ref: "#/components/responses/400_error" + * "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 { id } = req.params diff --git a/packages/medusa/src/api/routes/store/carts/create-cart.ts b/packages/medusa/src/api/routes/store/carts/create-cart.ts index 29cc39a6f6..9e26177075 100644 --- a/packages/medusa/src/api/routes/store/carts/create-cart.ts +++ b/packages/medusa/src/api/routes/store/carts/create-cart.ts @@ -65,6 +65,20 @@ import { isDefined } from "../../../../utils"; * example: * ip: "::1" * user_agent: "Chrome" + * 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.carts.create() + * .then(({ cart }) => { + * console.log(cart.id); + * }); + * - lang: Shell + * label: cURL + * source: | + * curl --location --request POST 'https://medusa-url.com/store/carts' * tags: * - Cart * responses: @@ -76,6 +90,16 @@ import { isDefined } from "../../../../utils"; * properties: * cart: * $ref: "#/components/schemas/cart" + * "400": + * $ref: "#/components/responses/400_error" + * "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 validated = req.validatedBody as StorePostCartReq diff --git a/packages/medusa/src/api/routes/store/carts/create-line-item.ts b/packages/medusa/src/api/routes/store/carts/create-line-item.ts index eed62b2c78..6f4ef1ab71 100644 --- a/packages/medusa/src/api/routes/store/carts/create-line-item.ts +++ b/packages/medusa/src/api/routes/store/carts/create-line-item.ts @@ -17,6 +17,28 @@ import { FlagRouter } from "../../../../utils/flag-router" * - (body) variant_id=* {string} The id of the Product Variant to generate the Line Item from. * - (body) quantity=* {integer} The quantity of the Product Variant to add to the Line Item. * - (body) metadata {object} An optional key-value map with additional details about the Line Item. + * 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.carts.lineItems.create(cart_id, { + * variant_id, + * quantity: 1 + * }) + * .then(({ cart }) => { + * console.log(cart.id); + * }); + * - lang: Shell + * label: cURL + * source: | + * curl --location --request POST 'https://medusa-url.com/store/carts/{id}/line-items' \ + * --header 'Content-Type: application/json' \ + * --data-raw '{ + * "variant_id": "{variant_id}", + * "quantity": 1 + * }' * tags: * - Cart * responses: @@ -28,6 +50,16 @@ import { FlagRouter } from "../../../../utils/flag-router" * properties: * cart: * $ref: "#/components/schemas/cart" + * "400": + * $ref: "#/components/responses/400_error" + * "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 { id } = req.params diff --git a/packages/medusa/src/api/routes/store/carts/create-payment-sessions.ts b/packages/medusa/src/api/routes/store/carts/create-payment-sessions.ts index 537268ab2e..c7f7bfe485 100644 --- a/packages/medusa/src/api/routes/store/carts/create-payment-sessions.ts +++ b/packages/medusa/src/api/routes/store/carts/create-payment-sessions.ts @@ -11,6 +11,20 @@ import IdempotencyKeyService from "../../../../services/idempotency-key"; * description: "Creates Payment Sessions for each of the available Payment Providers in the Cart's Region." * parameters: * - (path) id=* {string} The id of the Cart. + * 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.carts.createPaymentSessions(cart_id) + * .then(({ cart }) => { + * console.log(cart.id); + * }); + * - lang: Shell + * label: cURL + * source: | + * curl --location --request POST 'https://medusa-url.com/store/carts/{id}/payment-sessions' * tags: * - Cart * responses: @@ -22,6 +36,16 @@ import IdempotencyKeyService from "../../../../services/idempotency-key"; * properties: * cart: * $ref: "#/components/schemas/cart" + * "400": + * $ref: "#/components/responses/400_error" + * "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 { id } = req.params diff --git a/packages/medusa/src/api/routes/store/carts/delete-discount.ts b/packages/medusa/src/api/routes/store/carts/delete-discount.ts index cdca0cdcc9..28fa514348 100644 --- a/packages/medusa/src/api/routes/store/carts/delete-discount.ts +++ b/packages/medusa/src/api/routes/store/carts/delete-discount.ts @@ -11,6 +11,20 @@ import { decorateLineItemsWithTotals } from "./decorate-line-items-with-totals" * parameters: * - (path) id=* {string} The id of the Cart. * - (path) code=* {string} The unique Discount code. + * 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.carts.deleteDiscount(cart_id, code) + * .then(({ cart }) => { + * console.log(cart.id); + * }); + * - lang: Shell + * label: cURL + * source: | + * curl --location --request DELETE 'https://medusa-url.com/store/carts/{id}/discounts/{code}' * tags: * - Cart * responses: @@ -22,6 +36,16 @@ import { decorateLineItemsWithTotals } from "./decorate-line-items-with-totals" * properties: * cart: * $ref: "#/components/schemas/cart" + * "400": + * $ref: "#/components/responses/400_error" + * "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 { id, code } = req.params diff --git a/packages/medusa/src/api/routes/store/carts/delete-line-item.ts b/packages/medusa/src/api/routes/store/carts/delete-line-item.ts index e667ad26c7..dfb02f8d14 100644 --- a/packages/medusa/src/api/routes/store/carts/delete-line-item.ts +++ b/packages/medusa/src/api/routes/store/carts/delete-line-item.ts @@ -11,6 +11,20 @@ import { decorateLineItemsWithTotals } from "./decorate-line-items-with-totals" * parameters: * - (path) id=* {string} The id of the Cart. * - (path) line_id=* {string} The id of the Line Item. + * 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.carts.lineItems.delete(cart_id, line_id) + * .then(({ cart }) => { + * console.log(cart.id); + * }); + * - lang: Shell + * label: cURL + * source: | + * curl --location --request DELETE 'https://medusa-url.com/store/carts/{id}/line-items/{line_id}' * tags: * - Cart * responses: @@ -22,6 +36,16 @@ import { decorateLineItemsWithTotals } from "./decorate-line-items-with-totals" * properties: * cart: * $ref: "#/components/schemas/cart" + * "400": + * $ref: "#/components/responses/400_error" + * "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 { id, line_id } = req.params diff --git a/packages/medusa/src/api/routes/store/carts/delete-payment-session.ts b/packages/medusa/src/api/routes/store/carts/delete-payment-session.ts index 55ea6af601..42c0811d58 100644 --- a/packages/medusa/src/api/routes/store/carts/delete-payment-session.ts +++ b/packages/medusa/src/api/routes/store/carts/delete-payment-session.ts @@ -11,6 +11,20 @@ import { EntityManager } from "typeorm"; * parameters: * - (path) id=* {string} The id of the Cart. * - (path) provider_id=* {string} The id of the Payment Provider used to create the Payment Session to be deleted. + * 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.carts.deletePaymentSession(cart_id, 'manual') + * .then(({ cart }) => { + * console.log(cart.id); + * }); + * - lang: Shell + * label: cURL + * source: | + * curl --location --request DELETE 'https://medusa-url.com/store/carts/{id}/payment-sessions/manual' * tags: * - Cart * responses: @@ -22,6 +36,16 @@ import { EntityManager } from "typeorm"; * properties: * cart: * $ref: "#/components/schemas/cart" + * "400": + * $ref: "#/components/responses/400_error" + * "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 { id, provider_id } = req.params diff --git a/packages/medusa/src/api/routes/store/carts/get-cart.ts b/packages/medusa/src/api/routes/store/carts/get-cart.ts index 4876a1e620..cf71f89f26 100644 --- a/packages/medusa/src/api/routes/store/carts/get-cart.ts +++ b/packages/medusa/src/api/routes/store/carts/get-cart.ts @@ -8,6 +8,20 @@ import { decorateLineItemsWithTotals } from "./decorate-line-items-with-totals" * description: "Retrieves a Cart." * parameters: * - (path) id=* {string} The id of the Cart. + * 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.carts.retrieve(cart_id) + * .then(({ cart }) => { + * console.log(cart.id); + * }); + * - lang: Shell + * label: cURL + * source: | + * curl --location --request GET 'https://medusa-url.com/store/carts/{id}' * tags: * - Cart * responses: @@ -19,6 +33,16 @@ import { decorateLineItemsWithTotals } from "./decorate-line-items-with-totals" * properties: * cart: * $ref: "#/components/schemas/cart" + * "400": + * $ref: "#/components/responses/400_error" + * "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 { id } = req.params diff --git a/packages/medusa/src/api/routes/store/carts/refresh-payment-session.ts b/packages/medusa/src/api/routes/store/carts/refresh-payment-session.ts index 131c066b65..0e1742d299 100644 --- a/packages/medusa/src/api/routes/store/carts/refresh-payment-session.ts +++ b/packages/medusa/src/api/routes/store/carts/refresh-payment-session.ts @@ -10,6 +10,20 @@ import { EntityManager } from "typeorm"; * parameters: * - (path) id=* {string} The id of the Cart. * - (path) provider_id=* {string} The id of the Payment Provider that created the Payment Session to be refreshed. + * 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.carts.refreshPaymentSession(cart_id, 'manual') + * .then(({ cart }) => { + * console.log(cart.id); + * }); + * - lang: Shell + * label: cURL + * source: | + * curl --location --request POST 'https://medusa-url.com/store/carts/{id}/payment-sessions/manual/refresh' * tags: * - Cart * responses: @@ -21,6 +35,16 @@ import { EntityManager } from "typeorm"; * properties: * cart: * $ref: "#/components/schemas/cart" + * "400": + * $ref: "#/components/responses/400_error" + * "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 { id, provider_id } = req.params diff --git a/packages/medusa/src/api/routes/store/carts/set-payment-session.ts b/packages/medusa/src/api/routes/store/carts/set-payment-session.ts index 8a8106e500..906348d456 100644 --- a/packages/medusa/src/api/routes/store/carts/set-payment-session.ts +++ b/packages/medusa/src/api/routes/store/carts/set-payment-session.ts @@ -14,6 +14,26 @@ import { validator } from "../../../../utils/validator" * parameters: * - (path) id=* {string} The ID of the Cart. * - (body) provider_id=* {string} The ID of the Payment Provider. + * 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.carts.setPaymentSession(cart_id, { + * provider_id: 'manual' + * }) + * .then(({ cart }) => { + * console.log(cart.id); + * }); + * - lang: Shell + * label: cURL + * source: | + * curl --location --request POST 'https://medusa-url.com/store/carts/{id}/payment-sessions' \ + * --header 'Content-Type: application/json' \ + * --data-raw '{ + * "provider_id": "manual" + * }' * tags: * - Cart * responses: @@ -25,6 +45,16 @@ import { validator } from "../../../../utils/validator" * properties: * cart: * $ref: "#/components/schemas/cart" + * "400": + * $ref: "#/components/responses/400_error" + * "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 { id } = req.params diff --git a/packages/medusa/src/api/routes/store/carts/update-cart.ts b/packages/medusa/src/api/routes/store/carts/update-cart.ts index 206dd22014..b09ef00c95 100644 --- a/packages/medusa/src/api/routes/store/carts/update-cart.ts +++ b/packages/medusa/src/api/routes/store/carts/update-cart.ts @@ -87,6 +87,26 @@ import { decorateLineItemsWithTotals } from "./decorate-line-items-with-totals" * example: * ip: "::1" * user_agent: "Chrome" + * 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.carts.update(cart_id, { + * email: 'user@example.com' + * }) + * .then(({ cart }) => { + * console.log(cart.id); + * }); + * - lang: Shell + * label: cURL + * source: | + * curl --location --request POST 'https://medusa-url.com/store/carts/{id}' \ + * --header 'Content-Type: application/json' \ + * --data-raw '{ + * "email": "user@example.com" + * }' * tags: * - Cart * responses: @@ -98,6 +118,16 @@ import { decorateLineItemsWithTotals } from "./decorate-line-items-with-totals" * properties: * cart: * $ref: "#/components/schemas/cart" + * "400": + * $ref: "#/components/responses/400_error" + * "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 { id } = req.params diff --git a/packages/medusa/src/api/routes/store/carts/update-line-item.ts b/packages/medusa/src/api/routes/store/carts/update-line-item.ts index df81403938..25caeeaafe 100644 --- a/packages/medusa/src/api/routes/store/carts/update-line-item.ts +++ b/packages/medusa/src/api/routes/store/carts/update-line-item.ts @@ -15,6 +15,26 @@ import { decorateLineItemsWithTotals } from "./decorate-line-items-with-totals" * - (path) id=* {string} The id of the Cart. * - (path) line_id=* {string} The id of the Line Item. * - (body) quantity=* {integer} The quantity to set the Line Item to. + * 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.carts.lineItems.update(cart_id, line_id, { + * quantity: 1 + * }) + * .then(({ cart }) => { + * console.log(cart.id); + * }); + * - lang: Shell + * label: cURL + * source: | + * curl --location --request POST 'https://medusa-url.com/store/carts/{id}/line-items/{line_id}' \ + * --header 'Content-Type: application/json' \ + * --data-raw '{ + * "quantity": 1 + * }' * tags: * - Cart * responses: @@ -26,6 +46,16 @@ import { decorateLineItemsWithTotals } from "./decorate-line-items-with-totals" * properties: * cart: * $ref: "#/components/schemas/cart" + * "400": + * $ref: "#/components/responses/400_error" + * "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 { id, line_id } = req.params diff --git a/packages/medusa/src/api/routes/store/carts/update-payment-session.ts b/packages/medusa/src/api/routes/store/carts/update-payment-session.ts index 67b9ca8aed..9bbce00f08 100644 --- a/packages/medusa/src/api/routes/store/carts/update-payment-session.ts +++ b/packages/medusa/src/api/routes/store/carts/update-payment-session.ts @@ -14,6 +14,28 @@ import { EntityManager } from "typeorm"; * - (path) id=* {string} The id of the Cart. * - (path) provider_id=* {string} The id of the payment provider. * - (body) data=* {object} The data to update the payment session with. + * 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.carts.updatePaymentSession(cart_id, 'manual', { + * data: { + * + * } + * }) + * .then(({ cart }) => { + * console.log(cart.id); + * }); + * - lang: Shell + * label: cURL + * source: | + * curl --location --request POST 'https://medusa-url.com/store/carts/{id}/payment-sessions/manual' \ + * --header 'Content-Type: application/json' \ + * --data-raw '{ + * "data": {} + * }' * tags: * - Cart * responses: @@ -25,6 +47,16 @@ import { EntityManager } from "typeorm"; * properties: * cart: * $ref: "#/components/schemas/cart" + * "400": + * $ref: "#/components/responses/400_error" + * "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 { id, provider_id } = req.params diff --git a/packages/medusa/src/api/routes/store/collections/get-collection.ts b/packages/medusa/src/api/routes/store/collections/get-collection.ts index 404fae2583..a810ecf8f7 100644 --- a/packages/medusa/src/api/routes/store/collections/get-collection.ts +++ b/packages/medusa/src/api/routes/store/collections/get-collection.ts @@ -6,6 +6,20 @@ import ProductCollectionService from "../../../../services/product-collection" * description: "Retrieves a Product Collection." * parameters: * - (path) id=* {string} The id of the Product Collection + * 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.collections.retrieve(collection_id) + * .then(({ collection }) => { + * console.log(collection.id); + * }); + * - lang: Shell + * label: cURL + * source: | + * curl --location --request GET 'https://medusa-url.com/store/collections/{id}' * tags: * - Collection * responses: @@ -17,6 +31,16 @@ import ProductCollectionService from "../../../../services/product-collection" * properties: * collection: * $ref: "#/components/schemas/product_collection" + * "400": + * $ref: "#/components/responses/400_error" + * "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) => { diff --git a/packages/medusa/src/api/routes/store/collections/list-collections.ts b/packages/medusa/src/api/routes/store/collections/list-collections.ts index 975eb21096..948599d0ee 100644 --- a/packages/medusa/src/api/routes/store/collections/list-collections.ts +++ b/packages/medusa/src/api/routes/store/collections/list-collections.ts @@ -57,6 +57,20 @@ import { validator } from "../../../../utils/validator" * type: string * description: filter by dates greater than or equal to this date * format: date + * 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.collections.list() + * .then(({ collections, limit, offset, count }) => { + * console.log(collections.length); + * }); + * - lang: Shell + * label: cURL + * source: | + * curl --location --request GET 'https://medusa-url.com/store/collections' * tags: * - Collection * responses: @@ -79,6 +93,16 @@ import { validator } from "../../../../utils/validator" * limit: * type: integer * description: The number of items per page + * "400": + * $ref: "#/components/responses/400_error" + * "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 validated = await validator(StoreGetCollectionsParams, req.query) diff --git a/packages/medusa/src/api/routes/store/customers/create-address.ts b/packages/medusa/src/api/routes/store/customers/create-address.ts index a0c2c488ea..87b3f8394f 100644 --- a/packages/medusa/src/api/routes/store/customers/create-address.ts +++ b/packages/medusa/src/api/routes/store/customers/create-address.ts @@ -23,6 +23,49 @@ import { EntityManager } from "typeorm" * description: "The Address to add to the Customer." * anyOf: * - $ref: "#/components/schemas/address" + * x-codeSamples: + * - lang: JavaScript + * label: JS Client + * source: | + * import Medusa from "@medusajs/medusa-js" + * const medusa = new Medusa({ baseUrl: MEDUSA_BACKEND_URL, maxRetries: 3 }) + * // must be previously logged + * medusa.customers.addresses.addAddress({ + * address: { + * first_name: 'Celia', + * last_name: 'Schumm', + * address_1: '225 Bednar Curve', + * city: 'Danielville', + * country_code: 'US', + * postal_code: '85137', + * phone: '981-596-6748 x90188', + * company: 'Wyman LLC', + * address_2: '', + * province: 'Georgia', + * metadata: {} + * } + * }) + * .then(({ customer }) => { + * console.log(customer.id); + * }); + * - lang: Shell + * label: cURL + * source: | + * curl --location --request POST 'https://medusa-url.com/store/customers/me/addresses' \ + * --header 'Cookie: connect.sid={sid}' \ + * --header 'Content-Type: application/json' \ + * --data-raw '{ + * "address": { + * "first_name": "Celia", + * "last_name": "Schumm", + * "address_1": "225 Bednar Curve", + * "city": "Danielville", + * "country_code": "US", + * "postal_code": "85137" + * } + * }' + * security: + * - cookie_auth: [] * tags: * - Customer * responses: @@ -34,6 +77,18 @@ import { EntityManager } from "typeorm" * properties: * customer: * $ref: "#/components/schemas/customer" + * "400": + * $ref: "#/components/responses/400_error" + * "401": + * $ref: "#/components/responses/unauthorized" + * "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 id = req.user.customer_id diff --git a/packages/medusa/src/api/routes/store/customers/create-customer.ts b/packages/medusa/src/api/routes/store/customers/create-customer.ts index 2bf26a9533..2b2646c840 100644 --- a/packages/medusa/src/api/routes/store/customers/create-customer.ts +++ b/packages/medusa/src/api/routes/store/customers/create-customer.ts @@ -39,6 +39,32 @@ import { EntityManager } from "typeorm" * phone: * description: "The Customer's phone number." * type: string + * 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.customers.create({ + * first_name: 'Alec', + * last_name: 'Reynolds', + * email: 'user@example.com', + * password: 'supersecret' + * }) + * .then(({ customer }) => { + * console.log(customer.id); + * }); + * - lang: Shell + * label: cURL + * source: | + * curl --location --request POST 'https://medusa-url.com/store/customers' \ + * --header 'Content-Type: application/json' \ + * --data-raw '{ + * "first_name": "Alec", + * "last_name": "Reynolds", + * "email": "user@example.com", + * "password": "supersecret" + * }' * tags: * - Customer * responses: @@ -69,6 +95,14 @@ import { EntityManager } from "typeorm" * code: "invalid_request_error" * type: "duplicate_error" * message: "A customer with the given email already has an account. Log in instead" + * "400": + * $ref: "#/components/responses/400_error" + * "404": + * $ref: "#/components/responses/not_found_error" + * "409": + * $ref: "#/components/responses/invalid_state_error" + * "500": + * $ref: "#/components/responses/500_error" */ export default async (req, res) => { const validated = await validator(StorePostCustomersReq, req.body) diff --git a/packages/medusa/src/api/routes/store/customers/delete-address.ts b/packages/medusa/src/api/routes/store/customers/delete-address.ts index f42f7f3623..b8e104b877 100644 --- a/packages/medusa/src/api/routes/store/customers/delete-address.ts +++ b/packages/medusa/src/api/routes/store/customers/delete-address.ts @@ -11,6 +11,24 @@ import { EntityManager } from "typeorm" * x-authenticated: true * parameters: * - (path) address_id=* {string} The id of the Address to remove. + * x-codeSamples: + * - lang: JavaScript + * label: JS Client + * source: | + * import Medusa from "@medusajs/medusa-js" + * const medusa = new Medusa({ baseUrl: MEDUSA_BACKEND_URL, maxRetries: 3 }) + * // must be previously logged + * medusa.customers.addresses.deleteAddress(address_id) + * .then(({ customer }) => { + * console.log(customer.id); + * }); + * - lang: Shell + * label: cURL + * source: | + * curl --location --request DELETE 'https://medusa-url.com/store/customers/me/addresses/{address_id}' \ + * --header 'Cookie: connect.sid={sid}' + * security: + * - cookie_auth: [] * tags: * - Customer * responses: @@ -22,6 +40,18 @@ import { EntityManager } from "typeorm" * properties: * customer: * $ref: "#/components/schemas/customer" + * "400": + * $ref: "#/components/responses/400_error" + * "401": + * $ref: "#/components/responses/unauthorized" + * "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 id = req.user.customer_id diff --git a/packages/medusa/src/api/routes/store/customers/get-customer.ts b/packages/medusa/src/api/routes/store/customers/get-customer.ts index 0d1d153b98..b5404355b5 100644 --- a/packages/medusa/src/api/routes/store/customers/get-customer.ts +++ b/packages/medusa/src/api/routes/store/customers/get-customer.ts @@ -7,6 +7,24 @@ import CustomerService from "../../../../services/customer" * summary: Retrieves a Customer * description: "Retrieves a Customer - the Customer must be logged in to retrieve their details." * x-authenticated: true + * x-codeSamples: + * - lang: JavaScript + * label: JS Client + * source: | + * import Medusa from "@medusajs/medusa-js" + * const medusa = new Medusa({ baseUrl: MEDUSA_BACKEND_URL, maxRetries: 3 }) + * // must be previously logged + * medusa.customers.retrieve() + * .then(({ customer }) => { + * console.log(customer.id); + * }); + * - lang: Shell + * label: cURL + * source: | + * curl --location --request GET 'https://medusa-url.com/store/customers/me' \ + * --header 'Cookie: connect.sid={sid}' + * security: + * - cookie_auth: [] * tags: * - Customer * responses: @@ -18,6 +36,18 @@ import CustomerService from "../../../../services/customer" * properties: * customer: * $ref: "#/components/schemas/customer" + * "400": + * $ref: "#/components/responses/400_error" + * "401": + * $ref: "#/components/responses/unauthorized" + * "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 id = req.user.customer_id diff --git a/packages/medusa/src/api/routes/store/customers/get-payment-methods.ts b/packages/medusa/src/api/routes/store/customers/get-payment-methods.ts index c964102669..35c284833c 100644 --- a/packages/medusa/src/api/routes/store/customers/get-payment-methods.ts +++ b/packages/medusa/src/api/routes/store/customers/get-payment-methods.ts @@ -10,6 +10,24 @@ import { PaymentProvider } from "../../../../models" * summary: Retrieve saved payment methods * description: "Retrieves a list of a Customer's saved payment methods. Payment methods are saved with Payment Providers and it is their responsibility to fetch saved methods." * x-authenticated: true + * x-codeSamples: + * - lang: JavaScript + * label: JS Client + * source: | + * import Medusa from "@medusajs/medusa-js" + * const medusa = new Medusa({ baseUrl: MEDUSA_BACKEND_URL, maxRetries: 3 }) + * // must be previously logged + * medusa.customers.paymentMethods.list() + * .then(({ payment_methods }) => { + * console.log(payment_methods.length); + * }); + * - lang: Shell + * label: cURL + * source: | + * curl --location --request GET 'https://medusa-url.com/store/customers/me/payment-methods' \ + * --header 'Cookie: connect.sid={sid}' + * security: + * - cookie_auth: [] * tags: * - Customer * responses: @@ -29,6 +47,18 @@ import { PaymentProvider } from "../../../../models" * data: * type: object * description: The data needed for the Payment Provider to use the saved payment method. + * "400": + * $ref: "#/components/responses/400_error" + * "401": + * $ref: "#/components/responses/unauthorized" + * "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 id = req.user.customer_id diff --git a/packages/medusa/src/api/routes/store/customers/list-orders.ts b/packages/medusa/src/api/routes/store/customers/list-orders.ts index 5019475b42..9b8f0db48a 100644 --- a/packages/medusa/src/api/routes/store/customers/list-orders.ts +++ b/packages/medusa/src/api/routes/store/customers/list-orders.ts @@ -129,6 +129,24 @@ import { Type } from "class-transformer" * - (query) offset=0 {integer} The offset in the resulting orders. * - (query) fields {string} (Comma separated string) Which fields should be included in the resulting orders. * - (query) expand {string} (Comma separated string) Which relations should be expanded in the resulting orders. + * x-codeSamples: + * - lang: JavaScript + * label: JS Client + * source: | + * import Medusa from "@medusajs/medusa-js" + * const medusa = new Medusa({ baseUrl: MEDUSA_BACKEND_URL, maxRetries: 3 }) + * // must be previously logged + * medusa.customers.listOrders() + * .then(({ orders, limit, offset, count }) => { + * console.log(orders); + * }); + * - lang: Shell + * label: cURL + * source: | + * curl --location --request GET 'https://medusa-url.com/store/customers/me/orders' \ + * --header 'Cookie: connect.sid={sid}' + * security: + * - cookie_auth: [] * tags: * - Customer * responses: @@ -151,6 +169,18 @@ import { Type } from "class-transformer" * limit: * type: integer * description: The number of items per page + * "400": + * $ref: "#/components/responses/400_error" + * "401": + * $ref: "#/components/responses/unauthorized" + * "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: Request, res: Response) => { const id: string | undefined = req.user?.customer_id diff --git a/packages/medusa/src/api/routes/store/customers/reset-password-token.ts b/packages/medusa/src/api/routes/store/customers/reset-password-token.ts index 26de59e6d2..4ff708369a 100644 --- a/packages/medusa/src/api/routes/store/customers/reset-password-token.ts +++ b/packages/medusa/src/api/routes/store/customers/reset-password-token.ts @@ -19,11 +19,46 @@ import { EntityManager } from "typeorm" * description: "The email of the customer." * type: string * format: email + * 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.customers.generatePasswordToken({ + * email: 'user@example.com' + * }) + * .then(() => { + * // successful + * }) + * .catch(() => { + * // failed + * }) + * - lang: Shell + * label: cURL + * source: | + * curl --location --request POST 'https://medusa-url.com/store/customers/password-token' \ + * --header 'Content-Type: application/json' \ + * --data-raw '{ + * "email": "user@example.com" + * }' * tags: * - Customer * responses: * 204: * description: OK + * "400": + * $ref: "#/components/responses/400_error" + * "401": + * $ref: "#/components/responses/unauthorized" + * "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 validated = await validator( diff --git a/packages/medusa/src/api/routes/store/customers/reset-password.ts b/packages/medusa/src/api/routes/store/customers/reset-password.ts index 9af27db335..84138d3732 100644 --- a/packages/medusa/src/api/routes/store/customers/reset-password.ts +++ b/packages/medusa/src/api/routes/store/customers/reset-password.ts @@ -30,6 +30,30 @@ import { EntityManager } from "typeorm" * token: * description: "The reset password token" * type: string + * 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.customers.resetPassword({ + * email: 'user@example.com', + * password: 'supersecret', + * token: 'supersecrettoken' + * }) + * .then(({ customer }) => { + * console.log(customer.id); + * }); + * - lang: Shell + * label: cURL + * source: | + * curl --location --request POST 'https://medusa-url.com/store/customers/password-reset' \ + * --header 'Content-Type: application/json' \ + * --data-raw '{ + * "email": "user@example.com", + * "password": "supersecret", + * "token": "supersecrettoken" + * }' * tags: * - Customer * responses: @@ -41,6 +65,18 @@ import { EntityManager } from "typeorm" * properties: * customer: * $ref: "#/components/schemas/customer" + * "400": + * $ref: "#/components/responses/400_error" + * "401": + * $ref: "#/components/responses/unauthorized" + * "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 validated = await validator( diff --git a/packages/medusa/src/api/routes/store/customers/update-address.ts b/packages/medusa/src/api/routes/store/customers/update-address.ts index fbbc809189..bd68481e73 100644 --- a/packages/medusa/src/api/routes/store/customers/update-address.ts +++ b/packages/medusa/src/api/routes/store/customers/update-address.ts @@ -19,6 +19,30 @@ import { EntityManager } from "typeorm" * schema: * anyOf: * - $ref: "#/components/schemas/address" + * x-codeSamples: + * - lang: JavaScript + * label: JS Client + * source: | + * import Medusa from "@medusajs/medusa-js" + * const medusa = new Medusa({ baseUrl: MEDUSA_BACKEND_URL, maxRetries: 3 }) + * // must be previously logged + * medusa.customers.addresses.updateAddress(address_id, { + * first_name: 'Gina' + * }) + * .then(({ customer }) => { + * console.log(customer.id); + * }); + * - lang: Shell + * label: cURL + * source: | + * curl --location --request POST 'https://medusa-url.com/store/customers/me/addresses/{address_id}' \ + * --header 'Cookie: connect.sid={sid}' \ + * --header 'Content-Type: application/json' \ + * --data-raw '{ + * "first_name": "Gina" + * }' + * security: + * - cookie_auth: [] * tags: * - Customer * responses: @@ -30,6 +54,18 @@ import { EntityManager } from "typeorm" * properties: * customer: * $ref: "#/components/schemas/customer" + * "400": + * $ref: "#/components/responses/400_error" + * "401": + * $ref: "#/components/responses/unauthorized" + * "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 id = req.user.customer_id diff --git a/packages/medusa/src/api/routes/store/customers/update-customer.ts b/packages/medusa/src/api/routes/store/customers/update-customer.ts index 7f93d52bd2..8d5a2d463a 100644 --- a/packages/medusa/src/api/routes/store/customers/update-customer.ts +++ b/packages/medusa/src/api/routes/store/customers/update-customer.ts @@ -43,6 +43,30 @@ import { EntityManager } from "typeorm" * metadata: * description: "Metadata about the customer." * type: object + * x-codeSamples: + * - lang: JavaScript + * label: JS Client + * source: | + * import Medusa from "@medusajs/medusa-js" + * const medusa = new Medusa({ baseUrl: MEDUSA_BACKEND_URL, maxRetries: 3 }) + * // must be previously logged + * medusa.customers.update({ + * first_name: 'Laury' + * }) + * .then(({ customer }) => { + * console.log(customer.id); + * }); + * - lang: Shell + * label: cURL + * source: | + * curl --location --request POST 'https://medusa-url.com/store/customers/me' \ + * --header 'Cookie: connect.sid={sid}' \ + * --header 'Content-Type: application/json' \ + * --data-raw '{ + * "first_name": "Laury" + * }' + * security: + * - cookie_auth: [] * tags: * - Customer * responses: @@ -54,6 +78,18 @@ import { EntityManager } from "typeorm" * properties: * customer: * $ref: "#/components/schemas/customer" + * "400": + * $ref: "#/components/responses/400_error" + * "401": + * $ref: "#/components/responses/unauthorized" + * "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 id = req.user.customer_id diff --git a/packages/medusa/src/api/routes/store/gift-cards/get-gift-card.ts b/packages/medusa/src/api/routes/store/gift-cards/get-gift-card.ts index 1b4b2e8b7d..d4dc1372fc 100644 --- a/packages/medusa/src/api/routes/store/gift-cards/get-gift-card.ts +++ b/packages/medusa/src/api/routes/store/gift-cards/get-gift-card.ts @@ -9,6 +9,20 @@ import GiftCardService from "../../../../services/gift-card" * description: "Retrieves a Gift Card by its associated unqiue code." * parameters: * - (path) code=* {string} The unique Gift Card code. + * 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.giftCards.retrieve(code) + * .then(({ gift_card }) => { + * console.log(gift_card.id); + * }); + * - lang: Shell + * label: cURL + * source: | + * curl --location --request GET 'https://medusa-url.com/store/gift-cards/{code}' * tags: * - Gift Card * responses: @@ -20,6 +34,16 @@ import GiftCardService from "../../../../services/gift-card" * properties: * gift_card: * $ref: "#/components/schemas/gift_card" + * "400": + * $ref: "#/components/responses/400_error" + * "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 { code } = req.params diff --git a/packages/medusa/src/api/routes/store/orders/get-order-by-cart.ts b/packages/medusa/src/api/routes/store/orders/get-order-by-cart.ts index 7dd63384bd..f83cfde797 100644 --- a/packages/medusa/src/api/routes/store/orders/get-order-by-cart.ts +++ b/packages/medusa/src/api/routes/store/orders/get-order-by-cart.ts @@ -9,6 +9,20 @@ import { OrderService } from "../../../../services" * description: "Retrieves an Order by the id of the Cart that was used to create the Order." * parameters: * - (path) cart_id=* {string} The ID of Cart. + * 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.orders.retrieveByCartId(cart_id) + * .then(({ order }) => { + * console.log(order.id); + * }); + * - lang: Shell + * label: cURL + * source: | + * curl --location --request GET 'https://medusa-url.com/store/orders/cart/{id}' * tags: * - Order * responses: @@ -20,6 +34,16 @@ import { OrderService } from "../../../../services" * properties: * order: * $ref: "#/components/schemas/order" + * "400": + * $ref: "#/components/responses/400_error" + * "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 { cart_id } = req.params diff --git a/packages/medusa/src/api/routes/store/orders/get-order.ts b/packages/medusa/src/api/routes/store/orders/get-order.ts index fb4218bc47..248d9686f2 100644 --- a/packages/medusa/src/api/routes/store/orders/get-order.ts +++ b/packages/medusa/src/api/routes/store/orders/get-order.ts @@ -9,6 +9,20 @@ import { OrderService } from "../../../../services" * description: "Retrieves an Order" * parameters: * - (path) id=* {string} The id of the Order. + * 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.orders.retrieve(order_id) + * .then(({ order }) => { + * console.log(order.id); + * }); + * - lang: Shell + * label: cURL + * source: | + * curl --location --request GET 'https://medusa-url.com/store/orders/{id}' * tags: * - Order * responses: @@ -20,6 +34,16 @@ import { OrderService } from "../../../../services" * properties: * order: * $ref: "#/components/schemas/order" + * "400": + * $ref: "#/components/responses/400_error" + * "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 { id } = req.params diff --git a/packages/medusa/src/api/routes/store/orders/lookup-order.ts b/packages/medusa/src/api/routes/store/orders/lookup-order.ts index 2efb40b718..b351b1d106 100644 --- a/packages/medusa/src/api/routes/store/orders/lookup-order.ts +++ b/packages/medusa/src/api/routes/store/orders/lookup-order.ts @@ -38,6 +38,23 @@ import { validator } from "../../../../utils/validator" * postal_code: * type: string * description: The postal code of the shipping address + * 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.orders.lookupOrder({ + * display_id: 1, + * email: 'user@example.com' + * }) + * .then(({ order }) => { + * console.log(order.id); + * }); + * - lang: Shell + * label: cURL + * source: | + * curl --location --request GET 'https://medusa-url.com/store/orders?display_id=1&email=user@example.com' * tags: * - Order * responses: @@ -49,6 +66,16 @@ import { validator } from "../../../../utils/validator" * properties: * order: * $ref: "#/components/schemas/order" + * "400": + * $ref: "#/components/responses/400_error" + * "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 validated = await validator(StoreGetOrdersParams, req.query) diff --git a/packages/medusa/src/api/routes/store/products/get-product.ts b/packages/medusa/src/api/routes/store/products/get-product.ts index 53a3a6ee20..9ea12010f9 100644 --- a/packages/medusa/src/api/routes/store/products/get-product.ts +++ b/packages/medusa/src/api/routes/store/products/get-product.ts @@ -15,6 +15,20 @@ import { validator } from "../../../../utils/validator" * description: "Retrieves a Product." * parameters: * - (path) id=* {string} The id of the Product. + * 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.products.retrieve(product_id) + * .then(({ product }) => { + * console.log(product.id); + * }); + * - lang: Shell + * label: cURL + * source: | + * curl --location --request GET 'https://medusa-url.com/store/products/{id}' * tags: * - Product * responses: @@ -26,6 +40,16 @@ import { validator } from "../../../../utils/validator" * properties: * product: * $ref: "#/components/schemas/product" + * "400": + * $ref: "#/components/responses/400_error" + * "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 { id } = req.params diff --git a/packages/medusa/src/api/routes/store/products/list-products.ts b/packages/medusa/src/api/routes/store/products/list-products.ts index 972556952f..e6bd6d5b16 100644 --- a/packages/medusa/src/api/routes/store/products/list-products.ts +++ b/packages/medusa/src/api/routes/store/products/list-products.ts @@ -113,6 +113,20 @@ import { isDefined } from "../../../../utils" * - (query) limit=100 {integer} Limit the number of products returned. * - (query) expand {string} (Comma separated) Which fields should be expanded in each order of the result. * - (query) fields {string} (Comma separated) Which fields should be included in each order of the result. + * 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.products.list() + * .then(({ products, limit, offset, count }) => { + * console.log(products.length); + * }); + * - lang: Shell + * label: cURL + * source: | + * curl --location --request GET 'https://medusa-url.com/store/products' * tags: * - Product * responses: @@ -135,6 +149,16 @@ import { isDefined } from "../../../../utils" * limit: * type: integer * description: The number of items per page + * "400": + * $ref: "#/components/responses/400_error" + * "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 productService: ProductService = req.scope.resolve("productService") diff --git a/packages/medusa/src/api/routes/store/products/search.ts b/packages/medusa/src/api/routes/store/products/search.ts index d8d61e1448..c826fdd08d 100644 --- a/packages/medusa/src/api/routes/store/products/search.ts +++ b/packages/medusa/src/api/routes/store/products/search.ts @@ -6,8 +6,8 @@ import { Type } from "class-transformer" import { validator } from "../../../../utils/validator" /** - * @oas [get] /products/search - * operationId: GetProductsSearch + * @oas [post] /products/search + * operationId: PostProductsSearch * summary: Search Products * description: "Run a search query on products using the search engine installed on Medusa" * parameters: @@ -15,6 +15,22 @@ import { validator } from "../../../../utils/validator" * - (query) offset {integer} How many products to skip in the result. * - (query) limit {integer} Limit the number of products returned. * - (query) filter {} Filter based on the search engine. + * 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.products.search({ + * q: 'Shirt' + * }) + * .then(({ hits }) => { + * console.log(hits.length); + * }); + * - lang: Shell + * label: cURL + * source: | + * curl --location --request POST 'https://medusa-url.com/store/products/search?q=Shirt' * tags: * - Product * responses: @@ -27,6 +43,16 @@ import { validator } from "../../../../utils/validator" * hits: * type: array * description: Array of results. The format of the items depends on the search engine installed on the server. + * "400": + * $ref: "#/components/responses/400_error" + * "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) => { // As we want to allow wildcards, we pass a config allowing this diff --git a/packages/medusa/src/api/routes/store/regions/get-region.ts b/packages/medusa/src/api/routes/store/regions/get-region.ts index 83a80422d0..d7766d6079 100644 --- a/packages/medusa/src/api/routes/store/regions/get-region.ts +++ b/packages/medusa/src/api/routes/store/regions/get-region.ts @@ -6,6 +6,20 @@ import RegionService from "../../../../services/region" * description: "Retrieves a Region." * parameters: * - (path) id=* {string} The id of the Region. + * 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.regions.retrieve(region_id) + * .then(({ region }) => { + * console.log(region.id); + * }); + * - lang: Shell + * label: cURL + * source: | + * curl --location --request GET 'https://medusa-url.com/store/regions/{id}' * tags: * - Region * responses: @@ -17,6 +31,16 @@ import RegionService from "../../../../services/region" * properties: * region: * $ref: "#/components/schemas/region" + * "400": + * $ref: "#/components/responses/400_error" + * "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 { region_id } = req.params diff --git a/packages/medusa/src/api/routes/store/regions/list-regions.ts b/packages/medusa/src/api/routes/store/regions/list-regions.ts index ffdf84a351..7f311881da 100644 --- a/packages/medusa/src/api/routes/store/regions/list-regions.ts +++ b/packages/medusa/src/api/routes/store/regions/list-regions.ts @@ -58,6 +58,20 @@ import { validator } from "../../../../utils/validator" * type: string * description: filter by dates greater than or equal to this date * format: date + * 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.regions.list() + * .then(({ regions }) => { + * console.log(regions.length); + * }); + * - lang: Shell + * label: cURL + * source: | + * curl --location --request GET 'https://medusa-url.com/store/regions' * tags: * - Region * responses: @@ -71,6 +85,16 @@ import { validator } from "../../../../utils/validator" * type: array * items: * $ref: "#/components/schemas/region" + * "400": + * $ref: "#/components/responses/400_error" + * "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 validated = await validator(StoreGetRegionsParams, req.query) diff --git a/packages/medusa/src/api/routes/store/return-reasons/get-reason.ts b/packages/medusa/src/api/routes/store/return-reasons/get-reason.ts index 47870eea97..241d1166a4 100644 --- a/packages/medusa/src/api/routes/store/return-reasons/get-reason.ts +++ b/packages/medusa/src/api/routes/store/return-reasons/get-reason.ts @@ -11,6 +11,20 @@ import ReturnReasonService from "../../../../services/return-reason" * description: "Retrieves a Return Reason." * parameters: * - (path) id=* {string} The id of the Return Reason. + * 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.returnReasons.retrieve(reason_id) + * .then(({ return_reason }) => { + * console.log(return_reason.id); + * }); + * - lang: Shell + * label: cURL + * source: | + * curl --location --request GET 'https://medusa-url.com/store/return-reasons/{id}' * tags: * - Return Reason * responses: @@ -22,6 +36,16 @@ import ReturnReasonService from "../../../../services/return-reason" * properties: * return_reason: * $ref: "#/components/schemas/return_reason" + * "400": + * $ref: "#/components/responses/400_error" + * "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 { id } = req.params diff --git a/packages/medusa/src/api/routes/store/return-reasons/list-reasons.ts b/packages/medusa/src/api/routes/store/return-reasons/list-reasons.ts index c6cece9e49..d556180beb 100644 --- a/packages/medusa/src/api/routes/store/return-reasons/list-reasons.ts +++ b/packages/medusa/src/api/routes/store/return-reasons/list-reasons.ts @@ -9,6 +9,20 @@ import ReturnReasonService from "../../../../services/return-reason" * operationId: "GetReturnReasons" * summary: "List Return Reasons" * description: "Retrieves a list of Return Reasons." + * 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.returnReasons.list() + * .then(({ return_reasons }) => { + * console.log(return_reasons.length); + * }); + * - lang: Shell + * label: cURL + * source: | + * curl --location --request GET 'https://medusa-url.com/store/return-reasons' * tags: * - Return Reason * responses: @@ -22,6 +36,16 @@ import ReturnReasonService from "../../../../services/return-reason" * type: array * items: * $ref: "#/components/schemas/return_reason" + * "400": + * $ref: "#/components/responses/400_error" + * "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 returnReasonService: ReturnReasonService = req.scope.resolve( diff --git a/packages/medusa/src/api/routes/store/returns/create-return.ts b/packages/medusa/src/api/routes/store/returns/create-return.ts index e93538dcfc..354506f88e 100644 --- a/packages/medusa/src/api/routes/store/returns/create-return.ts +++ b/packages/medusa/src/api/routes/store/returns/create-return.ts @@ -62,6 +62,38 @@ import { validator } from "../../../../utils/validator" * option_id: * type: string * description: The ID of the Shipping Option to create the Shipping Method from. + * 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.returns.create({ + * order_id, + * items: [ + * { + * item_id, + * quantity: 1 + * } + * ] + * }) + * .then(({ return }) => { + * console.log(return.id); + * }); + * - lang: Shell + * label: cURL + * source: | + * curl --location --request POST 'https://medusa-url.com/store/returns' \ + * --header 'Content-Type: application/json' \ + * --data-raw '{ + * "order_id": "asfasf", + * "items": [ + * { + * "item_id": "assfasf", + * "quantity": 1 + * } + * ] + * }' * tags: * - Return * responses: @@ -73,6 +105,16 @@ import { validator } from "../../../../utils/validator" * properties: * return: * $ref: "#/components/schemas/return" + * "400": + * $ref: "#/components/responses/400_error" + * "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 returnDto = await validator(StorePostReturnsReq, req.body) diff --git a/packages/medusa/src/api/routes/store/shipping-options/list-options.ts b/packages/medusa/src/api/routes/store/shipping-options/list-options.ts index 1d2f7ae04b..452184509a 100644 --- a/packages/medusa/src/api/routes/store/shipping-options/list-options.ts +++ b/packages/medusa/src/api/routes/store/shipping-options/list-options.ts @@ -12,6 +12,20 @@ import { validator } from "../../../../utils/validator" * - (query) is_return {boolean} Whether return Shipping Options should be included. By default all Shipping Options are returned. * - (query) product_ids {string} A comma separated list of Product ids to filter Shipping Options by. * - (query) region_id {string} the Region to retrieve Shipping Options from. + * 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.shippingOptions.list() + * .then(({ shipping_options }) => { + * console.log(shipping_options.length); + * }); + * - lang: Shell + * label: cURL + * source: | + * curl --location --request GET 'https://medusa-url.com/store/shipping-options' * tags: * - Shipping Option * responses: @@ -25,6 +39,16 @@ import { validator } from "../../../../utils/validator" * type: array * items: * $ref: "#/components/schemas/shipping_option" + * "400": + * $ref: "#/components/responses/400_error" + * "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 validated = await validator(StoreGetShippingOptionsParams, req.query) diff --git a/packages/medusa/src/api/routes/store/shipping-options/list-shipping-options.ts b/packages/medusa/src/api/routes/store/shipping-options/list-shipping-options.ts index 764f0fbbe4..8711654ce2 100644 --- a/packages/medusa/src/api/routes/store/shipping-options/list-shipping-options.ts +++ b/packages/medusa/src/api/routes/store/shipping-options/list-shipping-options.ts @@ -8,6 +8,20 @@ import ShippingProfileService from "../../../../services/shipping-profile" * description: "Retrieves a list of Shipping Options available to a cart." * parameters: * - (path) cart_id {string} The id of the Cart. + * 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.shippingOptions.listCartOptions(cart_id) + * .then(({ shipping_options }) => { + * console.log(shipping_options.length); + * }); + * - lang: Shell + * label: cURL + * source: | + * curl --location --request GET 'https://medusa-url.com/store/shipping-options/{cart_id}' * tags: * - Shipping Option * responses: @@ -21,6 +35,16 @@ import ShippingProfileService from "../../../../services/shipping-profile" * type: array * items: * $ref: "#/components/schemas/shipping_option" + * "400": + * $ref: "#/components/responses/400_error" + * "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 { cart_id } = req.params diff --git a/packages/medusa/src/api/routes/store/swaps/create-swap.ts b/packages/medusa/src/api/routes/store/swaps/create-swap.ts index c5a261da28..aa80523c19 100644 --- a/packages/medusa/src/api/routes/store/swaps/create-swap.ts +++ b/packages/medusa/src/api/routes/store/swaps/create-swap.ts @@ -72,6 +72,50 @@ import { validator } from "../../../../utils/validator" * quantity: * description: The quantity to send of the variant. * type: integer + * 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.swaps.create({ + * order_id, + * return_items: [ + * { + * item_id, + * quantity: 1 + * } + * ], + * additional_items: [ + * { + * variant_id, + * quantity: 1 + * } + * ] + * }) + * .then(({ swap }) => { + * console.log(swap.id); + * }); + * - lang: Shell + * label: cURL + * source: | + * curl --location --request POST 'https://medusa-url.com/store/swaps' \ + * --header 'Content-Type: application/json' \ + * --data-raw '{ + * "order_id": "asfasf", + * "return_items": [ + * { + * "item_id": "asfas", + * "quantity": 1 + * } + * ], + * "additional_items": [ + * { + * "variant_id": "asfas", + * "quantity": 1 + * } + * ] + * }' * tags: * - Swap * responses: @@ -83,6 +127,16 @@ import { validator } from "../../../../utils/validator" * properties: * swap: * $ref: "#/components/schemas/swap" + * "400": + * $ref: "#/components/responses/400_error" + * "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 swapDto = await validator(StorePostSwapsReq, req.body) diff --git a/packages/medusa/src/api/routes/store/swaps/get-swap-by-cart.ts b/packages/medusa/src/api/routes/store/swaps/get-swap-by-cart.ts index 3298ed7054..99f842ff65 100644 --- a/packages/medusa/src/api/routes/store/swaps/get-swap-by-cart.ts +++ b/packages/medusa/src/api/routes/store/swaps/get-swap-by-cart.ts @@ -6,6 +6,20 @@ import SwapService from "../../../../services/swap" * description: "Retrieves a Swap by the id of the Cart used to confirm the Swap." * parameters: * - (path) cart_id {string} The id of the Cart + * 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.swaps.retrieveByCartId(cart_id) + * .then(({ swap }) => { + * console.log(swap.id); + * }); + * - lang: Shell + * label: cURL + * source: | + * curl --location --request GET 'https://medusa-url.com/store/swaps/{cart_id}' * tags: * - Swap * responses: @@ -17,6 +31,16 @@ import SwapService from "../../../../services/swap" * properties: * swap: * $ref: "#/components/schemas/swap" + * "400": + * $ref: "#/components/responses/400_error" + * "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 { cart_id } = req.params diff --git a/packages/medusa/src/api/routes/store/variants/get-variant.ts b/packages/medusa/src/api/routes/store/variants/get-variant.ts index da5634678f..ea47f3b065 100644 --- a/packages/medusa/src/api/routes/store/variants/get-variant.ts +++ b/packages/medusa/src/api/routes/store/variants/get-variant.ts @@ -28,6 +28,11 @@ import { validator } from "../../../../utils/validator" * externalDocs: * url: https://en.wikipedia.org/wiki/ISO_4217#Active_codes * description: See a list of codes. + * x-codeSamples: + * - lang: Shell + * label: cURL + * source: | + * curl --location --request GET 'https://medusa-url.com/store/variants/{id}' * tags: * - Product Variant * responses: @@ -39,6 +44,16 @@ import { validator } from "../../../../utils/validator" * properties: * variant: * $ref: "#/components/schemas/product_variant" + * "400": + * $ref: "#/components/responses/400_error" + * "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 { id } = req.params diff --git a/packages/medusa/src/api/routes/store/variants/list-variants.ts b/packages/medusa/src/api/routes/store/variants/list-variants.ts index 75bfdff6c8..01be56e307 100644 --- a/packages/medusa/src/api/routes/store/variants/list-variants.ts +++ b/packages/medusa/src/api/routes/store/variants/list-variants.ts @@ -60,6 +60,11 @@ import { validator } from "../../../../utils/validator" * gte: * type: number * description: filter by inventory quantity greater than or equal to this number + * x-codeSamples: + * - lang: Shell + * label: cURL + * source: | + * curl --location --request GET 'https://medusa-url.com/store/variants' * tags: * - Product Variant * responses: @@ -73,6 +78,16 @@ import { validator } from "../../../../utils/validator" * type: array * items: * $ref: "#/components/schemas/product_variant" + * "400": + * $ref: "#/components/responses/400_error" + * "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 validated = await validator(StoreGetVariantsParams, req.query) diff --git a/scripts/build-openapi.js b/scripts/build-openapi.js index c219624ab2..2fd99bffe4 100755 --- a/scripts/build-openapi.js +++ b/scripts/build-openapi.js @@ -4,15 +4,14 @@ const fs = require("fs") const OAS = require("oas-normalize") const swaggerInline = require("swagger-inline") const { exec } = require("child_process"); -const { exit } = require("process"); const isDryRun = process.argv.indexOf('--dry-run') !== -1; // Storefront API swaggerInline( - ["./packages/medusa/src/models", "./packages/medusa/src/api/routes/store"], + ["./packages/medusa/src/models", "./packages/medusa/src/api/middlewares" , "./packages/medusa/src/api/routes/store"], { - base: "./docs/api/store-spec3-base.json", + base: "./docs/api/store-spec3-base.yaml", } ).then((gen) => { const oas = new OAS(gen) @@ -31,9 +30,9 @@ swaggerInline( }) swaggerInline( - ["./packages/medusa/src/models", "./packages/medusa/src/api/routes/store"], + ["./packages/medusa/src/models", "./packages/medusa/src/api/middlewares" , "./packages/medusa/src/api/routes/store"], { - base: "./docs/api/store-spec3-base.json", + base: "./docs/api/store-spec3-base.yaml", format: "yaml", } ).then((gen) => { @@ -52,9 +51,9 @@ swaggerInline( // Admin API swaggerInline( - ["./packages/medusa/src/models", "./packages/medusa/src/api/routes/admin"], + ["./packages/medusa/src/models", "./packages/medusa/src/api/middlewares" , "./packages/medusa/src/api/routes/admin"], { - base: "./docs/api/admin-spec3-base.json", + base: "./docs/api/admin-spec3-base.yaml", } ).then((gen) => { const oas = new OAS(gen) @@ -73,9 +72,9 @@ swaggerInline( }) swaggerInline( - ["./packages/medusa/src/models", "./packages/medusa/src/api/routes/admin"], + ["./packages/medusa/src/models", "./packages/medusa/src/api/middlewares" , "./packages/medusa/src/api/routes/admin"], { - base: "./docs/api/admin-spec3-base.json", + base: "./docs/api/admin-spec3-base.yaml", format: "yaml", } ).then((gen) => { @@ -91,4 +90,4 @@ swaggerInline( } else { console.log('No errors occurred while generating Admin API Reference'); } -}) +}) \ No newline at end of file diff --git a/www/docs/docusaurus.config.js b/www/docs/docusaurus.config.js index 9f75c53b36..f7f818c515 100644 --- a/www/docs/docusaurus.config.js +++ b/www/docs/docusaurus.config.js @@ -228,10 +228,11 @@ module.exports = { expandResponses: "200,204", generatedPayloadSamplesMaxDepth: 4, showObjectSchemaExamples: true, - requiredPropsFirst: true + requiredPropsFirst: true, + hideRequestPayloadSample: true } } }, ], ], -} +} \ No newline at end of file diff --git a/www/docs/src/css/custom.css b/www/docs/src/css/custom.css index 7980436b53..9b2f3f2f29 100644 --- a/www/docs/src/css/custom.css +++ b/www/docs/src/css/custom.css @@ -332,6 +332,23 @@ html[data-theme="dark"] .redocusaurus .expanded + tr > td > div { color: var(--ifm-link-color) !important; } +.redocusaurus [data-section-id] > div:nth-child(2) pre { + background-color: transparent !important; + margin-top: 10px; +} + +html[data-theme="dark"] .redocusaurus h5 + svg { + fill: #fff; +} + +html[data-theme="dark"] .redocusaurus h2 + div + div > div + div { + padding: 8px 9.6px; +} + +html[data-theme="dark"] .redocusaurus h2 + div + div > div + div { + background-color: #11171a; +} + /* User Guide Styling */ html[data-theme="dark"] kbd { --ifm-color-emphasis-0: var(--ifm-color-gray-200);