@nuxtjs/sanity
Advanced tools
Comparing version 0.7.1 to 0.8.0
@@ -0,1 +1,22 @@ | ||
## [0.8.0](https://github.com/nuxt-community/sanity-module/compare/0.7.1...0.8.0) (2021-03-31) | ||
### ⚠ BREAKING CHANGES | ||
* `@nuxtjs/sanity/module` is now how the module should be imported in `nuxt.config` | ||
### Features | ||
* support sanity `apiVersion` option ([6a2c956](https://github.com/nuxt-community/sanity-module/commit/6a2c9569f079bdce222dbcd9c37fefec0c40866d)) | ||
### Bug Fixes | ||
* add entrypoint for pre-exports support ([a053822](https://github.com/nuxt-community/sanity-module/commit/a053822dfee85ae4b9ffd129a67a01b2faa988ec)) | ||
### Code Refactoring | ||
* change how library is imported ([#101](https://github.com/nuxt-community/sanity-module/issues/101)) ([21c4fa9](https://github.com/nuxt-community/sanity-module/commit/21c4fa9c30edc7a9b5601b1d8529ce6f599269ae)) | ||
### [0.7.1](https://github.com/nuxt-community/sanity-module/compare/0.7.0...0.7.1) (2021-02-16) | ||
@@ -2,0 +23,0 @@ |
@@ -1,2 +0,2 @@ | ||
import { ExtendedVue } from 'vue/types/vue'; | ||
import * as vue_types_vue from 'vue/types/vue'; | ||
import * as vue_types_umd from 'vue/types/umd'; | ||
@@ -46,3 +46,3 @@ import { VueConstructor } from 'vue'; | ||
} | ||
declare const SanityContent: ExtendedVue<vue_types_umd, {}, {}, {}, { | ||
declare const SanityContent: vue_types_vue.ExtendedVue<vue_types_umd, {}, {}, {}, { | ||
blocks: (Block | CustomBlock)[]; | ||
@@ -49,0 +49,0 @@ serializers: Serializers; |
@@ -5,7 +5,7 @@ 'use strict'; | ||
const defu2 = require('defu'); | ||
const defu = require('defu'); | ||
function _interopDefaultLegacy (e) { return e && typeof e === 'object' && 'default' in e ? e : { 'default': e }; } | ||
const defu2__default = /*#__PURE__*/_interopDefaultLegacy(defu2); | ||
const defu__default = /*#__PURE__*/_interopDefaultLegacy(defu); | ||
@@ -135,3 +135,3 @@ const extendVue = (definition) => definition; | ||
render(h, {props, data}) { | ||
const serializers = defu2__default['default'](props.serializers, defaults); | ||
const serializers = defu__default['default'](props.serializers, defaults); | ||
serializers.types.list = serializers.types.list || extendVue({ | ||
@@ -138,0 +138,0 @@ name: "ListComponent", |
@@ -1,5 +0,5 @@ | ||
import { ExtendedVue } from 'vue/types/vue'; | ||
import * as vue_types_vue from 'vue/types/vue'; | ||
import * as vue_types_umd from 'vue/types/umd'; | ||
declare const SanityImage: ExtendedVue<vue_types_umd, {}, {}, {}, { | ||
declare const SanityImage: vue_types_vue.ExtendedVue<vue_types_umd, {}, {}, {}, { | ||
assetId: string; | ||
@@ -6,0 +6,0 @@ projectId: string; |
@@ -1,4 +0,33 @@ | ||
import { Module } from '@nuxt/types'; | ||
import { SanityClient } from '@sanity/client'; | ||
interface SanityModuleOptions extends Partial<SanityConfiguration> { | ||
/** | ||
* Use a micro-client that only supports making queries. | ||
* @default false | ||
*/ | ||
minimal?: boolean; | ||
/** | ||
* Register a global SanityImage component to generate correct Sanity image URLs | ||
* @default true | ||
*/ | ||
imageHelper?: boolean; | ||
/** | ||
* Register a global SanityContent component to serialize Sanity Portable Text | ||
* @default true | ||
*/ | ||
contentHelper?: boolean; | ||
/** | ||
* Don't disable `useCdn` when preview mode is on | ||
* https://nuxtjs.org/docs/2.x/features/live-preview/ | ||
* | ||
* @default false | ||
*/ | ||
disableSmartCdn?: boolean; | ||
/** | ||
* Configuration for any additional clients | ||
*/ | ||
additionalClients?: Record<string, Partial<SanityConfiguration>>; | ||
} | ||
declare const CONFIG_KEY: "sanity"; | ||
/** | ||
@@ -11,2 +40,3 @@ * Adapted from https://github.com/rexxars/picosanity | ||
dataset?: string; | ||
apiVersion: string; | ||
withCredentials?: boolean; | ||
@@ -33,33 +63,4 @@ token?: string; | ||
interface SanityModuleOptions extends Partial<SanityConfiguration> { | ||
/** | ||
* Use a micro-client that only supports making queries. | ||
* @default false | ||
*/ | ||
minimal?: boolean; | ||
/** | ||
* Register a global SanityImage component to generate correct Sanity image URLs | ||
* @default true | ||
*/ | ||
imageHelper?: boolean; | ||
/** | ||
* Register a global SanityContent component to serialize Sanity Portable Text | ||
* @default true | ||
*/ | ||
contentHelper?: boolean; | ||
/** | ||
* Don't disable `useCdn` when preview mode is on | ||
* https://nuxtjs.org/docs/2.x/features/live-preview/ | ||
* | ||
* @default false | ||
*/ | ||
disableSmartCdn?: boolean; | ||
/** | ||
* Configuration for any additional clients | ||
*/ | ||
additionalClients?: Record<string, Partial<SanityConfiguration>>; | ||
} | ||
declare const CONFIG_KEY = "sanity"; | ||
declare const HELPER_KEY = "$sanity"; | ||
declare const nuxtModule: Module<SanityModuleOptions>; | ||
declare const HELPER_KEY: `$${typeof CONFIG_KEY}`; | ||
interface Client { | ||
@@ -94,3 +95,2 @@ client: SanityClient; | ||
export default nuxtModule; | ||
export { SanityConfiguration, SanityModuleOptions, createClient, getByteSize, getQuery, groq }; | ||
export { SanityConfiguration, createClient, getByteSize, getQuery, groq }; |
@@ -1,3 +0,1 @@ | ||
import defu2 from 'defu'; | ||
const apiHost = "api.sanity.io"; | ||
@@ -14,3 +12,10 @@ const cdnHost = "apicdn.sanity.io"; | ||
function createClient(config) { | ||
const {projectId, dataset, useCdn, withCredentials, token} = config; | ||
const { | ||
useCdn, | ||
projectId, | ||
dataset, | ||
apiVersion, | ||
withCredentials, | ||
token | ||
} = config; | ||
const fetchOptions = { | ||
@@ -27,3 +32,10 @@ credentials: withCredentials ? "include" : "omit", | ||
return { | ||
clone: () => createClient({projectId, dataset, useCdn, withCredentials, token}), | ||
clone: () => createClient({ | ||
useCdn, | ||
projectId, | ||
dataset, | ||
apiVersion, | ||
withCredentials, | ||
token | ||
}), | ||
async fetch(query, params) { | ||
@@ -33,3 +45,4 @@ const qs = getQuery(query, params); | ||
const host = useCdn && !usePostRequest ? cdnHost : apiHost; | ||
const response = usePostRequest ? await fetch(`https://${projectId}.${host}/v1/data/query/${dataset}`, { | ||
const urlBase = `https://${projectId}.${host}/v${apiVersion}/data/query/${dataset}`; | ||
const response = usePostRequest ? await fetch(urlBase, { | ||
method: "post", | ||
@@ -42,3 +55,3 @@ body: JSON.stringify({query, params}), | ||
} | ||
}) : await fetch(`https://${projectId}.${host}/v1/data/query/${dataset}${qs}`, fetchOptions); | ||
}) : await fetch(`${urlBase}${qs}`, fetchOptions); | ||
const {result} = await response.json(); | ||
@@ -55,88 +68,2 @@ return result; | ||
const isNuxtBuild = process.client || process.server; | ||
const isProd = process.env.NODE_ENV === "production"; | ||
const DEFAULTS = { | ||
contentHelper: true, | ||
imageHelper: true, | ||
dataset: "production", | ||
withCredentials: false, | ||
additionalClients: {} | ||
}; | ||
const CONFIG_KEY = "sanity"; | ||
function validateConfig({projectId, dataset}) { | ||
if (isNuxtBuild) | ||
return; | ||
const {bold} = process.client ? {} : require("chalk"); | ||
const consola = process.client ? {} : require("consola"); | ||
if (!projectId) { | ||
consola.warn(`Make sure you specify a ${bold("projectId")} in your sanity config.`); | ||
return false; | ||
} else { | ||
consola.info(`Enabled ${bold("@nuxtjs/sanity")} for project ${bold(projectId)} (${bold(dataset)}).`); | ||
return true; | ||
} | ||
} | ||
const nuxtModule = function(moduleOptions) { | ||
if (isNuxtBuild) | ||
return; | ||
const {bold} = process.client ? {} : require("chalk"); | ||
const consola = process.client ? {} : require("consola"); | ||
const {join, resolve} = process.client ? {} : require("upath"); | ||
let sanityConfig = {}; | ||
try { | ||
const fs = process.client ? {} : require("fs-extra"); | ||
const {projectId, dataset} = fs.readJSONSync(resolve(this.options.rootDir, "./sanity.json")).api; | ||
sanityConfig = {projectId, dataset}; | ||
} catch (e) { | ||
} | ||
const options = defu2(this.options[CONFIG_KEY], moduleOptions, sanityConfig, {useCdn: isProd && !moduleOptions.token && (!this.options[CONFIG_KEY] || !this.options[CONFIG_KEY].token)}, DEFAULTS); | ||
if (!validateConfig(options)) { | ||
return; | ||
} | ||
try { | ||
if (!options.minimal) { | ||
options.minimal = !this.nuxt.resolver.requireModule("@sanity/client"); | ||
} | ||
} catch (e) { | ||
options.minimal = true; | ||
consola.warn(`Not using ${bold("@sanity/client")} as it cannot be resolved in your project dependencies. | ||
Try running ${bold("yarn add @sanity/client")} or ${bold("npm install @sanity/client")}. | ||
To disable this warning, set ${bold("sanity: { minimal: true }")} in your nuxt.config.js.`); | ||
} | ||
this.options[CONFIG_KEY] = options; | ||
const autoregister = !!this.options.components; | ||
this.addPlugin({ | ||
src: resolve(__dirname, "../templates/plugin.js"), | ||
fileName: "sanity/plugin.js", | ||
options: { | ||
client: !options.minimal, | ||
components: { | ||
autoregister, | ||
imageHelper: options.imageHelper, | ||
contentHelper: options.contentHelper | ||
}, | ||
sanityConfig: JSON.stringify({ | ||
useCdn: options.useCdn, | ||
projectId: options.projectId, | ||
dataset: options.dataset, | ||
withCredentials: options.withCredentials, | ||
token: options.token | ||
}), | ||
additionalClients: JSON.stringify(options.additionalClients) | ||
} | ||
}); | ||
if (autoregister) { | ||
this.nuxt.hook("components:dirs", (dirs) => { | ||
dirs.push({ | ||
path: join(__dirname, "components"), | ||
extensions: ["js"] | ||
}); | ||
}); | ||
} | ||
this.options.build.transpile = this.options.build.transpile || []; | ||
this.options.build.transpile.push(/^@nuxtjs[\\/]sanity/); | ||
}; | ||
nuxtModule.meta = {name: "@nuxtjs/sanity"}; | ||
export default nuxtModule; | ||
export { createClient, getByteSize, getQuery, groq }; |
@@ -5,8 +5,2 @@ 'use strict'; | ||
const defu2 = require('defu'); | ||
function _interopDefaultLegacy (e) { return e && typeof e === 'object' && 'default' in e ? e : { 'default': e }; } | ||
const defu2__default = /*#__PURE__*/_interopDefaultLegacy(defu2); | ||
const apiHost = "api.sanity.io"; | ||
@@ -23,3 +17,10 @@ const cdnHost = "apicdn.sanity.io"; | ||
function createClient(config) { | ||
const {projectId, dataset, useCdn, withCredentials, token} = config; | ||
const { | ||
useCdn, | ||
projectId, | ||
dataset, | ||
apiVersion, | ||
withCredentials, | ||
token | ||
} = config; | ||
const fetchOptions = { | ||
@@ -36,3 +37,10 @@ credentials: withCredentials ? "include" : "omit", | ||
return { | ||
clone: () => createClient({projectId, dataset, useCdn, withCredentials, token}), | ||
clone: () => createClient({ | ||
useCdn, | ||
projectId, | ||
dataset, | ||
apiVersion, | ||
withCredentials, | ||
token | ||
}), | ||
async fetch(query, params) { | ||
@@ -42,3 +50,4 @@ const qs = getQuery(query, params); | ||
const host = useCdn && !usePostRequest ? cdnHost : apiHost; | ||
const response = usePostRequest ? await fetch(`https://${projectId}.${host}/v1/data/query/${dataset}`, { | ||
const urlBase = `https://${projectId}.${host}/v${apiVersion}/data/query/${dataset}`; | ||
const response = usePostRequest ? await fetch(urlBase, { | ||
method: "post", | ||
@@ -51,3 +60,3 @@ body: JSON.stringify({query, params}), | ||
} | ||
}) : await fetch(`https://${projectId}.${host}/v1/data/query/${dataset}${qs}`, fetchOptions); | ||
}) : await fetch(`${urlBase}${qs}`, fetchOptions); | ||
const {result} = await response.json(); | ||
@@ -64,91 +73,5 @@ return result; | ||
const isNuxtBuild = process.client || process.server; | ||
const isProd = process.env.NODE_ENV === "production"; | ||
const DEFAULTS = { | ||
contentHelper: true, | ||
imageHelper: true, | ||
dataset: "production", | ||
withCredentials: false, | ||
additionalClients: {} | ||
}; | ||
const CONFIG_KEY = "sanity"; | ||
function validateConfig({projectId, dataset}) { | ||
if (isNuxtBuild) | ||
return; | ||
const {bold} = process.client ? {} : require("chalk"); | ||
const consola = process.client ? {} : require("consola"); | ||
if (!projectId) { | ||
consola.warn(`Make sure you specify a ${bold("projectId")} in your sanity config.`); | ||
return false; | ||
} else { | ||
consola.info(`Enabled ${bold("@nuxtjs/sanity")} for project ${bold(projectId)} (${bold(dataset)}).`); | ||
return true; | ||
} | ||
} | ||
const nuxtModule = function(moduleOptions) { | ||
if (isNuxtBuild) | ||
return; | ||
const {bold} = process.client ? {} : require("chalk"); | ||
const consola = process.client ? {} : require("consola"); | ||
const {join, resolve} = process.client ? {} : require("upath"); | ||
let sanityConfig = {}; | ||
try { | ||
const fs = process.client ? {} : require("fs-extra"); | ||
const {projectId, dataset} = fs.readJSONSync(resolve(this.options.rootDir, "./sanity.json")).api; | ||
sanityConfig = {projectId, dataset}; | ||
} catch (e) { | ||
} | ||
const options = defu2__default['default'](this.options[CONFIG_KEY], moduleOptions, sanityConfig, {useCdn: isProd && !moduleOptions.token && (!this.options[CONFIG_KEY] || !this.options[CONFIG_KEY].token)}, DEFAULTS); | ||
if (!validateConfig(options)) { | ||
return; | ||
} | ||
try { | ||
if (!options.minimal) { | ||
options.minimal = !this.nuxt.resolver.requireModule("@sanity/client"); | ||
} | ||
} catch (e) { | ||
options.minimal = true; | ||
consola.warn(`Not using ${bold("@sanity/client")} as it cannot be resolved in your project dependencies. | ||
Try running ${bold("yarn add @sanity/client")} or ${bold("npm install @sanity/client")}. | ||
To disable this warning, set ${bold("sanity: { minimal: true }")} in your nuxt.config.js.`); | ||
} | ||
this.options[CONFIG_KEY] = options; | ||
const autoregister = !!this.options.components; | ||
this.addPlugin({ | ||
src: resolve(__dirname, "../templates/plugin.js"), | ||
fileName: "sanity/plugin.js", | ||
options: { | ||
client: !options.minimal, | ||
components: { | ||
autoregister, | ||
imageHelper: options.imageHelper, | ||
contentHelper: options.contentHelper | ||
}, | ||
sanityConfig: JSON.stringify({ | ||
useCdn: options.useCdn, | ||
projectId: options.projectId, | ||
dataset: options.dataset, | ||
withCredentials: options.withCredentials, | ||
token: options.token | ||
}), | ||
additionalClients: JSON.stringify(options.additionalClients) | ||
} | ||
}); | ||
if (autoregister) { | ||
this.nuxt.hook("components:dirs", (dirs) => { | ||
dirs.push({ | ||
path: join(__dirname, "components"), | ||
extensions: ["js"] | ||
}); | ||
}); | ||
} | ||
this.options.build.transpile = this.options.build.transpile || []; | ||
this.options.build.transpile.push(/^@nuxtjs[\\/]sanity/); | ||
}; | ||
nuxtModule.meta = {name: "@nuxtjs/sanity"}; | ||
exports.createClient = createClient; | ||
exports.default = nuxtModule; | ||
exports.getByteSize = getByteSize; | ||
exports.getQuery = getQuery; | ||
exports.groq = groq; |
{ | ||
"name": "@nuxtjs/sanity", | ||
"version": "0.7.1", | ||
"version": "0.8.0", | ||
"description": "Sanity integration for Nuxt.js", | ||
@@ -21,2 +21,6 @@ "keywords": [ | ||
}, | ||
"./module": { | ||
"require": "./dist/module.js", | ||
"import": "./dist/module.es.js" | ||
}, | ||
"./": "./", | ||
@@ -30,2 +34,3 @@ "./sanity-content": "./dist/components/sanity-content.js", | ||
"files": [ | ||
"module.js", | ||
"dist", | ||
@@ -37,43 +42,40 @@ "vetur", | ||
"build": "siroc build", | ||
"dev": "nuxt-ts example", | ||
"dev": "nuxt example", | ||
"lint": "eslint --fix --ext .js,.ts,.vue .", | ||
"prepare": "yarn build", | ||
"prepare": "husky install && yarn build", | ||
"prepublishOnly": "yarn test", | ||
"test": "yarn lint && jest" | ||
}, | ||
"husky": { | ||
"gitHooks": { | ||
"pre-commit": "lint-staged" | ||
} | ||
}, | ||
"dependencies": { | ||
"chalk": "^4.1.0", | ||
"consola": "^2.15.0", | ||
"defu": "3.2.2", | ||
"upath": "^2.0.1" | ||
"fs-extra": "^9.1.0", | ||
"upath": "2.0.1" | ||
}, | ||
"devDependencies": { | ||
"@babel/plugin-transform-runtime": "7.12.15", | ||
"@babel/preset-env": "7.12.16", | ||
"@babel/preset-typescript": "7.12.16", | ||
"@nuxt/test-utils": "0.1.3", | ||
"@nuxt/types": "2.15.0", | ||
"@nuxt/typescript-build": "2.0.4", | ||
"@nuxt/typescript-runtime": "2.0.1", | ||
"@nuxtjs/eslint-config-typescript": "5.0.0", | ||
"@nuxtjs/tailwindcss": "3.4.2", | ||
"@release-it/conventional-changelog": "2.0.0", | ||
"@sanity/client": "2.2.6", | ||
"@types/fs-extra": "9.0.7", | ||
"@types/jest": "26.0.20", | ||
"@babel/plugin-transform-runtime": "7.13.10", | ||
"@babel/preset-env": "7.13.12", | ||
"@babel/preset-typescript": "7.13.0", | ||
"@nuxt/test-utils": "0.2.0", | ||
"@nuxt/types": "2.15.3", | ||
"@nuxt/typescript-build": "2.1.0", | ||
"@nuxtjs/eslint-config-typescript": "6.0.0", | ||
"@nuxtjs/tailwindcss": "4.0.2", | ||
"@release-it/conventional-changelog": "2.0.1", | ||
"@sanity/client": "2.7.1", | ||
"@types/fs-extra": "9.0.9", | ||
"@types/jest": "26.0.22", | ||
"@types/webpack-env": "1.16.0", | ||
"@vue/test-utils": "1.1.3", | ||
"babel-jest": "26.6.3", | ||
"eslint": "7.20.0", | ||
"husky": "4.3.8", | ||
"eslint": "7.23.0", | ||
"husky": "^6.0.0", | ||
"jest": "26.6.3", | ||
"jest-serializer-vue-tjw": "3.15.0", | ||
"jest-serializer-vue-tjw": "3.17.0", | ||
"lint-staged": "10.5.4", | ||
"nuxt": "^2.15.0", | ||
"playwright": "1.8.1", | ||
"release-it": "14.4.0", | ||
"siroc": "0.6.6" | ||
"nuxt": "2.15.3", | ||
"playwright": "1.10.0", | ||
"release-it": "14.5.0", | ||
"siroc": "0.8.0" | ||
}, | ||
@@ -92,4 +94,4 @@ "peerDependencies": { | ||
"volta": { | ||
"node": "12.20.1" | ||
"node": "12.22.0" | ||
} | ||
} |
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
Filesystem access
Supply chain riskAccesses the file system, and could potentially read sensitive data.
Found 1 instance in 1 package
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
Filesystem access
Supply chain riskAccesses the file system, and could potentially read sensitive data.
Found 1 instance in 1 package
51572
24
19
1103
7
+ Addedchalk@^4.1.0
+ Addedconsola@^2.15.0
+ Addedfs-extra@^9.1.0
+ Addedat-least-node@1.0.0(transitive)
+ Addedchalk@4.1.2(transitive)
+ Addedfs-extra@9.1.0(transitive)
+ Addedgraceful-fs@4.2.11(transitive)
+ Addedjsonfile@6.1.0(transitive)
+ Addeduniversalify@2.0.1(transitive)
- Removedchalk@3.0.0(transitive)
Updatedupath@2.0.1