@hestia-earth/api 0.21.13 → 0.22.0

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.
@@ -5,31 +5,28 @@ export declare enum EarthEngineCallType {
5
5
  }
6
6
  export declare enum EarthEngineType {
7
7
  raster = "raster",
8
- raster_by_period = "raster_by_period",
9
8
  vector = "vector"
10
9
  }
11
10
  export interface IEarthEngineParams {
12
- collection: string;
13
11
  ee_type: EarthEngineType;
12
+ collection: string;
13
+ band_name?: string;
14
14
  fields?: string;
15
15
  reducer?: string;
16
- scale?: number;
16
+ reducer_by_period?: string;
17
17
  year?: number;
18
18
  start_date?: string;
19
19
  end_date?: string;
20
- band_name?: string;
21
20
  force?: boolean;
22
21
  }
23
22
  export interface IEarthEngineParamsBoundary extends IEarthEngineParams {
24
23
  boundary: any;
25
- max_area?: number;
26
24
  }
27
25
  export interface IEarthEngineParamsCoordinates extends IEarthEngineParams {
28
26
  latitude: number;
29
27
  longitude: number;
30
28
  }
31
29
  export interface IEarthEngineParamsGadm extends IEarthEngineParams {
32
- gadm_id?: string;
33
- max_area?: number;
30
+ 'gadm-ids': string[];
34
31
  }
35
32
  export type earthEngineParams = IEarthEngineParamsBoundary | IEarthEngineParamsCoordinates | IEarthEngineParamsGadm;
@@ -10,6 +10,5 @@ var EarthEngineCallType;
10
10
  var EarthEngineType;
11
11
  (function (EarthEngineType) {
12
12
  EarthEngineType["raster"] = "raster";
13
- EarthEngineType["raster_by_period"] = "raster_by_period";
14
13
  EarthEngineType["vector"] = "vector";
15
14
  })(EarthEngineType = exports.EarthEngineType || (exports.EarthEngineType = {}));
@@ -32,6 +32,7 @@ export declare enum FileProgress {
32
32
  validateHestia = "validateHestia",
33
33
  validateData = "validateData",
34
34
  copyHestia = "copyHestia",
35
+ processJson = "processJson",
35
36
  indexJson = "indexJson"
36
37
  }
37
38
  export declare enum FileStatus {
@@ -44,6 +45,7 @@ export declare enum FileStatus {
44
45
  validateHestiaDone = "validateHestiaDone",
45
46
  validateDataDone = "validateDataDone",
46
47
  copyHestiaDone = "copyHestiaDone",
48
+ processJsonDone = "processJsonDone",
47
49
  indexJsonDone = "indexJsonDone"
48
50
  }
49
51
  export declare enum FileError {
@@ -56,6 +58,7 @@ export declare enum FileError {
56
58
  validateHestiaError = "validateHestiaError",
57
59
  validateDataError = "validateDataError",
58
60
  copyHestiaError = "copyHestiaError",
61
+ processJsonError = "processJsonError",
59
62
  indexJsonError = "indexJsonError"
60
63
  }
61
64
  export type status = FileStatus | FileProgress | FileError;
@@ -52,10 +52,7 @@ var maxFileSizeExt = (_a = {},
52
52
  _a);
53
53
  var maxFileSizeByFile = function (filename) { return maxFileSizeExt[(0, exports.fileExt)(filename).replace('.', '')]; };
54
54
  exports.maxFileSizeByFile = maxFileSizeByFile;
55
- exports.finalFormatExtensions = [
56
- SupportedExtensions.json,
57
- SupportedExtensions.csv
58
- ];
55
+ exports.finalFormatExtensions = [SupportedExtensions.json, SupportedExtensions.csv];
59
56
  var HestiaExtensions;
60
57
  (function (HestiaExtensions) {
61
58
  HestiaExtensions["nodes"] = "hestia";
@@ -76,6 +73,7 @@ var FileProgress;
76
73
  FileProgress["validateHestia"] = "validateHestia";
77
74
  FileProgress["validateData"] = "validateData";
78
75
  FileProgress["copyHestia"] = "copyHestia";
76
+ FileProgress["processJson"] = "processJson";
79
77
  FileProgress["indexJson"] = "indexJson";
80
78
  })(FileProgress = exports.FileProgress || (exports.FileProgress = {}));
81
79
  var FileStatus;
@@ -89,6 +87,7 @@ var FileStatus;
89
87
  FileStatus["validateHestiaDone"] = "validateHestiaDone";
90
88
  FileStatus["validateDataDone"] = "validateDataDone";
91
89
  FileStatus["copyHestiaDone"] = "copyHestiaDone";
90
+ FileStatus["processJsonDone"] = "processJsonDone";
92
91
  FileStatus["indexJsonDone"] = "indexJsonDone";
93
92
  })(FileStatus = exports.FileStatus || (exports.FileStatus = {}));
