
Security News
vlt Launches "reproduce": A New Tool Challenging the Limits of Package Provenance
vlt's new "reproduce" tool verifies npm packages against their source code, outperforming traditional provenance adoption in the JavaScript ecosystem.
@cloak-app/algolia
Advanced tools
Record syncing generate hook and SSR components for Algolia with Nuxt.
Record syncing generate hook and SSR components for Algolia with Nuxt.
yarn add @cloak-app/algolia
nuxt.config
with buildModules: ['@cloak-app/algolia']
Set these properties within cloak: { algolia: { ... } }
in the nuxt.config.js:
appId
- Algolia app ID, defaults to process.env.ALGOLIA_APP_ID
.searchKey
- Algolia public search API key, defaults to process.env.ALGOLIA_SEARCH_KEY
.adminKey
- Algolia private admin API key, defaults to process.env.ALGOLIA_ADMIN_KEY
.syncHook
- The Nuxt lifecycle to run sync operation on. Defaults to generate:before
, a good default if you are using Algolia data during SSR. If you only use client side, change to generate:done
to prevent syncing if the generate
operation fails.sync
- An array of sync configuration rules. There shoud be an array item for each index you want to sync to. See Usage for more information..max-w*
styles (included in Cloak via whitespace.styl
)In the sync
array's simplest form, give it a simple string per index:
// nuxt.config.js
export default {
cloak: {
algolia: {
sync: ['articles'],
}
}
}
This does a couple a couple of things:
It will create an Algolia index automatically during yarn generate
that named ${env}_${site}_${name}
where env
is derived from $config.cloak.boilerplate.appEnv
and site
is derived from $config.cloak.craft.site
. For example, prod_en-US_articles
.
It will query the CMS for records matching that name. If using Craft, this means querying for all entries that have a section of articles
. The composition of these entry objects is made using a gql fragment that is expected to live at ~/queries/fragments/article.gql
. This should be the same fragment that is used to render these entries in other places on the site where they are listed. Thus, if you render these entries in some sort of card UX, the objects returned by Algolia and the objects returned by the CMS should be identical so you can directly render the card components without any massaging of Algolia data.
The sync
array also supports an expanded form, if you want to tweak any of these names.
// nuxt.config.js
import { join } from 'path'
export default {
cloak: {
algolia: {
sync: [
{
name: 'blogs',
indexName: 'prod_articles',
fragmentPath: join(__dirname, 'path/to/fragment.gql'),
section: 'blog', // Craft section type
type: 'article', // Craft entry type
// ... or completely replace the query and variables ...
// query: `query($section:[String]) {...}`,
// variables: { section: "blog", category: "..." },
// ... or fetch all your records some other way ...
// records: [{ ... }],
}
],
}
}
}
Another common pattern is merging Shopify product data with CMS product data. This can be easily accomplished with the mergeShopify
option:
// nuxt.config.js
export default {
cloak: {
algolia: {
sync: [{
name: 'products,
mergeShopify: 'products',
}],
}
}
}
This uses the @cloak-app/shopify
package to fetch products that match the CMS products, comparing CMS slugs with Shopify handles. The product
fragment is used with the Shopify data.
You can manually run the sync operation by running:
$ yarn @cloak-app/algolia
Run yarn dev
to open a Nuxt dev build of the demo directory.
To work on the record-sync module, run chmod +x ./cli.js
to make cli.js executable and then run ./cli.js demo --mock
to run the record-sync
process using the demo Nuxt environment.
FAQs
Record syncing generate hook and SSR components for Algolia with Nuxt.
The npm package @cloak-app/algolia receives a total of 1 weekly downloads. As such, @cloak-app/algolia popularity was classified as not popular.
We found that @cloak-app/algolia demonstrated a not healthy version release cadence and project activity because the last version was released a year ago. It has 6 open source maintainers collaborating on the project.
Did you know?
Socket for GitHub automatically highlights issues in each pull request and monitors the health of all your open source dependencies. Discover the contents of your packages and block harmful activity before you install or update your dependencies.
Security News
vlt's new "reproduce" tool verifies npm packages against their source code, outperforming traditional provenance adoption in the JavaScript ecosystem.
Research
Security News
Socket researchers uncovered a malicious PyPI package exploiting Deezer’s API to enable coordinated music piracy through API abuse and C2 server control.
Research
The Socket Research Team discovered a malicious npm package, '@ton-wallet/create', stealing cryptocurrency wallet keys from developers and users in the TON ecosystem.