api-platform-vendor.php 7.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228
  1. <?php
  2. /*
  3. * This file is part of the API Platform project.
  4. *
  5. * (c) Kévin Dunglas <dunglas@gmail.com>
  6. *
  7. * For the full copyright and license information, please view the LICENSE
  8. * file that was distributed with this source code.
  9. */
  10. declare(strict_types=1);
  11. use ApiPlatform\Metadata\Operation\DashPathSegmentNameGenerator;
  12. use ApiPlatform\Metadata\UrlGeneratorInterface;
  13. use Illuminate\Auth\Access\AuthorizationException;
  14. use Illuminate\Auth\AuthenticationException;
  15. use Symfony\Component\Serializer\NameConverter\SnakeCaseToCamelCaseNameConverter;
  16. use Webkul\BagistoApi\Exception\InvalidInputException;
  17. use Webkul\BagistoApi\Exception\ValidationException;
  18. return [
  19. 'title' => '',
  20. 'description' => '',
  21. 'version' => '1.0.0',
  22. 'show_webby' => true,
  23. 'routes' => [
  24. 'domain' => null,
  25. // Global middleware applied to every API Platform routes
  26. // HandleInvalidInputException: Catches validation errors and returns RFC 7807 format
  27. // VerifyStorefrontKey: Validates X-STOREFRONT-KEY header and rate limiting for shop APIs
  28. // BagistoApiDocumentationMiddleware: Handles custom /api index and documentation pages
  29. // ForceApiJson: Ensures API responses have JSON content-type
  30. // CacheResponse: Using custom ApiAwareResponseCache profile that:
  31. // - Excludes API routes from caching (APIs need fresh data)
  32. // - Caches shop pages for performance
  33. // - Only caches HTML, not JSON responses
  34. 'middleware' => [
  35. 'Webkul\BagistoApi\Http\Middleware\HandleInvalidInputException',
  36. 'Webkul\BagistoApi\Http\Middleware\SecurityHeaders',
  37. 'Webkul\BagistoApi\Http\Middleware\LogApiRequests',
  38. 'Webkul\BagistoApi\Http\Middleware\VerifyStorefrontKey',
  39. 'Webkul\BagistoApi\Http\Middleware\BagistoApiDocumentationMiddleware',
  40. 'Webkul\BagistoApi\Http\Middleware\ForceApiJson',
  41. 'Spatie\ResponseCache\Middlewares\CacheResponse',
  42. ],
  43. ],
  44. 'resources' => [
  45. base_path('vendor/bagisto/bagisto-api/src/Models/')
  46. ],
  47. 'formats' => [
  48. 'json'=> ['application/json'],
  49. ],
  50. 'patch_formats' => [
  51. 'json' => ['application/merge-patch+json'],
  52. ],
  53. 'docs_formats' => [
  54. 'jsonopenapi' => ['application/vnd.openapi+json'],
  55. 'html' => ['text/html'],
  56. ],
  57. 'error_formats' => [
  58. 'jsonproblem' => ['application/problem+json'],
  59. ],
  60. 'defaults' => [
  61. 'pagination_enabled' => true,
  62. 'pagination_partial' => false,
  63. 'pagination_client_enabled' => false,
  64. 'pagination_client_items_per_page' => false,
  65. 'pagination_client_partial' => false,
  66. 'pagination_items_per_page' => 10,
  67. 'pagination_maximum_items_per_page' => 50,
  68. 'route_prefix' => '/api',
  69. 'middleware' => [],
  70. ],
  71. 'pagination' => [
  72. 'page_parameter_name' => 'page',
  73. 'enabled_parameter_name' => 'pagination',
  74. 'items_per_page_parameter_name' => 'itemsPerPage',
  75. 'partial_parameter_name' => 'partial',
  76. ],
  77. 'graphql' => [
  78. 'enabled' => true,
  79. 'nesting_separator' => '__',
  80. 'introspection' => ['enabled' => true],
  81. 'max_query_complexity' => 400,
  82. 'max_query_depth' => 20,
  83. 'graphiql' => [
  84. 'enabled' => true,
  85. 'default_query' => null,
  86. 'default_variables' => null,
  87. ],
  88. 'graphql_playground' => [
  89. 'enabled' => true,
  90. 'default_query' => null,
  91. 'default_variables' => null,
  92. ],
  93. // GraphQL middleware for authentication and rate limiting
  94. 'middleware' => [
  95. 'Webkul\BagistoApi\Http\Middleware\VerifyGraphQLStorefrontKey',
  96. ],
  97. ],
  98. 'graphiql' => [
  99. 'enabled' => true,
  100. ],
  101. 'name_converter' => SnakeCaseToCamelCaseNameConverter::class,
  102. 'path_segment_name_generator' => DashPathSegmentNameGenerator::class,
  103. 'exception_to_status' => [
  104. AuthenticationException::class => 401,
  105. AuthorizationException::class => 403,
  106. ValidationException::class => 400,
  107. InvalidInputException::class => 400,
  108. ],
  109. 'swagger_ui' => [
  110. 'enabled' => true,
  111. 'apiKeys' => [
  112. 'api' => [
  113. 'name' => 'Authorization',
  114. 'type' => 'header',
  115. 'scheme' => 'bearer',
  116. ],
  117. ],
  118. ],
  119. 'url_generation_strategy' => UrlGeneratorInterface::ABS_PATH,
  120. 'serializer' => [
  121. 'hydra_prefix' => false,
  122. 'datetime_format' => 'Y-m-d\TH:i:sP',
  123. ],
  124. 'cache' => 'redis',
  125. 'schema_cache' => [
  126. 'enabled' => true,
  127. 'store' => 'redis',
  128. ],
  129. 'security' => [
  130. 'sanctum' => true,
  131. ],
  132. 'rate_limit' => [
  133. 'skip_localhost' => env('RATE_LIMIT_SKIP_LOCALHOST', true),
  134. 'auth' => env('RATE_LIMIT_AUTH', 5),
  135. 'admin' => env('RATE_LIMIT_ADMIN', 60),
  136. 'shop' => env('RATE_LIMIT_SHOP', 100),
  137. 'graphql' => env('RATE_LIMIT_GRAPHQL', 100),
  138. 'cache_driver' => env('RATE_LIMIT_CACHE', 'redis'),
  139. 'cache_prefix' => 'api:rate-limit:',
  140. ],
  141. 'security_headers' => [
  142. 'enabled' => true,
  143. 'force_https' => env('APP_FORCE_HTTPS', false),
  144. 'csp_header' => "default-src 'self'; script-src 'self' 'unsafe-inline' 'unsafe-eval'; style-src 'self' 'unsafe-inline'; img-src 'self' data: https:; font-src 'self'; connect-src 'self'; frame-ancestors 'none'; base-uri 'self'; form-action 'self'",
  145. ],
  146. 'api_logging' => [
  147. 'enabled' => env('API_LOG_ENABLED', true),
  148. 'log_sensitive_data' => env('API_LOG_SENSITIVE_DATA', false),
  149. 'exclude_paths' => ['docs', 'graphiql', 'swagger-ui', 'docs.json'],
  150. 'channel' => 'api',
  151. 'async' => env('API_LOG_ASYNC', true),
  152. 'queue' => env('API_LOG_QUEUE', 'api-logs'),
  153. ],
  154. 'graphql_validation' => [
  155. 'max_depth' => env('GRAPHQL_MAX_DEPTH', 10),
  156. 'max_complexity' => env('GRAPHQL_MAX_COMPLEXITY', 300),
  157. ],
  158. 'request_limits' => [
  159. 'max_size_mb' => env('MAX_REQUEST_SIZE', 10),
  160. 'max_pagination_limit' => env('MAX_PAGINATION_LIMIT', 100),
  161. ],
  162. 'database' => [
  163. 'log_queries' => env('DB_QUERY_LOG_ENABLED', false),
  164. 'slow_query_threshold' => env('DB_SLOW_QUERY_THRESHOLD', 1000),
  165. ],
  166. 'caching' => [
  167. 'enable_security_cache' => env('API_SECURITY_CACHE', true),
  168. 'security_cache_ttl' => env('API_SECURITY_CACHE_TTL', 3600),
  169. 'enable_response_cache' => env('API_RESPONSE_CACHE', true),
  170. 'response_cache_ttl' => env('API_RESPONSE_CACHE_TTL', 3600),
  171. ],
  172. 'http_cache' => [
  173. 'etag' => true,
  174. 'max_age' => 3600,
  175. 'shared_max_age' => null,
  176. 'vary' => null,
  177. 'public' => true,
  178. 'stale_while_revalidate' => 30,
  179. 'stale_if_error' => null,
  180. 'invalidation' => [
  181. 'urls' => [],
  182. 'scoped_clients' => [],
  183. 'max_header_length' => 7500,
  184. 'request_options' => [],
  185. 'purger' => ApiPlatform\HttpCache\SouinPurger::class,
  186. ],
  187. ],
  188. 'key_rotation_policy' => [
  189. 'enabled' => true,
  190. 'expiration_months' => env('API_KEY_EXPIRATION_MONTHS', 12),
  191. 'transition_days' => env('API_KEY_TRANSITION_DAYS', 7),
  192. 'cleanup_days' => env('API_KEY_CLEANUP_DAYS', 90),
  193. 'cache_ttl' => env('API_KEY_CACHE_TTL', 3600),
  194. 'storefront_key_prefix' => env('STOREFRONT_KEY_PREFIX', 'pk_storefront_'),
  195. ],
  196. ];