api-platform-vendor.php 8.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231
  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. 'Webkul\BagistoApi\Http\Middleware\PaginationHeaders',
  42. 'Spatie\ResponseCache\Middlewares\CacheResponse',
  43. ],
  44. ],
  45. 'resources' => [
  46. base_path('vendor/bagisto/bagisto-api/src/Models/'),
  47. base_path('vendor/bagisto/bagisto-api/src/Dto/ProductDetail/'),
  48. base_path('vendor/bagisto/bagisto-api/src/Dto/CustomerOrder/'),
  49. ],
  50. 'formats' => [
  51. 'json'=> ['application/json'],
  52. ],
  53. 'patch_formats' => [
  54. 'json' => ['application/merge-patch+json'],
  55. ],
  56. 'docs_formats' => [
  57. 'jsonopenapi' => ['application/vnd.openapi+json'],
  58. 'html' => ['text/html'],
  59. ],
  60. 'error_formats' => [
  61. 'jsonproblem' => ['application/problem+json'],
  62. ],
  63. 'defaults' => [
  64. 'pagination_enabled' => true,
  65. 'pagination_partial' => false,
  66. 'pagination_client_enabled' => false,
  67. 'pagination_client_items_per_page' => true,
  68. 'pagination_client_partial' => false,
  69. 'pagination_items_per_page' => 10,
  70. 'pagination_maximum_items_per_page' => 50,
  71. 'route_prefix' => '/api',
  72. 'middleware' => [],
  73. ],
  74. 'pagination' => [
  75. 'page_parameter_name' => 'page',
  76. 'enabled_parameter_name' => 'pagination',
  77. 'items_per_page_parameter_name' => 'per_page',
  78. 'partial_parameter_name' => 'partial',
  79. ],
  80. 'graphql' => [
  81. 'enabled' => true,
  82. 'nesting_separator' => '__',
  83. 'introspection' => ['enabled' => true],
  84. 'max_query_complexity' => 400,
  85. 'max_query_depth' => 20,
  86. 'graphiql' => [
  87. 'enabled' => true,
  88. 'default_query' => null,
  89. 'default_variables' => null,
  90. ],
  91. 'graphql_playground' => [
  92. 'enabled' => true,
  93. 'default_query' => null,
  94. 'default_variables' => null,
  95. ],
  96. // GraphQL middleware for authentication and rate limiting
  97. 'middleware' => [
  98. 'Webkul\BagistoApi\Http\Middleware\VerifyGraphQLStorefrontKey',
  99. ],
  100. ],
  101. 'graphiql' => [
  102. 'enabled' => true,
  103. ],
  104. 'name_converter' => SnakeCaseToCamelCaseNameConverter::class,
  105. 'path_segment_name_generator' => DashPathSegmentNameGenerator::class,
  106. 'exception_to_status' => [
  107. AuthenticationException::class => 401,
  108. AuthorizationException::class => 403,
  109. ValidationException::class => 400,
  110. InvalidInputException::class => 400,
  111. ],
  112. 'swagger_ui' => [
  113. 'enabled' => true,
  114. 'apiKeys' => [
  115. 'api' => [
  116. 'name' => 'Authorization',
  117. 'type' => 'header',
  118. 'scheme' => 'bearer',
  119. ],
  120. ],
  121. ],
  122. 'url_generation_strategy' => UrlGeneratorInterface::ABS_PATH,
  123. 'serializer' => [
  124. 'hydra_prefix' => false,
  125. 'datetime_format' => 'Y-m-d\TH:i:sP',
  126. ],
  127. 'cache' => 'redis',
  128. 'schema_cache' => [
  129. 'enabled' => true,
  130. 'store' => 'redis',
  131. ],
  132. 'security' => [
  133. 'sanctum' => true,
  134. ],
  135. 'rate_limit' => [
  136. 'skip_localhost' => env('RATE_LIMIT_SKIP_LOCALHOST', true),
  137. 'auth' => env('RATE_LIMIT_AUTH', 5),
  138. 'admin' => env('RATE_LIMIT_ADMIN', 60),
  139. 'shop' => env('RATE_LIMIT_SHOP', 100),
  140. 'graphql' => env('RATE_LIMIT_GRAPHQL', 100),
  141. 'cache_driver' => env('RATE_LIMIT_CACHE', 'redis'),
  142. 'cache_prefix' => 'api:rate-limit:',
  143. ],
  144. 'security_headers' => [
  145. 'enabled' => true,
  146. 'force_https' => env('APP_FORCE_HTTPS', false),
  147. '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'",
  148. ],
  149. 'api_logging' => [
  150. 'enabled' => env('API_LOG_ENABLED', true),
  151. 'log_sensitive_data' => env('API_LOG_SENSITIVE_DATA', false),
  152. 'exclude_paths' => ['docs', 'graphiql', 'swagger-ui', 'docs.json'],
  153. 'channel' => 'api',
  154. 'async' => env('API_LOG_ASYNC', true),
  155. 'queue' => env('API_LOG_QUEUE', 'api-logs'),
  156. ],
  157. 'graphql_validation' => [
  158. 'max_depth' => env('GRAPHQL_MAX_DEPTH', 10),
  159. 'max_complexity' => env('GRAPHQL_MAX_COMPLEXITY', 300),
  160. ],
  161. 'request_limits' => [
  162. 'max_size_mb' => env('MAX_REQUEST_SIZE', 10),
  163. 'max_pagination_limit' => env('MAX_PAGINATION_LIMIT', 100),
  164. ],
  165. 'database' => [
  166. 'log_queries' => env('DB_QUERY_LOG_ENABLED', false),
  167. 'slow_query_threshold' => env('DB_SLOW_QUERY_THRESHOLD', 1000),
  168. ],
  169. 'caching' => [
  170. 'enable_security_cache' => env('API_SECURITY_CACHE', true),
  171. 'security_cache_ttl' => env('API_SECURITY_CACHE_TTL', 3600),
  172. 'enable_response_cache' => env('API_RESPONSE_CACHE', true),
  173. 'response_cache_ttl' => env('API_RESPONSE_CACHE_TTL', 3600),
  174. ],
  175. 'http_cache' => [
  176. 'etag' => true,
  177. 'max_age' => 3600,
  178. 'shared_max_age' => null,
  179. 'vary' => null,
  180. 'public' => true,
  181. 'stale_while_revalidate' => 30,
  182. 'stale_if_error' => null,
  183. 'invalidation' => [
  184. 'urls' => [],
  185. 'scoped_clients' => [],
  186. 'max_header_length' => 7500,
  187. 'request_options' => [],
  188. 'purger' => ApiPlatform\HttpCache\SouinPurger::class,
  189. ],
  190. ],
  191. 'key_rotation_policy' => [
  192. 'enabled' => true,
  193. 'expiration_months' => env('API_KEY_EXPIRATION_MONTHS', 12),
  194. 'transition_days' => env('API_KEY_TRANSITION_DAYS', 7),
  195. 'cleanup_days' => env('API_KEY_CLEANUP_DAYS', 90),
  196. 'cache_ttl' => env('API_KEY_CACHE_TTL', 3600),
  197. 'storefront_key_prefix' => env('STOREFRONT_KEY_PREFIX', 'pk_storefront_'),
  198. ],
  199. ];