@hestia-earth/api 0.19.2 → 0.20.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.
@@ -1,10 +1,9 @@
1
1
  import { ITermJSONLD } from '@hestia-earth/schema';
2
2
  import { BaseModel } from '../../db/model.base';
3
- export type analysisChangeType = 'increase' | 'decrease';
4
3
  export interface IAnalysisDetail {
5
4
  key: 'inputs' | 'products' | 'practices';
6
5
  grouping: string;
7
- type: analysisChangeType;
6
+ analysis: string;
8
7
  originalUrl?: string;
9
8
  recalculatedUrl?: string;
10
9
  }
@@ -13,13 +12,13 @@ export interface IAnalaysisIndicator {
13
12
  model: Partial<ITermJSONLD>;
14
13
  }
15
14
  export declare enum AnalysisType {
16
- quantity = "quantity"
15
+ quantity = "quantity",
16
+ term = "term"
17
17
  }
18
18
  export declare class Analysis extends BaseModel {
19
19
  cycleId: string;
20
20
  name: string;
21
21
  indicators: IAnalaysisIndicator[];
22
- readonly quantity?: IAnalysisDetail[];
23
22
  readonly cycle: {
24
23
  originalUrl: string;
25
24
  recalculatedUrl: string;
@@ -28,4 +27,6 @@ export declare class Analysis extends BaseModel {
28
27
  originalUrl: string;
29
28
  recalculatedUrl: string;
30
29
  };
30
+ readonly quantity?: IAnalysisDetail[];
31
+ readonly term?: IAnalysisDetail[];
31
32
  }
@@ -20,6 +20,7 @@ var model_base_1 = require("../../db/model.base");
20
20
  var AnalysisType;
21
21
  (function (AnalysisType) {
22
22
  AnalysisType["quantity"] = "quantity";
23
+ AnalysisType["term"] = "term";
23
24
  })(AnalysisType = exports.AnalysisType || (exports.AnalysisType = {}));
24
25
  var Analysis = (function (_super) {
25
26
  __extends(Analysis, _super);
@@ -2,7 +2,7 @@ import { BaseModel } from '../../db/model.base';
2
2
  import { User } from '../../users/model/model';
3
3
  export declare const mb = 1048576;
4
4
  export declare const sizeInMb: (size: number) => number;
5
- export declare const maxFileSizeMb = 50;
5
+ export declare const maxFileSizeMb = 100;
6
6
  export declare const maxFileSize: number;
7
7
  export declare enum SupportedExtensions {
8
8
  xlsx = "xlsx",
@@ -12,6 +12,7 @@ export declare enum SupportedExtensions {
12
12
  draft = "txt",
13
13
  pdf = "pdf"
14
14
  }
15
+ export declare const maxFileSizeByFile: (filename: string) => any;
15
16
  export declare const finalFormatExtensions: SupportedExtensions[];
16
17
  export declare enum HestiaExtensions {
17
18
  nodes = "hestia",
@@ -133,18 +134,20 @@ export declare const filepathSearch: (...parts: string[]) => {
133
134
  };
134
135
  };
135
136
  export declare const fileExt: (path: string) => string;
136
- export declare const fileToExt: (path: string, extension: string) => string;
137
+ export declare const fileToExt: (path: string, extension?: string) => string;
137
138
  export declare const filenameWithoutExt: (filename?: string) => string;
138
139
  export declare const validPathChars = "A-Za-z\\d.\\-_";
139
- export declare const replaceInvalidChars: (value: string) => string;
140
+ export declare const replaceInvalidChars: (value: string) => any;
140
141
  export declare const folderFromPath: (path: string) => string;
141
142
  export declare const rootFolderFromPath: (path: string) => string;
142
143
  export declare const filenameFromPath: (path: string) => string;
143
144
  export declare const analysesFolder = "analyses";
144
145
  export declare const glossaryFolder = "glossary";
146
+ export declare const termFolder = "term";
145
147
  export declare const reconciliationFolder = "reconciliation";
146
148
  export declare const isReconciliation: (path: string) => boolean;
147
149
  export declare const isGlossary: (path: string) => boolean;
150
+ export declare const isTerm: (path: string) => boolean;
148
151
  export declare const aggregationFolder = "aggregation";
149
152
  export declare const isAggregation: (path: string) => boolean;
150
153
  export declare const isFolderUpload: (path: string, termsOnly?: boolean) => boolean;
@@ -23,14 +23,15 @@ var __spreadArray = (this && this.__spreadArray) || function (to, from, pack) {
23
23
  }
24
24
  return to.concat(ar || Array.prototype.slice.call(from));
25
25
  };
26
+ var _a;
26
27
  Object.defineProperty(exports, "__esModule", { value: true });
27
- exports.canEditComment = exports.isDraft = exports.canFeedback = exports.canSubmit = exports.isValidated = exports.canValidate = exports.validatedStatuses = exports.canRemove = exports.isAssigned = exports.isAuthorized = exports.isOwner = exports.isFolderUpload = exports.isAggregation = exports.aggregationFolder = exports.isGlossary = exports.isReconciliation = exports.reconciliationFolder = exports.glossaryFolder = exports.analysesFolder = exports.filenameFromPath = exports.rootFolderFromPath = exports.folderFromPath = exports.replaceInvalidChars = exports.validPathChars = exports.filenameWithoutExt = exports.fileToExt = exports.fileExt = exports.filepathSearch = exports.filenameSearch = exports.File = exports.FilePipelineError = exports.FilePipelineProgress = exports.FilePipelineStatus = exports.FileError = exports.FileStatus = exports.FileProgress = exports.HestiaExtensions = exports.finalFormatExtensions = exports.SupportedExtensions = exports.maxFileSize = exports.maxFileSizeMb = exports.sizeInMb = exports.mb = void 0;
28
+ exports.canEditComment = exports.isDraft = exports.canFeedback = exports.canSubmit = exports.isValidated = exports.canValidate = exports.validatedStatuses = exports.canRemove = exports.isAssigned = exports.isAuthorized = exports.isOwner = exports.isFolderUpload = exports.isAggregation = exports.aggregationFolder = exports.isTerm = exports.isGlossary = exports.isReconciliation = exports.reconciliationFolder = exports.termFolder = exports.glossaryFolder = exports.analysesFolder = exports.filenameFromPath = exports.rootFolderFromPath = exports.folderFromPath = exports.replaceInvalidChars = exports.validPathChars = exports.filenameWithoutExt = exports.fileToExt = exports.fileExt = exports.filepathSearch = exports.filenameSearch = exports.File = exports.FilePipelineError = exports.FilePipelineProgress = exports.FilePipelineStatus = exports.FileError = exports.FileStatus = exports.FileProgress = exports.HestiaExtensions = exports.finalFormatExtensions = exports.maxFileSizeByFile = exports.SupportedExtensions = exports.maxFileSize = exports.maxFileSizeMb = exports.sizeInMb = exports.mb = void 0;
28
29
  var model_base_1 = require("../../db/model.base");
29
30
  var model_1 = require("../../users/model/model");
30
31
  exports.mb = 1048576;
31
32
  var sizeInMb = function (size) { return Math.round((size / exports.mb) * 1000) / 1000; };
32
33
  exports.sizeInMb = sizeInMb;
33
- exports.maxFileSizeMb = 50;
34
+ exports.maxFileSizeMb = 100;
34
35
  exports.maxFileSize = exports.maxFileSizeMb * exports.mb;
35
36
  var SupportedExtensions;
36
37
  (function (SupportedExtensions) {
@@ -41,6 +42,16 @@ var SupportedExtensions;
41
42
  SupportedExtensions["draft"] = "txt";
42
43
  SupportedExtensions["pdf"] = "pdf";
43
44
  })(SupportedExtensions = exports.SupportedExtensions || (exports.SupportedExtensions = {}));
45
+ var maxFileSizeExt = (_a = {},
46
+ _a[SupportedExtensions.csv] = exports.maxFileSize,
47
+ _a[SupportedExtensions.xlsx] = exports.maxFileSize / 2,
48
+ _a[SupportedExtensions.xls] = exports.maxFileSize / 2,
49
+ _a[SupportedExtensions.draft] = exports.maxFileSize,
50
+ _a[SupportedExtensions.json] = exports.maxFileSize,
51
+ _a[SupportedExtensions.pdf] = exports.maxFileSize / 2,
52
+ _a);
53
+ var maxFileSizeByFile = function (filename) { return maxFileSizeExt[(0, exports.fileExt)(filename).replace('.', '')]; };
54
+ exports.maxFileSizeByFile = maxFileSizeByFile;
44
55
  exports.finalFormatExtensions = [
45
56
  SupportedExtensions.json,
46
57
  SupportedExtensions.csv
@@ -145,10 +156,17 @@ var filepathSearch = function () {
145
156
  return fileNoExtSearch.apply(void 0, __spreadArray(['filepath'], parts, false));
146
157
  };
147
158
  exports.filepathSearch = filepathSearch;
148
- var fileExt = function (path) { return path.split('.').pop(); };
159
+ var fileExt = function (path) {
160
+ var paths = path === null || path === void 0 ? void 0 : path.split('.');
161
+ return paths.length > 1 ? paths.pop() : null;
162
+ };
149
163
  exports.fileExt = fileExt;
150
164
  var fileToExt = function (path, extension) {
151
- return [path.split('.')[0], extension.startsWith('.') ? extension.substring(1) : extension].join('.');
165
+ if (extension === void 0) { extension = ''; }
166
+ return [
167
+ path.replace((0, exports.fileExt)(path), '').replace(/^\./g, '').replace(/\.$/g, ''),
168
+ (extension || '').replace(/^\./g, '').replace(/\.$/g, '')
169
+ ].filter(Boolean).join('.');
152
170
  };
153
171
  exports.fileToExt = fileToExt;
154
172
  var filenameWithoutExt = function (filename) {
@@ -159,21 +177,26 @@ var filenameWithoutExt = function (filename) {
159
177
  exports.filenameWithoutExt = filenameWithoutExt;
160
178
  exports.validPathChars = 'A-Za-z\\d.\\-_';
161
179
  var replaceInvalidChars = function (value) {
162
- return value
163
- ? value
180
+ var folder = (0, exports.folderFromPath)(value);
181
+ var newFilename = value
182
+ ? (0, exports.filenameWithoutExt)(value)
164
183
  .replace(/\s/g, '_')
165
- .replace(/\.$/g, '')
184
+ .replace(/[\.\_]$/g, '')
166
185
  .replace(new RegExp("[^".concat(exports.validPathChars, "]"), 'g'), '')
167
- .replace(new RegExp("(\\.)[^(".concat(Object.values(SupportedExtensions).map(function (v) { return ".".concat(v); }).join('|'), ")]"), 'g'), function (v) { return v.replace('.', '_'); })
168
186
  .replace(/\^/g, '')
187
+ .replace(/\./g, '_')
169
188
  : null;
189
+ return newFilename
190
+ ? (value === null || value === void 0 ? void 0 : value.includes('.'))
191
+ ? [
192
+ (0, exports.replaceInvalidChars)(folder),
193
+ (0, exports.fileToExt)(newFilename, (0, exports.fileExt)(value))
194
+ ].filter(Boolean).join('/')
195
+ : newFilename
196
+ : value;
170
197
  };
171
198
  exports.replaceInvalidChars = replaceInvalidChars;
172
- var folderFromPath = function (path) {
173
- var folders = path.split('/');
174
- folders.pop();
175
- return folders.join('/');
176
- };
199
+ var folderFromPath = function (path) { return (path === null || path === void 0 ? void 0 : path.includes('.')) ? path.split('/').slice(0, -1).join('/') : path; };
177
200
  exports.folderFromPath = folderFromPath;
178
201
  var rootFolderFromPath = function (path) { return path.split('/')[0]; };
179
202
  exports.rootFolderFromPath = rootFolderFromPath;
@@ -181,12 +204,14 @@ var filenameFromPath = function (path) { return path.split('/').pop(); };
181
204
  exports.filenameFromPath = filenameFromPath;
182
205
  exports.analysesFolder = 'analyses';
183
206
  exports.glossaryFolder = 'glossary';
207
+ exports.termFolder = 'term';
184
208
  exports.reconciliationFolder = 'reconciliation';
185
209
  var isReconciliation = function (path) { return (0, exports.rootFolderFromPath)(path) === exports.reconciliationFolder; };
186
210
  exports.isReconciliation = isReconciliation;
187
211
  var isGlossary = function (path) { return (0, exports.rootFolderFromPath)(path) === exports.glossaryFolder; };
188
212
  exports.isGlossary = isGlossary;
189
- var isTerm = function (path) { return (0, exports.rootFolderFromPath)(path) === 'term'; };
213
+ var isTerm = function (path) { return (0, exports.rootFolderFromPath)(path) === exports.termFolder; };
214
+ exports.isTerm = isTerm;
190
215
  exports.aggregationFolder = 'aggregation';
191
216
  var isAggregation = function (path) { return (0, exports.rootFolderFromPath)(path) === exports.aggregationFolder; };
192
217
  exports.isAggregation = isAggregation;
@@ -194,7 +219,7 @@ var isFolderUpload = function (path, termsOnly) {
194
219
  if (termsOnly === void 0) { termsOnly = false; }
195
220
  return __spreadArray([
196
221
  exports.isGlossary,
197
- isTerm
222
+ exports.isTerm
198
223
  ], (termsOnly ? [] : [
199
224
  exports.isAggregation,
200
225
  exports.isReconciliation
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@hestia-earth/api",
3
- "version": "0.19.2",
3
+ "version": "0.20.0",
4
4
  "description": "Hestia API definitions",
5
5
  "main": "dist/models.js",
6
6
  "typings": "dist/models.d.ts",
@@ -30,7 +30,7 @@
30
30
  "author": "Guillaume Royer <guillaumeroyer.mail@gmail.com>",
31
31
  "license": "UNLICENSED",
32
32
  "dependencies": {
33
- "@hestia-earth/schema": ">=14.0.0",
33
+ "@hestia-earth/schema": ">=20.0.0",
34
34
  "@hestia-earth/utils": ">=0.11.2"
35
35
  },
36
36
  "devDependencies": {
@@ -38,9 +38,9 @@
38
38
  "@commitlint/config-conventional": "^16.2.4",
39
39
  "@elastic/elasticsearch": "7.13.0",
40
40
  "@hestia-earth/eslint-config": "^0.0.5",
41
- "@hestia-earth/json-schema": "^14.0.0",
42
- "@hestia-earth/schema-convert": "^14.0.0",
43
- "@hestia-earth/schema-validation": "^14.0.0",
41
+ "@hestia-earth/json-schema": "^20.0.0",
42
+ "@hestia-earth/schema-convert": "^20.0.0",
43
+ "@hestia-earth/schema-validation": "^20.0.0",
44
44
  "@mendeley/api": "^10.0.2",
45
45
  "@sentry/node": "^7.33.0",
46
46
  "@sentry/tracing": "^7.33.0",