@nuxtseo/protocol 0.1.4 → 0.1.5

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/dist/v1/gsc.js CHANGED
@@ -15,6 +15,31 @@ export const searchAnalyticsViewSchema = schema.enum([
15
15
  'analysis',
16
16
  ]);
17
17
  const periodSchema = schema.enum(['7d', '28d', '3m', '6m', '12m']);
18
+ /**
19
+ * Legacy response discriminator alias. This operation shipped in 1.0.0 with
20
+ * its response objects discriminating on `type`; v1 clients generated from
21
+ * that contract still key on it. Producers keep emitting `type` alongside the
22
+ * canonical `view` for one deprecation window instead of breaking them
23
+ * implicitly within the same major version.
24
+ */
25
+ function legacyViewDiscriminator(view) {
26
+ return schema.literal(view).default(view);
27
+ }
28
+ /**
29
+ * Accept envelopes keyed by either spelling: a payload carrying only the
30
+ * legacy `type` gains the canonical `view` before the discriminated union
31
+ * parses it.
32
+ */
33
+ function acceptLegacyViewDiscriminator(union) {
34
+ return schema.preprocess((value) => {
35
+ if (typeof value !== 'object' || value === null || Array.isArray(value))
36
+ return value;
37
+ const candidate = value;
38
+ if (!('view' in candidate) && typeof candidate.type === 'string')
39
+ return { ...candidate, view: candidate.type };
40
+ return value;
41
+ }, union);
42
+ }
18
43
  const pageUrlSchema = schema.string().refine(value => value.startsWith('/') || URL.canParse(value), 'Expected an absolute URL or a site-relative path starting with /.');
