@adobe/spacecat-shared-data-access 2.109.0 → 3.0.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.
- package/CHANGELOG.md +14 -0
- package/README.md +260 -245
- package/docker-compose.test.yml +39 -0
- package/package.json +5 -6
- package/src/index.js +10 -5
- package/src/models/audit/audit.collection.js +6 -20
- package/src/models/base/base.collection.js +699 -395
- package/src/models/base/base.model.js +13 -6
- package/src/models/base/entity.registry.js +11 -4
- package/src/models/base/schema.builder.js +2 -0
- package/src/models/base/schema.js +15 -4
- package/src/models/fix-entity-suggestion/fix-entity-suggestion.model.js +15 -0
- package/src/models/fix-entity-suggestion/fix-entity-suggestion.schema.js +12 -0
- package/src/models/key-event/key-event.collection.js +23 -1
- package/src/models/latest-audit/latest-audit.collection.js +77 -3
- package/src/models/scrape-job/scrape-job.collection.js +38 -0
- package/src/models/scrape-job/scrape-job.schema.js +4 -2
- package/src/models/site/site.schema.js +1 -0
- package/src/models/site-enrollment/site-enrollment.collection.js +11 -1
- package/src/models/trial-user/trial-user.collection.js +0 -2
- package/src/models/trial-user/trial-user.schema.js +5 -1
- package/src/service/index.d.ts +7 -1
- package/src/service/index.js +32 -51
- package/src/util/index.js +2 -1
- package/src/util/logger-registry.js +12 -0
- package/src/util/patcher.js +64 -112
- package/src/util/postgrest.utils.js +203 -0
- package/tsconfig.json +24 -0
package/src/index.js
CHANGED
|
@@ -14,8 +14,6 @@ import { createDataAccess } from './service/index.js';
|
|
|
14
14
|
|
|
15
15
|
export * from './service/index.js';
|
|
16
16
|
|
|
17
|
-
const TABLE_NAME_DATA = 'spacecat-services-data';
|
|
18
|
-
|
|
19
17
|
/**
|
|
20
18
|
* Wrapper for data access layer
|
|
21
19
|
* @param {function} fn - The function to wrap
|
|
@@ -25,7 +23,7 @@ export default function dataAccessWrapper(fn) {
|
|
|
25
23
|
/**
|
|
26
24
|
* Wrapper for data access layer. This wrapper will create a data access layer if it is not
|
|
27
25
|
* already created. It requires the context to have a log object. It will also use the
|
|
28
|
-
*
|
|
26
|
+
* POSTGREST_URL environment variable to create the data access layer.
|
|
29
27
|
* Optionally, it will use the ENV and AWS_REGION environment variables
|
|
30
28
|
*
|
|
31
29
|
* @param {object} request - The request object
|
|
@@ -37,18 +35,25 @@ export default function dataAccessWrapper(fn) {
|
|
|
37
35
|
const { log } = context;
|
|
38
36
|
|
|
39
37
|
const {
|
|
40
|
-
|
|
38
|
+
POSTGREST_URL: postgrestUrl,
|
|
39
|
+
POSTGREST_SCHEMA: postgrestSchema,
|
|
40
|
+
POSTGREST_API_KEY: postgrestApiKey,
|
|
41
41
|
S3_CONFIG_BUCKET: s3Bucket,
|
|
42
42
|
AWS_REGION: region,
|
|
43
43
|
S2S_ALLOWED_IMS_ORG_IDS: s2sAllowedImsOrgIdsRaw,
|
|
44
44
|
} = context.env;
|
|
45
45
|
|
|
46
|
+
if (!postgrestUrl) {
|
|
47
|
+
throw new Error('POSTGREST_URL is required');
|
|
48
|
+
}
|
|
46
49
|
const s2sAllowedImsOrgIds = s2sAllowedImsOrgIdsRaw
|
|
47
50
|
? s2sAllowedImsOrgIdsRaw.split(',').map((id) => id.trim()).filter(Boolean)
|
|
48
51
|
: [];
|
|
49
52
|
|
|
50
53
|
context.dataAccess = createDataAccess({
|
|
51
|
-
|
|
54
|
+
postgrestUrl,
|
|
55
|
+
postgrestSchema,
|
|
56
|
+
postgrestApiKey,
|
|
52
57
|
s3Bucket,
|
|
53
58
|
region,
|
|
54
59
|
s2sAllowedImsOrgIds,
|
|
@@ -22,30 +22,16 @@ import BaseCollection from '../base/base.collection.js';
|
|
|
22
22
|
class AuditCollection extends BaseCollection {
|
|
23
23
|
static COLLECTION_NAME = 'AuditCollection';
|
|
24
24
|
|
|
25
|
-
//
|
|
25
|
+
// LatestAudit is derived from audits in v3; no copy table writes.
|
|
26
|
+
// eslint-disable-next-line class-methods-use-this,no-unused-vars
|
|
26
27
|
async _onCreate(item) {
|
|
27
|
-
|
|
28
|
-
await collection.create(item.toJSON());
|
|
28
|
+
// no-op
|
|
29
29
|
}
|
|
30
30
|
|
|
31
|
-
//
|
|
32
|
-
//
|
|
31
|
+
// LatestAudit is derived from audits in v3; no copy table writes.
|
|
32
|
+
// eslint-disable-next-line class-methods-use-this,no-unused-vars
|
|
33
33
|
async _onCreateMany(items) {
|
|
34
|
-
|
|
35
|
-
const latestAudits = items.createdItems.reduce((acc, audit) => {
|
|
36
|
-
const siteId = audit.getSiteId();
|
|
37
|
-
const auditType = audit.getAuditType();
|
|
38
|
-
const auditedAt = audit.getAuditedAt();
|
|
39
|
-
const key = `${siteId}-${auditType}`;
|
|
40
|
-
|
|
41
|
-
if (!acc[key] || acc[key].getAuditedAt() < auditedAt) {
|
|
42
|
-
acc[key] = audit;
|
|
43
|
-
}
|
|
44
|
-
|
|
45
|
-
return acc;
|
|
46
|
-
}, {});
|
|
47
|
-
|
|
48
|
-
await collection.createMany(Object.values(latestAudits).map((audit) => audit.toJSON()));
|
|
34
|
+
// no-op
|
|
49
35
|
}
|
|
50
36
|
}
|
|
51
37
|
|