chore(js-sdk,types): add tsdocs for admin JS SDK methods [3/n] (#9712)

This commit is contained in:
Shahed Nasser
2024-10-22 18:08:33 +03:00
committed by GitHub
parent 1c1ba88220
commit 14efb2a420
22 changed files with 1327 additions and 15 deletions

View File

@@ -14,6 +14,21 @@ export class FulfillmentSet {
this.client = client
}
/**
* This method deletes a fulfillment set. It sends a request to the
* [Delete Fulfillment Set](https://docs.medusajs.com/v2/api/admin#fulfillment-sets_deletefulfillmentsetsid)
* API route.
*
* @param id - The fulfillment set's ID.
* @param headers - Headers to pass in the request.
* @returns The deletion's details.
*
* @example
* sdk.admin.fulfillmentSet.delete("fset_123")
* .then(({ deleted }) => {
* console.log(deleted)
* })
*/
async delete(id: string, headers?: ClientHeaders) {
return await this.client.fetch<HttpTypes.AdminFulfillmentSetDeleteResponse>(
`/admin/fulfillment-sets/${id}`,
@@ -24,6 +39,29 @@ export class FulfillmentSet {
)
}
/**
* This method adds a service zone to a fulfillment set. It uses the
* [Add Service Zone](https://docs.medusajs.com/v2/api/admin#fulfillment-sets_postfulfillmentsetsidservicezones)
* API route.
*
* @param id - The fulfillment set's ID.
* @param body - The service zone's details.
* @param query - Configure the fields to retrieve in the fulfillment set.
* @param headers - Headers to pass in the request.
* @returns The fulfillment set's details.
*
* @example
* sdk.admin.fulfillmentSet.createServiceZone("fset_123", {
* name: "Europe Service Zone",
* geo_zones: [{
* type: "country",
* country_code: "us"
* }]
* })
* .then(({ fulfillment_set }) => {
* console.log(fulfillment_set)
* })
*/
async createServiceZone(
id: string,
body: HttpTypes.AdminCreateFulfillmentSetServiceZone,
@@ -41,6 +79,47 @@ export class FulfillmentSet {
)
}
/**
* This method retrieves a fulfillment set's service zone's details. It sends a request to the
* [Get Service Zone](https://docs.medusajs.com/v2/api/admin#fulfillment-sets_getfulfillmentsetsidservicezoneszone_id)
* API route.
*
* @param fulfillmentSetId - The fulfillment set's ID.
* @param serviceZoneId - The service zone's ID.
* @param query - Configure the fields to retrieve in the service zone.
* @param headers - Headers to pass in the request.
* @returns The service zone's details.
*
* @example
* To retrieve a fulfillment set's service zone by its ID:
*
* ```ts
* sdk.admin.fulfillmentSet.retrieveServiceZone(
* "fset_123",
* "serzo_123"
* )
* .then(({ service_zone }) => {
* console.log(service_zone)
* })
* ```
*
* To specify the fields and relations to retrieve:
*
* ```ts
* sdk.admin.fulfillmentSet.retrieveServiceZone(
* "fset_123",
* "serzo_123",
* {
* fields: "id,*geo_zones"
* }
* )
* .then(({ service_zone }) => {
* console.log(service_zone)
* })
* ```
*
* Learn more about the `fields` property in the [API reference](https://docs.medusajs.com/v2/api/store#select-fields-and-relations).
*/
async retrieveServiceZone(
fulfillmentSetId: string,
serviceZoneId: string,
@@ -57,6 +136,30 @@ export class FulfillmentSet {
)
}
/**
* This method updates a service zone in a fulfillment set. It sends a request to the
* [Update Service Zone](https://docs.medusajs.com/v2/api/admin#fulfillment-sets_postfulfillmentsetsidservicezoneszone_id)
* API route.
*
* @param fulfillmentSetId - The fulfillment set's ID.
* @param serviceZoneId - The service zone's ID.
* @param body - The data to update in the service zone.
* @param query - Configure the fields to retrieve in the fulfillment set.
* @param headers - Headers to pass in the request.
* @returns The fulfillment set's details.
*
* @example
* sdk.admin.fulfillmentSet.updateServiceZone(
* "fset_123",
* "serzo_123",
* {
* name: "Europe Service Zone",
* }
* )
* .then(({ fulfillment_set }) => {
* console.log(fulfillment_set)
* })
*/
async updateServiceZone(
fulfillmentSetId: string,
serviceZoneId: string,
@@ -75,6 +178,25 @@ export class FulfillmentSet {
)
}
/**
* This method deletes a service zone in a fulfillment set. It sends a request to the
* [Remove Service Zone](https://docs.medusajs.com/v2/api/admin#fulfillment-sets_deletefulfillmentsetsidservicezoneszone_id)
* API route.
*
* @param fulfillmentSetId - The fulfullment set's ID.
* @param serviceZoneId - The service zone's ID.
* @param headers - Headers to pass in the request.
* @returns The deletion's details.
*
* @example
* sdk.admin.fulfillmentSet.deleteServiceZone(
* "fset_123",
* "serzo_123",
* )
* .then(({ deleted, parent: fulfillmentSet }) => {
* console.log(deleted, fulfillmentSet)
* })
*/
async deleteServiceZone(
fulfillmentSetId: string,
serviceZoneId: string,

View File

@@ -14,6 +14,39 @@ export class Fulfillment {
this.client = client
}
/**
* This method creates a fulfillment. It sends a request to the
* [Create Fulfillment](https://docs.medusajs.com/v2/api/admin#fulfillments_postfulfillments)
* API route.
*
* @param body - The fulfillment's details.
* @param query - Configure the fields to retrieve in the fulfillment.
* @param headers - Headers to pass in the request.
* @returns The fulfillment's details.
*
* @example
* sdk.admin.fulfillment.create({
* location_id: "sloc_123",
* provider_id: "my_fulfillment",
* delivery_address: {
* country_code: "us"
* },
* items: [
* {
* title: "Shirt",
* sku: "SHIRT",
* quantity: 1,
* barcode: "123"
* }
* ],
* labels: [],
* order: {},
* order_id: "order_123"
* })
* .then(({ fulfillment }) => {
* console.log(fulfillment)
* })
*/
async create(
body: HttpTypes.AdminCreateFulfillment,
query?: HttpTypes.SelectParams,
@@ -30,6 +63,22 @@ export class Fulfillment {
)
}
/**
* This method cancels a fulfillment. It sends a request to the
* [Cancel Fulfillment](https://docs.medusajs.com/v2/api/admin#fulfillments_postfulfillmentsidcancel)
* API route.
*
* @param id - The fulfillment's ID.
* @param query - Configure the fields to retrieve in the fulfillment.
* @param headers - Headers to pass in the request.
* @returns The fulfillment's details.
*
* @example
* sdk.admin.fulfillment.cancel("ful_123")
* .then(({ fulfillment }) => {
* console.log(fulfillment)
* })
*/
async cancel(
id: string,
query?: HttpTypes.SelectParams,
@@ -41,10 +90,36 @@ export class Fulfillment {
method: "POST",
body: {},
headers,
query
}
)
}
/**
* This method creates a shipment for a fulfillment. It sends a request to the
* [Create Shipment](https://docs.medusajs.com/v2/api/admin#fulfillments_postfulfillmentsidshipment)
* API route.
*
* @param id - The fulfillment's ID.
* @param body - The shipment's details.
* @param query - Configure the fields to retrieve in the fulfillment.
* @param headers - Headers to pass in the request.
* @returns The fulfillment's details.
*
* @example
* sdk.admin.fulfillment.createShipment("ful_123", {
* labels: [
* {
* tracking_number: "123",
* tracking_url: "example.com",
* label_url: "example.com"
* }
* ]
* })
* .then(({ fulfillment }) => {
* console.log(fulfillment)
* })
*/
async createShipment(
id: string,
body: HttpTypes.AdminCreateFulfillmentShipment,

View File

@@ -14,6 +14,24 @@ export class InventoryItem {
this.client = client
}
/**
* This method creates an inventory item. It sends a request to the
* [Create Inventory Item](https://docs.medusajs.com/v2/api/admin#inventory-items_postinventoryitems)
* API route.
*
* @param body - The inventory item's details.
* @param query - Configure the fields to retrieve in the inventory item.
* @param headers - Headers to pass in the request.
* @returns The inventory item's details.
*
* @example
* sdk.admin.inventoryItem.create({
* sku: "SHIRT"
* })
* .then(({ inventory_item }) => {
* console.log(inventory_item)
* })
*/
async create(
body: HttpTypes.AdminCreateInventoryItem,
query?: HttpTypes.SelectParams,
@@ -30,6 +48,25 @@ export class InventoryItem {
)
}
/**
* This method updates an inventory level. It sends a request to the
* [Update Inventory Item](https://docs.medusajs.com/v2/api/admin#inventory-items_postinventoryitemsid)
* API route.
*
* @param id - The inventory item's ID.
* @param body - The data to update.
* @param query - Configure the fields to retrieve in the inventory item.
* @param headers - Headers to pass in the request.
* @returns The inventory item's details.
*
* @example
* sdk.admin.inventoryItem.update("iitem_123", {
* sku: "SHIRT"
* })
* .then(({ inventory_item }) => {
* console.log(inventory_item)
* })
*/
async update(
id: string,
body: HttpTypes.AdminUpdateInventoryItem,
@@ -47,6 +84,53 @@ export class InventoryItem {
)
}
/**
* This method retrieves a paginated list of inventory items. It sends a request to the
* [List Inventory Items](https://docs.medusajs.com/v2/api/admin#inventory-items_getinventoryitems)
* API route.
*
* @param query - Filters and pagination configurations.
* @param headers - Headers to pass in the request.
* @returns The paginated list of inventory items.
*
* @example
* To retrieve the list of inventory items:
*
* ```ts
* sdk.admin.inventoryItem.list()
* .then(({ inventory_items, count, limit, offset }) => {
* console.log(inventory_items)
* })
* ```
*
* To configure the pagination, pass the `limit` and `offset` query parameters.
*
* For example, to retrieve only 10 items and skip 10 items:
*
* ```ts
* sdk.admin.inventoryItem.list({
* limit: 10,
* offset: 10
* })
* .then(({ inventory_items, count, limit, offset }) => {
* console.log(inventory_items)
* })
* ```
*
* Using the `fields` query parameter, you can specify the fields and relations to retrieve
* in each inventory item:
*
* ```ts
* sdk.admin.inventoryItem.list({
* fields: "id,*location_levels"
* })
* .then(({ inventory_items, count, limit, offset }) => {
* console.log(inventory_items)
* })
* ```
*
* Learn more about the `fields` property in the [API reference](https://docs.medusajs.com/v2/api/store#select-fields-and-relations).
*/
async list(
query?: HttpTypes.AdminInventoryItemParams,
headers?: ClientHeaders
@@ -60,6 +144,38 @@ export class InventoryItem {
)
}
/**
* This method retrieves an inventory item by its ID. It sends a request to the
* [Get Inventory Item](https://docs.medusajs.com/v2/api/admin#inventory-items_getinventoryitemsid) API route.
*
* @param id - The inventory item's ID.
* @param query - Configure the fields to retrieve in the inventory item.
* @param headers - Headers to pass in the request
* @returns The inventory item's details.
*
* @example
* To retrieve an inventory item by its ID:
*
* ```ts
* sdk.admin.inventoryItem.retrieve("iitem_123")
* .then(({ inventory_item }) => {
* console.log(inventory_item)
* })
* ```
*
* To specify the fields and relations to retrieve:
*
* ```ts
* sdk.admin.inventoryItem.retrieve("iitem_123", {
* fields: "id,*location_levels"
* })
* .then(({ inventory_item }) => {
* console.log(inventory_item)
* })
* ```
*
* Learn more about the `fields` property in the [API reference](https://docs.medusajs.com/v2/api/store#select-fields-and-relations).
*/
async retrieve(id: string, query?: SelectParams, headers?: ClientHeaders) {
return await this.client.fetch<HttpTypes.AdminInventoryItemResponse>(
`/admin/inventory-items/${id}`,
@@ -70,6 +186,21 @@ export class InventoryItem {
)
}
/**
* This method deletes an inventory item. This sends a request to the
* [Delete Inventory Item](https://docs.medusajs.com/v2/api/admin#inventory-items_deleteinventoryitemsid)
* API route.
*
* @param id - The inventory item's ID.
* @param headers - Headers to pass in the request
* @returns The deletion's details.
*
* @example
* sdk.admin.inventoryItem.delete("iitem_123")
* .then(({ deleted }) => {
* console.log(deleted)
* })
*/
async delete(id: string, headers?: ClientHeaders) {
return await this.client.fetch<HttpTypes.AdminInventoryItemDeleteResponse>(
`/admin/inventory-items/${id}`,
@@ -80,6 +211,54 @@ export class InventoryItem {
)
}
/**
* This method retrieves a paginated list of inventory levels that belong to an inventory item.
* It sends a request to the [List Inventory Items](https://docs.medusajs.com/v2/api/admin#inventory-items_getinventoryitems)
* API route.
*
* @param id - The inventory item's ID.
* @param query - Filters and pagination configurations.
* @param headers - Headers to pass in the request.
* @returns The paginated list of inventory levels.
*
* @example
* To retrieve the list of inventory levels:
*
* ```ts
* sdk.admin.inventoryItem.listLevels("iitem_123")
* .then(({ inventory_levels, count, limit, offset }) => {
* console.log(inventory_levels)
* })
* ```
*
* To configure the pagination, pass the `limit` and `offset` query parameters.
*
* For example, to retrieve only 10 items and skip 10 items:
*
* ```ts
* sdk.admin.inventoryItem.listLevels("iitem_123", {
* limit: 10,
* offset: 10
* })
* .then(({ inventory_levels, count, limit, offset }) => {
* console.log(inventory_levels)
* })
* ```
*
* Using the `fields` query parameter, you can specify the fields and relations to retrieve
* in each inventory level:
*
* ```ts
* sdk.admin.inventoryItem.listLevels("iitem_123", {
* fields: "id,*inventory_item"
* })
* .then(({ inventory_levels, count, limit, offset }) => {
* console.log(inventory_levels)
* })
* ```
*
* Learn more about the `fields` property in the [API reference](https://docs.medusajs.com/v2/api/store#select-fields-and-relations).
*/
async listLevels(
id: string,
query?: HttpTypes.AdminInventoryLevelFilters,
@@ -94,6 +273,33 @@ export class InventoryItem {
)
}
/**
* This method updates the inventory level of the specified inventory item and
* stock location.
*
* This method sends a request to the
* [Update Inventory Level](https://docs.medusajs.com/v2/api/admin#inventory-items_postinventoryitemsidlocationlevelslocation_id)
* API route.
*
* @param id - The inventory item's ID.
* @param locationId - The stock location's ID.
* @param body - The details to update.
* @param query - Configure the fields to retrieve in the inventory item.
* @param headers - Headers to pass in the request
* @returns The inventory item's details.
*
* @example
* sdk.admin.inventoryItem.updateLevel(
* "iitem_123",
* "sloc_123",
* {
* stocked_quantity: 10
* }
* )
* .then(({ inventory_item }) => {
* console.log(inventory_item)
* })
*/
async updateLevel(
id: string,
locationId: string,
@@ -112,8 +318,30 @@ export class InventoryItem {
)
}
/**
* This method deletes an inventory level associated with an inventory item
* and a stock location.
*
* This method sends a request to the
* [Remove Inventory Level](https://docs.medusajs.com/v2/api/admin#inventory-items_deleteinventoryitemsidlocationlevelslocation_id)
* API route.
*
* @param id - The inventory item's ID.
* @param locationId - The stock location's ID.
* @param headers - Headers to pass in the request
* @returns The deletion's details.
*
* @example
* sdk.admin.inventoryItem.deleteLevel(
* "iitem_123",
* "sloc_123",
* )
* .then(({ deleted, parent: inventoryItem }) => {
* console.log(deleted, inventoryItem)
* })
*/
async deleteLevel(id: string, locationId: string, headers?: ClientHeaders) {
return await this.client.fetch<HttpTypes.AdminInventoryItemDeleteResponse>(
return await this.client.fetch<HttpTypes.AdminInventoryLevelDeleteResponse>(
`/admin/inventory-items/${id}/location-levels/${locationId}`,
{
method: "DELETE",
@@ -122,6 +350,29 @@ export class InventoryItem {
)
}
/**
* This method manages the inventory levels of an inventory item. It sends a request to the
* [Manage Inventory Levels](https://docs.medusajs.com/v2/api/admin#inventory-items_postinventoryitemsidlocationlevelsbatch)
* API route.
*
* @param id - The inventory item's ID.
* @param body - The inventory levels to create or delete.
* @param query - Configure the fields to retrieve in the inventory item.
* @param headers - Headers to pass in the request
* @returns The inventory item's details.
*
* @example
* sdk.admin.inventoryItem.batchUpdateLevels("iitem_123", {
* create: [{
* location_id: "sloc_123",
* stocked_quantity: 10
* }],
* delete: ["sloc_123"]
* })
* .then(({ inventory_item }) => {
* console.log(inventory_item)
* })
*/
async batchUpdateLevels(
id: string,
body: HttpTypes.AdminBatchUpdateInventoryLevelLocation,

View File

@@ -1,7 +1,6 @@
import {
FindParams,
HttpTypes,
PaginatedResponse,
SelectParams,
} from "@medusajs/types"
import { Client } from "../client"
@@ -19,13 +18,52 @@ export class Invite {
this.client = client
}
/**
* This method accepts an invite. It requires sending a previous request to
* the {@link Auth.register}.
*
* This method sends a request to the [Accept Invite]
* (https://docs.medusajs.com/v2/api/admin#invites_postinvitesaccept)
* API route.
*
* @param input - The details of the user to create.
* @param query - Configure the fields to retrieve in the user.
* @param headers - Headers to pass in the request
* @returns The user's details.
*
* @example
* const token = await sdk.auth.register("user", "emailpass", {
* email: "user@gmail.com",
* password: "supersecret"
* })
*
* sdk.admin.invite.accept(
* {
* email: "user@gmail.com",
* first_name: "John",
* last_name: "Smith",
* invite_token: "12345..."
* },
* {
* Authorization: `Bearer ${token}`
* }
* )
* .then(({ user }) => {
* console.log(user)
* })
*/
async accept(
input: HttpTypes.AdminAcceptInvite & { invite_token: string },
input: HttpTypes.AdminAcceptInvite & {
/**
* The invite's token.
*/
invite_token: string
},
query?: SelectParams,
headers?: ClientHeaders
) {
const { invite_token, ...rest } = input
return await this.client.fetch<{ user: HttpTypes.AdminUserResponse }>(
return await this.client.fetch<HttpTypes.AdminAcceptInviteResponse>(
`/admin/invites/accept?token=${input.invite_token}`,
{
method: "POST",
@@ -36,12 +74,30 @@ export class Invite {
)
}
/**
* This method creates an invite. It sends a request to the
* [Create Invite](https://docs.medusajs.com/v2/api/admin#invites_postinvites)
* API route.
*
* @param body - The invite's details.
* @param query - Configure the fields to retrieve in the invite.
* @param headers - Headers to pass in the request
* @returns The invite's details.
*
* @example
* sdk.admin.invite.create({
* email: "user@gmail.com",
* })
* .then(({ invite }) => {
* console.log(invite)
* })
*/
async create(
body: HttpTypes.AdminCreateInvite,
query?: SelectParams,
headers?: ClientHeaders
) {
return await this.client.fetch<{ invite: HttpTypes.AdminInviteResponse }>(
return await this.client.fetch<HttpTypes.AdminInviteResponse>(
`/admin/invites`,
{
method: "POST",
@@ -52,8 +108,41 @@ export class Invite {
)
}
/**
* This method retrieves an invite by its ID. It sends a request to the
* [Get Invite](https://docs.medusajs.com/v2/api/admin#invites_getinvitesid)
* API route.
*
* @param id - The invite's ID.
* @param query - Configure the fields to retrieve in the invite.
* @param headers - Headers to pass in the request
* @returns The invite's details.
*
* @example
* To retrieve an invite its ID:
*
* ```ts
* sdk.admin.invite.retrieve("invite_123")
* .then(({ invite }) => {
* console.log(invite)
* })
* ```
*
* To specify the fields and relations to retrieve:
*
* ```ts
* sdk.admin.invite.retrieve("invite_123", {
* fields: "id,email"
* })
* .then(({ invite }) => {
* console.log(invite)
* })
* ```
*
* Learn more about the `fields` property in the [API reference](https://docs.medusajs.com/v2/api/store#select-fields-and-relations).
*/
async retrieve(id: string, query?: SelectParams, headers?: ClientHeaders) {
return await this.client.fetch<{ invite: HttpTypes.AdminInviteResponse }>(
return await this.client.fetch<HttpTypes.AdminInviteResponse>(
`/admin/invites/${id}`,
{
headers,
@@ -62,17 +151,79 @@ export class Invite {
)
}
/**
* This method retrieves a paginated list of invites. It sends a request to the
* [List Invites](https://docs.medusajs.com/v2/api/admin#invites_getinvites)
* API route.
*
* @param queryParams - Filters and pagination configurations.
* @param headers - Headers to pass in the request.
* @returns The paginated list of invites.
*
* @example
* To retrieve the list of invites:
*
* ```ts
* sdk.admin.invite.list()
* .then(({ invites, count, limit, offset }) => {
* console.log(invites)
* })
* ```
*
* To configure the pagination, pass the `limit` and `offset` query parameters.
*
* For example, to retrieve only 10 items and skip 10 items:
*
* ```ts
* sdk.admin.invite.list({
* limit: 10,
* offset: 10
* })
* .then(({ invites, count, limit, offset }) => {
* console.log(invites)
* })
* ```
*
* Using the `fields` query parameter, you can specify the fields and relations to retrieve
* in each invite:
*
* ```ts
* sdk.admin.invite.list({
* fields: "id,email"
* })
* .then(({ invites, count, limit, offset }) => {
* console.log(invites)
* })
* ```
*
* Learn more about the `fields` property in the [API reference](https://docs.medusajs.com/v2/api/store#select-fields-and-relations).
*/
async list(queryParams?: FindParams, headers?: ClientHeaders) {
return await this.client.fetch<
PaginatedResponse<{ invites: HttpTypes.AdminInviteResponse[] }>
HttpTypes.AdminInviteListResponse
>(`/admin/invites`, {
headers,
query: queryParams,
})
}
/**
* This method refreshes the token of an invite. It sends a request to the
* [Refresh Invite Token](https://docs.medusajs.com/v2/api/admin#invites_postinvitesidresend)
* API route.
*
* @param id - The invite's ID.
* @param headers - Headers to pass in the request.
* @returns The invite's details.
*
* @example
* sdk.admin.invite.resend("invite_123")
* .then(({ invite }) => {
* console.log(invite)
* })
*/
async resend(id: string, headers?: ClientHeaders) {
return await this.client.fetch<{ invite: HttpTypes.AdminInviteResponse }>(
return await this.client.fetch<HttpTypes.AdminInviteResponse>(
`/admin/invites/${id}/resend`,
{
method: "POST",
@@ -81,6 +232,21 @@ export class Invite {
)
}
/**
* This method deletes an invite. It sends a request to the
* [Delete Invite](https://docs.medusajs.com/v2/api/admin#invites_deleteinvitesid)
* API route.
*
* @param id - The invite's ID.
* @param headers - Headers to pass in the request.
* @returns The deletion's details.
*
* @example
* sdk.admin.invite.delete("invite_123")
* .then(({ deleted }) => {
* console.log(deleted)
* })
*/
async delete(id: string, headers?: ClientHeaders) {
return await this.client.fetch<HttpTypes.AdminInviteDeleteResponse>(
`/admin/invites/${id}`,