@casual-simulation/aux-records 3.2.13 → 3.2.14-alpha.7890390188
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/AIController.d.ts +7 -4
- package/AIController.js +11 -0
- package/AIController.js.map +1 -1
- package/AuthController.d.ts +2 -1
- package/AuthController.js +6 -3
- package/AuthController.js.map +1 -1
- package/AuthStore.d.ts +1 -21
- package/CachingPolicyStore.d.ts +16 -5
- package/CachingPolicyStore.js +66 -39
- package/CachingPolicyStore.js.map +1 -1
- package/DataRecordsController.d.ts +67 -5
- package/DataRecordsController.js +141 -78
- package/DataRecordsController.js.map +1 -1
- package/DataRecordsStore.d.ts +35 -1
- package/DataRecordsStore.js.map +1 -1
- package/EventRecordsController.d.ts +5 -5
- package/EventRecordsController.js +54 -35
- package/EventRecordsController.js.map +1 -1
- package/FileRecordsController.d.ts +6 -6
- package/FileRecordsController.js +142 -76
- package/FileRecordsController.js.map +1 -1
- package/MemoryStore.d.ts +28 -17
- package/MemoryStore.js +457 -110
- package/MemoryStore.js.map +1 -1
- package/PolicyController.d.ts +512 -677
- package/PolicyController.js +1196 -2934
- package/PolicyController.js.map +1 -1
- package/PolicyStore.d.ts +319 -90
- package/PolicyStore.js +125 -0
- package/PolicyStore.js.map +1 -1
- package/RecordsServer.d.ts +3 -4
- package/RecordsServer.js +88 -111
- package/RecordsServer.js.map +1 -1
- package/RecordsStore.d.ts +3 -0
- package/TestUtils.d.ts +1 -1
- package/TestUtils.js.map +1 -1
- package/Utils.d.ts +21 -3
- package/Utils.js +42 -3
- package/Utils.js.map +1 -1
- package/package.json +3 -3
- package/websockets/InstRecordsStore.d.ts +21 -0
- package/websockets/InstRecordsStore.js +43 -1
- package/websockets/InstRecordsStore.js.map +1 -1
- package/websockets/WebsocketController.d.ts +7 -7
- package/websockets/WebsocketController.js +153 -82
- package/websockets/WebsocketController.js.map +1 -1
package/MemoryStore.js
CHANGED
|
@@ -18,10 +18,9 @@ var __rest = (this && this.__rest) || function (s, e) {
|
|
|
18
18
|
}
|
|
19
19
|
return t;
|
|
20
20
|
};
|
|
21
|
-
import { sortBy } from 'lodash';
|
|
21
|
+
import { cloneDeep, orderBy, sortBy } from 'lodash';
|
|
22
22
|
import { v4 as uuid } from 'uuid';
|
|
23
|
-
import { getExpireTime, } from './PolicyStore';
|
|
24
|
-
import { DEFAULT_ANY_RESOURCE_POLICY_DOCUMENT, DEFAULT_PUBLIC_READ_POLICY_DOCUMENT, DEFAULT_PUBLIC_WRITE_POLICY_DOCUMENT, PUBLIC_READ_MARKER, PUBLIC_WRITE_MARKER, } from '@casual-simulation/aux-common';
|
|
23
|
+
import { getExpireTime, getSubjectUserId, } from './PolicyStore';
|
|
25
24
|
import { DateTime } from 'luxon';
|
|
26
25
|
export class MemoryStore {
|
|
27
26
|
get users() {
|
|
@@ -109,6 +108,10 @@ export class MemoryStore {
|
|
|
109
108
|
this._moderationConfiguration = null;
|
|
110
109
|
this._recordNotifications = [];
|
|
111
110
|
this._comIdRequests = [];
|
|
111
|
+
this._resourcePermissionAssignments = [];
|
|
112
|
+
this._markerPermissionAssignments = [];
|
|
113
|
+
// TODO: Support global permissions
|
|
114
|
+
// private _globalPermissionAssignments: GlobalPermissionAssignment[] = [];
|
|
112
115
|
this.maxAllowedInstSize = Infinity;
|
|
113
116
|
this._subscriptionConfiguration = config.subscriptions;
|
|
114
117
|
this._privoConfiguration = (_a = config.privo) !== null && _a !== void 0 ? _a : null;
|
|
@@ -117,6 +120,50 @@ export class MemoryStore {
|
|
|
117
120
|
this.roles = {};
|
|
118
121
|
this.roleAssignments = {};
|
|
119
122
|
}
|
|
123
|
+
/**
|
|
124
|
+
* Constructs a deep clone of this memory store.
|
|
125
|
+
* Effectively copies all the data in the store into a new one.
|
|
126
|
+
*/
|
|
127
|
+
clone() {
|
|
128
|
+
const newStore = new MemoryStore({
|
|
129
|
+
subscriptions: cloneDeep(this._subscriptionConfiguration),
|
|
130
|
+
privo: cloneDeep(this._privoConfiguration),
|
|
131
|
+
moderation: cloneDeep(this._moderationConfiguration),
|
|
132
|
+
});
|
|
133
|
+
newStore._users = cloneDeep(this._users);
|
|
134
|
+
newStore._loginRequests = cloneDeep(this._loginRequests);
|
|
135
|
+
newStore._oidLoginRequests = cloneDeep(this._oidLoginRequests);
|
|
136
|
+
newStore._sessions = cloneDeep(this._sessions);
|
|
137
|
+
newStore._subscriptions = cloneDeep(this._subscriptions);
|
|
138
|
+
newStore._periods = cloneDeep(this._periods);
|
|
139
|
+
newStore._invoices = cloneDeep(this._invoices);
|
|
140
|
+
newStore._records = cloneDeep(this._records);
|
|
141
|
+
newStore._recordKeys = cloneDeep(this._recordKeys);
|
|
142
|
+
newStore._studios = cloneDeep(this._studios);
|
|
143
|
+
newStore._studioAssignments = cloneDeep(this._studioAssignments);
|
|
144
|
+
newStore._aiChatMetrics = cloneDeep(this._aiChatMetrics);
|
|
145
|
+
newStore._aiImageMetrics = cloneDeep(this._aiImageMetrics);
|
|
146
|
+
newStore._aiSkyboxMetrics = cloneDeep(this._aiSkyboxMetrics);
|
|
147
|
+
newStore._dataBuckets = cloneDeep(this._dataBuckets);
|
|
148
|
+
newStore._eventBuckets = cloneDeep(this._eventBuckets);
|
|
149
|
+
newStore._files = cloneDeep(this._files);
|
|
150
|
+
newStore._fileUploadUrl = cloneDeep(this._fileUploadUrl);
|
|
151
|
+
newStore._emailRules = cloneDeep(this._emailRules);
|
|
152
|
+
newStore._smsRules = cloneDeep(this._smsRules);
|
|
153
|
+
newStore._userInstReports = cloneDeep(this._userInstReports);
|
|
154
|
+
newStore._instRecords = cloneDeep(this._instRecords);
|
|
155
|
+
newStore._subscriptionConfiguration = cloneDeep(this._subscriptionConfiguration);
|
|
156
|
+
newStore._privoConfiguration = cloneDeep(this._privoConfiguration);
|
|
157
|
+
newStore._moderationConfiguration = cloneDeep(this._moderationConfiguration);
|
|
158
|
+
newStore._recordNotifications = cloneDeep(this._recordNotifications);
|
|
159
|
+
newStore._comIdRequests = cloneDeep(this._comIdRequests);
|
|
160
|
+
newStore._resourcePermissionAssignments = cloneDeep(this._resourcePermissionAssignments);
|
|
161
|
+
newStore._markerPermissionAssignments = cloneDeep(this._markerPermissionAssignments);
|
|
162
|
+
newStore.maxAllowedInstSize = this.maxAllowedInstSize;
|
|
163
|
+
newStore.roles = cloneDeep(this.roles);
|
|
164
|
+
newStore.roleAssignments = cloneDeep(this.roleAssignments);
|
|
165
|
+
return newStore;
|
|
166
|
+
}
|
|
120
167
|
saveComIdRequest(request) {
|
|
121
168
|
return __awaiter(this, void 0, void 0, function* () {
|
|
122
169
|
this._comIdRequests.push(request);
|
|
@@ -398,6 +445,252 @@ export class MemoryStore {
|
|
|
398
445
|
});
|
|
399
446
|
});
|
|
400
447
|
}
|
|
448
|
+
getUserPrivacyFeatures(userId) {
|
|
449
|
+
return __awaiter(this, void 0, void 0, function* () {
|
|
450
|
+
return yield this._getUserPrivacyFeatures(userId);
|
|
451
|
+
});
|
|
452
|
+
}
|
|
453
|
+
getRecordOwnerPrivacyFeatures(recordName) {
|
|
454
|
+
return __awaiter(this, void 0, void 0, function* () {
|
|
455
|
+
const record = yield this.getRecordByName(recordName);
|
|
456
|
+
if (!record || !record.ownerId) {
|
|
457
|
+
return null;
|
|
458
|
+
}
|
|
459
|
+
return yield this._getUserPrivacyFeatures(record.ownerId);
|
|
460
|
+
});
|
|
461
|
+
}
|
|
462
|
+
getPermissionForSubjectAndResource(subjectType, subjectId, recordName, resourceKind, resourceId, action, currentTimeMs) {
|
|
463
|
+
return __awaiter(this, void 0, void 0, function* () {
|
|
464
|
+
const existingRoles = subjectType === 'user'
|
|
465
|
+
? yield this.listRolesForUser(recordName, subjectId)
|
|
466
|
+
: subjectType === 'inst'
|
|
467
|
+
? yield this.listRolesForInst(recordName, subjectId)
|
|
468
|
+
: [];
|
|
469
|
+
const roles = existingRoles.map((r) => r.role);
|
|
470
|
+
const assignment = this._resourcePermissionAssignments.find((p) => p.recordName === recordName &&
|
|
471
|
+
((p.subjectType === 'role' &&
|
|
472
|
+
roles.indexOf(p.subjectId) >= 0) ||
|
|
473
|
+
(p.subjectType === subjectType &&
|
|
474
|
+
p.subjectId === subjectId)) &&
|
|
475
|
+
p.resourceKind === resourceKind &&
|
|
476
|
+
p.resourceId === resourceId &&
|
|
477
|
+
(p.action === null || p.action === action) &&
|
|
478
|
+
(!p.expireTimeMs || p.expireTimeMs > currentTimeMs));
|
|
479
|
+
return {
|
|
480
|
+
success: true,
|
|
481
|
+
permissionAssignment: assignment,
|
|
482
|
+
};
|
|
483
|
+
});
|
|
484
|
+
}
|
|
485
|
+
getPermissionForSubjectAndMarkers(subjectType, subjectId, recordName, resourceKind, markers, action, currentTimeMs) {
|
|
486
|
+
return __awaiter(this, void 0, void 0, function* () {
|
|
487
|
+
const existingRoles = subjectType === 'user'
|
|
488
|
+
? yield this.listRolesForUser(recordName, subjectId)
|
|
489
|
+
: subjectType === 'inst'
|
|
490
|
+
? yield this.listRolesForInst(recordName, subjectId)
|
|
491
|
+
: [];
|
|
492
|
+
const roles = existingRoles.map((r) => r.role);
|
|
493
|
+
const assignment = this._markerPermissionAssignments.find((p) => p.recordName === recordName &&
|
|
494
|
+
markers.indexOf(p.marker) >= 0 &&
|
|
495
|
+
((p.subjectType === 'role' &&
|
|
496
|
+
roles.indexOf(p.subjectId) >= 0) ||
|
|
497
|
+
(p.subjectType === subjectType &&
|
|
498
|
+
p.subjectId === subjectId)) &&
|
|
499
|
+
p.resourceKind === resourceKind &&
|
|
500
|
+
(p.action === null || p.action === action) &&
|
|
501
|
+
(!p.expireTimeMs || p.expireTimeMs > currentTimeMs));
|
|
502
|
+
return {
|
|
503
|
+
success: true,
|
|
504
|
+
permissionAssignment: assignment,
|
|
505
|
+
};
|
|
506
|
+
});
|
|
507
|
+
}
|
|
508
|
+
// TODO: Support global permissions
|
|
509
|
+
// async assignGlobalPermissionToSubject(
|
|
510
|
+
// subjectType: SubjectType,
|
|
511
|
+
// subjectId: string,
|
|
512
|
+
// resourceKind: ResourceKinds,
|
|
513
|
+
// action: ActionKinds,
|
|
514
|
+
// options: PermissionOptions,
|
|
515
|
+
// expireTimeMs: number
|
|
516
|
+
// ): Promise<AssignGlobalPermissionToSubjectResult> {
|
|
517
|
+
// const userId = getSubjectUserId(subjectType, subjectId);
|
|
518
|
+
// const assignment: GlobalPermissionAssignment = {
|
|
519
|
+
// id: uuid(),
|
|
520
|
+
// userId,
|
|
521
|
+
// subjectType,
|
|
522
|
+
// subjectId,
|
|
523
|
+
// resourceKind,
|
|
524
|
+
// action,
|
|
525
|
+
// options,
|
|
526
|
+
// expireTimeMs
|
|
527
|
+
// };
|
|
528
|
+
// this._globalPermissionAssignments.push(assignment);
|
|
529
|
+
// return {
|
|
530
|
+
// success: true,
|
|
531
|
+
// permissionAssignment: assignment,
|
|
532
|
+
// };
|
|
533
|
+
// }
|
|
534
|
+
assignPermissionToSubjectAndResource(recordName, subjectType, subjectId, resourceKind, resourceId, action, options, expireTimeMs) {
|
|
535
|
+
return __awaiter(this, void 0, void 0, function* () {
|
|
536
|
+
const assignmentIndex = this._resourcePermissionAssignments.findIndex((a) => a.recordName === recordName &&
|
|
537
|
+
a.subjectType === subjectType &&
|
|
538
|
+
a.subjectId === subjectId &&
|
|
539
|
+
a.resourceKind === resourceKind &&
|
|
540
|
+
a.resourceId === resourceId &&
|
|
541
|
+
a.action === action);
|
|
542
|
+
if (assignmentIndex >= 0) {
|
|
543
|
+
const assignment = this._resourcePermissionAssignments[assignmentIndex];
|
|
544
|
+
this._resourcePermissionAssignments[assignmentIndex] = Object.assign(Object.assign({}, assignment), { options,
|
|
545
|
+
expireTimeMs });
|
|
546
|
+
return {
|
|
547
|
+
success: true,
|
|
548
|
+
permissionAssignment: assignment,
|
|
549
|
+
};
|
|
550
|
+
}
|
|
551
|
+
const userId = getSubjectUserId(subjectType, subjectId);
|
|
552
|
+
const assignment = {
|
|
553
|
+
id: uuid(),
|
|
554
|
+
recordName,
|
|
555
|
+
userId,
|
|
556
|
+
subjectType,
|
|
557
|
+
subjectId,
|
|
558
|
+
resourceKind,
|
|
559
|
+
resourceId,
|
|
560
|
+
action,
|
|
561
|
+
options,
|
|
562
|
+
expireTimeMs,
|
|
563
|
+
};
|
|
564
|
+
this._resourcePermissionAssignments.push(assignment);
|
|
565
|
+
return {
|
|
566
|
+
success: true,
|
|
567
|
+
permissionAssignment: assignment,
|
|
568
|
+
};
|
|
569
|
+
});
|
|
570
|
+
}
|
|
571
|
+
assignPermissionToSubjectAndMarker(recordName, subjectType, subjectId, resourceKind, marker, action, options, expireTimeMs) {
|
|
572
|
+
return __awaiter(this, void 0, void 0, function* () {
|
|
573
|
+
const assignmentIndex = this._markerPermissionAssignments.findIndex((a) => a.recordName === recordName &&
|
|
574
|
+
a.subjectType === subjectType &&
|
|
575
|
+
a.subjectId === subjectId &&
|
|
576
|
+
a.marker === marker &&
|
|
577
|
+
a.resourceKind === resourceKind &&
|
|
578
|
+
a.action === action);
|
|
579
|
+
if (assignmentIndex >= 0) {
|
|
580
|
+
const assignment = this._markerPermissionAssignments[assignmentIndex];
|
|
581
|
+
this._markerPermissionAssignments[assignmentIndex] = Object.assign(Object.assign({}, assignment), { options,
|
|
582
|
+
expireTimeMs });
|
|
583
|
+
return {
|
|
584
|
+
success: true,
|
|
585
|
+
permissionAssignment: assignment,
|
|
586
|
+
};
|
|
587
|
+
}
|
|
588
|
+
const userId = getSubjectUserId(subjectType, subjectId);
|
|
589
|
+
const assignment = {
|
|
590
|
+
id: uuid(),
|
|
591
|
+
recordName,
|
|
592
|
+
userId,
|
|
593
|
+
subjectType,
|
|
594
|
+
subjectId,
|
|
595
|
+
resourceKind,
|
|
596
|
+
marker,
|
|
597
|
+
action,
|
|
598
|
+
options,
|
|
599
|
+
expireTimeMs,
|
|
600
|
+
};
|
|
601
|
+
this._markerPermissionAssignments.push(assignment);
|
|
602
|
+
return {
|
|
603
|
+
success: true,
|
|
604
|
+
permissionAssignment: assignment,
|
|
605
|
+
};
|
|
606
|
+
});
|
|
607
|
+
}
|
|
608
|
+
getMarkerPermissionAssignmentById(id) {
|
|
609
|
+
var _a;
|
|
610
|
+
return __awaiter(this, void 0, void 0, function* () {
|
|
611
|
+
return ((_a = this._markerPermissionAssignments.find((a) => a.id === id)) !== null && _a !== void 0 ? _a : null);
|
|
612
|
+
});
|
|
613
|
+
}
|
|
614
|
+
getResourcePermissionAssignmentById(id) {
|
|
615
|
+
var _a;
|
|
616
|
+
return __awaiter(this, void 0, void 0, function* () {
|
|
617
|
+
return ((_a = this._resourcePermissionAssignments.find((a) => a.id === id)) !== null && _a !== void 0 ? _a : null);
|
|
618
|
+
});
|
|
619
|
+
}
|
|
620
|
+
deleteResourcePermissionAssignment(assigment) {
|
|
621
|
+
return __awaiter(this, void 0, void 0, function* () {
|
|
622
|
+
this._resourcePermissionAssignments =
|
|
623
|
+
this._resourcePermissionAssignments.filter((p) => p.id !== assigment.id);
|
|
624
|
+
return {
|
|
625
|
+
success: true,
|
|
626
|
+
};
|
|
627
|
+
});
|
|
628
|
+
}
|
|
629
|
+
deleteResourcePermissionAssignmentById(id) {
|
|
630
|
+
return __awaiter(this, void 0, void 0, function* () {
|
|
631
|
+
this._resourcePermissionAssignments =
|
|
632
|
+
this._resourcePermissionAssignments.filter((p) => p.id !== id);
|
|
633
|
+
return {
|
|
634
|
+
success: true,
|
|
635
|
+
};
|
|
636
|
+
});
|
|
637
|
+
}
|
|
638
|
+
deleteMarkerPermissionAssignment(assigment) {
|
|
639
|
+
return __awaiter(this, void 0, void 0, function* () {
|
|
640
|
+
this._markerPermissionAssignments =
|
|
641
|
+
this._markerPermissionAssignments.filter((p) => p.id !== assigment.id);
|
|
642
|
+
return {
|
|
643
|
+
success: true,
|
|
644
|
+
};
|
|
645
|
+
});
|
|
646
|
+
}
|
|
647
|
+
deleteMarkerPermissionAssignmentById(id) {
|
|
648
|
+
return __awaiter(this, void 0, void 0, function* () {
|
|
649
|
+
this._markerPermissionAssignments =
|
|
650
|
+
this._markerPermissionAssignments.filter((p) => p.id !== id);
|
|
651
|
+
return {
|
|
652
|
+
success: true,
|
|
653
|
+
};
|
|
654
|
+
});
|
|
655
|
+
}
|
|
656
|
+
listPermissionsInRecord(recordName) {
|
|
657
|
+
return __awaiter(this, void 0, void 0, function* () {
|
|
658
|
+
const resourceAssignments = this._resourcePermissionAssignments.filter((p) => p.recordName === recordName);
|
|
659
|
+
const markerAssignments = this._markerPermissionAssignments.filter((p) => p.recordName === recordName);
|
|
660
|
+
return {
|
|
661
|
+
success: true,
|
|
662
|
+
resourceAssignments,
|
|
663
|
+
markerAssignments,
|
|
664
|
+
};
|
|
665
|
+
});
|
|
666
|
+
}
|
|
667
|
+
listPermissionsForResource(recordName, resourceKind, resourceId) {
|
|
668
|
+
return __awaiter(this, void 0, void 0, function* () {
|
|
669
|
+
return this._resourcePermissionAssignments.filter((p) => p.recordName === recordName &&
|
|
670
|
+
p.resourceKind === resourceKind &&
|
|
671
|
+
p.resourceId === resourceId);
|
|
672
|
+
});
|
|
673
|
+
}
|
|
674
|
+
listPermissionsForMarker(recordName, marker) {
|
|
675
|
+
return __awaiter(this, void 0, void 0, function* () {
|
|
676
|
+
return this._markerPermissionAssignments.filter((p) => p.recordName === recordName && p.marker === marker);
|
|
677
|
+
});
|
|
678
|
+
}
|
|
679
|
+
listPermissionsForSubject(recordName, subjectType, subjectId) {
|
|
680
|
+
return __awaiter(this, void 0, void 0, function* () {
|
|
681
|
+
const resourceAssignments = this._resourcePermissionAssignments.filter((p) => p.recordName === recordName &&
|
|
682
|
+
p.subjectType === subjectType &&
|
|
683
|
+
p.subjectId === subjectId);
|
|
684
|
+
const markerAssignments = this._markerPermissionAssignments.filter((p) => p.recordName === recordName &&
|
|
685
|
+
p.subjectType === subjectType &&
|
|
686
|
+
p.subjectId === subjectId);
|
|
687
|
+
return {
|
|
688
|
+
success: true,
|
|
689
|
+
resourceAssignments,
|
|
690
|
+
markerAssignments,
|
|
691
|
+
};
|
|
692
|
+
});
|
|
693
|
+
}
|
|
401
694
|
countRecords(filter) {
|
|
402
695
|
return __awaiter(this, void 0, void 0, function* () {
|
|
403
696
|
let count = 0;
|
|
@@ -866,6 +1159,46 @@ export class MemoryStore {
|
|
|
866
1159
|
success: true,
|
|
867
1160
|
items,
|
|
868
1161
|
totalCount: count,
|
|
1162
|
+
marker: null,
|
|
1163
|
+
};
|
|
1164
|
+
});
|
|
1165
|
+
}
|
|
1166
|
+
listDataByMarker(request) {
|
|
1167
|
+
var _a;
|
|
1168
|
+
return __awaiter(this, void 0, void 0, function* () {
|
|
1169
|
+
const marker = request.marker;
|
|
1170
|
+
let record = this._getDataRecord(request.recordName);
|
|
1171
|
+
let items = [];
|
|
1172
|
+
const address = request.startingAddress;
|
|
1173
|
+
const sortAscending = ((_a = request.sort) !== null && _a !== void 0 ? _a : 'ascending') === 'ascending';
|
|
1174
|
+
let count = 0;
|
|
1175
|
+
for (let [key, item] of record.entries()) {
|
|
1176
|
+
if (item.markers.includes(marker)) {
|
|
1177
|
+
count += 1;
|
|
1178
|
+
if (!address ||
|
|
1179
|
+
(sortAscending && key > address) ||
|
|
1180
|
+
(!sortAscending && key < address)) {
|
|
1181
|
+
items.push({
|
|
1182
|
+
address: key,
|
|
1183
|
+
data: item.data,
|
|
1184
|
+
markers: item.markers,
|
|
1185
|
+
});
|
|
1186
|
+
}
|
|
1187
|
+
}
|
|
1188
|
+
}
|
|
1189
|
+
if (request.sort) {
|
|
1190
|
+
if (request.sort === 'ascending') {
|
|
1191
|
+
items = sortBy(items, (i) => i.address);
|
|
1192
|
+
}
|
|
1193
|
+
else if (request.sort === 'descending') {
|
|
1194
|
+
items = orderBy(items, (i) => i.address, 'desc');
|
|
1195
|
+
}
|
|
1196
|
+
}
|
|
1197
|
+
return {
|
|
1198
|
+
success: true,
|
|
1199
|
+
items,
|
|
1200
|
+
totalCount: count,
|
|
1201
|
+
marker: marker,
|
|
869
1202
|
};
|
|
870
1203
|
});
|
|
871
1204
|
}
|
|
@@ -1126,85 +1459,87 @@ export class MemoryStore {
|
|
|
1126
1459
|
}
|
|
1127
1460
|
return record;
|
|
1128
1461
|
}
|
|
1129
|
-
listUserPolicies(
|
|
1130
|
-
|
|
1131
|
-
|
|
1132
|
-
|
|
1133
|
-
|
|
1134
|
-
|
|
1135
|
-
|
|
1136
|
-
|
|
1137
|
-
|
|
1138
|
-
|
|
1139
|
-
|
|
1140
|
-
|
|
1141
|
-
|
|
1142
|
-
|
|
1143
|
-
|
|
1144
|
-
|
|
1145
|
-
|
|
1146
|
-
|
|
1147
|
-
|
|
1148
|
-
|
|
1149
|
-
|
|
1150
|
-
|
|
1151
|
-
|
|
1152
|
-
|
|
1153
|
-
|
|
1154
|
-
|
|
1155
|
-
|
|
1156
|
-
|
|
1157
|
-
|
|
1158
|
-
|
|
1159
|
-
|
|
1160
|
-
|
|
1161
|
-
|
|
1162
|
-
|
|
1163
|
-
|
|
1164
|
-
|
|
1165
|
-
|
|
1166
|
-
|
|
1167
|
-
|
|
1168
|
-
|
|
1169
|
-
|
|
1170
|
-
|
|
1171
|
-
|
|
1172
|
-
|
|
1173
|
-
|
|
1174
|
-
|
|
1175
|
-
|
|
1176
|
-
|
|
1177
|
-
|
|
1178
|
-
|
|
1179
|
-
|
|
1180
|
-
|
|
1181
|
-
|
|
1182
|
-
|
|
1183
|
-
|
|
1184
|
-
|
|
1185
|
-
|
|
1186
|
-
}
|
|
1187
|
-
|
|
1188
|
-
|
|
1189
|
-
|
|
1190
|
-
|
|
1191
|
-
|
|
1192
|
-
|
|
1193
|
-
|
|
1194
|
-
|
|
1195
|
-
|
|
1196
|
-
|
|
1197
|
-
|
|
1198
|
-
|
|
1199
|
-
|
|
1200
|
-
|
|
1201
|
-
|
|
1202
|
-
|
|
1203
|
-
|
|
1204
|
-
|
|
1205
|
-
|
|
1206
|
-
|
|
1207
|
-
|
|
1462
|
+
// async listUserPolicies(
|
|
1463
|
+
// recordName: string,
|
|
1464
|
+
// startingMarker: string
|
|
1465
|
+
// ): Promise<ListUserPoliciesStoreResult> {
|
|
1466
|
+
// const recordPolicies = this.policies[recordName] ?? {};
|
|
1467
|
+
// const keys = sortBy(Object.keys(recordPolicies));
|
|
1468
|
+
// let results: ListedUserPolicy[] = [];
|
|
1469
|
+
// let start = !startingMarker;
|
|
1470
|
+
// for (let key of keys) {
|
|
1471
|
+
// if (start) {
|
|
1472
|
+
// results.push({
|
|
1473
|
+
// marker: key,
|
|
1474
|
+
// document: recordPolicies[key].document,
|
|
1475
|
+
// markers: recordPolicies[key].markers,
|
|
1476
|
+
// });
|
|
1477
|
+
// } else if (key === startingMarker || key > startingMarker) {
|
|
1478
|
+
// start = true;
|
|
1479
|
+
// }
|
|
1480
|
+
// }
|
|
1481
|
+
// return {
|
|
1482
|
+
// success: true,
|
|
1483
|
+
// policies: results,
|
|
1484
|
+
// totalCount: results.length,
|
|
1485
|
+
// };
|
|
1486
|
+
// }
|
|
1487
|
+
// async getUserPolicy(
|
|
1488
|
+
// recordName: string,
|
|
1489
|
+
// marker: string
|
|
1490
|
+
// ): Promise<GetUserPolicyResult> {
|
|
1491
|
+
// const policy = this.policies[recordName]?.[marker];
|
|
1492
|
+
// if (!policy) {
|
|
1493
|
+
// return {
|
|
1494
|
+
// success: false,
|
|
1495
|
+
// errorCode: 'policy_not_found',
|
|
1496
|
+
// errorMessage: 'The policy was not found.',
|
|
1497
|
+
// };
|
|
1498
|
+
// }
|
|
1499
|
+
// return {
|
|
1500
|
+
// success: true,
|
|
1501
|
+
// document: policy.document,
|
|
1502
|
+
// markers: policy.markers,
|
|
1503
|
+
// };
|
|
1504
|
+
// }
|
|
1505
|
+
// async updateUserPolicy(
|
|
1506
|
+
// recordName: string,
|
|
1507
|
+
// marker: string,
|
|
1508
|
+
// policy: UserPolicyRecord
|
|
1509
|
+
// ): Promise<UpdateUserPolicyResult> {
|
|
1510
|
+
// if (!this.policies[recordName]) {
|
|
1511
|
+
// this.policies[recordName] = {};
|
|
1512
|
+
// }
|
|
1513
|
+
// this.policies[recordName][marker] = {
|
|
1514
|
+
// document: policy.document,
|
|
1515
|
+
// markers: policy.markers,
|
|
1516
|
+
// };
|
|
1517
|
+
// return {
|
|
1518
|
+
// success: true,
|
|
1519
|
+
// };
|
|
1520
|
+
// }
|
|
1521
|
+
// async listPoliciesForMarkerAndUser(
|
|
1522
|
+
// recordName: string,
|
|
1523
|
+
// userId: string,
|
|
1524
|
+
// marker: string
|
|
1525
|
+
// ): Promise<ListMarkerPoliciesResult> {
|
|
1526
|
+
// const policies = [DEFAULT_ANY_RESOURCE_POLICY_DOCUMENT];
|
|
1527
|
+
// if (marker === PUBLIC_READ_MARKER) {
|
|
1528
|
+
// policies.push(DEFAULT_PUBLIC_READ_POLICY_DOCUMENT);
|
|
1529
|
+
// } else if (marker === PUBLIC_WRITE_MARKER) {
|
|
1530
|
+
// policies.push(DEFAULT_PUBLIC_WRITE_POLICY_DOCUMENT);
|
|
1531
|
+
// }
|
|
1532
|
+
// const policy = this.policies[recordName]?.[marker];
|
|
1533
|
+
// if (policy) {
|
|
1534
|
+
// policies.push(policy.document);
|
|
1535
|
+
// }
|
|
1536
|
+
// return {
|
|
1537
|
+
// policies,
|
|
1538
|
+
// recordOwnerPrivacyFeatures:
|
|
1539
|
+
// await this._getRecordOwnerPrivacyFeatures(recordName),
|
|
1540
|
+
// userPrivacyFeatures: await this._getUserPrivacyFeatures(userId),
|
|
1541
|
+
// };
|
|
1542
|
+
// }
|
|
1208
1543
|
_getRecordOwnerPrivacyFeatures(recordName) {
|
|
1209
1544
|
return __awaiter(this, void 0, void 0, function* () {
|
|
1210
1545
|
let record = yield this.getRecordByName(recordName);
|
|
@@ -1356,34 +1691,46 @@ export class MemoryStore {
|
|
|
1356
1691
|
};
|
|
1357
1692
|
});
|
|
1358
1693
|
}
|
|
1359
|
-
updateUserRoles(
|
|
1360
|
-
|
|
1361
|
-
|
|
1362
|
-
|
|
1363
|
-
|
|
1364
|
-
|
|
1365
|
-
|
|
1366
|
-
|
|
1367
|
-
|
|
1368
|
-
|
|
1369
|
-
|
|
1370
|
-
|
|
1371
|
-
|
|
1372
|
-
|
|
1373
|
-
|
|
1374
|
-
|
|
1375
|
-
|
|
1376
|
-
|
|
1377
|
-
|
|
1378
|
-
|
|
1379
|
-
|
|
1380
|
-
|
|
1381
|
-
|
|
1382
|
-
|
|
1383
|
-
|
|
1384
|
-
|
|
1385
|
-
|
|
1386
|
-
}
|
|
1694
|
+
// async updateUserRoles(
|
|
1695
|
+
// recordName: string,
|
|
1696
|
+
// userId: string,
|
|
1697
|
+
// update: UpdateRolesUpdate
|
|
1698
|
+
// ): Promise<UpdateUserRolesResult> {
|
|
1699
|
+
// if (!this.roleAssignments[recordName]) {
|
|
1700
|
+
// this.roleAssignments[recordName] = {};
|
|
1701
|
+
// }
|
|
1702
|
+
// const assignments = update.roles
|
|
1703
|
+
// .filter((r) => getExpireTime(r.expireTimeMs) > Date.now())
|
|
1704
|
+
// .map((r) => ({
|
|
1705
|
+
// ...r,
|
|
1706
|
+
// expireTimeMs:
|
|
1707
|
+
// r.expireTimeMs === Infinity ? null : r.expireTimeMs,
|
|
1708
|
+
// }));
|
|
1709
|
+
// this.roleAssignments[recordName][userId] = assignments;
|
|
1710
|
+
// return {
|
|
1711
|
+
// success: true,
|
|
1712
|
+
// };
|
|
1713
|
+
// }
|
|
1714
|
+
// async updateInstRoles(
|
|
1715
|
+
// recordName: string,
|
|
1716
|
+
// inst: string,
|
|
1717
|
+
// update: UpdateRolesUpdate
|
|
1718
|
+
// ): Promise<UpdateUserRolesResult> {
|
|
1719
|
+
// if (!this.roleAssignments[recordName]) {
|
|
1720
|
+
// this.roleAssignments[recordName] = {};
|
|
1721
|
+
// }
|
|
1722
|
+
// const assignments = update.roles
|
|
1723
|
+
// .filter((r) => getExpireTime(r.expireTimeMs) > Date.now())
|
|
1724
|
+
// .map((r) => ({
|
|
1725
|
+
// ...r,
|
|
1726
|
+
// expireTimeMs:
|
|
1727
|
+
// r.expireTimeMs === Infinity ? null : r.expireTimeMs,
|
|
1728
|
+
// }));
|
|
1729
|
+
// this.roleAssignments[recordName][inst] = assignments;
|
|
1730
|
+
// return {
|
|
1731
|
+
// success: true,
|
|
1732
|
+
// };
|
|
1733
|
+
// }
|
|
1387
1734
|
_getRolesForEntity(recordName, id) {
|
|
1388
1735
|
var _a, _b, _c, _d;
|
|
1389
1736
|
const roles = (_b = (_a = this.roles[recordName]) === null || _a === void 0 ? void 0 : _a[id]) !== null && _b !== void 0 ? _b : new Set();
|