@dhis2/app-service-data 3.11.3 → 3.12.0-alpha.2

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.
Files changed (113) hide show
  1. package/build/cjs/__tests__/integration.test.js +6 -15
  2. package/build/cjs/__tests__/mutations.test.js +4 -11
  3. package/build/cjs/engine/DataEngine.js +4 -14
  4. package/build/cjs/engine/DataEngine.test.js +0 -2
  5. package/build/cjs/engine/helpers/getMutationFetchType.js +0 -2
  6. package/build/cjs/engine/helpers/getMutationFetchType.test.js +0 -1
  7. package/build/cjs/engine/helpers/resolveDynamicQuery.js +0 -2
  8. package/build/cjs/engine/helpers/resolveDynamicQuery.test.js +3 -4
  9. package/build/cjs/engine/helpers/validate.js +0 -21
  10. package/build/cjs/engine/helpers/validate.test.js +0 -1
  11. package/build/cjs/engine/index.js +0 -18
  12. package/build/cjs/engine/types/FetchError.js +3 -8
  13. package/build/cjs/engine/types/FetchError.test.js +0 -1
  14. package/build/cjs/engine/types/InvalidQueryError.js +3 -8
  15. package/build/cjs/index.js +0 -2
  16. package/build/cjs/links/CustomDataLink.js +3 -17
  17. package/build/cjs/links/CustomDataLink.test.js +0 -1
  18. package/build/cjs/links/ErrorLink.js +3 -7
  19. package/build/cjs/links/RestAPILink/fetchData.js +12 -22
  20. package/build/cjs/links/RestAPILink/fetchData.test.js +0 -2
  21. package/build/cjs/links/RestAPILink/metadataResources.js +9 -7
  22. package/build/cjs/links/RestAPILink/path.js +0 -3
  23. package/build/cjs/links/RestAPILink/path.test.js +0 -1
  24. package/build/cjs/links/RestAPILink/queryToRequestOptions/multipartFormDataMatchers.js +9 -14
  25. package/build/cjs/links/RestAPILink/queryToRequestOptions/multipartFormDataMatchers.test.js +0 -1
  26. package/build/cjs/links/RestAPILink/queryToRequestOptions/requestContentType.js +4 -31
  27. package/build/cjs/links/RestAPILink/queryToRequestOptions/requestContentType.test.js +0 -1
  28. package/build/cjs/links/RestAPILink/queryToRequestOptions/textPlainMatchers.js +22 -39
  29. package/build/cjs/links/RestAPILink/queryToRequestOptions/textPlainMatchers.test.js +0 -1
  30. package/build/cjs/links/RestAPILink/queryToRequestOptions/xWwwFormUrlencodedMatchers.js +0 -2
  31. package/build/cjs/links/RestAPILink/queryToRequestOptions/xWwwFormUrlencodedMatchers.test.js +0 -1
  32. package/build/cjs/links/RestAPILink/queryToRequestOptions.js +0 -9
  33. package/build/cjs/links/RestAPILink/queryToRequestOptions.test.js +0 -1
  34. package/build/cjs/links/RestAPILink/queryToResourcePath.js +3 -24
  35. package/build/cjs/links/RestAPILink/queryToResourcePath.test.js +2 -4
  36. package/build/cjs/links/RestAPILink/validateQuery.js +4 -18
  37. package/build/cjs/links/RestAPILink/validateQuery.test.js +0 -1
  38. package/build/cjs/links/RestAPILink.js +3 -14
  39. package/build/cjs/links/RestAPILink.test.js +0 -2
  40. package/build/cjs/links/index.js +0 -6
  41. package/build/cjs/react/components/CustomDataProvider.js +3 -12
  42. package/build/cjs/react/components/DataMutation.js +1 -4
  43. package/build/cjs/react/components/DataProvider.js +11 -16
  44. package/build/cjs/react/components/DataProvider.test.js +2 -9
  45. package/build/cjs/react/components/DataQuery.js +1 -4
  46. package/build/cjs/react/context/DataContext.js +2 -8
  47. package/build/cjs/react/context/defaultContext.js +2 -6
  48. package/build/cjs/react/context/defaultContext.test.js +0 -1
  49. package/build/cjs/react/hooks/mergeAndCompareVariables.js +4 -6
  50. package/build/cjs/react/hooks/mergeAndCompareVariables.test.js +2 -3
  51. package/build/cjs/react/hooks/stableVariablesHash.js +11 -16
  52. package/build/cjs/react/hooks/stableVariablesHash.test.js +0 -1
  53. package/build/cjs/react/hooks/useDataEngine.js +0 -4
  54. package/build/cjs/react/hooks/useDataMutation.js +0 -7
  55. package/build/cjs/react/hooks/useDataMutation.test.js +42 -71
  56. package/build/cjs/react/hooks/useDataQuery.js +26 -44
  57. package/build/cjs/react/hooks/useDataQuery.test.js +318 -374
  58. package/build/cjs/react/hooks/useQueryExecutor.js +6 -14
  59. package/build/cjs/react/hooks/useQueryExecutor.test.js +42 -45
  60. package/build/cjs/react/hooks/useStaticInput.js +0 -3
  61. package/build/cjs/react/hooks/useStaticInput.test.js +8 -10
  62. package/build/cjs/react/index.js +0 -11
  63. package/build/cjs/setupRTL.js +1 -2
  64. package/build/es/__tests__/integration.test.js +4 -8
  65. package/build/es/__tests__/mutations.test.js +2 -4
  66. package/build/es/engine/DataEngine.js +3 -8
  67. package/build/es/engine/DataEngine.test.js +0 -1
  68. package/build/es/engine/helpers/resolveDynamicQuery.test.js +3 -3
  69. package/build/es/engine/helpers/validate.js +0 -13
  70. package/build/es/engine/types/FetchError.js +3 -6
  71. package/build/es/engine/types/InvalidQueryError.js +3 -6
  72. package/build/es/links/CustomDataLink.js +3 -15
  73. package/build/es/links/ErrorLink.js +3 -5
  74. package/build/es/links/RestAPILink/fetchData.js +12 -16
  75. package/build/es/links/RestAPILink/metadataResources.js +8 -3
  76. package/build/es/links/RestAPILink/path.js +0 -1
  77. package/build/es/links/RestAPILink/queryToRequestOptions/multipartFormDataMatchers.js +9 -4
  78. package/build/es/links/RestAPILink/queryToRequestOptions/requestContentType.js +2 -19
  79. package/build/es/links/RestAPILink/queryToRequestOptions/textPlainMatchers.js +22 -19
  80. package/build/es/links/RestAPILink/queryToRequestOptions.js +0 -7
  81. package/build/es/links/RestAPILink/queryToResourcePath.js +3 -21
  82. package/build/es/links/RestAPILink/queryToResourcePath.test.js +2 -3
  83. package/build/es/links/RestAPILink/validateQuery.js +4 -16
  84. package/build/es/links/RestAPILink.js +3 -8
  85. package/build/es/react/components/CustomDataProvider.js +2 -2
  86. package/build/es/react/components/DataMutation.js +1 -1
  87. package/build/es/react/components/DataProvider.js +9 -3
  88. package/build/es/react/components/DataProvider.test.js +1 -1
  89. package/build/es/react/components/DataQuery.js +1 -1
  90. package/build/es/react/hooks/mergeAndCompareVariables.js +4 -3
  91. package/build/es/react/hooks/mergeAndCompareVariables.test.js +2 -1
  92. package/build/es/react/hooks/stableVariablesHash.js +11 -14
  93. package/build/es/react/hooks/useDataMutation.test.js +17 -39
  94. package/build/es/react/hooks/useDataQuery.js +26 -37
  95. package/build/es/react/hooks/useDataQuery.test.js +268 -318
  96. package/build/es/react/hooks/useQueryExecutor.js +6 -9
  97. package/build/es/react/hooks/useQueryExecutor.test.js +33 -34
  98. package/build/es/react/hooks/useStaticInput.test.js +6 -6
  99. package/build/es/setupRTL.js +1 -1
  100. package/build/types/engine/types/ExecuteOptions.d.ts +1 -1
  101. package/build/types/engine/types/FetchError.d.ts +2 -2
  102. package/build/types/engine/types/JsonValue.d.ts +1 -1
  103. package/build/types/engine/types/Mutation.d.ts +2 -2
  104. package/build/types/engine/types/PossiblyDynamic.d.ts +1 -1
  105. package/build/types/engine/types/Query.d.ts +3 -3
  106. package/build/types/engine/types/QueryParameters.d.ts +4 -4
  107. package/build/types/links/CustomDataLink.d.ts +2 -2
  108. package/build/types/links/RestAPILink/queryToRequestOptions/requestContentType.d.ts +1 -1
  109. package/build/types/links/RestAPILink/queryToRequestOptions.d.ts +1 -1
  110. package/build/types/react/components/DataProvider.d.ts +2 -11
  111. package/build/types/react/hooks/mergeAndCompareVariables.d.ts +1 -1
  112. package/build/types/types.d.ts +6 -6
  113. package/package.json +5 -5
