settings-store-test-plugin.ts 2.1 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364
  1. import { Permission, SettingsStoreScopes, VendurePlugin } from '@vendure/core';
  2. /**
  3. * Test plugin that registers various settings store fields for testing different
  4. * scoping, validation, and permission scenarios.
  5. */
  6. @VendurePlugin({
  7. configuration: config => {
  8. config.settingsStoreFields = {
  9. ...config.settingsStoreFields,
  10. test: [
  11. {
  12. name: 'globalSetting',
  13. scope: SettingsStoreScopes.global,
  14. },
  15. {
  16. name: 'userSetting',
  17. scope: SettingsStoreScopes.user,
  18. },
  19. {
  20. name: 'channelSetting',
  21. scope: SettingsStoreScopes.channel,
  22. },
  23. {
  24. name: 'userAndChannelSetting',
  25. scope: SettingsStoreScopes.userAndChannel,
  26. },
  27. {
  28. name: 'readonlyField',
  29. scope: SettingsStoreScopes.global,
  30. readonly: true,
  31. },
  32. {
  33. name: 'validatedField',
  34. scope: SettingsStoreScopes.global,
  35. validate: value => {
  36. if (!['valid-option', 'another-option'].includes(value)) {
  37. return 'Value must be valid-option or another-option';
  38. }
  39. },
  40. },
  41. {
  42. name: 'complexData',
  43. scope: SettingsStoreScopes.global,
  44. },
  45. {
  46. name: 'bulk1',
  47. scope: SettingsStoreScopes.global,
  48. },
  49. {
  50. name: 'bulk2',
  51. scope: SettingsStoreScopes.global,
  52. },
  53. {
  54. name: 'adminOnlyField',
  55. scope: SettingsStoreScopes.global,
  56. requiresPermission: Permission.CreateAdministrator,
  57. },
  58. ],
  59. };
  60. return config;
  61. },
  62. })
  63. export class SettingsStoreTestPlugin {}