docs: add missing methods in guides and references (#12495)

* initial

* remove unused references
This commit is contained in:
Shahed Nasser authored and GitHub committed 2025-05-15 14:22:23 +03:00
1 parent b2984f48f5
commit b312a7e077
47 files changed
+48520 -54324

No files matched your search

@@ -113,31 +113,172 @@ class MyFileProviderService extends AbstractFileProviderService {
}
```
### validateOptions
### delete
This method validates the options of the provider set in `medusa-config.ts`.
Implementing this method is optional. It's useful if your provider requires custom validation.
If the options aren't valid, throw an error.
This method deletes the file from storage. It's used when an admin user deletes a product image,
or other custom file deletions.
#### Example
```ts
class MyFileProviderService extends AbstractFileProviderService {
static validateOptions(options: Record<any, any>) {
if (!options.apiKey) {
throw new MedusaError(
MedusaError.Types.INVALID_DATA,
"API key is required in the provider's options."
)
}
// ...
async delete(file: ProviderDeleteFileDTO): Promise<void> {
// TODO logic to remove the file from storage
// Use the `file.fileKey` to delete the file, which is the identifier of the file
// in the provider's storage.
// for example:
this.client.delete(file.fileKey)
}
}
```
#### Parameters
<TypeList types={[{"name":"options","type":"`Record<any, any>`","description":"The provider's options.","optional":false,"defaultValue":"","expandable":false,"children":[]}]} expandUrl="https://docs.medusajs.com/learn/fundamentals/data-models/manage-relationships#retrieve-records-of-relation" sectionTitle="validateOptions"/>
<TypeList types={[{"name":"file","type":"[ProviderDeleteFileDTO](../../../types/FileTypes/interfaces/types.FileTypes.ProviderDeleteFileDTO/page.mdx)","description":"The details of the file to delete.","optional":false,"defaultValue":"","expandable":false,"children":[{"name":"fileKey","type":"`string`","description":"The file's key. When uploading a file, the\nreturned key is used here.","optional":false,"defaultValue":"","expandable":false,"children":[]}]}]} expandUrl="https://docs.medusajs.com/learn/fundamentals/data-models/manage-relationships#retrieve-records-of-relation" sectionTitle="delete"/>
#### Returns
<TypeList types={[{"name":"Promise","type":"Promise&#60;void&#62;","optional":false,"defaultValue":"","description":"Resolves when the file is deleted.","expandable":false,"children":[]}]} expandUrl="https://docs.medusajs.com/learn/fundamentals/data-models/manage-relationships#retrieve-records-of-relation" sectionTitle="delete"/>
### getAsBuffer
This method retrieves an uploaded file as a buffer. This is useful when you want to
process the entire file in memory or send it as a response.
:::note
This is only available after Medusa `v2.8.0`.
:::
#### Example
```ts
class MyFileProviderService extends AbstractFileProviderService {
// ...
async getAsBuffer(file: ProviderDeleteFileDTO): Promise<Buffer> {
// TODO logic to get the file as a buffer
// Use the `file.fileKey` to get the file, which is the identifier of the file
// in the provider's storage.
// for example:
this.client.getAsBuffer(file.fileKey)
}
}
```
#### Parameters
<TypeList types={[{"name":"fileData","type":"[ProviderGetFileDTO](../../../types/FileTypes/interfaces/types.FileTypes.ProviderGetFileDTO/page.mdx)","description":"The details of the file to get its buffer.","optional":false,"defaultValue":"","expandable":false,"children":[{"name":"fileKey","type":"`string`","description":"The file's key allowing you to later\nidentify the file in the third-party\nsystem. For example, the S3 Module Provider\nreturns the file's key in S3, whereas the\nLocal File Module Provider returns the file's\npath.","optional":false,"defaultValue":"","expandable":false,"children":[]}]}]} expandUrl="https://docs.medusajs.com/learn/fundamentals/data-models/manage-relationships#retrieve-records-of-relation" sectionTitle="getAsBuffer"/>
#### Returns
<TypeList types={[{"name":"Promise","type":"Promise&#60;Buffer&#62;","optional":false,"defaultValue":"","description":"The file's buffer.","expandable":false,"children":[]}]} expandUrl="https://docs.medusajs.com/learn/fundamentals/data-models/manage-relationships#retrieve-records-of-relation" sectionTitle="getAsBuffer"/>
### getDownloadStream
This method retrieves an uploaded file as a stream. This is useful when streaming
a file to clients or you want to process the file in chunks.
:::note
This is only available after Medusa `v2.8.0`.
:::
#### Example
```ts
class MyFileProviderService extends AbstractFileProviderService {
// ...
async getAsStream(file: ProviderDeleteFileDTO): Promise<Readable> {
// TODO logic to get the file as a stream
// Use the `file.fileKey` to get the file, which is the identifier of the file
// in the provider's storage.
// for example:
this.client.getAsStream(file.fileKey)
}
}
```
#### Parameters
<TypeList types={[{"name":"fileData","type":"[ProviderGetFileDTO](../../../types/FileTypes/interfaces/types.FileTypes.ProviderGetFileDTO/page.mdx)","description":"The details of the file to get its stream.","optional":false,"defaultValue":"","expandable":false,"children":[{"name":"fileKey","type":"`string`","description":"The file's key allowing you to later\nidentify the file in the third-party\nsystem. For example, the S3 Module Provider\nreturns the file's key in S3, whereas the\nLocal File Module Provider returns the file's\npath.","optional":false,"defaultValue":"","expandable":false,"children":[]}]}]} expandUrl="https://docs.medusajs.com/learn/fundamentals/data-models/manage-relationships#retrieve-records-of-relation" sectionTitle="getDownloadStream"/>
#### Returns
<TypeList types={[{"name":"Promise","type":"Promise&#60;Readable&#62;","optional":false,"defaultValue":"","description":"The file's stream.","expandable":false,"children":[]}]} expandUrl="https://docs.medusajs.com/learn/fundamentals/data-models/manage-relationships#retrieve-records-of-relation" sectionTitle="getDownloadStream"/>
### getPresignedDownloadUrl
This method is used to retrieve a download URL of the file. For some providers,
such as S3, a presigned URL indicates a temporary URL to get access to a file.
If your provider doesn’t perform or offer a similar functionality, you can
return the URL to download the file.
#### Example
```ts
class MyFileProviderService extends AbstractFileProviderService {
// ...
async getPresignedDownloadUrl(
fileData: ProviderGetFileDTO
): Promise<string> {
// TODO logic to get the presigned URL
// Use the `file.fileKey` to delete the file, which is the identifier of the file
// in the provider's storage.
// for example:
return this.client.getPresignedUrl(fileData.fileKey)
}
}
```
#### Parameters
<TypeList types={[{"name":"fileData","type":"[ProviderGetFileDTO](../../../types/FileTypes/interfaces/types.FileTypes.ProviderGetFileDTO/page.mdx)","description":"The details of the file to get its\npresigned URL.","optional":false,"defaultValue":"","expandable":false,"children":[{"name":"fileKey","type":"`string`","description":"The file's key allowing you to later\nidentify the file in the third-party\nsystem. For example, the S3 Module Provider\nreturns the file's key in S3, whereas the\nLocal File Module Provider returns the file's\npath.","optional":false,"defaultValue":"","expandable":false,"children":[]}]}]} expandUrl="https://docs.medusajs.com/learn/fundamentals/data-models/manage-relationships#retrieve-records-of-relation" sectionTitle="getPresignedDownloadUrl"/>
#### Returns
<TypeList types={[{"name":"Promise","type":"Promise&#60;string&#62;","optional":false,"defaultValue":"","description":"The file's presigned URL.","expandable":false,"children":[{"name":"string","type":"`string`","optional":false,"defaultValue":"","description":"","expandable":false,"children":[]}]}]} expandUrl="https://docs.medusajs.com/learn/fundamentals/data-models/manage-relationships#retrieve-records-of-relation" sectionTitle="getPresignedDownloadUrl"/>
### getPresignedUploadUrl
<BadgesList badges={[
{
"variant": "neutral",
"children": "optional"
}
]} className="mb-1" />
This method is used to get a presigned upload URL for a file. For some providers,
such as S3, a presigned URL indicates a temporary URL to get upload a file.
If your provider doesn’t perform or offer a similar functionality, you don't have to
implement this method. Instead, an error is thrown when the method is called.
#### Example
```ts
class MyFileProviderService extends AbstractFileProviderService {
// ...
async getPresignedUploadUrl(
fileData: ProviderGetPresignedUploadUrlDTO
): Promise<ProviderFileResultDTO> {
// TODO logic to get the presigned upload URL
// for example:
return this.client.getPresignedUploadUrl(fileData.filename, fileData.mimeType)
}
}
```
#### Parameters
<TypeList types={[{"name":"fileData","type":"[ProviderGetPresignedUploadUrlDTO](../../../types/FileTypes/interfaces/types.FileTypes.ProviderGetPresignedUploadUrlDTO/page.mdx)","description":"The details of the file to get a presigned upload URL for.","optional":false,"defaultValue":"","expandable":false,"children":[{"name":"filename","type":"`string`","description":"The filename of the file to get a presigned upload URL for.","optional":false,"defaultValue":"","expandable":false,"children":[]},{"name":"mimeType","type":"`string`","description":"The mimetype of the file to get a presigned upload URL for.","optional":true,"defaultValue":"","expandable":false,"children":[]},{"name":"access","type":"[FileAccessPermission](../../../types/FileTypes/types/types.FileTypes.FileAccessPermission/page.mdx)","description":"The access level of the file to get a presigned upload URL for.","optional":true,"defaultValue":"","expandable":false,"children":[]},{"name":"expiresIn","type":"`number`","description":"The validity of the presigned upload URL in seconds.","optional":true,"defaultValue":"","expandable":false,"children":[]}]}]} expandUrl="https://docs.medusajs.com/learn/fundamentals/data-models/manage-relationships#retrieve-records-of-relation" sectionTitle="getPresignedUploadUrl"/>
#### Returns
<TypeList types={[{"name":"Promise","type":"Promise&#60;[ProviderFileResultDTO](../../../types/FileTypes/interfaces/types.FileTypes.ProviderFileResultDTO/page.mdx)&#62;","optional":false,"defaultValue":"","description":"The presigned URL and file key to upload the file to","expandable":false,"children":[{"name":"url","type":"`string`","description":"The file's URL that users or systems\ncan use to access the file.","optional":false,"defaultValue":"","expandable":false,"children":[]},{"name":"key","type":"`string`","description":"The file's key allowing you to later\nidentify the file in the third-party\nsystem. For example, the S3 Module Provider\nreturns the file's key in S3, whereas the\nLocal File Module Provider returns the file's\npath.","optional":false,"defaultValue":"","expandable":false,"children":[]}]}]} expandUrl="https://docs.medusajs.com/learn/fundamentals/data-models/manage-relationships#retrieve-records-of-relation" sectionTitle="getPresignedUploadUrl"/>
### upload
@@ -176,134 +317,31 @@ class MyFileProviderService extends AbstractFileProviderService {
<TypeList types={[{"name":"Promise","type":"Promise&#60;[ProviderFileResultDTO](../../../types/FileTypes/interfaces/types.FileTypes.ProviderFileResultDTO/page.mdx)&#62;","optional":false,"defaultValue":"","description":"The uploaded file's details.","expandable":false,"children":[{"name":"url","type":"`string`","description":"The file's URL that users or systems\ncan use to access the file.","optional":false,"defaultValue":"","expandable":false,"children":[]},{"name":"key","type":"`string`","description":"The file's key allowing you to later\nidentify the file in the third-party\nsystem. For example, the S3 Module Provider\nreturns the file's key in S3, whereas the\nLocal File Module Provider returns the file's\npath.","optional":false,"defaultValue":"","expandable":false,"children":[]}]}]} expandUrl="https://docs.medusajs.com/learn/fundamentals/data-models/manage-relationships#retrieve-records-of-relation" sectionTitle="upload"/>
### delete
### validateOptions
This method deletes the file from storage. It's used when an admin user deletes a product image,
or other custom file deletions.
This method validates the options of the provider set in `medusa-config.ts`.
Implementing this method is optional. It's useful if your provider requires custom validation.
If the options aren't valid, throw an error.
#### Example
```ts
class MyFileProviderService extends AbstractFileProviderService {
// ...
async delete(file: ProviderDeleteFileDTO): Promise<void> {
// TODO logic to remove the file from storage
// Use the `file.fileKey` to delete the file, which is the identifier of the file
// in the provider's storage.
// for example:
this.client.delete(file.fileKey)
static validateOptions(options: Record<any, any>) {
if (!options.apiKey) {
throw new MedusaError(
MedusaError.Types.INVALID_DATA,
"API key is required in the provider's options."
)
}
}
}
```
#### Parameters
<TypeList types={[{"name":"file","type":"[ProviderDeleteFileDTO](../../../types/FileTypes/interfaces/types.FileTypes.ProviderDeleteFileDTO/page.mdx)","description":"The details of the file to delete.","optional":false,"defaultValue":"","expandable":false,"children":[{"name":"fileKey","type":"`string`","description":"The file's key. When uploading a file, the\nreturned key is used here.","optional":false,"defaultValue":"","expandable":false,"children":[]}]}]} expandUrl="https://docs.medusajs.com/learn/fundamentals/data-models/manage-relationships#retrieve-records-of-relation" sectionTitle="delete"/>
#### Returns
<TypeList types={[{"name":"Promise","type":"Promise&#60;void&#62;","optional":false,"defaultValue":"","description":"Resolves when the file is deleted.","expandable":false,"children":[]}]} expandUrl="https://docs.medusajs.com/learn/fundamentals/data-models/manage-relationships#retrieve-records-of-relation" sectionTitle="delete"/>
### getPresignedDownloadUrl
This method is used to retrieve a download URL of the file. For some providers,
such as S3, a presigned URL indicates a temporary URL to get access to a file.
If your provider doesn’t perform or offer a similar functionality, you can
return the URL to download the file.
#### Example
```ts
class MyFileProviderService extends AbstractFileProviderService {
// ...
async getPresignedDownloadUrl(
fileData: ProviderGetFileDTO
): Promise<string> {
// TODO logic to get the presigned URL
// Use the `file.fileKey` to delete the file, which is the identifier of the file
// in the provider's storage.
// for example:
return this.client.getPresignedUrl(fileData.fileKey)
}
}
```
#### Parameters
<TypeList types={[{"name":"fileData","type":"[ProviderGetFileDTO](../../../types/FileTypes/interfaces/types.FileTypes.ProviderGetFileDTO/page.mdx)","description":"The details of the file to get its\npresigned URL.","optional":false,"defaultValue":"","expandable":false,"children":[{"name":"fileKey","type":"`string`","description":"The file's key allowing you to later\nidentify the file in the third-party\nsystem. For example, the S3 Module Provider\nreturns the file's key in S3, whereas the\nLocal File Module Provider returns the file's\npath.","optional":false,"defaultValue":"","expandable":false,"children":[]}]}]} expandUrl="https://docs.medusajs.com/learn/fundamentals/data-models/manage-relationships#retrieve-records-of-relation" sectionTitle="getPresignedDownloadUrl"/>
#### Returns
<TypeList types={[{"name":"Promise","type":"Promise&#60;string&#62;","optional":false,"defaultValue":"","description":"The file's presigned URL.","expandable":false,"children":[{"name":"string","type":"`string`","optional":false,"defaultValue":"","description":"","expandable":false,"children":[]}]}]} expandUrl="https://docs.medusajs.com/learn/fundamentals/data-models/manage-relationships#retrieve-records-of-relation" sectionTitle="getPresignedDownloadUrl"/>
### getDownloadStream
This method retrieves an uploaded file as a stream. This is useful when streaming
a file to clients or you want to process the file in chunks.
:::note
This is only available after Medusa `v2.8.0`.
:::
#### Example
```ts
class MyFileProviderService extends AbstractFileProviderService {
// ...
async getAsStream(file: ProviderDeleteFileDTO): Promise<Readable> {
// TODO logic to get the file as a stream
// Use the `file.fileKey` to get the file, which is the identifier of the file
// in the provider's storage.
// for example:
this.client.getAsStream(file.fileKey)
}
}
```
#### Parameters
<TypeList types={[{"name":"fileData","type":"[ProviderGetFileDTO](../../../types/FileTypes/interfaces/types.FileTypes.ProviderGetFileDTO/page.mdx)","description":"The details of the file to get its stream.","optional":false,"defaultValue":"","expandable":false,"children":[{"name":"fileKey","type":"`string`","description":"The file's key allowing you to later\nidentify the file in the third-party\nsystem. For example, the S3 Module Provider\nreturns the file's key in S3, whereas the\nLocal File Module Provider returns the file's\npath.","optional":false,"defaultValue":"","expandable":false,"children":[]}]}]} expandUrl="https://docs.medusajs.com/learn/fundamentals/data-models/manage-relationships#retrieve-records-of-relation" sectionTitle="getDownloadStream"/>
#### Returns
<TypeList types={[{"name":"Promise","type":"Promise&#60;Readable&#62;","optional":false,"defaultValue":"","description":"The file's stream.","expandable":false,"children":[]}]} expandUrl="https://docs.medusajs.com/learn/fundamentals/data-models/manage-relationships#retrieve-records-of-relation" sectionTitle="getDownloadStream"/>
### getAsBuffer
This method retrieves an uploaded file as a buffer. This is useful when you want to
process the entire file in memory or send it as a response.
:::note
This is only available after Medusa `v2.8.0`.
:::
#### Example
```ts
class MyFileProviderService extends AbstractFileProviderService {
// ...
async getAsBuffer(file: ProviderDeleteFileDTO): Promise<Buffer> {
// TODO logic to get the file as a buffer
// Use the `file.fileKey` to get the file, which is the identifier of the file
// in the provider's storage.
// for example:
this.client.getAsBuffer(file.fileKey)
}
}
```
#### Parameters
<TypeList types={[{"name":"fileData","type":"[ProviderGetFileDTO](../../../types/FileTypes/interfaces/types.FileTypes.ProviderGetFileDTO/page.mdx)","description":"The details of the file to get its buffer.","optional":false,"defaultValue":"","expandable":false,"children":[{"name":"fileKey","type":"`string`","description":"The file's key allowing you to later\nidentify the file in the third-party\nsystem. For example, the S3 Module Provider\nreturns the file's key in S3, whereas the\nLocal File Module Provider returns the file's\npath.","optional":false,"defaultValue":"","expandable":false,"children":[]}]}]} expandUrl="https://docs.medusajs.com/learn/fundamentals/data-models/manage-relationships#retrieve-records-of-relation" sectionTitle="getAsBuffer"/>
#### Returns
<TypeList types={[{"name":"Promise","type":"Promise&#60;Buffer&#62;","optional":false,"defaultValue":"","description":"The file's buffer.","expandable":false,"children":[]}]} expandUrl="https://docs.medusajs.com/learn/fundamentals/data-models/manage-relationships#retrieve-records-of-relation" sectionTitle="getAsBuffer"/>
<TypeList types={[{"name":"options","type":"`Record<any, any>`","description":"The provider's options.","optional":false,"defaultValue":"","expandable":false,"children":[]}]} expandUrl="https://docs.medusajs.com/learn/fundamentals/data-models/manage-relationships#retrieve-records-of-relation" sectionTitle="validateOptions"/>
---