@canonry/canonry 7.57.0 → 7.57.2
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/assets/assets/{AgentSetupPage-C-kQupMX.js → AgentSetupPage-Cc_zsHR0.js} +1 -1
- package/assets/assets/{AuditHistoryPanel-DvZk-ikR.js → AuditHistoryPanel-vMTAZBj_.js} +1 -1
- package/assets/assets/{BacklinksPage-TLB85t4y.js → BacklinksPage-CbploUJf.js} +1 -1
- package/assets/assets/{HistoryPage-C4nHeKDs.js → HistoryPage-m-59cu3N.js} +1 -1
- package/assets/assets/{MeasurementPropertyPage-8E17rN5d.js → MeasurementPropertyPage-C68Gtag-.js} +1 -1
- package/assets/assets/{ProjectPage-B4SbAE_N.js → ProjectPage-BLdhBCRJ.js} +1 -1
- package/assets/assets/{RunsPage-Enho1Wqz.js → RunsPage-qnNeAXTI.js} +1 -1
- package/assets/assets/{SettingsPage-BjLpSN4f.js → SettingsPage-UT9KpfMj.js} +1 -1
- package/assets/assets/{SiteHealthSection-BUOBO4VH.js → SiteHealthSection-DUYFjszN.js} +2 -2
- package/assets/assets/{ToneBadge-BLQKJIMR.js → ToneBadge-Yt2Lm4cB.js} +1 -1
- package/assets/assets/{TrafficPage-BtjRPsdl.js → TrafficPage-BPwgnTWA.js} +1 -1
- package/assets/assets/{TrafficSourceDetailPage-Bw-9JMOF.js → TrafficSourceDetailPage-D7_b16wr.js} +1 -1
- package/assets/assets/{account-context-bLel7cL8.js → account-context-BAJ4-K7g.js} +1 -1
- package/assets/assets/{card-DFlbarlV.js → card-OSE9muoF.js} +1 -1
- package/assets/assets/{extract-error-message-BYvs9oIt.js → extract-error-message-CmAMG5OS.js} +1 -1
- package/assets/assets/{format-helpers-DPVlVrlp.js → format-helpers-k8DWKWfO.js} +1 -1
- package/assets/assets/{index-DWP0Oz6d.js → index-C04O5pbQ.js} +4 -4
- package/assets/assets/{query-client-DLuEpFRm.js → query-client-CmCGzr9j.js} +1 -1
- package/assets/assets/{react-query-BVY1CIRz.js → react-query-CWskqnJ3.js} +1 -1
- package/assets/assets/{react-sigma_core.esm.min-BaR2koVY.js → react-sigma_core.esm.min-DLc_m5Ao.js} +1 -1
- package/assets/assets/{service-DiBkOka7.js → service-B51xJDz2.js} +1 -1
- package/assets/index.html +7 -7
- package/dist/{ads-6PCFYPZ6.js → ads-5ZKOYN72.js} +3 -3
- package/dist/{agent-UA3J23KG.js → agent-Q63YJLFN.js} +7 -7
- package/dist/{agent-ask-D4RWVHZX.js → agent-ask-5EZKRAMG.js} +3 -3
- package/dist/{agent-conversations-BSKUJF7H.js → agent-conversations-B3P2DHD2.js} +3 -3
- package/dist/{agent-memory-ENPPLOV7.js → agent-memory-4672STKY.js} +3 -3
- package/dist/{agent-providers-5NV7YEVG.js → agent-providers-IARC3ZE6.js} +3 -3
- package/dist/{agent-transcript-TXDTQ7Q2.js → agent-transcript-CQLUO6TR.js} +3 -3
- package/dist/{analytics-6ITOJIGW.js → analytics-HBWILHPQ.js} +3 -3
- package/dist/{apply-EPQXYQRO.js → apply-YRVGOW4D.js} +3 -3
- package/dist/{backfill-4LAL4IIT.js → backfill-T2R2QTOZ.js} +9 -9
- package/dist/{backlinks-ECIDQQ4I.js → backlinks-KOSJ4BAT.js} +3 -3
- package/dist/{bing-LHTVVJK7.js → bing-LYCNZP6M.js} +3 -3
- package/dist/{bootstrap-KHYUCFLP.js → bootstrap-AI7CKW3E.js} +10 -10
- package/dist/{cdp-YZWEKVRO.js → cdp-LP3GDIXS.js} +7 -7
- package/dist/{chunk-VF36TGF4.js → chunk-2THE4GKG.js} +1 -1
- package/dist/{chunk-3HRHHFQM.js → chunk-3PMACMXD.js} +1 -1
- package/dist/{chunk-TXBL3N46.js → chunk-42V5EYJX.js} +1 -1
- package/dist/{chunk-2R32P77U.js → chunk-46S3COHT.js} +1 -1
- package/dist/{chunk-OJ5IDPYY.js → chunk-4NDWRR4B.js} +3 -3
- package/dist/{chunk-JQS2H65K.js → chunk-4PYN2J6Z.js} +330 -330
- package/dist/{chunk-LCC5ZJPV.js → chunk-7RLF3PV4.js} +2 -2
- package/dist/{chunk-6MK426LA.js → chunk-ADWVQ3UM.js} +2 -2
- package/dist/{chunk-5L2ZTXBH.js → chunk-BM4AWHD6.js} +3 -3
- package/dist/{chunk-E3YBETL6.js → chunk-BMLVLHSH.js} +1 -1
- package/dist/{chunk-3OTH3ABK.js → chunk-DJ4YDAI6.js} +4 -4
- package/dist/{chunk-5AJWITKP.js → chunk-EIGZFAQJ.js} +1 -1
- package/dist/{chunk-YFUQHJRZ.js → chunk-FILMLHNG.js} +1 -1
- package/dist/{chunk-TIYL4KVS.js → chunk-HRYRYUI2.js} +1 -1
- package/dist/{chunk-MVUYDJ7G.js → chunk-ICVMS2JE.js} +2 -2
- package/dist/{chunk-FHYOQI26.js → chunk-IVSJLTKC.js} +522 -457
- package/dist/{chunk-SOKD3TRA.js → chunk-JZX4CR7V.js} +2 -2
- package/dist/{chunk-522MYBLV.js → chunk-KZZAU4SN.js} +1 -1
- package/dist/{chunk-TIKT62IV.js → chunk-LACYPNQA.js} +2 -0
- package/dist/{chunk-GT7HWKBO.js → chunk-MUSBD3EX.js} +3 -3
- package/dist/{chunk-J4YFSAAY.js → chunk-N3WRXGRW.js} +8 -8
- package/dist/{chunk-NUHCDBKR.js → chunk-PXEU7GIW.js} +5 -5
- package/dist/{chunk-KRIZF753.js → chunk-QN3YYE4J.js} +1 -1
- package/dist/{chunk-HPC3CBPI.js → chunk-QTFHMU6I.js} +1 -1
- package/dist/{chunk-ULFDCKIC.js → chunk-T76XI4DS.js} +4 -4
- package/dist/{chunk-F7WRZW3A.js → chunk-TAEBXXGQ.js} +3 -3
- package/dist/{chunk-ZUAXF73A.js → chunk-TCXRQZYE.js} +1 -1
- package/dist/{chunk-BURMKOEF.js → chunk-TRXD3CXS.js} +2 -2
- package/dist/{chunk-JWBFDZIP.js → chunk-TX6JOU2D.js} +3 -3
- package/dist/{chunk-OAA7RHMG.js → chunk-UMMF5KC5.js} +5 -5
- package/dist/{chunk-BJN7FNIB.js → chunk-WODNZ6PH.js} +4 -4
- package/dist/{chunk-S2UDQAT7.js → chunk-XJJNKNX3.js} +1 -1
- package/dist/{chunk-SHUTA74W.js → chunk-YWUB5ZU6.js} +20 -20
- package/dist/{chunk-XXYBDAS2.js → chunk-ZD37CGTP.js} +2 -2
- package/dist/{citations-HXVWVRDO.js → citations-XUAOQHRF.js} +3 -3
- package/dist/{cli-catalog-EDAH3242.js → cli-catalog-R6JZ5ELQ.js} +3 -3
- package/dist/{cli-commands-NUXQWIKA.js → cli-commands-YFN3ZE4O.js} +7 -7
- package/dist/cli.js +13 -13
- package/dist/{competitor-XYPBUM4Q.js → competitor-67DBTBBA.js} +3 -3
- package/dist/{content-SDTRO2XT.js → content-3OVMQETU.js} +3 -3
- package/dist/{dashboard-55IRUB73.js → dashboard-LFJXKLFE.js} +6 -6
- package/dist/{demo-KEFXTKRQ.js → demo-6ANGZSRC.js} +1 -1
- package/dist/{demo-server-BDQDPUWN.js → demo-server-HUVMI3XH.js} +11 -11
- package/dist/{discover-I6AQJPUK.js → discover-YF3FDGSD.js} +3 -3
- package/dist/{discover-eval-GLGBZC7B.js → discover-eval-CMHDYK5O.js} +3 -3
- package/dist/{doctor-Q47J7GZI.js → doctor-WKNWJSK4.js} +3 -3
- package/dist/{evidence-AMLTPRHA.js → evidence-CLNQ2CYR.js} +3 -3
- package/dist/{export-cmd-NTCX43DE.js → export-cmd-OHRV4TVH.js} +3 -3
- package/dist/{ga-END6LQJW.js → ga-FX742WRJ.js} +3 -3
- package/dist/{gbp-CVJXSTTB.js → gbp-MRQ4IZCG.js} +3 -3
- package/dist/{google-4OCFGWGV.js → google-C7TZMMMK.js} +4 -4
- package/dist/{google-marketing-NW27PADK.js → google-marketing-D2UGYDMK.js} +1 -1
- package/dist/{health-cmd-2KMNASB3.js → health-cmd-67I3W2ZU.js} +3 -3
- package/dist/{history-6LBFXVKF.js → history-ZWVARGNG.js} +3 -3
- package/dist/index.d.ts +10 -10
- package/dist/index.js +24 -24
- package/dist/{init-542CZBNS.js → init-AOBSZ2LL.js} +11 -11
- package/dist/{insights-YH7NP5LX.js → insights-7LBGR4WZ.js} +3 -3
- package/dist/intelligence-service-B266DYRT.js +15 -0
- package/dist/{keys-CJ5DTL4Y.js → keys-6QJRMT55.js} +3 -3
- package/dist/{keyword-7FMLF3B7.js → keyword-OPBDMSWK.js} +3 -3
- package/dist/{logs-362Y2Z55.js → logs-EGD3OBA4.js} +3 -3
- package/dist/{mcp-RTJ3HZLY.js → mcp-KAM74JPU.js} +2 -2
- package/dist/mcp.js +9 -9
- package/dist/{measurement-plan-ICT6U62D.js → measurement-plan-V53W3HSX.js} +5 -5
- package/dist/{notify-HT7QBF3B.js → notify-KYZJ2RDC.js} +3 -3
- package/dist/{organic-evidence-CAGEQ5OR.js → organic-evidence-N53Z2XJH.js} +3 -3
- package/dist/{overview-Y6RVRPC7.js → overview-BE25C6Q5.js} +4 -4
- package/dist/{project-7OBPDHLH.js → project-NO32ZURN.js} +3 -3
- package/dist/{query-23GN3BC6.js → query-NKVTEXLS.js} +3 -3
- package/dist/{research-N7EVBN47.js → research-YISKR3TJ.js} +3 -3
- package/dist/{results-export-BHEYAZXQ.js → results-export-HD6Q6ZNB.js} +3 -3
- package/dist/{run-KVPMLHGQ.js → run-MAOMVPZL.js} +4 -4
- package/dist/{schedule-EZ2TLM22.js → schedule-NWDR5YEK.js} +3 -3
- package/dist/{search-UHUPUGT3.js → search-PBA5FKL7.js} +3 -3
- package/dist/{serve-R2OR4ZF2.js → serve-VRTPB4I3.js} +25 -25
- package/dist/{session-CSYHALIE.js → session-M2SYYRPJ.js} +12 -12
- package/dist/{settings-QCFPNHSC.js → settings-Q2FL6ONA.js} +3 -3
- package/dist/{skills-FXPAKCVV.js → skills-7LRRFGYJ.js} +2 -2
- package/dist/{snapshot-NY5PNDWR.js → snapshot-BPYTJ4C4.js} +3 -3
- package/dist/{src-V6W5XBAI.js → src-5KXLTZQQ.js} +2 -2
- package/dist/{status-MYXAVPIB.js → status-T56ADODQ.js} +4 -4
- package/dist/{technical-aeo-4C2EQ6C5.js → technical-aeo-W5VS6DYU.js} +3 -3
- package/dist/{telemetry-SMY4NDD2.js → telemetry-4V3L3ZQ2.js} +4 -4
- package/dist/{tools-HIRCGFM2.js → tools-M4S6JACN.js} +11 -11
- package/dist/{traffic-QTHEOB5M.js → traffic-ESXWT2F2.js} +5 -5
- package/dist/{users-FDZPHCWI.js → users-YCOSFESL.js} +3 -3
- package/dist/{visibility-stats-6B3S3AIY.js → visibility-stats-AA4AQPSL.js} +3 -3
- package/dist/{wordpress-5IIA4H3G.js → wordpress-GSONHGOA.js} +3 -3
- package/package.json +1 -1
- package/dist/intelligence-service-6IVSAF2X.js +0 -15
|
@@ -6,14 +6,14 @@ import {
|
|
|
6
6
|
isSelfTraffic,
|
|
7
7
|
normalizeCloudflareWorkerEvent,
|
|
8
8
|
verifyRequestSignature
|
|
9
|
-
} from "./chunk-
|
|
9
|
+
} from "./chunk-42V5EYJX.js";
|
|
10
10
|
import {
|
|
11
11
|
currentOutcomeAttribution,
|
|
12
12
|
getRequestContext,
|
|
13
13
|
registerRequestContext,
|
|
14
14
|
requestAuditIdentity,
|
|
15
15
|
sanitizeRequestContext
|
|
16
|
-
} from "./chunk-
|
|
16
|
+
} from "./chunk-46S3COHT.js";
|
|
17
17
|
import {
|
|
18
18
|
SentimentIdempotencyConflict,
|
|
19
19
|
SentimentRepository,
|
|
@@ -144,7 +144,7 @@ import {
|
|
|
144
144
|
userSessions,
|
|
145
145
|
users,
|
|
146
146
|
writeNegativeReviewMaxStars
|
|
147
|
-
} from "./chunk-
|
|
147
|
+
} from "./chunk-EIGZFAQJ.js";
|
|
148
148
|
import {
|
|
149
149
|
ADS_ACTIVATE_SCOPE,
|
|
150
150
|
ADS_ACTIVATION_ABSOLUTE_MAX_ENTITIES,
|
|
@@ -1099,7 +1099,7 @@ import {
|
|
|
1099
1099
|
wordpressSchemaDeployResultDtoSchema,
|
|
1100
1100
|
wordpressSchemaStatusResultDtoSchema,
|
|
1101
1101
|
wordpressStatusDtoSchema
|
|
1102
|
-
} from "./chunk-
|
|
1102
|
+
} from "./chunk-LACYPNQA.js";
|
|
1103
1103
|
|
|
1104
1104
|
// ../api-routes/src/user-session.ts
|
|
1105
1105
|
import crypto2 from "crypto";
|
|
@@ -41910,20 +41910,33 @@ async function gbpFetchGet(url, accessToken, opts = {}) {
|
|
|
41910
41910
|
}
|
|
41911
41911
|
|
|
41912
41912
|
// ../integration-google-business-profile/src/local-posts-client.ts
|
|
41913
|
+
var GbpLocalPostResponseError = class extends Error {
|
|
41914
|
+
constructor(reason) {
|
|
41915
|
+
super(reason === "UNSUPPORTED_MEDIA" ? "Unsupported or incomplete Google Local Post media" : reason === "WRONG_IDENTITY" ? "Wrong Google Local Post identity" : "Invalid Google Local Post response");
|
|
41916
|
+
this.reason = reason;
|
|
41917
|
+
this.name = "GbpLocalPostResponseError";
|
|
41918
|
+
}
|
|
41919
|
+
reason;
|
|
41920
|
+
};
|
|
41913
41921
|
function parent(account, location) {
|
|
41914
41922
|
return `${gbpAccountNameSchema.parse(account)}/${gbpLocationNameSchema.parse(location)}`;
|
|
41915
41923
|
}
|
|
41916
|
-
function post(value) {
|
|
41924
|
+
function post(value, mediaMode = "exact") {
|
|
41917
41925
|
if (!value || typeof value !== "object")
|
|
41918
|
-
throw new
|
|
41926
|
+
throw new GbpLocalPostResponseError("INVALID_RESPONSE");
|
|
41919
41927
|
const raw = value;
|
|
41920
41928
|
const action = raw.callToAction;
|
|
41921
|
-
|
|
41922
|
-
|
|
41923
|
-
|
|
41924
|
-
))
|
|
41925
|
-
throw new
|
|
41926
|
-
|
|
41929
|
+
if (raw.media !== void 0 && !Array.isArray(raw.media))
|
|
41930
|
+
throw new GbpLocalPostResponseError("INVALID_RESPONSE");
|
|
41931
|
+
const media = raw.media ?? [];
|
|
41932
|
+
if (media.some((item2) => !item2 || typeof item2 !== "object" || Array.isArray(item2)))
|
|
41933
|
+
throw new GbpLocalPostResponseError("INVALID_RESPONSE");
|
|
41934
|
+
const mediaSourceUrlsComplete = media.every(
|
|
41935
|
+
(item2) => item2.mediaFormat === "PHOTO" && typeof item2.sourceUrl === "string"
|
|
41936
|
+
);
|
|
41937
|
+
if (!mediaSourceUrlsComplete && mediaMode === "exact")
|
|
41938
|
+
throw new GbpLocalPostResponseError("UNSUPPORTED_MEDIA");
|
|
41939
|
+
const parsed = gbpLocalPostDtoSchema.safeParse({
|
|
41927
41940
|
name: raw.name,
|
|
41928
41941
|
languageCode: raw.languageCode ?? "",
|
|
41929
41942
|
summary: raw.summary ?? "",
|
|
@@ -41931,11 +41944,14 @@ function post(value) {
|
|
|
41931
41944
|
state: raw.state ?? GbpLocalPostStates.LOCAL_POST_STATE_UNSPECIFIED,
|
|
41932
41945
|
actionType: action?.actionType ?? null,
|
|
41933
41946
|
articleUrl: action?.url ?? null,
|
|
41934
|
-
imageUrls: media.map((item2) => item2.sourceUrl),
|
|
41947
|
+
imageUrls: mediaSourceUrlsComplete ? media.map((item2) => item2.sourceUrl) : [],
|
|
41948
|
+
...mediaMode === "discovery" ? { mediaSourceUrlsComplete } : {},
|
|
41935
41949
|
createTime: raw.createTime,
|
|
41936
41950
|
updateTime: raw.updateTime,
|
|
41937
41951
|
searchUrl: raw.searchUrl ?? null
|
|
41938
41952
|
});
|
|
41953
|
+
if (!parsed.success) throw new GbpLocalPostResponseError("INVALID_RESPONSE");
|
|
41954
|
+
return parsed.data;
|
|
41939
41955
|
}
|
|
41940
41956
|
async function listLocalPosts(token, account, location, pageToken, options = {}) {
|
|
41941
41957
|
const scope = parent(account, location);
|
|
@@ -41943,9 +41959,11 @@ async function listLocalPosts(token, account, location, pageToken, options = {})
|
|
|
41943
41959
|
url.searchParams.set("pageSize", "100");
|
|
41944
41960
|
if (pageToken) url.searchParams.set("pageToken", pageToken);
|
|
41945
41961
|
const raw = await gbpFetchGet(url.toString(), token, options);
|
|
41946
|
-
|
|
41962
|
+
if (!raw || typeof raw !== "object" || Array.isArray(raw) || raw.localPosts !== void 0 && !Array.isArray(raw.localPosts))
|
|
41963
|
+
throw new GbpLocalPostResponseError("INVALID_RESPONSE");
|
|
41964
|
+
const posts = (raw.localPosts ?? []).map((item2) => post(item2, "discovery"));
|
|
41947
41965
|
if (posts.some((item2) => !item2.name.startsWith(`${scope}/localPosts/`)))
|
|
41948
|
-
throw new
|
|
41966
|
+
throw new GbpLocalPostResponseError("WRONG_IDENTITY");
|
|
41949
41967
|
return { posts, nextPageToken: raw.nextPageToken ?? null };
|
|
41950
41968
|
}
|
|
41951
41969
|
async function getLocalPost(token, name, options = {}) {
|
|
@@ -41953,7 +41971,7 @@ async function getLocalPost(token, name, options = {}) {
|
|
|
41953
41971
|
const result = post(
|
|
41954
41972
|
await gbpFetchGet(`${GBP_LEGACY_V4_BASE}/${name}`, token, options)
|
|
41955
41973
|
);
|
|
41956
|
-
if (result.name !== name) throw new
|
|
41974
|
+
if (result.name !== name) throw new GbpLocalPostResponseError("WRONG_IDENTITY");
|
|
41957
41975
|
return result;
|
|
41958
41976
|
}
|
|
41959
41977
|
async function createLocalPost(token, account, location, content) {
|
|
@@ -42299,6 +42317,417 @@ function classifyReviewsError(err) {
|
|
|
42299
42317
|
return { access: "error", reason: "NETWORK", projectWide: false };
|
|
42300
42318
|
}
|
|
42301
42319
|
|
|
42320
|
+
// ../integration-google/src/constants.ts
|
|
42321
|
+
var GOOGLE_AUTH_URL = "https://accounts.google.com/o/oauth2/v2/auth";
|
|
42322
|
+
var GOOGLE_TOKEN_URL = "https://oauth2.googleapis.com/token";
|
|
42323
|
+
var GSC_SCOPE = "https://www.googleapis.com/auth/webmasters";
|
|
42324
|
+
var GSC_READONLY_SCOPE = "https://www.googleapis.com/auth/webmasters.readonly";
|
|
42325
|
+
var INDEXING_SCOPE = "https://www.googleapis.com/auth/indexing";
|
|
42326
|
+
var GSC_API_BASE = "https://www.googleapis.com/webmasters/v3";
|
|
42327
|
+
var URL_INSPECTION_API = "https://searchconsole.googleapis.com/v1/urlInspection/index:inspect";
|
|
42328
|
+
var GSC_MAX_ROWS_PER_REQUEST = 25e3;
|
|
42329
|
+
var GSC_REPORTING_TIME_ZONE = "America/Los_Angeles";
|
|
42330
|
+
var GSC_DATA_LAG_DAYS = 3;
|
|
42331
|
+
var INDEXING_API_BASE = "https://indexing.googleapis.com/v3";
|
|
42332
|
+
var INDEXING_API_DAILY_LIMIT = 200;
|
|
42333
|
+
var GOOGLE_REQUEST_TIMEOUT_MS = 3e4;
|
|
42334
|
+
var GSC_MAX_PAGES = 40;
|
|
42335
|
+
|
|
42336
|
+
// ../integration-google/src/types.ts
|
|
42337
|
+
var GoogleAuthError = class extends Error {
|
|
42338
|
+
statusCode;
|
|
42339
|
+
constructor(message, statusCode) {
|
|
42340
|
+
super(message);
|
|
42341
|
+
this.name = "GoogleAuthError";
|
|
42342
|
+
this.statusCode = statusCode;
|
|
42343
|
+
}
|
|
42344
|
+
};
|
|
42345
|
+
var GoogleApiError = class extends Error {
|
|
42346
|
+
status;
|
|
42347
|
+
constructor(message, status) {
|
|
42348
|
+
super(message);
|
|
42349
|
+
this.name = "GoogleApiError";
|
|
42350
|
+
this.status = status;
|
|
42351
|
+
}
|
|
42352
|
+
};
|
|
42353
|
+
|
|
42354
|
+
// ../integration-google/src/oauth.ts
|
|
42355
|
+
function validateClientId(clientId) {
|
|
42356
|
+
if (!clientId || typeof clientId !== "string" || clientId.trim().length === 0) {
|
|
42357
|
+
throw new GoogleAuthError("Client ID is required and must be a non-empty string");
|
|
42358
|
+
}
|
|
42359
|
+
}
|
|
42360
|
+
function validateClientSecret(clientSecret) {
|
|
42361
|
+
if (!clientSecret || typeof clientSecret !== "string" || clientSecret.trim().length === 0) {
|
|
42362
|
+
throw new GoogleAuthError("Client secret is required and must be a non-empty string");
|
|
42363
|
+
}
|
|
42364
|
+
}
|
|
42365
|
+
function validateRedirectUri(redirectUri) {
|
|
42366
|
+
if (!redirectUri || typeof redirectUri !== "string" || redirectUri.trim().length === 0) {
|
|
42367
|
+
throw new GoogleAuthError("Redirect URI is required and must be a non-empty string");
|
|
42368
|
+
}
|
|
42369
|
+
try {
|
|
42370
|
+
const url = new URL(redirectUri);
|
|
42371
|
+
if (!url.protocol.startsWith("http")) {
|
|
42372
|
+
throw new GoogleAuthError("Redirect URI must be an HTTP or HTTPS URL");
|
|
42373
|
+
}
|
|
42374
|
+
} catch {
|
|
42375
|
+
throw new GoogleAuthError("Redirect URI must be a valid URL");
|
|
42376
|
+
}
|
|
42377
|
+
}
|
|
42378
|
+
function validateCode(code) {
|
|
42379
|
+
if (!code || typeof code !== "string" || code.trim().length === 0) {
|
|
42380
|
+
throw new GoogleAuthError("Authorization code is required and must be a non-empty string");
|
|
42381
|
+
}
|
|
42382
|
+
}
|
|
42383
|
+
function validateScopes(scopes) {
|
|
42384
|
+
if (!Array.isArray(scopes) || scopes.length === 0) {
|
|
42385
|
+
throw new GoogleAuthError("At least one scope is required");
|
|
42386
|
+
}
|
|
42387
|
+
for (const scope of scopes) {
|
|
42388
|
+
if (!scope || typeof scope !== "string" || scope.trim().length === 0) {
|
|
42389
|
+
throw new GoogleAuthError("Scope must be a non-empty string");
|
|
42390
|
+
}
|
|
42391
|
+
}
|
|
42392
|
+
}
|
|
42393
|
+
function validateRefreshToken(refreshToken) {
|
|
42394
|
+
if (!refreshToken || typeof refreshToken !== "string" || refreshToken.trim().length === 0) {
|
|
42395
|
+
throw new GoogleAuthError("Refresh token is required and must be a non-empty string");
|
|
42396
|
+
}
|
|
42397
|
+
}
|
|
42398
|
+
function getAuthUrl(clientId, redirectUri, scopes, state) {
|
|
42399
|
+
validateClientId(clientId);
|
|
42400
|
+
validateRedirectUri(redirectUri);
|
|
42401
|
+
validateScopes(scopes);
|
|
42402
|
+
if (state && (typeof state !== "string" || state.trim().length === 0)) {
|
|
42403
|
+
throw new GoogleAuthError("State must be a non-empty string if provided");
|
|
42404
|
+
}
|
|
42405
|
+
const params = new URLSearchParams({
|
|
42406
|
+
client_id: clientId,
|
|
42407
|
+
redirect_uri: redirectUri,
|
|
42408
|
+
response_type: "code",
|
|
42409
|
+
scope: scopes.join(" "),
|
|
42410
|
+
access_type: "offline",
|
|
42411
|
+
prompt: "consent"
|
|
42412
|
+
});
|
|
42413
|
+
if (state) params.set("state", state);
|
|
42414
|
+
return `${GOOGLE_AUTH_URL}?${params.toString()}`;
|
|
42415
|
+
}
|
|
42416
|
+
async function exchangeCode(clientId, clientSecret, code, redirectUri) {
|
|
42417
|
+
validateClientId(clientId);
|
|
42418
|
+
validateClientSecret(clientSecret);
|
|
42419
|
+
validateCode(code);
|
|
42420
|
+
validateRedirectUri(redirectUri);
|
|
42421
|
+
const res = await fetch(GOOGLE_TOKEN_URL, {
|
|
42422
|
+
method: "POST",
|
|
42423
|
+
headers: { "Content-Type": "application/x-www-form-urlencoded" },
|
|
42424
|
+
body: new URLSearchParams({
|
|
42425
|
+
client_id: clientId,
|
|
42426
|
+
client_secret: clientSecret,
|
|
42427
|
+
code,
|
|
42428
|
+
redirect_uri: redirectUri,
|
|
42429
|
+
grant_type: "authorization_code"
|
|
42430
|
+
}),
|
|
42431
|
+
signal: AbortSignal.timeout(GOOGLE_REQUEST_TIMEOUT_MS)
|
|
42432
|
+
});
|
|
42433
|
+
if (res.status === 429) {
|
|
42434
|
+
throw new GoogleAuthError("Google OAuth rate limit exceeded", 429);
|
|
42435
|
+
}
|
|
42436
|
+
if (!res.ok) {
|
|
42437
|
+
const body = await res.text();
|
|
42438
|
+
let detail = "";
|
|
42439
|
+
try {
|
|
42440
|
+
const parsed = JSON.parse(body);
|
|
42441
|
+
if (parsed.error) detail = parsed.error;
|
|
42442
|
+
if (parsed.error_description) {
|
|
42443
|
+
const sanitized = parsed.error_description.replace(new RegExp(escapeRegExp2(clientId), "g"), "***").replace(new RegExp(escapeRegExp2(clientSecret), "g"), "***").replace(new RegExp(escapeRegExp2(code), "g"), "***");
|
|
42444
|
+
detail += detail ? `: ${sanitized}` : sanitized;
|
|
42445
|
+
}
|
|
42446
|
+
} catch {
|
|
42447
|
+
const truncated = body.length <= 120 ? body : `${body.slice(0, 120)}...`;
|
|
42448
|
+
detail = truncated.replace(new RegExp(escapeRegExp2(clientId), "g"), "***").replace(new RegExp(escapeRegExp2(clientSecret), "g"), "***").replace(new RegExp(escapeRegExp2(code), "g"), "***");
|
|
42449
|
+
}
|
|
42450
|
+
throw new GoogleAuthError(`Token exchange failed (${res.status}): ${detail}`);
|
|
42451
|
+
}
|
|
42452
|
+
return await res.json();
|
|
42453
|
+
}
|
|
42454
|
+
function escapeRegExp2(str) {
|
|
42455
|
+
return str.replace(/[.*+?^${}()|[\]\\]/g, "\\$&");
|
|
42456
|
+
}
|
|
42457
|
+
async function refreshAccessToken(clientId, clientSecret, currentRefreshToken) {
|
|
42458
|
+
validateClientId(clientId);
|
|
42459
|
+
validateClientSecret(clientSecret);
|
|
42460
|
+
validateRefreshToken(currentRefreshToken);
|
|
42461
|
+
const res = await fetch(GOOGLE_TOKEN_URL, {
|
|
42462
|
+
method: "POST",
|
|
42463
|
+
headers: { "Content-Type": "application/x-www-form-urlencoded" },
|
|
42464
|
+
body: new URLSearchParams({
|
|
42465
|
+
client_id: clientId,
|
|
42466
|
+
client_secret: clientSecret,
|
|
42467
|
+
refresh_token: currentRefreshToken,
|
|
42468
|
+
grant_type: "refresh_token"
|
|
42469
|
+
}),
|
|
42470
|
+
signal: AbortSignal.timeout(GOOGLE_REQUEST_TIMEOUT_MS)
|
|
42471
|
+
});
|
|
42472
|
+
if (res.status === 429) {
|
|
42473
|
+
throw new GoogleAuthError("Google OAuth rate limit exceeded", 429);
|
|
42474
|
+
}
|
|
42475
|
+
if (!res.ok) {
|
|
42476
|
+
const body = await res.text();
|
|
42477
|
+
let detail = "";
|
|
42478
|
+
try {
|
|
42479
|
+
const parsed = JSON.parse(body);
|
|
42480
|
+
if (parsed.error) detail = parsed.error;
|
|
42481
|
+
if (parsed.error_description) {
|
|
42482
|
+
const sanitized = parsed.error_description.replace(new RegExp(escapeRegExp2(clientId), "g"), "***").replace(new RegExp(escapeRegExp2(clientSecret), "g"), "***").replace(new RegExp(escapeRegExp2(currentRefreshToken), "g"), "***");
|
|
42483
|
+
detail += detail ? `: ${sanitized}` : sanitized;
|
|
42484
|
+
}
|
|
42485
|
+
} catch {
|
|
42486
|
+
const truncated = body.length <= 120 ? body : `${body.slice(0, 120)}...`;
|
|
42487
|
+
detail = truncated.replace(new RegExp(escapeRegExp2(clientId), "g"), "***").replace(new RegExp(escapeRegExp2(clientSecret), "g"), "***").replace(new RegExp(escapeRegExp2(currentRefreshToken), "g"), "***");
|
|
42488
|
+
}
|
|
42489
|
+
throw new GoogleAuthError(`Token refresh failed (${res.status}): ${detail}`);
|
|
42490
|
+
}
|
|
42491
|
+
return await res.json();
|
|
42492
|
+
}
|
|
42493
|
+
|
|
42494
|
+
// ../integration-google/src/gsc-client.ts
|
|
42495
|
+
function validateAccessToken(accessToken) {
|
|
42496
|
+
if (!accessToken || typeof accessToken !== "string" || accessToken.trim().length === 0) {
|
|
42497
|
+
throw new GoogleApiError("Access token is required and must be a non-empty string", 400);
|
|
42498
|
+
}
|
|
42499
|
+
}
|
|
42500
|
+
function validateSiteUrl(siteUrl) {
|
|
42501
|
+
if (!siteUrl || typeof siteUrl !== "string" || siteUrl.trim().length === 0) {
|
|
42502
|
+
throw new GoogleApiError("Site URL is required and must be a non-empty string", 400);
|
|
42503
|
+
}
|
|
42504
|
+
if (/^\d+$/.test(siteUrl)) {
|
|
42505
|
+
return;
|
|
42506
|
+
}
|
|
42507
|
+
if (siteUrl.startsWith("sc-domain:")) {
|
|
42508
|
+
const domain = siteUrl.slice("sc-domain:".length);
|
|
42509
|
+
if (!domain) {
|
|
42510
|
+
throw new GoogleApiError("Site URL sc-domain must include a domain", 400);
|
|
42511
|
+
}
|
|
42512
|
+
if (!domain.includes(".")) {
|
|
42513
|
+
throw new GoogleApiError("Site URL sc-domain must be a valid domain", 400);
|
|
42514
|
+
}
|
|
42515
|
+
} else {
|
|
42516
|
+
try {
|
|
42517
|
+
const url = new URL(siteUrl);
|
|
42518
|
+
if (!url.protocol.startsWith("http")) {
|
|
42519
|
+
throw new GoogleApiError("Site URL must be an HTTP or HTTPS URL", 400);
|
|
42520
|
+
}
|
|
42521
|
+
} catch {
|
|
42522
|
+
throw new GoogleApiError("Site URL must be a valid URL", 400);
|
|
42523
|
+
}
|
|
42524
|
+
}
|
|
42525
|
+
}
|
|
42526
|
+
function validateUrl(urlParam) {
|
|
42527
|
+
if (!urlParam || typeof urlParam !== "string" || urlParam.trim().length === 0) {
|
|
42528
|
+
throw new GoogleApiError("URL is required and must be a non-empty string", 400);
|
|
42529
|
+
}
|
|
42530
|
+
try {
|
|
42531
|
+
const url = new URL(urlParam);
|
|
42532
|
+
if (!url.protocol.startsWith("http")) {
|
|
42533
|
+
throw new GoogleApiError("URL must be an HTTP or HTTPS URL", 400);
|
|
42534
|
+
}
|
|
42535
|
+
} catch {
|
|
42536
|
+
throw new GoogleApiError("URL must be a valid URL", 400);
|
|
42537
|
+
}
|
|
42538
|
+
}
|
|
42539
|
+
function validateDate(date, label) {
|
|
42540
|
+
if (!date || typeof date !== "string" || date.trim().length === 0) {
|
|
42541
|
+
throw new GoogleApiError(`${label} is required and must be a non-empty string`, 400);
|
|
42542
|
+
}
|
|
42543
|
+
if (!/^\d{4}-\d{2}-\d{2}$/.test(date)) {
|
|
42544
|
+
throw new GoogleApiError(`${label} must be in YYYY-MM-DD format, got "${date}"`, 400);
|
|
42545
|
+
}
|
|
42546
|
+
const parsed = /* @__PURE__ */ new Date(`${date}T00:00:00Z`);
|
|
42547
|
+
if (Number.isNaN(parsed.getTime())) {
|
|
42548
|
+
throw new GoogleApiError(`${label} is not a valid date, got "${date}"`, 400);
|
|
42549
|
+
}
|
|
42550
|
+
}
|
|
42551
|
+
function gscClientLog(level, action, ctx) {
|
|
42552
|
+
const entry = {
|
|
42553
|
+
ts: (/* @__PURE__ */ new Date()).toISOString(),
|
|
42554
|
+
level,
|
|
42555
|
+
module: "GscClient",
|
|
42556
|
+
action,
|
|
42557
|
+
...ctx
|
|
42558
|
+
};
|
|
42559
|
+
if (entry.accessToken) entry.accessToken = "***";
|
|
42560
|
+
if (typeof entry.siteUrl === "string") {
|
|
42561
|
+
try {
|
|
42562
|
+
const url = new URL(entry.siteUrl);
|
|
42563
|
+
if (url.search) {
|
|
42564
|
+
url.searchParams.forEach((_, key) => {
|
|
42565
|
+
if (key.toLowerCase().includes("token") || key.toLowerCase().includes("key") || key.toLowerCase().includes("auth")) {
|
|
42566
|
+
url.searchParams.set(key, "***");
|
|
42567
|
+
}
|
|
42568
|
+
});
|
|
42569
|
+
entry.siteUrl = url.toString();
|
|
42570
|
+
}
|
|
42571
|
+
} catch {
|
|
42572
|
+
}
|
|
42573
|
+
}
|
|
42574
|
+
const stream = level === "error" ? process.stderr : process.stdout;
|
|
42575
|
+
stream.write(JSON.stringify(entry) + "\n");
|
|
42576
|
+
}
|
|
42577
|
+
function escapeRegExp3(str) {
|
|
42578
|
+
return str.replace(/[.*+?^${}()|[\]\\]/g, "\\$&");
|
|
42579
|
+
}
|
|
42580
|
+
async function gscFetchResponse(accessToken, url, opts) {
|
|
42581
|
+
const method = opts?.method ?? "GET";
|
|
42582
|
+
const headers = {
|
|
42583
|
+
Authorization: `Bearer ${accessToken}`,
|
|
42584
|
+
"Content-Type": "application/json"
|
|
42585
|
+
};
|
|
42586
|
+
let res;
|
|
42587
|
+
try {
|
|
42588
|
+
res = await fetch(url, {
|
|
42589
|
+
method,
|
|
42590
|
+
headers,
|
|
42591
|
+
body: opts?.body != null ? JSON.stringify(opts.body) : void 0,
|
|
42592
|
+
signal: AbortSignal.timeout(GOOGLE_REQUEST_TIMEOUT_MS)
|
|
42593
|
+
});
|
|
42594
|
+
} catch (error) {
|
|
42595
|
+
throw new Error(describeFetchError(error, url), { cause: error });
|
|
42596
|
+
}
|
|
42597
|
+
if (res.status === 401) {
|
|
42598
|
+
gscClientLog("error", "http.auth-expired", { url, method, httpStatus: 401 });
|
|
42599
|
+
throw new GoogleApiError("Access token expired or revoked", 401);
|
|
42600
|
+
}
|
|
42601
|
+
if (res.status === 429) {
|
|
42602
|
+
gscClientLog("error", "http.rate-limited", { url, method, httpStatus: 429 });
|
|
42603
|
+
throw new GoogleApiError("Google API rate limit exceeded", 429);
|
|
42604
|
+
}
|
|
42605
|
+
if (!res.ok) {
|
|
42606
|
+
const body = await res.text();
|
|
42607
|
+
gscClientLog("error", "http.error", { url, method, httpStatus: res.status });
|
|
42608
|
+
const detail = body.length <= 500 ? body : `${body.slice(0, 500)}... [truncated]`;
|
|
42609
|
+
let sanitizedDetail = detail;
|
|
42610
|
+
if (accessToken) {
|
|
42611
|
+
sanitizedDetail = sanitizedDetail.replace(new RegExp(escapeRegExp3(accessToken), "g"), "***");
|
|
42612
|
+
}
|
|
42613
|
+
throw new GoogleApiError(`GSC API error (${res.status}): ${sanitizedDetail}`, res.status);
|
|
42614
|
+
}
|
|
42615
|
+
return res;
|
|
42616
|
+
}
|
|
42617
|
+
async function gscFetchJson(accessToken, url, opts) {
|
|
42618
|
+
const res = await gscFetchResponse(accessToken, url, opts);
|
|
42619
|
+
const text = await res.text();
|
|
42620
|
+
if (!text) {
|
|
42621
|
+
throw new GoogleApiError("GSC API returned an empty response where JSON was expected", res.status);
|
|
42622
|
+
}
|
|
42623
|
+
try {
|
|
42624
|
+
return JSON.parse(text);
|
|
42625
|
+
} catch {
|
|
42626
|
+
throw new GoogleApiError("GSC API returned invalid JSON", res.status);
|
|
42627
|
+
}
|
|
42628
|
+
}
|
|
42629
|
+
async function listSites(accessToken) {
|
|
42630
|
+
validateAccessToken(accessToken);
|
|
42631
|
+
const data = await gscFetchJson(
|
|
42632
|
+
accessToken,
|
|
42633
|
+
`${GSC_API_BASE}/sites`
|
|
42634
|
+
);
|
|
42635
|
+
return data.siteEntry ?? [];
|
|
42636
|
+
}
|
|
42637
|
+
async function listSitemaps(accessToken, siteUrl, sitemapIndex) {
|
|
42638
|
+
validateAccessToken(accessToken);
|
|
42639
|
+
validateSiteUrl(siteUrl);
|
|
42640
|
+
if (sitemapIndex != null) validateUrl(sitemapIndex);
|
|
42641
|
+
const encodedSiteUrl = encodeURIComponent(siteUrl);
|
|
42642
|
+
const sitemapIndexQuery = sitemapIndex == null ? "" : `?sitemapIndex=${encodeURIComponent(sitemapIndex)}`;
|
|
42643
|
+
const data = await gscFetchJson(
|
|
42644
|
+
accessToken,
|
|
42645
|
+
`${GSC_API_BASE}/sites/${encodedSiteUrl}/sitemaps${sitemapIndexQuery}`
|
|
42646
|
+
);
|
|
42647
|
+
return data.sitemap ?? [];
|
|
42648
|
+
}
|
|
42649
|
+
async function submitSitemap(accessToken, siteUrl, sitemapUrl) {
|
|
42650
|
+
validateAccessToken(accessToken);
|
|
42651
|
+
validateSiteUrl(siteUrl);
|
|
42652
|
+
validateUrl(sitemapUrl);
|
|
42653
|
+
await gscFetchResponse(
|
|
42654
|
+
accessToken,
|
|
42655
|
+
`${GSC_API_BASE}/sites/${encodeURIComponent(siteUrl)}/sitemaps/${encodeURIComponent(sitemapUrl)}`,
|
|
42656
|
+
{ method: "PUT" }
|
|
42657
|
+
);
|
|
42658
|
+
}
|
|
42659
|
+
async function fetchSearchAnalytics(accessToken, siteUrl, opts) {
|
|
42660
|
+
validateAccessToken(accessToken);
|
|
42661
|
+
validateSiteUrl(siteUrl);
|
|
42662
|
+
validateDate(opts.startDate, "startDate");
|
|
42663
|
+
validateDate(opts.endDate, "endDate");
|
|
42664
|
+
const allRows = [];
|
|
42665
|
+
let startRow = 0;
|
|
42666
|
+
const dimensions = opts.dimensions ?? ["query", "page", "country", "device", "date"];
|
|
42667
|
+
for (; ; ) {
|
|
42668
|
+
if (startRow >= GSC_MAX_ROWS_PER_REQUEST * GSC_MAX_PAGES) {
|
|
42669
|
+
gscClientLog("error", "pagination.safety-limit", { siteUrl, startRow, maxRows: GSC_MAX_ROWS_PER_REQUEST * GSC_MAX_PAGES });
|
|
42670
|
+
break;
|
|
42671
|
+
}
|
|
42672
|
+
const requestBody = {
|
|
42673
|
+
startDate: opts.startDate,
|
|
42674
|
+
endDate: opts.endDate,
|
|
42675
|
+
dimensions,
|
|
42676
|
+
rowLimit: GSC_MAX_ROWS_PER_REQUEST,
|
|
42677
|
+
startRow
|
|
42678
|
+
};
|
|
42679
|
+
if (opts.query || opts.page) {
|
|
42680
|
+
const filters = [];
|
|
42681
|
+
const filterList = [];
|
|
42682
|
+
if (opts.query) filterList.push({ dimension: "query", operator: "contains", expression: opts.query });
|
|
42683
|
+
if (opts.page) filterList.push({ dimension: "page", operator: "contains", expression: opts.page });
|
|
42684
|
+
filters.push({ filters: filterList });
|
|
42685
|
+
requestBody.dimensionFilterGroups = filters;
|
|
42686
|
+
}
|
|
42687
|
+
const encodedSiteUrl = encodeURIComponent(siteUrl);
|
|
42688
|
+
const data = await gscFetchJson(
|
|
42689
|
+
accessToken,
|
|
42690
|
+
`${GSC_API_BASE}/sites/${encodedSiteUrl}/searchAnalytics/query`,
|
|
42691
|
+
{ method: "POST", body: requestBody }
|
|
42692
|
+
);
|
|
42693
|
+
const rows = data.rows ?? [];
|
|
42694
|
+
allRows.push(...rows);
|
|
42695
|
+
if (rows.length < GSC_MAX_ROWS_PER_REQUEST) {
|
|
42696
|
+
break;
|
|
42697
|
+
}
|
|
42698
|
+
startRow += rows.length;
|
|
42699
|
+
}
|
|
42700
|
+
return allRows;
|
|
42701
|
+
}
|
|
42702
|
+
async function publishUrlNotification(accessToken, url, type = "URL_UPDATED") {
|
|
42703
|
+
validateAccessToken(accessToken);
|
|
42704
|
+
validateUrl(url);
|
|
42705
|
+
return gscFetchJson(
|
|
42706
|
+
accessToken,
|
|
42707
|
+
`${INDEXING_API_BASE}/urlNotifications:publish`,
|
|
42708
|
+
{
|
|
42709
|
+
method: "POST",
|
|
42710
|
+
body: { url, type }
|
|
42711
|
+
}
|
|
42712
|
+
);
|
|
42713
|
+
}
|
|
42714
|
+
async function inspectUrl(accessToken, inspectionUrl, siteUrl) {
|
|
42715
|
+
validateAccessToken(accessToken);
|
|
42716
|
+
validateUrl(inspectionUrl);
|
|
42717
|
+
validateSiteUrl(siteUrl);
|
|
42718
|
+
return gscFetchJson(
|
|
42719
|
+
accessToken,
|
|
42720
|
+
URL_INSPECTION_API,
|
|
42721
|
+
{
|
|
42722
|
+
method: "POST",
|
|
42723
|
+
body: {
|
|
42724
|
+
inspectionUrl,
|
|
42725
|
+
siteUrl
|
|
42726
|
+
}
|
|
42727
|
+
}
|
|
42728
|
+
);
|
|
42729
|
+
}
|
|
42730
|
+
|
|
42302
42731
|
// ../../node_modules/.pnpm/entities@8.1.0/node_modules/entities/dist/decode-codepoint.js
|
|
42303
42732
|
var c1 = [
|
|
42304
42733
|
8364,
|
|
@@ -43025,6 +43454,52 @@ async function hotelEditorialDestination(domain, summary3, articleUrl, fetchImpl
|
|
|
43025
43454
|
|
|
43026
43455
|
// ../api-routes/src/gbp-local-posts.ts
|
|
43027
43456
|
var digest = (value) => createHash8("sha256").update(JSON.stringify(value)).digest("hex");
|
|
43457
|
+
var READ_REASONS = /* @__PURE__ */ new Set([
|
|
43458
|
+
"ACCESS_TOKEN_SCOPE_INSUFFICIENT",
|
|
43459
|
+
"RATE_LIMIT_EXCEEDED",
|
|
43460
|
+
"SERVICE_DISABLED",
|
|
43461
|
+
"API_DISABLED",
|
|
43462
|
+
"CONSUMER_INVALID",
|
|
43463
|
+
"IAM_PERMISSION_DENIED",
|
|
43464
|
+
"ACCESS_DENIED",
|
|
43465
|
+
"UNAUTHENTICATED",
|
|
43466
|
+
"NOT_FOUND",
|
|
43467
|
+
"INVALID_ARGUMENT",
|
|
43468
|
+
"QUOTA_EXCEEDED",
|
|
43469
|
+
"PERMISSION_DENIED",
|
|
43470
|
+
"FAILED_PRECONDITION",
|
|
43471
|
+
"INTERNAL",
|
|
43472
|
+
"UNAVAILABLE",
|
|
43473
|
+
"RESOURCE_EXHAUSTED"
|
|
43474
|
+
]);
|
|
43475
|
+
function localPostReadError(error, stage, message) {
|
|
43476
|
+
let category = stage === "token" ? "token" : "unclassified";
|
|
43477
|
+
let reason = "UNCLASSIFIED";
|
|
43478
|
+
let upstreamStatus;
|
|
43479
|
+
if (stage === "token") {
|
|
43480
|
+
if (error instanceof GoogleAuthError) {
|
|
43481
|
+
reason = "REFRESH_FAILED";
|
|
43482
|
+
upstreamStatus = error.statusCode ?? Number(error.message.match(/^Token refresh failed \((\d{3})\):/u)?.[1]);
|
|
43483
|
+
} else if (error instanceof AppError) {
|
|
43484
|
+
if (error.code === "NOT_FOUND") reason = "NOT_CONNECTED";
|
|
43485
|
+
if (error.code === "VALIDATION_ERROR") reason = "NOT_CONFIGURED";
|
|
43486
|
+
}
|
|
43487
|
+
} else if (error instanceof GbpApiError) {
|
|
43488
|
+
category = "google_api";
|
|
43489
|
+
const body = error.body;
|
|
43490
|
+
const code = body?.error?.status;
|
|
43491
|
+
reason = error.reason !== null && READ_REASONS.has(error.reason) ? error.reason : typeof code === "string" && READ_REASONS.has(code) ? code : reason;
|
|
43492
|
+
upstreamStatus = error.status;
|
|
43493
|
+
} else if (error instanceof GbpLocalPostResponseError) {
|
|
43494
|
+
category = "response";
|
|
43495
|
+
reason = error.reason;
|
|
43496
|
+
}
|
|
43497
|
+
return providerError(message, {
|
|
43498
|
+
category,
|
|
43499
|
+
reason,
|
|
43500
|
+
...typeof upstreamStatus === "number" && Number.isInteger(upstreamStatus) && upstreamStatus >= 100 && upstreamStatus <= 599 ? { upstreamStatus } : {}
|
|
43501
|
+
});
|
|
43502
|
+
}
|
|
43028
43503
|
function readGrant(request) {
|
|
43029
43504
|
requireAdminSession(request);
|
|
43030
43505
|
requirePaidReadScope(
|
|
@@ -43035,6 +43510,19 @@ function readGrant(request) {
|
|
|
43035
43510
|
requireScope(request, GBP_LIVE_READ_SCOPE);
|
|
43036
43511
|
}
|
|
43037
43512
|
async function gbpLocalPostsRoutes(app, options) {
|
|
43513
|
+
async function readPostResource(domain, read, message) {
|
|
43514
|
+
let token;
|
|
43515
|
+
try {
|
|
43516
|
+
token = await options.token(domain);
|
|
43517
|
+
} catch (error) {
|
|
43518
|
+
throw localPostReadError(error, "token", message);
|
|
43519
|
+
}
|
|
43520
|
+
try {
|
|
43521
|
+
return await read(token);
|
|
43522
|
+
} catch (error) {
|
|
43523
|
+
throw localPostReadError(error, "read", message);
|
|
43524
|
+
}
|
|
43525
|
+
}
|
|
43038
43526
|
function selected(projectId, account, location) {
|
|
43039
43527
|
const a = gbpAccountNameSchema.safeParse(account);
|
|
43040
43528
|
const l = gbpLocationNameSchema.safeParse(location);
|
|
@@ -43067,18 +43555,11 @@ async function gbpLocalPostsRoutes(app, options) {
|
|
|
43067
43555
|
const page3 = request.query.pageToken;
|
|
43068
43556
|
if (page3 !== void 0 && (page3.length > 2e3 || /[\p{Cc}\p{Cf}]/u.test(page3)))
|
|
43069
43557
|
throw validationError("Invalid GBP page token.");
|
|
43070
|
-
|
|
43071
|
-
|
|
43072
|
-
|
|
43073
|
-
|
|
43074
|
-
|
|
43075
|
-
page3
|
|
43076
|
-
);
|
|
43077
|
-
} catch {
|
|
43078
|
-
throw providerError(
|
|
43079
|
-
"Google Local Posts could not be read; coverage is unknown."
|
|
43080
|
-
);
|
|
43081
|
-
}
|
|
43558
|
+
return readPostResource(
|
|
43559
|
+
project.canonicalDomain,
|
|
43560
|
+
(token) => listLocalPosts(token, location.accountName, location.locationName, page3),
|
|
43561
|
+
"Google Local Posts could not be read; coverage is unknown."
|
|
43562
|
+
);
|
|
43082
43563
|
});
|
|
43083
43564
|
app.get(
|
|
43084
43565
|
"/projects/:name/gbp/local-post",
|
|
@@ -43094,16 +43575,11 @@ async function gbpLocalPostsRoutes(app, options) {
|
|
|
43094
43575
|
parts.slice(0, 2).join("/"),
|
|
43095
43576
|
parts.slice(2, 4).join("/")
|
|
43096
43577
|
);
|
|
43097
|
-
|
|
43098
|
-
|
|
43099
|
-
|
|
43100
|
-
|
|
43101
|
-
|
|
43102
|
-
} catch {
|
|
43103
|
-
throw providerError(
|
|
43104
|
-
"Google Local Post could not be verified; do not resubmit it."
|
|
43105
|
-
);
|
|
43106
|
-
}
|
|
43578
|
+
return readPostResource(
|
|
43579
|
+
project.canonicalDomain,
|
|
43580
|
+
(token) => getLocalPost(token, parsed.data),
|
|
43581
|
+
"Google Local Post could not be verified; do not resubmit it."
|
|
43582
|
+
);
|
|
43107
43583
|
}
|
|
43108
43584
|
);
|
|
43109
43585
|
app.get("/projects/:name/gbp/reviews/live", async (request) => {
|
|
@@ -43433,417 +43909,6 @@ function verifySignedGoogleOAuthState(encoded, secret, nowMs = Date.now()) {
|
|
|
43433
43909
|
}
|
|
43434
43910
|
}
|
|
43435
43911
|
|
|
43436
|
-
// ../integration-google/src/constants.ts
|
|
43437
|
-
var GOOGLE_AUTH_URL = "https://accounts.google.com/o/oauth2/v2/auth";
|
|
43438
|
-
var GOOGLE_TOKEN_URL = "https://oauth2.googleapis.com/token";
|
|
43439
|
-
var GSC_SCOPE = "https://www.googleapis.com/auth/webmasters";
|
|
43440
|
-
var GSC_READONLY_SCOPE = "https://www.googleapis.com/auth/webmasters.readonly";
|
|
43441
|
-
var INDEXING_SCOPE = "https://www.googleapis.com/auth/indexing";
|
|
43442
|
-
var GSC_API_BASE = "https://www.googleapis.com/webmasters/v3";
|
|
43443
|
-
var URL_INSPECTION_API = "https://searchconsole.googleapis.com/v1/urlInspection/index:inspect";
|
|
43444
|
-
var GSC_MAX_ROWS_PER_REQUEST = 25e3;
|
|
43445
|
-
var GSC_REPORTING_TIME_ZONE = "America/Los_Angeles";
|
|
43446
|
-
var GSC_DATA_LAG_DAYS = 3;
|
|
43447
|
-
var INDEXING_API_BASE = "https://indexing.googleapis.com/v3";
|
|
43448
|
-
var INDEXING_API_DAILY_LIMIT = 200;
|
|
43449
|
-
var GOOGLE_REQUEST_TIMEOUT_MS = 3e4;
|
|
43450
|
-
var GSC_MAX_PAGES = 40;
|
|
43451
|
-
|
|
43452
|
-
// ../integration-google/src/types.ts
|
|
43453
|
-
var GoogleAuthError = class extends Error {
|
|
43454
|
-
statusCode;
|
|
43455
|
-
constructor(message, statusCode) {
|
|
43456
|
-
super(message);
|
|
43457
|
-
this.name = "GoogleAuthError";
|
|
43458
|
-
this.statusCode = statusCode;
|
|
43459
|
-
}
|
|
43460
|
-
};
|
|
43461
|
-
var GoogleApiError = class extends Error {
|
|
43462
|
-
status;
|
|
43463
|
-
constructor(message, status) {
|
|
43464
|
-
super(message);
|
|
43465
|
-
this.name = "GoogleApiError";
|
|
43466
|
-
this.status = status;
|
|
43467
|
-
}
|
|
43468
|
-
};
|
|
43469
|
-
|
|
43470
|
-
// ../integration-google/src/oauth.ts
|
|
43471
|
-
function validateClientId(clientId) {
|
|
43472
|
-
if (!clientId || typeof clientId !== "string" || clientId.trim().length === 0) {
|
|
43473
|
-
throw new GoogleAuthError("Client ID is required and must be a non-empty string");
|
|
43474
|
-
}
|
|
43475
|
-
}
|
|
43476
|
-
function validateClientSecret(clientSecret) {
|
|
43477
|
-
if (!clientSecret || typeof clientSecret !== "string" || clientSecret.trim().length === 0) {
|
|
43478
|
-
throw new GoogleAuthError("Client secret is required and must be a non-empty string");
|
|
43479
|
-
}
|
|
43480
|
-
}
|
|
43481
|
-
function validateRedirectUri(redirectUri) {
|
|
43482
|
-
if (!redirectUri || typeof redirectUri !== "string" || redirectUri.trim().length === 0) {
|
|
43483
|
-
throw new GoogleAuthError("Redirect URI is required and must be a non-empty string");
|
|
43484
|
-
}
|
|
43485
|
-
try {
|
|
43486
|
-
const url = new URL(redirectUri);
|
|
43487
|
-
if (!url.protocol.startsWith("http")) {
|
|
43488
|
-
throw new GoogleAuthError("Redirect URI must be an HTTP or HTTPS URL");
|
|
43489
|
-
}
|
|
43490
|
-
} catch {
|
|
43491
|
-
throw new GoogleAuthError("Redirect URI must be a valid URL");
|
|
43492
|
-
}
|
|
43493
|
-
}
|
|
43494
|
-
function validateCode(code) {
|
|
43495
|
-
if (!code || typeof code !== "string" || code.trim().length === 0) {
|
|
43496
|
-
throw new GoogleAuthError("Authorization code is required and must be a non-empty string");
|
|
43497
|
-
}
|
|
43498
|
-
}
|
|
43499
|
-
function validateScopes(scopes) {
|
|
43500
|
-
if (!Array.isArray(scopes) || scopes.length === 0) {
|
|
43501
|
-
throw new GoogleAuthError("At least one scope is required");
|
|
43502
|
-
}
|
|
43503
|
-
for (const scope of scopes) {
|
|
43504
|
-
if (!scope || typeof scope !== "string" || scope.trim().length === 0) {
|
|
43505
|
-
throw new GoogleAuthError("Scope must be a non-empty string");
|
|
43506
|
-
}
|
|
43507
|
-
}
|
|
43508
|
-
}
|
|
43509
|
-
function validateRefreshToken(refreshToken) {
|
|
43510
|
-
if (!refreshToken || typeof refreshToken !== "string" || refreshToken.trim().length === 0) {
|
|
43511
|
-
throw new GoogleAuthError("Refresh token is required and must be a non-empty string");
|
|
43512
|
-
}
|
|
43513
|
-
}
|
|
43514
|
-
function getAuthUrl(clientId, redirectUri, scopes, state) {
|
|
43515
|
-
validateClientId(clientId);
|
|
43516
|
-
validateRedirectUri(redirectUri);
|
|
43517
|
-
validateScopes(scopes);
|
|
43518
|
-
if (state && (typeof state !== "string" || state.trim().length === 0)) {
|
|
43519
|
-
throw new GoogleAuthError("State must be a non-empty string if provided");
|
|
43520
|
-
}
|
|
43521
|
-
const params = new URLSearchParams({
|
|
43522
|
-
client_id: clientId,
|
|
43523
|
-
redirect_uri: redirectUri,
|
|
43524
|
-
response_type: "code",
|
|
43525
|
-
scope: scopes.join(" "),
|
|
43526
|
-
access_type: "offline",
|
|
43527
|
-
prompt: "consent"
|
|
43528
|
-
});
|
|
43529
|
-
if (state) params.set("state", state);
|
|
43530
|
-
return `${GOOGLE_AUTH_URL}?${params.toString()}`;
|
|
43531
|
-
}
|
|
43532
|
-
async function exchangeCode(clientId, clientSecret, code, redirectUri) {
|
|
43533
|
-
validateClientId(clientId);
|
|
43534
|
-
validateClientSecret(clientSecret);
|
|
43535
|
-
validateCode(code);
|
|
43536
|
-
validateRedirectUri(redirectUri);
|
|
43537
|
-
const res = await fetch(GOOGLE_TOKEN_URL, {
|
|
43538
|
-
method: "POST",
|
|
43539
|
-
headers: { "Content-Type": "application/x-www-form-urlencoded" },
|
|
43540
|
-
body: new URLSearchParams({
|
|
43541
|
-
client_id: clientId,
|
|
43542
|
-
client_secret: clientSecret,
|
|
43543
|
-
code,
|
|
43544
|
-
redirect_uri: redirectUri,
|
|
43545
|
-
grant_type: "authorization_code"
|
|
43546
|
-
}),
|
|
43547
|
-
signal: AbortSignal.timeout(GOOGLE_REQUEST_TIMEOUT_MS)
|
|
43548
|
-
});
|
|
43549
|
-
if (res.status === 429) {
|
|
43550
|
-
throw new GoogleAuthError("Google OAuth rate limit exceeded", 429);
|
|
43551
|
-
}
|
|
43552
|
-
if (!res.ok) {
|
|
43553
|
-
const body = await res.text();
|
|
43554
|
-
let detail = "";
|
|
43555
|
-
try {
|
|
43556
|
-
const parsed = JSON.parse(body);
|
|
43557
|
-
if (parsed.error) detail = parsed.error;
|
|
43558
|
-
if (parsed.error_description) {
|
|
43559
|
-
const sanitized = parsed.error_description.replace(new RegExp(escapeRegExp2(clientId), "g"), "***").replace(new RegExp(escapeRegExp2(clientSecret), "g"), "***").replace(new RegExp(escapeRegExp2(code), "g"), "***");
|
|
43560
|
-
detail += detail ? `: ${sanitized}` : sanitized;
|
|
43561
|
-
}
|
|
43562
|
-
} catch {
|
|
43563
|
-
const truncated = body.length <= 120 ? body : `${body.slice(0, 120)}...`;
|
|
43564
|
-
detail = truncated.replace(new RegExp(escapeRegExp2(clientId), "g"), "***").replace(new RegExp(escapeRegExp2(clientSecret), "g"), "***").replace(new RegExp(escapeRegExp2(code), "g"), "***");
|
|
43565
|
-
}
|
|
43566
|
-
throw new GoogleAuthError(`Token exchange failed (${res.status}): ${detail}`);
|
|
43567
|
-
}
|
|
43568
|
-
return await res.json();
|
|
43569
|
-
}
|
|
43570
|
-
function escapeRegExp2(str) {
|
|
43571
|
-
return str.replace(/[.*+?^${}()|[\]\\]/g, "\\$&");
|
|
43572
|
-
}
|
|
43573
|
-
async function refreshAccessToken(clientId, clientSecret, currentRefreshToken) {
|
|
43574
|
-
validateClientId(clientId);
|
|
43575
|
-
validateClientSecret(clientSecret);
|
|
43576
|
-
validateRefreshToken(currentRefreshToken);
|
|
43577
|
-
const res = await fetch(GOOGLE_TOKEN_URL, {
|
|
43578
|
-
method: "POST",
|
|
43579
|
-
headers: { "Content-Type": "application/x-www-form-urlencoded" },
|
|
43580
|
-
body: new URLSearchParams({
|
|
43581
|
-
client_id: clientId,
|
|
43582
|
-
client_secret: clientSecret,
|
|
43583
|
-
refresh_token: currentRefreshToken,
|
|
43584
|
-
grant_type: "refresh_token"
|
|
43585
|
-
}),
|
|
43586
|
-
signal: AbortSignal.timeout(GOOGLE_REQUEST_TIMEOUT_MS)
|
|
43587
|
-
});
|
|
43588
|
-
if (res.status === 429) {
|
|
43589
|
-
throw new GoogleAuthError("Google OAuth rate limit exceeded", 429);
|
|
43590
|
-
}
|
|
43591
|
-
if (!res.ok) {
|
|
43592
|
-
const body = await res.text();
|
|
43593
|
-
let detail = "";
|
|
43594
|
-
try {
|
|
43595
|
-
const parsed = JSON.parse(body);
|
|
43596
|
-
if (parsed.error) detail = parsed.error;
|
|
43597
|
-
if (parsed.error_description) {
|
|
43598
|
-
const sanitized = parsed.error_description.replace(new RegExp(escapeRegExp2(clientId), "g"), "***").replace(new RegExp(escapeRegExp2(clientSecret), "g"), "***").replace(new RegExp(escapeRegExp2(currentRefreshToken), "g"), "***");
|
|
43599
|
-
detail += detail ? `: ${sanitized}` : sanitized;
|
|
43600
|
-
}
|
|
43601
|
-
} catch {
|
|
43602
|
-
const truncated = body.length <= 120 ? body : `${body.slice(0, 120)}...`;
|
|
43603
|
-
detail = truncated.replace(new RegExp(escapeRegExp2(clientId), "g"), "***").replace(new RegExp(escapeRegExp2(clientSecret), "g"), "***").replace(new RegExp(escapeRegExp2(currentRefreshToken), "g"), "***");
|
|
43604
|
-
}
|
|
43605
|
-
throw new GoogleAuthError(`Token refresh failed (${res.status}): ${detail}`);
|
|
43606
|
-
}
|
|
43607
|
-
return await res.json();
|
|
43608
|
-
}
|
|
43609
|
-
|
|
43610
|
-
// ../integration-google/src/gsc-client.ts
|
|
43611
|
-
function validateAccessToken(accessToken) {
|
|
43612
|
-
if (!accessToken || typeof accessToken !== "string" || accessToken.trim().length === 0) {
|
|
43613
|
-
throw new GoogleApiError("Access token is required and must be a non-empty string", 400);
|
|
43614
|
-
}
|
|
43615
|
-
}
|
|
43616
|
-
function validateSiteUrl(siteUrl) {
|
|
43617
|
-
if (!siteUrl || typeof siteUrl !== "string" || siteUrl.trim().length === 0) {
|
|
43618
|
-
throw new GoogleApiError("Site URL is required and must be a non-empty string", 400);
|
|
43619
|
-
}
|
|
43620
|
-
if (/^\d+$/.test(siteUrl)) {
|
|
43621
|
-
return;
|
|
43622
|
-
}
|
|
43623
|
-
if (siteUrl.startsWith("sc-domain:")) {
|
|
43624
|
-
const domain = siteUrl.slice("sc-domain:".length);
|
|
43625
|
-
if (!domain) {
|
|
43626
|
-
throw new GoogleApiError("Site URL sc-domain must include a domain", 400);
|
|
43627
|
-
}
|
|
43628
|
-
if (!domain.includes(".")) {
|
|
43629
|
-
throw new GoogleApiError("Site URL sc-domain must be a valid domain", 400);
|
|
43630
|
-
}
|
|
43631
|
-
} else {
|
|
43632
|
-
try {
|
|
43633
|
-
const url = new URL(siteUrl);
|
|
43634
|
-
if (!url.protocol.startsWith("http")) {
|
|
43635
|
-
throw new GoogleApiError("Site URL must be an HTTP or HTTPS URL", 400);
|
|
43636
|
-
}
|
|
43637
|
-
} catch {
|
|
43638
|
-
throw new GoogleApiError("Site URL must be a valid URL", 400);
|
|
43639
|
-
}
|
|
43640
|
-
}
|
|
43641
|
-
}
|
|
43642
|
-
function validateUrl(urlParam) {
|
|
43643
|
-
if (!urlParam || typeof urlParam !== "string" || urlParam.trim().length === 0) {
|
|
43644
|
-
throw new GoogleApiError("URL is required and must be a non-empty string", 400);
|
|
43645
|
-
}
|
|
43646
|
-
try {
|
|
43647
|
-
const url = new URL(urlParam);
|
|
43648
|
-
if (!url.protocol.startsWith("http")) {
|
|
43649
|
-
throw new GoogleApiError("URL must be an HTTP or HTTPS URL", 400);
|
|
43650
|
-
}
|
|
43651
|
-
} catch {
|
|
43652
|
-
throw new GoogleApiError("URL must be a valid URL", 400);
|
|
43653
|
-
}
|
|
43654
|
-
}
|
|
43655
|
-
function validateDate(date, label) {
|
|
43656
|
-
if (!date || typeof date !== "string" || date.trim().length === 0) {
|
|
43657
|
-
throw new GoogleApiError(`${label} is required and must be a non-empty string`, 400);
|
|
43658
|
-
}
|
|
43659
|
-
if (!/^\d{4}-\d{2}-\d{2}$/.test(date)) {
|
|
43660
|
-
throw new GoogleApiError(`${label} must be in YYYY-MM-DD format, got "${date}"`, 400);
|
|
43661
|
-
}
|
|
43662
|
-
const parsed = /* @__PURE__ */ new Date(`${date}T00:00:00Z`);
|
|
43663
|
-
if (Number.isNaN(parsed.getTime())) {
|
|
43664
|
-
throw new GoogleApiError(`${label} is not a valid date, got "${date}"`, 400);
|
|
43665
|
-
}
|
|
43666
|
-
}
|
|
43667
|
-
function gscClientLog(level, action, ctx) {
|
|
43668
|
-
const entry = {
|
|
43669
|
-
ts: (/* @__PURE__ */ new Date()).toISOString(),
|
|
43670
|
-
level,
|
|
43671
|
-
module: "GscClient",
|
|
43672
|
-
action,
|
|
43673
|
-
...ctx
|
|
43674
|
-
};
|
|
43675
|
-
if (entry.accessToken) entry.accessToken = "***";
|
|
43676
|
-
if (typeof entry.siteUrl === "string") {
|
|
43677
|
-
try {
|
|
43678
|
-
const url = new URL(entry.siteUrl);
|
|
43679
|
-
if (url.search) {
|
|
43680
|
-
url.searchParams.forEach((_, key) => {
|
|
43681
|
-
if (key.toLowerCase().includes("token") || key.toLowerCase().includes("key") || key.toLowerCase().includes("auth")) {
|
|
43682
|
-
url.searchParams.set(key, "***");
|
|
43683
|
-
}
|
|
43684
|
-
});
|
|
43685
|
-
entry.siteUrl = url.toString();
|
|
43686
|
-
}
|
|
43687
|
-
} catch {
|
|
43688
|
-
}
|
|
43689
|
-
}
|
|
43690
|
-
const stream = level === "error" ? process.stderr : process.stdout;
|
|
43691
|
-
stream.write(JSON.stringify(entry) + "\n");
|
|
43692
|
-
}
|
|
43693
|
-
function escapeRegExp3(str) {
|
|
43694
|
-
return str.replace(/[.*+?^${}()|[\]\\]/g, "\\$&");
|
|
43695
|
-
}
|
|
43696
|
-
async function gscFetchResponse(accessToken, url, opts) {
|
|
43697
|
-
const method = opts?.method ?? "GET";
|
|
43698
|
-
const headers = {
|
|
43699
|
-
Authorization: `Bearer ${accessToken}`,
|
|
43700
|
-
"Content-Type": "application/json"
|
|
43701
|
-
};
|
|
43702
|
-
let res;
|
|
43703
|
-
try {
|
|
43704
|
-
res = await fetch(url, {
|
|
43705
|
-
method,
|
|
43706
|
-
headers,
|
|
43707
|
-
body: opts?.body != null ? JSON.stringify(opts.body) : void 0,
|
|
43708
|
-
signal: AbortSignal.timeout(GOOGLE_REQUEST_TIMEOUT_MS)
|
|
43709
|
-
});
|
|
43710
|
-
} catch (error) {
|
|
43711
|
-
throw new Error(describeFetchError(error, url), { cause: error });
|
|
43712
|
-
}
|
|
43713
|
-
if (res.status === 401) {
|
|
43714
|
-
gscClientLog("error", "http.auth-expired", { url, method, httpStatus: 401 });
|
|
43715
|
-
throw new GoogleApiError("Access token expired or revoked", 401);
|
|
43716
|
-
}
|
|
43717
|
-
if (res.status === 429) {
|
|
43718
|
-
gscClientLog("error", "http.rate-limited", { url, method, httpStatus: 429 });
|
|
43719
|
-
throw new GoogleApiError("Google API rate limit exceeded", 429);
|
|
43720
|
-
}
|
|
43721
|
-
if (!res.ok) {
|
|
43722
|
-
const body = await res.text();
|
|
43723
|
-
gscClientLog("error", "http.error", { url, method, httpStatus: res.status });
|
|
43724
|
-
const detail = body.length <= 500 ? body : `${body.slice(0, 500)}... [truncated]`;
|
|
43725
|
-
let sanitizedDetail = detail;
|
|
43726
|
-
if (accessToken) {
|
|
43727
|
-
sanitizedDetail = sanitizedDetail.replace(new RegExp(escapeRegExp3(accessToken), "g"), "***");
|
|
43728
|
-
}
|
|
43729
|
-
throw new GoogleApiError(`GSC API error (${res.status}): ${sanitizedDetail}`, res.status);
|
|
43730
|
-
}
|
|
43731
|
-
return res;
|
|
43732
|
-
}
|
|
43733
|
-
async function gscFetchJson(accessToken, url, opts) {
|
|
43734
|
-
const res = await gscFetchResponse(accessToken, url, opts);
|
|
43735
|
-
const text = await res.text();
|
|
43736
|
-
if (!text) {
|
|
43737
|
-
throw new GoogleApiError("GSC API returned an empty response where JSON was expected", res.status);
|
|
43738
|
-
}
|
|
43739
|
-
try {
|
|
43740
|
-
return JSON.parse(text);
|
|
43741
|
-
} catch {
|
|
43742
|
-
throw new GoogleApiError("GSC API returned invalid JSON", res.status);
|
|
43743
|
-
}
|
|
43744
|
-
}
|
|
43745
|
-
async function listSites(accessToken) {
|
|
43746
|
-
validateAccessToken(accessToken);
|
|
43747
|
-
const data = await gscFetchJson(
|
|
43748
|
-
accessToken,
|
|
43749
|
-
`${GSC_API_BASE}/sites`
|
|
43750
|
-
);
|
|
43751
|
-
return data.siteEntry ?? [];
|
|
43752
|
-
}
|
|
43753
|
-
async function listSitemaps(accessToken, siteUrl, sitemapIndex) {
|
|
43754
|
-
validateAccessToken(accessToken);
|
|
43755
|
-
validateSiteUrl(siteUrl);
|
|
43756
|
-
if (sitemapIndex != null) validateUrl(sitemapIndex);
|
|
43757
|
-
const encodedSiteUrl = encodeURIComponent(siteUrl);
|
|
43758
|
-
const sitemapIndexQuery = sitemapIndex == null ? "" : `?sitemapIndex=${encodeURIComponent(sitemapIndex)}`;
|
|
43759
|
-
const data = await gscFetchJson(
|
|
43760
|
-
accessToken,
|
|
43761
|
-
`${GSC_API_BASE}/sites/${encodedSiteUrl}/sitemaps${sitemapIndexQuery}`
|
|
43762
|
-
);
|
|
43763
|
-
return data.sitemap ?? [];
|
|
43764
|
-
}
|
|
43765
|
-
async function submitSitemap(accessToken, siteUrl, sitemapUrl) {
|
|
43766
|
-
validateAccessToken(accessToken);
|
|
43767
|
-
validateSiteUrl(siteUrl);
|
|
43768
|
-
validateUrl(sitemapUrl);
|
|
43769
|
-
await gscFetchResponse(
|
|
43770
|
-
accessToken,
|
|
43771
|
-
`${GSC_API_BASE}/sites/${encodeURIComponent(siteUrl)}/sitemaps/${encodeURIComponent(sitemapUrl)}`,
|
|
43772
|
-
{ method: "PUT" }
|
|
43773
|
-
);
|
|
43774
|
-
}
|
|
43775
|
-
async function fetchSearchAnalytics(accessToken, siteUrl, opts) {
|
|
43776
|
-
validateAccessToken(accessToken);
|
|
43777
|
-
validateSiteUrl(siteUrl);
|
|
43778
|
-
validateDate(opts.startDate, "startDate");
|
|
43779
|
-
validateDate(opts.endDate, "endDate");
|
|
43780
|
-
const allRows = [];
|
|
43781
|
-
let startRow = 0;
|
|
43782
|
-
const dimensions = opts.dimensions ?? ["query", "page", "country", "device", "date"];
|
|
43783
|
-
for (; ; ) {
|
|
43784
|
-
if (startRow >= GSC_MAX_ROWS_PER_REQUEST * GSC_MAX_PAGES) {
|
|
43785
|
-
gscClientLog("error", "pagination.safety-limit", { siteUrl, startRow, maxRows: GSC_MAX_ROWS_PER_REQUEST * GSC_MAX_PAGES });
|
|
43786
|
-
break;
|
|
43787
|
-
}
|
|
43788
|
-
const requestBody = {
|
|
43789
|
-
startDate: opts.startDate,
|
|
43790
|
-
endDate: opts.endDate,
|
|
43791
|
-
dimensions,
|
|
43792
|
-
rowLimit: GSC_MAX_ROWS_PER_REQUEST,
|
|
43793
|
-
startRow
|
|
43794
|
-
};
|
|
43795
|
-
if (opts.query || opts.page) {
|
|
43796
|
-
const filters = [];
|
|
43797
|
-
const filterList = [];
|
|
43798
|
-
if (opts.query) filterList.push({ dimension: "query", operator: "contains", expression: opts.query });
|
|
43799
|
-
if (opts.page) filterList.push({ dimension: "page", operator: "contains", expression: opts.page });
|
|
43800
|
-
filters.push({ filters: filterList });
|
|
43801
|
-
requestBody.dimensionFilterGroups = filters;
|
|
43802
|
-
}
|
|
43803
|
-
const encodedSiteUrl = encodeURIComponent(siteUrl);
|
|
43804
|
-
const data = await gscFetchJson(
|
|
43805
|
-
accessToken,
|
|
43806
|
-
`${GSC_API_BASE}/sites/${encodedSiteUrl}/searchAnalytics/query`,
|
|
43807
|
-
{ method: "POST", body: requestBody }
|
|
43808
|
-
);
|
|
43809
|
-
const rows = data.rows ?? [];
|
|
43810
|
-
allRows.push(...rows);
|
|
43811
|
-
if (rows.length < GSC_MAX_ROWS_PER_REQUEST) {
|
|
43812
|
-
break;
|
|
43813
|
-
}
|
|
43814
|
-
startRow += rows.length;
|
|
43815
|
-
}
|
|
43816
|
-
return allRows;
|
|
43817
|
-
}
|
|
43818
|
-
async function publishUrlNotification(accessToken, url, type = "URL_UPDATED") {
|
|
43819
|
-
validateAccessToken(accessToken);
|
|
43820
|
-
validateUrl(url);
|
|
43821
|
-
return gscFetchJson(
|
|
43822
|
-
accessToken,
|
|
43823
|
-
`${INDEXING_API_BASE}/urlNotifications:publish`,
|
|
43824
|
-
{
|
|
43825
|
-
method: "POST",
|
|
43826
|
-
body: { url, type }
|
|
43827
|
-
}
|
|
43828
|
-
);
|
|
43829
|
-
}
|
|
43830
|
-
async function inspectUrl(accessToken, inspectionUrl, siteUrl) {
|
|
43831
|
-
validateAccessToken(accessToken);
|
|
43832
|
-
validateUrl(inspectionUrl);
|
|
43833
|
-
validateSiteUrl(siteUrl);
|
|
43834
|
-
return gscFetchJson(
|
|
43835
|
-
accessToken,
|
|
43836
|
-
URL_INSPECTION_API,
|
|
43837
|
-
{
|
|
43838
|
-
method: "POST",
|
|
43839
|
-
body: {
|
|
43840
|
-
inspectionUrl,
|
|
43841
|
-
siteUrl
|
|
43842
|
-
}
|
|
43843
|
-
}
|
|
43844
|
-
);
|
|
43845
|
-
}
|
|
43846
|
-
|
|
43847
43912
|
// ../integration-google-analytics/src/ga4-client.ts
|
|
43848
43913
|
import crypto35 from "crypto";
|
|
43849
43914
|
|
|
@@ -72974,14 +73039,6 @@ export {
|
|
|
72974
73039
|
hashAttributes,
|
|
72975
73040
|
listReviews,
|
|
72976
73041
|
classifyReviewsError,
|
|
72977
|
-
EgressRefusedError,
|
|
72978
|
-
EgressFailedError,
|
|
72979
|
-
createGuardedFetch,
|
|
72980
|
-
getPlaceDetails,
|
|
72981
|
-
hashPlaceDetails,
|
|
72982
|
-
extractPlaceAmenities,
|
|
72983
|
-
getPlaceReviewSignals,
|
|
72984
|
-
buildGbpSummary,
|
|
72985
73042
|
GSC_REPORTING_TIME_ZONE,
|
|
72986
73043
|
GSC_DATA_LAG_DAYS,
|
|
72987
73044
|
GoogleAuthError,
|
|
@@ -72991,6 +73048,14 @@ export {
|
|
|
72991
73048
|
refreshAccessToken,
|
|
72992
73049
|
fetchSearchAnalytics,
|
|
72993
73050
|
inspectUrl,
|
|
73051
|
+
EgressRefusedError,
|
|
73052
|
+
EgressFailedError,
|
|
73053
|
+
createGuardedFetch,
|
|
73054
|
+
getPlaceDetails,
|
|
73055
|
+
hashPlaceDetails,
|
|
73056
|
+
extractPlaceAmenities,
|
|
73057
|
+
getPlaceReviewSignals,
|
|
73058
|
+
buildGbpSummary,
|
|
72994
73059
|
BingApiError,
|
|
72995
73060
|
getUrlInfo,
|
|
72996
73061
|
getCrawlIssues,
|