npm package discovery and stats viewer.

Discover Tips

  • General search

    [free text search, go nuts!]

  • Package details

    pkg:[package-name]

  • User packages

    @[username]

Sponsor

Optimize Toolset

I’ve always been into building performant and accessible sites, but lately I’ve been taking it extremely seriously. So much so that I’ve been building a tool to help me optimize and monitor the sites that I build to make sure that I’m making an attempt to offer the best experience to those who visit them. If you’re into performant, accessible and SEO friendly sites, you might like it too! You can check it out at Optimize Toolset.

About

Hi, 👋, I’m Ryan Hefner  and I built this site for me, and you! The goal of this site was to provide an easy way for me to check the stats on my npm packages, both for prioritizing issues and updates, and to give me a little kick in the pants to keep up on stuff.

As I was building it, I realized that I was actually using the tool to build the tool, and figured I might as well put this out there and hopefully others will find it to be a fast and useful way to search and browse npm packages as I have.

If you’re interested in other things I’m working on, follow me on Twitter or check out the open source projects I’ve been publishing on GitHub.

I am also working on a Twitter bot for this site to tweet the most popular, newest, random packages from npm. Please follow that account now and it will start sending out packages soon–ish.

Open Software & Tools

This site wouldn’t be possible without the immense generosity and tireless efforts from the people who make contributions to the world and share their work via open source initiatives. Thank you 🙏

© 2024 – Pkg Stats / Ryan Hefner

@egym/mwa-logger

v0.2.9

Published

The screen logger component that can capture and display request/response data exchanged between web and native apps.

Downloads

177

Readme

lib-mwa-logger

The screen logger component that can capture and display request/response data exchanged between web and native apps.

Install

npm install @egym/mwa-logger --save

Components:

<EgymMwaDevtools />

<EgymMwaDevtools /> responsible for collection of different log messages and displaying them.

type Props = {
  position?: 'top-left' | 'top-right' | 'bottom-left' | 'bottom-right';
  wrapperStyle?: CSSProperties;
  buttonStyle?: CSSProperties;
  ciConfig?: CIConfig;
};
type CIConfigItem = {
  value: string;
  description: string;
}

export type CIConfig = {
  appId: CIConfigItem,
  appName: CIConfigItem,
  gitCommitSha: CIConfigItem,
  gitCommitMsg: CIConfigItem,
  gitRef: CIConfigItem,
  gitRefType: CIConfigItem,
  isAutomatedBuild: CIConfigItem,
  automationId: CIConfigItem,
  automationName: CIConfigItem,
  buildId: CIConfigItem,
  buildNumber: CIConfigItem,
  platform: CIConfigItem,
}

Place it at the top level of your app tree, prefferably outside component. See example:

const App: React.FC = () => {
  const [showLogger] = useStore(getShowLoggerSelector);

  return (
    <Suspense fallback={<span />}>
      {showLogger && <EgymMwaDevtools position="top-right" />}
      <I18nextProvider i18n={i18n}>
        <ErrorBoundary fallback={<ErrorFallback />}>
          <Layout />
        </ErrorBoundary>
      </I18nextProvider>
    </Suspense>
  );
};

After you add <EgymMwaDevtools /> component you will see the debug button on the screen, click it to see messages:

<ErrorBoundary />

<ErrorBoundary /> catches errors anywhere in the child component tree, log those errors as WSOD message in the dev tools window, and display a fallback UI instead of the component tree that crashed. See example:

const App: React.FC = () => {
  const [showLogger] = useStore(getShowLoggerSelector);

  return (
    <Suspense fallback={<span />}>
      {showLogger && <EgymMwaDevtools position="top-right" />}
      <I18nextProvider i18n={i18n}>
        <ErrorBoundary fallback={<ErrorFallback />}>
          <Layout />
        </ErrorBoundary>
      </I18nextProvider>
    </Suspense>
  );
};

Log functions:

logHttpRequest, logHttpResponse

Should be used in pair to display http request and it's corresponding response, provided requestId will join them in one group.

declare const logHttpRequest: (method: string, url: string, requestId: string | number, payload?: any) => void;
declare const logHttpResponse: (method: string, url: string, requestId: string | number, response?: any) => void;

See example:

 try {
  const headers = await createHeaders(baseBackendUrl);

  logHttpRequest(method, urlResult, String(requestId), {
    payload: options?.payload,
    headers,
  });

  const response = await CapacitorHttp.request({
    method,
    url: urlResult,
    data: options?.payload,
    responseType: 'json',
    headers,
  });

  return await new Promise((resolve, reject) => {
    if (response.status >= 400 && response.status < 600) {
      reject(response);
    } else {
      logHttpResponse(method, urlResult, requestId, response);
      resolve(response);
    }
  });
} catch (error) {
  logHttpResponse(method, urlResult, requestId, error);
  return Promise.reject(error);
}

logDebug

Log any random message

declare const logDebug: (text: string, data?: any) => void;

See example:

logDebug('initialContext', initialContext);

logPortalsRequest, logPortalsResponse

Log portals pub/sub messages

declare const logPortalsRequest: (topic: string, data?: any) => void;
declare const logPortalsResponse: (topic: string, data?: any) => void;

It is recommended to wrap the Portals.publish call with a custom implementation that includes a log request, so this way every publish event is captured and displayed in the logger window:

export const portalsPublish: PortalsPlugin['publish'] = async (message) => {
  logPortalsRequest(`${message.topic} ${message.data.type}`, message.data);

  await Portals.publish(message);
};

Same for Portals.subscribe:

export const portalsSubscribe = async <T>(
  options: SubscribeOptions,
  callback: SubscriptionCallback<T>
): Promise<PortalSubscription> => {
  return Portals.subscribe<T>(options, (...args) => {
    logPortalsResponse(options.topic, {
      ...options,
      ...args,
    });
    callback(...args);
  });
};

logWebWitals

export declare const logWebWitals: (metric: any) => void;

Pass this function to the reportWebVitals to log results of performance metrics src/index.tsx#77:

reportWebVitals(logWebWitals);