@enbox/dwn-sdk-js 0.4.16 → 0.4.18
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/dist/browser.mjs +1 -1
- package/dist/browser.mjs.map +4 -4
- package/dist/esm/generated/precompiled-validators.js +978 -840
- package/dist/esm/generated/precompiled-validators.js.map +1 -1
- package/dist/esm/json-schemas/definitions.json +5 -0
- package/dist/esm/src/core/dwn-constant.js +2 -2
- package/dist/esm/src/core/dwn-error.js +0 -1
- package/dist/esm/src/core/dwn-error.js.map +1 -1
- package/dist/esm/src/core/protocol-authorization-validation.js +1 -24
- package/dist/esm/src/core/protocol-authorization-validation.js.map +1 -1
- package/dist/esm/src/core/protocol-authorization.js +1 -5
- package/dist/esm/src/core/protocol-authorization.js.map +1 -1
- package/dist/esm/src/core/validation-state-reader.js +2 -3
- package/dist/esm/src/core/validation-state-reader.js.map +1 -1
- package/dist/esm/src/handlers/records-collection.js +200 -0
- package/dist/esm/src/handlers/records-collection.js.map +1 -0
- package/dist/esm/src/handlers/records-count.js +26 -195
- package/dist/esm/src/handlers/records-count.js.map +1 -1
- package/dist/esm/src/handlers/records-query.js +19 -373
- package/dist/esm/src/handlers/records-query.js.map +1 -1
- package/dist/esm/src/handlers/records-subscribe.js +21 -338
- package/dist/esm/src/handlers/records-subscribe.js.map +1 -1
- package/dist/esm/src/handlers/records-write.js +8 -26
- package/dist/esm/src/handlers/records-write.js.map +1 -1
- package/dist/esm/src/index.js +1 -1
- package/dist/esm/src/index.js.map +1 -1
- package/dist/esm/src/interfaces/protocols-configure.js +4 -9
- package/dist/esm/src/interfaces/protocols-configure.js.map +1 -1
- package/dist/esm/src/interfaces/records-count.js +1 -1
- package/dist/esm/src/interfaces/records-count.js.map +1 -1
- package/dist/esm/src/interfaces/records-query.js +1 -1
- package/dist/esm/src/interfaces/records-query.js.map +1 -1
- package/dist/esm/src/interfaces/records-subscribe.js +3 -1
- package/dist/esm/src/interfaces/records-subscribe.js.map +1 -1
- package/dist/esm/src/store/index-level.js +210 -21
- package/dist/esm/src/store/index-level.js.map +1 -1
- package/dist/esm/src/store/message-store-level.js +192 -21
- package/dist/esm/src/store/message-store-level.js.map +1 -1
- package/dist/esm/src/store/storage-controller.js +1 -3
- package/dist/esm/src/store/storage-controller.js.map +1 -1
- package/dist/esm/src/types/protocols-types.js +0 -10
- package/dist/esm/src/types/protocols-types.js.map +1 -1
- package/dist/esm/src/utils/filter.js +35 -1
- package/dist/esm/src/utils/filter.js.map +1 -1
- package/dist/esm/src/utils/grant-key-coverage.js +4 -6
- package/dist/esm/src/utils/grant-key-coverage.js.map +1 -1
- package/dist/esm/src/utils/messages.js +4 -14
- package/dist/esm/src/utils/messages.js.map +1 -1
- package/dist/esm/src/utils/permission-scope.js +3 -9
- package/dist/esm/src/utils/permission-scope.js.map +1 -1
- package/dist/esm/src/utils/record-limit-occupancy.js +73 -202
- package/dist/esm/src/utils/record-limit-occupancy.js.map +1 -1
- package/dist/esm/src/utils/records.js +19 -52
- package/dist/esm/src/utils/records.js.map +1 -1
- package/dist/esm/tests/core/records-grant-authorization.spec.js +13 -0
- package/dist/esm/tests/core/records-grant-authorization.spec.js.map +1 -1
- package/dist/esm/tests/core/replication-replay-property.spec.js +2 -2
- package/dist/esm/tests/core/replication-replay-property.spec.js.map +1 -1
- package/dist/esm/tests/core/validation-read-closure.spec.js +1 -1
- package/dist/esm/tests/core/validation-read-closure.spec.js.map +1 -1
- package/dist/esm/tests/dwn.spec.js +2 -2
- package/dist/esm/tests/dwn.spec.js.map +1 -1
- package/dist/esm/tests/features/records-delivery.spec.js +2 -5
- package/dist/esm/tests/features/records-delivery.spec.js.map +1 -1
- package/dist/esm/tests/features/records-nested-query-scope.spec.js +149 -70
- package/dist/esm/tests/features/records-nested-query-scope.spec.js.map +1 -1
- package/dist/esm/tests/features/records-record-limit.spec.js +380 -95
- package/dist/esm/tests/features/records-record-limit.spec.js.map +1 -1
- package/dist/esm/tests/fuzz/filter.fuzz.spec.js +19 -4
- package/dist/esm/tests/fuzz/filter.fuzz.spec.js.map +1 -1
- package/dist/esm/tests/handlers/records-count.spec.js +52 -1
- package/dist/esm/tests/handlers/records-count.spec.js.map +1 -1
- package/dist/esm/tests/handlers/records-subscribe.spec.js +76 -1
- package/dist/esm/tests/handlers/records-subscribe.spec.js.map +1 -1
- package/dist/esm/tests/handlers/records-write.spec.js +57 -3
- package/dist/esm/tests/handlers/records-write.spec.js.map +1 -1
- package/dist/esm/tests/store/index-level.spec.js +208 -1
- package/dist/esm/tests/store/index-level.spec.js.map +1 -1
- package/dist/esm/tests/store/message-store-cross-context.spec.js +46 -0
- package/dist/esm/tests/store/message-store-cross-context.spec.js.map +1 -0
- package/dist/esm/tests/store/message-store-level.spec.js +76 -1
- package/dist/esm/tests/store/message-store-level.spec.js.map +1 -1
- package/dist/esm/tests/store/message-store.spec.js +81 -0
- package/dist/esm/tests/store/message-store.spec.js.map +1 -1
- package/dist/esm/tests/utils/filters.spec.js +25 -4
- package/dist/esm/tests/utils/filters.spec.js.map +1 -1
- package/dist/esm/tests/utils/permission-scope.spec.js +4 -0
- package/dist/esm/tests/utils/permission-scope.spec.js.map +1 -1
- package/dist/esm/tests/utils/records.spec.js +12 -0
- package/dist/esm/tests/utils/records.spec.js.map +1 -1
- package/dist/esm/tests/validation/json-schemas/records/records-write.spec.js +3 -1
- package/dist/esm/tests/validation/json-schemas/records/records-write.spec.js.map +1 -1
- package/dist/types/generated/precompiled-validators.d.ts.map +1 -1
- package/dist/types/src/core/dwn-constant.d.ts +2 -2
- package/dist/types/src/core/dwn-error.d.ts +0 -1
- package/dist/types/src/core/dwn-error.d.ts.map +1 -1
- package/dist/types/src/core/protocol-authorization-validation.d.ts +0 -10
- package/dist/types/src/core/protocol-authorization-validation.d.ts.map +1 -1
- package/dist/types/src/core/protocol-authorization.d.ts.map +1 -1
- package/dist/types/src/core/validation-state-reader.d.ts.map +1 -1
- package/dist/types/src/handlers/records-collection.d.ts +32 -0
- package/dist/types/src/handlers/records-collection.d.ts.map +1 -0
- package/dist/types/src/handlers/records-count.d.ts +0 -34
- package/dist/types/src/handlers/records-count.d.ts.map +1 -1
- package/dist/types/src/handlers/records-query.d.ts +0 -61
- package/dist/types/src/handlers/records-query.d.ts.map +1 -1
- package/dist/types/src/handlers/records-subscribe.d.ts +1 -37
- package/dist/types/src/handlers/records-subscribe.d.ts.map +1 -1
- package/dist/types/src/handlers/records-write.d.ts +3 -0
- package/dist/types/src/handlers/records-write.d.ts.map +1 -1
- package/dist/types/src/index.d.ts +3 -3
- package/dist/types/src/index.d.ts.map +1 -1
- package/dist/types/src/interfaces/protocols-configure.d.ts.map +1 -1
- package/dist/types/src/interfaces/records-subscribe.d.ts.map +1 -1
- package/dist/types/src/store/index-level.d.ts +61 -0
- package/dist/types/src/store/index-level.d.ts.map +1 -1
- package/dist/types/src/store/message-store-level.d.ts +24 -6
- package/dist/types/src/store/message-store-level.d.ts.map +1 -1
- package/dist/types/src/store/storage-controller.d.ts.map +1 -1
- package/dist/types/src/types/message-store.d.ts +28 -2
- package/dist/types/src/types/message-store.d.ts.map +1 -1
- package/dist/types/src/types/protocols-types.d.ts +7 -24
- package/dist/types/src/types/protocols-types.d.ts.map +1 -1
- package/dist/types/src/types/query-types.d.ts +8 -1
- package/dist/types/src/types/query-types.d.ts.map +1 -1
- package/dist/types/src/types/records-types.d.ts +3 -2
- package/dist/types/src/types/records-types.d.ts.map +1 -1
- package/dist/types/src/utils/filter.d.ts +14 -1
- package/dist/types/src/utils/filter.d.ts.map +1 -1
- package/dist/types/src/utils/grant-key-coverage.d.ts.map +1 -1
- package/dist/types/src/utils/messages.d.ts.map +1 -1
- package/dist/types/src/utils/permission-scope.d.ts +0 -2
- package/dist/types/src/utils/permission-scope.d.ts.map +1 -1
- package/dist/types/src/utils/record-limit-occupancy.d.ts +25 -12
- package/dist/types/src/utils/record-limit-occupancy.d.ts.map +1 -1
- package/dist/types/src/utils/records.d.ts +6 -24
- package/dist/types/src/utils/records.d.ts.map +1 -1
- package/dist/types/tests/features/records-delivery.spec.d.ts.map +1 -1
- package/dist/types/tests/features/records-nested-query-scope.spec.d.ts.map +1 -1
- package/dist/types/tests/features/records-record-limit.spec.d.ts.map +1 -1
- package/dist/types/tests/handlers/records-count.spec.d.ts.map +1 -1
- package/dist/types/tests/handlers/records-subscribe.spec.d.ts.map +1 -1
- package/dist/types/tests/handlers/records-write.spec.d.ts.map +1 -1
- package/dist/types/tests/store/message-store-cross-context.spec.d.ts +2 -0
- package/dist/types/tests/store/message-store-cross-context.spec.d.ts.map +1 -0
- package/dist/types/tests/store/message-store.spec.d.ts.map +1 -1
- package/package.json +4 -4
- package/src/core/dwn-constant.ts +2 -2
- package/src/core/dwn-error.ts +0 -2
- package/src/core/protocol-authorization-validation.ts +1 -33
- package/src/core/protocol-authorization.ts +0 -7
- package/src/core/validation-state-reader.ts +2 -3
- package/src/handlers/records-collection.ts +269 -0
- package/src/handlers/records-count.ts +38 -232
- package/src/handlers/records-query.ts +22 -444
- package/src/handlers/records-subscribe.ts +26 -397
- package/src/handlers/records-write.ts +17 -32
- package/src/index.ts +3 -3
- package/src/interfaces/protocols-configure.ts +4 -13
- package/src/interfaces/records-count.ts +1 -1
- package/src/interfaces/records-query.ts +1 -1
- package/src/interfaces/records-subscribe.ts +5 -2
- package/src/store/index-level.ts +323 -28
- package/src/store/message-store-level.ts +251 -25
- package/src/store/storage-controller.ts +1 -3
- package/src/types/message-store.ts +30 -2
- package/src/types/protocols-types.ts +7 -26
- package/src/types/query-types.ts +10 -2
- package/src/types/records-types.ts +3 -2
- package/src/utils/filter.ts +40 -3
- package/src/utils/grant-key-coverage.ts +4 -7
- package/src/utils/messages.ts +4 -14
- package/src/utils/permission-scope.ts +4 -11
- package/src/utils/record-limit-occupancy.ts +108 -293
- package/src/utils/records.ts +22 -57
|
@@ -1,13 +1,10 @@
|
|
|
1
|
-
import { authenticate } from '../core/auth.js';
|
|
2
1
|
import { EncryptionControl } from '../core/encryption-control.js';
|
|
3
2
|
import { Message } from '../core/message.js';
|
|
4
3
|
import { messageReplyFromError } from '../core/message-reply.js';
|
|
5
|
-
import { ProtocolAuthorization } from '../core/protocol-authorization.js';
|
|
6
4
|
import { Records } from '../utils/records.js';
|
|
7
5
|
import { RecordsCount } from '../interfaces/records-count.js';
|
|
8
|
-
import {
|
|
9
|
-
import { countRecordsWithRecordLimitOccupancy, queryRecordsWithRecordLimitOccupancy } from '../utils/record-limit-occupancy.js';
|
|
10
|
-
import { DwnInterfaceName, DwnMethodName } from '../enums/dwn-interface-method.js';
|
|
6
|
+
import { buildRecordsSnapshotFilters, resolveRecordsCollectionVisibility } from './records-collection.js';
|
|
7
|
+
import { countRecordsWithRecordLimitOccupancy, queryRecordsWithRecordLimitOccupancy, resolveRecordLimitOccupancy, } from '../utils/record-limit-occupancy.js';
|
|
11
8
|
export class RecordsCountHandler {
|
|
12
9
|
deps;
|
|
13
10
|
constructor(deps) {
|
|
@@ -18,104 +15,38 @@ export class RecordsCountHandler {
|
|
|
18
15
|
try {
|
|
19
16
|
recordsCount = await RecordsCount.parse(message);
|
|
20
17
|
}
|
|
21
|
-
catch (
|
|
22
|
-
return messageReplyFromError(
|
|
18
|
+
catch (error) {
|
|
19
|
+
return messageReplyFromError(error, 400);
|
|
23
20
|
}
|
|
24
|
-
let count;
|
|
25
21
|
const requester = Message.getRequester(recordsCount.message);
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
22
|
+
let visibility;
|
|
23
|
+
try {
|
|
24
|
+
visibility = await resolveRecordsCollectionVisibility(tenant, recordsCount, this.deps);
|
|
29
25
|
}
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
try {
|
|
33
|
-
await authenticate(message.authorization, this.deps.didResolver);
|
|
34
|
-
await RecordsCountHandler.authorizeRecordsCount(tenant, recordsCount, this.deps);
|
|
35
|
-
}
|
|
36
|
-
catch (e) {
|
|
37
|
-
return messageReplyFromError(e, 401);
|
|
38
|
-
}
|
|
39
|
-
if (recordsCount.author === tenant && requester === tenant) {
|
|
40
|
-
count = await this.countRecordsAsOwner(tenant, recordsCount);
|
|
41
|
-
}
|
|
42
|
-
else if (recordsCount.author === tenant) {
|
|
43
|
-
count = await this.countRecordsAsOwnerDelegate(tenant, recordsCount, requester);
|
|
44
|
-
}
|
|
45
|
-
else {
|
|
46
|
-
count = await this.countRecordsAsNonOwner(tenant, recordsCount, requester);
|
|
47
|
-
}
|
|
26
|
+
catch (error) {
|
|
27
|
+
return messageReplyFromError(error, 401);
|
|
48
28
|
}
|
|
29
|
+
const filters = buildRecordsSnapshotFilters(recordsCount, visibility);
|
|
30
|
+
const recordLimit = await resolveRecordLimitOccupancy({
|
|
31
|
+
validationStateReader: this.deps.validationStateReader,
|
|
32
|
+
tenant,
|
|
33
|
+
recordsFilter: recordsCount.message.descriptor.filter,
|
|
34
|
+
messageTimestamp: recordsCount.message.descriptor.messageTimestamp,
|
|
35
|
+
});
|
|
36
|
+
const count = recordsCount.author === tenant && requester === tenant
|
|
37
|
+
? await this.countProjectedRecords(tenant, filters, recordLimit)
|
|
38
|
+
: await this.countProjectedRecordsForRequester(tenant, recordsCount, requester, filters, recordLimit);
|
|
49
39
|
return {
|
|
50
40
|
status: { code: 200, detail: 'OK' },
|
|
51
41
|
count,
|
|
52
42
|
};
|
|
53
43
|
}
|
|
54
|
-
|
|
55
|
-
* Counts records as the owner of the DWN with no additional filtering.
|
|
56
|
-
*/
|
|
57
|
-
async countRecordsAsOwner(tenant, recordsCount) {
|
|
58
|
-
const { filter } = recordsCount.message.descriptor;
|
|
59
|
-
const countFilter = {
|
|
60
|
-
...Records.convertFilter(filter),
|
|
61
|
-
interface: DwnInterfaceName.Records,
|
|
62
|
-
method: DwnMethodName.Write,
|
|
63
|
-
isLatestBaseState: true
|
|
64
|
-
};
|
|
65
|
-
return this.countProjectedRecords(tenant, recordsCount, [countFilter]);
|
|
66
|
-
}
|
|
67
|
-
async countRecordsAsOwnerDelegate(tenant, recordsCount, requester) {
|
|
68
|
-
const { filter } = recordsCount.message.descriptor;
|
|
69
|
-
const countFilter = {
|
|
70
|
-
...Records.convertFilter(filter),
|
|
71
|
-
interface: DwnInterfaceName.Records,
|
|
72
|
-
method: DwnMethodName.Write,
|
|
73
|
-
isLatestBaseState: true
|
|
74
|
-
};
|
|
75
|
-
return this.countProjectedRecordsForRequester(tenant, recordsCount, requester, [countFilter]);
|
|
76
|
-
}
|
|
77
|
-
/**
|
|
78
|
-
* Counts records as a non-owner, applying the same filter logic as RecordsQuery.
|
|
79
|
-
*/
|
|
80
|
-
async countRecordsAsNonOwner(tenant, recordsCount, requester) {
|
|
81
|
-
const { filter } = recordsCount.message.descriptor;
|
|
82
|
-
const filters = [];
|
|
83
|
-
if (Records.filterIncludesPublishedRecords(filter)) {
|
|
84
|
-
filters.push(RecordsCountHandler.buildPublishedRecordsFilter(recordsCount));
|
|
85
|
-
}
|
|
86
|
-
if (Records.filterIncludesUnpublishedRecords(filter)) {
|
|
87
|
-
if (EncryptionControl.isExactAudienceFilter(filter)) {
|
|
88
|
-
filters.push(Records.buildUnpublishedControlRecordsFilter(filter));
|
|
89
|
-
}
|
|
90
|
-
if (Records.shouldBuildUnpublishedAuthorFilter(filter, recordsCount.author)) {
|
|
91
|
-
filters.push(RecordsCountHandler.buildUnpublishedRecordsByCountAuthorFilter(recordsCount));
|
|
92
|
-
}
|
|
93
|
-
if (Records.shouldProtocolAuthorize(recordsCount.signaturePayload)) {
|
|
94
|
-
filters.push(RecordsCountHandler.buildUnpublishedProtocolAuthorizedRecordsFilter(recordsCount));
|
|
95
|
-
}
|
|
96
|
-
if (Message.getPermissionGrantId(recordsCount.signaturePayload) !== undefined) {
|
|
97
|
-
filters.push(RecordsCountHandler.buildUnpublishedPermissionGrantAuthorizedRecordsFilter(recordsCount));
|
|
98
|
-
}
|
|
99
|
-
if (Records.shouldBuildUnpublishedRecipientFilter(filter, recordsCount.author)) {
|
|
100
|
-
filters.push(RecordsCountHandler.buildUnpublishedRecordsForCountAuthorFilter(recordsCount));
|
|
101
|
-
}
|
|
102
|
-
}
|
|
103
|
-
return this.countProjectedRecordsForRequester(tenant, recordsCount, requester, filters);
|
|
104
|
-
}
|
|
105
|
-
/**
|
|
106
|
-
* Counts only published records.
|
|
107
|
-
*/
|
|
108
|
-
async countPublishedRecords(tenant, recordsCount, requester) {
|
|
109
|
-
const filter = RecordsCountHandler.buildPublishedRecordsFilter(recordsCount);
|
|
110
|
-
return this.countProjectedRecordsForRequester(tenant, recordsCount, requester, [filter]);
|
|
111
|
-
}
|
|
112
|
-
async countProjectedRecords(tenant, recordsCount, filters) {
|
|
44
|
+
async countProjectedRecords(tenant, filters, recordLimit) {
|
|
113
45
|
const totalCount = await countRecordsWithRecordLimitOccupancy({
|
|
114
46
|
messageStore: this.deps.messageStore,
|
|
115
|
-
validationStateReader: this.deps.validationStateReader,
|
|
116
47
|
tenant,
|
|
117
48
|
filters,
|
|
118
|
-
|
|
49
|
+
recordLimit,
|
|
119
50
|
});
|
|
120
51
|
const audienceFilters = EncryptionControl.buildAudienceRecordFilters(filters);
|
|
121
52
|
if (audienceFilters.length === 0) {
|
|
@@ -134,22 +65,21 @@ export class RecordsCountHandler {
|
|
|
134
65
|
});
|
|
135
66
|
return totalCount - storedAudienceCount + projectedAudienceMessages.length;
|
|
136
67
|
}
|
|
137
|
-
async countProjectedRecordsForRequester(tenant, recordsCount, requester, filters) {
|
|
68
|
+
async countProjectedRecordsForRequester(tenant, recordsCount, requester, filters, recordLimit) {
|
|
138
69
|
const controlFilters = Records.buildControlRecordsFilters(filters);
|
|
139
70
|
if (controlFilters.length === 0) {
|
|
140
|
-
return this.countProjectedRecords(tenant,
|
|
71
|
+
return this.countProjectedRecords(tenant, filters, recordLimit);
|
|
141
72
|
}
|
|
142
|
-
const totalCount = await this.countProjectedRecords(tenant,
|
|
143
|
-
const controlCount = await this.countProjectedRecords(tenant,
|
|
73
|
+
const totalCount = await this.countProjectedRecords(tenant, filters, recordLimit);
|
|
74
|
+
const controlCount = await this.countProjectedRecords(tenant, controlFilters, recordLimit);
|
|
144
75
|
if (controlCount === 0) {
|
|
145
76
|
return totalCount;
|
|
146
77
|
}
|
|
147
78
|
const { messages } = await queryRecordsWithRecordLimitOccupancy({
|
|
148
79
|
messageStore: this.deps.messageStore,
|
|
149
|
-
validationStateReader: this.deps.validationStateReader,
|
|
150
80
|
tenant,
|
|
151
81
|
filters: controlFilters,
|
|
152
|
-
|
|
82
|
+
recordLimit,
|
|
153
83
|
});
|
|
154
84
|
const projectedMessages = await EncryptionControl.projectCurrentAudienceRecords({
|
|
155
85
|
messageStore: this.deps.messageStore,
|
|
@@ -166,104 +96,5 @@ export class RecordsCountHandler {
|
|
|
166
96
|
});
|
|
167
97
|
return totalCount - controlCount + visibleMessages.length;
|
|
168
98
|
}
|
|
169
|
-
static buildPublishedRecordsFilter(recordsCount) {
|
|
170
|
-
const { filter } = recordsCount.message.descriptor;
|
|
171
|
-
return {
|
|
172
|
-
...Records.convertFilter(filter),
|
|
173
|
-
interface: DwnInterfaceName.Records,
|
|
174
|
-
method: DwnMethodName.Write,
|
|
175
|
-
published: true,
|
|
176
|
-
isLatestBaseState: true
|
|
177
|
-
};
|
|
178
|
-
}
|
|
179
|
-
/**
|
|
180
|
-
* Creates a filter for unpublished records that are intended for the count author (where `recipient` is the author).
|
|
181
|
-
*/
|
|
182
|
-
static buildUnpublishedRecordsForCountAuthorFilter(recordsCount) {
|
|
183
|
-
const { filter } = recordsCount.message.descriptor;
|
|
184
|
-
return {
|
|
185
|
-
...Records.convertFilter(filter),
|
|
186
|
-
interface: DwnInterfaceName.Records,
|
|
187
|
-
method: DwnMethodName.Write,
|
|
188
|
-
recipient: recordsCount.author,
|
|
189
|
-
isLatestBaseState: true,
|
|
190
|
-
published: false
|
|
191
|
-
};
|
|
192
|
-
}
|
|
193
|
-
/**
|
|
194
|
-
* Creates a filter for unpublished records that are within the specified protocol.
|
|
195
|
-
*/
|
|
196
|
-
static buildUnpublishedProtocolAuthorizedRecordsFilter(recordsCount) {
|
|
197
|
-
const { filter } = recordsCount.message.descriptor;
|
|
198
|
-
return {
|
|
199
|
-
...Records.convertFilter(filter),
|
|
200
|
-
interface: DwnInterfaceName.Records,
|
|
201
|
-
method: DwnMethodName.Write,
|
|
202
|
-
isLatestBaseState: true,
|
|
203
|
-
published: false
|
|
204
|
-
};
|
|
205
|
-
}
|
|
206
|
-
/**
|
|
207
|
-
* Creates a filter for unpublished records authorized by a permission grant.
|
|
208
|
-
*/
|
|
209
|
-
static buildUnpublishedPermissionGrantAuthorizedRecordsFilter(recordsCount) {
|
|
210
|
-
const { filter } = recordsCount.message.descriptor;
|
|
211
|
-
return {
|
|
212
|
-
...Records.convertFilter(filter),
|
|
213
|
-
interface: DwnInterfaceName.Records,
|
|
214
|
-
method: DwnMethodName.Write,
|
|
215
|
-
isLatestBaseState: true,
|
|
216
|
-
published: false
|
|
217
|
-
};
|
|
218
|
-
}
|
|
219
|
-
/**
|
|
220
|
-
* Creates a filter for only unpublished records where the author is the same as the count author.
|
|
221
|
-
*/
|
|
222
|
-
static buildUnpublishedRecordsByCountAuthorFilter(recordsCount) {
|
|
223
|
-
const { filter } = recordsCount.message.descriptor;
|
|
224
|
-
return {
|
|
225
|
-
...Records.convertFilter(filter),
|
|
226
|
-
author: recordsCount.author,
|
|
227
|
-
interface: DwnInterfaceName.Records,
|
|
228
|
-
method: DwnMethodName.Write,
|
|
229
|
-
isLatestBaseState: true,
|
|
230
|
-
published: false
|
|
231
|
-
};
|
|
232
|
-
}
|
|
233
|
-
/**
|
|
234
|
-
* @param messageStore Used to check if the grant has been revoked.
|
|
235
|
-
*/
|
|
236
|
-
static async authorizeRecordsCount(tenant, recordsCount, deps) {
|
|
237
|
-
if (Message.isSignedByAuthorDelegate(recordsCount.message) &&
|
|
238
|
-
!EncryptionControl.filterTargetsOnlyControlRecords(recordsCount.message.descriptor.filter)) {
|
|
239
|
-
await recordsCount.authorizeDelegate(deps.validationStateReader);
|
|
240
|
-
}
|
|
241
|
-
else if (EncryptionControl.filterTargetsOnlyControlRecords(recordsCount.message.descriptor.filter)) {
|
|
242
|
-
await EncryptionControl.authorizeControlReadRequest({
|
|
243
|
-
tenant,
|
|
244
|
-
incomingMessage: recordsCount.message,
|
|
245
|
-
requester: Message.getRequester(recordsCount.message),
|
|
246
|
-
validationStateReader: deps.validationStateReader,
|
|
247
|
-
});
|
|
248
|
-
}
|
|
249
|
-
const permissionGrantId = Message.getPermissionGrantId(recordsCount.signaturePayload);
|
|
250
|
-
if (permissionGrantId !== undefined) {
|
|
251
|
-
const permissionGrant = await deps.validationStateReader.fetchGrant(tenant, permissionGrantId);
|
|
252
|
-
await RecordsGrantAuthorization.authorizeQueryOrSubscribe({
|
|
253
|
-
incomingMessage: recordsCount.message,
|
|
254
|
-
expectedGrantor: tenant,
|
|
255
|
-
expectedGrantee: recordsCount.author,
|
|
256
|
-
permissionGrant,
|
|
257
|
-
validationStateReader: deps.validationStateReader,
|
|
258
|
-
});
|
|
259
|
-
return;
|
|
260
|
-
}
|
|
261
|
-
// NOTE: not all RecordsCount messages require protocol authorization even if the filter includes protocol-related fields,
|
|
262
|
-
// this is because we dynamically filter out records that the caller is not authorized to see.
|
|
263
|
-
// Currently only run protocol authorization if message deliberately invokes a protocol role.
|
|
264
|
-
if (Records.shouldProtocolAuthorize(recordsCount.signaturePayload)) {
|
|
265
|
-
await ProtocolAuthorization.authorizeQueryOrSubscribe(tenant, recordsCount, deps.validationStateReader);
|
|
266
|
-
}
|
|
267
|
-
}
|
|
268
99
|
}
|
|
269
100
|
//# sourceMappingURL=records-count.js.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"records-count.js","sourceRoot":"","sources":["../../../../src/handlers/records-count.ts"],"names":[],"mappings":"
|
|
1
|
+
{"version":3,"file":"records-count.js","sourceRoot":"","sources":["../../../../src/handlers/records-count.ts"],"names":[],"mappings":"AAMA,OAAO,EAAE,iBAAiB,EAAE,MAAM,+BAA+B,CAAC;AAClE,OAAO,EAA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