jenkins-bot has submitted this change and it was merged. ( 
https://gerrit.wikimedia.org/r/380903 )

Change subject: Chore: add missing types to page summaries
......................................................................


Chore: add missing types to page summaries

- Add missed response ETags, Mobile Content Service Errors, and request
  redirects to page summaries for completeness. These aren't currently
  used but Marvin's definition for the service responses should be
  accurate. Error is currently unreferenced but will soon be wanted.

- Add missing references to page summary related types. Most of these
  are URLs but may be difficult to uncover because they live in multiple
  services.

Bug: T173324
Change-Id: I475f6d78151d4c5d403454b02554a163607f7daa
---
M package-lock.json
M package.json
M src/common/data-clients/page-data-client.ts
M src/common/marshallers/page-restbase-mount-everest-expected.test.json
M src/common/marshallers/page-unmarshaller.test.ts
M src/common/marshallers/page-unmarshaller.ts
M src/common/marshallers/restbase.ts
M src/common/models/page.ts
A src/common/types/isomorphic-unfetch-extras.d.ts
9 files changed, 90 insertions(+), 9 deletions(-)

Approvals:
  Jhernandez: Looks good to me, approved
  jenkins-bot: Verified



diff --git a/package-lock.json b/package-lock.json
index 8a432a8..3234cf5 100644
--- a/package-lock.json
+++ b/package-lock.json
@@ -74,6 +74,15 @@
       "integrity": 
"sha512-HupkFXEv3O3KSzcr3Ylfajg0kaerBg1DyaZzRBBQfrU3NN1mTBRE7sCveqHwXLS5Yrjvww8qFzkzYQQakG9FuQ==",
       "dev": true
     },
+    "@types/node-fetch": {
+      "version": "1.6.7",
+      "resolved": 
"https://registry.npmjs.org/@types/node-fetch/-/node-fetch-1.6.7.tgz";,
+      "integrity": "sha1-UhB46PDGmhWOUCIAWsqS0mIPbVc=",
+      "dev": true,
+      "requires": {
+        "@types/node": "8.0.28"
+      }
+    },
     "@types/serve-static": {
       "version": "1.7.32",
       "resolved": 
"https://registry.npmjs.org/@types/serve-static/-/serve-static-1.7.32.tgz";,
diff --git a/package.json b/package.json
index b5ac1b2..a71b824 100644
--- a/package.json
+++ b/package.json
@@ -60,6 +60,7 @@
     "@types/history": "4.6.0",
     "@types/mocha": "2.2.43",
     "@types/node": "8.0.28",
+    "@types/node-fetch": "1.6.7",
     "@types/touch": "3.1.0",
     "assets-webpack-plugin": "3.5.1",
     "copyfiles": "1.2.0",
diff --git a/src/common/data-clients/page-data-client.ts 
b/src/common/data-clients/page-data-client.ts
index 5a914a6..f739feb 100644
--- a/src/common/data-clients/page-data-client.ts
+++ b/src/common/data-clients/page-data-client.ts
@@ -2,12 +2,29 @@
 import { PageSummary, PageTitlePath } from "../models/page";
 import { unmarshalPageSummary } from "../marshallers/page-unmarshaller";
 
+// https://en.wikipedia.org/api/rest_v1/#!/Page_content/get_page_summary_title
 export interface Params {
   titlePath: PageTitlePath;
+
+  /**
+   * When enabled (the default), requests for [redirect pages] return an HTTP
+   * 302 with a redirect target in the Location header and content in the body.
+   * When disabled, an HTTP 200 response is returned instead.
+   *
+   * Beware that redirected pre-flighted cross-origin requests (such as those
+   * sending custom request headers like Api-User-Agent) will fail in most
+   * current browsers due to a [spec bug].
+   *
+   * [redirect pages]: https://www.mediawiki.org/wiki/Help:Redirects
+   * [spec bug]: https://github.com/whatwg/fetch/issues/204
+   */
+  redirect?: boolean;
 }
 
-const url = ({ titlePath }: Params) =>
-  `https://en.wikipedia.org/api/rest_v1/page/summary/${titlePath}`;
+const url = ({ titlePath, redirect }: Params) => {
+  const redirectParam = redirect === undefined ? "" : `&redirect=${redirect}`;
+  return 
`https://en.wikipedia.org/api/rest_v1/page/summary/${titlePath}${redirectParam}`;
+};
 
 const HEADERS = {
   accept:
@@ -16,5 +33,5 @@
 
 export const requestPageSummary = (params: Params): Promise<PageSummary> =>
   fetch(url(params), { headers: HEADERS })
-    .then((response: Response) => response.json())
-    .then(unmarshalPageSummary);
+    .then(response => Promise.all([response.headers, response.json()]))
+    .then(([headers, json]) => unmarshalPageSummary({ headers, json }));
diff --git 
a/src/common/marshallers/page-restbase-mount-everest-expected.test.json 
b/src/common/marshallers/page-restbase-mount-everest-expected.test.json
index 72ecd4e..d56cfec 100644
--- a/src/common/marshallers/page-restbase-mount-everest-expected.test.json
+++ b/src/common/marshallers/page-restbase-mount-everest-expected.test.json
@@ -28,5 +28,6 @@
   "geolocation": {
     "latitude": 27.98805556,
     "longitude": 86.92527778
-  }
-}
\ No newline at end of file
+  },
+  "etag": "802006980/4f754377-a235-11e7-a776-efb84f18649a"
+}
diff --git a/src/common/marshallers/page-unmarshaller.test.ts 
b/src/common/marshallers/page-unmarshaller.test.ts
index 084df01..22418a5 100644
--- a/src/common/marshallers/page-unmarshaller.test.ts
+++ b/src/common/marshallers/page-unmarshaller.test.ts
@@ -1,11 +1,15 @@
 import * as assert from "assert";
