PlatformWebhooks.utils.ts 929 B

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849
  1. import type { WebhookEndpoint } from './PlatformWebhooks.types'
  2. const WEBHOOK_NAME_ADJECTIVES = [
  3. 'swift',
  4. 'winged',
  5. 'wayfinding',
  6. 'moonlit',
  7. 'fleet',
  8. 'nimble',
  9. 'roving',
  10. 'brisk',
  11. 'gliding',
  12. 'steady',
  13. 'northbound',
  14. 'starlit',
  15. 'quiet',
  16. 'amber',
  17. 'far-flung',
  18. 'secret',
  19. 'flying',
  20. ]
  21. const WEBHOOK_NAME_NOUNS = [
  22. 'pigeon',
  23. 'courier',
  24. 'postmark',
  25. 'relay',
  26. 'dispatch',
  27. 'lantern',
  28. 'beacon',
  29. 'messenger',
  30. 'waypost',
  31. 'sparrow',
  32. 'satchel',
  33. 'signalfire',
  34. 'envelope',
  35. 'parcel',
  36. 'gull',
  37. 'kite',
  38. 'beagle',
  39. ]
  40. const getRandomItem = (values: string[]) => values[Math.floor(Math.random() * values.length)]
  41. export const generateWebhookEndpointName = () =>
  42. `${getRandomItem(WEBHOOK_NAME_ADJECTIVES)}-${getRandomItem(WEBHOOK_NAME_NOUNS)}`
  43. export const getWebhookEndpointDisplayName = (endpoint: Pick<WebhookEndpoint, 'name' | 'url'>) =>
  44. endpoint.name.trim() || endpoint.url