19
44
  export const searchAnalyticsQuerySchema = schema.strictObject({
20
45
  view: searchAnalyticsViewSchema,
@@ -92,7 +117,8 @@ const deviceRowSchema = defineResponseObject({
92
117
  function breakdownSchema(view, row) {
93
118
  return defineResponseObject({
94
119
  site: schema.string().min(1),
95
- type: schema.literal(view),
120
+ view: schema.literal(view),
121
+ type: legacyViewDiscriminator(view),
96
122
  period: periodSchema,
97
123
  total: schema.number().int().nonnegative(),
98
124
  totals: totalsSchema.producer.nullable(),
@@ -102,7 +128,7 @@ function breakdownSchema(view, row) {
102
128
  rows: schema.array(row.producer),
103
129
  }, {
104
130
  site: schema.string().min(1),
105
- type: schema.literal(view),
131
+ view: schema.literal(view),
106
132
  period: periodSchema,
107
133
  total: schema.number().int().nonnegative(),
108
134
  totals: totalsSchema.client.nullable(),
@@ -125,14 +151,15 @@ const dailyRowSchema = defineResponseObject({
125
151
  });
126
152
  const timeseriesDataSchema = defineResponseObject({
127
153
  site: schema.string().min(1),
128
- type: schema.literal('timeseries'),
154
+ view: schema.literal('timeseries'),
155
+ type: legacyViewDiscriminator('timeseries'),
129
156
  period: periodSchema,
130
157
  totals: totalsSchema.producer.nullable(),
131
158
  prevTotals: totalsSchema.producer.nullable(),
132
159
  daily: schema.array(dailyRowSchema.producer),
133
160
  }, {
134
161
  site: schema.string().min(1),
135
- type: schema.literal('timeseries'),
162
+ view: schema.literal('timeseries'),
136
163
  period: periodSchema,
137
164
  totals: totalsSchema.client.nullable(),
138
165
  prevTotals: totalsSchema.client.nullable(),
@@ -149,14 +176,15 @@ const pageDetailRowSchema = defineResponseObject({
149
176
  });
150
177
  const pageDetailDataSchema = defineResponseObject({
151
178
  site: schema.string().min(1),
152
- type: schema.literal('page-detail'),
179
+ view: schema.literal('page-detail'),
180
+ type: legacyViewDiscriminator('page-detail'),
153
181
  pageUrl: pageUrlSchema,
154
182
  period: periodSchema,
155
183
  totals: totalsSchema.producer.nullable(),
156
184
  rows: schema.array(pageDetailRowSchema.producer),
157
185
  }, {
158
186
  site: schema.string().min(1),
159
- type: schema.literal('page-detail'),
187
+ view: schema.literal('page-detail'),
160
188
  pageUrl: pageUrlSchema,
161
189
  period: periodSchema,
162
190
  totals: totalsSchema.client.nullable(),
@@ -173,14 +201,15 @@ const keywordDetailRowSchema = defineResponseObject({
173
201
  });
174
202
  const keywordDetailDataSchema = defineResponseObject({
175
203
  site: schema.string().min(1),
176
- type: schema.literal('keyword-detail'),
204
+ view: schema.literal('keyword-detail'),
205
+ type: legacyViewDiscriminator('keyword-detail'),
177
206
  keyword: schema.string().min(1),
178
207
  period: periodSchema,
179
208
  totals: totalsSchema.producer.nullable(),
180
209
  rows: schema.array(keywordDetailRowSchema.producer),
181
210
  }, {
182
211
  site: schema.string().min(1),
183
- type: schema.literal('keyword-detail'),
212
+ view: schema.literal('keyword-detail'),
184
213
  keyword: schema.string().min(1),
185
214
  period: periodSchema,
186
215
  totals: totalsSchema.client.nullable(),
@@ -205,7 +234,8 @@ const analysisRowSchema = defineResponseObject({
205
234
  });
206
235
  const analysisDataSchema = defineResponseObject({
207
236
  site: schema.string().min(1),
208
- type: schema.literal('analysis'),
237
+ view: schema.literal('analysis'),
238
+ type: legacyViewDiscriminator('analysis'),
209
239
  preset: gscdumpAnalysisPresetSchema,
210
240
  description: schema.string().min(1),
211
241
  criteria: schema.record(schema.string(), schema.union([schema.string(), schema.number(), schema.null()])),
@@ -215,7 +245,7 @@ const analysisDataSchema = defineResponseObject({
215
245
  rows: schema.array(analysisRowSchema.producer),
216
246
  }, {
217
247
  site: schema.string().min(1),
218
- type: schema.literal('analysis'),
248
+ view: schema.literal('analysis'),
219
249
  preset: gscdumpAnalysisPresetSchema,
220
250
  description: schema.string().min(1),
221
251
  criteria: schema.record(schema.string(), schema.union([schema.string(), schema.number(), schema.null()])),
@@ -225,7 +255,7 @@ const analysisDataSchema = defineResponseObject({
225
255
  rows: schema.array(analysisRowSchema.client),
226
256
  });
227
257
  export const searchAnalyticsDataSchema = {
228
- producer: schema.discriminatedUnion('type', [
258
+ producer: schema.discriminatedUnion('view', [
229
259
  pagesDataSchema.producer,
230
260
  keywordsDataSchema.producer,
231
261
  countriesDataSchema.producer,
@@ -235,7 +265,7 @@ export const searchAnalyticsDataSchema = {
235
265
  keywordDetailDataSchema.producer,
236
266
  analysisDataSchema.producer,
237
267
  ]),
238
- client: schema.discriminatedUnion('type', [
268
+ client: acceptLegacyViewDiscriminator(schema.discriminatedUnion('view', [
239
269
  pagesDataSchema.client,
240
270
  keywordsDataSchema.client,
241
271
  countriesDataSchema.client,
@@ -244,7 +274,7 @@ export const searchAnalyticsDataSchema = {
244
274
  pageDetailDataSchema.client,
245
275
  keywordDetailDataSchema.client,
246
276
  analysisDataSchema.client,
247
- ]),
277
+ ])),
248
278
  };
249
279
  export const searchAnalyticsResponseSchema = defineSuccessEnvelope(searchAnalyticsDataSchema);
250
280
  export const searchStatusDataSchema = {
@@ -480,7 +510,7 @@ export const searchAnalyticsQueryOperation = defineOperation({
480
510
  tags: ['Sites', 'Search'],
481
511
  examples: [{
482
512
  request: { params: { siteId: 'site_01JXYZ' }, query: { view: 'keywords' } },
483
- response: { status: 200, body: { data: { site: 'https://example.com', type: 'keywords', period: '28d', total: 1, totals: { clicks: 12, impressions: 100, ctr: 0.12, position: 4 }, totalsScope: 'full upstream query population', representedTotals: { clicks: 12, impressions: 100 }, representedTotalsScope: 'returned rows', rows: [{ keyword: 'nuxt seo', clicks: 12, impressions: 100, ctr: 0.12, pos: 4, topPage: 'https://example.com/docs', change: 2 }] }, meta: { requestId: 'req_01JXYZ', version: '1.0' } } },
513
+ response: { status: 200, body: { data: { site: 'https://example.com', view: 'keywords', period: '28d', total: 1, totals: { clicks: 12, impressions: 100, ctr: 0.12, position: 4 }, totalsScope: 'full upstream query population', representedTotals: { clicks: 12, impressions: 100 }, representedTotalsScope: 'returned rows', rows: [{ keyword: 'nuxt seo', clicks: 12, impressions: 100, ctr: 0.12, pos: 4, topPage: 'https://example.com/docs', change: 2 }] }, meta: { requestId: 'req_01JXYZ', version: '1.0' } } },
484
514
  }],
485
515
  },
486
516
  });
package/dist/v1/pages.js CHANGED
@@ -1,11 +1,11 @@
1
1
  import { z as schema } from 'zod';
2
- import { defineOperation, defineRegistry, defineResponseObject, defineSuccessEnvelope, publicV1ErrorEnvelope, publicV1StandardRatePolicy, } from './core.js';
2
+ import { defineOperation, defineRegistry, defineResponseObject, defineSuccessEnvelope, publicV1BooleanFlag, publicV1ErrorEnvelope, publicV1StandardRatePolicy, } from './core.js';
3
3
  export const pageSiteParamsSchema = schema.strictObject({
4
4
  siteId: schema.string().min(1),
5
5
  });
6
6
  export const pageInspectQuerySchema = schema.strictObject({
7
7
  url: schema.string().url(),
8
- includeResolved: schema.enum(['0', '1', 'true', 'false']).default('0').transform(value => value === '1' || value === 'true'),
8
+ includeResolved: publicV1BooleanFlag(false),
9
9
  limit: schema.coerce.number().int().min(1).max(200).default(100),
10
10
  offset: schema.coerce.number().int().min(0).default(0),
11
11
  });