+import * as fetch from "node-fetch";
 import { pageSummaryReviver } from "../models/page";
 import { unmarshalPageSummary } from "./page-unmarshaller";
+
+const HEADERS = new fetch.Headers();
+HEADERS.append("etag", "802006980/4f754377-a235-11e7-a776-efb84f18649a");
 
 describe("page-unmarshaller", () => {
   it("unmarshalPageSummary() unmarshals", () => {
     const input = require("./page-restbase-mount-everest-input.test.json");
-    const result = unmarshalPageSummary(input);
+    const result = unmarshalPageSummary({ headers: HEADERS, json: input });
     const expected = JSON.parse(
       JSON.stringify(
         require("./page-restbase-mount-everest-expected.test.json")
diff --git a/src/common/marshallers/page-unmarshaller.ts 
b/src/common/marshallers/page-unmarshaller.ts
index 71c58be..5033d78 100644
--- a/src/common/marshallers/page-unmarshaller.ts
+++ b/src/common/marshallers/page-unmarshaller.ts
@@ -4,6 +4,7 @@
   PageSummary,
   PageThumbnail
 } from "../models/page";
+import { IsomorphicHeaders } from "../types/isomorphic-unfetch-extras";
 import { JSONObject } from "../types/json";
 import { RESTBase } from "./restbase";
 
@@ -71,7 +72,21 @@
   );
 };
 
-export const unmarshalPageSummary = (json: JSONObject): PageSummary => {
+export const unmarshalETag = (headers: IsomorphicHeaders): RESTBase.ETag => {
+  const eTag = headers.get("ETag");
+  if (!eTag) {
+    throw new Error("ETag is undefined.");
+  }
+  return eTag;
+};
+
+export const unmarshalPageSummary = ({
+  headers,
+  json
+}: {
+  headers: IsomorphicHeaders;
+  json: JSONObject;
+}): PageSummary => {
   const type: RESTBase.PageSummary.PageSummary = json as any;
   return {
     wikiLanguageCode: type.lang,
@@ -86,6 +101,7 @@
     thumbnail: type.thumbnail && unmarshalPageThumbnail(type.thumbnail as {}),
     image: type.originalimage && unmarshalPageImage(type.originalimage as {}),
     geolocation:
-      type.coordinates && unmarshalPageGeolocation(type.coordinates as {})
+      type.coordinates && unmarshalPageGeolocation(type.coordinates as {}),
+    etag: unmarshalETag(headers)
   };
 };
diff --git a/src/common/marshallers/restbase.ts 
b/src/common/marshallers/restbase.ts
index 37c1d94..a8e9086 100644
--- a/src/common/marshallers/restbase.ts
+++ b/src/common/marshallers/restbase.ts
@@ -1,6 +1,29 @@
 export namespace RESTBase {
+  // 
https://phabricator.wikimedia.org/diffusion/GMOA/browse/master/spec.yaml;399c85e3e782ffa7fef2d4a73c4ee85e98c9114d$690
+  // 
https://phabricator.wikimedia.org/diffusion/GMOA/browse/master/lib/util.js;552a924e45d11a0c20b284c252f0b02065a0d44c$210
+  export interface Error {
+    status?: number;
+    type: number;
+    title?: string;
+    detail?: string;
+    method?: string;
+    uri?: string;
+  }
+
+  /**
+   * A response ETag header indicating the revision and render time UUID or
+   * "TID" separated by a slash (ex:
+   * `ETag: 701384379/154d7bca-c264-11e5-8c2f-1b51b33b59fc`). This ETag can be
+   * passed to the HTML save end point (as the base_etag POST parameter), and
+   * can also be used to retrieve the exact corresponding data-parsoid 
metadata,
+   * by requesting the specific revision and time UUID / TID indicated by the
+   * ETag.
+   */
+  export type ETag = string;
+
   // 
https://en.wikipedia.org/api/rest_v1/#!/Page_content/get_page_summary_title
   export namespace PageSummary {
+    // 
https://phabricator.wikimedia.org/diffusion/GRES/browse/master/v1/summary.yaml;efa0412225221d49e901fdce0ba2ae88cd6ccc11$138
     export interface Thumbnail {
       source: string;
       original: string;
@@ -8,21 +31,25 @@
       height: number;
     }
 
+    // 
https://phabricator.wikimedia.org/diffusion/GRES/browse/master/v1/summary.yaml;efa0412225221d49e901fdce0ba2ae88cd6ccc11$139
     export interface Image {
       source: string;
       width: number;
       height: number;
     }
 
+    // 
https://phabricator.wikimedia.org/diffusion/GRES/browse/master/v1/summary.yaml;efa0412225221d49e901fdce0ba2ae88cd6ccc11$144
     export interface Geolocation {
       lat: number;
       lon: number;
     }
 
+    // 
https://phabricator.wikimedia.org/diffusion/GRES/browse/master/v1/summary.yaml;efa0412225221d49e901fdce0ba2ae88cd6ccc11$128-144
     export interface PageSummary {
       title: string;
       displaytitle: string;
       pageid: number;
+      // 
https://phabricator.wikimedia.org/diffusion/GMOA/browse/master/lib/transformations/summarize.js;a4f603b2f535d8d153b62044a2210acf22bf6e11$58-59
       extract: string;
       extract_html: string; // eslint-disable-line camelcase
       thumbnail?: Thumbnail;
diff --git a/src/common/models/page.ts b/src/common/models/page.ts
index ecc2eb1..334a7a3 100644
--- a/src/common/models/page.ts
+++ b/src/common/models/page.ts
@@ -1,3 +1,5 @@
+import { RESTBase } from "../marshallers/restbase";
+
 /**
  * URL-decoded normalized wiki URL path. e.g.: Main_Page,
  * Bill_&_Ted's_Excellent_Adventure.
@@ -46,6 +48,7 @@
   thumbnail?: PageThumbnail;
   image?: PageImage;
   geolocation?: PageGeolocation;
+  etag: RESTBase.ETag;
 }
 
 export const pageSummaryReviver = (key: string, value: any): any =>
diff --git a/src/common/types/isomorphic-unfetch-extras.d.ts 
b/src/common/types/isomorphic-unfetch-extras.d.ts
new file mode 100644
index 0000000..721cad4
--- /dev/null
+++ b/src/common/types/isomorphic-unfetch-extras.d.ts
@@ -0,0 +1,3 @@
+import { Headers as NodeHeaders } from "node-fetch";
+
+export type IsomorphicHeaders = Headers | NodeHeaders;

-- 
To view, visit https://gerrit.wikimedia.org/r/380903
To unsubscribe, visit https://gerrit.wikimedia.org/r/settings

Gerrit-MessageType: merged
Gerrit-Change-Id: I475f6d78151d4c5d403454b02554a163607f7daa
Gerrit-PatchSet: 4
Gerrit-Project: marvin
Gerrit-Branch: master
Gerrit-Owner: Niedzielski <sniedziel...@wikimedia.org>
Gerrit-Reviewer: Jhernandez <jhernan...@wikimedia.org>
Gerrit-Reviewer: Sniedzielski <sniedziel...@wikimedia.org>
Gerrit-Reviewer: jenkins-bot <>

_______________________________________________
MediaWiki-commits mailing list
MediaWiki-commits@lists.wikimedia.org
https://lists.wikimedia.org/mailman/listinfo/mediawiki-commits

Reply via email to