chore(docs): Updated API Reference (v2) (#9666)

Automated changes by [create-pull-request](https://github.com/peter-evans/create-pull-request) GitHub action

Co-authored-by: Oli Juhl <59018053+olivermrbl@users.noreply.github.com>
Co-authored-by: Shahed Nasser <27354907+shahednasser@users.noreply.github.com>
This commit is contained in:
authored and GitHub committed 2024-10-18 17:14:26 +00:00
1 parent 2ea766daf5
commit 8209d936a0
595 files changed
+33468 -13327

No files matched your search

@@ -37,13 +37,6 @@ and the module's options using the second parameter.
If you're creating a client or establishing a connection with a third-party service, do it in the constructor.
In the constructor, you must pass to the parent constructor two parameters:
1. The first one is an empty object.
2. The second is an object having two properties:
- `provider`: The ID of the provider. For example, `emailpass`.
- `displayName`: The label or displayable name of the provider. For example, `Email and Password Authentication`.
#### Example
```ts
@@ -59,6 +52,7 @@ type Options = {
}
class MyAuthProviderService extends AbstractAuthModuleProvider {
static identifier = "my-auth"
protected logger_: Logger
protected options_: Options
// assuming you're initializing a client
@@ -68,13 +62,7 @@ class MyAuthProviderService extends AbstractAuthModuleProvider {
{ logger }: InjectedDependencies,
options: Options
) {
super(
{},
{
provider: "my-auth",
displayName: "My Custom Authentication"
}
)
super(...arguments)
this.logger_ = logger
this.options_ = options
@@ -89,17 +77,38 @@ class MyAuthProviderService extends AbstractAuthModuleProvider {
export default MyAuthProviderService
```
### constructor
### validateOptions
Override this static method in order for the loader to validate the options provided to the module provider.
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 MyAuthProviderService extends AbstractAuthModuleProvider {
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":"options","type":"`Record<any, any>`","description":"","optional":false,"defaultValue":"","expandable":false,"children":[]}]} expandUrl="https://docs.medusajs.com/v2/advanced-development/data-models/manage-relationships#retrieve-records-of-relation" sectionTitle="validateOptions"/>
<TypeList types={[{"name":"options","type":"`Record<any, any>`","description":"The provider's options.","optional":false,"defaultValue":"","expandable":false,"children":[]}]} expandUrl="https://docs.medusajs.com/v2/advanced-development/data-models/manage-relationships#retrieve-records-of-relation" sectionTitle="validateOptions"/>
#### Returns
<TypeList types={[{"name":"void","type":"`void`","optional":false,"defaultValue":"","description":"Override this static method in order for the loader to validate the options provided to the module provider.","expandable":false,"children":[]}]} expandUrl="https://docs.medusajs.com/v2/advanced-development/data-models/manage-relationships#retrieve-records-of-relation" sectionTitle="validateOptions"/>
<TypeList types={[{"name":"void","type":"`void`","optional":false,"defaultValue":"","description":"This method validates the options of the provider set in `medusa-config.ts`.\nImplementing this method is optional. It's useful if your provider requires custom validation.\n\nIf the options aren't valid, throw an error.","expandable":false,"children":[]}]} expandUrl="https://docs.medusajs.com/v2/advanced-development/data-models/manage-relationships#retrieve-records-of-relation" sectionTitle="validateOptions"/>
### authenticate
@@ -413,10 +422,14 @@ Create the file `src/modules/my-auth/index.ts` with the following content:
```ts title="src/modules/my-auth/index.ts"
import MyAuthProviderService from "./service"
import {
ModuleProvider,
Modules
} from "@medusajs/framework/utils"
export default {
export default ModuleProvider(Modules.AUTH, {
services: [MyAuthProviderService],
}
})
```
This exports the module's definition, indicating that the `MyAuthProviderService` is the module's service.
@@ -440,7 +453,7 @@ module.exports = defineConfig({
options: {
providers: [
{
resolve: "./modules/my-auth",
resolve: "./src/modules/my-auth",
id: "my-auth",
options: {
// provider options...
@@ -54,6 +54,7 @@ type Options = {
class MyFileProviderService extends AbstractFileProviderService {
protected logger_: Logger
protected options_: Options
static identifier = "my-file"
// assuming you're initializing a client
protected client
@@ -78,15 +79,33 @@ export default MyFileProviderService
### validateOptions
Override this static method in order for the loader to validate the options provided to the module provider.
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 {
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":"options","type":"`Record<any, any>`","description":"","optional":false,"defaultValue":"","expandable":false,"children":[]}]} expandUrl="https://docs.medusajs.com/v2/advanced-development/data-models/manage-relationships#retrieve-records-of-relation" sectionTitle="validateOptions"/>
<TypeList types={[{"name":"options","type":"`Record<any, any>`","description":"The provider's options.","optional":false,"defaultValue":"","expandable":false,"children":[]}]} expandUrl="https://docs.medusajs.com/v2/advanced-development/data-models/manage-relationships#retrieve-records-of-relation" sectionTitle="validateOptions"/>
#### Returns
<TypeList types={[{"name":"void","type":"`void`","optional":false,"defaultValue":"","description":"Override this static method in order for the loader to validate the options provided to the module provider.","expandable":false,"children":[]}]} expandUrl="https://docs.medusajs.com/v2/advanced-development/data-models/manage-relationships#retrieve-records-of-relation" sectionTitle="validateOptions"/>
<TypeList types={[{"name":"void","type":"`void`","optional":false,"defaultValue":"","description":"This method validates the options of the provider set in `medusa-config.ts`.\nImplementing this method is optional. It's useful if your provider requires custom validation.\n\nIf the options aren't valid, throw an error.","expandable":false,"children":[]}]} expandUrl="https://docs.medusajs.com/v2/advanced-development/data-models/manage-relationships#retrieve-records-of-relation" sectionTitle="validateOptions"/>
### upload
@@ -185,10 +204,14 @@ Create the file `src/modules/my-file/index.ts` with the following content:
```ts title="src/modules/my-file/index.ts"
import MyFileProviderService from "./service"
import {
ModuleProvider,
Modules
} from "@medusajs/framework/utils"
export default {
export default ModuleProvider(Modules.FILE, {
services: [MyFileProviderService],
}
})
```
This exports the module's definition, indicating that the `MyFileProviderService` is the module's service.
@@ -214,11 +237,11 @@ module.exports = defineConfig({
// ...
modules: [
{
resolve: "@medusajs/medusa/file",
resolve: "@medusajs/framework/file",
options: {
providers: [
{
resolve: "./modules/my-file",
resolve: "./src/modules/my-file",
id: "my-file",
options: {
// provider options...
@@ -454,10 +454,14 @@ Create the file `src/modules/my-fulfillment/index.ts` with the following content
```ts title="src/modules/my-fulfillment/index.ts"
import MyFulfillmentProviderService from "./service"
import {
ModuleProvider,
Modules
} from "@medusajs/framework/utils"
export default {
export default ModuleProvider(Modules.FULFILLMENT, {
services: [MyFulfillmentProviderService],
}
})
```
This exports the module's definition, indicating that the `MyFulfillmentProviderService` is the module's service.
@@ -481,7 +485,7 @@ module.exports = defineConfig({
options: {
providers: [
{
resolve: "./modules/my-fulfillment",
resolve: "./src/modules/my-fulfillment",
id: "my-fulfillment",
options: {
// provider options...
@@ -8,9 +8,9 @@ import { TypeList } from "docs-ui"
In this document, you’ll learn how to create a file service in the Medusa application and the methods you must implement in it.
The configurations for your Medusa application are in `medusa-config.js` located in the root of your Medusa project. The configurations include configurations for database, modules, and more.
The configurations for your Medusa application are in `medusa-config.ts` located in the root of your Medusa project. The configurations include configurations for database, modules, and more.
`medusa-config.js` exports the value returned by the `defineConfig` utility function imported from `@medusajs/utils`.
`medusa-config.ts` exports the value returned by the `defineConfig` utility function imported from `@medusajs/framework/utils`.
`defineConfig` accepts as a parameter an object with the following properties:
@@ -21,7 +21,7 @@ The configurations for your Medusa application are in `medusa-config.js` located
For example:
```js title="medusa-config.js"
```ts title="medusa-config.ts"
module.exports = defineConfig({
projectConfig: {
// ...
@@ -42,7 +42,7 @@ module.exports = defineConfig({
## Environment Variables
It's highly recommended to store the values of configurations in environment variables, then reference them within `medusa-config.js`.
It's highly recommended to store the values of configurations in environment variables, then reference them within `medusa-config.ts`.
During development, you can set your environment variables in the `.env` file at the root of your Medusa application project. In production,
setting the environment variables depends on the hosting provider.
@@ -62,7 +62,7 @@ Make sure to create the PostgreSQL database before using it. You can check how t
#### Example
```js title="medusa-config.js"
```ts title="medusa-config.ts"
module.exports = defineConfig({
projectConfig: {
databaseName: process.env.DATABASE_NAME ||
@@ -99,9 +99,9 @@ For example, set the following database URL in your environment variables:
DATABASE_URL=postgres://postgres@localhost/medusa-store
```
Then, use the value in `medusa-config.js`:
Then, use the value in `medusa-config.ts`:
```js title="medusa-config.js"
```ts title="medusa-config.ts"
module.exports = defineConfig({
projectConfig: {
databaseUrl: process.env.DATABASE_URL,
@@ -115,7 +115,7 @@ module.exports = defineConfig({
The database schema to connect to. This is not required to provide if you’re using the default schema, which is `public`.
```js title="medusa-config.js"
```ts title="medusa-config.ts"
module.exports = defineConfig({
projectConfig: {
databaseSchema: process.env.DATABASE_SCHEMA ||
@@ -132,7 +132,7 @@ This configuration specifies whether database messages should be logged.
#### Example
```js title="medusa-config.js"
```ts title="medusa-config.ts"
module.exports = defineConfig({
projectConfig: {
databaseLogging: false
@@ -158,7 +158,7 @@ Make sure to add to the end of the database URL `?ssl_mode=disable` as well when
#### Example
```js title="medusa-config.js"
```ts title="medusa-config.ts"
module.exports = defineConfig({
projectConfig: {
databaseDriverOptions: process.env.NODE_ENV !== "development" ?
@@ -193,7 +193,7 @@ For a local Redis installation, the connection URL should be `redis://localhost:
#### Example
```js title="medusa-config.js"
```ts title="medusa-config.ts"
module.exports = defineConfig({
projectConfig: {
redisUrl: process.env.REDIS_URL ||
@@ -212,7 +212,7 @@ If this configuration option is provided, it is prepended to `sess:`.
#### Example
```js title="medusa-config.js"
```ts title="medusa-config.ts"
module.exports = defineConfig({
projectConfig: {
redisPrefix: process.env.REDIS_URL || "medusa:",
@@ -229,7 +229,7 @@ for the list of available options.
#### Example
```js title="medusa-config.js"
```ts title="medusa-config.ts"
module.exports = defineConfig({
projectConfig: {
redisOptions: {
@@ -248,7 +248,7 @@ This configuration defines additional options to pass to [express-session](https
#### Example
```js title="medusa-config.js"
```ts title="medusa-config.ts"
module.exports = defineConfig({
projectConfig: {
sessionOptions: {
@@ -287,7 +287,7 @@ In production, it's recommended to deploy two instances:
#### Example
```js title="medusa-config.js"
```ts title="medusa-config.ts"
module.exports = defineConfig({
projectConfig: {
workerMode: process.env.WORKER_MODE || "shared"
@@ -303,7 +303,7 @@ This property configures the application's http-specific settings.
#### Example
```js title="medusa-config.js"
```ts title="medusa-config.ts"
module.exports = defineConfig({
projectConfig: {
http: {
@@ -330,7 +330,7 @@ This property holds configurations for the Medusa Admin dashboard.
### Example
```js title="medusa-config.js"
```ts title="medusa-config.ts"
module.exports = defineConfig({
admin: {
backendUrl: process.env.MEDUSA_BACKEND_URL ||
@@ -347,11 +347,11 @@ in both development and production environments. The default value is `false`.
#### Example
```js title="medusa-config.js"
```ts
title = "medusa-config.ts"
module.exports = defineConfig({
admin: {
disable: process.env.ADMIN_DISABLED === "true" ||
false
disable: process.env.ADMIN_DISABLED === "true" || false,
},
// ...
})
@@ -376,7 +376,7 @@ the value of the `path` configuration, as it's `/app` by default.
#### Example
```js title="medusa-config.js"
```ts title="medusa-config.ts"
module.exports = defineConfig({
admin: {
path: process.env.ADMIN_PATH || `/app`,
@@ -392,7 +392,7 @@ The default value is `./build`.
#### Example
```js title="medusa-config.js"
```ts title="medusa-config.ts"
module.exports = defineConfig({
admin: {
outDir: process.env.ADMIN_BUILD_DIR || `./build`,
@@ -407,7 +407,7 @@ The URL of your Medusa application. This is useful to set when you deploy the Me
#### Example
```js title="medusa-config.js"
```ts title="medusa-config.ts"
module.exports = defineConfig({
admin: {
backendUrl: process.env.MEDUSA_BACKEND_URL ||
@@ -435,22 +435,20 @@ add them to this property if you're changing their configurations or adding prov
:::
The keys of the `modules` configuration object refer to the module's registration name. Its value can be one of the following:
`modules` is an array of objects, each holding a module's registration configurations. Each object has the following properties:
1. A boolean value indicating whether the module type is enabled. This is only supported for Medusa's commerce and architectural modules;
2. Or an object having the following properties:
1. `resolve`: a string indicating the path to the module relative to `src`, or the module's NPM package name. For example, `./modules/my-module`.
2. `options`: (optional) an object indicating the options to pass to the module.
1. `resolve`: a string indicating the path to the module relative to `src`, or the module's NPM package name. For example, `./modules/my-module`.
2. `options`: (optional) an object indicating the options to pass to the module.
### Example
```js title="medusa-config.js"
```ts title="medusa-config.ts"
module.exports = defineConfig({
modules: {
helloModuleService: {
modules: [
{
resolve: "./modules/hello"
}
}
]
// ...
})
```
@@ -462,7 +460,7 @@ ___
Some features in the Medusa application are guarded by a feature flag. This ensures constant shipping of new features while maintaining the engine’s stability.
You can enable a feature in your application by enabling its feature flag. Feature flags are enabled through either environment
variables or through this configuration property exported in `medusa-config.js`.
variables or through this configuration property exported in `medusa-config.ts`.
The `featureFlags`'s value is an object. Its properties are the names of the feature flags, and their value is a boolean indicating whether the feature flag is enabled.
@@ -470,7 +468,7 @@ You can find available feature flags and their key name [here](https://github.co
### Example
```js title="medusa-config.js"
```ts title="medusa-config.ts"
module.exports = defineConfig({
featureFlags: {
analytics: true,
@@ -4,4 +4,4 @@ import { TypeList } from "docs-ui"
Essential configurations related to the Medusa application, such as database and CORS configurations.
<TypeList types={[{"name":"http","type":"`object`","description":"This property configures the application's http-specific settings.","optional":false,"defaultValue":"","expandable":false,"children":[{"name":"authCors","type":"`string`","description":"The Medusa application's API Routes are protected by Cross-Origin Resource Sharing (CORS). So, only allowed URLs or URLs matching a specified pattern can send requests to the backend’s API Routes.\n\n`cors` is a string used to specify the accepted URLs or patterns for API Routes starting with `/auth`. It can either be one accepted origin, or a comma-separated list of accepted origins.\n\nEvery origin in that list must either be:\n\n1. A URL. For example, `http://localhost:7001`. The URL must not end with a backslash;\n2. Or a regular expression pattern that can match more than one origin. For example, `.example.com`. The regex pattern that Medusa tests for is `^([/~@;%#'])(.*?)\\1([gimsuy]*)$`.","optional":false,"defaultValue":"","expandable":false,"children":[]},{"name":"storeCors","type":"`string`","description":"The Medusa application's API Routes are protected by Cross-Origin Resource Sharing (CORS). So, only allowed URLs or URLs matching a specified pattern can send requests to the backend’s API Routes.\n\n`store_cors` is a string used to specify the accepted URLs or patterns for store API Routes. It can either be one accepted origin, or a comma-separated list of accepted origins.\n\nEvery origin in that list must either be:\n\n1. A URL. For example, `http://localhost:8000`. The URL must not end with a backslash;\n2. Or a regular expression pattern that can match more than one origin. For example, `.example.com`. The regex pattern that the backend tests for is `^([/~@;%#'])(.*?)\\1([gimsuy]*)$`.","optional":false,"defaultValue":"","expandable":false,"children":[]},{"name":"adminCors","type":"`string`","description":"The Medusa application's API Routes are protected by Cross-Origin Resource Sharing (CORS). So, only allowed URLs or URLs matching a specified pattern can send requests to the backend’s API Routes.\n\n`admin_cors` is a string used to specify the accepted URLs or patterns for admin API Routes. It can either be one accepted origin, or a comma-separated list of accepted origins.\n\nEvery origin in that list must either be:\n\n1. A URL. For example, `http://localhost:7001`. The URL must not end with a backslash;\n2. Or a regular expression pattern that can match more than one origin. For example, `.example.com`. The regex pattern that the backend tests for is `^([/~@;%#'])(.*?)\\1([gimsuy]*)$`.","optional":false,"defaultValue":"","expandable":false,"children":[]},{"name":"jwtSecret","type":"`string`","description":"A random string used to create authentication tokens in the http layer. Although this configuration option is not required, it’s highly recommended to set it for better security.\n\nIn a development environment, if this option is not set the default secret is `supersecret`. However, in production, if this configuration is not set, an\nerror is thrown and the application crashes.","optional":true,"defaultValue":"","expandable":false,"children":[]},{"name":"jwtExpiresIn","type":"`string`","description":"The expiration time for the JWT token. Its format is based off the [ms package](https://github.com/vercel/ms).\n\nIf not provided, the default value is `24h`.","optional":true,"defaultValue":"","expandable":false,"children":[]},{"name":"cookieSecret","type":"`string`","description":"A random string used to create cookie tokens in the http layer. Although this configuration option is not required, it’s highly recommended to set it for better security.\n\nIn a development environment, if this option is not set, the default secret is `supersecret`. However, in production, if this configuration is not set, an error is thrown and\nthe application crashes.","optional":true,"defaultValue":"","expandable":false,"children":[]},{"name":"compression","type":"[HttpCompressionOptions](../medusa_config.HttpCompressionOptions/page.mdx)","description":"Configure HTTP compression from the application layer. If you have access to the HTTP server, the recommended approach would be to enable it there.\nHowever, some platforms don't offer access to the HTTP layer and in those cases, this is a good alternative.\n\nIf you enable HTTP compression and you want to disable it for specific API Routes, you can pass in the request header `\"x-no-compression\": true`.\nLearn more in the [API Reference](https://docs.medusajs.com/v2/api/store#http-compression).","optional":true,"defaultValue":"","expandable":false,"children":[{"name":"enabled","type":"`boolean`","description":"Whether HTTP compression is enabled. By default, it's `false`.","optional":true,"defaultValue":"","expandable":false,"children":[]},{"name":"level","type":"`number`","description":"The level of zlib compression to apply to responses. A higher level will result in better compression but wilLine truncated
<TypeList types={[{"name":"http","type":"`object`","description":"This property configures the application's http-specific settings.","optional":false,"defaultValue":"","expandable":false,"children":[{"name":"authCors","type":"`string`","description":"The Medusa application's API Routes are protected by Cross-Origin Resource Sharing (CORS). So, only allowed URLs or URLs matching a specified pattern can send requests to the backend’s API Routes.\n\n`cors` is a string used to specify the accepted URLs or patterns for API Routes starting with `/auth`. It can either be one accepted origin, or a comma-separated list of accepted origins.\n\nEvery origin in that list must either be:\n\n1. A URL. For example, `http://localhost:7001`. The URL must not end with a backslash;\n2. Or a regular expression pattern that can match more than one origin. For example, `.example.com`. The regex pattern that Medusa tests for is `^([/~@;%#'])(.*?)\\1([gimsuy]*)$`.","optional":false,"defaultValue":"","expandable":false,"children":[]},{"name":"storeCors","type":"`string`","description":"The Medusa application's API Routes are protected by Cross-Origin Resource Sharing (CORS). So, only allowed URLs or URLs matching a specified pattern can send requests to the backend’s API Routes.\n\n`store_cors` is a string used to specify the accepted URLs or patterns for store API Routes. It can either be one accepted origin, or a comma-separated list of accepted origins.\n\nEvery origin in that list must either be:\n\n1. A URL. For example, `http://localhost:8000`. The URL must not end with a backslash;\n2. Or a regular expression pattern that can match more than one origin. For example, `.example.com`. The regex pattern that the backend tests for is `^([/~@;%#'])(.*?)\\1([gimsuy]*)$`.","optional":false,"defaultValue":"","expandable":false,"children":[]},{"name":"adminCors","type":"`string`","description":"The Medusa application's API Routes are protected by Cross-Origin Resource Sharing (CORS). So, only allowed URLs or URLs matching a specified pattern can send requests to the backend’s API Routes.\n\n`admin_cors` is a string used to specify the accepted URLs or patterns for admin API Routes. It can either be one accepted origin, or a comma-separated list of accepted origins.\n\nEvery origin in that list must either be:\n\n1. A URL. For example, `http://localhost:7001`. The URL must not end with a backslash;\n2. Or a regular expression pattern that can match more than one origin. For example, `.example.com`. The regex pattern that the backend tests for is `^([/~@;%#'])(.*?)\\1([gimsuy]*)$`.","optional":false,"defaultValue":"","expandable":false,"children":[]},{"name":"jwtSecret","type":"`string`","description":"A random string used to create authentication tokens in the http layer. Although this configuration option is not required, it’s highly recommended to set it for better security.\n\nIn a development environment, if this option is not set the default secret is `supersecret`. However, in production, if this configuration is not set, an\nerror is thrown and the application crashes.","optional":true,"defaultValue":"","expandable":false,"children":[]},{"name":"jwtExpiresIn","type":"`string`","description":"The expiration time for the JWT token. Its format is based off the [ms package](https://github.com/vercel/ms).\n\nIf not provided, the default value is `24h`.","optional":true,"defaultValue":"","expandable":false,"children":[]},{"name":"cookieSecret","type":"`string`","description":"A random string used to create cookie tokens in the http layer. Although this configuration option is not required, it’s highly recommended to set it for better security.\n\nIn a development environment, if this option is not set, the default secret is `supersecret`. However, in production, if this configuration is not set, an error is thrown and\nthe application crashes.","optional":true,"defaultValue":"","expandable":false,"children":[]},{"name":"compression","type":"[HttpCompressionOptions](../medusa_config.HttpCompressionOptions/page.mdx)","description":"Configure HTTP compression from the application layer. If you have access to the HTTP server, the recommended approach would be to enable it there.\nHowever, some platforms don't offer access to the HTTP layer and in those cases, this is a good alternative.\n\nIf you enable HTTP compression and you want to disable it for specific API Routes, you can pass in the request header `\"x-no-compression\": true`.\nLearn more in the [API Reference](https://docs.medusajs.com/v2/api/store#http-compression).","optional":true,"defaultValue":"","expandable":false,"children":[{"name":"enabled","type":"`boolean`","description":"Whether HTTP compression is enabled. By default, it's `false`.","optional":true,"defaultValue":"","expandable":false,"children":[]},{"name":"level","type":"`number`","description":"The level of zlib compression to apply to responses. A higher level will result in better compression but wilLine truncated
@@ -4,6 +4,4 @@ import { TypeList } from "docs-ui"
**PluginDetails**: `Object`
## Properties
<TypeList types={[{"name":"resolve","type":"`string`","description":"","optional":false,"defaultValue":"","expandable":false,"children":[]},{"name":"name","type":"`string`","description":"","optional":false,"defaultValue":"","expandable":false,"children":[]},{"name":"id","type":"`string`","description":"","optional":false,"defaultValue":"","expandable":false,"children":[]},{"name":"options","type":"`Record<string, unknown>`","description":"","optional":false,"defaultValue":"","expandable":false,"children":[]},{"name":"version","type":"`string`","description":"","optional":false,"defaultValue":"","expandable":false,"children":[]}]} expandUrl="https://docs.medusajs.com/v2/advanced-development/data-models/manage-relationships#retrieve-records-of-relation" sectionTitle="PluginDetails"/>
@@ -82,15 +82,33 @@ export default MyNotificationProviderService
### validateOptions
Override this static method in order for the loader to validate the options provided to the module provider.
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 MyNotificationProviderService extends AbstractNotificationProviderService {
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":"options","type":"`Record<any, any>`","description":"","optional":false,"defaultValue":"","expandable":false,"children":[]}]} expandUrl="https://docs.medusajs.com/v2/advanced-development/data-models/manage-relationships#retrieve-records-of-relation" sectionTitle="validateOptions"/>
<TypeList types={[{"name":"options","type":"`Record<any, any>`","description":"The provider's options.","optional":false,"defaultValue":"","expandable":false,"children":[]}]} expandUrl="https://docs.medusajs.com/v2/advanced-development/data-models/manage-relationships#retrieve-records-of-relation" sectionTitle="validateOptions"/>
#### Returns
<TypeList types={[{"name":"void","type":"`void`","optional":false,"defaultValue":"","description":"Override this static method in order for the loader to validate the options provided to the module provider.","expandable":false,"children":[]}]} expandUrl="https://docs.medusajs.com/v2/advanced-development/data-models/manage-relationships#retrieve-records-of-relation" sectionTitle="validateOptions"/>
<TypeList types={[{"name":"void","type":"`void`","optional":false,"defaultValue":"","description":"This method validates the options of the provider set in `medusa-config.ts`.\nImplementing this method is optional. It's useful if your provider requires custom validation.\n\nIf the options aren't valid, throw an error.","expandable":false,"children":[]}]} expandUrl="https://docs.medusajs.com/v2/advanced-development/data-models/manage-relationships#retrieve-records-of-relation" sectionTitle="validateOptions"/>
### send
@@ -124,7 +142,7 @@ class MyNotificationProviderService extends AbstractNotificationProviderService
#### Parameters
<TypeList types={[{"name":"notification","type":"[ProviderSendNotificationDTO](../../../types/NotificationTypes/interfaces/types.NotificationTypes.ProviderSendNotificationDTO/page.mdx)","description":"The details of the\nnotification to send.","optional":false,"defaultValue":"","expandable":false,"children":[{"name":"to","type":"`string`","description":"The recipient of the notification. It can be email, phone number, or username, depending on the channel.","optional":false,"defaultValue":"","expandable":false,"children":[]},{"name":"channel","type":"`string`","description":"The channel through which the notification is sent, such as 'email' or 'sms'","optional":false,"defaultValue":"","expandable":false,"children":[]},{"name":"template","type":"`string`","description":"The template name in the provider's system.","optional":false,"defaultValue":"","expandable":false,"children":[]},{"name":"from","type":"`null` \\| `string`","description":"The sender of the notification. It can be email, phone number, or username, depending on the channel.","optional":true,"defaultValue":"","expandable":false,"children":[]},{"name":"attachments","type":"`null` \\| [Attachment](../../../types/NotificationTypes/interfaces/types.NotificationTypes.Attachment/page.mdx)[]","description":"Optional attachments for the notification.","optional":true,"defaultValue":"","expandable":false,"children":[{"name":"content","type":"`string`","description":"The content of the attachment, encoded as a base64 string.","optional":false,"defaultValue":"","expandable":false,"children":[]},{"name":"filename","type":"`string`","description":"The filename of the attachment.","optional":false,"defaultValue":"","expandable":false,"children":[]},{"name":"content_type","type":"`string`","description":"The MIME type of the attachment.","optional":true,"defaultValue":"","expandable":false,"children":[]},{"name":"disposition","type":"`string`","description":"The disposition of the attachment, e.g., \"inline\" or \"attachment\".","optional":true,"defaultValue":"","expandable":false,"children":[]},{"name":"id","type":"`string`","description":"The ID, if the attachment is meant to be referenced within the body of the message.","optional":true,"defaultValue":"","expandable":false,"children":[]}]},{"name":"data","type":"`null` \\| `Record<string, unknown>`","description":"The data that gets passed over to the provider for rendering the notification.","optional":true,"defaultValue":"","expandable":false,"children":[]}]}]} expandUrl="https://docs.medusajs.com/v2/advanced-development/data-models/manage-relationships#retrieve-records-of-relation" sectionTitle="send"/>
<TypeList types={[{"name":"notification","type":"[ProviderSendNotificationDTO](../../../types/NotificationTypes/interfaces/types.NotificationTypes.ProviderSendNotificationDTO/page.mdx)","description":"The details of the\nnotification to send.","optional":false,"defaultValue":"","expandable":false,"children":[{"name":"to","type":"`string`","description":"The recipient of the notification. It can be email, phone number, or username, depending on the channel.","optional":false,"defaultValue":"","expandable":false,"children":[]},{"name":"channel","type":"`string`","description":"The channel through which the notification is sent, such as 'email' or 'sms'","optional":false,"defaultValue":"","expandable":false,"children":[]},{"name":"template","type":"`string`","description":"The template name in the provider's system.","optional":false,"defaultValue":"","expandable":false,"children":[]},{"name":"from","type":"`null` \\| `string`","description":"The sender of the notification. It can be email, phone number, or username, depending on the channel.","optional":true,"defaultValue":"","expandable":false,"children":[]},{"name":"attachments","type":"`null` \\| [Attachment](../../../types/NotificationTypes/interfaces/types.NotificationTypes.Attachment/page.mdx)[]","description":"Optional attachments for the notification.","optional":true,"defaultValue":"","expandable":false,"children":[{"name":"content","type":"`string`","description":"The content of the attachment, encoded as a base64 string.","optional":false,"defaultValue":"","expandable":false,"children":[]},{"name":"filename","type":"`string`","description":"The filename of the attachment.","optional":false,"defaultValue":"","expandable":false,"children":[]},{"name":"content_type","type":"`string`","description":"The MIME type of the attachment.","optional":true,"defaultValue":"","expandable":false,"children":[]},{"name":"disposition","type":"`string`","description":"The disposition of the attachment, e.g., \"inline\" or \"attachment\".","optional":true,"defaultValue":"","expandable":false,"children":[]},{"name":"id","type":"`string`","description":"The ID, if the attachment is meant to be referenced within the body of the message.","optional":true,"defaultValue":"","expandable":false,"children":[]}]},{"name":"data","type":"`null` \\| `Record<string, unknown>`","description":"The data that gets passed over to the provider for rendering the notification.","optional":true,"defaultValue":"","expandable":false,"children":[]},{"name":"content","type":"`null` \\| [NotificationContent](../../../types/NotificationTypes/interfaces/types.NotificationTypes.NotificationContent/page.mdx)","description":"The content that gets passed to the provider.","optional":true,"defaultValue":"","expandable":false,"children":[{"name":"subject","type":"`string`","description":"the subject of the notification","optional":true,"defaultValue":"","expandable":false,"children":[]},{"name":"text","type":"`string`","description":"the text content of the notification","optional":true,"defaultValue":"","expandable":false,"children":[]},{"name":"html","type":"`string`","description":"the html content of the notification","optional":true,"defaultValue":"","expandable":false,"children":[]}]}]}]} expandUrl="https://docs.medusajs.com/v2/advanced-development/data-models/manage-relationships#retrieve-records-of-relation" sectionTitle="send"/>
#### Returns
@@ -138,10 +156,14 @@ Create the file `src/modules/my-notification/index.ts` with the following conten
```ts title="src/modules/my-notification/index.ts"
import MyNotificationProviderService from "./service"
import {
ModuleProvider,
Modules
} from "@medusajs/framework/utils"
export default {
export default ModuleProvider(Modules.NOTIFICATION, {
services: [MyNotificationProviderService],
}
})
```
This exports the module's definition, indicating that the `MyNotificationProviderService` is the module's service.
@@ -171,7 +193,7 @@ module.exports = defineConfig({
options: {
providers: [
{
resolve: "./modules/my-notification",
resolve: "./src/modules/my-notification",
id: "my-notification",
options: {
channels: ["email"],
@@ -68,6 +68,7 @@ type Options = {
class MyPaymentProviderService extends AbstractPaymentProvider<
Options
> {
static identifier = "my-payment"
protected logger_: Logger
protected options_: Options
// Assuming you're using a client to integrate
@@ -96,19 +97,37 @@ export default MyPaymentProviderService
#### Parameters
<TypeList types={[{"name":"container","type":"[MedusaContainer](../../../medusa/types/medusa.MedusaContainer-1/page.mdx)","description":"The module's container used to resolve resources.","optional":false,"defaultValue":"","expandable":false,"children":[{"name":"registerAdd","type":"`<T>`(`name`: `string`, `registration`: T) => [MedusaContainer](../../../medusa/types/medusa.MedusaContainer-1/page.mdx)","description":"","optional":false,"defaultValue":"","expandable":false,"children":[]},{"name":"createScope","type":"() => [MedusaContainer](../../../medusa/types/medusa.MedusaContainer-1/page.mdx)","description":"","optional":false,"defaultValue":"","expandable":false,"children":[]}]},{"name":"config","type":"TConfig","description":"The options passed to the payment module provider.","optional":false,"defaultValue":"","expandable":false,"children":[]}]} expandUrl="https://docs.medusajs.com/v2/advanced-development/data-models/manage-relationships#retrieve-records-of-relation" sectionTitle="new AbstractPaymentProvider"/>
<TypeList types={[{"name":"container","type":"[MedusaContainer](../../../medusa/types/medusa.MedusaContainer-1/page.mdx)","description":"The module's container used to resolve resources.","optional":false,"defaultValue":"","expandable":false,"children":[]},{"name":"config","type":"TConfig","description":"The options passed to the payment module provider.","optional":false,"defaultValue":"","expandable":false,"children":[]}]} expandUrl="https://docs.medusajs.com/v2/advanced-development/data-models/manage-relationships#retrieve-records-of-relation" sectionTitle="new AbstractPaymentProvider"/>
### validateOptions
Override this static method in order for the loader to validate the options provided to the module provider.
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 MyPaymentProviderService extends AbstractPaymentProvider<Options> {
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":"options","type":"`Record<any, any>`","description":"","optional":false,"defaultValue":"","expandable":false,"children":[]}]} expandUrl="https://docs.medusajs.com/v2/advanced-development/data-models/manage-relationships#retrieve-records-of-relation" sectionTitle="validateOptions"/>
<TypeList types={[{"name":"options","type":"`Record<any, any>`","description":"The provider's options.","optional":false,"defaultValue":"","expandable":false,"children":[]}]} expandUrl="https://docs.medusajs.com/v2/advanced-development/data-models/manage-relationships#retrieve-records-of-relation" sectionTitle="validateOptions"/>
#### Returns
<TypeList types={[{"name":"void","type":"`void`","optional":false,"defaultValue":"","description":"Override this static method in order for the loader to validate the options provided to the module provider.","expandable":false,"children":[]}]} expandUrl="https://docs.medusajs.com/v2/advanced-development/data-models/manage-relationships#retrieve-records-of-relation" sectionTitle="validateOptions"/>
<TypeList types={[{"name":"void","type":"`void`","optional":false,"defaultValue":"","description":"This method validates the options of the provider set in `medusa-config.ts`.\nImplementing this method is optional. It's useful if your provider requires custom validation.\n\nIf the options aren't valid, throw an error.","expandable":false,"children":[]}]} expandUrl="https://docs.medusajs.com/v2/advanced-development/data-models/manage-relationships#retrieve-records-of-relation" sectionTitle="validateOptions"/>
### capturePayment
@@ -681,10 +700,14 @@ Create the file `src/modules/my-payment/index.ts` with the following content:
```ts title="src/modules/my-payment/index.ts"
import MyPaymentProviderService from "./service"
import {
ModuleProvider,
Modules
} from "@medusajs/framework/utils"
export default {
export default ModuleProvider(Modules.PAYMENT, {
services: [MyPaymentProviderService],
}
})
```
This exports the module's definition, indicating that the `MyPaymentProviderService` is the module's service.
@@ -708,7 +731,7 @@ module.exports = defineConfig({
options: {
providers: [
{
resolve: "./modules/my-payment",
resolve: "./src/modules/my-payment",
id: "my-payment",
options: {
// provider options...