@@ -5,62 +5,52 @@ Object.defineProperty(exports, "__esModule", {
5
5
  });
6
6
  exports.fetchData = fetchData;
7
7
  exports.parseStatus = exports.parseContentType = void 0;
8
-
9
8
  var _engine = require("../../engine");
10
-
11
9
  const parseContentType = contentType => contentType ? contentType.split(';')[0].trim().toLowerCase() : '';
12
-
13
10
  exports.parseContentType = parseContentType;
14
-
15
11
  const parseStatus = async response => {
16
12
  const accessError = response.status === 401 || response.status === 403 || response.status === 409;
17
-
18
13
  if (accessError) {
19
14
  let message;
20
15
  let details = {};
21
-
22
16
  try {
23
17
  details = await response.json();
24
18
  message = details.message;
25
- } catch (e) {// Do nothing
26
- } // Set a message in case of invalid json, or json without 'message' property
27
-
19
+ } catch (e) {
20
+ // Do nothing
21
+ }
28
22
 
23
+ // Set a message in case of invalid json, or json without 'message' property
29
24
  if (!message) {
30
25
  message = response.status === 401 ? 'Unauthorized' : 'Forbidden';
31
26
  }
32
-
33
27
  throw new _engine.FetchError({
34
28
  type: 'access',
35
29
  message,
36
30
  details
37
31
  });
38
32
  }
