updateDynamicSdkLoaderOptions.ts 1.5 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950
  1. import type {Client} from 'sentry/api';
  2. import {ProductSolution} from 'sentry/components/onboarding/productSelection';
  3. import {t} from 'sentry/locale';
  4. import type {Organization} from 'sentry/types/organization';
  5. import type {Project, ProjectKey} from 'sentry/types/project';
  6. import {handleXhrErrorResponse} from 'sentry/utils/handleXhrErrorResponse';
  7. export async function updateDynamicSdkLoaderOptions({
  8. orgSlug,
  9. projectSlug,
  10. products,
  11. api,
  12. projectKey,
  13. }: {
  14. api: Client;
  15. orgSlug: Organization['slug'];
  16. projectKey: ProjectKey['id'];
  17. projectSlug: Project['slug'];
  18. products?: ProductSolution[];
  19. }) {
  20. const newDynamicSdkLoaderOptions: ProjectKey['dynamicSdkLoaderOptions'] = {
  21. hasPerformance: false,
  22. hasReplay: false,
  23. hasDebug: false,
  24. };
  25. (products ?? []).forEach(product => {
  26. // eslint-disable-next-line default-case
  27. switch (product) {
  28. case ProductSolution.PERFORMANCE_MONITORING:
  29. newDynamicSdkLoaderOptions.hasPerformance = true;
  30. break;
  31. case ProductSolution.SESSION_REPLAY:
  32. newDynamicSdkLoaderOptions.hasReplay = true;
  33. break;
  34. }
  35. });
  36. try {
  37. await api.requestPromise(`/projects/${orgSlug}/${projectSlug}/keys/${projectKey}/`, {
  38. method: 'PUT',
  39. data: {
  40. dynamicSdkLoaderOptions: newDynamicSdkLoaderOptions,
  41. },
  42. });
  43. } catch (error) {
  44. const message = t('Unable to dynamically update the SDK loader configuration');
  45. handleXhrErrorResponse(message, error);
  46. }
  47. }