@rawdash/connector-google-search-console 0.16.0 → 0.18.0
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/LICENSE +202 -0
- package/dist/index.d.ts +105 -1
- package/dist/index.js +5 -2
- package/dist/index.js.map +1 -1
- package/package.json +14 -13
package/LICENSE
ADDED
|
@@ -0,0 +1,202 @@
|
|
|
1
|
+
|
|
2
|
+
Apache License
|
|
3
|
+
Version 2.0, January 2004
|
|
4
|
+
http://www.apache.org/licenses/
|
|
5
|
+
|
|
6
|
+
TERMS AND CONDITIONS FOR USE, REPRODUCTION, AND DISTRIBUTION
|
|
7
|
+
|
|
8
|
+
1. Definitions.
|
|
9
|
+
|
|
10
|
+
"License" shall mean the terms and conditions for use, reproduction,
|
|
11
|
+
and distribution as defined by Sections 1 through 9 of this document.
|
|
12
|
+
|
|
13
|
+
"Licensor" shall mean the copyright owner or entity authorized by
|
|
14
|
+
the copyright owner that is granting the License.
|
|
15
|
+
|
|
16
|
+
"Legal Entity" shall mean the union of the acting entity and all
|
|
17
|
+
other entities that control, are controlled by, or are under common
|
|
18
|
+
control with that entity. For the purposes of this definition,
|
|
19
|
+
"control" means (i) the power, direct or indirect, to cause the
|
|
20
|
+
direction or management of such entity, whether by contract or
|
|
21
|
+
otherwise, or (ii) ownership of fifty percent (50%) or more of the
|
|
22
|
+
outstanding shares, or (iii) beneficial ownership of such entity.
|
|
23
|
+
|
|
24
|
+
"You" (or "Your") shall mean an individual or Legal Entity
|
|
25
|
+
exercising permissions granted by this License.
|
|
26
|
+
|
|
27
|
+
"Source" form shall mean the preferred form for making modifications,
|
|
28
|
+
including but not limited to software source code, documentation
|
|
29
|
+
source, and configuration files.
|
|
30
|
+
|
|
31
|
+
"Object" form shall mean any form resulting from mechanical
|
|
32
|
+
transformation or translation of a Source form, including but
|
|
33
|
+
not limited to compiled object code, generated documentation,
|
|
34
|
+
and conversions to other media types.
|
|
35
|
+
|
|
36
|
+
"Work" shall mean the work of authorship, whether in Source or
|
|
37
|
+
Object form, made available under the License, as indicated by a
|
|
38
|
+
copyright notice that is included in or attached to the work
|
|
39
|
+
(an example is provided in the Appendix below).
|
|
40
|
+
|
|
41
|
+
"Derivative Works" shall mean any work, whether in Source or Object
|
|
42
|
+
form, that is based on (or derived from) the Work and for which the
|
|
43
|
+
editorial revisions, annotations, elaborations, or other modifications
|
|
44
|
+
represent, as a whole, an original work of authorship. For the purposes
|
|
45
|
+
of this License, Derivative Works shall not include works that remain
|
|
46
|
+
separable from, or merely link (or bind by name) to the interfaces of,
|
|
47
|
+
the Work and Derivative Works thereof.
|
|
48
|
+
|
|
49
|
+
"Contribution" shall mean any work of authorship, including
|
|
50
|
+
the original version of the Work and any modifications or additions
|
|
51
|
+
to that Work or Derivative Works thereof, that is intentionally
|
|
52
|
+
submitted to Licensor for inclusion in the Work by the copyright owner
|
|
53
|
+
or by an individual or Legal Entity authorized to submit on behalf of
|
|
54
|
+
the copyright owner. For the purposes of this definition, "submitted"
|
|
55
|
+
means any form of electronic, verbal, or written communication sent
|
|
56
|
+
to the Licensor or its representatives, including but not limited to
|
|
57
|
+
communication on electronic mailing lists, source code control systems,
|
|
58
|
+
and issue tracking systems that are managed by, or on behalf of, the
|
|
59
|
+
Licensor for the purpose of discussing and improving the Work, but
|
|
60
|
+
excluding communication that is conspicuously marked or otherwise
|
|
61
|
+
designated in writing by the copyright owner as "Not a Contribution."
|
|
62
|
+
|
|
63
|
+
"Contributor" shall mean Licensor and any individual or Legal Entity
|
|
64
|
+
on behalf of whom a Contribution has been received by Licensor and
|
|
65
|
+
subsequently incorporated within the Work.
|
|
66
|
+
|
|
67
|
+
2. Grant of Copyright License. Subject to the terms and conditions of
|
|
68
|
+
this License, each Contributor hereby grants to You a perpetual,
|
|
69
|
+
worldwide, non-exclusive, no-charge, royalty-free, irrevocable
|
|
70
|
+
copyright license to reproduce, prepare Derivative Works of,
|
|
71
|
+
publicly display, publicly perform, sublicense, and distribute the
|
|
72
|
+
Work and such Derivative Works in Source or Object form.
|
|
73
|
+
|
|
74
|
+
3. Grant of Patent License. Subject to the terms and conditions of
|
|
75
|
+
this License, each Contributor hereby grants to You a perpetual,
|
|
76
|
+
worldwide, non-exclusive, no-charge, royalty-free, irrevocable
|
|
77
|
+
(except as stated in this section) patent license to make, have made,
|
|
78
|
+
use, offer to sell, sell, import, and otherwise transfer the Work,
|
|
79
|
+
where such license applies only to those patent claims licensable
|
|
80
|
+
by such Contributor that are necessarily infringed by their
|
|
81
|
+
Contribution(s) alone or by combination of their Contribution(s)
|
|
82
|
+
with the Work to which such Contribution(s) was submitted. If You
|
|
83
|
+
institute patent litigation against any entity (including a
|
|
84
|
+
cross-claim or counterclaim in a lawsuit) alleging that the Work
|
|
85
|
+
or a Contribution incorporated within the Work constitutes direct
|
|
86
|
+
or contributory patent infringement, then any patent licenses
|
|
87
|
+
granted to You under this License for that Work shall terminate
|
|
88
|
+
as of the date such litigation is filed.
|
|
89
|
+
|
|
90
|
+
4. Redistribution. You may reproduce and distribute copies of the
|
|
91
|
+
Work or Derivative Works thereof in any medium, with or without
|
|
92
|
+
modifications, and in Source or Object form, provided that You
|
|
93
|
+
meet the following conditions:
|
|
94
|
+
|
|
95
|
+
(a) You must give any other recipients of the Work or
|
|
96
|
+
Derivative Works a copy of this License; and
|
|
97
|
+
|
|
98
|
+
(b) You must cause any modified files to carry prominent notices
|
|
99
|
+
stating that You changed the files; and
|
|
100
|
+
|
|
101
|
+
(c) You must retain, in the Source form of any Derivative Works
|
|
102
|
+
that You distribute, all copyright, patent, trademark, and
|
|
103
|
+
attribution notices from the Source form of the Work,
|
|
104
|
+
excluding those notices that do not pertain to any part of
|
|
105
|
+
the Derivative Works; and
|
|
106
|
+
|
|
107
|
+
(d) If the Work includes a "NOTICE" text file as part of its
|
|
108
|
+
distribution, then any Derivative Works that You distribute must
|
|
109
|
+
include a readable copy of the attribution notices contained
|
|
110
|
+
within such NOTICE file, excluding those notices that do not
|
|
111
|
+
pertain to any part of the Derivative Works, in at least one
|
|
112
|
+
of the following places: within a NOTICE text file distributed
|
|
113
|
+
as part of the Derivative Works; within the Source form or
|
|
114
|
+
documentation, if provided along with the Derivative Works; or,
|
|
115
|
+
within a display generated by the Derivative Works, if and
|
|
116
|
+
wherever such third-party notices normally appear. The contents
|
|
117
|
+
of the NOTICE file are for informational purposes only and
|
|
118
|
+
do not modify the License. You may add Your own attribution
|
|
119
|
+
notices within Derivative Works that You distribute, alongside
|
|
120
|
+
or as an addendum to the NOTICE text from the Work, provided
|
|
121
|
+
that such additional attribution notices cannot be construed
|
|
122
|
+
as modifying the License.
|
|
123
|
+
|
|
124
|
+
You may add Your own copyright statement to Your modifications and
|
|
125
|
+
may provide additional or different license terms and conditions
|
|
126
|
+
for use, reproduction, or distribution of Your modifications, or
|
|
127
|
+
for any such Derivative Works as a whole, provided Your use,
|
|
128
|
+
reproduction, and distribution of the Work otherwise complies with
|
|
129
|
+
the conditions stated in this License.
|
|
130
|
+
|
|
131
|
+
5. Submission of Contributions. Unless You explicitly state otherwise,
|
|
132
|
+
any Contribution intentionally submitted for inclusion in the Work
|
|
133
|
+
by You to the Licensor shall be under the terms and conditions of
|
|
134
|
+
this License, without any additional terms or conditions.
|
|
135
|
+
Notwithstanding the above, nothing herein shall supersede or modify
|
|
136
|
+
the terms of any separate license agreement you may have executed
|
|
137
|
+
with Licensor regarding such Contributions.
|
|
138
|
+
|
|
139
|
+
6. Trademarks. This License does not grant permission to use the trade
|
|
140
|
+
names, trademarks, service marks, or product names of the Licensor,
|
|
141
|
+
except as required for reasonable and customary use in describing the
|
|
142
|
+
origin of the Work and reproducing the content of the NOTICE file.
|
|
143
|
+
|
|
144
|
+
7. Disclaimer of Warranty. Unless required by applicable law or
|
|
145
|
+
agreed to in writing, Licensor provides the Work (and each
|
|
146
|
+
Contributor provides its Contributions) on an "AS IS" BASIS,
|
|
147
|
+
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or
|
|
148
|
+
implied, including, without limitation, any warranties or conditions
|
|
149
|
+
of TITLE, NON-INFRINGEMENT, MERCHANTABILITY, or FITNESS FOR A
|
|
150
|
+
PARTICULAR PURPOSE. You are solely responsible for determining the
|
|
151
|
+
appropriateness of using or redistributing the Work and assume any
|
|
152
|
+
risks associated with Your exercise of permissions under this License.
|
|
153
|
+
|
|
154
|
+
8. Limitation of Liability. In no event and under no legal theory,
|
|
155
|
+
whether in tort (including negligence), contract, or otherwise,
|
|
156
|
+
unless required by applicable law (such as deliberate and grossly
|
|
157
|
+
negligent acts) or agreed to in writing, shall any Contributor be
|
|
158
|
+
liable to You for damages, including any direct, indirect, special,
|
|
159
|
+
incidental, or consequential damages of any character arising as a
|
|
160
|
+
result of this License or out of the use or inability to use the
|
|
161
|
+
Work (including but not limited to damages for loss of goodwill,
|
|
162
|
+
work stoppage, computer failure or malfunction, or any and all
|
|
163
|
+
other commercial damages or losses), even if such Contributor
|
|
164
|
+
has been advised of the possibility of such damages.
|
|
165
|
+
|
|
166
|
+
9. Accepting Warranty or Additional Liability. While redistributing
|
|
167
|
+
the Work or Derivative Works thereof, You may choose to offer,
|
|
168
|
+
and charge a fee for, acceptance of support, warranty, indemnity,
|
|
169
|
+
or other liability obligations and/or rights consistent with this
|
|
170
|
+
License. However, in accepting such obligations, You may act only
|
|
171
|
+
on Your own behalf and on Your sole responsibility, not on behalf
|
|
172
|
+
of any other Contributor, and only if You agree to indemnify,
|
|
173
|
+
defend, and hold each Contributor harmless for any liability
|
|
174
|
+
incurred by, or claims asserted against, such Contributor by reason
|
|
175
|
+
of your accepting any such warranty or additional liability.
|
|
176
|
+
|
|
177
|
+
END OF TERMS AND CONDITIONS
|
|
178
|
+
|
|
179
|
+
APPENDIX: How to apply the Apache License to your work.
|
|
180
|
+
|
|
181
|
+
To apply the Apache License to your work, attach the following
|
|
182
|
+
boilerplate notice, with the fields enclosed by brackets "[]"
|
|
183
|
+
replaced with your own identifying information. (Don't include
|
|
184
|
+
the brackets!) The text should be enclosed in the appropriate
|
|
185
|
+
comment syntax for the file format. We also recommend that a
|
|
186
|
+
file or class name and description of purpose be included on the
|
|
187
|
+
same "printed page" as the copyright notice for easier
|
|
188
|
+
identification within third-party archives.
|
|
189
|
+
|
|
190
|
+
Copyright [yyyy] [name of copyright owner]
|
|
191
|
+
|
|
192
|
+
Licensed under the Apache License, Version 2.0 (the "License");
|
|
193
|
+
you may not use this file except in compliance with the License.
|
|
194
|
+
You may obtain a copy of the License at
|
|
195
|
+
|
|
196
|
+
http://www.apache.org/licenses/LICENSE-2.0
|
|
197
|
+
|
|
198
|
+
Unless required by applicable law or agreed to in writing, software
|
|
199
|
+
distributed under the License is distributed on an "AS IS" BASIS,
|
|
200
|
+
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
|
201
|
+
See the License for the specific language governing permissions and
|
|
202
|
+
limitations under the License.
|
package/dist/index.d.ts
CHANGED
|
@@ -52,6 +52,110 @@ declare function rowToMetricSample(row: GSCReportRow, dimensions: string[], metr
|
|
|
52
52
|
value: number;
|
|
53
53
|
attributes: Record<string, string | number>;
|
|
54
54
|
};
|
|
55
|
+
declare const googleSearchConsoleResources: {
|
|
56
|
+
readonly gsc_search_analytics_by_day: {
|
|
57
|
+
readonly shape: "metric";
|
|
58
|
+
readonly description: "Daily site totals - clicks, impressions, CTR, and average position across all queries and pages.";
|
|
59
|
+
readonly unit: "clicks";
|
|
60
|
+
readonly granularity: "day";
|
|
61
|
+
readonly endpoint: "POST /webmasters/v3/sites/{siteUrl}/searchAnalytics/query";
|
|
62
|
+
readonly dimensions: [{
|
|
63
|
+
readonly name: "date";
|
|
64
|
+
readonly description: "Calendar day of the metric sample.";
|
|
65
|
+
}];
|
|
66
|
+
readonly responses: {
|
|
67
|
+
readonly oauth_token: z.ZodObject<{
|
|
68
|
+
access_token: z.ZodString;
|
|
69
|
+
expires_in: z.ZodOptional<z.ZodNumber>;
|
|
70
|
+
}, z.core.$strip>;
|
|
71
|
+
readonly search_analytics_by_day: z.ZodObject<{
|
|
72
|
+
rows: z.ZodOptional<z.ZodArray<z.ZodObject<{
|
|
73
|
+
keys: z.ZodTuple<[z.ZodString, ...z.ZodType<unknown, unknown, z.core.$ZodTypeInternals<unknown, unknown>>[]], null>;
|
|
74
|
+
clicks: z.ZodOptional<z.ZodNumber>;
|
|
75
|
+
impressions: z.ZodOptional<z.ZodNumber>;
|
|
76
|
+
ctr: z.ZodOptional<z.ZodNumber>;
|
|
77
|
+
position: z.ZodOptional<z.ZodNumber>;
|
|
78
|
+
}, z.core.$strip>>>;
|
|
79
|
+
}, z.core.$strip>;
|
|
80
|
+
};
|
|
81
|
+
};
|
|
82
|
+
readonly gsc_top_queries: {
|
|
83
|
+
readonly shape: "metric";
|
|
84
|
+
readonly description: "Daily clicks, impressions, CTR, and average position broken down by search query.";
|
|
85
|
+
readonly unit: "clicks";
|
|
86
|
+
readonly granularity: "day";
|
|
87
|
+
readonly endpoint: "POST /webmasters/v3/sites/{siteUrl}/searchAnalytics/query";
|
|
88
|
+
readonly dimensions: [{
|
|
89
|
+
readonly name: "date";
|
|
90
|
+
readonly description: "Calendar day of the metric sample.";
|
|
91
|
+
}, {
|
|
92
|
+
readonly name: "query";
|
|
93
|
+
readonly description: "Search term that surfaced a result for the property.";
|
|
94
|
+
}];
|
|
95
|
+
readonly responses: {
|
|
96
|
+
readonly top_queries: z.ZodObject<{
|
|
97
|
+
rows: z.ZodOptional<z.ZodArray<z.ZodObject<{
|
|
98
|
+
keys: z.ZodTuple<[z.ZodString, ...z.ZodType<unknown, unknown, z.core.$ZodTypeInternals<unknown, unknown>>[]], null>;
|
|
99
|
+
clicks: z.ZodOptional<z.ZodNumber>;
|
|
100
|
+
impressions: z.ZodOptional<z.ZodNumber>;
|
|
101
|
+
ctr: z.ZodOptional<z.ZodNumber>;
|
|
102
|
+
position: z.ZodOptional<z.ZodNumber>;
|
|
103
|
+
}, z.core.$strip>>>;
|
|
104
|
+
}, z.core.$strip>;
|
|
105
|
+
};
|
|
106
|
+
};
|
|
107
|
+
readonly gsc_top_pages: {
|
|
108
|
+
readonly shape: "metric";
|
|
109
|
+
readonly description: "Daily clicks, impressions, CTR, and average position broken down by landing page URL.";
|
|
110
|
+
readonly unit: "clicks";
|
|
111
|
+
readonly granularity: "day";
|
|
112
|
+
readonly endpoint: "POST /webmasters/v3/sites/{siteUrl}/searchAnalytics/query";
|
|
113
|
+
readonly dimensions: [{
|
|
114
|
+
readonly name: "date";
|
|
115
|
+
readonly description: "Calendar day of the metric sample.";
|
|
116
|
+
}, {
|
|
117
|
+
readonly name: "page";
|
|
118
|
+
readonly description: "Canonical URL of the page that surfaced in search.";
|
|
119
|
+
}];
|
|
120
|
+
readonly responses: {
|
|
121
|
+
readonly top_pages: z.ZodObject<{
|
|
122
|
+
rows: z.ZodOptional<z.ZodArray<z.ZodObject<{
|
|
123
|
+
keys: z.ZodTuple<[z.ZodString, ...z.ZodType<unknown, unknown, z.core.$ZodTypeInternals<unknown, unknown>>[]], null>;
|
|
124
|
+
clicks: z.ZodOptional<z.ZodNumber>;
|
|
125
|
+
impressions: z.ZodOptional<z.ZodNumber>;
|
|
126
|
+
ctr: z.ZodOptional<z.ZodNumber>;
|
|
127
|
+
position: z.ZodOptional<z.ZodNumber>;
|
|
128
|
+
}, z.core.$strip>>>;
|
|
129
|
+
}, z.core.$strip>;
|
|
130
|
+
};
|
|
131
|
+
};
|
|
132
|
+
readonly gsc_top_countries: {
|
|
133
|
+
readonly shape: "metric";
|
|
134
|
+
readonly description: "Daily clicks, impressions, CTR, and average position broken down by visitor country.";
|
|
135
|
+
readonly unit: "clicks";
|
|
136
|
+
readonly granularity: "day";
|
|
137
|
+
readonly endpoint: "POST /webmasters/v3/sites/{siteUrl}/searchAnalytics/query";
|
|
138
|
+
readonly dimensions: [{
|
|
139
|
+
readonly name: "date";
|
|
140
|
+
readonly description: "Calendar day of the metric sample.";
|
|
141
|
+
}, {
|
|
142
|
+
readonly name: "country";
|
|
143
|
+
readonly description: "ISO 3166-1 alpha-3 country code of the searcher.";
|
|
144
|
+
}];
|
|
145
|
+
readonly responses: {
|
|
146
|
+
readonly top_countries: z.ZodObject<{
|
|
147
|
+
rows: z.ZodOptional<z.ZodArray<z.ZodObject<{
|
|
148
|
+
keys: z.ZodTuple<[z.ZodString, ...z.ZodType<unknown, unknown, z.core.$ZodTypeInternals<unknown, unknown>>[]], null>;
|
|
149
|
+
clicks: z.ZodOptional<z.ZodNumber>;
|
|
150
|
+
impressions: z.ZodOptional<z.ZodNumber>;
|
|
151
|
+
ctr: z.ZodOptional<z.ZodNumber>;
|
|
152
|
+
position: z.ZodOptional<z.ZodNumber>;
|
|
153
|
+
}, z.core.$strip>>>;
|
|
154
|
+
}, z.core.$strip>;
|
|
155
|
+
};
|
|
156
|
+
};
|
|
157
|
+
};
|
|
158
|
+
declare const id = "google-search-console";
|
|
55
159
|
declare class GSCConnector extends BaseConnector<GSCSettings, GSCCredentials> {
|
|
56
160
|
static readonly id = "google-search-console";
|
|
57
161
|
static readonly resources: {
|
|
@@ -229,4 +333,4 @@ declare class GSCConnector extends BaseConnector<GSCSettings, GSCCredentials> {
|
|
|
229
333
|
sync(options: SyncOptions, storage: StorageHandle, signal?: AbortSignal): Promise<SyncResult>;
|
|
230
334
|
}
|
|
231
335
|
|
|
232
|
-
export { GSCConnector, type GSCSettings, configFields, GSCConnector as default, doc, rowToMetricSample };
|
|
336
|
+
export { GSCConnector, type GSCSettings, configFields, GSCConnector as default, doc, id, googleSearchConsoleResources as resources, rowToMetricSample };
|
package/dist/index.js
CHANGED
|
@@ -346,8 +346,9 @@ var googleSearchConsoleResources = defineResources({
|
|
|
346
346
|
responses: { top_countries: reportSchema(2) }
|
|
347
347
|
}
|
|
348
348
|
});
|
|
349
|
+
var id = "google-search-console";
|
|
349
350
|
var GSCConnector = class _GSCConnector extends BaseConnector {
|
|
350
|
-
static id =
|
|
351
|
+
static id = id;
|
|
351
352
|
static resources = googleSearchConsoleResources;
|
|
352
353
|
static schemas = schemasFromResources(googleSearchConsoleResources);
|
|
353
354
|
static create(input, ctx) {
|
|
@@ -366,7 +367,7 @@ var GSCConnector = class _GSCConnector extends BaseConnector {
|
|
|
366
367
|
ctx
|
|
367
368
|
);
|
|
368
369
|
}
|
|
369
|
-
id =
|
|
370
|
+
id = id;
|
|
370
371
|
credentials = gscCredentials;
|
|
371
372
|
cachedToken = null;
|
|
372
373
|
async fetchOAuthToken(url, body, signal) {
|
|
@@ -504,6 +505,8 @@ export {
|
|
|
504
505
|
configFields,
|
|
505
506
|
index_default as default,
|
|
506
507
|
doc,
|
|
508
|
+
id,
|
|
509
|
+
googleSearchConsoleResources as resources,
|
|
507
510
|
rowToMetricSample
|
|
508
511
|
};
|
|
509
512
|
//# sourceMappingURL=index.js.map
|
package/dist/index.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"sources":["../../../connector-shared/src/errors.ts","../../../connector-shared/src/retry.ts","../../../connector-shared/src/version.ts","../../../connector-shared/src/request.ts","../../../connector-shared/src/rate-limit.ts","../../../connector-shared/src/sanitize.ts","../../../connector-shared/src/epoch.ts","../../../connector-shared/src/pagination.ts","../../../connector-shared/src/logger.ts","../src/google-search-console.ts","../src/index.ts"],"sourcesContent":["import type { HttpResponse } from './types';\n\nexport type HttpErrorKind =\n | 'transient'\n | 'rate_limit'\n | 'auth'\n | 'upstream_bug'\n | 'client_bug';\n\nexport abstract class HttpClientError extends Error {\n abstract readonly kind: HttpErrorKind;\n readonly response?: HttpResponse;\n\n constructor(message: string, response?: HttpResponse) {\n super(message);\n this.name = new.target.name;\n this.response = response;\n }\n}\n\nexport class TransientError extends HttpClientError {\n readonly kind = 'transient' as const;\n}\n\nexport class RateLimitError extends HttpClientError {\n readonly kind = 'rate_limit' as const;\n readonly retryAfter?: Date;\n\n constructor(message: string, response?: HttpResponse, retryAfter?: Date) {\n super(message, response);\n this.retryAfter = retryAfter;\n }\n}\n\nexport class AuthError extends HttpClientError {\n readonly kind = 'auth' as const;\n}\n\nexport class UpstreamBugError extends HttpClientError {\n readonly kind = 'upstream_bug' as const;\n}\n\nexport class ClientBugError extends HttpClientError {\n readonly kind = 'client_bug' as const;\n}\n\nexport function classifyStatus(status: number): HttpErrorKind {\n if (status === 429) {\n return 'rate_limit';\n }\n if (status === 401 || status === 403) {\n return 'auth';\n }\n if (status === 408) {\n return 'transient';\n }\n if (status >= 500) {\n return 'upstream_bug';\n }\n if (status >= 400) {\n return 'client_bug';\n }\n return 'client_bug';\n}\n\nexport function errorForStatus(\n message: string,\n response: HttpResponse,\n retryAfter?: Date,\n): HttpClientError {\n const kind = classifyStatus(response.status);\n switch (kind) {\n case 'rate_limit':\n return new RateLimitError(message, response, retryAfter);\n case 'auth':\n return new AuthError(message, response);\n case 'transient':\n return new TransientError(message, response);\n case 'upstream_bug':\n return new UpstreamBugError(message, response);\n case 'client_bug':\n return new ClientBugError(message, response);\n }\n}\n","import { HttpClientError, RateLimitError, TransientError } from './errors';\n\nexport interface RetryPolicy {\n maxAttempts?: number;\n initialDelayMs?: number;\n maxDelayMs?: number;\n retryOn?: (status: number | null, err?: Error) => boolean;\n}\n\nexport const defaultRetryOn = (status: number | null, err?: Error): boolean => {\n if (err instanceof RateLimitError) {\n return true;\n }\n if (err instanceof TransientError) {\n return true;\n }\n if (status === null) {\n return err instanceof Error && !(err instanceof HttpClientError);\n }\n if (status === 408 || status === 429) {\n return true;\n }\n if (status >= 500) {\n return true;\n }\n return false;\n};\n\nexport function backoffDelayMs(\n attempt: number,\n policy: Required<Pick<RetryPolicy, 'initialDelayMs' | 'maxDelayMs'>>,\n): number {\n const base = policy.initialDelayMs * 2 ** attempt;\n const jitter = base * 0.25 * Math.random();\n return Math.min(base + jitter, policy.maxDelayMs);\n}\n\nexport function parseRetryAfter(\n headerValue: string | null,\n now: Date = new Date(),\n): Date | undefined {\n if (!headerValue) {\n return undefined;\n }\n const trimmed = headerValue.trim();\n if (/^\\d+$/.test(trimmed)) {\n return new Date(now.getTime() + Number(trimmed) * 1000);\n }\n const parsed = Date.parse(trimmed);\n if (Number.isNaN(parsed)) {\n return undefined;\n }\n return new Date(parsed);\n}\n\nexport function sleep(ms: number, signal?: AbortSignal): Promise<void> {\n if (signal?.aborted) {\n return Promise.reject(signal.reason ?? new Error('Aborted'));\n }\n return new Promise<void>((resolve, reject) => {\n const onAbort = () => {\n clearTimeout(timer);\n reject(signal!.reason ?? new Error('Aborted'));\n };\n const timer = setTimeout(() => {\n signal?.removeEventListener('abort', onAbort);\n resolve();\n }, ms);\n signal?.addEventListener('abort', onAbort, { once: true });\n });\n}\n","export const HTTP_CLIENT_VERSION = '0.0.0';\n\nexport const DEFAULT_USER_AGENT = `rawdash-connector/${HTTP_CLIENT_VERSION} (+https://rawdash.dev)`;\n\nexport function connectorUserAgent(connectorId: string): string {\n return `rawdash-connector-${connectorId}/${HTTP_CLIENT_VERSION} (+https://rawdash.dev)`;\n}\n","import {\n AuthError,\n ClientBugError,\n HttpClientError,\n RateLimitError,\n TransientError,\n UpstreamBugError,\n errorForStatus,\n} from './errors';\nimport { defaultRetryOn, parseRetryAfter, sleep } from './retry';\nimport type { FetchLike, HttpMethod, HttpRequest, HttpResponse } from './types';\nimport { DEFAULT_USER_AGENT } from './version';\n\nconst DEFAULT_TIMEOUT_MS = 10_000;\nconst DEFAULT_MAX_ATTEMPTS = 3;\nconst DEFAULT_INITIAL_DELAY_MS = 1000;\nconst DEFAULT_MAX_DELAY_MS = 60_000;\nconst OBSERVER_TIMEOUT_MS = 250;\n\nexport interface RequestObservation {\n url: string;\n method: HttpMethod;\n status: number;\n resource: string;\n requestId: string;\n body: unknown;\n}\n\nexport type RequestObserver = (\n event: RequestObservation,\n) => void | Promise<void>;\n\nexport interface RequestOptions {\n fetch?: FetchLike;\n observer?: RequestObserver;\n resource: string;\n requestId?: string;\n}\n\nasync function notifyObserver(\n observer: RequestObserver,\n event: RequestObservation,\n): Promise<void> {\n let result: void | Promise<void>;\n try {\n result = observer(event);\n } catch (err) {\n console.warn('[connector-shared] request observer threw:', err);\n return;\n }\n if (!(result instanceof Promise)) {\n return;\n }\n const guarded = result.catch((err) => {\n console.warn('[connector-shared] request observer rejected:', err);\n });\n let timer: ReturnType<typeof setTimeout> | undefined;\n const timeout = new Promise<void>((resolve) => {\n timer = setTimeout(resolve, OBSERVER_TIMEOUT_MS);\n });\n try {\n await Promise.race([guarded, timeout]);\n } finally {\n if (timer) {\n clearTimeout(timer);\n }\n }\n}\n\nfunction newRequestId(): string {\n const c = (globalThis as { crypto?: { randomUUID?: () => string } }).crypto;\n if (c?.randomUUID) {\n return c.randomUUID();\n }\n return `${Date.now().toString(36)}-${Math.random().toString(36).slice(2, 10)}`;\n}\n\nfunction mergeHeaders(\n defaults: Record<string, string>,\n overrides: Record<string, string> | undefined,\n): Record<string, string> {\n const merged: Record<string, string> = {};\n for (const [k, v] of Object.entries(defaults)) {\n merged[k.toLowerCase()] = v;\n }\n if (overrides) {\n for (const [k, v] of Object.entries(overrides)) {\n merged[k.toLowerCase()] = v;\n }\n }\n return merged;\n}\n\nfunction linkTimeoutSignal(\n parent: AbortSignal | undefined,\n timeoutMs: number,\n): { signal: AbortSignal; cancel: () => void } {\n const controller = new AbortController();\n const onParentAbort = () => {\n controller.abort(parent?.reason);\n };\n if (parent) {\n if (parent.aborted) {\n controller.abort(parent.reason);\n } else {\n parent.addEventListener('abort', onParentAbort, { once: true });\n }\n }\n const timer = setTimeout(() => {\n controller.abort(new Error(`Request timed out after ${timeoutMs}ms`));\n }, timeoutMs);\n return {\n signal: controller.signal,\n cancel: () => {\n clearTimeout(timer);\n if (parent) {\n parent.removeEventListener('abort', onParentAbort);\n }\n },\n };\n}\n\nasync function readBody(res: Response, parseJson: boolean): Promise<unknown> {\n if (res.status === 204 || res.status === 205) {\n return null;\n }\n const contentType = res.headers.get('content-type') ?? '';\n if (parseJson && contentType.includes('application/json')) {\n const text = await res.text();\n if (text.length === 0) {\n return null;\n }\n return JSON.parse(text);\n }\n return res.text();\n}\n\nexport async function request<T = unknown>(\n req: HttpRequest,\n options: RequestOptions,\n): Promise<HttpResponse<T>> {\n const fetchImpl: FetchLike = options.fetch ?? (globalThis.fetch as FetchLike);\n const retry = req.retry ?? {};\n const maxAttempts = retry.maxAttempts ?? DEFAULT_MAX_ATTEMPTS;\n const initialDelayMs = retry.initialDelayMs ?? DEFAULT_INITIAL_DELAY_MS;\n const maxDelayMs = retry.maxDelayMs ?? DEFAULT_MAX_DELAY_MS;\n const retryOn = retry.retryOn ?? defaultRetryOn;\n const timeoutMs = req.timeoutMs ?? DEFAULT_TIMEOUT_MS;\n const parseJson = req.parseJson ?? true;\n\n const headers = mergeHeaders(\n {\n 'User-Agent': DEFAULT_USER_AGENT,\n Accept: 'application/json',\n },\n req.headers,\n );\n\n let lastErr: Error | undefined;\n\n for (let attempt = 0; attempt < maxAttempts; attempt++) {\n req.signal?.throwIfAborted();\n\n const { signal, cancel } = linkTimeoutSignal(req.signal, timeoutMs);\n let res: Response;\n try {\n res = await fetchImpl(req.url, {\n method: req.method ?? 'GET',\n headers,\n body: req.body as RequestInit['body'],\n signal,\n });\n } catch (err) {\n cancel();\n if (req.signal?.aborted) {\n throw req.signal.reason ?? err;\n }\n const error = err instanceof Error ? err : new Error(String(err));\n lastErr = error;\n if (attempt < maxAttempts - 1 && retryOn(null, error)) {\n const delay = computeDelay(attempt, initialDelayMs, maxDelayMs);\n await sleep(delay, req.signal);\n continue;\n }\n throw new TransientError(error.message);\n }\n cancel();\n\n const body = await readBody(res, parseJson);\n const httpResponse: HttpResponse<T> = {\n status: res.status,\n headers: res.headers,\n body: body as T,\n };\n if (req.rateLimit) {\n const state = req.rateLimit.parse(res.headers);\n if (state) {\n httpResponse.rateLimitState = state;\n }\n }\n\n if (options.observer) {\n await notifyObserver(options.observer, {\n url: req.url,\n method: req.method ?? 'GET',\n status: res.status,\n resource: options.resource,\n requestId: options.requestId ?? newRequestId(),\n body,\n });\n }\n\n if (res.ok) {\n return httpResponse;\n }\n\n const retryAfter = parseRetryAfter(res.headers.get('retry-after'));\n const message = `HTTP ${res.status} ${res.statusText} for ${req.method ?? 'GET'} ${req.url}`;\n const err = errorForStatus(message, httpResponse, retryAfter);\n\n if (\n attempt < maxAttempts - 1 &&\n retryOn(res.status, err) &&\n !(err instanceof AuthError) &&\n !(err instanceof ClientBugError)\n ) {\n lastErr = err;\n let delay = computeDelay(attempt, initialDelayMs, maxDelayMs);\n if (err instanceof RateLimitError && retryAfter) {\n const wait = retryAfter.getTime() - Date.now();\n if (wait > 0) {\n delay = Math.min(wait, maxDelayMs);\n }\n }\n await sleep(delay, req.signal);\n continue;\n }\n\n throw err;\n }\n\n throw lastErr ?? new UpstreamBugError('Exhausted retry attempts');\n}\n\nfunction computeDelay(\n attempt: number,\n initialDelayMs: number,\n maxDelayMs: number,\n): number {\n const base = initialDelayMs * 2 ** attempt;\n const jitter = base * 0.25 * Math.random();\n return Math.min(base + jitter, maxDelayMs);\n}\n\nexport { HttpClientError };\n","export interface RateLimitState {\n remaining: number;\n resetAt: Date;\n}\n\nexport interface RateLimitPolicy {\n parse(headers: Headers): RateLimitState | null;\n}\n\nexport interface StandardRateLimitPolicyConfig {\n remainingHeader: string;\n resetHeader: string;\n resetUnit: 's' | 'ms';\n resetFallbackMs?: number;\n}\n\nexport function standardRateLimitPolicy(\n config: StandardRateLimitPolicyConfig,\n): RateLimitPolicy {\n const { remainingHeader, resetHeader, resetUnit, resetFallbackMs } = config;\n const multiplier = resetUnit === 's' ? 1000 : 1;\n return {\n parse(h) {\n const remainingRaw = h.get(remainingHeader);\n if (remainingRaw === null || remainingRaw.trim() === '') {\n return null;\n }\n const remaining = Number(remainingRaw);\n if (!Number.isFinite(remaining)) {\n return null;\n }\n const resetRaw = h.get(resetHeader);\n if (resetRaw === null) {\n if (resetFallbackMs === undefined) {\n return null;\n }\n return {\n remaining,\n resetAt: new Date(Date.now() + resetFallbackMs),\n };\n }\n if (resetRaw.trim() === '') {\n return null;\n }\n const reset = Number(resetRaw);\n if (!Number.isFinite(reset) || reset < 0) {\n return null;\n }\n const resetMs = reset * multiplier;\n if (!Number.isFinite(resetMs)) {\n return null;\n }\n return { remaining, resetAt: new Date(resetMs) };\n },\n };\n}\n","export interface SanitizeAllowedUrlOptions {\n url: string | null;\n host: string;\n pathname: string;\n protocol?: 'https:' | 'http:';\n}\n\nexport function sanitizeAllowedUrl(\n options: SanitizeAllowedUrlOptions,\n): string | null {\n const { url, host, pathname, protocol = 'https:' } = options;\n if (url === null) {\n return null;\n }\n try {\n const u = new URL(url);\n if (u.protocol !== protocol || u.host !== host || u.pathname !== pathname) {\n return null;\n }\n return u.toString();\n } catch {\n return null;\n }\n}\n","export type EpochUnit = 'ms' | 's' | 'iso';\n\nexport function parseEpoch(\n value: number | string | null | undefined,\n unit: EpochUnit,\n): number | null {\n if (value === null || value === undefined) {\n return null;\n }\n if (unit === 'iso') {\n if (typeof value !== 'string') {\n return null;\n }\n const ms = new Date(value).getTime();\n return Number.isFinite(ms) ? ms : null;\n }\n if (typeof value === 'string' && value.trim() === '') {\n return null;\n }\n const n = typeof value === 'number' ? value : Number(value);\n if (!Number.isFinite(n)) {\n return null;\n }\n const result = unit === 's' ? n * 1000 : n;\n return Number.isFinite(result) ? result : null;\n}\n","import { request } from './request';\nimport type { HttpRequest } from './types';\n\nexport function parseLinkHeader(header: string | null): Record<string, string> {\n if (!header) {\n return {};\n }\n const result: Record<string, string> = {};\n for (const part of header.split(',')) {\n const match = part.match(/<([^>]+)>\\s*;\\s*rel=\"([^\"]+)\"/);\n if (match) {\n result[match[2]!] = match[1]!;\n }\n }\n return result;\n}\n\nexport async function* paginateLink<T>(\n initial: HttpRequest,\n parse: (body: unknown) => T[],\n options: { resource: string },\n): AsyncIterable<T> {\n let next: string | null = initial.url;\n while (next) {\n const res: Awaited<ReturnType<typeof request>> = await request(\n {\n ...initial,\n url: next,\n },\n { resource: options.resource },\n );\n for (const item of parse(res.body)) {\n yield item;\n }\n const links = parseLinkHeader(res.headers.get('link'));\n next = links['next'] ?? null;\n }\n}\n\nexport async function* paginateCursor<T>(\n initial: HttpRequest,\n parse: (body: unknown) => { items: T[]; nextCursor: string | null },\n buildNext: (req: HttpRequest, cursor: string) => HttpRequest,\n options: { resource: string },\n): AsyncIterable<T> {\n let req: HttpRequest = initial;\n while (true) {\n const res = await request(req, { resource: options.resource });\n const { items, nextCursor } = parse(res.body);\n for (const item of items) {\n yield item;\n }\n if (!nextCursor) {\n return;\n }\n req = buildNext(req, nextCursor);\n }\n}\n\nexport async function* paginatePage<T>(\n initial: HttpRequest,\n parse: (body: unknown) => { items: T[]; hasMore: boolean },\n buildPage: (req: HttpRequest, page: number) => HttpRequest,\n options: { resource: string },\n): AsyncIterable<T> {\n let page = 1;\n while (true) {\n const req = page === 1 ? initial : buildPage(initial, page);\n const res = await request(req, { resource: options.resource });\n const { items, hasMore } = parse(res.body);\n for (const item of items) {\n yield item;\n }\n if (!hasMore || items.length === 0) {\n return;\n }\n page++;\n }\n}\n","export type LogFields = Record<string, unknown>;\n\nexport interface ConnectorLogger {\n info(event: string, fields?: LogFields): void;\n warn(event: string, fields?: LogFields): void;\n}\n\nexport interface ConnectorLoggerOptions {\n scope: string;\n}\n\nconst MAX_VALUE_LEN = 120;\n\nfunction truncate(s: string, max = MAX_VALUE_LEN): string {\n if (s.length <= max) {\n return s;\n }\n return `${s.slice(0, max - 1)}…`;\n}\n\nfunction formatValue(value: unknown): string {\n if (value === null) {\n return 'null';\n }\n if (value === undefined) {\n return '';\n }\n if (typeof value === 'number' || typeof value === 'boolean') {\n return String(value);\n }\n if (typeof value === 'string') {\n const t = truncate(value);\n if (/[\\s\"=]/.test(t)) {\n return JSON.stringify(t);\n }\n return t;\n }\n if (typeof value === 'bigint') {\n return value.toString();\n }\n let json: string | undefined;\n try {\n json = JSON.stringify(value);\n } catch {\n json = undefined;\n }\n return truncate(json ?? String(value));\n}\n\nexport function formatLogFields(fields?: LogFields): string {\n if (!fields) {\n return '';\n }\n const parts: string[] = [];\n for (const [k, v] of Object.entries(fields)) {\n if (v === undefined) {\n continue;\n }\n parts.push(`${k}=${formatValue(v)}`);\n }\n return parts.length > 0 ? ` ${parts.join(' ')}` : '';\n}\n\nexport function formatLogLine(\n scope: string,\n event: string,\n fields?: LogFields,\n): string {\n return `[${scope}] ${event}${formatLogFields(fields)}`;\n}\n\nexport function createDefaultConnectorLogger(\n opts: ConnectorLoggerOptions,\n): ConnectorLogger {\n return {\n info(event, fields) {\n console.info(formatLogLine(opts.scope, event, fields));\n },\n warn(event, fields) {\n console.warn(formatLogLine(opts.scope, event, fields));\n },\n };\n}\n\nconst NOOP_LOGGER: ConnectorLogger = {\n info() {},\n warn() {},\n};\n\nexport function noopConnectorLogger(): ConnectorLogger {\n return NOOP_LOGGER;\n}\n","import { connectorUserAgent } from '@rawdash/connector-shared';\nimport {\n BaseConnector,\n type ConnectorContext,\n type ConnectorDoc,\n type CredentialsSchema,\n type StorageHandle,\n type SyncOptions,\n type SyncResult,\n defineConfigFields,\n defineConnectorDoc,\n defineResources,\n schemasFromResources,\n} from '@rawdash/core';\nimport { z } from 'zod';\n\nexport const configFields = defineConfigFields(\n z\n .object({\n siteUrl: z.string().trim().min(1).meta({\n label: 'Site URL',\n description:\n 'Verified Search Console property. URL-prefix properties look like \"https://example.com/\"; Domain properties look like \"sc-domain:example.com\".',\n placeholder: 'https://example.com/',\n }),\n serviceAccountJson: z\n .object({ $secret: z.string().trim().min(1) })\n .optional()\n .meta({\n label: 'Service Account JSON (recommended)',\n description:\n 'Contents of the JSON key file for a Google service account that has been added as a Search Console user (Owner or Full user) on the property. Create one at Google Cloud -> IAM & Admin -> Service Accounts.',\n secret: true,\n }),\n refreshToken: z\n .object({ $secret: z.string().trim().min(1) })\n .optional()\n .meta({\n label: 'OAuth Refresh Token',\n description:\n 'Google OAuth 2.0 refresh token with webmasters.readonly scope. Required if not using serviceAccountJson.',\n secret: true,\n }),\n clientId: z.string().trim().min(1).optional().meta({\n label: 'OAuth Client ID',\n description:\n 'OAuth 2.0 client ID from Google Cloud Console. Required when using refreshToken auth.',\n placeholder: '...apps.googleusercontent.com',\n }),\n clientSecret: z\n .object({ $secret: z.string().trim().min(1) })\n .optional()\n .meta({\n label: 'OAuth Client Secret',\n description:\n 'OAuth 2.0 client secret from Google Cloud Console. Required when using refreshToken auth.',\n secret: true,\n }),\n lookbackDays: z.number().int().positive().optional().meta({\n label: 'Lookback days (full sync)',\n description:\n 'How many calendar days to fetch on a full sync. Defaults to 90.',\n placeholder: '90',\n }),\n })\n .refine(\n (val) =>\n val.serviceAccountJson !== undefined ||\n (val.refreshToken !== undefined &&\n val.clientId !== undefined &&\n val.clientSecret !== undefined),\n {\n message:\n 'Provide either serviceAccountJson or the full OAuth tuple (refreshToken + clientId + clientSecret)',\n },\n ),\n);\n\nexport const doc: ConnectorDoc = defineConnectorDoc({\n displayName: 'Google Search Console',\n category: 'marketing',\n brandColor: '#458CF5',\n tagline:\n 'Sync daily Search Console SEO metrics - clicks, impressions, CTR, and average position - by date, query, page, and country.',\n vendor: {\n name: 'Google Search Console',\n apiDocs:\n 'https://developers.google.com/webmaster-tools/v1/api_reference_index',\n website: 'https://search.google.com/search-console',\n },\n auth: {\n summary:\n 'Authenticate against the Search Console API with either a Google service account JSON key (recommended) or an OAuth 2.0 refresh-token tuple. The identity must be added as a user on the Search Console property (Owner or Full user).',\n setup: [\n 'Identify the property to sync. URL-prefix properties use the full origin (e.g. https://example.com/); Domain properties use the sc-domain:example.com format.',\n 'Recommended: create a service account at Google Cloud -> IAM & Admin -> Service Accounts, generate a JSON key, then in Search Console add the service account email as a user on the property. Store the JSON as a secret and reference it as serviceAccountJson: secret(\"GSC_SERVICE_ACCOUNT_JSON\").',\n 'Alternative: provide an OAuth 2.0 refresh token with the webmasters.readonly scope together with its clientId and clientSecret from the Google Cloud Console.',\n ],\n },\n rateLimit:\n 'Search Console API quota is 1,200 queries per minute per project (default); 429 responses are retried automatically with exponential backoff.',\n limitations: [\n 'Search Console aggregates data with a 2-3 day lag, so incremental syncs refetch the trailing 3 days.',\n 'Each query is paginated 25,000 rows per page; a phase that yields more than that paginates by startRow.',\n ],\n});\n\n// ---------------------------------------------------------------------------\n// Settings / credentials\n// ---------------------------------------------------------------------------\n\nexport interface GSCSettings {\n siteUrl: string;\n lookbackDays?: number;\n}\n\nconst gscCredentials = {\n serviceAccountJson: {\n description: 'Google service account JSON key (base64 or raw JSON)',\n auth: 'optional' as const,\n },\n refreshToken: {\n description: 'Google OAuth 2.0 refresh token',\n auth: 'optional' as const,\n },\n clientId: {\n description: 'Google OAuth 2.0 client ID',\n auth: 'optional' as const,\n },\n clientSecret: {\n description: 'Google OAuth 2.0 client secret',\n auth: 'optional' as const,\n },\n} satisfies CredentialsSchema;\n\ntype GSCCredentials = typeof gscCredentials;\n\n// ---------------------------------------------------------------------------\n// Sync phases + cursor\n// ---------------------------------------------------------------------------\n\nconst PHASE_ORDER = [\n 'search_analytics_by_day',\n 'top_queries',\n 'top_pages',\n 'top_countries',\n] as const;\n\ntype GSCPhase = (typeof PHASE_ORDER)[number];\n\ninterface GSCDateRange {\n startDate: string;\n endDate: string;\n}\n\ninterface GSCSyncCursor {\n phase: GSCPhase;\n dateRange: GSCDateRange;\n}\n\nconst GSC_DATE_RE = /^\\d{4}-\\d{2}-\\d{2}$/;\n\nfunction isGSCDateString(value: unknown): value is string {\n return typeof value === 'string' && GSC_DATE_RE.test(value);\n}\n\nfunction isGSCDateRange(value: unknown): value is GSCDateRange {\n if (typeof value !== 'object' || value === null) {\n return false;\n }\n const v = value as { startDate?: unknown; endDate?: unknown };\n return isGSCDateString(v.startDate) && isGSCDateString(v.endDate);\n}\n\nfunction isGSCSyncCursor(value: unknown): value is GSCSyncCursor {\n if (typeof value !== 'object' || value === null) {\n return false;\n }\n const v = value as { phase?: unknown; dateRange?: unknown };\n if (typeof v.phase !== 'string') {\n return false;\n }\n if (!(PHASE_ORDER as readonly string[]).includes(v.phase)) {\n return false;\n }\n return isGSCDateRange(v.dateRange);\n}\n\n// ---------------------------------------------------------------------------\n// Phase configs - dimensions for each resource\n// ---------------------------------------------------------------------------\n\ninterface PhaseConfig {\n dimensions: string[];\n metricName: string;\n}\n\nconst PHASE_CONFIGS: Record<GSCPhase, PhaseConfig> = {\n search_analytics_by_day: {\n dimensions: ['date'],\n metricName: 'gsc_search_analytics_by_day',\n },\n top_queries: {\n dimensions: ['date', 'query'],\n metricName: 'gsc_top_queries',\n },\n top_pages: {\n dimensions: ['date', 'page'],\n metricName: 'gsc_top_pages',\n },\n top_countries: {\n dimensions: ['date', 'country'],\n metricName: 'gsc_top_countries',\n },\n};\n\nconst ROWS_PER_PAGE = 25_000;\nconst METRIC_FIELDS = ['clicks', 'impressions', 'ctr', 'position'] as const;\n\n// ---------------------------------------------------------------------------\n// GSC Search Analytics API types\n// ---------------------------------------------------------------------------\n\nexport interface GSCReportRow {\n keys?: string[];\n clicks?: number;\n impressions?: number;\n ctr?: number;\n position?: number;\n}\n\ninterface GSCReportResponse {\n rows?: GSCReportRow[];\n responseAggregationType?: string;\n}\n\n// ---------------------------------------------------------------------------\n// Service account / OAuth token helpers\n// ---------------------------------------------------------------------------\n\ninterface ServiceAccountKey {\n client_email: string;\n private_key: string;\n token_uri?: string;\n}\n\ninterface TokenResponse {\n access_token: string;\n expires_in?: number;\n}\n\nfunction base64urlFromBytes(bytes: Uint8Array): string {\n let binary = '';\n for (let i = 0; i < bytes.length; i++) {\n binary += String.fromCharCode(bytes[i]!);\n }\n return btoa(binary).replace(/\\+/g, '-').replace(/\\//g, '_').replace(/=/g, '');\n}\n\nfunction base64urlFromString(str: string): string {\n return base64urlFromBytes(new TextEncoder().encode(str));\n}\n\nasync function signRS256JWT(\n payload: Record<string, unknown>,\n privateKeyPem: string,\n): Promise<string> {\n const header = { alg: 'RS256', typ: 'JWT' };\n const headerB64 = base64urlFromString(JSON.stringify(header));\n const payloadB64 = base64urlFromString(JSON.stringify(payload));\n const signingInput = `${headerB64}.${payloadB64}`;\n\n const pemContent = privateKeyPem\n .replace(/-----BEGIN PRIVATE KEY-----/g, '')\n .replace(/-----END PRIVATE KEY-----/g, '')\n .replace(/\\s/g, '');\n const der = Uint8Array.from(atob(pemContent), (c) => c.charCodeAt(0));\n\n const key = await globalThis.crypto.subtle.importKey(\n 'pkcs8',\n der,\n { name: 'RSASSA-PKCS1-v1_5', hash: 'SHA-256' },\n false,\n ['sign'],\n );\n\n const signature = await globalThis.crypto.subtle.sign(\n 'RSASSA-PKCS1-v1_5',\n key,\n new TextEncoder().encode(signingInput),\n );\n\n return `${signingInput}.${base64urlFromBytes(new Uint8Array(signature))}`;\n}\n\nfunction parseServiceAccountJson(value: string): ServiceAccountKey {\n const trimmed = value.trim();\n if (trimmed.startsWith('{')) {\n return JSON.parse(trimmed) as ServiceAccountKey;\n }\n const binary = atob(trimmed);\n const bytes = new Uint8Array(binary.length);\n for (let i = 0; i < binary.length; i++) {\n bytes[i] = binary.charCodeAt(i);\n }\n const decoded = new TextDecoder().decode(bytes);\n return JSON.parse(decoded) as ServiceAccountKey;\n}\n\nasync function buildServiceAccountJwt(\n serviceAccountJson: string,\n): Promise<{ url: string; body: string }> {\n const sa = parseServiceAccountJson(serviceAccountJson);\n const now = Math.floor(Date.now() / 1000);\n const jwt = await signRS256JWT(\n {\n iss: sa.client_email,\n scope: 'https://www.googleapis.com/auth/webmasters.readonly',\n aud: sa.token_uri ?? 'https://oauth2.googleapis.com/token',\n exp: now + 3600,\n iat: now,\n },\n sa.private_key,\n );\n\n const body = new URLSearchParams({\n grant_type: 'urn:ietf:params:oauth:grant-type:jwt-bearer',\n assertion: jwt,\n }).toString();\n\n return {\n url: sa.token_uri ?? 'https://oauth2.googleapis.com/token',\n body,\n };\n}\n\n// ---------------------------------------------------------------------------\n// Date helpers\n// ---------------------------------------------------------------------------\n\nfunction toGSCDate(date: Date): string {\n const y = date.getUTCFullYear();\n const m = String(date.getUTCMonth() + 1).padStart(2, '0');\n const d = String(date.getUTCDate()).padStart(2, '0');\n return `${y}-${m}-${d}`;\n}\n\nfunction gscDateToMs(gscDate: string): number {\n // GSC date dimension comes back as 'YYYY-MM-DD'\n const y = gscDate.slice(0, 4);\n const m = gscDate.slice(5, 7);\n const d = gscDate.slice(8, 10);\n return Date.UTC(Number(y), Number(m) - 1, Number(d));\n}\n\nconst MS_PER_DAY = 24 * 60 * 60 * 1000;\nconst INCREMENTAL_LOOKBACK_DAYS = 3;\n\nfunction getDateRange(\n options: SyncOptions,\n lookbackDays: number,\n): GSCDateRange {\n const now = Date.now();\n const endDate = toGSCDate(new Date(now));\n if (options.mode === 'latest') {\n const startMs = now - (INCREMENTAL_LOOKBACK_DAYS - 1) * MS_PER_DAY;\n return { startDate: toGSCDate(new Date(startMs)), endDate };\n }\n if (options.since) {\n const sinceMs = new Date(options.since).getTime();\n if (Number.isFinite(sinceMs)) {\n const days = Math.max(1, Math.ceil((now - sinceMs) / MS_PER_DAY));\n const cappedDays = Math.min(days, lookbackDays);\n const startMs = now - (cappedDays - 1) * MS_PER_DAY;\n return { startDate: toGSCDate(new Date(startMs)), endDate };\n }\n }\n const startMs = now - (lookbackDays - 1) * MS_PER_DAY;\n return { startDate: toGSCDate(new Date(startMs)), endDate };\n}\n\n// ---------------------------------------------------------------------------\n// Row conversion\n// ---------------------------------------------------------------------------\n\nexport function rowToMetricSample(\n row: GSCReportRow,\n dimensions: string[],\n metricName: string,\n): {\n name: string;\n ts: number;\n value: number;\n attributes: Record<string, string | number>;\n} {\n const attributes: Record<string, string | number> = {};\n const keys = row.keys ?? [];\n for (let i = 0; i < dimensions.length; i++) {\n attributes[dimensions[i]!] = keys[i] ?? '';\n }\n\n for (const field of METRIC_FIELDS) {\n const raw = row[field];\n attributes[field] =\n typeof raw === 'number' && Number.isFinite(raw) ? raw : 0;\n }\n\n const dateStr =\n typeof attributes['date'] === 'string' ? attributes['date'] : '1970-01-01';\n const ts = gscDateToMs(dateStr);\n const primaryValue = attributes['clicks'] as number;\n\n return {\n name: metricName,\n ts,\n value: primaryValue,\n attributes,\n };\n}\n\n// ---------------------------------------------------------------------------\n// Schemas - describe the per-resource API response shape consumed by request()\n// ---------------------------------------------------------------------------\n\nconst dateKey = z\n .string()\n .regex(/^(19|20)\\d{2}-(0[1-9]|1[0-2])-(0[1-9]|[12]\\d|3[01])$/);\nconst stringKey = z.string();\nconst numericField = z.number();\n\nfunction reportSchema(dimensionCount: number) {\n const keys =\n dimensionCount === 1\n ? z.tuple([dateKey])\n : z.tuple([dateKey, ...Array(dimensionCount - 1).fill(stringKey)] as [\n typeof dateKey,\n ...z.ZodType[],\n ]);\n return z.object({\n rows: z\n .array(\n z.object({\n keys,\n clicks: numericField.optional(),\n impressions: numericField.optional(),\n ctr: numericField.optional(),\n position: numericField.optional(),\n }),\n )\n .optional(),\n });\n}\n\nconst tokenResponseSchema = z.object({\n access_token: z.string().min(1),\n expires_in: z.number().int().positive().optional(),\n});\n\nconst googleSearchConsoleResources = defineResources({\n gsc_search_analytics_by_day: {\n shape: 'metric',\n description:\n 'Daily site totals - clicks, impressions, CTR, and average position across all queries and pages.',\n unit: 'clicks',\n granularity: 'day',\n endpoint: 'POST /webmasters/v3/sites/{siteUrl}/searchAnalytics/query',\n dimensions: [\n { name: 'date', description: 'Calendar day of the metric sample.' },\n ],\n responses: {\n oauth_token: tokenResponseSchema,\n search_analytics_by_day: reportSchema(1),\n },\n },\n gsc_top_queries: {\n shape: 'metric',\n description:\n 'Daily clicks, impressions, CTR, and average position broken down by search query.',\n unit: 'clicks',\n granularity: 'day',\n endpoint: 'POST /webmasters/v3/sites/{siteUrl}/searchAnalytics/query',\n dimensions: [\n { name: 'date', description: 'Calendar day of the metric sample.' },\n {\n name: 'query',\n description: 'Search term that surfaced a result for the property.',\n },\n ],\n responses: { top_queries: reportSchema(2) },\n },\n gsc_top_pages: {\n shape: 'metric',\n description:\n 'Daily clicks, impressions, CTR, and average position broken down by landing page URL.',\n unit: 'clicks',\n granularity: 'day',\n endpoint: 'POST /webmasters/v3/sites/{siteUrl}/searchAnalytics/query',\n dimensions: [\n { name: 'date', description: 'Calendar day of the metric sample.' },\n {\n name: 'page',\n description: 'Canonical URL of the page that surfaced in search.',\n },\n ],\n responses: { top_pages: reportSchema(2) },\n },\n gsc_top_countries: {\n shape: 'metric',\n description:\n 'Daily clicks, impressions, CTR, and average position broken down by visitor country.',\n unit: 'clicks',\n granularity: 'day',\n endpoint: 'POST /webmasters/v3/sites/{siteUrl}/searchAnalytics/query',\n dimensions: [\n { name: 'date', description: 'Calendar day of the metric sample.' },\n {\n name: 'country',\n description: 'ISO 3166-1 alpha-3 country code of the searcher.',\n },\n ],\n responses: { top_countries: reportSchema(2) },\n },\n});\n\nexport class GSCConnector extends BaseConnector<GSCSettings, GSCCredentials> {\n static readonly id = 'google-search-console';\n\n static readonly resources = googleSearchConsoleResources;\n\n static readonly schemas = schemasFromResources(googleSearchConsoleResources);\n\n static create(input: unknown, ctx?: ConnectorContext): GSCConnector {\n const parsed = configFields.parse(input);\n return new GSCConnector(\n {\n siteUrl: parsed.siteUrl,\n lookbackDays: parsed.lookbackDays,\n },\n {\n serviceAccountJson: parsed.serviceAccountJson,\n refreshToken: parsed.refreshToken,\n clientId: parsed.clientId,\n clientSecret: parsed.clientSecret,\n },\n ctx,\n );\n }\n\n readonly id = 'google-search-console';\n override readonly credentials = gscCredentials;\n\n private cachedToken: { token: string; expiresAt: number } | null = null;\n\n private async fetchOAuthToken(\n url: string,\n body: string,\n signal: AbortSignal | undefined,\n ): Promise<{ token: string; expiresAt: number }> {\n const res = await this.post<TokenResponse>(url, {\n resource: 'oauth_token',\n headers: { 'Content-Type': 'application/x-www-form-urlencoded' },\n body,\n signal,\n });\n const expiresIn = res.body.expires_in ?? 3600;\n return {\n token: res.body.access_token,\n expiresAt: Date.now() + (expiresIn - 60) * 1000,\n };\n }\n\n private async getAccessToken(signal?: AbortSignal): Promise<string> {\n if (this.cachedToken && Date.now() < this.cachedToken.expiresAt) {\n return this.cachedToken.token;\n }\n\n const { serviceAccountJson, refreshToken, clientId, clientSecret } =\n this.creds;\n\n if (serviceAccountJson) {\n const { url, body } = await buildServiceAccountJwt(serviceAccountJson);\n this.cachedToken = await this.fetchOAuthToken(url, body, signal);\n return this.cachedToken.token;\n }\n\n if (refreshToken && clientId && clientSecret) {\n const body = new URLSearchParams({\n grant_type: 'refresh_token',\n refresh_token: refreshToken,\n client_id: clientId,\n client_secret: clientSecret,\n }).toString();\n this.cachedToken = await this.fetchOAuthToken(\n 'https://oauth2.googleapis.com/token',\n body,\n signal,\n );\n return this.cachedToken.token;\n }\n\n throw new Error(\n 'GSC connector: provide either serviceAccountJson or (refreshToken + clientId + clientSecret)',\n );\n }\n\n private async runReport(\n accessToken: string,\n phase: GSCPhase,\n dateRange: GSCDateRange,\n startRow: number,\n signal?: AbortSignal,\n ): Promise<GSCReportResponse> {\n const { dimensions } = PHASE_CONFIGS[phase];\n const url = `https://searchconsole.googleapis.com/webmasters/v3/sites/${encodeURIComponent(this.settings.siteUrl)}/searchAnalytics/query`;\n\n const body: Record<string, unknown> = {\n startDate: dateRange.startDate,\n endDate: dateRange.endDate,\n dimensions,\n rowLimit: ROWS_PER_PAGE,\n startRow,\n };\n\n const res = await this.post<GSCReportResponse>(url, {\n resource: phase,\n headers: {\n Authorization: `Bearer ${accessToken}`,\n 'Content-Type': 'application/json',\n 'User-Agent': connectorUserAgent('google-search-console'),\n },\n body: JSON.stringify(body),\n signal,\n });\n return res.body;\n }\n\n async sync(\n options: SyncOptions,\n storage: StorageHandle,\n signal?: AbortSignal,\n ): Promise<SyncResult> {\n const lookbackDays = this.settings.lookbackDays ?? 90;\n\n const cursor = isGSCSyncCursor(options.cursor) ? options.cursor : undefined;\n // Restore the originally-computed window on resume so phases stay aligned\n // across midnight rollovers and lookbackDays changes between runs.\n const dateRange = cursor?.dateRange ?? getDateRange(options, lookbackDays);\n\n let accessToken: string | null = null;\n const getToken = async (sig?: AbortSignal): Promise<string> => {\n if (!accessToken) {\n accessToken = await this.getAccessToken(sig);\n }\n return accessToken;\n };\n\n const runReportWithRetry = async (\n phase: GSCPhase,\n startRow: number,\n sig: AbortSignal | undefined,\n ): Promise<GSCReportResponse> => {\n const token = await getToken(sig);\n try {\n return await this.runReport(token, phase, dateRange, startRow, sig);\n } catch (err) {\n console.warn(\n `[gsc] runReport failed, refreshing token and retrying once`,\n err,\n );\n accessToken = null;\n const freshToken = await getToken(sig);\n return this.runReport(freshToken, phase, dateRange, startRow, sig);\n }\n };\n\n const drainPhase = async (phase: GSCPhase): Promise<GSCReportRow[]> => {\n const allRows: GSCReportRow[] = [];\n let startRow = 0;\n for (;;) {\n const response = await runReportWithRetry(phase, startRow, signal);\n const rows = response.rows ?? [];\n allRows.push(...rows);\n startRow += rows.length;\n // GSC has no totalRowCount field on responses, so a short page is the\n // terminating signal. Empty page also breaks out (covers the rare\n // \"exact multiple of rowLimit\" case where one extra request is fine).\n if (rows.length < ROWS_PER_PAGE) {\n break;\n }\n }\n return allRows;\n };\n\n const resumeIdx = cursor ? PHASE_ORDER.indexOf(cursor.phase) : -1;\n const startIdx = resumeIdx >= 0 ? resumeIdx : 0;\n\n for (let i = startIdx; i < PHASE_ORDER.length; i++) {\n const phase = PHASE_ORDER[i]!;\n if (signal?.aborted) {\n return { done: false, cursor: { phase, dateRange } };\n }\n\n // Drain every page of this phase in-memory before writing so the commit\n // is one atomic call. A mid-phase failure restarts this phase from\n // scratch on the next sync; the clear-and-replace below wipes partial\n // state. If the abort signal trips mid-drain, surface a resumable\n // cursor instead of throwing the AbortError up to the caller.\n let rows: GSCReportRow[];\n try {\n rows = await drainPhase(phase);\n } catch (err) {\n if (signal?.aborted) {\n return { done: false, cursor: { phase, dateRange } };\n }\n throw err;\n }\n const cfg = PHASE_CONFIGS[phase];\n const samples = rows.map((row) =>\n rowToMetricSample(row, cfg.dimensions, cfg.metricName),\n );\n // Scoping by name ensures stale rows are wiped even when samples is empty.\n await storage.metrics(samples, { names: [cfg.metricName] });\n }\n\n return { done: true };\n }\n}\n","import { GSCConnector } from './google-search-console';\n\nexport {\n configFields,\n doc,\n GSCConnector,\n rowToMetricSample,\n} from './google-search-console';\nexport type { GSCSettings } from './google-search-console';\nexport default GSCConnector;\n"],"mappings":";AEAO,IAAM,sBAAsB;AAE5B,IAAM,qBAAqB,qBAAqB,mBAAmB;AAEnE,SAAS,mBAAmB,aAA6B;AAC9D,SAAO,qBAAqB,WAAW,IAAI,mBAAmB;AAChE;;;AOLA;AAAA,EACE;AAAA,EAOA;AAAA,EACA;AAAA,EACA;AAAA,EACA;AAAA,OACK;AACP,SAAS,SAAS;AAEX,IAAM,eAAe;AAAA,EAC1B,EACG,OAAO;AAAA,IACN,SAAS,EAAE,OAAO,EAAE,KAAK,EAAE,IAAI,CAAC,EAAE,KAAK;AAAA,MACrC,OAAO;AAAA,MACP,aACE;AAAA,MACF,aAAa;AAAA,IACf,CAAC;AAAA,IACD,oBAAoB,EACjB,OAAO,EAAE,SAAS,EAAE,OAAO,EAAE,KAAK,EAAE,IAAI,CAAC,EAAE,CAAC,EAC5C,SAAS,EACT,KAAK;AAAA,MACJ,OAAO;AAAA,MACP,aACE;AAAA,MACF,QAAQ;AAAA,IACV,CAAC;AAAA,IACH,cAAc,EACX,OAAO,EAAE,SAAS,EAAE,OAAO,EAAE,KAAK,EAAE,IAAI,CAAC,EAAE,CAAC,EAC5C,SAAS,EACT,KAAK;AAAA,MACJ,OAAO;AAAA,MACP,aACE;AAAA,MACF,QAAQ;AAAA,IACV,CAAC;AAAA,IACH,UAAU,EAAE,OAAO,EAAE,KAAK,EAAE,IAAI,CAAC,EAAE,SAAS,EAAE,KAAK;AAAA,MACjD,OAAO;AAAA,MACP,aACE;AAAA,MACF,aAAa;AAAA,IACf,CAAC;AAAA,IACD,cAAc,EACX,OAAO,EAAE,SAAS,EAAE,OAAO,EAAE,KAAK,EAAE,IAAI,CAAC,EAAE,CAAC,EAC5C,SAAS,EACT,KAAK;AAAA,MACJ,OAAO;AAAA,MACP,aACE;AAAA,MACF,QAAQ;AAAA,IACV,CAAC;AAAA,IACH,cAAc,EAAE,OAAO,EAAE,IAAI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AAK;AACZ,YAAI,QAAQ,SAAS;AACnB,iBAAO,EAAE,MAAM,OAAO,QAAQ,EAAE,OAAO,UAAU,EAAE;AAAA,QACrD;AACA,cAAM;AAAA,MACR;AACA,YAAM,MAAM,cAAc,KAAK;AAC/B,YAAM,UAAU,KAAK;AAAA,QAAI,CAAC,QACxB,kBAAkB,KAAK,IAAI,YAAY,IAAI,UAAU;AAAA,MACvD;AAEA,YAAM,QAAQ,QAAQ,SAAS,EAAE,OAAO,CAAC,IAAI,UAAU,EAAE,CAAC;AAAA,IAC5D;AAEA,WAAO,EAAE,MAAM,KAAK;AAAA,EACtB;AACF;;;AC7sBA,IAAO,gBAAQ;","names":["startMs"]}
|
|
1
|
+
{"version":3,"sources":["../../../connector-shared/src/errors.ts","../../../connector-shared/src/retry.ts","../../../connector-shared/src/version.ts","../../../connector-shared/src/request.ts","../../../connector-shared/src/rate-limit.ts","../../../connector-shared/src/sanitize.ts","../../../connector-shared/src/epoch.ts","../../../connector-shared/src/pagination.ts","../../../connector-shared/src/logger.ts","../src/google-search-console.ts","../src/index.ts"],"sourcesContent":["import type { HttpResponse } from './types';\n\nexport type HttpErrorKind =\n | 'transient'\n | 'rate_limit'\n | 'auth'\n | 'upstream_bug'\n | 'client_bug';\n\nexport abstract class HttpClientError extends Error {\n abstract readonly kind: HttpErrorKind;\n readonly response?: HttpResponse;\n\n constructor(message: string, response?: HttpResponse) {\n super(message);\n this.name = new.target.name;\n this.response = response;\n }\n}\n\nexport class TransientError extends HttpClientError {\n readonly kind = 'transient' as const;\n}\n\nexport class RateLimitError extends HttpClientError {\n readonly kind = 'rate_limit' as const;\n readonly retryAfter?: Date;\n\n constructor(message: string, response?: HttpResponse, retryAfter?: Date) {\n super(message, response);\n this.retryAfter = retryAfter;\n }\n}\n\nexport class AuthError extends HttpClientError {\n readonly kind = 'auth' as const;\n}\n\nexport class UpstreamBugError extends HttpClientError {\n readonly kind = 'upstream_bug' as const;\n}\n\nexport class ClientBugError extends HttpClientError {\n readonly kind = 'client_bug' as const;\n}\n\nexport function classifyStatus(status: number): HttpErrorKind {\n if (status === 429) {\n return 'rate_limit';\n }\n if (status === 401 || status === 403) {\n return 'auth';\n }\n if (status === 408) {\n return 'transient';\n }\n if (status >= 500) {\n return 'upstream_bug';\n }\n if (status >= 400) {\n return 'client_bug';\n }\n return 'client_bug';\n}\n\nexport function errorForStatus(\n message: string,\n response: HttpResponse,\n retryAfter?: Date,\n): HttpClientError {\n const kind = classifyStatus(response.status);\n switch (kind) {\n case 'rate_limit':\n return new RateLimitError(message, response, retryAfter);\n case 'auth':\n return new AuthError(message, response);\n case 'transient':\n return new TransientError(message, response);\n case 'upstream_bug':\n return new UpstreamBugError(message, response);\n case 'client_bug':\n return new ClientBugError(message, response);\n }\n}\n","import { HttpClientError, RateLimitError, TransientError } from './errors';\n\nexport interface RetryPolicy {\n maxAttempts?: number;\n initialDelayMs?: number;\n maxDelayMs?: number;\n retryOn?: (status: number | null, err?: Error) => boolean;\n}\n\nexport const defaultRetryOn = (status: number | null, err?: Error): boolean => {\n if (err instanceof RateLimitError) {\n return true;\n }\n if (err instanceof TransientError) {\n return true;\n }\n if (status === null) {\n return err instanceof Error && !(err instanceof HttpClientError);\n }\n if (status === 408 || status === 429) {\n return true;\n }\n if (status >= 500) {\n return true;\n }\n return false;\n};\n\nexport function backoffDelayMs(\n attempt: number,\n policy: Required<Pick<RetryPolicy, 'initialDelayMs' | 'maxDelayMs'>>,\n): number {\n const base = policy.initialDelayMs * 2 ** attempt;\n const jitter = base * 0.25 * Math.random();\n return Math.min(base + jitter, policy.maxDelayMs);\n}\n\nexport function parseRetryAfter(\n headerValue: string | null,\n now: Date = new Date(),\n): Date | undefined {\n if (!headerValue) {\n return undefined;\n }\n const trimmed = headerValue.trim();\n if (/^\\d+$/.test(trimmed)) {\n return new Date(now.getTime() + Number(trimmed) * 1000);\n }\n const parsed = Date.parse(trimmed);\n if (Number.isNaN(parsed)) {\n return undefined;\n }\n return new Date(parsed);\n}\n\nexport function sleep(ms: number, signal?: AbortSignal): Promise<void> {\n if (signal?.aborted) {\n return Promise.reject(signal.reason ?? new Error('Aborted'));\n }\n return new Promise<void>((resolve, reject) => {\n const onAbort = () => {\n clearTimeout(timer);\n reject(signal!.reason ?? new Error('Aborted'));\n };\n const timer = setTimeout(() => {\n signal?.removeEventListener('abort', onAbort);\n resolve();\n }, ms);\n signal?.addEventListener('abort', onAbort, { once: true });\n });\n}\n","export const HTTP_CLIENT_VERSION = '0.0.0';\n\nexport const DEFAULT_USER_AGENT = `rawdash-connector/${HTTP_CLIENT_VERSION} (+https://rawdash.dev)`;\n\nexport function connectorUserAgent(connectorId: string): string {\n return `rawdash-connector-${connectorId}/${HTTP_CLIENT_VERSION} (+https://rawdash.dev)`;\n}\n","import {\n AuthError,\n ClientBugError,\n HttpClientError,\n RateLimitError,\n TransientError,\n UpstreamBugError,\n errorForStatus,\n} from './errors';\nimport { defaultRetryOn, parseRetryAfter, sleep } from './retry';\nimport type { FetchLike, HttpMethod, HttpRequest, HttpResponse } from './types';\nimport { DEFAULT_USER_AGENT } from './version';\n\nconst DEFAULT_TIMEOUT_MS = 10_000;\nconst DEFAULT_MAX_ATTEMPTS = 3;\nconst DEFAULT_INITIAL_DELAY_MS = 1000;\nconst DEFAULT_MAX_DELAY_MS = 60_000;\nconst OBSERVER_TIMEOUT_MS = 250;\n\nexport interface RequestObservation {\n url: string;\n method: HttpMethod;\n status: number;\n resource: string;\n requestId: string;\n body: unknown;\n}\n\nexport type RequestObserver = (\n event: RequestObservation,\n) => void | Promise<void>;\n\nexport interface RequestOptions {\n fetch?: FetchLike;\n observer?: RequestObserver;\n resource: string;\n requestId?: string;\n}\n\nasync function notifyObserver(\n observer: RequestObserver,\n event: RequestObservation,\n): Promise<void> {\n let result: void | Promise<void>;\n try {\n result = observer(event);\n } catch (err) {\n console.warn('[connector-shared] request observer threw:', err);\n return;\n }\n if (!(result instanceof Promise)) {\n return;\n }\n const guarded = result.catch((err) => {\n console.warn('[connector-shared] request observer rejected:', err);\n });\n let timer: ReturnType<typeof setTimeout> | undefined;\n const timeout = new Promise<void>((resolve) => {\n timer = setTimeout(resolve, OBSERVER_TIMEOUT_MS);\n });\n try {\n await Promise.race([guarded, timeout]);\n } finally {\n if (timer) {\n clearTimeout(timer);\n }\n }\n}\n\nfunction newRequestId(): string {\n const c = (globalThis as { crypto?: { randomUUID?: () => string } }).crypto;\n if (c?.randomUUID) {\n return c.randomUUID();\n }\n return `${Date.now().toString(36)}-${Math.random().toString(36).slice(2, 10)}`;\n}\n\nfunction mergeHeaders(\n defaults: Record<string, string>,\n overrides: Record<string, string> | undefined,\n): Record<string, string> {\n const merged: Record<string, string> = {};\n for (const [k, v] of Object.entries(defaults)) {\n merged[k.toLowerCase()] = v;\n }\n if (overrides) {\n for (const [k, v] of Object.entries(overrides)) {\n merged[k.toLowerCase()] = v;\n }\n }\n return merged;\n}\n\nfunction linkTimeoutSignal(\n parent: AbortSignal | undefined,\n timeoutMs: number,\n): { signal: AbortSignal; cancel: () => void } {\n const controller = new AbortController();\n const onParentAbort = () => {\n controller.abort(parent?.reason);\n };\n if (parent) {\n if (parent.aborted) {\n controller.abort(parent.reason);\n } else {\n parent.addEventListener('abort', onParentAbort, { once: true });\n }\n }\n const timer = setTimeout(() => {\n controller.abort(new Error(`Request timed out after ${timeoutMs}ms`));\n }, timeoutMs);\n return {\n signal: controller.signal,\n cancel: () => {\n clearTimeout(timer);\n if (parent) {\n parent.removeEventListener('abort', onParentAbort);\n }\n },\n };\n}\n\nasync function readBody(res: Response, parseJson: boolean): Promise<unknown> {\n if (res.status === 204 || res.status === 205) {\n return null;\n }\n const contentType = res.headers.get('content-type') ?? '';\n if (parseJson && contentType.includes('application/json')) {\n const text = await res.text();\n if (text.length === 0) {\n return null;\n }\n return JSON.parse(text);\n }\n return res.text();\n}\n\nexport async function request<T = unknown>(\n req: HttpRequest,\n options: RequestOptions,\n): Promise<HttpResponse<T>> {\n const fetchImpl: FetchLike = options.fetch ?? (globalThis.fetch as FetchLike);\n const retry = req.retry ?? {};\n const maxAttempts = retry.maxAttempts ?? DEFAULT_MAX_ATTEMPTS;\n const initialDelayMs = retry.initialDelayMs ?? DEFAULT_INITIAL_DELAY_MS;\n const maxDelayMs = retry.maxDelayMs ?? DEFAULT_MAX_DELAY_MS;\n const retryOn = retry.retryOn ?? defaultRetryOn;\n const timeoutMs = req.timeoutMs ?? DEFAULT_TIMEOUT_MS;\n const parseJson = req.parseJson ?? true;\n\n const headers = mergeHeaders(\n {\n 'User-Agent': DEFAULT_USER_AGENT,\n Accept: 'application/json',\n },\n req.headers,\n );\n\n let lastErr: Error | undefined;\n\n for (let attempt = 0; attempt < maxAttempts; attempt++) {\n req.signal?.throwIfAborted();\n\n const { signal, cancel } = linkTimeoutSignal(req.signal, timeoutMs);\n let res: Response;\n try {\n res = await fetchImpl(req.url, {\n method: req.method ?? 'GET',\n headers,\n body: req.body as RequestInit['body'],\n signal,\n });\n } catch (err) {\n cancel();\n if (req.signal?.aborted) {\n throw req.signal.reason ?? err;\n }\n const error = err instanceof Error ? err : new Error(String(err));\n lastErr = error;\n if (attempt < maxAttempts - 1 && retryOn(null, error)) {\n const delay = computeDelay(attempt, initialDelayMs, maxDelayMs);\n await sleep(delay, req.signal);\n continue;\n }\n throw new TransientError(error.message);\n }\n cancel();\n\n const body = await readBody(res, parseJson);\n const httpResponse: HttpResponse<T> = {\n status: res.status,\n headers: res.headers,\n body: body as T,\n };\n if (req.rateLimit) {\n const state = req.rateLimit.parse(res.headers);\n if (state) {\n httpResponse.rateLimitState = state;\n }\n }\n\n if (options.observer) {\n await notifyObserver(options.observer, {\n url: req.url,\n method: req.method ?? 'GET',\n status: res.status,\n resource: options.resource,\n requestId: options.requestId ?? newRequestId(),\n body,\n });\n }\n\n if (res.ok) {\n return httpResponse;\n }\n\n const retryAfter = parseRetryAfter(res.headers.get('retry-after'));\n const message = `HTTP ${res.status} ${res.statusText} for ${req.method ?? 'GET'} ${req.url}`;\n const err = errorForStatus(message, httpResponse, retryAfter);\n\n if (\n attempt < maxAttempts - 1 &&\n retryOn(res.status, err) &&\n !(err instanceof AuthError) &&\n !(err instanceof ClientBugError)\n ) {\n lastErr = err;\n let delay = computeDelay(attempt, initialDelayMs, maxDelayMs);\n if (err instanceof RateLimitError && retryAfter) {\n const wait = retryAfter.getTime() - Date.now();\n if (wait > 0) {\n delay = Math.min(wait, maxDelayMs);\n }\n }\n await sleep(delay, req.signal);\n continue;\n }\n\n throw err;\n }\n\n throw lastErr ?? new UpstreamBugError('Exhausted retry attempts');\n}\n\nfunction computeDelay(\n attempt: number,\n initialDelayMs: number,\n maxDelayMs: number,\n): number {\n const base = initialDelayMs * 2 ** attempt;\n const jitter = base * 0.25 * Math.random();\n return Math.min(base + jitter, maxDelayMs);\n}\n\nexport { HttpClientError };\n","export interface RateLimitState {\n remaining: number;\n resetAt: Date;\n}\n\nexport interface RateLimitPolicy {\n parse(headers: Headers): RateLimitState | null;\n}\n\nexport interface StandardRateLimitPolicyConfig {\n remainingHeader: string;\n resetHeader: string;\n resetUnit: 's' | 'ms';\n resetFallbackMs?: number;\n}\n\nexport function standardRateLimitPolicy(\n config: StandardRateLimitPolicyConfig,\n): RateLimitPolicy {\n const { remainingHeader, resetHeader, resetUnit, resetFallbackMs } = config;\n const multiplier = resetUnit === 's' ? 1000 : 1;\n return {\n parse(h) {\n const remainingRaw = h.get(remainingHeader);\n if (remainingRaw === null || remainingRaw.trim() === '') {\n return null;\n }\n const remaining = Number(remainingRaw);\n if (!Number.isFinite(remaining)) {\n return null;\n }\n const resetRaw = h.get(resetHeader);\n if (resetRaw === null) {\n if (resetFallbackMs === undefined) {\n return null;\n }\n return {\n remaining,\n resetAt: new Date(Date.now() + resetFallbackMs),\n };\n }\n if (resetRaw.trim() === '') {\n return null;\n }\n const reset = Number(resetRaw);\n if (!Number.isFinite(reset) || reset < 0) {\n return null;\n }\n const resetMs = reset * multiplier;\n if (!Number.isFinite(resetMs)) {\n return null;\n }\n return { remaining, resetAt: new Date(resetMs) };\n },\n };\n}\n","export interface SanitizeAllowedUrlOptions {\n url: string | null;\n host: string;\n pathname: string;\n protocol?: 'https:' | 'http:';\n}\n\nexport function sanitizeAllowedUrl(\n options: SanitizeAllowedUrlOptions,\n): string | null {\n const { url, host, pathname, protocol = 'https:' } = options;\n if (url === null) {\n return null;\n }\n try {\n const u = new URL(url);\n if (u.protocol !== protocol || u.host !== host || u.pathname !== pathname) {\n return null;\n }\n return u.toString();\n } catch {\n return null;\n }\n}\n","export type EpochUnit = 'ms' | 's' | 'iso';\n\nexport function parseEpoch(\n value: number | string | null | undefined,\n unit: EpochUnit,\n): number | null {\n if (value === null || value === undefined) {\n return null;\n }\n if (unit === 'iso') {\n if (typeof value !== 'string') {\n return null;\n }\n const ms = new Date(value).getTime();\n return Number.isFinite(ms) ? ms : null;\n }\n if (typeof value === 'string' && value.trim() === '') {\n return null;\n }\n const n = typeof value === 'number' ? value : Number(value);\n if (!Number.isFinite(n)) {\n return null;\n }\n const result = unit === 's' ? n * 1000 : n;\n return Number.isFinite(result) ? result : null;\n}\n","import { request } from './request';\nimport type { HttpRequest } from './types';\n\nexport function parseLinkHeader(header: string | null): Record<string, string> {\n if (!header) {\n return {};\n }\n const result: Record<string, string> = {};\n for (const part of header.split(',')) {\n const match = part.match(/<([^>]+)>\\s*;\\s*rel=\"([^\"]+)\"/);\n if (match) {\n result[match[2]!] = match[1]!;\n }\n }\n return result;\n}\n\nexport async function* paginateLink<T>(\n initial: HttpRequest,\n parse: (body: unknown) => T[],\n options: { resource: string },\n): AsyncIterable<T> {\n let next: string | null = initial.url;\n while (next) {\n const res: Awaited<ReturnType<typeof request>> = await request(\n {\n ...initial,\n url: next,\n },\n { resource: options.resource },\n );\n for (const item of parse(res.body)) {\n yield item;\n }\n const links = parseLinkHeader(res.headers.get('link'));\n next = links['next'] ?? null;\n }\n}\n\nexport async function* paginateCursor<T>(\n initial: HttpRequest,\n parse: (body: unknown) => { items: T[]; nextCursor: string | null },\n buildNext: (req: HttpRequest, cursor: string) => HttpRequest,\n options: { resource: string },\n): AsyncIterable<T> {\n let req: HttpRequest = initial;\n while (true) {\n const res = await request(req, { resource: options.resource });\n const { items, nextCursor } = parse(res.body);\n for (const item of items) {\n yield item;\n }\n if (!nextCursor) {\n return;\n }\n req = buildNext(req, nextCursor);\n }\n}\n\nexport async function* paginatePage<T>(\n initial: HttpRequest,\n parse: (body: unknown) => { items: T[]; hasMore: boolean },\n buildPage: (req: HttpRequest, page: number) => HttpRequest,\n options: { resource: string },\n): AsyncIterable<T> {\n let page = 1;\n while (true) {\n const req = page === 1 ? initial : buildPage(initial, page);\n const res = await request(req, { resource: options.resource });\n const { items, hasMore } = parse(res.body);\n for (const item of items) {\n yield item;\n }\n if (!hasMore || items.length === 0) {\n return;\n }\n page++;\n }\n}\n","export type LogFields = Record<string, unknown>;\n\nexport interface ConnectorLogger {\n info(event: string, fields?: LogFields): void;\n warn(event: string, fields?: LogFields): void;\n}\n\nexport interface ConnectorLoggerOptions {\n scope: string;\n}\n\nconst MAX_VALUE_LEN = 120;\n\nfunction truncate(s: string, max = MAX_VALUE_LEN): string {\n if (s.length <= max) {\n return s;\n }\n return `${s.slice(0, max - 1)}…`;\n}\n\nfunction formatValue(value: unknown): string {\n if (value === null) {\n return 'null';\n }\n if (value === undefined) {\n return '';\n }\n if (typeof value === 'number' || typeof value === 'boolean') {\n return String(value);\n }\n if (typeof value === 'string') {\n const t = truncate(value);\n if (/[\\s\"=]/.test(t)) {\n return JSON.stringify(t);\n }\n return t;\n }\n if (typeof value === 'bigint') {\n return value.toString();\n }\n let json: string | undefined;\n try {\n json = JSON.stringify(value);\n } catch {\n json = undefined;\n }\n return truncate(json ?? String(value));\n}\n\nexport function formatLogFields(fields?: LogFields): string {\n if (!fields) {\n return '';\n }\n const parts: string[] = [];\n for (const [k, v] of Object.entries(fields)) {\n if (v === undefined) {\n continue;\n }\n parts.push(`${k}=${formatValue(v)}`);\n }\n return parts.length > 0 ? ` ${parts.join(' ')}` : '';\n}\n\nexport function formatLogLine(\n scope: string,\n event: string,\n fields?: LogFields,\n): string {\n return `[${scope}] ${event}${formatLogFields(fields)}`;\n}\n\nexport function createDefaultConnectorLogger(\n opts: ConnectorLoggerOptions,\n): ConnectorLogger {\n return {\n info(event, fields) {\n console.info(formatLogLine(opts.scope, event, fields));\n },\n warn(event, fields) {\n console.warn(formatLogLine(opts.scope, event, fields));\n },\n };\n}\n\nconst NOOP_LOGGER: ConnectorLogger = {\n info() {},\n warn() {},\n};\n\nexport function noopConnectorLogger(): ConnectorLogger {\n return NOOP_LOGGER;\n}\n","import { connectorUserAgent } from '@rawdash/connector-shared';\nimport {\n BaseConnector,\n type ConnectorContext,\n type ConnectorDoc,\n type CredentialsSchema,\n type StorageHandle,\n type SyncOptions,\n type SyncResult,\n defineConfigFields,\n defineConnectorDoc,\n defineResources,\n schemasFromResources,\n} from '@rawdash/core';\nimport { z } from 'zod';\n\nexport const configFields = defineConfigFields(\n z\n .object({\n siteUrl: z.string().trim().min(1).meta({\n label: 'Site URL',\n description:\n 'Verified Search Console property. URL-prefix properties look like \"https://example.com/\"; Domain properties look like \"sc-domain:example.com\".',\n placeholder: 'https://example.com/',\n }),\n serviceAccountJson: z\n .object({ $secret: z.string().trim().min(1) })\n .optional()\n .meta({\n label: 'Service Account JSON (recommended)',\n description:\n 'Contents of the JSON key file for a Google service account that has been added as a Search Console user (Owner or Full user) on the property. Create one at Google Cloud -> IAM & Admin -> Service Accounts.',\n secret: true,\n }),\n refreshToken: z\n .object({ $secret: z.string().trim().min(1) })\n .optional()\n .meta({\n label: 'OAuth Refresh Token',\n description:\n 'Google OAuth 2.0 refresh token with webmasters.readonly scope. Required if not using serviceAccountJson.',\n secret: true,\n }),\n clientId: z.string().trim().min(1).optional().meta({\n label: 'OAuth Client ID',\n description:\n 'OAuth 2.0 client ID from Google Cloud Console. Required when using refreshToken auth.',\n placeholder: '...apps.googleusercontent.com',\n }),\n clientSecret: z\n .object({ $secret: z.string().trim().min(1) })\n .optional()\n .meta({\n label: 'OAuth Client Secret',\n description:\n 'OAuth 2.0 client secret from Google Cloud Console. Required when using refreshToken auth.',\n secret: true,\n }),\n lookbackDays: z.number().int().positive().optional().meta({\n label: 'Lookback days (full sync)',\n description:\n 'How many calendar days to fetch on a full sync. Defaults to 90.',\n placeholder: '90',\n }),\n })\n .refine(\n (val) =>\n val.serviceAccountJson !== undefined ||\n (val.refreshToken !== undefined &&\n val.clientId !== undefined &&\n val.clientSecret !== undefined),\n {\n message:\n 'Provide either serviceAccountJson or the full OAuth tuple (refreshToken + clientId + clientSecret)',\n },\n ),\n);\n\nexport const doc: ConnectorDoc = defineConnectorDoc({\n displayName: 'Google Search Console',\n category: 'marketing',\n brandColor: '#458CF5',\n tagline:\n 'Sync daily Search Console SEO metrics - clicks, impressions, CTR, and average position - by date, query, page, and country.',\n vendor: {\n name: 'Google Search Console',\n apiDocs:\n 'https://developers.google.com/webmaster-tools/v1/api_reference_index',\n website: 'https://search.google.com/search-console',\n },\n auth: {\n summary:\n 'Authenticate against the Search Console API with either a Google service account JSON key (recommended) or an OAuth 2.0 refresh-token tuple. The identity must be added as a user on the Search Console property (Owner or Full user).',\n setup: [\n 'Identify the property to sync. URL-prefix properties use the full origin (e.g. https://example.com/); Domain properties use the sc-domain:example.com format.',\n 'Recommended: create a service account at Google Cloud -> IAM & Admin -> Service Accounts, generate a JSON key, then in Search Console add the service account email as a user on the property. Store the JSON as a secret and reference it as serviceAccountJson: secret(\"GSC_SERVICE_ACCOUNT_JSON\").',\n 'Alternative: provide an OAuth 2.0 refresh token with the webmasters.readonly scope together with its clientId and clientSecret from the Google Cloud Console.',\n ],\n },\n rateLimit:\n 'Search Console API quota is 1,200 queries per minute per project (default); 429 responses are retried automatically with exponential backoff.',\n limitations: [\n 'Search Console aggregates data with a 2-3 day lag, so incremental syncs refetch the trailing 3 days.',\n 'Each query is paginated 25,000 rows per page; a phase that yields more than that paginates by startRow.',\n ],\n});\n\n// ---------------------------------------------------------------------------\n// Settings / credentials\n// ---------------------------------------------------------------------------\n\nexport interface GSCSettings {\n siteUrl: string;\n lookbackDays?: number;\n}\n\nconst gscCredentials = {\n serviceAccountJson: {\n description: 'Google service account JSON key (base64 or raw JSON)',\n auth: 'optional' as const,\n },\n refreshToken: {\n description: 'Google OAuth 2.0 refresh token',\n auth: 'optional' as const,\n },\n clientId: {\n description: 'Google OAuth 2.0 client ID',\n auth: 'optional' as const,\n },\n clientSecret: {\n description: 'Google OAuth 2.0 client secret',\n auth: 'optional' as const,\n },\n} satisfies CredentialsSchema;\n\ntype GSCCredentials = typeof gscCredentials;\n\n// ---------------------------------------------------------------------------\n// Sync phases + cursor\n// ---------------------------------------------------------------------------\n\nconst PHASE_ORDER = [\n 'search_analytics_by_day',\n 'top_queries',\n 'top_pages',\n 'top_countries',\n] as const;\n\ntype GSCPhase = (typeof PHASE_ORDER)[number];\n\ninterface GSCDateRange {\n startDate: string;\n endDate: string;\n}\n\ninterface GSCSyncCursor {\n phase: GSCPhase;\n dateRange: GSCDateRange;\n}\n\nconst GSC_DATE_RE = /^\\d{4}-\\d{2}-\\d{2}$/;\n\nfunction isGSCDateString(value: unknown): value is string {\n return typeof value === 'string' && GSC_DATE_RE.test(value);\n}\n\nfunction isGSCDateRange(value: unknown): value is GSCDateRange {\n if (typeof value !== 'object' || value === null) {\n return false;\n }\n const v = value as { startDate?: unknown; endDate?: unknown };\n return isGSCDateString(v.startDate) && isGSCDateString(v.endDate);\n}\n\nfunction isGSCSyncCursor(value: unknown): value is GSCSyncCursor {\n if (typeof value !== 'object' || value === null) {\n return false;\n }\n const v = value as { phase?: unknown; dateRange?: unknown };\n if (typeof v.phase !== 'string') {\n return false;\n }\n if (!(PHASE_ORDER as readonly string[]).includes(v.phase)) {\n return false;\n }\n return isGSCDateRange(v.dateRange);\n}\n\n// ---------------------------------------------------------------------------\n// Phase configs - dimensions for each resource\n// ---------------------------------------------------------------------------\n\ninterface PhaseConfig {\n dimensions: string[];\n metricName: string;\n}\n\nconst PHASE_CONFIGS: Record<GSCPhase, PhaseConfig> = {\n search_analytics_by_day: {\n dimensions: ['date'],\n metricName: 'gsc_search_analytics_by_day',\n },\n top_queries: {\n dimensions: ['date', 'query'],\n metricName: 'gsc_top_queries',\n },\n top_pages: {\n dimensions: ['date', 'page'],\n metricName: 'gsc_top_pages',\n },\n top_countries: {\n dimensions: ['date', 'country'],\n metricName: 'gsc_top_countries',\n },\n};\n\nconst ROWS_PER_PAGE = 25_000;\nconst METRIC_FIELDS = ['clicks', 'impressions', 'ctr', 'position'] as const;\n\n// ---------------------------------------------------------------------------\n// GSC Search Analytics API types\n// ---------------------------------------------------------------------------\n\nexport interface GSCReportRow {\n keys?: string[];\n clicks?: number;\n impressions?: number;\n ctr?: number;\n position?: number;\n}\n\ninterface GSCReportResponse {\n rows?: GSCReportRow[];\n responseAggregationType?: string;\n}\n\n// ---------------------------------------------------------------------------\n// Service account / OAuth token helpers\n// ---------------------------------------------------------------------------\n\ninterface ServiceAccountKey {\n client_email: string;\n private_key: string;\n token_uri?: string;\n}\n\ninterface TokenResponse {\n access_token: string;\n expires_in?: number;\n}\n\nfunction base64urlFromBytes(bytes: Uint8Array): string {\n let binary = '';\n for (let i = 0; i < bytes.length; i++) {\n binary += String.fromCharCode(bytes[i]!);\n }\n return btoa(binary).replace(/\\+/g, '-').replace(/\\//g, '_').replace(/=/g, '');\n}\n\nfunction base64urlFromString(str: string): string {\n return base64urlFromBytes(new TextEncoder().encode(str));\n}\n\nasync function signRS256JWT(\n payload: Record<string, unknown>,\n privateKeyPem: string,\n): Promise<string> {\n const header = { alg: 'RS256', typ: 'JWT' };\n const headerB64 = base64urlFromString(JSON.stringify(header));\n const payloadB64 = base64urlFromString(JSON.stringify(payload));\n const signingInput = `${headerB64}.${payloadB64}`;\n\n const pemContent = privateKeyPem\n .replace(/-----BEGIN PRIVATE KEY-----/g, '')\n .replace(/-----END PRIVATE KEY-----/g, '')\n .replace(/\\s/g, '');\n const der = Uint8Array.from(atob(pemContent), (c) => c.charCodeAt(0));\n\n const key = await globalThis.crypto.subtle.importKey(\n 'pkcs8',\n der,\n { name: 'RSASSA-PKCS1-v1_5', hash: 'SHA-256' },\n false,\n ['sign'],\n );\n\n const signature = await globalThis.crypto.subtle.sign(\n 'RSASSA-PKCS1-v1_5',\n key,\n new TextEncoder().encode(signingInput),\n );\n\n return `${signingInput}.${base64urlFromBytes(new Uint8Array(signature))}`;\n}\n\nfunction parseServiceAccountJson(value: string): ServiceAccountKey {\n const trimmed = value.trim();\n if (trimmed.startsWith('{')) {\n return JSON.parse(trimmed) as ServiceAccountKey;\n }\n const binary = atob(trimmed);\n const bytes = new Uint8Array(binary.length);\n for (let i = 0; i < binary.length; i++) {\n bytes[i] = binary.charCodeAt(i);\n }\n const decoded = new TextDecoder().decode(bytes);\n return JSON.parse(decoded) as ServiceAccountKey;\n}\n\nasync function buildServiceAccountJwt(\n serviceAccountJson: string,\n): Promise<{ url: string; body: string }> {\n const sa = parseServiceAccountJson(serviceAccountJson);\n const now = Math.floor(Date.now() / 1000);\n const jwt = await signRS256JWT(\n {\n iss: sa.client_email,\n scope: 'https://www.googleapis.com/auth/webmasters.readonly',\n aud: sa.token_uri ?? 'https://oauth2.googleapis.com/token',\n exp: now + 3600,\n iat: now,\n },\n sa.private_key,\n );\n\n const body = new URLSearchParams({\n grant_type: 'urn:ietf:params:oauth:grant-type:jwt-bearer',\n assertion: jwt,\n }).toString();\n\n return {\n url: sa.token_uri ?? 'https://oauth2.googleapis.com/token',\n body,\n };\n}\n\n// ---------------------------------------------------------------------------\n// Date helpers\n// ---------------------------------------------------------------------------\n\nfunction toGSCDate(date: Date): string {\n const y = date.getUTCFullYear();\n const m = String(date.getUTCMonth() + 1).padStart(2, '0');\n const d = String(date.getUTCDate()).padStart(2, '0');\n return `${y}-${m}-${d}`;\n}\n\nfunction gscDateToMs(gscDate: string): number {\n // GSC date dimension comes back as 'YYYY-MM-DD'\n const y = gscDate.slice(0, 4);\n const m = gscDate.slice(5, 7);\n const d = gscDate.slice(8, 10);\n return Date.UTC(Number(y), Number(m) - 1, Number(d));\n}\n\nconst MS_PER_DAY = 24 * 60 * 60 * 1000;\nconst INCREMENTAL_LOOKBACK_DAYS = 3;\n\nfunction getDateRange(\n options: SyncOptions,\n lookbackDays: number,\n): GSCDateRange {\n const now = Date.now();\n const endDate = toGSCDate(new Date(now));\n if (options.mode === 'latest') {\n const startMs = now - (INCREMENTAL_LOOKBACK_DAYS - 1) * MS_PER_DAY;\n return { startDate: toGSCDate(new Date(startMs)), endDate };\n }\n if (options.since) {\n const sinceMs = new Date(options.since).getTime();\n if (Number.isFinite(sinceMs)) {\n const days = Math.max(1, Math.ceil((now - sinceMs) / MS_PER_DAY));\n const cappedDays = Math.min(days, lookbackDays);\n const startMs = now - (cappedDays - 1) * MS_PER_DAY;\n return { startDate: toGSCDate(new Date(startMs)), endDate };\n }\n }\n const startMs = now - (lookbackDays - 1) * MS_PER_DAY;\n return { startDate: toGSCDate(new Date(startMs)), endDate };\n}\n\n// ---------------------------------------------------------------------------\n// Row conversion\n// ---------------------------------------------------------------------------\n\nexport function rowToMetricSample(\n row: GSCReportRow,\n dimensions: string[],\n metricName: string,\n): {\n name: string;\n ts: number;\n value: number;\n attributes: Record<string, string | number>;\n} {\n const attributes: Record<string, string | number> = {};\n const keys = row.keys ?? [];\n for (let i = 0; i < dimensions.length; i++) {\n attributes[dimensions[i]!] = keys[i] ?? '';\n }\n\n for (const field of METRIC_FIELDS) {\n const raw = row[field];\n attributes[field] =\n typeof raw === 'number' && Number.isFinite(raw) ? raw : 0;\n }\n\n const dateStr =\n typeof attributes['date'] === 'string' ? attributes['date'] : '1970-01-01';\n const ts = gscDateToMs(dateStr);\n const primaryValue = attributes['clicks'] as number;\n\n return {\n name: metricName,\n ts,\n value: primaryValue,\n attributes,\n };\n}\n\n// ---------------------------------------------------------------------------\n// Schemas - describe the per-resource API response shape consumed by request()\n// ---------------------------------------------------------------------------\n\nconst dateKey = z\n .string()\n .regex(/^(19|20)\\d{2}-(0[1-9]|1[0-2])-(0[1-9]|[12]\\d|3[01])$/);\nconst stringKey = z.string();\nconst numericField = z.number();\n\nfunction reportSchema(dimensionCount: number) {\n const keys =\n dimensionCount === 1\n ? z.tuple([dateKey])\n : z.tuple([dateKey, ...Array(dimensionCount - 1).fill(stringKey)] as [\n typeof dateKey,\n ...z.ZodType[],\n ]);\n return z.object({\n rows: z\n .array(\n z.object({\n keys,\n clicks: numericField.optional(),\n impressions: numericField.optional(),\n ctr: numericField.optional(),\n position: numericField.optional(),\n }),\n )\n .optional(),\n });\n}\n\nconst tokenResponseSchema = z.object({\n access_token: z.string().min(1),\n expires_in: z.number().int().positive().optional(),\n});\n\nexport const googleSearchConsoleResources = defineResources({\n gsc_search_analytics_by_day: {\n shape: 'metric',\n description:\n 'Daily site totals - clicks, impressions, CTR, and average position across all queries and pages.',\n unit: 'clicks',\n granularity: 'day',\n endpoint: 'POST /webmasters/v3/sites/{siteUrl}/searchAnalytics/query',\n dimensions: [\n { name: 'date', description: 'Calendar day of the metric sample.' },\n ],\n responses: {\n oauth_token: tokenResponseSchema,\n search_analytics_by_day: reportSchema(1),\n },\n },\n gsc_top_queries: {\n shape: 'metric',\n description:\n 'Daily clicks, impressions, CTR, and average position broken down by search query.',\n unit: 'clicks',\n granularity: 'day',\n endpoint: 'POST /webmasters/v3/sites/{siteUrl}/searchAnalytics/query',\n dimensions: [\n { name: 'date', description: 'Calendar day of the metric sample.' },\n {\n name: 'query',\n description: 'Search term that surfaced a result for the property.',\n },\n ],\n responses: { top_queries: reportSchema(2) },\n },\n gsc_top_pages: {\n shape: 'metric',\n description:\n 'Daily clicks, impressions, CTR, and average position broken down by landing page URL.',\n unit: 'clicks',\n granularity: 'day',\n endpoint: 'POST /webmasters/v3/sites/{siteUrl}/searchAnalytics/query',\n dimensions: [\n { name: 'date', description: 'Calendar day of the metric sample.' },\n {\n name: 'page',\n description: 'Canonical URL of the page that surfaced in search.',\n },\n ],\n responses: { top_pages: reportSchema(2) },\n },\n gsc_top_countries: {\n shape: 'metric',\n description:\n 'Daily clicks, impressions, CTR, and average position broken down by visitor country.',\n unit: 'clicks',\n granularity: 'day',\n endpoint: 'POST /webmasters/v3/sites/{siteUrl}/searchAnalytics/query',\n dimensions: [\n { name: 'date', description: 'Calendar day of the metric sample.' },\n {\n name: 'country',\n description: 'ISO 3166-1 alpha-3 country code of the searcher.',\n },\n ],\n responses: { top_countries: reportSchema(2) },\n },\n});\n\nexport const id = 'google-search-console';\n\nexport class GSCConnector extends BaseConnector<GSCSettings, GSCCredentials> {\n static readonly id = id;\n\n static readonly resources = googleSearchConsoleResources;\n\n static readonly schemas = schemasFromResources(googleSearchConsoleResources);\n\n static create(input: unknown, ctx?: ConnectorContext): GSCConnector {\n const parsed = configFields.parse(input);\n return new GSCConnector(\n {\n siteUrl: parsed.siteUrl,\n lookbackDays: parsed.lookbackDays,\n },\n {\n serviceAccountJson: parsed.serviceAccountJson,\n refreshToken: parsed.refreshToken,\n clientId: parsed.clientId,\n clientSecret: parsed.clientSecret,\n },\n ctx,\n );\n }\n\n readonly id = id;\n override readonly credentials = gscCredentials;\n\n private cachedToken: { token: string; expiresAt: number } | null = null;\n\n private async fetchOAuthToken(\n url: string,\n body: string,\n signal: AbortSignal | undefined,\n ): Promise<{ token: string; expiresAt: number }> {\n const res = await this.post<TokenResponse>(url, {\n resource: 'oauth_token',\n headers: { 'Content-Type': 'application/x-www-form-urlencoded' },\n body,\n signal,\n });\n const expiresIn = res.body.expires_in ?? 3600;\n return {\n token: res.body.access_token,\n expiresAt: Date.now() + (expiresIn - 60) * 1000,\n };\n }\n\n private async getAccessToken(signal?: AbortSignal): Promise<string> {\n if (this.cachedToken && Date.now() < this.cachedToken.expiresAt) {\n return this.cachedToken.token;\n }\n\n const { serviceAccountJson, refreshToken, clientId, clientSecret } =\n this.creds;\n\n if (serviceAccountJson) {\n const { url, body } = await buildServiceAccountJwt(serviceAccountJson);\n this.cachedToken = await this.fetchOAuthToken(url, body, signal);\n return this.cachedToken.token;\n }\n\n if (refreshToken && clientId && clientSecret) {\n const body = new URLSearchParams({\n grant_type: 'refresh_token',\n refresh_token: refreshToken,\n client_id: clientId,\n client_secret: clientSecret,\n }).toString();\n this.cachedToken = await this.fetchOAuthToken(\n 'https://oauth2.googleapis.com/token',\n body,\n signal,\n );\n return this.cachedToken.token;\n }\n\n throw new Error(\n 'GSC connector: provide either serviceAccountJson or (refreshToken + clientId + clientSecret)',\n );\n }\n\n private async runReport(\n accessToken: string,\n phase: GSCPhase,\n dateRange: GSCDateRange,\n startRow: number,\n signal?: AbortSignal,\n ): Promise<GSCReportResponse> {\n const { dimensions } = PHASE_CONFIGS[phase];\n const url = `https://searchconsole.googleapis.com/webmasters/v3/sites/${encodeURIComponent(this.settings.siteUrl)}/searchAnalytics/query`;\n\n const body: Record<string, unknown> = {\n startDate: dateRange.startDate,\n endDate: dateRange.endDate,\n dimensions,\n rowLimit: ROWS_PER_PAGE,\n startRow,\n };\n\n const res = await this.post<GSCReportResponse>(url, {\n resource: phase,\n headers: {\n Authorization: `Bearer ${accessToken}`,\n 'Content-Type': 'application/json',\n 'User-Agent': connectorUserAgent('google-search-console'),\n },\n body: JSON.stringify(body),\n signal,\n });\n return res.body;\n }\n\n async sync(\n options: SyncOptions,\n storage: StorageHandle,\n signal?: AbortSignal,\n ): Promise<SyncResult> {\n const lookbackDays = this.settings.lookbackDays ?? 90;\n\n const cursor = isGSCSyncCursor(options.cursor) ? options.cursor : undefined;\n // Restore the originally-computed window on resume so phases stay aligned\n // across midnight rollovers and lookbackDays changes between runs.\n const dateRange = cursor?.dateRange ?? getDateRange(options, lookbackDays);\n\n let accessToken: string | null = null;\n const getToken = async (sig?: AbortSignal): Promise<string> => {\n if (!accessToken) {\n accessToken = await this.getAccessToken(sig);\n }\n return accessToken;\n };\n\n const runReportWithRetry = async (\n phase: GSCPhase,\n startRow: number,\n sig: AbortSignal | undefined,\n ): Promise<GSCReportResponse> => {\n const token = await getToken(sig);\n try {\n return await this.runReport(token, phase, dateRange, startRow, sig);\n } catch (err) {\n console.warn(\n `[gsc] runReport failed, refreshing token and retrying once`,\n err,\n );\n accessToken = null;\n const freshToken = await getToken(sig);\n return this.runReport(freshToken, phase, dateRange, startRow, sig);\n }\n };\n\n const drainPhase = async (phase: GSCPhase): Promise<GSCReportRow[]> => {\n const allRows: GSCReportRow[] = [];\n let startRow = 0;\n for (;;) {\n const response = await runReportWithRetry(phase, startRow, signal);\n const rows = response.rows ?? [];\n allRows.push(...rows);\n startRow += rows.length;\n // GSC has no totalRowCount field on responses, so a short page is the\n // terminating signal. Empty page also breaks out (covers the rare\n // \"exact multiple of rowLimit\" case where one extra request is fine).\n if (rows.length < ROWS_PER_PAGE) {\n break;\n }\n }\n return allRows;\n };\n\n const resumeIdx = cursor ? PHASE_ORDER.indexOf(cursor.phase) : -1;\n const startIdx = resumeIdx >= 0 ? resumeIdx : 0;\n\n for (let i = startIdx; i < PHASE_ORDER.length; i++) {\n const phase = PHASE_ORDER[i]!;\n if (signal?.aborted) {\n return { done: false, cursor: { phase, dateRange } };\n }\n\n // Drain every page of this phase in-memory before writing so the commit\n // is one atomic call. A mid-phase failure restarts this phase from\n // scratch on the next sync; the clear-and-replace below wipes partial\n // state. If the abort signal trips mid-drain, surface a resumable\n // cursor instead of throwing the AbortError up to the caller.\n let rows: GSCReportRow[];\n try {\n rows = await drainPhase(phase);\n } catch (err) {\n if (signal?.aborted) {\n return { done: false, cursor: { phase, dateRange } };\n }\n throw err;\n }\n const cfg = PHASE_CONFIGS[phase];\n const samples = rows.map((row) =>\n rowToMetricSample(row, cfg.dimensions, cfg.metricName),\n );\n // Scoping by name ensures stale rows are wiped even when samples is empty.\n await storage.metrics(samples, { names: [cfg.metricName] });\n }\n\n return { done: true };\n }\n}\n","import { GSCConnector } from './google-search-console';\n\nexport {\n configFields,\n doc,\n GSCConnector,\n googleSearchConsoleResources as resources,\n id,\n rowToMetricSample,\n} from './google-search-console';\nexport type { GSCSettings } from './google-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AQ,SAAS;AACnB,iBAAO,EAAE,MAAM,OAAO,QAAQ,EAAE,OAAO,UAAU,EAAE;AAAA,QACrD;AACA,cAAM;AAAA,MACR;AACA,YAAM,MAAM,cAAc,KAAK;AAC/B,YAAM,UAAU,KAAK;AAAA,QAAI,CAAC,QACxB,kBAAkB,KAAK,IAAI,YAAY,IAAI,UAAU;AAAA,MACvD;AAEA,YAAM,QAAQ,QAAQ,SAAS,EAAE,OAAO,CAAC,IAAI,UAAU,EAAE,CAAC;AAAA,IAC5D;AAEA,WAAO,EAAE,MAAM,KAAK;AAAA,EACtB;AACF;;;AC7sBA,IAAO,gBAAQ;","names":["startMs"]}
|
package/package.json
CHANGED
|
@@ -1,9 +1,10 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@rawdash/connector-google-search-console",
|
|
3
|
-
"version": "0.
|
|
3
|
+
"version": "0.18.0",
|
|
4
4
|
"description": "Rawdash connector for Google Search Console - syncs SEO impressions, clicks, CTR, and position by day, query, page, and country into the six-shape storage model",
|
|
5
5
|
"license": "Apache-2.0",
|
|
6
6
|
"type": "module",
|
|
7
|
+
"sideEffects": false,
|
|
7
8
|
"repository": {
|
|
8
9
|
"type": "git",
|
|
9
10
|
"url": "https://github.com/rawdash/rawdash.git",
|
|
@@ -21,22 +22,22 @@
|
|
|
21
22
|
"import": "./dist/index.js"
|
|
22
23
|
}
|
|
23
24
|
},
|
|
24
|
-
"scripts": {
|
|
25
|
-
"build": "tsup",
|
|
26
|
-
"typecheck": "tsc --noEmit",
|
|
27
|
-
"lint": "eslint src",
|
|
28
|
-
"test": "vitest run"
|
|
29
|
-
},
|
|
30
25
|
"dependencies": {
|
|
31
|
-
"
|
|
32
|
-
"
|
|
26
|
+
"zod": "^4.4.3",
|
|
27
|
+
"@rawdash/core": "0.18.0"
|
|
33
28
|
},
|
|
34
29
|
"devDependencies": {
|
|
35
|
-
"@rawdash/connector-shared": "workspace:*",
|
|
36
|
-
"@rawdash/connector-test-utils": "workspace:*",
|
|
37
30
|
"fast-check": "^4.8.0",
|
|
38
31
|
"tsup": "^8.0.0",
|
|
39
32
|
"typescript": "^5.7.2",
|
|
40
|
-
"vitest": "^4.1.4"
|
|
33
|
+
"vitest": "^4.1.4",
|
|
34
|
+
"@rawdash/connector-shared": "0.3.0",
|
|
35
|
+
"@rawdash/connector-test-utils": "0.0.5"
|
|
36
|
+
},
|
|
37
|
+
"scripts": {
|
|
38
|
+
"build": "tsup",
|
|
39
|
+
"typecheck": "tsc --noEmit",
|
|
40
|
+
"lint": "eslint src",
|
|
41
|
+
"test": "vitest run"
|
|
41
42
|
}
|
|
42
|
-
}
|
|
43
|
+
}
|