Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 2 additions & 0 deletions docs/.vuepress/config/sidebar-developer.js
Original file line number Diff line number Diff line change
Expand Up @@ -222,6 +222,7 @@ const developer = [
['/developer-docs/latest/development/admin-customization', 'Admin panel customization'],
['/developer-docs/latest/development/plugins-extension.md', 'Plugins extension'],
['/developer-docs/latest/development/plugins-development.md', 'Plugins development'],
['/developer-docs/latest/development/providers.md', 'Providers'],
],
},
{
Expand Down Expand Up @@ -423,6 +424,7 @@ const developer = [
['/developer-docs/latest/plugins/users-permissions', 'Users & Permissions'],
['/developer-docs/latest/plugins/email', 'Email'],
['/developer-docs/latest/plugins/upload', 'Upload'],
['/developer-docs/latest/plugins/sentry', 'Sentry'],
['/developer-docs/latest/plugins/documentation', 'API Documentation'],
],
sidebarDepth: 1,
Expand Down
13 changes: 13 additions & 0 deletions docs/.vuepress/theme/global-components/PluginsLinks.vue
Original file line number Diff line number Diff line change
Expand Up @@ -261,6 +261,19 @@
</template>
</InstallLink>
</div>

<!-- Sentry -->
<div>
<InstallLink link="/developer-docs/latest/plugins/sentry.html">
<template #icon>
<svg class="css-lfbo6j e10nushx4" xmlns="http://www.w3.org/2000/svg" viewBox="0 0 72 66" width="30" height="28"><path d="M29,2.26a4.67,4.67,0,0,0-8,0L14.42,13.53A32.21,32.21,0,0,1,32.17,40.19H27.55A27.68,27.68,0,0,0,12.09,17.47L6,28a15.92,15.92,0,0,1,9.23,12.17H4.62A.76.76,0,0,1,4,39.06l2.94-5a10.74,10.74,0,0,0-3.36-1.9l-2.91,5a4.54,4.54,0,0,0,1.69,6.24A4.66,4.66,0,0,0,4.62,44H19.15a19.4,19.4,0,0,0-8-17.31l2.31-4A23.87,23.87,0,0,1,23.76,44H36.07a35.88,35.88,0,0,0-16.41-31.8l4.67-8a.77.77,0,0,1,1.05-.27c.53.29,20.29,34.77,20.66,35.17a.76.76,0,0,1-.68,1.13H40.6q.09,1.91,0,3.81h4.78A4.59,4.59,0,0,0,50,39.43a4.49,4.49,0,0,0-.62-2.28Z" transform="translate(11, 11)" fill="#362d59"></path></svg>
</template>
<template #title>Sentry</template>
<template #description>
Plugin to track errors in your Strapi application using Sentry
</template>
</InstallLink>
</div>
</div>
</template>

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -63,7 +63,7 @@ Errors thrown by the GraphQL API are included in the [response](/developer-docs/

The recommended way to throw errors when developing any custom logic with Strapi is to have the [controller](/developer-docs/latest/development/backend-customization/controllers.md) respond with the correct status and body.

This can be done by calling an error function on the context (i.e. `ctx`). Available error functions are listed in the [http-errors documentation](https://github.com/jshttp/http-errors#list-of-all-constructors) but their name should be camel-cased to be used by Strapi (e.g. `badRequest`).
This can be done by calling an error function on the context (i.e. `ctx`). Available error functions are listed in the [http-errors documentation](https://github.com/jshttp/http-errors#list-of-all-constructors) but their name should be lower camel-cased to be used by Strapi (e.g. `badRequest`).

Error functions accept 2 parameters that correspond to the `error.message` and `error.details` attributes [received](#receiving-errors) by a developer querying the API:

Expand Down
205 changes: 205 additions & 0 deletions docs/developer-docs/latest/development/providers.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,205 @@
---
title: Providers - Strapi Developer Docs
description: Install and use providers to extend the functionality of available plugins.
canonicalUrl: https://docs.strapi.io/developer-docs/latest/development/providers.html
---

# Providers

Certain [plugins](../../../user-docs/latest/plugins/introduction-to-plugins.md) can be extended via the installation and configuration of additional [providers](../../../user-docs/latest/plugins/introduction-to-plugins.md#providers).

Providers add an extension to the core capabilities of the plugin, for example to upload media files to Rackspace instead of the local server, or using Amazon SES for emails instead of Sendmail.

::: note
Only the [Upload](../plugins/upload.md) and [Email](../plugins/email.md) plugins are currently designed to work with providers.
:::

For the relevant plugins, there are both official providers maintained by Strapi — discoverable via the [Marketplace](../../../user-docs/latest/plugins/installing-plugins-via-marketplace.md) — and many community maintained providers available via [npm](https://www.npmjs.com/).

## Installing providers

New providers can be installed using `npm` or `yarn` using the following format `@strapi/provider-<plugin>-<provider> --save`.

For example:

<code-group>

<code-block title="NPM">
```sh
# Install the AWS S3 provider for the Upload plugin
npm install @strapi/provider-upload-aws-s3 --save

# Install the Sendgrid provider for the Email plugin
npm install @strapi/provider-email-sendgrid --save
```
</code-block>

<code-block title="YARN">
```sh
# Install the AWS S3 provider for the Upload plugin
yarn add @strapi/provider-upload-aws-s3

# Install the Sendgrid provider for the Email plugin
yarn add @strapi/provider-email-sendgrid --save
```
</code-block>

</code-group>

## Configuring providers

Newly installed providers are enabled and configured in the `./config/plugins.js` file. If this file does not exist you must create it.

Each provider will have different configuration settings available. Review the respective entry for that provider in the [Marketplace](../../../user-docs/latest/plugins/installing-plugins-via-marketplace.md) or [npm](https://www.npmjs.com/) to learn more.

Below are example configurations for the Upload and Email plugins.

:::: tabs card

::: tab Upload

```js
// path: ./config/plugins.js

module.exports = ({ env }) => ({
// ...
upload: {
config: {
provider: 'aws-s3', // For community providers pass the full package name (e.g. provider: 'strapi-provider-upload-google-cloud-storage')
providerOptions: {
accessKeyId: env('AWS_ACCESS_KEY_ID'),
secretAccessKey: env('AWS_ACCESS_SECRET'),
region: env('AWS_REGION'),
params: {
Bucket: env('AWS_BUCKET'),
},
},
},
},
// ...
});
```

::: note
Strapi has a default [`security` middleware](/developer-docs/latest/setup-deployment-guides/configurations/required/middlewares.md#security) that has a very strict `contentSecurityPolicy` that limits loading images and media to `"'self'"` only, see the example configuration on the [provider page](https://www.npmjs.com/package/@strapi/provider-upload-aws-s3) or the [middleware documentation](/developer-docs/latest/setup-deployment-guides/configurations/required/middlewares.md#security) for more information.
:::

::: tab Email

```js
// path: ./config/plugins.js

module.exports = ({ env }) => ({
// ...
email: {
config: {
provider: 'sendgrid', // For community providers pass the full package name (e.g. provider: 'strapi-provider-email-mandrill')
providerOptions: {
apiKey: env('SENDGRID_API_KEY'),
},
settings: {
defaultFrom: 'juliasedefdjian@strapi.io',
defaultReplyTo: 'juliasedefdjian@strapi.io',
testAddress: 'juliasedefdjian@strapi.io',
},
},
},
// ...
});
```

Keep in mind that:

* When using a different provider per environment, specify the correct configuration in `./config/env/${yourEnvironment}/plugins.js` (See [Environments](/developer-docs/latest/setup-deployment-guides/configurations/optional/environment.md)).
* Only one email provider will be active at a time. If the email provider setting isn't picked up by Strapi, verify the `plugins.js` file is in the correct folder.
* When testing the new email provider with those two email templates created during strapi setup, the _shipper email_ on the template defaults to `no-reply@strapi.io` and needs to be updated according to your email provider, otherwise it will fail the test (See [Configure templates locally](/user-docs/latest/settings/configuring-users-permissions-plugin-settings.md#configuring-email-templates)).

:::

::::

### Configuration per environment

When configuring your provider you might want to change the configuration based on the `NODE_ENV` environment variable or use environment specific credentials.

You can set a specific configuration in the `./config/env/{env}/plugins.js` configuration file and it will be used to overwrite the default configuration.

## Creating providers

To implement your own custom provider you must [create a Node.js module](https://docs.npmjs.com/creating-node-js-modules).

The interface that must be exported depends on the plugin you are developing the provider for. Below are templates for the Upload and Email plugins:

:::: tabs card

::: tab Upload

```js
module.exports = {
init(providerOptions) {
// init your provider if necessary

return {
upload(file) {
// upload the file in the provider
// file content is accessible by `file.buffer`
},
uploadStream(file) {
// upload the file in the provider
// file content is accessible by `file.stream`
},
delete(file) {
// delete the file in the provider
},
};
},
};
```
:::
::: tab Email

```js
module.exports = {
init: (providerOptions = {}, settings = {}) => {
return {
send: async options => {},
};
},
};
```

In the send function you will have access to:

* `providerOptions` that contains configurations written in `plugins.js`
* `settings` that contains configurations written in `plugins.js`
* `options` that contains options you send when you call the send function from the email plugin service

:::

::::

You can review the [Strapi maintained providers](https://github.com/strapi/strapi/tree/master/packages/providers) for example implementations.

After creating your new provider you can [publish it to npm](https://docs.npmjs.com/creating-and-publishing-unscoped-public-packages) to share with the community or [use it locally](#local-providers) for your project only.

### Local providers

If you want to create your own provider without publishing it on npm you can follow these steps:

1. Create a `providers` folder in your application.
2. Create your provider (e.g. `./providers/strapi-provider-<plugin>-<provider>`)
3. Then update your `package.json` to link your `strapi-provider-<plugin>-<provider>` dependency to the [local path](https://docs.npmjs.com/files/package.json#local-paths) of your new provider.

```json
{
...
"dependencies": {
...
"strapi-provider-<plugin>-<provider>": "file:providers/strapi-provider-<plugin>-<provider>",
...
}
}
```

4. Update your `./config/plugins.js` file to [configure the provider](#configuring-providers).
5. Finally, run `yarn install` or `npm install` to install your new custom provider.
Original file line number Diff line number Diff line change
Expand Up @@ -103,6 +103,6 @@ Due to these two issues, it is recommended you use a proxy application such as [

## Is X feature available yet?

You can see the [ProductBoard roadmap](https://portal.productboard.com/strapi) to see which feature requests are currently being worked on and which have not been started yet.
You can see the [Public roadmap](https://feedback.strapi.io/) to see which feature requests are currently being worked on and which have not been started yet.

<!-- TODO: This will be changed to Canny eventually, leave this note here for Derrick please -->
Loading