How to use the strapi-helper-plugin.request function in strapi-helper-plugin

To help you get started, we’ve selected a few strapi-helper-plugin examples, based on popular ways it is used in public projects.

Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.

github strapi / strapi / packages / strapi-admin / admin / src / containers / AuthPage / index.js View on Github external
const handleSubmit = async e => {
    e.preventDefault();
    const schema = forms[authType].schema;
    let formErrors = {};

    try {
      await schema.validate(modifiedData, { abortEarly: false });

      try {
        if (modifiedData.news === true) {
          await request('https://analytics.strapi.io/register', {
            method: 'POST',
            body: omit(modifiedData, ['password', 'confirmPassword']),
            signal,
          });
        }
      } catch (err) {
        // Do nothing
      }

      try {
        const requestEndPoint = forms[authType].endPoint;
        const requestURL = `/admin/auth/${requestEndPoint}`;
        const body = omit(modifiedData, 'news');

        if (authType === 'forgot-password') {
          set(body, 'url', `${strapi.remoteURL}/auth/reset-password`);
github strapi / strapi / packages / strapi-admin / admin / src / containers / AuthPage / index.js View on Github external
});
        }
      } catch (err) {
        // Do nothing
      }

      try {
        const requestEndPoint = forms[authType].endPoint;
        const requestURL = `/admin/auth/${requestEndPoint}`;
        const body = omit(modifiedData, 'news');

        if (authType === 'forgot-password') {
          set(body, 'url', `${strapi.remoteURL}/auth/reset-password`);
        }

        const { jwt, user, ok } = await request(requestURL, {
          method: 'POST',
          body,
          signal,
        });

        if (authType === 'forgot-password' && ok === true) {
          dispatch({
            type: 'SUBMIT_SUCCESS',
            email: modifiedData.email,
          });
        } else {
          auth.setToken(jwt, modifiedData.rememberMe);
          auth.setUserInfo(user, modifiedData.rememberMe);
        }
      } catch (err) {
        const formattedError = formatErrorFromRequest(err);
github strapi / strapi / packages / strapi-plugin-content-manager / admin / src / containers / EditViewDataManagerProvider / index.js View on Github external
files.forEach(file => {
          formData.append(`files.${key}`, file);
        });
      });

      // Change the request helper default headers so we can pass a FormData
      const headers = {};
      const method = isCreatingEntry ? 'POST' : 'PUT';
      const endPoint = isCreatingEntry ? slug : `${slug}/${id}`;

      emitEvent(isCreatingEntry ? 'willCreateEntry' : 'willEditEntry');

      try {
        // Time to actually send the data
        await request(
          getRequestUrl(endPoint),
          {
            method,
            headers,
            body: formData,
            signal,
          },
          false,
          false
        );
        emitEvent(isCreatingEntry ? 'didCreateEntry' : 'didEditEntry');
        dispatch({
          type: 'SUBMIT_SUCCESS',
        });
        redirectToPreviousPage();
      } catch (err) {
github strapi / strapi / packages / strapi-plugin-content-manager / admin / src / containers / EditView / index.js View on Github external
Object.keys(filesToUpload).forEach(key => {
        const files = filesToUpload[key];

        files.forEach(file => {
          formData.append(`files.${key}`, file);
        });
      });

      // Change the request helper default headers so we can pass a FormData
      const headers = {};
      const method = isCreatingEntry ? 'POST' : 'PUT';
      const endPoint = isCreatingEntry ? slug : `${slug}/${id}`;

      try {
        // Time to actually send the data
        await request(
          getRequestUrl(endPoint),
          {
            method,
            headers,
            params: { source },
            body: formData,
            signal,
          },
          false,
          false
        );
        emitEvent('didSaveEntry');
        redirectToPreviousPage();
      } catch (err) {
        const error = get(
          err,
github strapi / strapi / packages / strapi-plugin-content-manager / admin / src / lifecycles / didGetSecuredData.js View on Github external
async function didGetSecuredData() {
  const { updatePlugin } = this.props;
  const requestURL = `/${pluginId}/models`;

  try {
    const {
      models: { models },
    } = await request(requestURL, { method: 'GET' });
    const menu = [
      {
        name: 'Content Types',
        links: map(omit(models, 'plugins'), (model, key) => ({
          label: model.labelPlural || model.label || key,
          destination: key,
        })),
      },
    ];

    updatePlugin(pluginId, 'leftMenuSections', menu);
  } catch (err) {
    strapi.notification.error('content-manager.error.model.fetch');
  }
}
github strapi / strapi / packages / strapi-plugin-content-type-builder / admin / src / containers / DataManagerProvider / index.js View on Github external
const updateAppMenu = async () => {
    const requestURL = '/content-manager/content-types';

    try {
      const { data } = await request(requestURL, { method: 'GET' });

      const menu = [{ name: 'Content Types', links: data }];

      updatePlugin('content-manager', 'leftMenuSections', menu);
    } catch (err) {
      console.error({ err });
      strapi.notification.error('notification.error');
    }
  };
github strapi / strapi / packages / strapi-plugin-settings-manager / admin / src / containers / ConfigPage / index.js View on Github external
const handleSubmit = async e => {
    e.preventDefault();
    let formErrors = {};
    const schema = forms[slug].schema;

    try {
      await schema.validate(modifiedData, { abortEarly: false });

      if (!isEmpty(body)) {
        try {
          await request(
            `/${pluginId}/${endPoint}`,
            { method: 'PUT', body, params: { source: 'db' } },
            true
          );
          emitEvent('willEditSettings', { category: endPoint });
          dispatch({
            type: 'SUBMIT_SUCCEEDED',
          });
          strapi.notification.success(
            getTrad('strapi.notification.success.settingsEdit')
          );
        } catch (err) {
          strapi.notification.error('notification.error');
        }
      }
    } catch (err) {
github strapi / strapi / packages / strapi-plugin-content-manager / admin / src / containers / EditSettingsView / index.js View on Github external
const getData = async () => {
      try {
        const { data } = await request(
          getRequestUrl(`${type}/${slug || componentSlug}`),
          {
            method: 'GET',
            signal,
          }
        );

        dispatch({
          type: 'GET_DATA_SUCCEEDED',
          data: data.contentType || data.component,
          componentLayouts: data.components,
        });
      } catch (err) {
        if (err.code !== 20) {
          strapi.notification.error('notification.error');
        }
github strapi / strapi / packages / strapi-admin / admin / src / containers / App / index.js View on Github external
const getData = async () => {
      try {
        const requestURL = '/users-permissions/init';

        const { hasAdmin } = await request(requestURL, { method: 'GET' });
        const { data } = await request('/admin/init', { method: 'GET' });
        const { uuid } = data;

        if (uuid) {
          await fetch('https://analytics.strapi.io/track', {
            method: 'POST',
            body: JSON.stringify({
              event: 'didInitializeAdministration',
              uuid,
            }),
            headers: {
              'Content-Type': 'application/json',
            },
          });
        }

        getDataRef.current(hasAdmin, data);
github strapi / strapi / packages / strapi-plugin-settings-manager / admin / src / containers / LanguagePage / index.js View on Github external
const handleClick = async lang => {
    try {
      const locale = findLangTrad(lang);

      await request(
        `/${pluginId}/configurations/i18n`,
        { method: 'PUT', body: { 'language.defaultLocale': locale.value } },
        true
      );
      setShouldRefetch(prev => !prev);
    } catch (err) {
      strapi.notification.error('notification.error');
    }
  };
  const handleDeleteLanguage = async () => {