Skip to content

Commit

Permalink
chore(js-sdk,types): add tsdocs for admin JS SDK methods [3/n] (#9712)
Browse files Browse the repository at this point in the history
  • Loading branch information
shahednasser authored Oct 22, 2024
1 parent 1c1ba88 commit 14efb2a
Show file tree
Hide file tree
Showing 22 changed files with 1,327 additions and 15 deletions.
122 changes: 122 additions & 0 deletions packages/core/js-sdk/src/admin/fulfillment-set.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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}`,
Expand All @@ -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,
Expand All @@ -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,
Expand All @@ -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,
Expand All @@ -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,
Expand Down
75 changes: 75 additions & 0 deletions packages/core/js-sdk/src/admin/fulfillment.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand All @@ -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,
Expand All @@ -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,
Expand Down
Loading

0 comments on commit 14efb2a

Please sign in to comment.