summaryrefslogtreecommitdiff
path: root/devtools/client/application/src/types/manifest.js
blob: 7f49522a25d7eefc7db44227316703ec21b35ce2 (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
/* This Source Code Form is subject to the terms of the Mozilla Public
 * License, v. 2.0. If a copy of the MPL was not distributed with this
 * file, You can obtain one at http://mozilla.org/MPL/2.0/. */

"use strict";

const PropTypes = require("resource://devtools/client/shared/vendor/react-prop-types.js");

const {
  MANIFEST_ISSUE_LEVELS,
} = require("resource://devtools/client/application/src/constants.js");
const {
  MANIFEST_MEMBER_VALUE_TYPES,
} = require("resource://devtools/client/application/src/constants.js");

const manifestIssue = {
  level: PropTypes.oneOf(Object.values(MANIFEST_ISSUE_LEVELS)).isRequired,
  message: PropTypes.string.isRequired,
  // NOTE: we are currently ignoring the 'type' field that platform adds to errors
};

const manifestIssueArray = PropTypes.arrayOf(PropTypes.shape(manifestIssue));

const manifestItemColor = {
  label: PropTypes.string.isRequired,
  value: PropTypes.string,
};

const manifestItemIcon = {
  label: PropTypes.shape({
    contentType: PropTypes.string,
    sizes: PropTypes.string,
  }).isRequired,
  value: PropTypes.shape({
    src: PropTypes.string.isRequired,
    purpose: PropTypes.string.isRequired,
  }).isRequired,
};

const manifestItemUrl = {
  label: PropTypes.string.isRequired,
  value: PropTypes.string,
};

const manifestMemberColor = {
  key: manifestItemColor.label,
  value: manifestItemColor.value,
  type: PropTypes.oneOf([MANIFEST_MEMBER_VALUE_TYPES.COLOR]),
};

const manifestMemberIcon = {
  key: manifestItemIcon.label,
  value: manifestItemIcon.value,
  type: PropTypes.oneOf([MANIFEST_MEMBER_VALUE_TYPES.ICON]),
};

const manifestMemberString = {
  key: PropTypes.string.isRequired,
  value: PropTypes.string,
  type: PropTypes.oneOf([MANIFEST_MEMBER_VALUE_TYPES.STRING]),
};

const manifest = {
  // members
  identity: PropTypes.arrayOf(PropTypes.shape(manifestMemberString)).isRequired,
  presentation: PropTypes.arrayOf(
    PropTypes.oneOfType([
      PropTypes.shape(manifestMemberColor),
      PropTypes.shape(manifestMemberString),
    ])
  ).isRequired,
  icons: PropTypes.arrayOf(PropTypes.shape(manifestMemberIcon)).isRequired,
  // validation issues
  validation: manifestIssueArray.isRequired,
  // misc
  url: PropTypes.string.isRequired,
};

module.exports = {
  // full manifest
  manifest,
  // specific manifest items
  manifestItemColor,
  manifestItemIcon,
  manifestItemUrl,
  // manifest issues
  manifestIssue,
  manifestIssueArray,
};