94
93
  var FileError;
@@ -102,6 +101,7 @@ var FileError;
102
101
  FileError["validateHestiaError"] = "validateHestiaError";
103
102
  FileError["validateDataError"] = "validateDataError";
104
103
  FileError["copyHestiaError"] = "copyHestiaError";
104
+ FileError["processJsonError"] = "processJsonError";
105
105
  FileError["indexJsonError"] = "indexJsonError";
106
106
  })(FileError = exports.FileError || (exports.FileError = {}));
107
107
  var FilePipelineStatus;
@@ -165,9 +165,14 @@ exports.fileExt = fileExt;
165
165
  var fileToExt = function (path, extension) {
166
166
  if (extension === void 0) { extension = ''; }
167
167
  return [
168
- path.replace(".".concat((0, exports.fileExt)(path)), '').replace(/^\./g, '').replace(/\.$/g, ''),
168
+ path
169
+ .replace(".".concat((0, exports.fileExt)(path)), '')
170
+ .replace(/^\./g, '')
171
+ .replace(/\.$/g, ''),
169
172
  (extension || '').replace(/[.]/g, '')
170
- ].filter(Boolean).join('.');
173
+ ]
174
+ .filter(Boolean)
175
+ .join('.');
171
176
  };
172
177
  exports.fileToExt = fileToExt;
