breaking: move shared HTTP utils to the framework (#9402)

Fixes: FRMW-2728, FRMW-2729

After this PR gets merged the following middleware will be exported from the `@medusajs/framework/http` import path.

- applyParamsAsFilters
- clearFiltersByKey
- applyDefaultFilters
- setContext
- getQueryConfig
- httpCompression
- maybeApplyLinkFilter
- refetchEntities
- unlessPath
- validateBody
- validateQuery

Co-authored-by: Adrien de Peretti <25098370+adrien2p@users.noreply.github.com>
This commit is contained in:
Harminder Virk
2024-10-03 09:42:00 +00:00
committed by GitHub
co-authored by Adrien de Peretti
parent 193f93464f
commit 48e00169d2
557 changed files with 2365 additions and 3499 deletions
+61 -64
View File
@@ -1,18 +1,15 @@
import {
IFulfillmentProvider,
FulfillmentOption
} from "@medusajs/types"
import { FulfillmentOption, IFulfillmentProvider } from "@medusajs/types"
/**
* ### constructor
*
* The constructor allows you to access resources from the module's container using the first parameter,
* and the module's options using the second parameter.
*
*
* :::note
*
*
* A module's options are passed when you register it in the Medusa application.
*
*
* :::
*
* If you're creating a client or establishing a connection with a third-party service, do it in the constructor.
@@ -22,32 +19,32 @@ import {
* ```ts
* import { AbstractFulfillmentProviderService } from "@medusajs/framework/utils"
* import { Logger } from "@medusajs/framework/types"
*
*
* type InjectedDependencies = {
* logger: Logger
* }
*
*
* type Options = {
* apiKey: string
* }
*
*
* class MyFulfillmentProviderService extends AbstractFulfillmentProviderService {
* protected logger_: Logger
* protected options_: Options
* // assuming you're initializing a client
* protected client
*
*
* constructor(
* { logger }: InjectedDependencies,
* options: Options
* ) {
* super()
*
*
* this.logger_ = logger
* this.options_ = options
* }
* }
*
*
* export default MyFulfillmentProviderService
* ```
*/
@@ -56,15 +53,15 @@ export class AbstractFulfillmentProviderService
{
/**
* The `identifier` property holds a unique identifier of the fulfillment module provider.
*
*
* You can use the kebab-case name of the provider as its value.
*
*
* For example:
*
*
* ```ts
* class MyFulfillmentProviderService extends AbstractFulfillmentProviderService {
* static identifier = "my-fulfillment"
*
*
* // ...
* }
*/
@@ -84,7 +81,7 @@ export class AbstractFulfillmentProviderService
/**
* @ignore
*
*
* @privateRemarks
* This method is ignored as {@link validateOption} is the one used by the Fulfillment Module.
*/
@@ -99,13 +96,13 @@ export class AbstractFulfillmentProviderService
/**
* This method retrieves the shipping options this fulfillment provider supports.
*
*
* @returns The list of fulfillment options.
*
*
* @example
* // other imports...
* import { FulfillmentOption } from "@medusajs/framework/types"
*
*
* class MyFulfillmentProviderService extends AbstractFulfillmentProviderService {
* // ...
* async getFulfillmentOptions(): Promise<FulfillmentOption[]> {
@@ -128,28 +125,28 @@ export class AbstractFulfillmentProviderService
/**
* This method validates the `data` property of a shipping method and returns it. The returned data
* is stored in the shipping method's `data` property.
*
*
* Your fulfillment provider can use the `data` property to store additional information useful for
* handling the fulfillment later. For example, you may store an ID from the third-party fulfillment
* system.
*
*
* @param optionData - The `data` property of the shipping option.
* @param data - The `data` property of the shipping method.
* @param context - Context details, such as context of the cart or customer.
* @returns the data to store in the `data` property of the shipping method.
*
*
* @example
* class MyFulfillmentProviderService extends AbstractFulfillmentProviderService {
* // ...
* async validateFulfillmentData(
* optionData: any,
* data: any,
* optionData: any,
* data: any,
* context: any
* ): Promise<any> {
* // assuming your client retrieves an ID from the
* // third-party service
* const externalId = await this.client.getId()
*
*
* return {
* ...data,
* externalId
@@ -163,13 +160,13 @@ export class AbstractFulfillmentProviderService
/**
* This method validates the `data` property of a shipping option when it's created.
*
*
* The `data` property can hold useful information that's later added to the `data` attribute
* of shipping methods created from this option.
*
*
* @param data - The data to validate.
* @return Whether the data is valid.
*
*
* @example
* class MyFulfillmentProviderService extends AbstractFulfillmentProviderService {
* // ...
@@ -183,12 +180,12 @@ export class AbstractFulfillmentProviderService
}
/**
* This method indicates whether a shippin option's price is calculated during
* This method indicates whether a shippin option's price is calculated during
* checkout or is fixed.
*
*
* @param data - The `data` property of the shipping option.
* @returns Whether the price is calculated for the shipping option.
*
*
* @example
* class MyFulfillmentProviderService extends AbstractFulfillmentProviderService {
* // ...
@@ -203,15 +200,15 @@ export class AbstractFulfillmentProviderService
/**
* This method calculates the price of a shipping option, or a shipping method when it's created.
*
*
* The Medusa application uses the {@link canCalculate} method first to check whether the shipping option's price is calculated.
* If it returns `true`, Medusa uses this method to retrieve the calculated price.
*
*
* @param optionData - The `data` property of a shipping option.
* @param data - If the price is calculated for a shipping option, it's the `data` of the shipping option. Otherwise, it's the `data of the shipping method.
* @param cart - The cart details.
* @returns The calculated price
*
*
* @example
* class MyFulfillmentProviderService extends AbstractFulfillmentProviderService {
* // ...
@@ -219,7 +216,7 @@ export class AbstractFulfillmentProviderService
* // assuming the client can calculate the price using
* // the third-party service
* const price = await this.client.calculate(data)
*
*
* return price
* }
* }
@@ -229,27 +226,27 @@ export class AbstractFulfillmentProviderService
}
/**
* This method is used when a fulfillment is created. If the method returns in the object a
* This method is used when a fulfillment is created. If the method returns in the object a
* `data` property, it's stored in the fulfillment's `data` property.
*
*
* The `data` property is useful when handling the fulfillment later,
* as you can access information useful for your integration.
*
*
* You can also use this method to perform an action with the third-party fulfillment service.
*
*
* @param data - The `data` property of the shipping method this fulfillment is created for.
* @param items - The items in the fulfillment.
* @param order - The order this fulfillment is created for.
* @param fulfillment - The fulfillment's details.
* @returns The data to store in the fulfillment's `data` property.
*
*
* @example
* class MyFulfillmentProviderService extends AbstractFulfillmentProviderService {
* // ...
* async createFulfillment(
* data: any,
* items: any,
* order: any,
* data: any,
* items: any,
* order: any,
* fulfillment: any
* ): Promise<any> {
* // assuming the client creates a fulfillment
@@ -258,7 +255,7 @@ export class AbstractFulfillmentProviderService
* fulfillment,
* items
* )
*
*
* return {
* data: {
* ...data,
@@ -275,9 +272,9 @@ export class AbstractFulfillmentProviderService
/**
* This method is used when a fulfillment is canceled. Use it to perform operations
* with the third-party fulfillment service.
*
*
* @param fulfillment - The fulfillment's details.
*
*
* @example
* class MyFulfillmentProviderService extends AbstractFulfillmentProviderService {
* // ...
@@ -294,10 +291,10 @@ export class AbstractFulfillmentProviderService
/**
* This method retrieves the documents of a fulfillment.
*
*
* @param data - The `data` property of the fulfillment.
* @returns The fulfillment's documents.
*
*
* @example
* class MyFulfillmentProviderService extends AbstractFulfillmentProviderService {
* // ...
@@ -313,17 +310,17 @@ export class AbstractFulfillmentProviderService
}
/**
* This method is used when a fulfillment is created for a return. If the method returns in the object a
* This method is used when a fulfillment is created for a return. If the method returns in the object a
* `data` property, it's stored in the fulfillment's `data` property.
*
*
* The `data` property is useful when handling the fulfillment later,
* as you can access information useful for your integration.
*
*
* Use this method to perform actions necessary in the third-party fulfillment service.
*
*
* @param fulfillment - The fulfillment's details.
* @returns The data to store in the fulfillment's `data` property.
*
*
* @example
* class MyFulfillmentProviderService extends AbstractFulfillmentProviderService {
* // ...
@@ -333,7 +330,7 @@ export class AbstractFulfillmentProviderService
* const externalData = await this.client.createReturn(
* fulfillment
* )
*
*
* return {
* data: {
* ...fulfillment.data,
@@ -349,10 +346,10 @@ export class AbstractFulfillmentProviderService
/**
* This method retrieves documents for a return's fulfillment.
*
*
* @param data - The `data` property of the fulfillment.
* @returns The fulfillment's documents.
*
*
* @example
* class MyFulfillmentProviderService extends AbstractFulfillmentProviderService {
* // ...
@@ -369,10 +366,10 @@ export class AbstractFulfillmentProviderService
/**
* This method retrieves the documents for a shipment.
*
*
* @param data - The `data` property of the shipmnet.
* @returns The shipment's documents.
*
*
* @example
* class MyFulfillmentProviderService extends AbstractFulfillmentProviderService {
* // ...
@@ -382,7 +379,7 @@ export class AbstractFulfillmentProviderService
* return await this.client.documents(data)
* }
* }
*
*
*/
async getShipmentDocuments(data) {
return []
@@ -390,16 +387,16 @@ export class AbstractFulfillmentProviderService
/**
* This method retrieves the documents of a fulfillment of a certain type.
*
*
* @param fulfillmentData - The `data` property of the fulfillment.
* @param documentType - The document's type. For example, `invoice`.
* @returns The fulfillment's documents.
*
*
* @example
* class MyFulfillmentProviderService extends AbstractFulfillmentProviderService {
* // ...
* async retrieveDocuments(
* fulfillmentData: any,
* fulfillmentData: any,
* documentType: any
* ): Promise<void> {
* // assuming the client retrieves documents