How to use @commercetools-frontend/sdk - 10 common examples

To help you get started, we’ve selected a few @commercetools-frontend/sdk 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 commercetools / merchant-center-application-kit / packages / application-shell / src / configure-store.js View on Github external
const mergeObjectValues = object =>
  Object.entries(object).reduce((acc, [, value]) => ({ ...acc, ...value }), {});

const patchedGetCorrelationId = () =>
  getCorrelationId({
    userId: selectUserId({ apolloCache: apolloClient }),
  });

const createInternalReducer = (injectedReducers = {}) =>
  combineReducers({
    requestsInFlight: requestsInFlightReducer,
    notifications: notificationsReducer,
    ...injectedReducers,
  });

const sdkMiddleware = createSdkMiddleware({
  getCorrelationId: patchedGetCorrelationId,
  getProjectKey: selectProjectKeyFromUrl,
  getTeamId: selectTeamIdFromLocalStorage,
});

export const applyDefaultMiddlewares = (...middlewares) =>
  applyMiddleware(...middlewares, thunk, loggerMiddleware);

// We use a factory as it's more practicable for tests
// The application can import the configured store (the default export)
export const createReduxStore = (
  preloadedState = { requestsInFlight: null },
  // additional middleware, used for testing
  additionalMiddlewares = []
) => {
  const store = createStore(
github commercetools / merchant-center-application-kit / packages / application-shell / src / test-utils / test-utils.js View on Github external
const reduxStore = (() => {
    if (store) return store;

    if (sdkMocks.length === 0) return createReduxStore(storeState);

    const testingMiddleware = createSdkTestMiddleware(sdkMocks);
    return createReduxStore(storeState, [testingMiddleware]);
  })();
github commercetools / merchant-center-application-kit / playground / src / components / channels-list-connector / channels-list-connector.spec.js View on Github external
it('should pass action creator args to <Sdk.Get>', () => {
    expect(wrapper.find(Sdk.Get)).toHaveProp('actionCreatorArgs', [
      { perPage: 25, page: 1 },
    ]);
  });
});
github commercetools / merchant-center-application-kit / packages / application-shell / src / components / performance-timing / actions.js View on Github external
export const pushMetricHistogram = ({ payload }) =>
  sdkActions.post({
    uri: '/metrics/histograms',
    mcApiProxyTarget: MC_API_PROXY_TARGETS.MC_METRICS,
    payload: JSON.stringify(payload),
  });
github commercetools / merchant-center-application-kit / packages / application-shell / src / components / login / login.js View on Github external
requestAccessToken: payload =>
    dispatch(sdkActions.post({ uri: `/tokens`, payload })),
});
github commercetools / merchant-center-application-kit / packages / application-shell / src / components / version-tracker / actions.js View on Github external
export const pushDependencyVersionCounter = ({ payload }) =>
  sdkActions.post({
    uri: '/metrics/counters',
    mcApiProxyTarget: MC_API_PROXY_TARGETS.MC_METRICS,
    payload: JSON.stringify(payload),
  });
github commercetools / merchant-center-application-kit / packages / application-shell / src / components / quick-access / quick-access.js View on Github external
pimSearchProductIds: searchText =>
      dispatch(
        sdkActions.post({
          uri: `/${ownProps.applicationContext.project.key}/search/products`,
          mcApiProxyTarget: MC_API_PROXY_TARGETS.PIM_SEARCH,
          payload: {
            query: {
              fullText: {
                field: 'name',
                language: ownProps.applicationContext.dataLocale,
                value: searchText,
              },
            },
            sort: [
              {
                field: 'name',
                language: ownProps.applicationContext.dataLocale,
                order: 'desc',
              },
github commercetools / merchant-center-application-kit / playground / src / components / state-machines-list-connector / actions.js View on Github external
export const fetchStateMachines = requestOptions =>
  sdkActions.get({
    mcApiProxyTarget: MC_API_PROXY_TARGETS.COMMERCETOOLS_PLATFORM,
    service: 'states',
    options: requestOptions,
  });