173
178
  var filenameWithoutExt = function (filepath) {
@@ -184,27 +189,24 @@ var replaceInvalidChars = function (value) {
184
189
  ? (0, exports.filenameWithoutExt)(value)
185
190
  .replace(/(\.|\_)$/g, '')
186
191
  .replace(new RegExp("[^".concat(exports.validPathChars, "]"), 'g'), '_')
187
- .replace(new RegExp(Object.values(SupportedExtensions).map(function (v) { return "(_".concat(v, ")"); }).join('|'), 'g'), '')
192
+ .replace(new RegExp(Object.values(SupportedExtensions)
193
+ .map(function (v) { return "(_".concat(v, ")"); })
194
+ .join('|'), 'g'), '')
188
195
  .replace(/[\_]{2,}/g, '_')
189
196
  .replace(/(\.|\_)$/g, '')
190
197
  : null;
191
198
  return newFilename
192
199
  ? (value === null || value === void 0 ? void 0 : value.includes('.'))
193
- ? [
194
- (0, exports.normalizeFolder)(folder),
195
- (0, exports.fileToExt)(newFilename, (0, exports.fileExt)(value))
196
- ].filter(Boolean).join('/')
200
+ ? [(0, exports.normalizeFolder)(folder), (0, exports.fileToExt)(newFilename, (0, exports.fileExt)(value))].filter(Boolean).join('/')
197
201
  : newFilename
198
202
  : value;
199
203
  };
200
204
  exports.replaceInvalidChars = replaceInvalidChars;
201
205
  var normalizeFolder = function (folder) {
202
- return folder
203
- .replace(new RegExp("[^".concat(exports.validPathChars, "]"), 'g'), '_')
204
- .replace(/[\_]{2,}/g, '_');
206
+ return folder.replace(new RegExp("[^".concat(exports.validPathChars, "]"), 'g'), '_').replace(/[\_]{2,}/g, '_');
205
207
  };
206
208
  exports.normalizeFolder = normalizeFolder;
207
- var folderFromPath = function (path) { return (path === null || path === void 0 ? void 0 : path.includes('.')) ? path.split('/').slice(0, -1).join('/') : path; };
209
+ var folderFromPath = function (path) { return ((path === null || path === void 0 ? void 0 : path.includes('.')) ? path.split('/').slice(0, -1).join('/') : path); };
208
210
  exports.folderFromPath = folderFromPath;
209
211
  var rootFolderFromPath = function (path) { return path.split('/')[0]; };
210
212
  exports.rootFolderFromPath = rootFolderFromPath;
@@ -225,16 +227,10 @@ var isAggregation = function (path) { return (0, exports.rootFolderFromPath)(pat
225
227
  exports.isAggregation = isAggregation;
226
228
  var isFolderUpload = function (path, termsOnly) {
227
229
  if (termsOnly === void 0) { termsOnly = false; }
228
- return __spreadArray([
229
- exports.isGlossary,
230
- exports.isTerm
231
- ], (termsOnly ? [] : [
232
- exports.isAggregation,
233
- exports.isReconciliation
234
- ]), true).some(function (f) { return f(path); });
230
+ return __spreadArray([exports.isGlossary, exports.isTerm], (termsOnly ? [] : [exports.isAggregation, exports.isReconciliation]), true).some(function (f) { return f(path); });
235
231
  };
236
232
  exports.isFolderUpload = isFolderUpload;
237
- var asString = function (v) { var _a, _b; return typeof v === 'object' ? ((_a = v === null || v === void 0 ? void 0 : v._id) === null || _a === void 0 ? void 0 : _a.toString()) || ((_b = v === null || v === void 0 ? void 0 : v.id) === null || _b === void 0 ? void 0 : _b.toString()) : v === null || v === void 0 ? void 0 : v.toString(); };
233
+ var asString = function (v) { var _a, _b; return (typeof v === 'object' ? ((_a = v === null || v === void 0 ? void 0 : v._id) === null || _a === void 0 ? void 0 : _a.toString()) || ((_b = v === null || v === void 0 ? void 0 : v.id) === null || _b === void 0 ? void 0 : _b.toString()) : v === null || v === void 0 ? void 0 : v.toString()); };
238
234
  var isOwner = function (file, user) { return asString(file === null || file === void 0 ? void 0 : file.user) === asString(user); };
239
235
  exports.isOwner = isOwner;
240
236
  var isAuthorized = function (_a, user) {
@@ -247,21 +243,10 @@ var isAssigned = function (_a, user) {
247
243
  return (assignedUsers || []).map(asString).includes(asString(user));
248
244
  };
249
245
  exports.isAssigned = isAssigned;
250
- var canRemove = function (file, user) {
251
- return (0, model_1.isAdmin)(user) ||
252
- !(0, exports.isValidated)(file) ||
253
- file.isPrivate;
254
- };
246
+ var canRemove = function (file, user) { return (0, model_1.isAdmin)(user) || !(0, exports.isValidated)(file) || file.isPrivate; };
255
247
  exports.canRemove = canRemove;
256
- var validateStatuses = [
257
- FileStatus.validateDataDone,
258
- FileStatus.indexJsonDone,
259
- FileError.indexJsonError
260
- ];
261
- exports.validatedStatuses = [
262
- FileStatus.indexJsonDone,
263
- FileStatus.copyHestiaDone
264
- ];
248
+ var validateStatuses = [FileStatus.validateDataDone, FileStatus.indexJsonDone, FileError.indexJsonError];
249
+ exports.validatedStatuses = [FileStatus.copyHestiaDone, FileStatus.processJsonDone, FileStatus.indexJsonDone];
265
250
  var canValidate = function (_a, user) {
266
251
  var status = _a.status, isPrivate = _a.isPrivate, archived = _a.archived;
267
252
  return !archived && validateStatuses.includes(status) && (isPrivate || (0, model_1.isReviewer)(user));
@@ -269,17 +254,15 @@ var canValidate = function (_a, user) {
269
254
  exports.canValidate = canValidate;
270
255
  var isValidated = function (_a) {
271
256
  var validatedAt = _a.validatedAt, status = _a.status;
272
- return !!validatedAt ||
273
- exports.validatedStatuses.includes(status);
257
+ return !!validatedAt || exports.validatedStatuses.includes(status);
274
258
  };
275
259
  exports.isValidated = isValidated;
276
- var submitStatuses = [
277
- FileStatus.validateDataDone
278
- ];
260
+ var submitStatuses = [FileStatus.validateDataDone];
279
261
  var canSubmit = function (file, user) {
280
262
  return !file.archived &&
281
263
  submitStatuses.includes(file.status) &&
282
- !file.userValidatedAt && ((0, exports.isOwner)(file, user) || (0, exports.isAuthorized)(file, user));
264
+ !file.userValidatedAt &&
265
+ ((0, exports.isOwner)(file, user) || (0, exports.isAuthorized)(file, user));
283
266
  };
284
267
  exports.canSubmit = canSubmit;
285
268
  var feedbackStatuses = [
@@ -37,11 +37,7 @@ var DataState;
37
37
  })(DataState = exports.DataState || (exports.DataState = {}));
38
38
  exports.dataStatesTypeMapping = (_a = {},
39
39
  _a[DataState.original] = Object.values(schema_1.NodeType),
40
- _a[DataState.recalculated] = [
41
- schema_1.NodeType.Cycle,
42
- schema_1.NodeType.ImpactAssessment,
43
- schema_1.NodeType.Site
44
- ],
40
+ _a[DataState.recalculated] = [schema_1.NodeType.Cycle, schema_1.NodeType.ImpactAssessment, schema_1.NodeType.Site],
45
41
  _a[DataState.aggregated] = [],
46
42
  _a);
47
43
  var allowedDataStates = function (type) {
@@ -52,10 +48,9 @@ var pathWithState = function (type, id, dataState, strictDataState) {
52
48
  if (dataState === void 0) { dataState = DataState.original; }
53
49
  if (strictDataState === void 0) { strictDataState = false; }
54
50
  var state = exports.dataStatesTypeMapping[dataState].includes(type) ? dataState : null;
55
- return (state !== null || !strictDataState) ? [
56
- state === DataState.original ? null : state,
57
- (0, schema_1.jsonldPath)(type, id)
58
- ].filter(Boolean).join('/') : null;
51
+ return state !== null || !strictDataState
52
+ ? [state === DataState.original ? null : state, (0, schema_1.jsonldPath)(type, id)].filter(Boolean).join('/')
53
+ : null;
59
54
  };
60
55
  exports.pathWithState = pathWithState;
61
56
  var nodeTypeToParam = function (type) { return "".concat((type || '').toLowerCase(), "s"); };
@@ -87,7 +82,8 @@ var missingLookupPrefix = 'Missing lookup';
87
82
  var parseLookup = function (_a) {
88
83
  var column = _a.column, termid = _a.termid, _b = missingLookupPrefix, missingLookup = _a[_b];
89
84
  return ({
90
- filename: parseFilename(missingLookup), termId: termid,
85
+ filename: parseFilename(missingLookup),
86
+ termId: termid,
91
87
  column: column
92
88
  });
93
89
  };
@@ -97,12 +93,14 @@ var parseLogMissingLookups = function (data) {
97
93
  return (0, utils_1.unique)(messages.map(parseLookup));
98
94
  };
99
95
  exports.parseLogMissingLookups = parseLogMissingLookups;
100
- var mapTypeToId = function (nodes) { return nodes.reduce(function (prev, _a) {
101
- var type = _a["@type"], id = _a["@id"];
102
- prev[type] = prev[type] || [];
103
- prev[type].push(id);
104
- return prev;
105
- }, {}); };
96
+ var mapTypeToId = function (nodes) {
97
+ return nodes.reduce(function (prev, _a) {
98
+ var type = _a["@type"], id = _a["@id"];
99
+ prev[type] = prev[type] || [];
100
+ prev[type].push(id);
101
+ return prev;
102
+ }, {});
103
+ };
106
104
  var formatForUpload = function (nodes, typeToId, schemas) {
107
105
  if (typeToId === void 0) { typeToId = mapTypeToId(nodes); }
108
106
  if (schemas === void 0) { schemas = (0, json_schema_1.loadSchemas)(); }
@@ -111,11 +109,13 @@ var formatForUpload = function (nodes, typeToId, schemas) {
111
109
  var type = _a["@type"], id = _a["@id"], node = __rest(_a, ['@type', '@id']);
112
110
  return type === schema_1.NodeType.Term
113
111
  ? { '@type': type, '@id': id }
114
- : (0, utils_1.reduceUndefinedValues)(__assign(__assign({}, (!id || ((_b = typeToId[type]) !== null && _b !== void 0 ? _b : []).includes(id) ? { type: type, id: id } : { '@type': type, '@id': id })), Object.fromEntries(Object.entries(node).filter(function (_a) {
112
+ : (0, utils_1.reduceUndefinedValues)(__assign(__assign({}, (!id || ((_b = typeToId[type]) !== null && _b !== void 0 ? _b : []).includes(id) ? { type: type, id: id } : { '@type': type, '@id': id })), Object.fromEntries(Object.entries(node)
113
+ .filter(function (_a) {
115
114
  var _b, _c, _d;
116
115
  var key = _a[0];
117
116
  return !((_d = (_c = (_b = schemas === null || schemas === void 0 ? void 0 : schemas[type]) === null || _b === void 0 ? void 0 : _b.properties) === null || _c === void 0 ? void 0 : _c[key]) === null || _d === void 0 ? void 0 : _d.internal);
118
- }).map(function (_a) {
117
+ })
118
+ .map(function (_a) {
119
119
  var key = _a[0], value = _a[1];
120
120
  var newValue = (0, schema_1.isExpandable)(value)
121
121
  ? Array.isArray(value)
@@ -78,7 +78,9 @@ var validateProductCorrespondence = function (expectedProducts, recalculatedProd
78
78
  .map(function (_a) {
79
79
  var products = _a[0], errorType = _a[1];
80
80
  return products.length
81
- ? "Cycle ".concat(idRecalculated, " has ").concat(errorType, " impact assessment for products: ").concat(products.map(function (p) { return p['@id']; }).join(', '))
81
+ ? "Cycle ".concat(idRecalculated, " has ").concat(errorType, " impact assessment for products: ").concat(products
82
+ .map(function (p) { return p['@id']; })
83
+ .join(', '))
82
84
  : null;
83
85
  })
84
86
  .filter(Boolean);
@@ -64,19 +64,12 @@ var isAdmin = function (_a) {
64
64
  exports.isAdmin = isAdmin;
65
65
  var isReviewer = function (_a) {
66
66
  var role = _a.role;
67
- return [
68
- UserRole.Reviewer,
69
- UserRole.Admin
70
- ].includes(role);
67
+ return [UserRole.Reviewer, UserRole.Admin].includes(role);
71
68
  };
72
69
  exports.isReviewer = isReviewer;
73
70
  var isDeveloper = function (_a) {
74
71
  var role = _a.role;
75
- return [
76
- UserRole.Developer,
77
- UserRole.Reviewer,
78
- UserRole.Admin
79
- ].includes(role);
72
+ return [UserRole.Developer, UserRole.Reviewer, UserRole.Admin].includes(role);
80
73
  };
81
74
  exports.isDeveloper = isDeveloper;
82
75
  var contains = function (users, user) { return users.some(function (u) { return u.email === user.email; }); };
@@ -86,9 +79,13 @@ exports.actorId = actorId;
86
79
  var jsonLDContext = function (type, domain) { return "".concat(domain, "/schema/").concat(type, ".jsonld"); };
87
80
  var addIfDefined = function (key, value) {
88
81
  var _a;
89
- return !!value ? (_a = {}, _a[key] = value, _a) : {};
82
+ return (!!value ? (_a = {}, _a[key] = value, _a) : {});
83
+ };
84
+ var profileData = function (user) {
85
+ return user.dataPrivate
86
+ ? {}
87
+ : __assign(__assign(__assign(__assign(__assign(__assign({ email: user.email, firstName: user.firstName, lastName: user.lastName, name: user.displayName || (0, exports.name)(user) }, addIfDefined('scopusID', user.scopusID)), addIfDefined('orcid', user.orcid)), addIfDefined('primaryInstitution', user.primaryInstitution)), addIfDefined('city', user.city)), addIfDefined('country', user.country ? { type: schema_1.NodeType.Term, name: user.country } : undefined)), addIfDefined('website', user.website ? { '@id': user.website } : undefined));
90
88
  };
91
- var profileData = function (user) { return (user.dataPrivate ? {} : __assign(__assign(__assign(__assign(__assign(__assign({ email: user.email, firstName: user.firstName, lastName: user.lastName, name: user.displayName || (0, exports.name)(user) }, addIfDefined('scopusID', user.scopusID)), addIfDefined('orcid', user.orcid)), addIfDefined('primaryInstitution', user.primaryInstitution)), addIfDefined('city', user.city)), addIfDefined('country', user.country ? { type: schema_1.NodeType.Term, name: user.country } : undefined)), addIfDefined('website', user.website ? { '@id': user.website } : undefined))); };
92
89
  var userToActor = function (user, domain) {
93
90
  if (domain === void 0) { domain = 'https://hestia.earth'; }
94
91
  return (__assign({ '@context': jsonLDContext(schema_1.NodeType.Actor, domain), '@type': schema_1.NodeType.Actor, '@id': (0, exports.actorId)(user), dataPrivate: user.dataPrivate }, profileData(user)));
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@hestia-earth/api",
3
- "version": "0.21.13",
3
+ "version": "0.22.0",
4
4
  "description": "Hestia API definitions",
5
5
  "main": "dist/models.js",
6
6
  "typings": "dist/models.d.ts",
@@ -39,7 +39,7 @@
39
39
  "@commitlint/cli": "^16.2.4",
40
40
  "@commitlint/config-conventional": "^16.2.4",
41
41
  "@elastic/elasticsearch": "7.13.0",
42
- "@hestia-earth/eslint-config": "^0.0.5",
42
+ "@hestia-earth/eslint-config": "^0.1.0",
43
43
  "@hestia-earth/schema-convert": "^21.0.0",
44
44
  "@hestia-earth/schema-validation": "^21.0.0",
45
45
  "@mendeley/api": "^10.0.2",
@@ -100,6 +100,7 @@
100
100
  "passport": "^0.4.1",
101
101
  "passport-google-oauth20": "^2.0.0",
102
102
  "passport-orcid": "0.0.4",
103
+ "prettier": "^3.0.3",
103
104
  "python-shell": "^2.0.3",
104
105
  "redis": "^3.1.2",
105
106
  "request": "^2.88.2",
@@ -121,5 +122,6 @@
121
122
  "hooks": {
122
123
  "commit-msg": "commitlint -E HUSKY_GIT_PARAMS"
123
124
  }
124
- }
125
+ },
126
+ "prettier": "@hestia-earth/eslint-config/prettier.json"
125
127
  }