sanity-plugin-seo-copilot 0.2.14 → 0.2.15
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/dist/index.js +31 -19
- package/dist/index.js.map +1 -1
- package/dist/index.mjs +31 -19
- package/dist/index.mjs.map +1 -1
- package/package.json +64 -61
- package/src/components/KeywordPanel.tsx +4 -3
- package/src/index.ts +18 -16
- package/src/lib/api.ts +12 -10
- package/src/lib/apiKey.ts +30 -0
package/dist/index.js
CHANGED
|
@@ -423,6 +423,15 @@ function useDocumentContent() {
|
|
|
423
423
|
// src/hooks/useKeywordAnalysis.ts
|
|
424
424
|
var import_react2 = require("react");
|
|
425
425
|
|
|
426
|
+
// src/lib/apiKey.ts
|
|
427
|
+
var SHARED_CLIENT_KEY = "seo-copilot-public-client-key-v1";
|
|
428
|
+
function authHeaders() {
|
|
429
|
+
return { "x-api-key": SHARED_CLIENT_KEY };
|
|
430
|
+
}
|
|
431
|
+
function jsonHeaders() {
|
|
432
|
+
return { "Content-Type": "application/json", ...authHeaders() };
|
|
433
|
+
}
|
|
434
|
+
|
|
426
435
|
// src/lib/api.ts
|
|
427
436
|
function safeParseJson(text) {
|
|
428
437
|
try {
|
|
@@ -443,7 +452,7 @@ function safeParseJson(text) {
|
|
|
443
452
|
async function fetchAnalysis(apiUrl, content, mode, publication, seedKeywords, documentFields, focusKeyword, secondaryKeyword, signal) {
|
|
444
453
|
const response = await fetch(`${apiUrl}/api/seo-copilot/analyze`, {
|
|
445
454
|
method: "POST",
|
|
446
|
-
headers:
|
|
455
|
+
headers: jsonHeaders(),
|
|
447
456
|
body: JSON.stringify({ content, mode, publication, seedKeywords, documentFields, focusKeyword, secondaryKeyword }),
|
|
448
457
|
signal
|
|
449
458
|
});
|
|
@@ -458,7 +467,7 @@ async function fetchAnalysis(apiUrl, content, mode, publication, seedKeywords, d
|
|
|
458
467
|
async function fetchChatStream(apiUrl, messages, documentContext, publication, keywordPanelData, signal) {
|
|
459
468
|
const response = await fetch(`${apiUrl}/api/seo-copilot/chat`, {
|
|
460
469
|
method: "POST",
|
|
461
|
-
headers:
|
|
470
|
+
headers: jsonHeaders(),
|
|
462
471
|
body: JSON.stringify({ messages, documentContext, publication, keywordPanelData }),
|
|
463
472
|
signal
|
|
464
473
|
});
|
|
@@ -472,7 +481,7 @@ async function fetchChatStream(apiUrl, messages, documentContext, publication, k
|
|
|
472
481
|
async function submitFeedback(apiUrl, data) {
|
|
473
482
|
const res = await fetch(`${apiUrl}/api/seo-copilot/feedback`, {
|
|
474
483
|
method: "POST",
|
|
475
|
-
headers:
|
|
484
|
+
headers: jsonHeaders(),
|
|
476
485
|
body: JSON.stringify(data)
|
|
477
486
|
});
|
|
478
487
|
if (!res.ok) throw new Error(`Feedback submit failed: HTTP ${res.status}`);
|
|
@@ -480,7 +489,7 @@ async function submitFeedback(apiUrl, data) {
|
|
|
480
489
|
async function lookupKeywords(apiUrl, keywords, signal) {
|
|
481
490
|
const response = await fetch(`${apiUrl}/api/seo-copilot/keywords`, {
|
|
482
491
|
method: "POST",
|
|
483
|
-
headers:
|
|
492
|
+
headers: jsonHeaders(),
|
|
484
493
|
body: JSON.stringify({ keywords }),
|
|
485
494
|
signal
|
|
486
495
|
});
|
|
@@ -494,7 +503,8 @@ async function lookupKeywords(apiUrl, keywords, signal) {
|
|
|
494
503
|
async function loadChatHistory(apiUrl, userId, documentId) {
|
|
495
504
|
try {
|
|
496
505
|
const res = await fetch(
|
|
497
|
-
`${apiUrl}/api/seo-copilot/chat-history?userId=${encodeURIComponent(userId)}&documentId=${encodeURIComponent(documentId)}
|
|
506
|
+
`${apiUrl}/api/seo-copilot/chat-history?userId=${encodeURIComponent(userId)}&documentId=${encodeURIComponent(documentId)}`,
|
|
507
|
+
{ headers: authHeaders() }
|
|
498
508
|
);
|
|
499
509
|
if (!res.ok) return [];
|
|
500
510
|
const data = await res.json();
|
|
@@ -508,7 +518,7 @@ async function fetchContentSuggestions(apiUrl, content, primaryKeyword, publicat
|
|
|
508
518
|
try {
|
|
509
519
|
const res = await fetch(`${apiUrl}/api/seo-copilot/content-suggestions`, {
|
|
510
520
|
method: "POST",
|
|
511
|
-
headers:
|
|
521
|
+
headers: jsonHeaders(),
|
|
512
522
|
body: JSON.stringify({ content, primaryKeyword, publication }),
|
|
513
523
|
signal
|
|
514
524
|
});
|
|
@@ -529,7 +539,7 @@ async function fetchLinkingSuggestions(apiUrl, content, primaryKeyword, supporti
|
|
|
529
539
|
try {
|
|
530
540
|
const res = await fetch(`${apiUrl}/api/seo-copilot/linking-suggestions`, {
|
|
531
541
|
method: "POST",
|
|
532
|
-
headers:
|
|
542
|
+
headers: jsonHeaders(),
|
|
533
543
|
body: JSON.stringify({ content, primaryKeyword, supportingKeywords, currentDocumentId, publication }),
|
|
534
544
|
signal
|
|
535
545
|
});
|
|
@@ -546,7 +556,7 @@ async function checkLinks(apiUrl, urls) {
|
|
|
546
556
|
try {
|
|
547
557
|
const res = await fetch(`${apiUrl}/api/seo-copilot/check-links`, {
|
|
548
558
|
method: "POST",
|
|
549
|
-
headers:
|
|
559
|
+
headers: jsonHeaders(),
|
|
550
560
|
body: JSON.stringify({ urls })
|
|
551
561
|
});
|
|
552
562
|
if (!res.ok) return [];
|
|
@@ -561,7 +571,7 @@ async function saveChatHistory(apiUrl, userId, documentId, messages, publication
|
|
|
561
571
|
try {
|
|
562
572
|
await fetch(`${apiUrl}/api/seo-copilot/chat-history`, {
|
|
563
573
|
method: "POST",
|
|
564
|
-
headers:
|
|
574
|
+
headers: jsonHeaders(),
|
|
565
575
|
body: JSON.stringify({ userId, documentId, messages, publication })
|
|
566
576
|
});
|
|
567
577
|
} catch {
|
|
@@ -1975,7 +1985,7 @@ function SuggestedKeywordsCard({
|
|
|
1975
1985
|
const previousSuggestions = forceRegenerate && helpData[term] ? helpData[term].map((s) => s.revised || s.sentence || "").filter(Boolean) : void 0;
|
|
1976
1986
|
const res = await fetch(`${apiUrl}/api/seo-copilot/keyword-help`, {
|
|
1977
1987
|
method: "POST",
|
|
1978
|
-
headers:
|
|
1988
|
+
headers: jsonHeaders(),
|
|
1979
1989
|
// Clip to 5,000 chars: the backend only reads the first 4,000 anyway, so sending
|
|
1980
1990
|
// the full article needlessly bloats the request on long pieces.
|
|
1981
1991
|
body: JSON.stringify({ keyword: term, content: text.slice(0, 5e3), publication, previousSuggestions })
|
|
@@ -2003,7 +2013,7 @@ function SuggestedKeywordsCard({
|
|
|
2003
2013
|
try {
|
|
2004
2014
|
const res = await fetch(`${apiUrl}/api/seo-copilot/keywords`, {
|
|
2005
2015
|
method: "POST",
|
|
2006
|
-
headers:
|
|
2016
|
+
headers: jsonHeaders(),
|
|
2007
2017
|
body: JSON.stringify({ keywords: [trimmed] })
|
|
2008
2018
|
});
|
|
2009
2019
|
if (res.ok) {
|
|
@@ -2084,7 +2094,7 @@ function SuggestedKeywordsCard({
|
|
|
2084
2094
|
const existingTerms = allKeywords.map((kw) => kw.term);
|
|
2085
2095
|
const res = await fetch(`${apiUrl}/api/seo-copilot/more-keywords`, {
|
|
2086
2096
|
method: "POST",
|
|
2087
|
-
headers:
|
|
2097
|
+
headers: jsonHeaders(),
|
|
2088
2098
|
body: JSON.stringify({ content: text, existingKeywords: existingTerms, publication })
|
|
2089
2099
|
});
|
|
2090
2100
|
if (res.ok) {
|
|
@@ -7843,14 +7853,16 @@ function seoCopilotInspector(config) {
|
|
|
7843
7853
|
}
|
|
7844
7854
|
|
|
7845
7855
|
// src/index.ts
|
|
7846
|
-
var seoCopilot = (0, import_sanity5.definePlugin)((config) =>
|
|
7847
|
-
|
|
7848
|
-
|
|
7849
|
-
|
|
7850
|
-
|
|
7856
|
+
var seoCopilot = (0, import_sanity5.definePlugin)((config) => {
|
|
7857
|
+
return {
|
|
7858
|
+
name: "seo-copilot",
|
|
7859
|
+
document: {
|
|
7860
|
+
inspectors: (prev) => {
|
|
7861
|
+
return [...prev, seoCopilotInspector(config)];
|
|
7862
|
+
}
|
|
7851
7863
|
}
|
|
7852
|
-
}
|
|
7853
|
-
})
|
|
7864
|
+
};
|
|
7865
|
+
});
|
|
7854
7866
|
// Annotate the CommonJS export names for ESM import in node:
|
|
7855
7867
|
0 && (module.exports = {
|
|
7856
7868
|
seoCopilot
|