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 🙏

© 2025 – Pkg Stats / Ryan Hefner

@codeparticle/strapi-plugin-app-search

v1.1.1

Published

App Search integration for strapi

Readme

Strapi Plugin App Search

To run this plugin it must be installed into a strapi application.

Usage

Install in any strapi application pnpm add strapi-plugin-app-search Then add the proper config to config/hook.js Example:

module.exports = ({ env }) => ({
  settings: {
    'strapi-app-search': {
      enabled: true,
      applicationId: '0000000000',
      apiEndpoint: 'https://123.ent-search.us-east-2.aws.elastic-cloud.com/api/as/v1/',
      apiKey: 'asdfihweq123125432',
      debug: env('DEBUG_APP_SEARCH', false),
      formatIndex: (apiName, env) => `${apiName}-${env}`,
      apisToSync: [
        {
          name: 'api::content-type.content-type',
          indexName: 'es-index-name',
          processEsObj: (obj) => ({ ...obj, newProp: true }),
          populate: ['relation'],
        },
      ]
    }
  }
});

processEsObj is used to format the object before saving

You can also choose to individually upload the content type entries to App Search after creating instead of using the Sync button in the App Search plugin home page. Example: src/api/content-type/content-types/content-type/lifecycles.js

/**
 * Lifecycle callbacks for the `content-type` model.
 */

const APP_SEARCH_ENGINE = `content-type-${strapi.config.environment}`;

const saveAppSearchObj = (model) => {
  const { apisToSync } = getConfig();
  const apiToSync = (apisToSync || []).find(({ name }) => name === `content-type`);
  const indexName = getIndex(model.locale);

  if (strapi.appSearch) {
    strapi.appSearch.saveObject(apiToSync && apiToSync.processEsObj ? apiToSync.processEsObj(model) : model, indexName);
  }
}

const shouldUseAppSearch = () => {
  const { modelsToIgnore = [] } = getConfig();

  return !modelsToIgnore.includes(MODEL_NAME);
}

const getIds = (params, ids = []) => {
  if (!params || typeof params !== 'object') {
    return ids;
  }

  if (Array.isArray(params)) {
    params.forEach((item) => getIds(item, ids));
    return ids;
  }

  Object.entries(params).forEach(([key, entry]) => {
    if (key === 'id') {
      if (typeof entry !== 'object') {
        ids.push(entry);
      } else if (entry['$in']) {
        ids.push(...entry['$in']);
      }
    } else {
      getIds(entry, ids);
    }
  });

  return ids;
};

module.exports = {
  async afterCreate({ result }) {
    if (shouldUseAppSearch()) {
      saveAppSearchObj({ ...result });
    }
  },

  async afterUpdate({ result }) {
    if (shouldUseAppSearch()) {
      saveAppSearchObj({ ...result });
    }
  },

  async afterUpdateMany({ params }) {
    const ids = getIds(params);
    const service = strapi.service('api::report.report');

    if (shouldUseAppSearch()) {
      service.find({ filters: { id: { $in: ids } }, populate: [] }).then(({ results }) => {
        results.forEach((entry) => {
          saveAppSearchObj({ ...entry });
        });
      });
    }
  },

  async afterDelete({ result }) {
    if (shouldUseAppSearch()) {
      strapi.appSearch.deleteObject(result.id, getIndex(result.locale));
    }
  },

  async beforeDeleteMany({ params, state }) {
    const ids = getIds(params);
    const knex = strapi.db.connection;

    state.ids = ids;

    state.entries = await knex
      .select('id', 'locale')
      .from('report')
      .where('id', 'in', ids);
  },

  async afterDeleteMany({ state }) {
    const { ids, entries } = state;

    if (shouldUseAppSearch()) {
      ids.forEach((id) => {
        const entry = entries.find(({ id: entryId }) => entryId === id);
        strapi.appSearch.deleteObject(id, getIndex(entry?.locale));
      });
    }
  }
};

Dev

You need to create a new strapi project or just use an existing example one:

pnpm dev

Publishing

Publishing should already be setup. Just follow these steps to publish the project:

  • After code merged to main/master
  • Checkout the main/master branch
  • Run pnpm version [patch|minor|major]
  • Push to remote with git push --tags to trigger the tag pipeline