chore: fixes to JS SDK TSDocs (#12159)

This commit is contained in:
Shahed Nasser authored and GitHub committed 2025-04-11 16:41:52 +03:00
1 parent cd66cdd2bb
commit 90f9149735
4 files changed
+46 -72

No files matched your search

+1 -1
View File
@@ -700,7 +700,7 @@ export class Claim {
* @returns The details of the claim, with a preview of the order when the claim is applied. * @returns The details of the claim, with a preview of the order when the claim is applied.
* *
* @example * @example
* * sdk.admin.claim.addOutboundShipping( * sdk.admin.claim.addOutboundShipping(
* "claim_123", * "claim_123",
* { * {
* shipping_option_id: "so_123", * shipping_option_id: "so_123",
+19 -63
View File
@@ -130,9 +130,6 @@ export class DraftOrder {
* @param headers - Headers to pass in the request. * @param headers - Headers to pass in the request.
* *
* @example * @example
* To create a draft order:
*
* ```ts
* sdk.admin.draftOrder.create({ * sdk.admin.draftOrder.create({
* email: "test@test.com", * email: "test@test.com",
* items: [ * items: [
@@ -147,7 +144,6 @@ export class DraftOrder {
* .then(({ draft_order }) => { * .then(({ draft_order }) => {
* console.log(draft_order) * console.log(draft_order)
* }) * })
* ```
*/ */
async create( async create(
body: HttpTypes.AdminCreateDraftOrder, body: HttpTypes.AdminCreateDraftOrder,
@@ -175,16 +171,12 @@ export class DraftOrder {
* @param headers - Headers to pass in the request. * @param headers - Headers to pass in the request.
* *
* @example * @example
* To update a draft order:
*
* ```ts
* sdk.admin.draftOrder.update("order_123", { * sdk.admin.draftOrder.update("order_123", {
* email: "test@test.com", * email: "test@test.com",
* }) * })
* .then(({ draft_order }) => { * .then(({ draft_order }) => {
* console.log(draft_order) * console.log(draft_order)
* }) * })
* ```
*/ */
async update( async update(
id: string, id: string,
@@ -212,9 +204,6 @@ export class DraftOrder {
* @param headers - Headers to pass in the request. * @param headers - Headers to pass in the request.
* *
* @example * @example
* To convert a draft order to an order:
*
* ```ts
* sdk.admin.draftOrder.convertToOrder("order_123") * sdk.admin.draftOrder.convertToOrder("order_123")
* .then(({ order }) => { * .then(({ order }) => {
* console.log(order) * console.log(order)
@@ -244,9 +233,6 @@ export class DraftOrder {
* @param headers - Headers to pass in the request. * @param headers - Headers to pass in the request.
* *
* @example * @example
* To add items to a draft order:
*
* ```ts
* sdk.admin.draftOrder.addItems("order_123", { * sdk.admin.draftOrder.addItems("order_123", {
* items: [ * items: [
* { * {
@@ -258,7 +244,6 @@ export class DraftOrder {
* .then(({ draft_order_preview }) => { * .then(({ draft_order_preview }) => {
* console.log(draft_order_preview) * console.log(draft_order_preview)
* }) * })
* ```
*/ */
async addItems( async addItems(
id: string, id: string,
@@ -285,16 +270,12 @@ export class DraftOrder {
* @param headers - Headers to pass in the request. * @param headers - Headers to pass in the request.
* *
* @example * @example
* To update an item that is part of an action in a draft order:
*
* ```ts
* sdk.admin.draftOrder.updateActionItem("order_123", "action_123", { * sdk.admin.draftOrder.updateActionItem("order_123", "action_123", {
* quantity: 2, * quantity: 2,
* }) * })
* .then(({ draft_order_preview }) => { * .then(({ draft_order_preview }) => {
* console.log(draft_order_preview) * console.log(draft_order_preview)
* }) * })
* ```
*/ */
async updateActionItem( async updateActionItem(
id: string, id: string,
@@ -321,14 +302,10 @@ export class DraftOrder {
* @param headers - Headers to pass in the request. * @param headers - Headers to pass in the request.
* *
* @example * @example
* To remove an item that is part of an action in a draft order:
*
* ```ts
* sdk.admin.draftOrder.removeActionItem("order_123", "action_123") * sdk.admin.draftOrder.removeActionItem("order_123", "action_123")
* .then(({ draft_order_preview }) => { * .then(({ draft_order_preview }) => {
* console.log(draft_order_preview) * console.log(draft_order_preview)
* }) * })
* ```
*/ */
async removeActionItem( async removeActionItem(
id: string, id: string,
@@ -352,18 +329,15 @@ export class DraftOrder {
* @param itemId - The item ID. * @param itemId - The item ID.
* @param body - The data to update the item. * @param body - The data to update the item.
* @param headers - Headers to pass in the request. * @param headers - Headers to pass in the request.
* @returns The draft order preview's details.
* *
* @example * @example
* To update an item in a draft order:
*
* ```ts
* sdk.admin.draftOrder.updateItem("order_123", "item_123", { * sdk.admin.draftOrder.updateItem("order_123", "item_123", {
* quantity: 2, * quantity: 2,
* }) * })
* .then(({ draft_order_preview }) => { * .then(({ draft_order_preview }) => {
* console.log(draft_order_preview) * console.log(draft_order_preview)
* }) * })
* ```
*/ */
async updateItem( async updateItem(
id: string, id: string,
@@ -390,16 +364,12 @@ export class DraftOrder {
* @param headers - Headers to pass in the request. * @param headers - Headers to pass in the request.
* *
* @example * @example
* To add promotions to a draft order:
*
* ```ts
* sdk.admin.draftOrder.addPromotions("order_123", { * sdk.admin.draftOrder.addPromotions("order_123", {
* promo_codes: ["PROMO_CODE_1", "PROMO_CODE_2"], * promo_codes: ["PROMO_CODE_1", "PROMO_CODE_2"],
* }) * })
* .then(({ draft_order_preview }) => { * .then(({ draft_order_preview }) => {
* console.log(draft_order_preview) * console.log(draft_order_preview)
* }) * })
* ```
*/ */
async addPromotions( async addPromotions(
id: string, id: string,
@@ -425,13 +395,9 @@ export class DraftOrder {
* @param headers - Headers to pass in the request. * @param headers - Headers to pass in the request.
* *
* @example * @example
* To remove promotions from a draft order:
*
* ```ts
* sdk.admin.draftOrder.removePromotions("order_123", { * sdk.admin.draftOrder.removePromotions("order_123", {
* promo_codes: ["PROMO_CODE_1", "PROMO_CODE_2"], * promo_codes: ["PROMO_CODE_1", "PROMO_CODE_2"],
* }) * })
* ```
*/ */
async removePromotions( async removePromotions(
id: string, id: string,
@@ -457,16 +423,12 @@ export class DraftOrder {
* @param headers - Headers to pass in the request. * @param headers - Headers to pass in the request.
* *
* @example * @example
* To add a shipping method to a draft order:
*
* ```ts
* sdk.admin.draftOrder.addShippingMethod("order_123", { * sdk.admin.draftOrder.addShippingMethod("order_123", {
* shipping_option_id: "shipping_option_123", * shipping_option_id: "shipping_option_123",
* }) * })
* .then(({ draft_order_preview }) => { * .then(({ draft_order_preview }) => {
* console.log(draft_order_preview) * console.log(draft_order_preview)
* }) * })
* ```
*/ */
async addShippingMethod( async addShippingMethod(
id: string, id: string,
@@ -493,16 +455,12 @@ export class DraftOrder {
* @param headers - Headers to pass in the request. * @param headers - Headers to pass in the request.
* *
* @example * @example
* To update a shipping method in a draft order:
*
* ```ts
* sdk.admin.draftOrder.updateShippingMethod("order_123", "action_123", { * sdk.admin.draftOrder.updateShippingMethod("order_123", "action_123", {
* shipping_option_id: "shipping_option_123", * shipping_option_id: "shipping_option_123",
* }) * })
* .then(({ draft_order_preview }) => { * .then(({ draft_order_preview }) => {
* console.log(draft_order_preview) * console.log(draft_order_preview)
* }) * })
* ```
*/ */
async updateActionShippingMethod( async updateActionShippingMethod(
id: string, id: string,
@@ -529,14 +487,10 @@ export class DraftOrder {
* @param headers - Headers to pass in the request. * @param headers - Headers to pass in the request.
* *
* @example * @example
* To remove a shipping method from a draft order:
*
* ```ts
* sdk.admin.draftOrder.removeShippingMethod("order_123", "action_123") * sdk.admin.draftOrder.removeShippingMethod("order_123", "action_123")
* .then(({ draft_order_preview }) => { * .then(({ draft_order_preview }) => {
* console.log(draft_order_preview) * console.log(draft_order_preview)
* }) * })
* ```
*/ */
async removeActionShippingMethod( async removeActionShippingMethod(
id: string, id: string,
@@ -552,6 +506,24 @@ export class DraftOrder {
) )
} }
/**
* This method updates a shipping method in a draft order. It sends a request to the
* [Update Draft Order Shipping Method](https://docs.medusajs.com/api/admin#draft-orders_postordereditsidshipping-methodsaction_id) API route.
*
* @param id - The draft order's ID.
* @param methodId - The shipping method's ID.
* @param body - The data to update the shipping method.
* @param headers - Headers to pass in the request.
* @returns The draft order preview's details.
*
* @example
* sdk.admin.draftOrder.updateShippingMethod("order_123", "sm_123", {
* shipping_option_id: "so_123",
* })
* .then(({ draft_order_preview }) => {
* console.log(draft_order_preview)
* })
*/
async updateShippingMethod( async updateShippingMethod(
id: string, id: string,
methodId: string, methodId: string,
@@ -575,14 +547,10 @@ export class DraftOrder {
* @param headers - Headers to pass in the request. * @param headers - Headers to pass in the request.
* *
* @example * @example
* To begin an edit to a draft order:
*
* ```ts
* sdk.admin.draftOrder.beginEdit("order_123") * sdk.admin.draftOrder.beginEdit("order_123")
* .then(({ draft_order_preview }) => { * .then(({ draft_order_preview }) => {
* console.log(draft_order_preview) * console.log(draft_order_preview)
* }) * })
* ```
*/ */
async beginEdit(id: string, headers?: ClientHeaders) { async beginEdit(id: string, headers?: ClientHeaders) {
return await this.client.fetch<HttpTypes.AdminDraftOrderPreviewResponse>( return await this.client.fetch<HttpTypes.AdminDraftOrderPreviewResponse>(
@@ -602,14 +570,10 @@ export class DraftOrder {
* @param headers - Headers to pass in the request. * @param headers - Headers to pass in the request.
* *
* @example * @example
* To cancel an edit to a draft order:
*
* ```ts
* sdk.admin.draftOrder.cancelEdit("order_123") * sdk.admin.draftOrder.cancelEdit("order_123")
* .then(({ id, object, deleted }) => { * .then(({ id, object, deleted }) => {
* console.log(id, object, deleted) * console.log(id, object, deleted)
* }) * })
* ```
*/ */
async cancelEdit(id: string, headers?: ClientHeaders) { async cancelEdit(id: string, headers?: ClientHeaders) {
return await this.client.fetch< return await this.client.fetch<
@@ -628,14 +592,10 @@ export class DraftOrder {
* @param headers - Headers to pass in the request. * @param headers - Headers to pass in the request.
* *
* @example * @example
* To request an edit to a draft order:
*
* ```ts
* sdk.admin.draftOrder.requestEdit("order_123") * sdk.admin.draftOrder.requestEdit("order_123")
* .then(({ draft_order_preview }) => { * .then(({ draft_order_preview }) => {
* console.log(draft_order_preview) * console.log(draft_order_preview)
* }) * })
* ```
*/ */
async requestEdit(id: string, headers?: ClientHeaders) { async requestEdit(id: string, headers?: ClientHeaders) {
return await this.client.fetch<HttpTypes.AdminDraftOrderPreviewResponse>( return await this.client.fetch<HttpTypes.AdminDraftOrderPreviewResponse>(
@@ -655,14 +615,10 @@ export class DraftOrder {
* @param headers - Headers to pass in the request. * @param headers - Headers to pass in the request.
* *
* @example * @example
* To confirm an edit to a draft order:
*
* ```ts
* sdk.admin.draftOrder.confirmEdit("order_123") * sdk.admin.draftOrder.confirmEdit("order_123")
* .then(({ draft_order_preview }) => { * .then(({ draft_order_preview }) => {
* console.log(draft_order_preview) * console.log(draft_order_preview)
* }) * })
* ```
*/ */
async confirmEdit(id: string, headers?: ClientHeaders) { async confirmEdit(id: string, headers?: ClientHeaders) {
return await this.client.fetch<HttpTypes.AdminDraftOrderPreviewResponse>( return await this.client.fetch<HttpTypes.AdminDraftOrderPreviewResponse>(
+3 -8
View File
@@ -32,25 +32,20 @@ export class Invite {
* @returns The user's details. * @returns The user's details.
* *
* @example * @example
* const token = await sdk.auth.register("user", "emailpass", { * await sdk.auth.register("user", "emailpass", {
* email: "user@gmail.com", * email: "user@gmail.com",
* password: "supersecret" * password: "supersecret"
* }) * })
* *
* sdk.admin.invite.accept( * // all subsequent requests will use the token in the header
* const { user } = await sdk.admin.invite.accept(
* { * {
* email: "user@gmail.com", * email: "user@gmail.com",
* first_name: "John", * first_name: "John",
* last_name: "Smith", * last_name: "Smith",
* invite_token: "12345..." * invite_token: "12345..."
* }, * },
* {
* Authorization: `Bearer ${token}`
* }
* ) * )
* .then(({ user }) => {
* console.log(user)
* })
*/ */
async accept( async accept(
input: HttpTypes.AdminAcceptInvite & { input: HttpTypes.AdminAcceptInvite & {
+23
View File
@@ -501,6 +501,29 @@ export class Order {
) )
} }
/**
* This method creates a credit line for an order. It sends a request to the
* [Create Credit Line](https://docs.medusajs.com/api/admin#orders_postordersidcredit-lines) API route.
*
* @param orderId - The order's ID.
* @param body - The credit line's details.
* @param query - Configure the fields to retrieve in the order.
* @param headers - Headers to pass in the request
* @returns The order's details.
*
* @example
* sdk.admin.order.createCreditLine(
* "order_123",
* {
* amount: 100,
* reference: "order",
* reference_id: "order_123",
* }
* )
* .then(({ order }) => {
* console.log(order)
* })
*/
async createCreditLine( async createCreditLine(
orderId: string, orderId: string,
body: Omit<CreateOrderCreditLineDTO, "order_id">, body: Omit<CreateOrderCreditLineDTO, "order_id">,