39
-
40
33
  if (response.status < 200 || response.status >= 400) {
41
34
  const message = `An unknown error occurred - ${response.statusText} (${response.status})`;
42
35
  let details = {};
43
-
44
36
  try {
45
37
  details = await response.json();
46
- } catch (e) {// We can leave details as is if parsing fails
38
+ } catch (e) {
39
+ // We can leave details as is if parsing fails
47
40
  }
48
-
49
41
  throw new _engine.FetchError({
50
42
  type: 'unknown',
51
43
  message,
52
44
  details
53
45
  });
54
46
  }
55
-
56
47
  return response;
57
48
  };
58
-
59
49
  exports.parseStatus = parseStatus;
60
-
61
50
  function fetchData(url) {
62
51
  let options = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : {};
63
- return fetch(url, { ...options,
52
+ return fetch(url, {
53
+ ...options,
64
54
  credentials: 'include',
65
55
  headers: {
66
56
  'X-Requested-With': 'XMLHttpRequest',
@@ -74,17 +64,17 @@ function fetchData(url) {
74
64
  details: err
75
65
  });
76
66
  }).then(parseStatus).then(async response => {
77
- const contentType = parseContentType(response.headers.get('Content-Type')); // 'application/json'
67
+ const contentType = parseContentType(response.headers.get('Content-Type'));
78
68
 
69
+ // 'application/json'
79
70
  if (contentType === 'application/json') {
80
71
  return await response.json(); // Will throw if invalid JSON!
81
- } // 'text/*'
82
-
72
+ }
83
73
 
74
+ // 'text/*'
84
75
  if (/^text\/[a-z0-9.-]+$/.test(contentType)) {
85
76
  return await response.text();
86
77
  }
87
-
88
78
  return await response.blob();
89
79
  });
90
80
  }
@@ -1,9 +1,7 @@
1
1
  "use strict";
2
2
 
3
3
  var _engine = require("../../engine");
4
-
5
4
  var _fetchData = require("./fetchData");
6
-
7
5
  describe('networkFetch', () => {
8
6
  describe('parseContentType', () => {
9
7
  it('should pass through simple content-types', () => {
@@ -4,17 +4,19 @@ Object.defineProperty(exports, "__esModule", {
4
4
  value: true
5
5
  });
6
6
  exports.normativeMetadataResources = exports.nonNormativeMetadataResources = void 0;
7
-
8
7
  /*
9
8
  * These are metadata resources (from /api/resources) which are known to support paging.
10
9
  * They should all also support fields declarations. Only plural resource names are supported.
11
10
  * This list may be incomplete, and may require updating for new DHIS2 major versions
12
11
  */
13
- const normativeMetadataResources = ['programDataElements', 'indicatorTypes', 'programs', 'optionGroups', 'programRuleVariables', 'reports', 'users', 'constants', 'externalMapLayers', 'analyticsTableHooks', 'pushAnalysis', 'oAuth2Clients', 'validationRules', 'reportTables', 'userGroups', 'sqlViews', 'sections', 'validationNotificationTemplates', 'optionGroupSets', 'organisationUnitGroupSets', 'trackedEntityAttributes', 'dashboardItems', 'categoryCombos', 'programSections', 'trackedEntityTypes', 'dataSetNotificationTemplates', 'maps', 'dataApprovalWorkflows', 'programStages', 'categoryOptionGroups', 'relationshipTypes', 'validationRuleGroups', 'predictors', 'dataSets', 'options', 'organisationUnitLevels', 'dataEntryForms', 'predictorGroups', 'dataElementGroupSets', 'programIndicatorGroups', 'dataApprovalLevels', 'organisationUnits', 'programIndicators', 'dataElements', 'mapViews', 'categories', 'categoryOptionCombos', 'documents', 'indicators', 'optionSets', 'interpretations', 'programRuleActions', 'dataElementGroups', 'attributes', 'validationResults', 'categoryOptions', 'indicatorGroupSets', 'messageConversations', 'dashboards', 'programNotificationTemplates', 'programStageSections', 'legendSets', 'organisationUnitGroups', 'visualizations', 'indicatorGroups', 'programTrackedEntityAttributeGroups', 'programRules', 'categoryOptionGroupSets', 'userRoles', 'eventFilters', 'eventReports', 'eventCharts', 'smsCommands', 'jobConfigurations', 'minMaxDataElements', 'charts', 'dataElementOperands', // These exist and appear to accept field declarations, but have abnormal behavior when it comes to viewing collections and paging results
14
- 'trackedEntityInstance', 'relationships']; // Including non-normative resources listed under /api/resources for future follow-up
15
12
 
16
- exports.normativeMetadataResources = normativeMetadataResources;
17
- const nonNormativeMetadataResources = ['trackedEntityAttributeValues', 'programInstances', 'expressions', 'programStageInstances', 'externalFileResources', 'icons', 'fileResources', 'metadataVersions', 'dataStores', // This doesn't exist, but is listed as the plural of 'dataStore' in /api/resources
13
+ const normativeMetadataResources = exports.normativeMetadataResources = ['programDataElements', 'indicatorTypes', 'programs', 'optionGroups', 'programRuleVariables', 'reports', 'users', 'constants', 'externalMapLayers', 'analyticsTableHooks', 'pushAnalysis', 'oAuth2Clients', 'validationRules', 'reportTables', 'userGroups', 'sqlViews', 'sections', 'validationNotificationTemplates', 'optionGroupSets', 'organisationUnitGroupSets', 'trackedEntityAttributes', 'dashboardItems', 'categoryCombos', 'programSections', 'trackedEntityTypes', 'dataSetNotificationTemplates', 'maps', 'dataApprovalWorkflows', 'programStages', 'categoryOptionGroups', 'relationshipTypes', 'validationRuleGroups', 'predictors', 'dataSets', 'options', 'organisationUnitLevels', 'dataEntryForms', 'predictorGroups', 'dataElementGroupSets', 'programIndicatorGroups', 'dataApprovalLevels', 'organisationUnits', 'programIndicators', 'dataElements', 'mapViews', 'categories', 'categoryOptionCombos', 'documents', 'indicators', 'optionSets', 'interpretations', 'programRuleActions', 'dataElementGroups', 'attributes', 'validationResults', 'categoryOptions', 'indicatorGroupSets', 'messageConversations', 'dashboards', 'programNotificationTemplates', 'programStageSections', 'legendSets', 'organisationUnitGroups', 'visualizations', 'indicatorGroups', 'programTrackedEntityAttributeGroups', 'programRules', 'categoryOptionGroupSets', 'userRoles', 'eventFilters', 'eventReports', 'eventCharts', 'smsCommands', 'jobConfigurations', 'minMaxDataElements', 'charts', 'dataElementOperands',
14
+ // These exist and appear to accept field declarations, but have abnormal behavior when it comes to viewing collections and paging results
15
+ 'trackedEntityInstance', 'relationships'];
16
+
17
+ // Including non-normative resources listed under /api/resources for future follow-up
18
+ const nonNormativeMetadataResources = exports.nonNormativeMetadataResources = ['trackedEntityAttributeValues', 'programInstances', 'expressions', 'programStageInstances', 'externalFileResources', 'icons', 'fileResources', 'metadataVersions', 'dataStores',
19
+ // This doesn't exist, but is listed as the plural of 'dataStore' in /api/resources
20
+
18
21
  // Known but missing from /api/resources
19
- 'userDataStore', 'apps'];
20
- exports.nonNormativeMetadataResources = nonNormativeMetadataResources;
22
+ 'userDataStore', 'apps'];
@@ -4,14 +4,11 @@ Object.defineProperty(exports, "__esModule", {
4
4
  value: true
5
5
  });
6
6
  exports.joinPath = void 0;
7
-
8
7
  const joinPath = function () {
9
8
  for (var _len = arguments.length, parts = new Array(_len), _key = 0; _key < _len; _key++) {
10
9
  parts[_key] = arguments[_key];
11
10
  }
12
-
13
11
  const realParts = parts.filter(part => !!part);
14
12
  return realParts.map(part => part.replace(/^\/+|\/+$/g, '')).join('/');
15
13
  };
16
-
17
14
  exports.joinPath = joinPath;
@@ -1,7 +1,6 @@
1
1
  "use strict";
2
2
 
3
3
  var _path = require("./path");
4
-
5
4
  describe('Utils', () => {
6
5
  describe('pathJoin', () => {
7
6
  it('Should strip all leading and trailing slashes', () => {
@@ -4,12 +4,12 @@ Object.defineProperty(exports, "__esModule", {
4
4
  value: true
5
5
  });
6
6
  exports.isStaticContentUpload = exports.isMessageConversationAttachment = exports.isFileResourceUpload = exports.isDataValue = exports.isAppInstall = void 0;
7
-
8
7
  /*
9
8
  * Requests that expect a "multipart/form-data" Content-Type have been collected by scanning
10
9
  * the developer documentation:
11
10
  * https://docs.dhis2.org/master/en/developer/html/dhis2_developer_manual_full.html
12
11
  */
12
+
13
13
  // Post to 'dataValues' (send/update a data value; endpoint doesn't support JSON)
14
14
  // For file-uploads too
15
15
  const isDataValue = (type, _ref) => {
@@ -17,47 +17,42 @@ const isDataValue = (type, _ref) => {
17
17
  resource
18
18
  } = _ref;
19
19
  return type === 'create' && (resource === 'dataValues' || resource === 'dataValues/file');
20
- }; // POST to 'fileResources' (upload a file resource)
21
-
20
+ };
22
21
 
22
+ // POST to 'fileResources' (upload a file resource)
23
23
  exports.isDataValue = isDataValue;
24
-
25
24
  const isFileResourceUpload = (type, _ref2) => {
26
25
  let {
27
26
  resource
28
27
  } = _ref2;
29
28
  return type === 'create' && resource === 'fileResources';
30
- }; // POST to 'messageConversations/attachments' (upload a message conversation attachment)
31
-
29
+ };
32
30
 
31
+ // POST to 'messageConversations/attachments' (upload a message conversation attachment)
33
32
  exports.isFileResourceUpload = isFileResourceUpload;
34
-
35
33
  const isMessageConversationAttachment = (type, _ref3) => {
36
34
  let {
37
35
  resource
38
36
  } = _ref3;
39
37
  return type === 'create' && resource === 'messageConversations/attachments';
40
- }; // POST to `staticContent/${key}` (upload staticContent: logo_banner | logo_front)
41
-
38
+ };
42
39
 
40
+ // POST to `staticContent/${key}` (upload staticContent: logo_banner | logo_front)
43
41
  exports.isMessageConversationAttachment = isMessageConversationAttachment;
44
-
45
42
  const isStaticContentUpload = (type, _ref4) => {
46
43
  let {
47
44
  resource
48
45
  } = _ref4;
49
46
  const pattern = /^staticContent\/(?:logo_banner|logo_front)$/;
50
47
  return type === 'create' && pattern.test(resource);
51
- }; // POST to 'apps' (install an app)
52
-
48
+ };
53
49
 
50
+ // POST to 'apps' (install an app)
54
51
  exports.isStaticContentUpload = isStaticContentUpload;
55
-
56
52
  const isAppInstall = (type, _ref5) => {
57
53
  let {
58
54
  resource
59
55
  } = _ref5;
60
56
  return type === 'create' && resource === 'apps';
61
57
  };
62
-
63
58
  exports.isAppInstall = isAppInstall;
@@ -1,7 +1,6 @@
1
1
  "use strict";
2
2
 
3
3
  var _multipartFormDataMatchers = require("./multipartFormDataMatchers");
4
-
5
4
  describe('isDataValue', () => {
6
5
  it('returns true for a POST to "dataValues"', () => {
7
6
  expect((0, _multipartFormDataMatchers.isDataValue)('create', {
@@ -4,63 +4,44 @@ Object.defineProperty(exports, "__esModule", {
4
4
  value: true
5
5
  });
6
6
  exports.requestHeadersForContentType = exports.requestContentType = exports.requestBodyForContentType = void 0;
7
-
8
7
  var multipartFormDataMatchers = _interopRequireWildcard(require("./multipartFormDataMatchers"));
9
-
10
8
  var textPlainMatchers = _interopRequireWildcard(require("./textPlainMatchers"));
11
-
12
9
  var xWwwFormUrlencodedMatchers = _interopRequireWildcard(require("./xWwwFormUrlencodedMatchers"));
13
-
14
- function _getRequireWildcardCache() { if (typeof WeakMap !== "function") return null; var cache = new WeakMap(); _getRequireWildcardCache = function () { return cache; }; return cache; }
15
-
16
- function _interopRequireWildcard(obj) { if (obj && obj.__esModule) { return obj; } if (obj === null || typeof obj !== "object" && typeof obj !== "function") { return { default: obj }; } var cache = _getRequireWildcardCache(); if (cache && cache.has(obj)) { return cache.get(obj); } var newObj = {}; var hasPropertyDescriptor = Object.defineProperty && Object.getOwnPropertyDescriptor; for (var key in obj) { if (Object.prototype.hasOwnProperty.call(obj, key)) { var desc = hasPropertyDescriptor ? Object.getOwnPropertyDescriptor(obj, key) : null; if (desc && (desc.get || desc.set)) { Object.defineProperty(newObj, key, desc); } else { newObj[key] = obj[key]; } } } newObj.default = obj; if (cache) { cache.set(obj, newObj); } return newObj; }
17
-
10
+ function _getRequireWildcardCache(e) { if ("function" != typeof WeakMap) return null; var r = new WeakMap(), t = new WeakMap(); return (_getRequireWildcardCache = function (e) { return e ? t : r; })(e); }
11
+ function _interopRequireWildcard(e, r) { if (!r && e && e.__esModule) return e; if (null === e || "object" != typeof e && "function" != typeof e) return { default: e }; var t = _getRequireWildcardCache(r); if (t && t.has(e)) return t.get(e); var n = { __proto__: null }, a = Object.defineProperty && Object.getOwnPropertyDescriptor; for (var u in e) if ("default" !== u && {}.hasOwnProperty.call(e, u)) { var i = a ? Object.getOwnPropertyDescriptor(e, u) : null; i && (i.get || i.set) ? Object.defineProperty(n, u, i) : n[u] = e[u]; } return n.default = e, t && t.set(e, n), n; }
18
12
  const resourceExpectsTextPlain = (type, query) => Object.values(textPlainMatchers).some(textPlainMatcher => textPlainMatcher(type, query));
19
-
20
13
  const resourceExpectsMultipartFormData = (type, query) => Object.values(multipartFormDataMatchers).some(multipartFormDataMatcher => multipartFormDataMatcher(type, query));
21
-
22
14
  const resourceExpectsXWwwFormUrlencoded = (type, query) => Object.values(xWwwFormUrlencodedMatchers).some(xWwwFormUrlencodedMatcher => xWwwFormUrlencodedMatcher(type, query));
23
-
24
15
  const convertData = (data, initialValue) => {
25
16
  const dataEntries = Object.entries(data);
26
-
27
17
  if (dataEntries.length === 0) {
28
18
  throw new Error(`Could not convert data to ${initialValue.constructor.name}: object does not have own enumerable string-keyed properties`);
29
19
  }
30
-
31
20
  return dataEntries.reduce((convertedData, _ref) => {
32
21
  let [key, value] = _ref;
33
22
  convertedData.append(key, value);
34
23
  return convertedData;
35
24
  }, initialValue);
36
25
  };
37
-
38
26
  const requestContentType = (type, query) => {
39
27
  if (!query.data) {
40
28
  return null;
41
29
  }
42
-
43
30
  if (type === 'json-patch') {
44
31
  return 'application/json-patch+json';
45
32
  }
46
-
47
33
  if (resourceExpectsTextPlain(type, query)) {
48
34
  return 'text/plain';
49
35
  }
50
-
51
36
  if (resourceExpectsMultipartFormData(type, query)) {
52
37
  return 'multipart/form-data';
53
38
  }
54
-
55
39
  if (resourceExpectsXWwwFormUrlencoded(type, query)) {
56
40
  return 'application/x-www-form-urlencoded';
57
41
  }
58
-
59
42
  return 'application/json';
60
43
  };
61
-
62
44
  exports.requestContentType = requestContentType;
63
-
64
45
  const requestHeadersForContentType = contentType => {
65
46
  /*
66
47
  * Explicitely setting Content-Type to 'multipart/form-data' produces
@@ -72,37 +53,29 @@ const requestHeadersForContentType = contentType => {
72
53
  if (!contentType || contentType === 'multipart/form-data') {
73
54
  return undefined;
74
55
  }
75
-
76
56
  return {
77
57
  'Content-Type': contentType
78
58
  };
79
59
  };
80
-
81
60
  exports.requestHeadersForContentType = requestHeadersForContentType;
82
-
83
61
  const requestBodyForContentType = (contentType, _ref2) => {
84
62
  let {
85
63
  data
86
64
  } = _ref2;
87
-
88
65
  if (typeof data === 'undefined') {
89
66
  return undefined;
90
67
  }
91
-
92
68
  if (contentType === 'application/json' || contentType === 'application/json-patch+json') {
93
69
  return JSON.stringify(data);
94
70
  }
95
-
96
71
  if (contentType === 'multipart/form-data') {
97
72
  return convertData(data, new FormData());
98
73
  }
99
-
100
74
  if (contentType === 'application/x-www-form-urlencoded') {
101
75
  return convertData(data, new URLSearchParams());
102
- } // 'text/plain'
103
-
76
+ }
104
77
 
78
+ // 'text/plain'
105
79
  return data;
106
80
  };
107
-
108
81
  exports.requestBodyForContentType = requestBodyForContentType;
@@ -1,7 +1,6 @@
1
1
  "use strict";
2
2
 
3
3
  var _requestContentType = require("./requestContentType");
4
-
5
4
  describe('requestContentType', () => {
6
5
  it('returns "application/json" for a normal resource', () => {
7
6
  expect((0, _requestContentType.requestContentType)('create', {
@@ -4,7 +4,6 @@ Object.defineProperty(exports, "__esModule", {
4
4
  value: true
5
5
  });
6
6
  exports.isUpdateInterpretation = exports.isReplyToMessageConversation = exports.isMetadataPackageInstallation = exports.isInterpretationCommentUpdate = exports.isExpressionDescriptionValidation = exports.isCreateInterpretation = exports.isCreateFeedbackMessage = exports.isCommentOnInterpretation = exports.isAddOrUpdateSystemOrUserSetting = exports.addOrUpdateConfigurationProperty = void 0;
7
-
8
7
  /*
9
8
  * Requests that expect a "text/plain" Content-Type have been collected by scanning
10
9
  * the developer documentation:
@@ -15,6 +14,7 @@ exports.isUpdateInterpretation = exports.isReplyToMessageConversation = exports.
15
14
  * the resource property (string). If we decide to allow the `id` property for
16
15
  * "create" mutation-objects, we will have to include additional checks below.
17
16
  */
17
+
18
18
  // POST to `messageConversations/${id}` (reply to a messagConversation)
19
19
  const isReplyToMessageConversation = (type, _ref) => {
20
20
  let {
@@ -22,94 +22,81 @@ const isReplyToMessageConversation = (type, _ref) => {
22
22
  } = _ref;
23
23
  const pattern = /^messageConversations\/[a-zA-Z0-9]{11}$/;
24
24
  return type === 'create' && pattern.test(resource);
25
- }; // POST to 'messageConversations/feedback' (create a feedback message)
26
-
25
+ };
27
26
 
27
+ // POST to 'messageConversations/feedback' (create a feedback message)
28
28
  exports.isReplyToMessageConversation = isReplyToMessageConversation;
29
-
30
29
  const isCreateFeedbackMessage = (type, _ref2) => {
31
30
  let {
32
31
  resource
33
32
  } = _ref2;
34
33
  return type === 'create' && resource === 'messageConversations/feedback';
35
- }; // POST `interpretations/${objectType}/${id}` (add an interpretation to a visualization)
36
-
34
+ };
37
35
 
36
+ // POST `interpretations/${objectType}/${id}` (add an interpretation to a visualization)
38
37
  exports.isCreateFeedbackMessage = isCreateFeedbackMessage;
39
-
40
38
  const isCreateInterpretation = (type, _ref3) => {
41
39
  let {
42
40
  resource
43
41
  } = _ref3;
44
42
  const pattern = /^interpretations\/(?:reportTable|chart|visualization|map|eventVisualization|eventReport|eventChart|dataSetReport)\/[a-zA-Z0-9]{11}$/;
45
43
  return type === 'create' && pattern.test(resource);
46
- }; // PUT to `interpretations/${id}` (update an interpretation)
47
-
44
+ };
48
45
 
46
+ // PUT to `interpretations/${id}` (update an interpretation)
49
47
  exports.isCreateInterpretation = isCreateInterpretation;
50
-
51
48
  const isUpdateInterpretation = (type, _ref4) => {
52
49
  let {
53
50
  resource,
54
51
  id
55
52
  } = _ref4;
56
-
57
53
  if (type !== 'replace') {
58
54
  return false;
59
55
  }
60
-
61
56
  let resourcePattern;
62
-
63
57
  if (id) {
64
58
  resourcePattern = /^interpretations$/;
65
59
  const idPattern = /^[a-zA-Z0-9]{11}$/;
66
60
  return resourcePattern.test(resource) && idPattern.test(id);
67
61
  }
68
-
69
62
  resourcePattern = /^interpretations\/[a-zA-Z0-9]{11}$/;
70
63
  return resourcePattern.test(resource);
71
- }; // POST to `interpretations/${id}/comments` (comment on an interpretation)
72
-
64
+ };
73
65
 
66
+ // POST to `interpretations/${id}/comments` (comment on an interpretation)
74
67
  exports.isUpdateInterpretation = isUpdateInterpretation;
75
-
76
68
  const isCommentOnInterpretation = (type, _ref5) => {
77
69
  let {
78
70
  resource
79
71
  } = _ref5;
80
72
  const pattern = /^interpretations\/[a-zA-Z0-9]{11}\/comments$/;
81
73
  return type === 'create' && pattern.test(resource);
82
- }; // PUT to `interpretations/${interpretationId}/comments/${commentId}`
83
- // (update an interpretation comment)
84
-
74
+ };
85
75
 
76
+ // PUT to `interpretations/${interpretationId}/comments/${commentId}`
77
+ // (update an interpretation comment)
86
78
  exports.isCommentOnInterpretation = isCommentOnInterpretation;
87
-
88
79
  const isInterpretationCommentUpdate = (type, _ref6) => {
89
80
  let {
90
81
  resource,
91
82
  id
92
83
  } = _ref6;
93
-
94
84
  if (type !== 'replace') {
95
85
  return false;
96
86
  }
97
-
98
87
  if (id) {
99
88
  const idPatternLong = /^[a-zA-Z0-9]{11}\/comments\/[a-zA-Z0-9]{11}$/;
100
89
  const idPatternShort = /^[a-zA-Z0-9]{11}$/;
101
90
  const resourcePattern = /^interpretations\/[a-zA-Z0-9]{11}\/comments$/;
102
91
  return resource === 'interpretations' && idPatternLong.test(id) || resourcePattern.test(resource) && idPatternShort.test(id);
103
92
  }
104
-
105
93
  const pattern = /^interpretations\/[a-zA-Z0-9]{11}\/comments\/[a-zA-Z0-9]{11}$/;
106
94
  return pattern.test(resource);
107
- }; // POST to `systemSettings/${settingKey}` or `userSettings/${settingKey}`
108
- // (add or update a single system or user setting)
109
-
95
+ };
110
96
 
97
+ // POST to `systemSettings/${settingKey}` or `userSettings/${settingKey}`
98
+ // (add or update a single system or user setting)
111
99
  exports.isInterpretationCommentUpdate = isInterpretationCommentUpdate;
112
-
113
100
  const isAddOrUpdateSystemOrUserSetting = (type, _ref7) => {
114
101
  let {
115
102
  resource
@@ -117,12 +104,11 @@ const isAddOrUpdateSystemOrUserSetting = (type, _ref7) => {
117
104
  // At least 4 chars because the all start with 'key' (i.e. keyStyle)
118
105
  const pattern = /^(?:systemSettings|userSettings)\/[a-zA-Z]{4,}$/;
119
106
  return type === 'create' && pattern.test(resource);
120
- }; // POST to `configuration/${configurationProperty}`
121
- // (add or update a single configuration property)
122
-
107
+ };
123
108
 
109
+ // POST to `configuration/${configurationProperty}`
110
+ // (add or update a single configuration property)
124
111
  exports.isAddOrUpdateSystemOrUserSetting = isAddOrUpdateSystemOrUserSetting;
125
-
126
112
  const addOrUpdateConfigurationProperty = (type, _ref8) => {
127
113
  let {
128
114
  resource
@@ -131,21 +117,19 @@ const addOrUpdateConfigurationProperty = (type, _ref8) => {
131
117
  const pattern = /^(configuration)\/([a-zA-Z]{1,50})$/;
132
118
  const match = resource.match(pattern);
133
119
  return type === 'create' && !!match && match[2] !== 'corsWhitelist';
134
- }; // POST to 'synchronization/metadataPull' (install a metadata package)
135
-
120
+ };
136
121
 
122
+ // POST to 'synchronization/metadataPull' (install a metadata package)
137
123
  exports.addOrUpdateConfigurationProperty = addOrUpdateConfigurationProperty;
138
-
139
124
  const isMetadataPackageInstallation = (type, _ref9) => {
140
125
  let {
141
126
  resource
142
127
  } = _ref9;
143
128
  return type === 'create' && resource === 'synchronization/metadataPull';
144
- }; // POST to 'indicators/expression/description' or 'programIndicator/expression/description' (validate an expression)
145
-
129
+ };
146
130
 
131
+ // POST to 'indicators/expression/description' or 'programIndicator/expression/description' (validate an expression)
147
132
  exports.isMetadataPackageInstallation = isMetadataPackageInstallation;
148
-
149
133
  const isExpressionDescriptionValidation = (type, _ref10) => {
150
134
  let {
151
135
  resource
@@ -153,5 +137,4 @@ const isExpressionDescriptionValidation = (type, _ref10) => {
153
137
  const pattern = /^(indicators|programIndicators)\/expression\/description$/;
154
138
  return type === 'create' && pattern.test(resource);
155
139
  };
156
-
157
140
  exports.isExpressionDescriptionValidation = isExpressionDescriptionValidation;
@@ -1,7 +1,6 @@
1
1
  "use strict";
2
2
 
3
3
  var _textPlainMatchers = require("./textPlainMatchers");
4
-
5
4
  describe('isReplyToMessageConversation', () => {
6
5
  it('retuns true for POST to `messageConversations/${id}`', () => {
7
6
  expect((0, _textPlainMatchers.isReplyToMessageConversation)('create', {
@@ -4,7 +4,6 @@ Object.defineProperty(exports, "__esModule", {
4
4
  value: true
5
5
  });
6
6
  exports.isSvgConversion = void 0;
7
-
8
7
  // POST to convert an SVG file
9
8
  const isSvgConversion = (type, _ref) => {
10
9
  let {
@@ -12,5 +11,4 @@ const isSvgConversion = (type, _ref) => {
12
11
  } = _ref;
13
12
  return type === 'create' && (resource === 'svg.png' || resource === 'svg.pdf');
14
13
  };
15
-
16
14
  exports.isSvgConversion = isSvgConversion;
@@ -1,7 +1,6 @@
1
1
  "use strict";
2
2
 
3
3
  var _xWwwFormUrlencodedMatchers = require("./xWwwFormUrlencodedMatchers");
4
-
5
4
  describe('isSvgConversion', () => {
6
5
  it('returns true for a POST to "svg.png"', () => {
7
6
  expect((0, _xWwwFormUrlencodedMatchers.isSvgConversion)('create', {
@@ -4,32 +4,24 @@ Object.defineProperty(exports, "__esModule", {
4
4
  value: true
5
5
  });
6
6
  exports.queryToRequestOptions = void 0;
7
-
8
7
  var _requestContentType = require("./queryToRequestOptions/requestContentType");
9
-
10
8
  const getMethod = type => {
11
9
  switch (type) {
12
10
  case 'create':
13
11
  return 'POST';
14
-
15
12
  case 'read':
16
13
  return 'GET';
17
-
18
14
  case 'update':
19
15
  case 'json-patch':
20
16
  return 'PATCH';
21
-
22
17
  case 'replace':
23
18
  return 'PUT';
24
-
25
19
  case 'delete':
26
20
  return 'DELETE';
27
-
28
21
  default:
29
22
  throw new Error(`Unknown type ${type}`);
30
23
  }
31
24
  };
32
-
33
25
  const queryToRequestOptions = (type, query, signal) => {
34
26
  const contentType = (0, _requestContentType.requestContentType)(type, query);
35
27
  return {
@@ -39,5 +31,4 @@ const queryToRequestOptions = (type, query, signal) => {
39
31
  signal
40
32
  };
41
33
  };
42
-
43
34
  exports.queryToRequestOptions = queryToRequestOptions;
@@ -1,7 +1,6 @@
1
1
  "use strict";
2
2
 
3
3
  var _queryToRequestOptions = require("./queryToRequestOptions");
4
-
5
4
  describe('queryToRequestOptions', () => {
6
5
  it('should return a valid Fetch option object for read request', () => {
7
6
  const options = (0, _queryToRequestOptions.queryToRequestOptions)('read', {