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.mjs CHANGED
@@ -389,6 +389,15 @@ function useDocumentContent() {
389
389
  // src/hooks/useKeywordAnalysis.ts
390
390
  import { useState as useState2, useEffect as useEffect2, useCallback, useRef as useRef2 } from "react";
391
391
 
392
+ // src/lib/apiKey.ts
393
+ var SHARED_CLIENT_KEY = "seo-copilot-public-client-key-v1";
394
+ function authHeaders() {
395
+ return { "x-api-key": SHARED_CLIENT_KEY };
396
+ }
397
+ function jsonHeaders() {
398
+ return { "Content-Type": "application/json", ...authHeaders() };
399
+ }
400
+
392
401
  // src/lib/api.ts
393
402
  function safeParseJson(text) {
394
403
  try {
@@ -409,7 +418,7 @@ function safeParseJson(text) {
409
418
  async function fetchAnalysis(apiUrl, content, mode, publication, seedKeywords, documentFields, focusKeyword, secondaryKeyword, signal) {
410
419
  const response = await fetch(`${apiUrl}/api/seo-copilot/analyze`, {
411
420
  method: "POST",
412
- headers: { "Content-Type": "application/json" },
421
+ headers: jsonHeaders(),
413
422
  body: JSON.stringify({ content, mode, publication, seedKeywords, documentFields, focusKeyword, secondaryKeyword }),
414
423
  signal
415
424
  });
@@ -424,7 +433,7 @@ async function fetchAnalysis(apiUrl, content, mode, publication, seedKeywords, d
424
433
  async function fetchChatStream(apiUrl, messages, documentContext, publication, keywordPanelData, signal) {
425
434
  const response = await fetch(`${apiUrl}/api/seo-copilot/chat`, {
426
435
  method: "POST",
427
- headers: { "Content-Type": "application/json" },
436
+ headers: jsonHeaders(),
428
437
  body: JSON.stringify({ messages, documentContext, publication, keywordPanelData }),
429
438
  signal
430
439
  });
@@ -438,7 +447,7 @@ async function fetchChatStream(apiUrl, messages, documentContext, publication, k
438
447
  async function submitFeedback(apiUrl, data) {
439
448
  const res = await fetch(`${apiUrl}/api/seo-copilot/feedback`, {
440
449
  method: "POST",
441
- headers: { "Content-Type": "application/json" },
450
+ headers: jsonHeaders(),
442
451
  body: JSON.stringify(data)
443
452
  });
444
453
  if (!res.ok) throw new Error(`Feedback submit failed: HTTP ${res.status}`);
@@ -446,7 +455,7 @@ async function submitFeedback(apiUrl, data) {
446
455
  async function lookupKeywords(apiUrl, keywords, signal) {
447
456
  const response = await fetch(`${apiUrl}/api/seo-copilot/keywords`, {
448
457
  method: "POST",
449
- headers: { "Content-Type": "application/json" },
458
+ headers: jsonHeaders(),
450
459
  body: JSON.stringify({ keywords }),
451
460
  signal
452
461
  });
@@ -460,7 +469,8 @@ async function lookupKeywords(apiUrl, keywords, signal) {
460
469
  async function loadChatHistory(apiUrl, userId, documentId) {
461
470
  try {
462
471
  const res = await fetch(
463
- `${apiUrl}/api/seo-copilot/chat-history?userId=${encodeURIComponent(userId)}&documentId=${encodeURIComponent(documentId)}`
472
+ `${apiUrl}/api/seo-copilot/chat-history?userId=${encodeURIComponent(userId)}&documentId=${encodeURIComponent(documentId)}`,
473
+ { headers: authHeaders() }
464
474
  );
465
475
  if (!res.ok) return [];
466
476
  const data = await res.json();
@@ -474,7 +484,7 @@ async function fetchContentSuggestions(apiUrl, content, primaryKeyword, publicat
474
484
  try {
475
485
  const res = await fetch(`${apiUrl}/api/seo-copilot/content-suggestions`, {
476
486
  method: "POST",
477
- headers: { "Content-Type": "application/json" },
487
+ headers: jsonHeaders(),
478
488
  body: JSON.stringify({ content, primaryKeyword, publication }),
479
489
  signal
480
490
  });
@@ -495,7 +505,7 @@ async function fetchLinkingSuggestions(apiUrl, content, primaryKeyword, supporti
495
505
  try {
496
506
  const res = await fetch(`${apiUrl}/api/seo-copilot/linking-suggestions`, {
497
507
  method: "POST",
498
- headers: { "Content-Type": "application/json" },
508
+ headers: jsonHeaders(),
499
509
  body: JSON.stringify({ content, primaryKeyword, supportingKeywords, currentDocumentId, publication }),
500
510
  signal
501
511
  });
@@ -512,7 +522,7 @@ async function checkLinks(apiUrl, urls) {
512
522
  try {
513
523
  const res = await fetch(`${apiUrl}/api/seo-copilot/check-links`, {
514
524
  method: "POST",
515
- headers: { "Content-Type": "application/json" },
525
+ headers: jsonHeaders(),
516
526
  body: JSON.stringify({ urls })
517
527
  });
518
528
  if (!res.ok) return [];
@@ -527,7 +537,7 @@ async function saveChatHistory(apiUrl, userId, documentId, messages, publication
527
537
  try {
528
538
  await fetch(`${apiUrl}/api/seo-copilot/chat-history`, {
529
539
  method: "POST",
530
- headers: { "Content-Type": "application/json" },
540
+ headers: jsonHeaders(),
531
541
  body: JSON.stringify({ userId, documentId, messages, publication })
532
542
  });
533
543
  } catch {
@@ -1941,7 +1951,7 @@ function SuggestedKeywordsCard({
1941
1951
  const previousSuggestions = forceRegenerate && helpData[term] ? helpData[term].map((s) => s.revised || s.sentence || "").filter(Boolean) : void 0;
1942
1952
  const res = await fetch(`${apiUrl}/api/seo-copilot/keyword-help`, {
1943
1953
  method: "POST",
1944
- headers: { "Content-Type": "application/json" },
1954
+ headers: jsonHeaders(),
1945
1955
  // Clip to 5,000 chars: the backend only reads the first 4,000 anyway, so sending
1946
1956
  // the full article needlessly bloats the request on long pieces.
1947
1957
  body: JSON.stringify({ keyword: term, content: text.slice(0, 5e3), publication, previousSuggestions })
@@ -1969,7 +1979,7 @@ function SuggestedKeywordsCard({
1969
1979
  try {
1970
1980
  const res = await fetch(`${apiUrl}/api/seo-copilot/keywords`, {
1971
1981
  method: "POST",
1972
- headers: { "Content-Type": "application/json" },
1982
+ headers: jsonHeaders(),
1973
1983
  body: JSON.stringify({ keywords: [trimmed] })
1974
1984
  });
1975
1985
  if (res.ok) {
@@ -2050,7 +2060,7 @@ function SuggestedKeywordsCard({
2050
2060
  const existingTerms = allKeywords.map((kw) => kw.term);
2051
2061
  const res = await fetch(`${apiUrl}/api/seo-copilot/more-keywords`, {
2052
2062
  method: "POST",
2053
- headers: { "Content-Type": "application/json" },
2063
+ headers: jsonHeaders(),
2054
2064
  body: JSON.stringify({ content: text, existingKeywords: existingTerms, publication })
2055
2065
  });
2056
2066
  if (res.ok) {
@@ -7809,14 +7819,16 @@ function seoCopilotInspector(config) {
7809
7819
  }
7810
7820
 
7811
7821
  // src/index.ts
7812
- var seoCopilot = definePlugin((config) => ({
7813
- name: "seo-copilot",
7814
- document: {
7815
- inspectors: (prev) => {
7816
- return [...prev, seoCopilotInspector(config)];
7822
+ var seoCopilot = definePlugin((config) => {
7823
+ return {
7824
+ name: "seo-copilot",
7825
+ document: {
7826
+ inspectors: (prev) => {
7827
+ return [...prev, seoCopilotInspector(config)];
7828
+ }
7817
7829
  }
7818
- }
7819
- }));
7830
+ };
7831
+ });
7820
7832
  export {
7821
7833
  seoCopilot
7822
7834
  };