@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.
- package/README.md +1 -3
- package/bin/ota-track.js +3 -3
- package/bin/ota-validate.js +2 -2
- package/bin/ota.js +1 -1
- package/config/default.json +1 -1
- package/package.json +3 -4
- package/scripts/dataset/export/index.js +4 -4
- package/scripts/dataset/export/index.test.js +11 -17
- package/scripts/declarations/lint/index.mocha.js +1 -1
- package/scripts/declarations/utils/index.js +12 -12
- package/scripts/declarations/validate/definitions.js +1 -1
- package/scripts/declarations/validate/index.mocha.js +30 -34
- package/scripts/declarations/validate/service.history.schema.js +11 -11
- package/scripts/declarations/validate/service.schema.js +13 -13
- package/scripts/history/migrate-services.js +4 -4
- package/scripts/history/update-to-full-hash.js +2 -2
- package/scripts/import/index.js +14 -14
- package/scripts/rewrite/rewrite-snapshots.js +3 -3
- package/scripts/rewrite/rewrite-versions.js +14 -14
- package/scripts/utils/renamer/README.md +3 -3
- package/scripts/utils/renamer/index.js +13 -13
- package/src/archivist/errors.js +1 -1
- package/src/archivist/extract/exports.js +3 -0
- package/src/archivist/{filter → extract}/index.js +23 -27
- package/src/archivist/extract/index.test.js +516 -0
- package/src/archivist/index.js +101 -140
- package/src/archivist/index.test.js +178 -166
- package/src/archivist/recorder/index.js +11 -55
- package/src/archivist/recorder/index.test.js +310 -356
- package/src/archivist/recorder/record.js +18 -7
- package/src/archivist/recorder/repositories/git/dataMapper.js +41 -31
- package/src/archivist/recorder/repositories/git/index.js +11 -15
- package/src/archivist/recorder/repositories/git/index.test.js +1058 -463
- package/src/archivist/recorder/repositories/interface.js +8 -6
- package/src/archivist/recorder/repositories/mongo/dataMapper.js +21 -14
- package/src/archivist/recorder/repositories/mongo/index.js +8 -8
- package/src/archivist/recorder/repositories/mongo/index.test.js +898 -479
- package/src/archivist/recorder/snapshot.js +5 -0
- package/src/archivist/recorder/snapshot.test.js +65 -0
- package/src/archivist/recorder/version.js +14 -0
- package/src/archivist/recorder/version.test.js +65 -0
- package/src/archivist/services/index.js +60 -51
- package/src/archivist/services/index.test.js +63 -83
- package/src/archivist/services/service.js +26 -22
- package/src/archivist/services/service.test.js +46 -68
- package/src/archivist/services/{pageDeclaration.js → sourceDocument.js} +11 -9
- package/src/archivist/services/{pageDeclaration.test.js → sourceDocument.test.js} +21 -21
- package/src/archivist/services/terms.js +26 -0
- package/src/archivist/services/{documentDeclaration.test.js → terms.test.js} +15 -15
- package/src/exports.js +2 -2
- package/src/index.js +16 -13
- package/src/logger/index.js +35 -36
- package/src/notifier/index.js +8 -8
- package/src/tracker/index.js +6 -6
- package/src/archivist/filter/exports.js +0 -3
- package/src/archivist/filter/index.test.js +0 -564
- package/src/archivist/recorder/record.test.js +0 -91
- package/src/archivist/services/documentDeclaration.js +0 -26
- /package/scripts/utils/renamer/rules/{documentTypes.json → termsTypes.json} +0 -0
- /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
|
|
10
|
-
const archivist = new Archivist({
|
|
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
|
-
|
|
19
|
-
|
|
20
|
-
|
|
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
|
-
|
|
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 (
|
|
37
|
+
if (extractOnly) {
|
|
35
38
|
return;
|
|
36
39
|
}
|
|
37
40
|
|
|
38
41
|
if (process.env.NODE_ENV === 'production') {
|
|
39
|
-
archivist.attach(new Notifier(archivist.
|
|
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.
|
|
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('
|
|
59
|
+
logger.info('Terms will be tracked every six hours starting at half past midnight');
|
|
57
60
|
|
|
58
|
-
cron('30 */6 * * *', () => archivist.
|
|
61
|
+
cron('30 */6 * * *', () => archivist.track({ services, types }));
|
|
59
62
|
}
|
package/src/logger/index.js
CHANGED
|
@@ -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,
|
|
14
|
+
printf(({ level, message, timestamp, serviceId, termsType, documentId }) => {
|
|
15
15
|
let prefix = '';
|
|
16
16
|
|
|
17
|
-
if (serviceId &&
|
|
18
|
-
prefix = `${serviceId} — ${
|
|
17
|
+
if (serviceId && termsType) {
|
|
18
|
+
prefix = `${serviceId} — ${termsType}`;
|
|
19
19
|
}
|
|
20
20
|
|
|
21
|
-
if (
|
|
22
|
-
prefix = `${prefix}:${
|
|
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,
|
|
75
|
-
logger.info({ message: `Recorded first snapshot with id ${
|
|
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,
|
|
80
|
-
logger.info({ message: `Recorded snapshot with id ${
|
|
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,
|
|
85
|
-
logger.info({ message: 'No changes, did not record snapshot', serviceId,
|
|
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,
|
|
89
|
-
logger.info({ message: `Recorded first version with id ${
|
|
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,
|
|
94
|
-
logger.info({ message: `Recorded version with id ${
|
|
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,
|
|
99
|
-
logger.info({ message: 'No changes after filtering, did not record version', serviceId,
|
|
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.
|
|
103
|
-
|
|
104
|
-
|
|
105
|
-
}
|
|
106
|
-
|
|
107
|
-
|
|
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,
|
|
119
|
-
|
|
120
|
-
|
|
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 },
|
|
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,
|
|
128
|
-
logger.error({ message: error.stack, serviceId, type
|
|
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;
|
package/src/notifier/index.js
CHANGED
|
@@ -17,28 +17,28 @@ export default class Notifier {
|
|
|
17
17
|
this.delayedVersionNotificationsParams = [];
|
|
18
18
|
}
|
|
19
19
|
|
|
20
|
-
async onVersionRecorded(
|
|
21
|
-
this.delayedVersionNotificationsParams.push(
|
|
20
|
+
async onVersionRecorded(record) {
|
|
21
|
+
this.delayedVersionNotificationsParams.push(record);
|
|
22
22
|
}
|
|
23
23
|
|
|
24
24
|
async onTrackingCompleted() {
|
|
25
|
-
this.delayedVersionNotificationsParams.forEach(async ({ serviceId,
|
|
25
|
+
this.delayedVersionNotificationsParams.forEach(async ({ serviceId, termsType, id }) => {
|
|
26
26
|
try {
|
|
27
|
-
await this.notifyVersionRecorded(serviceId,
|
|
27
|
+
await this.notifyVersionRecorded(serviceId, termsType, id);
|
|
28
28
|
} catch (error) {
|
|
29
|
-
console.error(`The notification for version ${
|
|
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,
|
|
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:
|
|
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} - ${
|
|
50
|
+
const notificationListName = `${this.serviceProviders[serviceProviderId].name} - ${termsType} - Update`;
|
|
51
51
|
const notificationList = await this.searchContactList(notificationListName);
|
|
52
52
|
|
|
53
53
|
if (notificationList?.id) {
|
package/src/tracker/index.js
CHANGED
|
@@ -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,
|
|
73
|
-
const { title, body } = Tracker.formatIssueTitleAndBody({ message: error.toString(), repository: this.repository,
|
|
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,
|
|
183
|
-
const { service: { name }, type } =
|
|
184
|
-
const json =
|
|
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
|
-
|
|
198
|
+
These terms are no longer tracked.
|
|
199
199
|
|
|
200
200
|
${message}
|
|
201
201
|
|