@opentermsarchive/engine 0.26.1 → 0.27.1

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 (60) hide show
  1. package/README.md +1 -3
  2. package/bin/ota-track.js +3 -3
  3. package/bin/ota-validate.js +2 -2
  4. package/bin/ota.js +1 -1
  5. package/config/default.json +1 -1
  6. package/package.json +3 -4
  7. package/scripts/dataset/export/index.js +4 -4
  8. package/scripts/dataset/export/index.test.js +11 -17
  9. package/scripts/declarations/lint/index.mocha.js +1 -1
  10. package/scripts/declarations/utils/index.js +12 -12
  11. package/scripts/declarations/validate/definitions.js +1 -1
  12. package/scripts/declarations/validate/index.mocha.js +30 -34
  13. package/scripts/declarations/validate/service.history.schema.js +11 -11
  14. package/scripts/declarations/validate/service.schema.js +13 -13
  15. package/scripts/history/migrate-services.js +4 -4
  16. package/scripts/history/update-to-full-hash.js +2 -2
  17. package/scripts/import/index.js +14 -14
  18. package/scripts/rewrite/rewrite-snapshots.js +3 -3
  19. package/scripts/rewrite/rewrite-versions.js +14 -14
  20. package/scripts/utils/renamer/README.md +3 -3
  21. package/scripts/utils/renamer/index.js +13 -13
  22. package/src/archivist/errors.js +1 -1
  23. package/src/archivist/extract/exports.js +3 -0
  24. package/src/archivist/{filter → extract}/index.js +23 -27
  25. package/src/archivist/extract/index.test.js +516 -0
  26. package/src/archivist/index.js +101 -140
  27. package/src/archivist/index.test.js +178 -166
  28. package/src/archivist/recorder/index.js +11 -55
  29. package/src/archivist/recorder/index.test.js +310 -356
  30. package/src/archivist/recorder/record.js +18 -7
  31. package/src/archivist/recorder/repositories/git/dataMapper.js +41 -31
  32. package/src/archivist/recorder/repositories/git/index.js +11 -15
  33. package/src/archivist/recorder/repositories/git/index.test.js +1058 -463
  34. package/src/archivist/recorder/repositories/interface.js +8 -6
  35. package/src/archivist/recorder/repositories/mongo/dataMapper.js +21 -14
  36. package/src/archivist/recorder/repositories/mongo/index.js +8 -8
  37. package/src/archivist/recorder/repositories/mongo/index.test.js +898 -479
  38. package/src/archivist/recorder/snapshot.js +5 -0
  39. package/src/archivist/recorder/snapshot.test.js +65 -0
  40. package/src/archivist/recorder/version.js +14 -0
  41. package/src/archivist/recorder/version.test.js +65 -0
  42. package/src/archivist/services/index.js +60 -51
  43. package/src/archivist/services/index.test.js +63 -83
  44. package/src/archivist/services/service.js +26 -22
  45. package/src/archivist/services/service.test.js +46 -68
  46. package/src/archivist/services/{pageDeclaration.js → sourceDocument.js} +11 -9
  47. package/src/archivist/services/{pageDeclaration.test.js → sourceDocument.test.js} +21 -21
  48. package/src/archivist/services/terms.js +26 -0
  49. package/src/archivist/services/{documentDeclaration.test.js → terms.test.js} +15 -15
  50. package/src/exports.js +2 -2
  51. package/src/index.js +16 -13
  52. package/src/logger/index.js +35 -36
  53. package/src/notifier/index.js +8 -8
  54. package/src/tracker/index.js +6 -6
  55. package/src/archivist/filter/exports.js +0 -3
  56. package/src/archivist/filter/index.test.js +0 -564
  57. package/src/archivist/recorder/record.test.js +0 -91
  58. package/src/archivist/services/documentDeclaration.js +0 -26
  59. /package/scripts/utils/renamer/rules/{documentTypes.json → termsTypes.json} +0 -0
  60. /package/scripts/utils/renamer/rules/{documentTypesByService.json → termsTypesByService.json} +0 -0
package/src/index.js CHANGED
@@ -6,8 +6,11 @@ import logger from './logger/index.js';
6
6
  import Notifier from './notifier/index.js';
7
7
  import Tracker from './tracker/index.js';
8
8
 
