{"id":18463843,"url":"https://github.com/smartive/datocms-utils","last_synced_at":"2026-02-15T16:13:10.057Z","repository":{"id":258465178,"uuid":"862912340","full_name":"smartive/datocms-utils","owner":"smartive","description":"A set of utilities and helpers to work with DatoCMS in a Next.js project.","archived":false,"fork":false,"pushed_at":"2026-02-06T01:10:29.000Z","size":744,"stargazers_count":1,"open_issues_count":0,"forks_count":0,"subscribers_count":5,"default_branch":"main","last_synced_at":"2026-02-06T11:12:25.492Z","etag":null,"topics":[],"latest_commit_sha":null,"homepage":null,"language":"TypeScript","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":"mit","status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/smartive.png","metadata":{"files":{"readme":"README.md","changelog":null,"contributing":null,"funding":null,"license":"LICENSE","code_of_conduct":null,"threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":null,"support":null,"governance":null,"roadmap":null,"authors":null,"dei":null,"publiccode":null,"codemeta":null,"zenodo":null,"notice":null,"maintainers":null,"copyright":null,"agents":null,"dco":null,"cla":null}},"created_at":"2024-09-25T11:57:50.000Z","updated_at":"2026-02-06T01:10:32.000Z","dependencies_parsed_at":"2024-12-08T22:25:16.125Z","dependency_job_id":"13cb0e94-4e5f-4478-8636-02b03e87f469","html_url":"https://github.com/smartive/datocms-utils","commit_stats":null,"previous_names":["smartive/datocms-utils"],"tags_count":17,"template":false,"template_full_name":null,"purl":"pkg:github/smartive/datocms-utils","repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/smartive%2Fdatocms-utils","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/smartive%2Fdatocms-utils/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/smartive%2Fdatocms-utils/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/smartive%2Fdatocms-utils/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/smartive","download_url":"https://codeload.github.com/smartive/datocms-utils/tar.gz/refs/heads/main","sbom_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/smartive%2Fdatocms-utils/sbom","scorecard":null,"host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":286080680,"owners_count":29367827,"icon_url":"https://github.com/github.png","version":null,"created_at":"2022-05-30T11:31:42.601Z","updated_at":"2026-02-12T08:51:36.827Z","status":"ssl_error","status_checked_at":"2026-02-12T08:51:26.849Z","response_time":55,"last_error":"SSL_read: unexpected eof while reading","robots_txt_status":"success","robots_txt_updated_at":"2025-07-24T06:49:26.215Z","robots_txt_url":"https://github.com/robots.txt","online":false,"can_crawl_api":true,"host_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub","repositories_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories","repository_names_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repository_names","owners_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners"}},"keywords":[],"created_at":"2024-11-06T09:08:07.923Z","updated_at":"2026-02-12T15:08:03.603Z","avatar_url":"https://github.com/smartive.png","language":"TypeScript","funding_links":[],"categories":[],"sub_categories":[],"readme":"# smartive DatoCMS Utilities\n\nA set of utilities and helpers to work with DatoCMS in a Next.js project.\n\n## Installation\n\n```bash\nnpm install @smartive/datocms-utils\n```\n\n## Usage\n\nImport and use the utilities you need in your project. The following utilities are available.\n\n## Utilities\n\n### Utilities for DatoCMS Cache Tags\n\nThe following utilities are used to work with [DatoCMS cache tags](https://www.datocms.com/docs/content-delivery-api/cache-tags) and a [Vercel Postgres database](https://vercel.com/docs/storage/vercel-postgres).\n\n- `storeQueryCacheTags`: Stores the cache tags of a query in the database.\n- `queriesReferencingCacheTags`: Retrieves the queries that reference cache tags.\n- `deleteQueries`: Deletes the cache tags of a query from the database.\n\n#### Setup Postgres database\n\nIn order for the above utilites to work, you need to setup a the following database. You can use the following SQL script to do that:\n\n```sql\nCREATE TABLE IF NOT EXISTS query_cache_tags (\n  query_id TEXT NOT NULL,\n  cache_tag TEXT NOT NULL,\n  PRIMARY KEY (query_id, cache_tag)\n);\n```\n\n### Utilities for DatoCMS Cache Tags (Redis)\n\nThe following utilities provide Redis-based alternatives to the Postgres cache tags implementation above. They work with [DatoCMS cache tags](https://www.datocms.com/docs/content-delivery-api/cache-tags) and any Redis instance.\n\n- `redis.storeQueryCacheTags`: Stores the cache tags of a query in Redis.\n- `redis.queriesReferencingCacheTags`: Retrieves the queries that reference cache tags.\n- `redis.deleteCacheTags`: Deletes cache tags from Redis.\n- `redis.truncateCacheTags`: Wipes out all cache tags from Redis.\n\nThe Redis connection is automatically initialized on first use using the `REDIS_URL` environment variable.\n\n#### Environment Variables\n\nAdd your Redis connection URL to your `.env.local` file:\n\n```bash\n# Required: Redis connection URL\n# For Upstash Redis\nREDIS_URL=rediss://default:your-token@your-endpoint.upstash.io:6379\n\n# For Redis Cloud or other providers\nREDIS_URL=redis://username:password@your-redis-host:6379\n\n# For local development\nREDIS_URL=redis://localhost:6379\n\n# Optional: Key prefix for separating production/preview environments\n# Useful when using the same Redis instance for multiple environments\nREDIS_KEY_PREFIX=prod        # For production\nREDIS_KEY_PREFIX=preview     # For preview/staging\n# Leave empty for development (no prefix)\n```\n\n**Note**: Similar to how the Postgres version uses different table names, use `REDIS_KEY_PREFIX` to separate data between environments when using the same Redis instance.\n\n#### Usage Example\n\n```typescript\n// Recommended: Use namespaces for clarity\nimport { generateQueryId, redis } from '@smartive/datocms-utils';\n\nconst queryId = generateQueryId(query, variables);\n\n// Store cache tags for a query\nawait redis.storeQueryCacheTags(queryId, ['item:42', 'product', 'category:5']);\n\n// Find all queries that reference specific tags\nconst affectedQueries = await redis.queriesReferencingCacheTags(['item:42']);\n\n// Delete cache tags (keys will be recreated on next query)\nawait redis.deleteCacheTags(['item:42']);\n```\n\n#### Redis Data Structure\n\nThe Redis implementation uses Sets to track query-to-tag relationships:\n\n- **Cache tag keys**: `{prefix}{tag}` → Set of query IDs\n\nWhere `{prefix}` is the optional `REDIS_KEY_PREFIX` environment variable (e.g., `prod:`, `preview:`).\n\nWhen cache tags are invalidated, their keys are deleted entirely. Fresh mappings are created when queries run again.\n\n### Other Utilities\n\n- `classNames`: Cleans and joins an array of inputs with possible undefined or boolean values. Useful for tailwind classnames.\n- `getTelLink`: Formats a phone number to a tel link.\n\n### Types\n\n- `CacheTag`: A branded type for cache tags.\n- `CacheTagsInvalidateWebhook`: The payload of the DatoCMS cache tags invalidate webhook.\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fsmartive%2Fdatocms-utils","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fsmartive%2Fdatocms-utils","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fsmartive%2Fdatocms-utils/lists"}