sanity-plugin-iframe-pane 2.5.2 → 2.5.3
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/lib/_chunks/{is-valid-secret-16e6bdd6.js → is-valid-secret-d0fb874f.js} +5 -2
- package/lib/_chunks/{is-valid-secret-16e6bdd6.js.map → is-valid-secret-d0fb874f.js.map} +1 -1
- package/lib/_chunks/{is-valid-secret-b7d4a930.cjs → is-valid-secret-ffcae61b.cjs} +5 -2
- package/lib/_chunks/{is-valid-secret-b7d4a930.cjs.map → is-valid-secret-ffcae61b.cjs.map} +1 -1
- package/lib/_chunks/{utils-f76e0adf.cjs → utils-0d463b2b.cjs} +2 -2
- package/lib/_chunks/{utils-f76e0adf.cjs.map → utils-0d463b2b.cjs.map} +1 -1
- package/lib/_chunks/{utils-e30804e2.js → utils-7d21c3cd.js} +2 -2
- package/lib/_chunks/{utils-e30804e2.js.map → utils-7d21c3cd.js.map} +1 -1
- package/lib/index.cjs +2 -2
- package/lib/index.js +3 -3
- package/lib/is-valid-secret.cjs +1 -1
- package/lib/is-valid-secret.js +1 -1
- package/lib/preview-url.cjs +2 -2
- package/lib/preview-url.js +2 -2
- package/package.json +1 -1
- package/src/isValidSecret.tsx +6 -1
|
@@ -30,7 +30,10 @@ async function isValidSecret(client, urlSecretId, urlSecret) {
|
|
|
30
30
|
}, {
|
|
31
31
|
tag
|
|
32
32
|
});
|
|
33
|
-
|
|
33
|
+
if (!(data == null ? void 0 : data.secret)) {
|
|
34
|
+
throw new TypeError("Unable to find a secret in the dataset, with the id `".concat(urlSecretId, "`. Have you set the `urlSecretId` option in your `Iframe` and `previewUrl` configurations?"));
|
|
35
|
+
}
|
|
36
|
+
return data.secret === urlSecret;
|
|
34
37
|
}
|
|
35
38
|
export { SECRET_TTL, apiVersion, fetchSecretQuery, isValidSecret, tag };
|
|
36
|
-
//# sourceMappingURL=is-valid-secret-
|
|
39
|
+
//# sourceMappingURL=is-valid-secret-d0fb874f.js.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"is-valid-secret-
|
|
1
|
+
{"version":3,"file":"is-valid-secret-d0fb874f.js","sources":["../../src/isValidSecret.tsx"],"sourcesContent":["import {name} from '../package.json'\n\nexport type UrlSecretId = `${string}.${string}`\n\n// updated within the hour, if it's older it'll create a new secret or return null\nexport const SECRET_TTL = 60 * 60\n\nexport const fetchSecretQuery = /* groq */ `*[_id == $id && dateTime(_updatedAt) > dateTime(now()) - ${SECRET_TTL}][0]{secret, _updatedAt}`\nexport type FetchSecretResponse = {\n secret: string | null\n _updatedAt: string | null\n} | null\n\nexport const tag = name\n\nexport const apiVersion = '2023-08-08'\n\nexport type SanityClientLike = {\n config(): {token?: string}\n withConfig(config: {apiVersion?: string; useCdn?: boolean; perspective: 'raw'}): SanityClientLike\n fetch<\n R,\n Q = {\n [key: string]: any\n },\n >(\n query: string,\n params: Q,\n options: {tag?: string},\n ): Promise<R>\n}\nexport async function isValidSecret(\n client: SanityClientLike,\n urlSecretId: UrlSecretId,\n urlSecret: string,\n): Promise<boolean> {\n if (!urlSecret) {\n throw new TypeError('`urlSecret` is required')\n }\n if (!urlSecretId) {\n throw new TypeError('`urlSecretId` is required')\n }\n if (!urlSecretId.includes('.')) {\n throw new TypeError(\n `\\`urlSecretId\\` must have a dot prefix, \\`${urlSecretId}\\` is not secure, add a prefix, for example \\`preview.${urlSecretId}\\` `,\n )\n }\n if (!client) {\n throw new TypeError('`client` is required')\n }\n if (!client.config().token) {\n throw new TypeError('`client` must have a `token` specified')\n }\n\n const customClient = client.withConfig({\n apiVersion,\n useCdn: false,\n perspective: 'raw',\n })\n const data = await customClient.fetch<FetchSecretResponse>(\n fetchSecretQuery,\n {id: urlSecretId},\n {tag},\n )\n if (!data?.secret) {\n throw new TypeError(\n `Unable to find a secret in the dataset, with the id \\`${urlSecretId}\\`. Have you set the \\`urlSecretId\\` option in your \\`Iframe\\` and \\`previewUrl\\` configurations?`,\n )\n }\n\n return data.secret === urlSecret\n}\n"],"names":["SECRET_TTL","fetchSecretQuery","concat","tag","name","apiVersion","isValidSecret","client","urlSecretId","urlSecret","TypeError","includes","config","token","customClient","withConfig","useCdn","perspective","data","fetch","id","secret"],"mappings":";AAKO,MAAMA,aAAa,EAAK,GAAA,EAAA;AAElB,MAAAC,gBAAA,GAAA;AAA8B,4DAA4DC,MAAU,CAAAF,UAAA,EAAA,0BAAA,CAAA;AAM1G,MAAMG,GAAM,GAAAC,IAAA;AAEZ,MAAMC,UAAa,GAAA,YAAA;AAgBJ,eAAAC,aAAAA,CACpBC,MACA,EAAAC,WAAA,EACAC,SACkB,EAAA;EAClB,IAAI,CAACA,SAAW,EAAA;IACR,MAAA,IAAIC,UAAU,yBAAyB,CAAA;EAC/C;EACA,IAAI,CAACF,WAAa,EAAA;IACV,MAAA,IAAIE,UAAU,2BAA2B,CAAA;EACjD;EACA,IAAI,CAACF,WAAA,CAAYG,QAAS,CAAA,GAAG,CAAG,EAAA;IAC9B,MAAM,IAAID,SAAA,CACR,yCAAA,CAA6CR,MAAW,CAAAM,WAAA,EAAA,sDAAA,CAAA,CAAyDN,MAAW,CAAAM,WAAA,EAAA,IAAA,CAAA,CAC9H;EACF;EACA,IAAI,CAACD,MAAQ,EAAA;IACL,MAAA,IAAIG,UAAU,sBAAsB,CAAA;EAC5C;EACA,IAAI,CAACH,MAAA,CAAOK,MAAO,CAAA,CAAA,CAAEC,KAAO,EAAA;IACpB,MAAA,IAAIH,UAAU,wCAAwC,CAAA;EAC9D;EAEM,MAAAI,YAAA,GAAeP,OAAOQ,UAAW,CAAA;IACrCV,UAAA;IACAW,MAAQ,EAAA,KAAA;IACRC,WAAa,EAAA;EAAA,CACd,CAAA;EACK,MAAAC,IAAA,GAAO,MAAMJ,YAAa,CAAAK,KAAA,CAC9BlB,gBAAA,EACA;IAACmB,IAAIZ;EAAW,CAAA,EAChB;IAACL;EAAG,CAAA,CACN;EACI,IAAA,EAACe,6BAAMG,MAAQ,CAAA,EAAA;IACjB,MAAM,IAAIX,SAAA,CACR,wDAAyDR,MAAW,CAAAM,WAAA,EAAA,4FAAA,CAAA,CACtE;EACF;EAEA,OAAOU,KAAKG,MAAW,KAAAZ,SAAA;AACzB;"}
|
|
@@ -32,11 +32,14 @@ async function isValidSecret(client, urlSecretId, urlSecret) {
|
|
|
32
32
|
}, {
|
|
33
33
|
tag
|
|
34
34
|
});
|
|
35
|
-
|
|
35
|
+
if (!(data == null ? void 0 : data.secret)) {
|
|
36
|
+
throw new TypeError("Unable to find a secret in the dataset, with the id `".concat(urlSecretId, "`. Have you set the `urlSecretId` option in your `Iframe` and `previewUrl` configurations?"));
|
|
37
|
+
}
|
|
38
|
+
return data.secret === urlSecret;
|
|
36
39
|
}
|
|
37
40
|
exports.SECRET_TTL = SECRET_TTL;
|
|
38
41
|
exports.apiVersion = apiVersion;
|
|
39
42
|
exports.fetchSecretQuery = fetchSecretQuery;
|
|
40
43
|
exports.isValidSecret = isValidSecret;
|
|
41
44
|
exports.tag = tag;
|
|
42
|
-
//# sourceMappingURL=is-valid-secret-
|
|
45
|
+
//# sourceMappingURL=is-valid-secret-ffcae61b.cjs.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"is-valid-secret-
|
|
1
|
+
{"version":3,"file":"is-valid-secret-ffcae61b.cjs","sources":["../../src/isValidSecret.tsx"],"sourcesContent":["import {name} from '../package.json'\n\nexport type UrlSecretId = `${string}.${string}`\n\n// updated within the hour, if it's older it'll create a new secret or return null\nexport const SECRET_TTL = 60 * 60\n\nexport const fetchSecretQuery = /* groq */ `*[_id == $id && dateTime(_updatedAt) > dateTime(now()) - ${SECRET_TTL}][0]{secret, _updatedAt}`\nexport type FetchSecretResponse = {\n secret: string | null\n _updatedAt: string | null\n} | null\n\nexport const tag = name\n\nexport const apiVersion = '2023-08-08'\n\nexport type SanityClientLike = {\n config(): {token?: string}\n withConfig(config: {apiVersion?: string; useCdn?: boolean; perspective: 'raw'}): SanityClientLike\n fetch<\n R,\n Q = {\n [key: string]: any\n },\n >(\n query: string,\n params: Q,\n options: {tag?: string},\n ): Promise<R>\n}\nexport async function isValidSecret(\n client: SanityClientLike,\n urlSecretId: UrlSecretId,\n urlSecret: string,\n): Promise<boolean> {\n if (!urlSecret) {\n throw new TypeError('`urlSecret` is required')\n }\n if (!urlSecretId) {\n throw new TypeError('`urlSecretId` is required')\n }\n if (!urlSecretId.includes('.')) {\n throw new TypeError(\n `\\`urlSecretId\\` must have a dot prefix, \\`${urlSecretId}\\` is not secure, add a prefix, for example \\`preview.${urlSecretId}\\` `,\n )\n }\n if (!client) {\n throw new TypeError('`client` is required')\n }\n if (!client.config().token) {\n throw new TypeError('`client` must have a `token` specified')\n }\n\n const customClient = client.withConfig({\n apiVersion,\n useCdn: false,\n perspective: 'raw',\n })\n const data = await customClient.fetch<FetchSecretResponse>(\n fetchSecretQuery,\n {id: urlSecretId},\n {tag},\n )\n if (!data?.secret) {\n throw new TypeError(\n `Unable to find a secret in the dataset, with the id \\`${urlSecretId}\\`. Have you set the \\`urlSecretId\\` option in your \\`Iframe\\` and \\`previewUrl\\` configurations?`,\n )\n }\n\n return data.secret === urlSecret\n}\n"],"names":["SECRET_TTL","fetchSecretQuery","concat","tag","name","apiVersion","isValidSecret","client","urlSecretId","urlSecret","TypeError","includes","config","token","customClient","withConfig","useCdn","perspective","data","fetch","id","secret"],"mappings":";;;AAKO,MAAMA,aAAa,EAAK,GAAA,EAAA;AAElB,MAAAC,gBAAA,GAAA;AAA8B,4DAA4DC,MAAU,CAAAF,UAAA,EAAA,0BAAA,CAAA;AAM1G,MAAMG,GAAM,GAAAC,IAAA;AAEZ,MAAMC,UAAa,GAAA,YAAA;AAgBJ,eAAAC,aAAAA,CACpBC,MACA,EAAAC,WAAA,EACAC,SACkB,EAAA;EAClB,IAAI,CAACA,SAAW,EAAA;IACR,MAAA,IAAIC,UAAU,yBAAyB,CAAA;EAC/C;EACA,IAAI,CAACF,WAAa,EAAA;IACV,MAAA,IAAIE,UAAU,2BAA2B,CAAA;EACjD;EACA,IAAI,CAACF,WAAA,CAAYG,QAAS,CAAA,GAAG,CAAG,EAAA;IAC9B,MAAM,IAAID,SAAA,CACR,yCAAA,CAA6CR,MAAW,CAAAM,WAAA,EAAA,sDAAA,CAAA,CAAyDN,MAAW,CAAAM,WAAA,EAAA,IAAA,CAAA,CAC9H;EACF;EACA,IAAI,CAACD,MAAQ,EAAA;IACL,MAAA,IAAIG,UAAU,sBAAsB,CAAA;EAC5C;EACA,IAAI,CAACH,MAAA,CAAOK,MAAO,CAAA,CAAA,CAAEC,KAAO,EAAA;IACpB,MAAA,IAAIH,UAAU,wCAAwC,CAAA;EAC9D;EAEM,MAAAI,YAAA,GAAeP,OAAOQ,UAAW,CAAA;IACrCV,UAAA;IACAW,MAAQ,EAAA,KAAA;IACRC,WAAa,EAAA;EAAA,CACd,CAAA;EACK,MAAAC,IAAA,GAAO,MAAMJ,YAAa,CAAAK,KAAA,CAC9BlB,gBAAA,EACA;IAACmB,IAAIZ;EAAW,CAAA,EAChB;IAACL;EAAG,CAAA,CACN;EACI,IAAA,EAACe,6BAAMG,MAAQ,CAAA,EAAA;IACjB,MAAM,IAAIX,SAAA,CACR,wDAAyDR,MAAW,CAAAM,WAAA,EAAA,4FAAA,CAAA,CACtE;EACF;EAEA,OAAOU,KAAKG,MAAW,KAAAZ,SAAA;AACzB;;;;;"}
|
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
'use strict';
|
|
2
2
|
|
|
3
|
-
var isValidSecret = require('./is-valid-secret-
|
|
3
|
+
var isValidSecret = require('./is-valid-secret-ffcae61b.cjs');
|
|
4
4
|
const MissingSlug = Symbol("MissingSlug");
|
|
5
5
|
function defineUrlResolver(options) {
|
|
6
6
|
const {
|
|
@@ -57,4 +57,4 @@ exports.MissingSlug = MissingSlug;
|
|
|
57
57
|
exports.defineUrlResolver = defineUrlResolver;
|
|
58
58
|
exports.getExpiresAt = getExpiresAt;
|
|
59
59
|
exports.patchUrlSecret = patchUrlSecret;
|
|
60
|
-
//# sourceMappingURL=utils-
|
|
60
|
+
//# sourceMappingURL=utils-0d463b2b.cjs.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"utils-
|
|
1
|
+
{"version":3,"file":"utils-0d463b2b.cjs","sources":["../../src/types.ts","../../src/defineUrlResolver.tsx","../../src/utils.ts"],"sourcesContent":["export const MissingSlug = Symbol('MissingSlug')\n\nexport type UrlState = string | typeof MissingSlug\n\nexport type IframeSizeKey = keyof SizeProps\n\nexport type Size = 'desktop' | 'mobile'\n\nexport type SizeProps = {\n // eslint-disable-next-line no-unused-vars\n [key in Size]: {\n width: string | number\n height: string | number\n }\n}\n\nexport type SetError = (error: unknown) => void\n","import type {SanityDocument} from 'sanity'\n\nimport {MissingSlug, UrlState} from './types'\n\nexport type {UrlState}\n\nexport type UrlResolver = (\n document: SanityDocument,\n urlSecret: string | null | undefined,\n signal?: AbortSignal,\n) => UrlState | Promise<UrlState>\n\nexport interface DefineUrlResolverOptions {\n base: string | URL\n requiresSlug?: string[]\n}\nexport function defineUrlResolver(options: DefineUrlResolverOptions): UrlResolver {\n const {base, requiresSlug = []} = options\n return (document, urlSecret) => {\n const url = new URL(base, location.origin)\n url.searchParams.set('type', document._type)\n const slug = (document?.slug as any)?.current\n if (slug) {\n url.searchParams.set('slug', slug)\n } else if (requiresSlug.includes(document._type)) {\n return MissingSlug\n }\n if (urlSecret) {\n url.searchParams.set('secret', urlSecret)\n }\n return url.toString()\n }\n}\n","import type {SanityClient} from 'sanity'\n\nimport {SECRET_TTL, tag, UrlSecretId} from './isValidSecret'\n\nexport function getExpiresAt(_updatedAt: Date) {\n return new Date(_updatedAt.getTime() + 1000 * SECRET_TTL)\n}\n\nfunction generateUrlSecret() {\n // Try using WebCrypto if available\n if (typeof crypto !== 'undefined') {\n // Generate a random array of 16 bytes\n const array = new Uint8Array(16)\n crypto.getRandomValues(array)\n\n // Convert the array to a URL-safe string\n let key = ''\n for (let i = 0; i < array.length; i++) {\n // Convert each byte to a 2-digit hexadecimal number\n key += array[i].toString(16).padStart(2, '0')\n }\n\n // Replace '+' and '/' from base64url to '-' and '_'\n key = btoa(key).replace(/\\+/g, '-').replace(/\\//g, '_').replace(/[=]+$/, '')\n\n return key\n }\n // If not fallback to Math.random\n return Math.random().toString(36).slice(2)\n}\n\nexport async function patchUrlSecret(\n client: SanityClient,\n urlSecretId: UrlSecretId,\n signal?: AbortSignal,\n): Promise<string> {\n const newSecret = generateUrlSecret()\n const patch = client.patch(urlSecretId).set({secret: newSecret})\n await client\n .transaction()\n .createIfNotExists({_id: urlSecretId, _type: urlSecretId})\n .patch(patch)\n .commit({tag, signal})\n return newSecret\n}\n"],"names":["MissingSlug","Symbol","defineUrlResolver","options","base","requiresSlug","document","urlSecret","_a","url","URL","location","origin","searchParams","set","_type","slug","current","includes","toString","getExpiresAt","_updatedAt","Date","getTime","SECRET_TTL","generateUrlSecret","crypto","array","Uint8Array","getRandomValues","key","i","length","padStart","btoa","replace","Math","random","slice","patchUrlSecret","client","urlSecretId","signal","newSecret","patch","secret","transaction","createIfNotExists","_id","commit","tag"],"mappings":";;;AAAa,MAAAA,WAAA,GAAcC,OAAO,aAAa,CAAA;ACgBxC,SAASC,kBAAkBC,OAAgD,EAAA;EAChF,MAAM;IAACC,IAAA;IAAMC,YAAe,GAAA;GAAM,GAAAF,OAAA;EAC3B,OAAA,CAACG,UAAUC,SAAc,KAAA;IAlBlC,IAAAC,EAAA;IAmBI,MAAMC,GAAM,GAAA,IAAIC,GAAI,CAAAN,IAAA,EAAMO,SAASC,MAAM,CAAA;IACzCH,GAAA,CAAII,YAAa,CAAAC,GAAA,CAAI,MAAQ,EAAAR,QAAA,CAASS,KAAK,CAAA;IACrC,MAAAC,IAAA,GAAA,CAAQR,EAAU,GAAAF,QAAA,IAAA,IAAA,GAAA,KAAA,CAAA,GAAAA,QAAA,CAAAU,IAAA,KAAV,IAAwB,GAAA,KAAA,CAAA,GAAAR,EAAA,C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,eAAAC,cAAAA,CACpBC,MACA,EAAAC,WAAA,EACAC,MACiB,EAAA;EACjB,MAAMC,YAAYlB,iBAAkB,EAAA;EAC9B,MAAAmB,KAAA,GAAQJ,OAAOI,KAAM,CAAAH,WAAW,EAAE3B,GAAI,CAAA;IAAC+B,MAAQ,EAAAF;EAAA,CAAU,CAAA;EAC/D,MAAMH,OACHM,WAAY,EAAA,CACZC,kBAAkB;IAACC,GAAA,EAAKP;IAAa1B,KAAO,EAAA0B;EAAY,CAAA,CAAA,CACxDG,MAAMA,KAAK,CAAA,CACXK,OAAO;IAAAC,GAAA,EAACA,aAAA,CAAAA,GAAA;IAAKR;GAAO,CAAA;EAChB,OAAAC,SAAA;AACT;;;;"}
|
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import { tag, SECRET_TTL } from './is-valid-secret-
|
|
1
|
+
import { tag, SECRET_TTL } from './is-valid-secret-d0fb874f.js';
|
|
2
2
|
const MissingSlug = Symbol("MissingSlug");
|
|
3
3
|
function defineUrlResolver(options) {
|
|
4
4
|
const {
|
|
@@ -52,4 +52,4 @@ async function patchUrlSecret(client, urlSecretId, signal) {
|
|
|
52
52
|
return newSecret;
|
|
53
53
|
}
|
|
54
54
|
export { MissingSlug, defineUrlResolver, getExpiresAt, patchUrlSecret };
|
|
55
|
-
//# sourceMappingURL=utils-
|
|
55
|
+
//# sourceMappingURL=utils-7d21c3cd.js.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"utils-
|
|
1
|
+
{"version":3,"file":"utils-7d21c3cd.js","sources":["../../src/types.ts","../../src/defineUrlResolver.tsx","../../src/utils.ts"],"sourcesContent":["export const MissingSlug = Symbol('MissingSlug')\n\nexport type UrlState = string | typeof MissingSlug\n\nexport type IframeSizeKey = keyof SizeProps\n\nexport type Size = 'desktop' | 'mobile'\n\nexport type SizeProps = {\n // eslint-disable-next-line no-unused-vars\n [key in Size]: {\n width: string | number\n height: string | number\n }\n}\n\nexport type SetError = (error: unknown) => void\n","import type {SanityDocument} from 'sanity'\n\nimport {MissingSlug, UrlState} from './types'\n\nexport type {UrlState}\n\nexport type UrlResolver = (\n document: SanityDocument,\n urlSecret: string | null | undefined,\n signal?: AbortSignal,\n) => UrlState | Promise<UrlState>\n\nexport interface DefineUrlResolverOptions {\n base: string | URL\n requiresSlug?: string[]\n}\nexport function defineUrlResolver(options: DefineUrlResolverOptions): UrlResolver {\n const {base, requiresSlug = []} = options\n return (document, urlSecret) => {\n const url = new URL(base, location.origin)\n url.searchParams.set('type', document._type)\n const slug = (document?.slug as any)?.current\n if (slug) {\n url.searchParams.set('slug', slug)\n } else if (requiresSlug.includes(document._type)) {\n return MissingSlug\n }\n if (urlSecret) {\n url.searchParams.set('secret', urlSecret)\n }\n return url.toString()\n }\n}\n","import type {SanityClient} from 'sanity'\n\nimport {SECRET_TTL, tag, UrlSecretId} from './isValidSecret'\n\nexport function getExpiresAt(_updatedAt: Date) {\n return new Date(_updatedAt.getTime() + 1000 * SECRET_TTL)\n}\n\nfunction generateUrlSecret() {\n // Try using WebCrypto if available\n if (typeof crypto !== 'undefined') {\n // Generate a random array of 16 bytes\n const array = new Uint8Array(16)\n crypto.getRandomValues(array)\n\n // Convert the array to a URL-safe string\n let key = ''\n for (let i = 0; i < array.length; i++) {\n // Convert each byte to a 2-digit hexadecimal number\n key += array[i].toString(16).padStart(2, '0')\n }\n\n // Replace '+' and '/' from base64url to '-' and '_'\n key = btoa(key).replace(/\\+/g, '-').replace(/\\//g, '_').replace(/[=]+$/, '')\n\n return key\n }\n // If not fallback to Math.random\n return Math.random().toString(36).slice(2)\n}\n\nexport async function patchUrlSecret(\n client: SanityClient,\n urlSecretId: UrlSecretId,\n signal?: AbortSignal,\n): Promise<string> {\n const newSecret = generateUrlSecret()\n const patch = client.patch(urlSecretId).set({secret: newSecret})\n await client\n .transaction()\n .createIfNotExists({_id: urlSecretId, _type: urlSecretId})\n .patch(patch)\n .commit({tag, signal})\n return newSecret\n}\n"],"names":["MissingSlug","Symbol","defineUrlResolver","options","base","requiresSlug","document","urlSecret","_a","url","URL","location","origin","searchParams","set","_type","slug","current","includes","toString","getExpiresAt","_updatedAt","Date","getTime","SECRET_TTL","generateUrlSecret","crypto","array","Uint8Array","getRandomValues","key","i","length","padStart","btoa","replace","Math","random","slice","patchUrlSecret","client","urlSecretId","signal","newSecret","patch","secret","transaction","createIfNotExists","_id","commit","tag"],"mappings":";AAAa,MAAAA,WAAA,GAAcC,OAAO,aAAa,CAAA;ACgBxC,SAASC,kBAAkBC,OAAgD,EAAA;EAChF,MAAM;IAACC,IAAA;IAAMC,YAAe,GAAA;GAAM,GAAAF,OAAA;EAC3B,OAAA,CAACG,UAAUC,SAAc,KAAA;IAlBlC,IAAAC,EAAA;IAmBI,MAAMC,GAAM,GAAA,IAAIC,GAAI,CAAAN,IAAA,EAAMO,SAASC,MAAM,CAAA;IACzCH,GAAA,CAAII,YAAa,CAAAC,GAAA,CAAI,MAAQ,EAAAR,QAAA,CAASS,KAAK,CAAA;IACrC,MAAAC,IAAA,GAAA,CAAQR,EAAU,GAAAF,QAAA,IAAA,IAAA,GAAA,KAAA,CAAA,GAAAA,QAAA,CAAAU,IAAA,KAAV,IAAwB,GAAA,KAAA,CAAA,GAAAR,EAAA,CAAAS,OAAA;IACtC,IAAID,IAAM,EAAA;MACJP,GAAA,CAAAI,YAAA,CAAaC,GAAI,CAAA,MAAA,EAAQE,IAAI,CAAA;IACxB,CAAA,MAAA,IAAAX,YAAA,CAAaa,QAAS,CAAAZ,QAAA,CAASS,KAAK,CAAG,EAAA;MACzC,OAAAf,WAAA;IACT;IACA,IAAIO,SAAW,EAAA;MACTE,GAAA,CAAAI,YAAA,CAAaC,GAAI,CAAA,QAAA,EAAUP,SAAS,CAAA;IAC1C;IACA,OAAOE,IAAIU,QAAS,EAAA;EAAA,CACtB;AACF;AC5BO,SAASC,aAAaC,UAAkB,EAAA;EAC7C,OAAO,IAAIC,IAAK,CAAAD,UAAA,CAAWE,OAAQ,CAAA,CA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
|
Object.defineProperty(exports, '__esModule', {
|
|
4
4
|
value: true
|
|
5
5
|
});
|
|
6
|
-
var utils = require('./_chunks/utils-
|
|
6
|
+
var utils = require('./_chunks/utils-0d463b2b.cjs');
|
|
7
7
|
var jsxRuntime = require('react/jsx-runtime');
|
|
8
8
|
var icons = require('@sanity/icons');
|
|
9
9
|
var ui = require('@sanity/ui');
|
|
10
10
|
var framerMotion = require('framer-motion');
|
|
11
11
|
var react = require('react');
|
|
12
12
|
var sanity = require('sanity');
|
|
13
|
-
var isValidSecret = require('./_chunks/is-valid-secret-
|
|
13
|
+
var isValidSecret = require('./_chunks/is-valid-secret-ffcae61b.cjs');
|
|
14
14
|
var usehooksTs = require('usehooks-ts');
|
|
15
15
|
function GetUrlSecret(props) {
|
|
16
16
|
const {
|
package/lib/index.js
CHANGED
|
@@ -1,12 +1,12 @@
|
|
|
1
|
-
import { patchUrlSecret, getExpiresAt, MissingSlug } from './_chunks/utils-
|
|
2
|
-
export { defineUrlResolver } from './_chunks/utils-
|
|
1
|
+
import { patchUrlSecret, getExpiresAt, MissingSlug } from './_chunks/utils-7d21c3cd.js';
|
|
2
|
+
export { defineUrlResolver } from './_chunks/utils-7d21c3cd.js';
|
|
3
3
|
import { jsx, jsxs, Fragment } from 'react/jsx-runtime';
|
|
4
4
|
import { MobileDeviceIcon, UndoIcon, ClipboardIcon, LaunchIcon, WarningOutlineIcon } from '@sanity/icons';
|
|
5
5
|
import { Text, useToast, Card, Flex, Tooltip, Button, Box, Spinner, usePrefersReducedMotion, Container, Stack } from '@sanity/ui';
|
|
6
6
|
import { motion, AnimatePresence, MotionConfig } from 'framer-motion';
|
|
7
7
|
import { useState, useEffect, useMemo, useRef, forwardRef, useCallback, useDeferredValue } from 'react';
|
|
8
8
|
import { useClient } from 'sanity';
|
|
9
|
-
import { apiVersion, fetchSecretQuery, tag } from './_chunks/is-valid-secret-
|
|
9
|
+
import { apiVersion, fetchSecretQuery, tag } from './_chunks/is-valid-secret-d0fb874f.js';
|
|
10
10
|
import { useCopyToClipboard } from 'usehooks-ts';
|
|
11
11
|
function GetUrlSecret(props) {
|
|
12
12
|
const {
|
package/lib/is-valid-secret.cjs
CHANGED
|
@@ -3,6 +3,6 @@
|
|
|
3
3
|
Object.defineProperty(exports, '__esModule', {
|
|
4
4
|
value: true
|
|
5
5
|
});
|
|
6
|
-
var isValidSecret = require('./_chunks/is-valid-secret-
|
|
6
|
+
var isValidSecret = require('./_chunks/is-valid-secret-ffcae61b.cjs');
|
|
7
7
|
exports.isValidSecret = isValidSecret.isValidSecret;
|
|
8
8
|
//# sourceMappingURL=is-valid-secret.cjs.map
|
package/lib/is-valid-secret.js
CHANGED
|
@@ -1,2 +1,2 @@
|
|
|
1
|
-
export { isValidSecret } from './_chunks/is-valid-secret-
|
|
1
|
+
export { isValidSecret } from './_chunks/is-valid-secret-d0fb874f.js';
|
|
2
2
|
//# sourceMappingURL=is-valid-secret.js.map
|
package/lib/preview-url.cjs
CHANGED
|
@@ -4,8 +4,8 @@ Object.defineProperty(exports, '__esModule', {
|
|
|
4
4
|
value: true
|
|
5
5
|
});
|
|
6
6
|
var sanity = require('sanity');
|
|
7
|
-
var utils = require('./_chunks/utils-
|
|
8
|
-
var isValidSecret = require('./_chunks/is-valid-secret-
|
|
7
|
+
var utils = require('./_chunks/utils-0d463b2b.cjs');
|
|
8
|
+
var isValidSecret = require('./_chunks/is-valid-secret-ffcae61b.cjs');
|
|
9
9
|
const previewUrl = sanity.definePlugin(_ref => {
|
|
10
10
|
let {
|
|
11
11
|
urlSecretId,
|
package/lib/preview-url.js
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
import { definePlugin } from 'sanity';
|
|
2
|
-
import { patchUrlSecret, MissingSlug, defineUrlResolver } from './_chunks/utils-
|
|
3
|
-
import { apiVersion, fetchSecretQuery, tag } from './_chunks/is-valid-secret-
|
|
2
|
+
import { patchUrlSecret, MissingSlug, defineUrlResolver } from './_chunks/utils-7d21c3cd.js';
|
|
3
|
+
import { apiVersion, fetchSecretQuery, tag } from './_chunks/is-valid-secret-d0fb874f.js';
|
|
4
4
|
const previewUrl = definePlugin(_ref => {
|
|
5
5
|
let {
|
|
6
6
|
urlSecretId,
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "sanity-plugin-iframe-pane",
|
|
3
|
-
"version": "2.5.
|
|
3
|
+
"version": "2.5.3",
|
|
4
4
|
"description": "Display any URL in a View Pane, along with helpful buttons to Copy the URL or open in a new tab",
|
|
5
5
|
"homepage": "https://github.com/sanity-io/sanity-plugin-iframe-pane#readme",
|
|
6
6
|
"bugs": {
|
package/src/isValidSecret.tsx
CHANGED
|
@@ -62,6 +62,11 @@ export async function isValidSecret(
|
|
|
62
62
|
{id: urlSecretId},
|
|
63
63
|
{tag},
|
|
64
64
|
)
|
|
65
|
+
if (!data?.secret) {
|
|
66
|
+
throw new TypeError(
|
|
67
|
+
`Unable to find a secret in the dataset, with the id \`${urlSecretId}\`. Have you set the \`urlSecretId\` option in your \`Iframe\` and \`previewUrl\` configurations?`,
|
|
68
|
+
)
|
|
69
|
+
}
|
|
65
70
|
|
|
66
|
-
return data
|
|
71
|
+
return data.secret === urlSecret
|
|
67
72
|
}
|