9
- export default async function track({ services = [], termsTypes: documentTypes, refilterOnly, schedule }) {
10
- const archivist = new Archivist({ recorderConfig: config.get('recorder') });
9
+ export default async function track({ services, types, extractOnly, schedule }) {
10
+ const archivist = new Archivist({
11
+ recorderConfig: config.get('recorder'),
12
+ fetcherConfig: config.get('fetcher'),
13
+ });
11
14
 
12
15
  archivist.attach(logger);
13
16
 
@@ -15,11 +18,9 @@ export default async function track({ services = [], termsTypes: documentTypes,
15
18
 
16
19
  logger.info('Start Open Terms Archive\n');
17
20
 
18
- let serviceIds;
19
-
20
- if (services.length) {
21
- serviceIds = services.filter(serviceId => {
22
- const isServiceDeclared = archivist.serviceDeclarations[serviceId];
21
+ if (services?.length) {
22
+ services = services.filter(serviceId => {
23
+ const isServiceDeclared = archivist.services[serviceId];
23
24
 
24
25
  if (!isServiceDeclared) {
25
26
  logger.warn(`Parameter "${serviceId}" was interpreted as a service ID to update, but no matching declaration was found; it will be ignored`);
@@ -29,14 +30,16 @@ export default async function track({ services = [], termsTypes: documentTypes,
29
30
  });
30
31
  }
31
32
 
32
- await archivist.refilterAndRecord(serviceIds, documentTypes);
33
+ // The result of the extraction step that generates the version from the snapshots may depend on changes to the engine or its dependencies.
34
+ // The process thus starts by only performing the extraction process so that any version following such changes can be labelled (to avoid sending notifications, for example)
35
+ await archivist.track({ services, types, extractOnly: true });
33
36
 
34
- if (refilterOnly) {
37
+ if (extractOnly) {
35
38
  return;
36
39
  }
37
40
 
38
41
  if (process.env.NODE_ENV === 'production') {
39
- archivist.attach(new Notifier(archivist.serviceDeclarations));
42
+ archivist.attach(new Notifier(archivist.services));
40
43
  }
41
44
 
42
45
  if (process.env.GITHUB_TOKEN) {
@@ -47,13 +50,13 @@ export default async function track({ services = [], termsTypes: documentTypes,
47
50
  }
48
51
 
49
52
  if (!schedule) {
50
- await archivist.trackChanges(serviceIds, documentTypes);
53
+ await archivist.track({ services, types });
51
54
 
52
55
  return;
53
56
  }
54
57
 
55
58
  logger.info('The scheduler is running…');
56
- logger.info('Documents will be tracked every six hours starting at half past midnight');
59
+ logger.info('Terms will be tracked every six hours starting at half past midnight');
57
60
 
58
- cron('30 */6 * * *', () => archivist.trackChanges(serviceIds, documentTypes));
61
+ cron('30 */6 * * *', () => archivist.track({ services, types }));
59
62
  }
@@ -11,15 +11,15 @@ const { combine, timestamp, printf, colorize } = winston.format;
11
11
  const alignedWithColorsAndTime = combine(
12
12
  colorize(),
13
13
  timestamp({ format: 'YYYY-MM-DD HH:mm:ss' }),
14
- printf(({ level, message, timestamp, serviceId, type, pageId }) => {
14
+ printf(({ level, message, timestamp, serviceId, termsType, documentId }) => {
15
15
  let prefix = '';
16
16
 
17
- if (serviceId && type) {
18
- prefix = `${serviceId} — ${type}`;
17
+ if (serviceId && termsType) {
18
+ prefix = `${serviceId} — ${termsType}`;
19
19
  }
20
20
 
21
- if (pageId) {
22
- prefix = `${prefix}:${pageId}`;
21
+ if (documentId) {
22
+ prefix = `${prefix}:${documentId}`;
23
23
  }
24
24
 
25
25
  if (prefix.length > 75) {
@@ -71,61 +71,60 @@ const logger = winston.createLogger({
71
71
  rejectionHandlers: transports,
72
72
  });
73
73
 
74
- logger.onFirstSnapshotRecorded = (serviceId, type, pageId, snapshotId) => {
75
- logger.info({ message: `Recorded first snapshot with id ${snapshotId}`, serviceId, type, pageId });
74
+ logger.onFirstSnapshotRecorded = ({ serviceId, termsType, documentId, id }) => {
75
+ logger.info({ message: `Recorded first snapshot with id ${id}`, serviceId, termsType, documentId });
76
76
  recordedSnapshotsCount++;
77
77
  };
78
78
 
79
- logger.onSnapshotRecorded = (serviceId, type, pageId, snapshotId) => {
80
- logger.info({ message: `Recorded snapshot with id ${snapshotId}`, serviceId, type, pageId });
79
+ logger.onSnapshotRecorded = ({ serviceId, termsType, documentId, id }) => {
80
+ logger.info({ message: `Recorded snapshot with id ${id}`, serviceId, termsType, documentId });
81
81
  recordedSnapshotsCount++;
82
82
  };
83
83
 
84
- logger.onSnapshotNotChanged = (serviceId, type, pageId) => {
85
- logger.info({ message: 'No changes, did not record snapshot', serviceId, type, pageId });
84
+ logger.onSnapshotNotChanged = ({ serviceId, termsType, documentId }) => {
85
+ logger.info({ message: 'No changes, did not record snapshot', serviceId, termsType, documentId });
86
86
  };
87
87
 
88
- logger.onFirstVersionRecorded = (serviceId, type, versionId) => {
89
- logger.info({ message: `Recorded first version with id ${versionId}`, serviceId, type });
88
+ logger.onFirstVersionRecorded = ({ serviceId, termsType, id }) => {
89
+ logger.info({ message: `Recorded first version with id ${id}`, serviceId, termsType });
90
90
  recordedVersionsCount++;
91
91
  };
92
92
 
93
- logger.onVersionRecorded = (serviceId, type, versionId) => {
94
- logger.info({ message: `Recorded version with id ${versionId}`, serviceId, type });
93
+ logger.onVersionRecorded = ({ serviceId, termsType, id }) => {
94
+ logger.info({ message: `Recorded version with id ${id}`, serviceId, termsType });
95
95
  recordedVersionsCount++;
96
96
  };
97
97
 
98
- logger.onVersionNotChanged = (serviceId, type) => {
99
- logger.info({ message: 'No changes after filtering, did not record version', serviceId, type });
98
+ logger.onVersionNotChanged = ({ serviceId, termsType }) => {
99
+ logger.info({ message: 'No changes after filtering, did not record version', serviceId, termsType });
100
100
  };
101
101
 
102
- logger.onRefilteringStarted = (numberOfServices, numberOfDocuments) => {
103
- logger.info(`Examining ${numberOfDocuments} documents from ${numberOfServices} services for refiltering…`);
104
- recordedVersionsCount = 0;
105
- };
106
-
107
- logger.onRefilteringCompleted = (numberOfServices, numberOfDocuments) => {
108
- logger.info(`Examined ${numberOfDocuments} documents from ${numberOfServices} services for refiltering`);
109
- logger.info(`Recorded ${recordedVersionsCount} new versions\n`);
110
- };
111
-
112
- logger.onTrackingStarted = (numberOfServices, numberOfDocuments) => {
113
- logger.info(`Tracking changes of ${numberOfDocuments} documents from ${numberOfServices} services…`);
102
+ logger.onTrackingStarted = (numberOfServices, numberOfTerms, extractOnly) => {
103
+ if (extractOnly) {
104
+ logger.info(`Examining ${numberOfTerms} terms from ${numberOfServices} services for extraction…`);
105
+ } else {
106
+ logger.info(`Tracking changes of ${numberOfTerms} terms from ${numberOfServices} services…`);
107
+ }
114
108
  recordedSnapshotsCount = 0;
115
109
  recordedVersionsCount = 0;
116
110
  };
117
111
 
118
- logger.onTrackingCompleted = (numberOfServices, numberOfDocuments) => {
119
- logger.info(`Tracked changes of ${numberOfDocuments} documents from ${numberOfServices} services`);
120
- logger.info(`Recorded ${recordedSnapshotsCount} new snapshots and ${recordedVersionsCount} new versions\n`);
112
+ logger.onTrackingCompleted = (numberOfServices, numberOfTerms, extractOnly) => {
113
+ if (extractOnly) {
114
+ logger.info(`Examined ${numberOfTerms} terms from ${numberOfServices} services for extraction`);
115
+ logger.info(`Recorded ${recordedVersionsCount} new versions\n`);
116
+ } else {
117
+ logger.info(`Tracked changes of ${numberOfTerms} terms from ${numberOfServices} services`);
118
+ logger.info(`Recorded ${recordedSnapshotsCount} new snapshots and ${recordedVersionsCount} new versions\n`);
119
+ }
121
120
  };
122
121
 
123
- logger.onInaccessibleContent = ({ message }, serviceId, type) => {
124
- logger.warn({ message, serviceId, type });
122
+ logger.onInaccessibleContent = ({ message }, terms) => {
123
+ logger.warn({ message, serviceId: terms.serviceId, termsType: terms.type });
125
124
  };
126
125
 
127
- logger.onError = (error, serviceId, type, pageId) => {
128
- logger.error({ message: error.stack, serviceId, type, pageId });
126
+ logger.onError = (error, terms) => {
127
+ logger.error({ message: error.stack, serviceId: terms.serviceId, termsType: terms.type });
129
128
  };
130
129
 
131
130
  export default logger;
@@ -17,28 +17,28 @@ export default class Notifier {
17
17
  this.delayedVersionNotificationsParams = [];
18
18
  }
19
19
 
20
- async onVersionRecorded(serviceId, type, versionId) {
21
- this.delayedVersionNotificationsParams.push({ serviceId, type, versionId });
20
+ async onVersionRecorded(record) {
21
+ this.delayedVersionNotificationsParams.push(record);
22
22
  }
23
23
 
24
24
  async onTrackingCompleted() {
25
- this.delayedVersionNotificationsParams.forEach(async ({ serviceId, type, versionId }) => {
25
+ this.delayedVersionNotificationsParams.forEach(async ({ serviceId, termsType, id }) => {
26
26
  try {
27
- await this.notifyVersionRecorded(serviceId, type, versionId);
27
+ await this.notifyVersionRecorded(serviceId, termsType, id);
28
28
  } catch (error) {
29
- console.error(`The notification for version ${versionId} of ${serviceId} — ${type} can not be sent:`, error);
29
+ console.error(`The notification for version ${id} of ${serviceId} — ${termsType} can not be sent:`, error);
30
30
  }
31
31
  });
32
32
 
33
33
  this.delayedVersionNotificationsParams = [];
34
34
  }
35
35
 
36
- async notifyVersionRecorded(serviceProviderId, documentTypeId, versionId) {
36
+ async notifyVersionRecorded(serviceProviderId, termsType, versionId) {
37
37
  const sendParams = {
38
38
  templateId: config.get('notifier.sendInBlue.updateTemplateId'),
39
39
  params: {
40
40
  SERVICE_PROVIDER_NAME: this.serviceProviders[serviceProviderId].name,
41
- DOCUMENT_TYPE: documentTypeId,
41
+ DOCUMENT_TYPE: termsType,
42
42
  SHA: versionId,
43
43
  },
44
44
  };
@@ -47,7 +47,7 @@ export default class Notifier {
47
47
  config.get('notifier.sendInBlue.updatesListId'),
48
48
  ];
49
49
 
50
- const notificationListName = `${this.serviceProviders[serviceProviderId].name} - ${documentTypeId} - Update`;
50
+ const notificationListName = `${this.serviceProviders[serviceProviderId].name} - ${termsType} - Update`;
51
51
  const notificationList = await this.searchContactList(notificationListName);
52
52
 
53
53
  if (notificationList?.id) {
@@ -69,8 +69,8 @@ export default class Tracker {
69
69
  return this.onVersionRecorded(serviceId, type);
70
70
  }
71
71
 
72
- async onInaccessibleContent(error, serviceId, type, documentDeclaration) {
73
- const { title, body } = Tracker.formatIssueTitleAndBody({ message: error.toString(), repository: this.repository, documentDeclaration });
72
+ async onInaccessibleContent(error, serviceId, type, terms) {
73
+ const { title, body } = Tracker.formatIssueTitleAndBody({ message: error.toString(), repository: this.repository, terms });
74
74
 
75
75
  await this.createIssueIfNotExists({
76
76
  title,
@@ -179,9 +179,9 @@ export default class Tracker {
179
179
  }
180
180
  }
181
181
 
182
- static formatIssueTitleAndBody({ message, repository, documentDeclaration }) {
183
- const { service: { name }, type } = documentDeclaration;
184
- const json = documentDeclaration.toPersistence();
182
+ static formatIssueTitleAndBody({ message, repository, terms }) {
183
+ const { service: { name }, type } = terms;
184
+ const json = terms.toPersistence();
185
185
  const title = `Fix ${name} - ${type}`;
186
186
 
187
187
  const encodedName = encodeURIComponent(name);
@@ -195,7 +195,7 @@ export default class Tracker {
195
195
  });
196
196
 
197
197
  const body = `
198
- This document is no longer properly tracked.
198
+ These terms are no longer tracked.
199
199
 
200
200
  ${message}
201
201
 
@@ -1,3 +0,0 @@
1
- import filter from './index.js';
2
-
3
- export default filter;