1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
|
import { unwrapOptional as unwrap } from "@jet/environment/types/optional";
import { attributeAsArrayOrEmpty } from "../foundation/media/attributes";
import { dataFromDataContainer } from "../foundation/media/data-structure";
import { deviceFamiliesFromData } from "./content/device-family";
/**
* Retreive the current `PreviewPlatform`, in the format used to create a {@linkcode WithPlatform} `Intent`
*
* @example
* makeIntentWithPlatform({
* ...getPlatform(objectGraph)
* ...otherProps
* });
*/
export function getPlatform(objectGraph) {
var _a;
return {
platform: (_a = objectGraph.activeIntent) === null || _a === void 0 ? void 0 : _a.previewPlatform,
};
}
/**
* Determine the most relevant {@linkcode PreviewPlatform} from a Media API response that
* contains "device families", like an `app` or `app-bundle`
*/
export function inferPreviewPlatformFromDeviceFamilies(objectGraph, response) {
const data = unwrap(dataFromDataContainer(objectGraph, response));
const deviceFamilies = new Set(deviceFamiliesFromData(objectGraph, data, true));
if (deviceFamilies.has("iphone")) {
return "iphone";
}
if (deviceFamilies.has("ipad")) {
return "ipad";
}
if (deviceFamilies.has("mac")) {
return "mac";
}
if (deviceFamilies.has("realityDevice")) {
return "vision";
}
if (deviceFamilies.has("tvos")) {
return "tv";
}
if (deviceFamilies.has("watch")) {
return "watch";
}
throw new Error("Could not infer platform from device families");
}
/**
* Determine the most relevant {@linkcode PreviewPlatform} from a Media API response that
* contains "editorial platforms"", like `editorial-items`
*/
export function inferPreviewPlatformFromEditorialPlatforms(objectGraph, container) {
const data = unwrap(dataFromDataContainer(objectGraph, container));
const editorialPlatforms = new Set(attributeAsArrayOrEmpty(data, "editorialPlatforms"));
if (editorialPlatforms.has("iphone")) {
return "iphone";
}
if (editorialPlatforms.has("ipad")) {
return "ipad";
}
if (editorialPlatforms.has("desktop")) {
return "mac";
}
if (editorialPlatforms.has("realitydevice")) {
return "vision";
}
if (editorialPlatforms.has("watch")) {
return "watch";
}
if (editorialPlatforms.has("appletv")) {
return "tv";
}
throw new Error("Could not infer preview platform from editorial platforms");
}
/**
* Set the `previewPlatform` query param on the {@linkcode request}, if necessary
*
* This should only be used with requests being made for the following resources:
* - "Editorial" (Grouping Page, Editorial Page, Today, etc)
* - "Search"
*/
export function setPreviewPlatform(objectGraph, request) {
var _a;
return ((_a = objectGraph.activeIntent) === null || _a === void 0 ? void 0 : _a.previewPlatform)
? request.addingQuery("previewPlatform", objectGraph.activeIntent.platform).addingQuery("platform", "web")
: request;
}
//# sourceMappingURL=preview-platform.js.map
|