summaryrefslogtreecommitdiff
path: root/node_modules/@jet-app/app-store/tmp/src/common/content/sad.js
blob: 20fde05dda3e6dcea1b187c297b7f1514c48c061 (plain)
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
88
89
90
91
92
93
import { isSome } from "@jet/environment/types/optional";
import * as serverData from "../../foundation/json-parsing/server-data";
import * as mediaAttributes from "../../foundation/media/attributes";
import * as contentAttributes from "./attributes";
let implementation = null;
/**
 * Creates an implementation of the `SystemApps` interface
 * which is appropriate for the current platform.
 */
export function systemApps(objectGraph) {
    if (implementation !== null) {
        return implementation;
    }
    // Because watchOS is not a proper platform from the back end's perspective,
    // we must map adam IDs to bundle IDs using a bag property.
    if (objectGraph.client.isWatch) {
        const systemAppsMap = new Map();
        const nonDeletableSystemAppsMap = new Map();
        for (const systemApp of objectGraph.bag.systemApps) {
            const bundleId = serverData.asString(systemApp, "bundle-id", "coercible");
            const adamId = serverData.asString(systemApp, "id", "coercible");
            if (isSome(bundleId) && isSome(adamId)) {
                systemAppsMap.set(adamId, bundleId);
            }
        }
        for (const nonDeletableSystemApp of objectGraph.bag.nonDeletableSystemApps) {
            const bundleId = serverData.asString(nonDeletableSystemApp, "bundle-id", "coercible");
            const adamId = serverData.asString(nonDeletableSystemApp, "id", "coercible");
            if (isSome(bundleId) && isSome(adamId)) {
                nonDeletableSystemAppsMap.set(adamId, bundleId);
            }
        }
        const unsupportedSystemApps = new Map();
        implementation = {
            bundleIdFromData(data) {
                const mappedBundleId = systemAppsMap.get(data.id);
                if (!serverData.isNull(mappedBundleId)) {
                    return mappedBundleId;
                }
                else {
                    return contentAttributes.contentAttributeAsString(objectGraph, data, "bundleId");
                }
            },
            isSystemAppFromData(data) {
                return systemAppsMap.has(data.id);
            },
            isUnsupportedDeletableSystemAppFromData(data) {
                if (systemAppsMap.has(data.id) && !nonDeletableSystemAppsMap.has(data.id)) {
                    // We must use the bundleID from the bag here, rather than a bundleID from `data`,
                    // as AppConduit is expecting the bundleIDs which are provided in the bag
                    const bundleId = systemAppsMap.get(data.id);
                    if (serverData.isDefinedNonNullNonEmpty(bundleId)) {
                        const valueFromMap = unsupportedSystemApps.get(bundleId);
                        if (isSome(valueFromMap)) {
                            return valueFromMap;
                        }
                        const isUnsupported = !objectGraph.client.deletableSystemAppCanBeInstalledOnWatchWithBundleID(bundleId);
                        unsupportedSystemApps.set(bundleId, isUnsupported);
                        return isUnsupported;
                    }
                }
                return false;
            },
            adamIdFromSystemBundleId(bundleId) {
                for (const [key, value] of systemAppsMap) {
                    if (value === bundleId) {
                        return key;
                    }
                }
                return undefined;
            },
        };
    }
    else {
        implementation = {
            bundleIdFromData(data) {
                return contentAttributes.contentAttributeAsString(objectGraph, data, "bundleId");
            },
            isSystemAppFromData(data) {
                return mediaAttributes.attributeAsBooleanOrFalse(data, "isFirstPartyHideableApp");
            },
            isUnsupportedDeletableSystemAppFromData(data) {
                return false;
            },
            adamIdFromSystemBundleId(bundleId) {
                // This path shouldn't run on any other platforms.
                return undefined;
            },
        };
    }
    return implementation;
}
//# sourceMappingURL=sad.js.map